Przeglądaj źródła

ShadowMapViewerGPU: Fix DepthTexture usage (#31673)

* fix shadowmap viewer

* cleanup

* Update ShadowMapViewerGPU.js

Flip the UVs and render with near white, far black.

* revert demo

---------

Co-authored-by: WestLangley <WestLangley@users.noreply.github.com>
sunag 7 miesięcy temu
rodzic
commit
18128b8088
1 zmienionych plików z 12 dodań i 5 usunięć
  1. 12 5
      examples/jsm/utils/ShadowMapViewerGPU.js

+ 12 - 5
examples/jsm/utils/ShadowMapViewerGPU.js

@@ -7,9 +7,10 @@ import {
 	OrthographicCamera,
 	PlaneGeometry,
 	Scene,
-	Texture
+	DepthTexture,
+	Vector2
 } from 'three';
-import { texture } from 'three/tsl';
+import { uv, uniform, textureLoad } from 'three/tsl';
 
 /**
  * This is a helper for visualising a given light's shadow map.
@@ -60,8 +61,10 @@ class ShadowMapViewer {
 
 		const material = new NodeMaterial();
 
-		const shadowMapUniform = texture( new Texture() );
-		material.fragmentNode = shadowMapUniform;
+		const textureDimension = uniform( new Vector2() );
+
+		const shadowMapUniform = textureLoad( new DepthTexture(), uv().flipY().mul( textureDimension ) );
+		material.fragmentNode = shadowMapUniform.x.oneMinus();
 
 		const plane = new PlaneGeometry( frame.width, frame.height );
 		const mesh = new Mesh( plane, material );
@@ -173,7 +176,11 @@ class ShadowMapViewer {
 				//always end up with the scene's first added shadow casting light's shadowMap
 				//in the shader
 				//See: https://github.com/mrdoob/three.js/issues/5932
-				shadowMapUniform.value = light.shadow.map.texture;
+
+				const depthTexture = light.shadow.map.depthTexture;
+
+				shadowMapUniform.value = depthTexture;
+				textureDimension.value.set( depthTexture.width, depthTexture.height );
 
 				currentAutoClear = renderer.autoClear;
 				renderer.autoClear = false; // To allow render overlay

粤ICP备19079148号