Unusual patterns of shadow manipulation in ThreeJS

I am currently working on a threeJS scene with multiple spheres (multimaterial) and a directional light. The code snippet for adding the directional light is as follows:

this.light = new THREE.DirectionalLight( 0xFFFFFF, 1 );
this.light.position.set( 2, 10, 2 );  
this.light.castShadow = true;
this.light.shadowMapSoft = true;
this.light.shadowCameraVisible = true;
this.light.shadowCameraNear = 1;
this.light.shadowCameraFar = 10; 
this.light.shadowBias = 0.0009;
this.light.shadowDarkness = 0.3;
this.light.shadowMapWidth = 1024;
this.light.shadowMapHeight = 1024;
this.light.shadowCameraLeft = -8;
this.light.shadowCameraRight = 8;
this.light.shadowCameraTop = 8;
this.light.shadowCameraBottom = -8;

When spheres are added or removed by the user, a function called "reforms" adjusts the shadow camera frustum dynamically as illustrated in this diagram: https://i.sstatic.net/xWPee.png

    this.light.position.set( posV.x, posV.y, posV.z); 

    this.light.shadowCamera.far = l2*3;
    this.light.shadowCamera.left = -l2;
    this.light.shadowCamera.right = l2;
    this.light.shadowCamera.bottom = -l2;
    this.light.shadowCamera.top = l2;           
    this.light.shadowCamera.updateProjectionMatrix(); 

The result of implementing the above code can be seen below:

Another view of the same scenario shown above can be found here: https://i.sstatic.net/OMtvf.png

I have enabled the visibility of the camera frustum, but I am facing issues with unnecessary shadowing as highlighted by the red arrows. Despite no additional objects in the scene and the spheres being completely within the camera frustum.

Such shadowing problems often arise after sphere updates (add/remove), has anyone encountered a similar issue before?

I am using three.js r72, any insights would be greatly appreciated! thanks!

Answer №1

After reviewing your feedback, it appears that you are experiencing self-shadowing artifacts.

To address this issue, you should tweak the shadowBias parameter (now referred to as shadow.bias).

Adjusting the shadow bias will involve finding a balance between avoiding "peter-panning" (excessive positive bias) and minimizing self-shadowing artifacts (excessive negative bias).

Version of three.js being used: r.73

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

Exploring the dynamic changes in user authentication state with Angular Fire subscriptions

At the moment, I have been listening to authentication state changes in my ngOnInit method of my AppComponent: export class AppComponent implements OnInit { constructor(public fireAuth: AngularFireAuth) { } ngOnInit(): void { this.fireAuth.auth ...

What is the best method to obtain the following id for an image?

Whenever I hover over the li with the number 3, I am getting the wrong number for the next id in the img tag. The first time, I get next id = 4 which is incorrect. But on the second hover, I get next id = 0 which is what I actually need. How can I correctl ...

Challenges in using while-loops and timers in JavaScript

I am currently developing a timer similar to the Pomodoro technique. This timer has specific requirements: When the 'Start' button is clicked: The timer should start and run for 5 seconds (times may vary). Once the timer completes, an AJAX eve ...

WebWorker tends to be loaded intermittently on android devices

We have integrated a web worker in our Ionic application to handle certain computations. Previously, this setup functioned properly without any issues. However, suddenly we are encountering some challenges. Despite making significant changes throughout th ...

Submit a list of checkboxes selected to Google Sheets separated by commas

Is there a way to modify the script I'm using to enter data from an HTML form into a Google Sheet so that my checkbox fields will be entered as a list, separated by commas? If all boxes were checked in the example form below, I would like the cell fo ...

Automatically resetting the Redux toolkit store when navigating between pages in Next.js

I am a new Next user who has been using Redux with React for a while. However, I encountered many challenges when trying to integrate Redux with Next. I have decided to move on from this solution. store.js import { configureStore } from '@reduxjs/to ...

Troubleshooting Problem with Padding in ion-content for Ionic Angular

I am currently developing my inaugural Ionic application. The initial template I utilized was the rudimentary sidemenu layout. $ ionic start myApp sidemenu Afterwards, I crafted a straightforward page featuring a list which appears as follows... <ion ...

The links on my Bootstrap navigation menu are fully functional on mobile devices

While my WordPress website with a Bootstrap menu appears to work fine on desktop, I am facing an issue on mobile. The dropdown menu links do not respond when clicked. The hamburger button functionality seems intact as it opens and closes the dropdown menu ...

Automatically save checked checkboxes in localStorage

In my PHP code, I have something similar to the following: if(isset($_POST['submit']){ $check = in_array($row['service_object_id'], $values) ? 'checked' : ''; } echo ...

What are some creative ways to design the selected tab?

In my Vue parent component, I have multiple child components. There are several elements that toggle between components by updating the current data. The issue is that I am unsure how to indicate which tab is currently active. I've tried various li ...

How can you upload information while specifying the status?

Within my config.ts file, the contents are as follows: export const keyOrders: {} = { "aa": { active: true, order: 0 }, "bb": { active: true, order: 1 }, "cc": { active: true, order: 2 }, "dd": { active: true, order: 3 }, "ee": { activ ...

Error message received when calling a function within a Vue watcher states "function is not defined"

My goal is to trigger a function in a Vue component when a prop changes using a watcher: props: [ 'mediaUrl' ], watch: { mediaUrl: function() { this.attemptToLoadImage(); } }, medthods: { attemptToLoadImage: function() { console ...

"Efficiently handle multiple clicks with this handy jQuery shortcut

Hello, I am relatively new to JavaScript and programming in general. Can anyone provide guidance on how to optimize my code? I believe there are various ways to write a small and efficient code that achieves the same result. $('.ourservices-content . ...

Using Rails to render various js templates based on different AJAX requests

My Rails app includes a Movies#index page where I send AJAX requests in two scenarios: When I am loading more @movies When I am filtering @movies I am looking for a way to render different js files based on which scenario I am handling, instead of using ...

Navigating the Complexities of Ajax POST and Stringify

As I delve into the world of POST with Ajax, one common trend I've noticed is the use of stringify on static arrays in many examples. In my specific case, I am constructing an array using jQuery objects extracted from <input> values. The Power ...

"Learn how to create a scrolling div using a combination of CSS and JavaScript with absolute and relative

After relying solely on "pre-made" components like Mui or TailWind, I decided to create a component using only CSS and maybe JavaScript. However, I encountered some difficulties when attempting to position a div inside an image using relative and absolute ...

Ways to generate an Angular 7 component

Seeking guidance on creating an angular 7 component. I have forked a jsFiddle at this link: https://jsfiddle.net/gauravshrestha/fdxsywLv/. The chart in the fiddle allows data points to be dragged up and down. My goal is to convert this into a component whe ...

The functionality of CKEDITOR.tools.getindex has not been found

I'm currently in the process of updating my CKEDITOR version from 4.4.1 to 4.5.1. In order to do this, I am uploading my build-config.js file to ensure that I have all the same plugins as before with the latest CKEDITOR version. The issue arises when ...

Exploring Transparency in THREE JS: Rendering select faces of a BufferGeometry with a see-through effect

I am faced with the challenge of rendering two cubes on a single non-indexed buffer geometry. My goal is to make these cubes transparent so that all sides are visible simultaneously. To achieve this, I aim to utilize the "vertexAlphas" material property to ...

Incorporating HTML into the Ajax Response

I recently encountered a strange issue with a service that returns an HTML page as the AJAX response. This page contains a form that is automatically triggered by scripts within the page, resulting in a POST request being sent when the page is rendered. My ...