Some tricks for rich and efficient static illumination

Hi,

I would like to share a small trick that may be useful to others. I needed light-rich rooms. The usual options were extra Babylon lights (you hit the per-material cap and per-frame shadow maps fall over past ~10) or an offline ray-traced bake (I covered that in an earlier YouTube video — it works, but it is slow to iterate and painful to maintain).

The alternative I use in OpenVGAL is to bake at startup. The rooms have static lights and no moving shadow casters, so this fits. Lights are “created” in the GLB as dummy meshes or named markers (position, orientation, cone, intensity). Each mesh needs a unique UV2 unwrap. At load, each “light” is accumulated into per-mesh lightmaps; shadows and a limited AO pass are baked the same way. After the bake, the room is drawn as albedo × lightmap. Lights in the GLB are markers, not Babylon lights. The baker treats each as a cone and accumulates it into the lightmap at load.

The GPU trick is that the bake vertex shader rasterizes the mesh in UV2 space (gl_Position = vec4(uv2 * 2 - 1, 0, 1)), so the fragment shader runs once per lightmap texel. One additive pass per light means there is no Babylon light-count ceiling. I have rooms with more than 50 lights; a bake is a few seconds. It runs fine on old non-gaming GPUs. Memory scales with lightmap resolution — lighting is soft, so you often do not need huge maps.

Playground (stripped demo of the idea, not the full pipeline)

This is a very specific application but maybe there is still some appetite for load time baking as a Babylon feature.

7 Likes