# Using static lightmap from texture

**URL:** <https://forum.castle-engine.io/t/using-static-lightmap-from-texture/917>\
**Category:** 3D\
**Created:** [October 2, 2023, 7:40am UTC](https://forum.castle-engine.io/t/using-static-lightmap-from-texture/917 "2023-10-02T07:40:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Recongalina](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/recongalina/32/1530_2.png) [@Recongalina](https://forum.castle-engine.io/u/Recongalina)\
**Post date:** [October 2, 2023, 7:40am UTC](https://forum.castle-engine.io/t/using-static-lightmap-from-texture/917/1 "2023-10-02T07:40:28Z")

</div>

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:

 ![all](https://forum.castle-engine.io/uploads/default/original/2X/7/78b489043ad8e2550a5208d1db9b42a0ae6e0567.jpeg)

---

<div class="post-metadata">

**Author:** ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)\
**Post date:** [October 9, 2023, 1:15pm UTC](https://forum.castle-engine.io/t/using-static-lightmap-from-texture/917/2 "2023-10-09T13:15:24Z")

</div>

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](https://castle-engine.io/darkest_before_dawn.php) , 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](https://castle-engine.io/blender) , with the answer to this exact question 🙂 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 🙂

---

<div class="post-metadata">

**Author:** ![Recongalina](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/recongalina/32/1530_2.png) [@Recongalina](https://forum.castle-engine.io/u/Recongalina)\
**Post date:** [July 24, 2024, 1:19pm UTC](https://forum.castle-engine.io/t/using-static-lightmap-from-texture/917/3 "2024-07-24T13:19:41Z")

</div>

Hello!  
Any news about the topic?

---

<div class="post-metadata">

**Author:** ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)\
**Post date:** [July 29, 2024, 1:50am UTC](https://forum.castle-engine.io/t/using-static-lightmap-from-texture/917/4 "2024-07-29T01:50:53Z")

</div>

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](https://castle-engine.io/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](https://github.com/castle-engine/demo-models/tree/master/blender/baking_lighting).

Tested and rocks with latest Blender 4.2 🙂

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

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.

---

<div class="post-metadata">

**Author:** ![Recongalina](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/recongalina/32/1530_2.png) [@Recongalina](https://forum.castle-engine.io/u/Recongalina)\
**Post date:** [August 16, 2024, 2:25pm UTC](https://forum.castle-engine.io/t/using-static-lightmap-from-texture/917/5 "2024-08-16T14:25:52Z")

</div>

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.

 ![lightmap_test](https://forum.castle-engine.io/uploads/default/original/2X/a/a7afa2bd86491b4b96c162f942a2d7a90854d0e2.jpeg)

There is my test scene for researching this shadowing method:  
[lightmap\_test.zip](https://forum.castle-engine.io/uploads/short-url/4ZYc2BpXdaaDUWZZ73spz2A8sxQ.zip) (2.0 MB)

---

<div class="post-metadata">

**Author:** ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)\
**Post date:** [August 16, 2024, 3:16pm UTC](https://forum.castle-engine.io/t/using-static-lightmap-from-texture/917/6 "2024-08-16T15:16:09Z")

</div>

> [@Recongalina](#):
>
> 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.

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](https://castle-engine.io/blender#_baking_lighting) , 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).

---

<div class="post-metadata">

**Author:** ![Recongalina](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/recongalina/32/1530_2.png) [@Recongalina](https://forum.castle-engine.io/u/Recongalina)\
**Post date:** [August 16, 2024, 3:37pm UTC](https://forum.castle-engine.io/t/using-static-lightmap-from-texture/917/7 "2024-08-16T15:37:55Z")

</div>

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.
