Lightmap not working

Hello, I’m new to BabylonJS.

I can’t get lightmapping to work. I exported my glb from Blender 2.92, the model has two materials applied to the faces. Each have their own texture, one of them has a mapping so it’s repeating. I used the background node for the materials, which is supposed to make them unlit however I’m a little unsure about all that since there seems to be multiple ways of doing it and the gltf-examples from the official repo uses an emission node setup for unlit materials.

The export materials are setup like this for my model:

My model has two UV sets. The lightmap should use the second one.

Hope someone can help me out here :slight_smile:

adding our Blender wizard @PirateJC

Hey @martin - Welcome to the Babylon Family! It’s great to have you here!

How are you exporting to .glb from Blender? Is it using the built in exporter?

I’m pretty positive that the built-in exporter only supports PrincipledBSDF materials. From what I can tell in the images, it looks like you’re using other materials including the mix shader, which I’m fairly sure does not export using the built in exporter.

There is also a community maintained Babylon.js exporter for Blender that you can check out. It’s maintained by @JCPalmer who can likely provide some more info on what types of materials it supports in Blender.

You can find info about the Babylon.js exporter here: Blender to Babylon.js exporter | Babylon.js Documentation

Hi @JCPalmer , any insight on this one?

This seems to be working. I’m trying to multiply the lightmap with my unlit material. The lightmap is in srgb color space btw.

I have never done anything with material.lightmapTexture, which includes the exporting of it. I think that way you are baking it yourself, and load / assigning at run time is the best approach.

The exporter I work with does bake when there is no direct translation possible. Am pretty sure the GLB exporter does the same, though I do direct, single Blender => BJS translation, while theirs is a double translation of Blender => GLB, GLB => BJS.

While baking during export is convenient for let’s say evaluating something you got off of Blendswap to decide if it is worth using, there are several limitations:

  • Blender can only bake the whole mesh, not different materials in a mult-imaterial mesh.
  • That combined with metal & roughness & other stuff cannot be baked in Cycles, means with one material per mesh there has to be a common setting for these at the sub-material level.
  • Multiple uses of the same material need to be baked multiple times, since there is no guarantee the meshes have identical geometry resulting in identical UV, nor are both necessarily the only material of those meshes.
  • Blender has a hard time when one of the materials of a multi-material mesh of a mesh contains alpha, like a character with an eye brow texture. Order of baking is not something that is controllable in Blender, unless you do it in steps yourself.

For things like Base Color / Normals, once you bake it yourself, you could just then hook it up in Blender and let the exporter to the work. Not sure the double translation of light maps exists for GLB though.

1 Like

Okay so I got lightmapping to at least work last time, now I’m trying to get it to work with vertex colors thrown in as well but got stuck again.

The wall of the cube has a material assigned with an image texture, then the other two walls has a material with vertex color but that turns out white instead of red no matter if the lightmap is assigned or not.

This is how the vertex color material is set up, I tried getting it to work in the non-repeating second material slot too in order to limit the number of materials with no luck.

Also, do I end up with actual multiple copies of the same mesh when I assign different materials to individual face selections during export in Blender @JCPalmer? I’m new to BabylonJS so I don’t follow too well what you described in your post. Anyhow if it will impact performance, can/should I use multi-material/MergeMeshes or some other solution in BabylonJS?

1 Like