Lightmaps / Shadowmaps / Tiled Textures

Hello,

So I’m having a discussion about the possibility to bake only the lightmap / shadowmap on a separate texture from the tiled texture of the floor, so we can have a small sized texture to load.
I imagine that we can keep the tiled texture smaller on a separate channel, and on another channel to have just the lightmap texture. This will reduce the total size of the textures as the detailed tiled texture is smaller ( 256x256 ) and the lightmap texture will be 2k but only with greyscale pixel.
Unfortunately in all the examples I found on the forum, websites, videos, the lightmap contains the baked texture including the tiled texture, unwrapped.
Can somebody tell me if this can work, and how to do it using Blender or other tools to export a working gltf / glb?

cc @PatrickRyan

@theblackneko, you can certainly create a shadow map for a material using tiled textures utilizing a second UV set. You would have the tiled UVs in the first set and the unique unwrap in the second set which the shadow map is assigned to. In Babylon.js, you can assign light maps to PBRMaterial (which would be what you would have importing a glTF).

The way to assign the lightmap to be a shadow map is to set PBRMaterial.useLightmapAsShadowmap = true and then assign the UV set with PBRMaterial.lightmapTexture.coordinatesIndex = 1 which would set the texture to use the second UV set. All textures have the first UV set as coordinatesIndex[0] so the second UV set will be index 1.

The real issue here is that you ask to be able to pass a shadow map out of Blender into a glTF and as far as I know there is nothing in the spec or any extensions that enable lightmaps as part of the glTF format. @bghgary can correct me if I am wrong about this, but I looked through the spec and available extensions and I don’t see anything about lightmaps or baked lighting in glTF. I believe the preference is to let the engine handle the baking of lights for the transmission format since including that information in the glTF would limit how the asset could be used as it would no longer accurately adhere to the lighting of the scene it was imported to.

However, if you are looking for how to do this in Babylon, you simply need to create your tiling material in Blender as normal and add a second UV set to bake your shadows. Then export your glTF and export the shadow map as a stand alone texture. You then load the glTF and load the shadow texture separately and just append the shadow map texture to the PBRMaterial by setting:

PBRMaterial.lightmapTexture = myLoadedShadowTexture PBRMaterial.useLightmapAsShadowmap = true PBRMaterial.lightmapTexture.coordinatesIndex = 1

I hope this helps, but feel free to ping back if you have more questions.

2 Likes

Hey there just checking in, was your question answered? @theblackneko