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

**URL:** <https://forum.babylonjs.com/t/is-ibl-texture-tool-hdr-to-env-conversion-code-part-of-babylon-js/40031>\
**Category:** Questions\
**Created:** [April 20, 2023, 1:04pm UTC](https://forum.babylonjs.com/t/is-ibl-texture-tool-hdr-to-env-conversion-code-part-of-babylon-js/40031 "2023-04-20T13:04:26Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![MiikaH](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/miikah/32/23054_2.png) [@MiikaH](https://forum.babylonjs.com/u/MiikaH)\
**Post date:** [April 20, 2023, 1:04pm UTC](https://forum.babylonjs.com/t/is-ibl-texture-tool-hdr-to-env-conversion-code-part-of-babylon-js/40031/1 "2023-04-20T13:04:26Z")

</div>

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” ([https://doc.babylonjs.com/features/featuresDeepDive/materials/using/HDREnvironment#ibl-texture-tool](https://doc.babylonjs.com/features/featuresDeepDive/materials/using/HDREnvironment#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 ([https://github.com/sebavan/BabylonjsTextureTools](https://github.com/sebavan/BabylonjsTextureTools)) 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?

---

<div class="post-metadata">

**Author:** ![JCPalmer](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/jcpalmer/32/42_2.png) [@JCPalmer](https://forum.babylonjs.com/u/JCPalmer)\
**Post date:** [April 20, 2023, 1:16pm UTC](https://forum.babylonjs.com/t/is-ibl-texture-tool-hdr-to-env-conversion-code-part-of-babylon-js/40031/2 "2023-04-20T13:16:17Z")

</div>

[https://www.babylonjs.com/tools/ibl/](https://www.babylonjs.com/tools/ibl/)

---

<div class="post-metadata">

**Author:** ![MiikaH](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/miikah/32/23054_2.png) [@MiikaH](https://forum.babylonjs.com/u/MiikaH)\
**Post date:** [April 20, 2023, 2:30pm UTC](https://forum.babylonjs.com/t/is-ibl-texture-tool-hdr-to-env-conversion-code-part-of-babylon-js/40031/3 "2023-04-20T14:30:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [April 20, 2023, 2:48pm UTC](https://forum.babylonjs.com/t/is-ibl-texture-tool-hdr-to-env-conversion-code-part-of-babylon-js/40031/5 "2023-04-20T14:48:39Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![MiikaH](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/miikah/32/23054_2.png) [@MiikaH](https://forum.babylonjs.com/u/MiikaH)\
**Post date:** [April 20, 2023, 3:18pm UTC](https://forum.babylonjs.com/t/is-ibl-texture-tool-hdr-to-env-conversion-code-part-of-babylon-js/40031/6 "2023-04-20T15:18:41Z")

</div>

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](https://www.babylonjs-playground.com/#NWNUIH)

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:

 ![babylonjs-hdri-env](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/5/3/53eac372960d37fbf802869836f0431919412c5a.jpeg)  
Converted:  
 ![babylonjs-hdri-env-converted](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/1/d/1d71308b9f3ba317ea057d7ab3df2add9a9ed964.jpeg)

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

---

<div class="post-metadata">

**Author:** ![MiikaH](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/miikah/32/23054_2.png) [@MiikaH](https://forum.babylonjs.com/u/MiikaH)\
**Post date:** [April 20, 2023, 3:33pm UTC](https://forum.babylonjs.com/t/is-ibl-texture-tool-hdr-to-env-conversion-code-part-of-babylon-js/40031/7 "2023-04-20T15:33:41Z")

</div>

Hmm… Maybe it is a bug in prefiltering code? It seems to also happen when using `HDRCubeTexture` directly with prefiltering: [https://www.babylonjs-playground.com/#NWNUIH#1](https://www.babylonjs-playground.com/#NWNUIH#1)

---

<div class="post-metadata">

**Author:** ![MiikaH](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/miikah/32/23054_2.png) [@MiikaH](https://forum.babylonjs.com/u/MiikaH)\
**Post date:** [April 20, 2023, 3:49pm UTC](https://forum.babylonjs.com/t/is-ibl-texture-tool-hdr-to-env-conversion-code-part-of-babylon-js/40031/8 "2023-04-20T15:49:46Z")

</div>

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. 😵‍💫

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.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [April 20, 2023, 4:09pm UTC](https://forum.babylonjs.com/t/is-ibl-texture-tool-hdr-to-env-conversion-code-part-of-babylon-js/40031/9 "2023-04-20T16:09:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [April 20, 2023, 7:06pm UTC](https://forum.babylonjs.com/t/is-ibl-texture-tool-hdr-to-env-conversion-code-part-of-babylon-js/40031/10 "2023-04-20T19:06:32Z")

</div>

The uptodate way is the sandbox or the inspector 🙂

I will update the tool tonight for 6.0

The resolution is impacting color, due to interpolations.

---

<div class="post-metadata">

**Author:** ![MiikaH](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/miikah/32/23054_2.png) [@MiikaH](https://forum.babylonjs.com/u/MiikaH)\
**Post date:** [April 20, 2023, 7:27pm UTC](https://forum.babylonjs.com/t/is-ibl-texture-tool-hdr-to-env-conversion-code-part-of-babylon-js/40031/11 "2023-04-20T19:27:38Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![MiikaH](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/miikah/32/23054_2.png) [@MiikaH](https://forum.babylonjs.com/u/MiikaH)\
**Post date:** [April 20, 2023, 9:51pm UTC](https://forum.babylonjs.com/t/is-ibl-texture-tool-hdr-to-env-conversion-code-part-of-babylon-js/40031/12 "2023-04-20T21:51:05Z")

</div>

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](https://github.com/BabylonJS/Babylon.js/pull/13766)

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
