Lightmaps How they behave in sandbox.babylonjs?

Hi there,

I am not sure whether what i am getting here when i link Lightmaps is correct or not??
Help me out understanding better:

here is what i got

  1. So in the images uploaded here:
    without linking any lightmap the original texture is shown and when i apply Lightmaps there is a whiteness in the places shown which i feel like improper… :smirk:
    when i apply lightmap with use maps as shadowmaps the other area is darkened … my question is that is what happens when we apply light maps??

  2. and here is the lightmap file which is generated from Maya (using Render to Texture tool)

Is this is the correct map which i got from Maya?? and

  1. This lightmap file format is .PNG … is this a correct format to be used for Lightmaps. Or is there any specific format should be used for Lightmaps?

Pinging @PatrickRyan

@AD_Kar, it looks like your render is the issue here. From what I see in your render, it looks like what you want is a shadowmap rather than a light map, but the problem is that your render has grey tone in areas that aren’t in shadow. This is why your screen capture looks dark. You need to balance your lighting in the Babylon scene with the shadow that will be multiplied over the scene, so that needs to be done in the render. To illustrate, I did a quick example with one of our assets:

The setup is a simple directional light in scene with the assets. Rather than go to the extent of creating a UV set for the lightmap the correct way, I just reused the texture UVs to bake the light map. In this asset, that’s not the right way as I am overlapping some UVs to increase texel density, but the process is the same outside the UV step. If I were to just Render Selection to Texture like this, I would get the shadows baked into the diffuse texture, which isn’t what we want. Instead, I created a new material to render only shadows. Note that when I rendered each element’s shadow map, I only set the material of the mesh I was rendering to white to get realistic bounce light from the other assets around it.

image

This is a simple dielectric material with a high roughness value to spread any specular reflections. I then exported the render to texture which will export an exr file which is a 32-bit file. Opening this in an image editor, you will need to convert back to an 8-bit image before saving as a png, which is a fine format for this texture. This conversion is important because it needs to tonemap the values from 32-bit back to 8-bit and choosing the right tone mapping is key. In my case, I used an exposure and gamma conversion to keep the tones in the image close to what I would expect from the shadows in the scene.

As you can see there are some areas in front of the bench on the ground where there is some reflected light in the shadow map that is rendering as white. To get this bounce light in the scene, the ground outside this reflection needs to be slightly darker, but I am careful to make sure that the overall tone on the ground isn’t too dark or it will just feel like the whole scene is in shadow which will feel wrong if the light is streaming in a window. This is a comparison of the mesh with shadowmaps to the same mesh without shadowmaps:

You can see that the ground with the shadow maps is slightly darker than the original without a shadowmap, but the reflections on the ground in front of the bench where the concrete leg meets the ground adds a nice grounding effect of bounced light so you need to make sure you keep it in the shadow map.

Lastly, you will want to balance the lighting in the shadow map with your scene lighting. You can see with this next image I changed the IBL in the scene and it is having an effect in the shadow map where the direct light hitting the ground is lightening the shadow in that area slightly which is the benefit of a shadowmap. However, the lighting in the IBL doesn’t feel like it fits in the scene as the shadow implies there is a much stronger light casting the shadow than the back light which doesn’t cut the shadow. So it is good to match up your scene lighting and IBL with the lights you bake in the scene.

Hope this clarifies some of what you are seeing in your scene but feel free to ping me back if you have more questions.

7 Likes

Thank you so much for explaining so clearly. I am happy for the explanation.
So one one more clarification is Light Map is always used as Shadow-map compulsory???

I am actually looking for Light Maps only… Could you show me one more example like what you explained above where Light Maps are used as Light Maps only but not as shadow-maps. And how to generate those light-maps …??? and how do they look like??