Proper lightmap workflow and formats

Our RGBD support is pretty custom (including some quantization helper functions) and not a standard but we figured it was faster and smaller footprint than embedding an EXR loader or Downloading HDR files.

It is normally exclusively an internal trick to create .env textures.

We allowed the use of them within lightmaps due to the restricted size for the same reasons than the env files.

@Evgeni_Popov playground is the way to go to convert.

About the lightmap usage it would allow values bigger than one which are only possible normally with lightmapTexture.level but this could lead to banding artifacts.

Do you know how I could automatically convert from HDR to RGBD format? Going through that playground is quite tedious process.

@zylkowski, I am not aware of any in-tool path to export to an RGBD channel format in any of the DCC tools we use. As @sebavan mentioned, we use that format to reduce on size for high dynamic range images, but most of the DCC tools will go as far as .hdr or .exr formats for high dynamic range files and not use this optimization. For one, the optimization is not exact as for RGBD you will need to set an upper range for the value so that RGBD can be used. The formats baked by the standard DCC tools will just use float values to represent an exact value of light, but that comes at the cost of a very large file. The playground that @Evgeni_Popov linked is a shortcut tool to convert for us. Much like being able to drop an .hdr on the sandbox and then save out an .env file for use as an environment.

I would love to see us natively support .hdr and .exr formats, but those files are normally quite large in terms of displaying for the web. The formats themselves, .exr especially, are large with a lot of features to support so we have always opted not to tackle it with the resources available to us. I know this isn’t the answer you are looking for, but in every art pipeline there are things we need to do that the tooling is not equipped for. It may be that writing a stand-alone automation for Blender to convert to the format may be in your best interest if this is something that you do a lot.

1 Like

Thank you very much for such an answer. I am very much interested in writing such tool for HDR → RGBD in python and even making it available for everyone. In order to do so though I need a few details that are not so easy to get just by going through the code on babylon’s github. I have a few questions answers to which would help me tremendously in this task.

I found this piece of code for RGBD transformation.
What exactly is vec3 color there? Is it Linear or sRGB color? Is it clamped 0 to 1, 0 to 255 or 0 to float32::max?

Answers to these questions would help me a lot in creating Blender script that outputs RGBD lightmap automatically.

1 Like

The pixel value as read from the texture in linear space (as it is an hdr value from 0 to max, 1 being white or 255 in 8 bits color equivalent).

I’m really sorry for being picky here. By max you mean float32::max?

Not sure if this is much help, but I struggled with some of the same RGBD issues a while back when I made my blender lightmapper addon. There’s both CPU and GPU based encoding, but if I remember correctly the GPU one might be broken, so the CPU one is your safe bet: The_Lightmapper/addon/utility/encoding.py at e77b078d3b3c9417de442c1a3dd6530095596772 · Naxela/The_Lightmapper · GitHub

If everything else fails, using HDR files with a little RGBE encoding header should work just fine and it shouldn’t be too heavy as long as your scene assets are atlas packed properly to keep the texel density somewhat consistent: https://playground.babylonjs.com/#5KVL6P#8

3 Likes

Oh man, I love this response. You just saved me so much time of experimenting with different formats etc. Thank you very very much!

1 Like

Hey I just tried the solution with HDR files as you linked https://playground.babylonjs.com/#5KVL6P#8
My HDR files do not work, do you have any tips? I think I might be missing " little RGBE encoding header" but I am not exactly sure.

Hi, do you get any error messages? (F12 > Console?)

If you’re missing the rgbe header, you can just copy/paste the first 25 lines of code. Apart from that it should usually work just fine

You can see here: https://playground.babylonjs.com/#5KVL6P#31
It’s your playground with only thing changed to my hdr texture. You can see that it’s checkered texture as if it was not loaded properly.

I must admit, I’m not really sure what was wrong with the HDR texture you used or why BabylonJS wouldn’t load it. In this example, I downloaded your texture, opened it up in Affinity (Blender also works just fine), resaved as 32-bit HDR and it seems to work just fine?: Lightmap Test | Babylon.js Playground (babylonjs.com)

Okay, the problem is on my side then. Thank you very much for checking.

how do you do this? glb doesnt support lightmap exports by default? I know about exporting AO maps in a glb from blender using a custom node , is there some similar setup for doing lightmaps then?