Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,16 @@ export default /* glsl */`
float shadow = 1.0;

shadowCoord.xyz /= shadowCoord.w;
shadowCoord.z += shadowBias;

#ifdef USE_REVERSED_DEPTH_BUFFER

shadowCoord.z -= shadowBias;

#else

shadowCoord.z += shadowBias;

#endif

bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;
bool frustumTest = inFrustum && shadowCoord.z <= 1.0;
Expand All @@ -167,8 +176,16 @@ export default /* glsl */`
float mean = distribution.x;
float variance = distribution.y * distribution.y;

float hard_shadow = step( shadowCoord.z, mean );
#ifdef USE_REVERSED_DEPTH_BUFFER

float hard_shadow = step( mean, shadowCoord.z );

#else

float hard_shadow = step( shadowCoord.z, mean );

#endif

// Early return if fully lit
if ( hard_shadow == 1.0 ) {

Expand Down Expand Up @@ -205,7 +222,16 @@ export default /* glsl */`
float shadow = 1.0;

shadowCoord.xyz /= shadowCoord.w;
shadowCoord.z += shadowBias;

#ifdef USE_REVERSED_DEPTH_BUFFER

shadowCoord.z -= shadowBias;

#else

shadowCoord.z += shadowBias;

#endif

bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;
bool frustumTest = inFrustum && shadowCoord.z <= 1.0;
Expand All @@ -216,11 +242,13 @@ export default /* glsl */`

#ifdef USE_REVERSED_DEPTH_BUFFER

depth = 1.0 - depth;
shadow = step( depth, shadowCoord.z );

#endif
#else

shadow = step( shadowCoord.z, depth );

shadow = step( shadowCoord.z, depth );
#endif

}

Expand Down
7 changes: 0 additions & 7 deletions src/renderers/shaders/ShaderLib/vsm.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ void main() {
#else

float depth = texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ).r;

#ifdef USE_REVERSED_DEPTH_BUFFER

depth = 1.0 - depth;

#endif

mean += depth;
squared_mean += depth * depth;

Expand Down
5 changes: 3 additions & 2 deletions src/renderers/webgl/WebGLShadowMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ function WebGLShadowMap( renderer, objects, capabilities ) {

}

const reversedDepthBuffer = renderer.state.buffers.depth.getReversed();
shadow.camera._reversedDepth = reversedDepthBuffer;

if ( shadow.map === null || typeChanged === true ) {

if ( shadow.map !== null ) {
Expand Down Expand Up @@ -255,8 +258,6 @@ function WebGLShadowMap( renderer, objects, capabilities ) {
shadow.map.depthTexture.name = light.name + '.shadowMap';
shadow.map.depthTexture.format = DepthFormat;

const reversedDepthBuffer = renderer.state.buffers.depth.getReversed();

if ( this.type === PCFShadowMap ) {

shadow.map.depthTexture.compareFunction = reversedDepthBuffer ? GreaterEqualCompare : LessEqualCompare;
Expand Down