The shadows in HTML5 Three.js r81 experience a loss of alpha maps when the camera is rotated

While working on my project using Three.JS r81, I encountered a problem with shadows passing through transparent materials when using a custom depth shader. Initially, the shadows appeared fine when there was only a tree in the scene. However, as soon as I added a simple box about 100 units to the right of the tree, the transparency in the shadows from the transparent material disappeared. Disabling shadows on the box did not resolve the issue.

Click here to see how the shadows should appear

Here's what happens when the box is added

An interesting observation is that moving the box closer to the tree seems to fix the shadow transparency issue. Additionally, I am using an orbital camera, and rotating around the scene causes the shadows to alternate between good and bad as you move around the tree.

The setup for my light source is quite basic:

var directionalLight = new THREE.DirectionalLight(0xffffff, 1);
directionalLight.position.set(120, 120, 120);

directionalLight.castShadow = true;
directionalLight.shadow.camera.right = 250;
directionalLight.shadow.camera.left = -250;
directionalLight.shadow.camera.top = 250;
directionalLight.shadow.camera.bottom = -250;
directionalLight.shadow.camera.far = 300;
directionalLight.target.position.x = 80;

directionalLight.shadow.mapSize.width = directionalLight.shadow.mapSize.height = 1024;
directionalLight.shadow.bias = -0.0003;
directionalLight.shadow.camera.scale.x = 0.25;
directionalLight.shadow.camera.scale.y = 0.25;

scene.add(directionalLight);

I have experimented with various settings in the light shadow configurations but none seem to have a positive impact on the issue.

I am aware that the shadow system in Three.js has undergone some changes in the past year. However, I am uncertain whether the problem lies with me or if it could be a potential bug within the library. Any suggestions?

Answer №1

It turns out that the issue was caused by a simple oversight on my part. Instead of referencing mesh.material.map in my shader material uniforms, I mistakenly used mesh.material. Once I corrected this mistake, everything started working smoothly.

var uniforms = { texture: { type: "t", value: mesh.material.map } }

shaderLibrary[libraryName] = new THREE.ShaderMaterial({
                            uniforms: uniforms,
                            vertexShader: vertexShader,
                            fragmentShader: fragmentShader,
                        });  

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

In JavaScript, a prompt is used to request the user to input a CSS property. If the input is incorrect,

Implement a while loop that continuously prompts the user to enter a color. If the color entered matches a CSS property such as blue, red, or #000000: The background will change accordingly, but if the user enters an incorrect color, a message will be dis ...

Using mqtt in Node.js, an example of creating a client with the syntax mqtt.Client(streamBuilder,

Does anyone have a sample implementation of the mqtt.Client(streamBuilder, options) function they can share? https://github.com/mqttjs/MQTT.js/#mqttclientstreambuilder-options It would be really helpful if you could provide a thorough explanation. ...

Enable a click event within an iFrame by clicking on an element in the parent document

I am attempting to trigger the click event of an element inside an iFrame (specifically a standard Twitter follow button) when clicking on an element within my main webpage. Below is the code snippet I have been experimenting with, but unfortunately it do ...

There was an error that occurred when attempting to read the property 'hasOne' of an undefined value: TypeError

Error Alert: Property 'hasOne' is undefined and cannot be read in Function.ADataMembers.associate. Check out ADataMember.js below: 'use strict' module.exports = (sequelize, DataTypes) => { var ADataMembers = sequelize.define(' ...

The `pages` directory seems to be missing. Package error encountered while using NextJS

As I strive to create a NextJS executable application for Windows, an irritating error has arisen: (node:18500) UnhandledPromiseRejectionWarning: Error: > Couldn't find a pages directory. Please create one under the project root I assure you, th ...

Issues with d3.js transition removal functionality not functioning as expected

Having an issue with a d3.js visualization that involves multiple small visualizations and a timeline. When the timeline changes, data points are supposed to be added or removed accordingly. Here is the code snippet responsible for updating: var channels ...

IntelliSense in VSCode is unable to recognize the `exports` property within the package.json file

Currently, I am utilizing a library named sinuous, which contains a submodule known as "sinuous/map". Interestingly, VSCode seems to lack knowledge about the type of 'map' when using import { map } from "sinuous/map", but it recognizes the type ...

node.js experiencing crashing following loop iteration

I'm currently developing a performance testing tool using node.js to automate the process and store the results in MySQL. This tool is designed to track the load time of specific web pages in a browser, with the measurement displayed in seconds. I am ...

What is the correct location to store the bower.json file?

I'm currently using bower 1.2.2 to handle my client-side libraries for the first time with a new node app. I'm unsure whether I should initialize bower in the main project root alongside gruntfile.js and package.json, or within the static directo ...

Issue with .submit() not submitting form after setTimeout timer runs out

How can I add a delay after a user clicks submit on a form before it actually submits? I have an image that appears when the click event is triggered, but the form never actually submits... This is the HTML form in question: <form class='loginFor ...

Avoid refreshing the page upon pressing the back button in AngularJS

Currently, I am working on building a web application that heavily relies on AJAX with AngularJS. One issue I am facing is that when the user clicks the back button on their browser, the requests are being re-made which results in data having to be reloa ...

Ways to retrieve every element inside a specific div container

Is there a way to select all elements inside a div except for specific ones? For example, consider the following structure: <div id="abc"> <div class="def"> sagar patil</div> <div class="pqr"> patil</div& ...

Verifying the execute boolean status or utilizing try/catch with PDO

Apologies for the subpar title. My project heavily relies on AJAX, with most responses returning either 'error' or 'success' messages in an array. In my Javascript code, I display these messages in a custom notification bar. I'm u ...

Issue with accessing Contacts API functionality in Firefox OS application

I have followed all the instructions provided in this documentation, but I keep encountering errors. My testing environment is the "Firefox OS 2.2" simulator. In my manifest file, I have included two permissions as follows: "permissions": { "deskto ...

Having trouble implementing table row selection with semantic-ui table

I am currently in the process of adopting Semantic-UI, but I am encountering some issues. Specifically, I am struggling to make row selection work in a table. Below is the sample HTML I am using from Semantic-UI: <table class="ui selectable celled tab ...

Tips for inserting user input into an array and showcasing it

const [inputValue, setInputValue] = useState(""); return ( <input onChange={(event) => setInputValue(event.target.value)} /> <p>{inputValue}</p> ); I'm facing a problem where I need to take input from a user and store it in ...

Direct your cursor to move across the sphere surface in THREE.JS

I'm working on a project to develop an interactive globe where users can drag points on the surface using their mouse cursor. Here is the code snippet I've been working on Currently, I've managed to set up the main sphere and a smaller red ...

Retrieving data from a JSON file using JavaScript in a Node.js environment

Seeking help to extract a value from a JSON file in JavaScript but struggling to find the right syntax. If someone could assist me with writing this line of code in Node.js, I would greatly appreciate it. The value I am trying to retrieve is "totalCount". ...

Switching from React version 15.6.2 to 16 results in disruptions to the functionality of the web

Currently, I am encountering an issue where none of my index.js files are rendering. After using the react-scripts to build my web application in version 16.2.0, I receive an error stating that r.PropTypes is undefined when trying to access the localhost a ...

The Power of AngularJS Directives in Harnessing jQuery DOM Event Bindings

I have developed a new directive and have some doubts about the binding syntax like element.bind("click", function(){}). Every time the link function of the directive is called, it creates a duplicate binding. What is the best Angular approach to handle th ...