Strange shading behavior in ThreeJS

therefore, I have a script thrice, and I have some areas (multidimensional). I also have a directional light:

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;

So, when the user adds or removes spheres, a function that performs the "reform" of the shadow camera: enter image description here

    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(); 

and a possible result of the above code:

another aspect of the exact situation above:  enter image description here

I set the camera truncation visibility so that it appears. The problem is that shading is generated for no reason (indicated by red arrows). There are currently no other objects in the scene, and the spheres are completely inside the camera.

Problems in shadow mode like these are common after updating spheres (add / remove), does anyone have an idea about this?

I am using three.js r72 , thanks!

0
1

, , , , .

shadowBias ( shadow.bias).

" peter-panning" ( ) ( ).

three.js r.73

+1

Source: https://habr.com/ru/post/1685147/


All Articles