Is "IBL Texture Tool" .HDR to .env conversion code part of Babylon.js?

What is the current up-to-date way to convert .hdr environment files to .env within a project?

Documentation is pointing to “IBL Texture Tool” ( which does the job nicely, but if intention is to integrate .hdr → .env conversion as part of a project what is the recommended way?

IBL Texture Tool repository ( has last been updated for Babylon.js 4.2.0. So while I suppose that code should run without issues on latest babylonjs versions, I was wondering if that conversion code has been already added within the main Babylon.js repository and is hidden somewhere as a utility function? Or is migrating the implementation from the texture tool repository the way to go?

Yeah, I already linked to that one. The topic was about finding up to date code to do the conversion, not external website. :slight_smile:

You can use the HDRFiltering class to convert a normal cube map to a pre-filtered cube map, and then use BABYLON.EnvironmentTextureTools.CreateEnvTextureAsync to create an .env file (in effect, this gives you a buffer array with data that you can save to a file).

Hmm… I think I almost got it working but something is still wrong. Here is a Playground I have been testing with: Babylon.js Playground

Problem comes when comparing the .env file generated with IBL Texture Tool (“if (0)” condition in the Playground) and CreateEnvTextureAsync() latter has incorrect colors.

IBL Texture Tool:


See how the specular highlight incorrectly is yellow in the converted version. :grimacing:

Hmm… Maybe it is a bug in prefiltering code? It seems to also happen when using HDRCubeTexture directly with prefiltering:

Hmm… Actually, it seems to be about CubeTexture resolution while calculating prefiltering. 512 looks good.

So I guess the solution is to generate the prefiltering on 512 cube texture and then somehow downscale the size to desired target resolution (128) while keeping prefiltering results from the higher resolution. This is getting complicated. :face_with_spiral_eyes:

Or maybe just load the hdr with both resolutions and then transfer prefiltering to the lower resolution. Although that doesn’t sound optimal either, if even possible…

EDIT: It is starting to look like replicating the code from BabylonjsTextureTools repository is the only way to go. Otherwise there doesn’t seem to be a way to generate lower resolution .env file correctly.

Let’s ask @sebavan who is the creator of the IBL texture tool.

The uptodate way is the sandbox or the inspector :slight_smile:

I will update the tool tonight for 6.0

The resolution is impacting color, due to interpolations.

Yes indeed, the lights are too small to be properly sampled from lower resolution image. When low resolution cubemap is generated from .hdr either the pixel sample misses and you end up with too dim light (which changes color like in the case above), or it hits the light and the light becomes too large / strong.

I already concluded that the only way to accurately generate low resolution .env files is using the approach from the BabylonjsTextureTools repository where it samples higher resolution (512) cube map into the final downscaled one (256 in the current implementation but 128 also works really well and is only 200-250kb per .env file).

EDIT: Or well, other way would be to supersample the original HDR image during HDRCubeTexture(), but that would likely be harder to implement. :slight_smile:

I actually went ahead and created a Draft Pull Request for option to supersample HDRCubeTexture(): Add possibility to set number of samples for HDRCubeTexture() by MiikaH · Pull Request #13766 · BabylonJS/Babylon.js · GitHub

To my surprise it not only works, but the result matches the reference 128 resolution .env file generated with BabylonjsTextureTools exactly. So with 4 samples in place in the Playground example in the PR description:

  • Specular colors are correct
  • Environment itself that is rendered in the background (but also in reflections if looked closer) is way less blocky and closer to the higher resolution source because of that
1 Like