Skip to content
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

Respect physicallyCorrectLights on lightmaps in MeshBasicMaterial #23197

Closed
Closed
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
13 changes: 11 additions & 2 deletions src/renderers/shaders/ShaderLib/meshbasic.glsl.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,17 @@ void main() {
// accumulation (baked indirect lighting only)
#ifdef USE_LIGHTMAP

vec4 lightMapTexel= texture2D( lightMap, vUv2 );
reflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity;
vec4 lightMapTexel = texture2D( lightMap, vUv2 );
vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;

// Lightmaps are the only source of "light" for basic materials, respect them being "phsyically correct"
#ifdef PHYSICALLY_CORRECT_LIGHTS
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that in lightmap_fragment.glsl.js we have the inverse behavior, multiplying the value by PI if PHYSICALLY_CORRECT_LIGHTS is not defined. This is to cancel out the effect of BRDF_Lambert(diffuseColor) which is applied by default in most other materials (which multiplies the diffuseColro by RECIPROCAL_PI). MeshBasicMaterial does not apply BRDF_Lambert to the diffuseColor so we need to do the inverse for the lightmap to be "physically correct"

We probably do not want to change how a MeshBasicMaterial with no lightmap behaves so we instead apply this here, only to lightmaps, and only when PHYSICALLY_CORRECT_LIGHTS is defined. We could change the surrounding code a bit such that we could #include <lightmpmap_fragment> unchanged but it would slightly complicate the common case of a MeshBasicMaterial with no lightmap.


lightMapIrradiance *= RECIPROCAL_PI;

#endif

reflectedLight.indirectDiffuse += lightMapIrradiance;

#else

Expand Down