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

Conversation

netpro2k
Copy link

@netpro2k netpro2k commented Jan 11, 2022

Related issue: #21912

Description

MeshBasicMaterial allows the use of lightmaps but these lightmaps do not respect the physicallyCorrectLights renderer setting. This makes it difficult to combine MeshBasicMaterial with MeshStandardMaterial in the same scene.

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.

@mrdoob
Copy link
Owner

mrdoob commented Jan 12, 2022

@WestLangley Looks good to you?

@mrdoob mrdoob added this to the r137 milestone Jan 12, 2022
@WestLangley
Copy link
Collaborator

I'd like to think about this...

I was the one that re-added MeshBasicMaterial support for light maps. #22393 In hindsight, I wish I hadn't.

Subsequent to that PR, so-called "physically-correct" lights were added, which added a further complication.

@netpro2k Just asking, but is AOMap, lightMap support important to you in this case? Does it make sense to consider removing it, or will that cause a backlash?

//

On a related note, I had hoped to get the factor of PI out of the shaders. MeshBasicMaterial is, in fact, the stumbling block. See #22397.

I would like to see this logic moved out of the shaders and into the renderer.

@netpro2k
Copy link
Author

is AOMap, lightMap support important to you in this case

In Hubs we "gracefully degrade" all models down to MeshBasicMaterial on mobile clients. Since these materials start out as MeshStandardMaterials they often have lightmaps+AOMaps, so things look much better if we also include those on mobile. We already extend MeshBasicMaterial in Hubs to add support for emissiveMap for similar reasons, so I don't have super strong opinions on if it remains in core (we can easily just add them back to our custom material), but I would imagine others might find it useful for the same reasons we do. Maybe there should be something like a MeshIBLMaterial that has no realtime lighting but has lightmap+ao+emissive+PMREM. (basically what is being discussed in #21578)

Solong as lightMap does exist though I think it should be applied consistently across materials.

@netpro2k
Copy link
Author

Also note, as per the discussion in #21912 in Hubs we are likely going to effectively be removing the effect physicallyCorrectLights has on lightmaps (sort of negating this patch, but also applying an inverse patch to MeshStandardMaterial), since what we are getting out of Blender (our primary workflow for lightmpapping) already seems to have PI factored out, so artists end up having to set their lightmapIntensity to PI to compensate.

@WestLangley
Copy link
Collaborator

WestLangley commented Jan 13, 2022

we are likely going to effectively be removing the effect physicallyCorrectLights has on lightmaps (sort of negating this patch...)

That means you are going to negate this PR in your own fork if were to be merged?

@WestLangley
Copy link
Collaborator

@mrdoob Just to review...

  1. MeshBasicMaterial does not respond to AmbientLight, HemisphereLight , or LightProbe -- all ambient indirect light sources -- but it does respond to LightMap, which represents ... ambient light...

  2. MeshBasicMaterial supports AOMap, which occludes ambient light -- the very light the material does not support....

This was all done to be backwards-compatible with the earliest versions of three.js.

MeshBasicMaterial also supports environment maps, but not emissive maps.

There is nothing "physically correct" here.

//

@netpro2k I am open to making a change -- maybe even this PR or something similar.

Unfortunately, AFAIK, no blender dev has articulated what the exported "light maps" represent -- or their units. I doubt the exported maps are compatible with the three.js light map model. I certainly would not recommend a change in three.js to accommodate blender at this point.

@mrdoob
Copy link
Owner

mrdoob commented Jan 14, 2022

@WestLangley

I would like to see this logic moved out of the shaders and into the renderer.

That sounds good. Should we create a new Issue to tackle this?

@mrdoob
Copy link
Owner

mrdoob commented Jan 14, 2022

@WestLangley

MeshBasicMaterial also supports environment maps, but not emissive maps.

I wouldn't mind adding emissive maps to MeshBasicMaterial actually. I can see them being pretty useful and easy to add/maintain.

@memelotsqui
Copy link

Hi!, as a personal opinion, I believe lightmaps should work the same way as they work right now with non physically correct lights.

(Please correct me if Im wrong in something, this is based on personal toughts :) ). Since lightmaps are prebaked, physical correct lighting shouldnt be affecting the lightmap texture, they should be affecting the result of the combined lightmap with diffuse color (that is after multiplying by PI). Not having the lightmap multiplied by PI leads to a darker lightmap (this is happening to me too).

Im using right now a Unity to three js exporter that supports lightmaps, and this is the difference when using physical correct lightmap vs non physical correct lightmap, as you mentioned, everything looks darker, until you multiply it by PI

Non physical correct lighting - standard material
Web_secene_1

Physical correct lighting - standard material
Web_scene_2

Unity Scene:
Unity_Scene

The fix would be to always multiply the lightMapIrradiance by PI regardless of if physicallyCorrectLights is enabled or not, correct?

I would actually prefer this solution from #21912, rather than dividing meshBasicMaterial by PI, but either way it should have consistency to avoid differences between Mesh Standard Material and Mesh Basic Material :)

@mrdoob mrdoob modified the milestones: r137, r138 Jan 26, 2022
@mrdoob mrdoob modified the milestones: r138, r139 Feb 23, 2022
@mrdoob mrdoob closed this Mar 1, 2022
@mrdoob mrdoob removed this from the r139 milestone Mar 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants