Using static lightmap from texture

Hello everyone!
Please help me understand.
How to load a 3D model with a static lightmap from the Blender?

I found this solution https://blenderartists.org/t/newbie-how-to-export-lightmap-for-gltf-2-0/1335887/7
But result looks very strange:

Sorry for delay in answering, I have this in my TODO.

We used lights backing with CGE in “Darkest Before the Dawn”, Darkest Before the Dawn | Castle Game Engine , that was an old mobile game targeting really old Android devices, and 100% of the light was just baked into textures in Blender. The game still can be compiled and works, though I want to refresh it, and show how to use light baking in CGE using latest Blender + glTF.

So,

  1. yes, it absolutely should be possible (from CGE point of view, baked lights just mean we have a texture with them, and glTF should allow you to export it),
  2. I want to refresh our sample of it, and then update Blender | Creating Game Data | Castle Game Engine , with the answer to this exact question :slight_smile: To make the workflow “how to bake lights from Blender and use it with CGE” known.

I’ll post here when I’ve done it :slight_smile:

Hello!
Any news about the topic?

Sorry for delay!

I have tested today the whole lights baking procedure, and documented how to do it in the new big section “Baking Lighting” in our Blender docs page. There’s a detailed text and screenshots. It is accompanied by example model with textures in demo models subdirectory blender/baking_lighting.

Tested and rocks with latest Blender 4.2 :slight_smile:

I hope this is helpful. If you have any questions about it, go ahead and ask :slight_smile:

Note that I could not reproduce the issue you have shown in the first post in this thread, where the view in editor was missing the textures. This is strange, as rendering of Castle Model Viewer (formerly view3dscene) and editor should generally be equal, though naturally you can adjust in editor various things differently in RenderOptions, setup lights differently etc. Anyhow, if you still experience this difference, please submit all the files (glTF, textures, CGE project) for me to reproduce the problem and investigate.

I understood my mistake. I’m accustomed to paradigm of old game engines, such as Irrlicht, Quake 3, etc. with a light map that replaces lighting.
There’s another logic here. There is BaseTexture, MetallicRoughnessTexture and OcclusionTexture. And each of them can have its own UV coordinates, as I understand it. OcclusionTexture can be used as an analog of a light map and, moreover. And it can
be combines with light sources. This method can allow make pretty good looking shadows in static scenes.

There is my test scene for researching this shadowing method:
lightmap_test.zip (2.0 MB)

Happy that my explanation helped, and indeed – you have more flexibility here, the baked texture can be placed in any slot (like BaseTexture) and thus the result be affected by more lights (e.g. dynamic lights, that blink and/or move at runtime, so you would not want to bake them).

To be clear, the approach “a light map that replaces lighting” is also possible here, it’s just a special case. To get this effect, use the “Background” shader in Blender (this is called “unlit”, internally TUnlitMaterialNode, in Castle Game Engine / glTF / X3D terminology). Instead of the default “Principled BSDF” shader in Blender (called “physical material”, internally TPhysicalMaterialNode, , in Castle Game Engine / glTF / X3D terminology). IOW, using “Background” shader in Blender means that lighting will be ignored when we display it in CGE.

I mentioned this briefly at Blender | Creating Game Data | Castle Game Engine , see

If you don’t want any other lights than what you baked, then you can make the new material unlit (that is, use “Background” shader in Blender). If you want to add other lights, then keep the material physical (called “Principled BSDF” in Blender), just assign the baked texture to the “Base Color” (this is not really correct, since your baked texture is now a combination of base color + some lighting, but it may look reasonable in some cases).

Thanks. Yes, I understood the method described in Your guide. But I like method when BaseTexture can use repeating hi-res textures, and light map can be low-res. And both of these textures have different UV coordinates.

1 Like