Bladeren bron

ShadowNode: Fix shadows in first frame. (#32021)

* ShadowNode: Fix shadows in first frame.

* Lights: Fix `lightShadowMatrix()`.
Michael Herzog 3 maanden geleden
bovenliggende
commit
cfd6be3add
2 gewijzigde bestanden met toevoegingen van 12 en 1 verwijderingen
  1. 10 0
      src/nodes/accessors/Lights.js
  2. 2 1
      src/nodes/lighting/ShadowNode.js

+ 10 - 0
src/nodes/accessors/Lights.js

@@ -32,8 +32,18 @@ export function lightShadowMatrix( light ) {
 
 	return data.shadowMatrix || ( data.shadowMatrix = uniform( 'mat4' ).setGroup( renderGroup ).onRenderUpdate( ( frame ) => {
 
+		// normally, shadow matrices are updated in ShadowNode. However, if the shadow matrix is used outside
+		// of shadow rendering (like in ProjectorLightNode), the shadow matrix still requires an update
+
 		if ( light.castShadow !== true || frame.renderer.shadowMap.enabled === false ) {
 
+			if ( light.shadow.camera.coordinateSystem !== frame.camera.coordinateSystem ) {
+
+				light.shadow.camera.coordinateSystem = frame.camera.coordinateSystem;
+				light.shadow.camera.updateProjectionMatrix();
+
+			}
+
 			light.shadow.updateMatrices( light );
 
 		}

+ 2 - 1
src/nodes/lighting/ShadowNode.js

@@ -408,7 +408,7 @@ class ShadowNode extends ShadowBaseNode {
 	 */
 	setupShadow( builder ) {
 
-		const { renderer } = builder;
+		const { renderer, camera } = builder;
 
 		const { light, shadow } = this;
 
@@ -416,6 +416,7 @@ class ShadowNode extends ShadowBaseNode {
 
 		const { depthTexture, shadowMap } = this.setupRenderTarget( shadow, builder );
 
+		shadow.camera.coordinateSystem = camera.coordinateSystem;
 		shadow.camera.updateProjectionMatrix();
 
 		// VSM

粤ICP备19079148号