|
1 | | -import { FrontSide, BackSide, DoubleSide, NearestFilter, LinearFilter, PCFShadowMap, VSMShadowMap, NoBlending, LessEqualCompare, GreaterEqualCompare, DepthFormat, UnsignedIntType, RGFormat, HalfFloatType, PCFSoftShadowMap, IdentityDepthPacking } from '../../constants.js'; |
| 1 | +import { FrontSide, BackSide, DoubleSide, NearestFilter, LinearFilter, PCFShadowMap, VSMShadowMap, NoBlending, LessEqualCompare, GreaterEqualCompare, DepthFormat, UnsignedIntType, RGFormat, HalfFloatType, FloatType, PCFSoftShadowMap } from '../../constants.js'; |
2 | 2 | import { WebGLRenderTarget } from '../WebGLRenderTarget.js'; |
3 | 3 | import { WebGLCubeRenderTarget } from '../WebGLCubeRenderTarget.js'; |
4 | 4 | import { MeshDepthMaterial } from '../../materials/MeshDepthMaterial.js'; |
@@ -26,7 +26,6 @@ function WebGLShadowMap( renderer, objects, capabilities ) { |
26 | 26 | _viewport = new Vector4(), |
27 | 27 |
|
28 | 28 | _depthMaterial = new MeshDepthMaterial(), |
29 | | - _depthMaterialVSM = new MeshDepthMaterial( { depthPacking: IdentityDepthPacking } ), |
30 | 29 | _distanceMaterial = new MeshDistanceMaterial(), |
31 | 30 |
|
32 | 31 | _materialCache = {}, |
@@ -215,6 +214,14 @@ function WebGLShadowMap( renderer, objects, capabilities ) { |
215 | 214 | } ); |
216 | 215 | shadow.map.texture.name = light.name + '.shadowMap'; |
217 | 216 |
|
| 217 | + // Native depth texture for VSM - depth is captured here, then blurred into the color texture |
| 218 | + shadow.map.depthTexture = new DepthTexture( _shadowMapSize.x, _shadowMapSize.y, FloatType ); |
| 219 | + shadow.map.depthTexture.name = light.name + '.shadowMapDepth'; |
| 220 | + shadow.map.depthTexture.format = DepthFormat; |
| 221 | + shadow.map.depthTexture.compareFunction = null; // For regular sampling (not shadow comparison) |
| 222 | + shadow.map.depthTexture.minFilter = NearestFilter; |
| 223 | + shadow.map.depthTexture.magFilter = NearestFilter; |
| 224 | + |
218 | 225 | } else { |
219 | 226 |
|
220 | 227 | if ( light.isPointLight ) { |
@@ -339,9 +346,9 @@ function WebGLShadowMap( renderer, objects, capabilities ) { |
339 | 346 |
|
340 | 347 | } |
341 | 348 |
|
342 | | - // vertical pass |
| 349 | + // vertical pass - read from native depth texture |
343 | 350 |
|
344 | | - shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture; |
| 351 | + shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.depthTexture; |
345 | 352 | shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize; |
346 | 353 | shadowMaterialVertical.uniforms.radius.value = shadow.radius; |
347 | 354 | renderer.setRenderTarget( shadow.mapPass ); |
@@ -371,15 +378,7 @@ function WebGLShadowMap( renderer, objects, capabilities ) { |
371 | 378 |
|
372 | 379 | } else { |
373 | 380 |
|
374 | | - if ( type === VSMShadowMap ) { |
375 | | - |
376 | | - result = _depthMaterialVSM; |
377 | | - |
378 | | - } else { |
379 | | - |
380 | | - result = ( light.isPointLight === true ) ? _distanceMaterial : _depthMaterial; |
381 | | - |
382 | | - } |
| 381 | + result = ( light.isPointLight === true ) ? _distanceMaterial : _depthMaterial; |
383 | 382 |
|
384 | 383 | if ( ( renderer.localClippingEnabled && material.clipShadows === true && Array.isArray( material.clippingPlanes ) && material.clippingPlanes.length !== 0 ) || |
385 | 384 | ( material.displacementMap && material.displacementScale !== 0 ) || |
|
0 commit comments