-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CSM: Directional light without a shadow breaks shaders #23631
Conversation
Solution: directional lights without shadows need a dedicated loop, the shadow casting loop traverses only until |
examples/webgl_shadowmap_csm.html
Outdated
@@ -97,6 +97,10 @@ | |||
const ambientLight = new THREE.AmbientLight( 0xffffff, 0.5 ); | |||
scene.add( ambientLight ); | |||
|
|||
const additionalDirectionalLight = new THREE.DirectionalLight( 0x000020, 0.5 ); | |||
additionalDirectionalLight.position.set( params.lightX, params.lightY, params.lightZ ).normalize().multiplyScalar( - 200 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Indentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed.
3dd4d64
to
2fd0a03
Compare
@gkjohnson Do you mind double checking this PR? |
I'll take a deeper look in a bit but in the meantime here's a link for testing: https://raw.githack.com/OndrejSpanel/three.js/csm-additional-light/examples/webgl_shadowmap_csm.html |
examples/jsm/csm/CSMShader.js
Outdated
#if ( NUM_DIR_LIGHTS > NUM_DIR_LIGHT_SHADOWS) | ||
// compute the lights not casting shadows (if any) | ||
|
||
#pragma unroll_loop_start | ||
for ( int i = NUM_DIR_LIGHT_SHADOWS; i < NUM_DIR_LIGHTS; i ++ ) { | ||
|
||
directionalLight = directionalLights[ i ]; | ||
|
||
getDirectionalLightInfo( directionalLight, geometry, directLight ); | ||
|
||
RE_Direct( directLight, geometry, material, reflectedLight ); | ||
|
||
} | ||
#pragma unroll_loop_end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation looks a little wonky here but other than that it looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can fix that. Normally automated check catches this (caused by different Tab / Space settings in my editor), but not inside of string literals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed now.
2fd0a03
to
2180434
Compare
2180434
to
16f0f71
Compare
Thanks! |
* Demonstrate issue - directional light without a shadow breaks shaders * Fix: light not casting shadows need to be processed separately in the CSM shader
I'm a bit late to this, but it seems that after the changes in this PR, the CSM directional lights are no longer calculated at all when shadow maps are disabled ( I've modified the CSM example to add a toggle for shadow maps, so you can compare the result before this PR and after. Previously, turning shadow maps on or off didn't affect the lighting in the scene, only the shadows themselves. Now the whole scene becomes noticeably darker when shadow maps are turned off. |
float dist = min( linearDepth - csmx, csmy - linearDepth ); | ||
float ratio = clamp( dist / margin, 0.0, 1.0 ); | ||
if( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS ) { | ||
#if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Evaluating USE_SHADOWMAP
at this place is redundant since there is a #if defined( USE_SHADOWMAP )
in line 79 that already checks it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be fair this one is easy to miss since the code isn't properly formatted. There should be an indentation right after the check in line 79.
Sidenote: In recent version of CSMShader
the line numbers have changed a bit. The issue is still present though.
When you add another directional light without a shadow into the CSM example. it breaks, shaders no longer compile and example does not display any objects.
Solution being prepared, stay tuned.