PBR and LightMap is not visible

Hello everyone,

When using a lightmap in the PBRLighting shader, it does not appear until the Metallic factor is set to 1.

So, it’s not possible to add LightMap textures on non-metallic objects

Is there a notion that I do not understand or is it a problem in the shader?

Thank you

lightmapProb01

lightmapProb02

mhh… I’ll check this.

First of all, hello and happy new year 2018 !!!. :wink:

I looked at the PbrLighting fragment a bit.

I note this:

 #ifdef LIGHTMAP
       vec3 lightMapColor;
       #ifdef SEPARATE_TEXCOORD
          lightMapColor = texture2D(m_LightMap, texCoord2).rgb;
       #else
          lightMapColor = texture2D(m_LightMap, texCoord).rgb;
       #endif
       #ifdef AO_MAP
         lightMapColor.gb = lightMapColor.rr;
       #endif
       specularColor.rgb *= lightMapColor;
       albedo.rgb  *= lightMapColor;   <-- albedo variable modified
    #endif

    gl_FragColor.rgb = vec3(0.0);     <--  gl_FragColor at 0

the variable albedo.rgb is updated with the color of the LightMap but seems never to be used again

By modifying this:

gl_FragColor.rgb = vec3 (0.0);

by

 gl_FragColor.rgb = albedo.rgb;

This gives a better result, the lightmap is visible even on a material with a Metalliic factor at 0.

I’m not a specialist shaders, I do not know much, I do not know if this change has repercussions on the behavior of the shader. But the first tests seem good. We should continue to test

I have to dig more into this, but indeed the light map is not applied correctly.

And no, gl_FragColor.rgb has to be initialized with 0, because light information will be accumulated in it later. Initializing it with the albedo is wrong.
I’ll look into it.

I don’t have a good test case at hand, could you try to replace this line

albedo.rgb  *= lightMapColor;  

with

diffuseColor.rgb  *= lightMapColor;  

From a newb bystander… why have an albedo variable if it isn’t used? Or is it only used earlier and the lightmap stuff is in the wrong place?

This gives a good result. The shadow is present.

Another question, I had found that already with the shader Lighting. When a light (spotlight) illuminates a shadow of a lightmap,
in reality, the light should illuminate the area in the shade and the color of the texture should be visible.

This was not the case in the Lighting shader.

In this case (PbrLighting), the spot light illuminates the area in the shade but it is still relatively dark.

It’s used earlier and yes the lightmap does not applied to the correct variable.

This is a drawback of the way we render shadows. There is no way around it for now.

ok

Wait I read you wrong.
You mean with the lightmap?

yes with the lightmap

Well… technically a light map should be considered as another light source and it’s contribution should be added to the final color.
Only if it’s meant as an ao map it should be multiplied.

1 Like

I pushed a fix, could you test please?

It seems to work. There is a difference with activation of AO_MAP. or not.

But I want to show you something.

When the texture is useful as LightMap here is what it gives with a lightspot on it:

The static shadow is lit but there is still a slightly dark area

When the texture is used as an AOMAP, here’s what it gives with a lightspot on it:

here the lightspot does not illuminate the shadow zone.

Where does the problem come from?

Thank you

It’ son purpose, AO is supposed to darken lighting.
Here you have a lightmap, so don’t use it as an AO map.
Though maybe AO should only apply on indirect lighting…

As for the first video, it’s how it’s supposed to be, it’s not the shadowed area that is darker it’s actually the lighten area that is brighter.

Ok, I understand better.

Thanks for the changes made to the shader

Great, it works well,
the shadow of the lightmap disappears now with direct light. :wink:

1 Like