Material.twoSidedLighting not working for environment lights / texture(hdr)?

Hey folks,

I know on material there is a function twoSidedLighting(). Looks it not working for all light types right? For example, it works directional lights but not environment (hdr) lights, etc.

Is there a solution making twoSidedLighting() working for environment lights as well?

Many thanks,
Tawibox

Two sided lighting works by negating the normal if the current face is a back face. As the environment lighting reflect the view direction according to the normal, negating the normal does not change the result.

That’s because the formula for the reflection is: I - 2.0 * dot(N, I) * N.

If you negate N in the formula, you will see that you get the same result.

I’m not sure what two sided lighting should do?

@Evgeni_Popov Thanks for the response!

So what does you question mean here?

Are you asking what’s the use case for twoSidedLighting?

Many thanks,
Tawibox

No, I’m asking what you think two sided lighting should do in the case of environment lighting ((if I’ve understood correctly, you think the rendering should be different)?

@Evgeni_Popov

I found for some particular meshes, the two sided lighting with environment textures dont work well.

You can check this PG out:

In the PG, the entire shirt is a single sided mesh. The shirt collar is the back faces. The collar area reacts to the HDR textures wrongly (looks dark):

I’m just expecting both of the shirt and collar can be illuminated the same way by HDR textures. While with regular directional lights I don’t see the problem. (I disabled the direction light, you can turn it on to check out)

This does not happen when we force irradiance in fragment https://playground.babylonjs.com/#55DSAH#15

I ll have a look shortly it looks like a bug

@sebavan Oh cool! Thank you very much!

1 Like

@sebavan Thank you for this!

If I use un-fixed version of babylonjs, is it safe if I just turn on forceIrradianceInFragment for now? Or it has side effects on other things?

Nah it is all good

1 Like

@sebavan Yay!!! Thank you!!

One more quick question, is “twoSidedLighting” in general expensive to use?

Just wondering is it ok if I always keep it enabled? Or for better performance I should only enable it when there is a need.

It is not that expensive but adds extra shader instruction which are useless with back face culling for instance (this case is by the way optimized in the material) but in general I would only enable it if needed.

1 Like

@sebavan Gotcha. Thank you!!

1 Like