-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Improved Lambert shadowmaps + Hemisphere light #15557
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
Improved Lambert shadowmaps + Hemisphere light #15557
Conversation
|
Nice! Do you mind removing the builds from the PR though? |
| vLightFront = vec3( 0.0 ); | ||
| #if defined (USE_SHADOWMAP) && NUM_HEMI_LIGHTS > 0 |
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.
There is no need to condition on the presence of shadows. Keep it simple:
vLightFront = vec3( 0.0 );
vIndirectFront = vec3( 0.0 );
#ifdef DOUBLE_SIDED
vLightBack = vec3( 0.0 );
vIndirectBack = vec3( 0.0 );
#endifThere 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 like calling the light indirect rather than ambient.
As for the conditions, it's to prevent most uses of Lambert from doing the extra varying color, and also to prevent adding the light colors in the fragment shader. You're sure the simplicity trumps the small performance difference? I'm keen to agree, but just want to make sure.
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.
We can optimize for performance later if there is a performance issue. I doubt there will be.
| for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) { | ||
| vLightFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry ); | ||
| #ifdef USE_SHADOWMAP |
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.
No need to condition on shadows
for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {
vIndirectFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );
#ifdef DOUBLE_SIDED
vIndirectBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );
#endif
}| #define LAMBERT | ||
| varying vec3 vLightFront; | ||
| #if defined(USE_SHADOWMAP) && NUM_HEMI_LIGHTS > 0 |
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.
You can remove the conditional.
| // accumulation | ||
| reflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor ); | ||
| #if defined(USE_SHADOWMAP) && NUM_HEMI_LIGHTS > 0 |
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.
Something like this:
// accumulation
reflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor );
#include <lightmap_fragment>
#ifdef DOUBLE_SIDED
reflectedLight.indirectDiffuse += ( gl_FrontFacing ) ? vIndirectFront : vIndirectBack;
reflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;
#else
reflectedLight.indirectDiffuse += vIndirectFront;
reflectedLight.directDiffuse = vLightFront;
#endif
reflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );
reflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();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 just want to clarify that the reason for the shadow and hemisphere light check are because its only when we use these features together that we need to move the final light color calculation to the fragment shader. Otherwise it's fine to precalculate the final light color entirely in the vertex shader. Let me know if you'd prefer the simplicity wins over the small performance save and I'll submit a simplified commit.
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 prefer to model the lighting correctly, and keep indirect separate from direct.
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.
Ok cool, I'll have the modified PR ready tomorrow morning. Thanks!
|
@bunnybones1 Thanks for this. You are correct, this needs to be fixed, but the basic lighting equations should not be changed just because shadows are present. See #15530 (comment). Please see if my suggestions look correct to you. |
…black when using hemispherical light
6a01cf2 to
bdf5fc2
Compare
Done! I'll remove the conditions as @WestLangley suggested and we should be good to go. |
|
Should be good to go! |
|
Thanks! |
I changed the indirect lighting on the Lambert material so that shadows aren't pitch black when using hemispherical light. I accomplished this with an extra varying for ambient light, but only if using shadows and a hemisphere light. Supports double-sided materials.

Fixes #15530.