# HDR JPG Loader Request

**URL:** <https://forum.babylonjs.com/t/hdr-jpg-loader-request/45807>\
**Category:** Completed Features\
**Created:** [November 20, 2023, 11:37am UTC](https://forum.babylonjs.com/t/hdr-jpg-loader-request/45807 "2023-11-20T11:37:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![SirFizX](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sirfizx/32/11703_2.png) [@SirFizX](https://forum.babylonjs.com/u/SirFizX)\
**Post date:** [November 20, 2023, 11:37am UTC](https://forum.babylonjs.com/t/hdr-jpg-loader-request/45807/1 "2023-11-20T11:37:40Z")

</div>

I humbly request that Babylon.js implement a similar loader to [this Three.js loader](https://raw.githack.com/mrdoob/three.js/dev/examples/index.html?q=hdr#webgl_loader_texture_hdrjpg).

---

<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:** [November 20, 2023, 2:20pm UTC](https://forum.babylonjs.com/t/hdr-jpg-loader-request/45807/2 "2023-11-20T14:20:39Z")

</div>

I think this is currently covered just not in the same ways. For Environment / reflection textures, there is a tool to create .env files, it escapes me where at the moment, that takes in a .hdr and does all the pre-processing ahead of time, instead of at “go time”. It can also make it significantly smaller than the .hdr.

I have a 5199kb .hdr that comes out as a 622kb .env.

A texture itself is of zero worth unless it is attached to a material which is then attached to a mesh. For 360 jpegs there is a photo dome mesh.

I think this arrangement is better. That is just an example. It says so in the page title. It as most example code, does not really go anywhere, as a practical matter.

---

<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:** [November 20, 2023, 11:28pm UTC](https://forum.babylonjs.com/t/hdr-jpg-loader-request/45807/3 "2023-11-20T23:28:46Z")

</div>

@SirFizX what is the limitation you are experiencing with our env format ?

---

<div class="post-metadata">

**Author:** ![brightMoon](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brightmoon/32/9959_2.png) [@brightMoon](https://forum.babylonjs.com/u/brightMoon)\
**Post date:** [September 13, 2024, 6:50am UTC](https://forum.babylonjs.com/t/hdr-jpg-loader-request/45807/4 "2024-09-13T06:50:42Z")

</div>

I think some users only have JPG or PNG environment ball images, so they want to use them directly as the background or material for the Sky Box

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [September 13, 2024, 2:36pm UTC](https://forum.babylonjs.com/t/hdr-jpg-loader-request/45807/5 "2024-09-13T14:36:28Z")

</div>

Can you elaborate more on the need here? We already support hdr files (and I’ve just added exr as well)

---

<div class="post-metadata">

**Author:** ![brightMoon](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brightmoon/32/9959_2.png) [@brightMoon](https://forum.babylonjs.com/u/brightMoon)\
**Post date:** [September 13, 2024, 3:27pm UTC](https://forum.babylonjs.com/t/hdr-jpg-loader-request/45807/6 "2024-09-13T15:27:45Z")

</div>

It’s just a regular EquiRectangular, and I see in the documentation that EquiRectangular CubeTexture is already supported.

---

<div class="post-metadata">

**Author:** ![Deltakosh](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/deltakosh/32/26635_2.png) [@Deltakosh](https://forum.babylonjs.com/u/Deltakosh)\
**Post date:** [September 13, 2024, 3:28pm UTC](https://forum.babylonjs.com/t/hdr-jpg-loader-request/45807/7 "2024-09-13T15:28:14Z")

</div>

Yep:) hence my question 🙂 I feel like this feature is already supported

---

<div class="post-metadata">

**Author:** ![brightMoon](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brightmoon/32/9959_2.png) [@brightMoon](https://forum.babylonjs.com/u/brightMoon)\
**Post date:** [September 13, 2024, 3:29pm UTC](https://forum.babylonjs.com/t/hdr-jpg-loader-request/45807/8 "2024-09-13T15:29:23Z")

</div>

Indeed, it’s great 👍

---

<div class="post-metadata">

**Author:** ![brightMoon](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brightmoon/32/9959_2.png) [@brightMoon](https://forum.babylonjs.com/u/brightMoon)\
**Post date:** [September 13, 2024, 3:44pm UTC](https://forum.babylonjs.com/t/hdr-jpg-loader-request/45807/9 "2024-09-13T15:44:24Z")

</div>

> [@Deltakosh](#):
>
> Can you elaborate more on the need here?

This is what I saw:

> <https://github.com/mrdoob/three.js/issues/27171>
>
> \### Description
> 
> \`.hdr\` and \`.exr\` files are commonly used for generating HDR …\`envMaps\` and scene backgrounds, they work nicely as long as you keep them within reasonable file size which, in turn, constraints their maximum resolution.
> 
> The \[webgl\_materials\_envmaps\_hdr\](https://threejs.org/examples/#webgl\_materials\_envmaps\_hdr) example is a perfect representation of this problem, the background is low resolution because otherwise it would need to download huge \`.exr\` files.
> 
> Some people (like @elalish) \[lamented the disadvantages\](https://github.com/mrdoob/three.js/pull/27036#issuecomment-1783158461) of using traditional hdr files because of their huge file size.
> 
> \### Solution
> 
> \[We ported to javascript\](https://github.com/MONOGRID/gainmap-js/) a new technology called \`Gain maps\` (also \[published on NPM\](https://www.npmjs.com/package/@monogrid/gainmap-js)).
> 
> Gain maps work by reconstructing an HDR image starting from 3 pieces of information:
> 1. A normal 8 bit SDR Representation of the image
> 2. Another 8-bit \*recovery image\* called gain map.
> 3. Some metadata which tells the decoder how to apply the gain map to the SDR image
> 
> These 3 pieces of information can be kept separate or embedded into a single image file.
> 
> Keeping the files separate allows you to use additional compressed image formats, including \`webp\`.
> 
> Embedding the gain map into a single file is theoretically possible with \`jpeg\`, \`heic\` \`avif\` \`jpeg xl\` \`tiff\` and \`dng\` (see \[the spec\](https://helpx.adobe.com/content/dam/help/en/camera-raw/using/gain-map/jcr\_content/root/content/flex/items/position/position-par/table/row-io13dug-column-4a63daf/download\_section/download-1/Gain\_Map\_1\_0d14.pdf)
> at \`How to Store Gain Maps in Various File Formats\`) file formats but we currently \[implemented a wasm encoder/decoder\](https://github.com/MONOGRID/libultrahdr-wasm) only for \`jpeg\`, this is a fork of google's own \[ultra hdr file format lib\](https://github.com/google/libultrahdr) compiled in \`wasm\` (see additional context below).
> 
> Additionally, we created a \*\*\[free online converter\](https://gainmap-creator.mono-grid.com)\*\* that allows to input an \`.exr\` or \`.hdr\` and convert it to a gain map. It also allows you to view already created gain maps as if they were conventional HDR files.
> 
> The online converter/viewer tool works entirely in your browser, encoding and decoding happen on your CPU and GPU.
> 
> \*\*For starters\*\*, we propose the integration of an \[an external example\](https://monogrid.github.io/gainmap-js/) (like previously done with \[this one\](https://github.com/mrdoob/three.js/blob/master/examples/webgl\_raycaster\_bvh.html) ), which leverages our \[Three.js Loaders\](https://github.com/MONOGRID/gainmap-js/tree/main/src/loaders).
> 
> I can create a pull request that adds such an examples if you like the technology and the implementation.
> 
> I'm also available to answer any questions you may have about our implementation and/or the technology in general.
> 
> \### Alternatives
> 
> \[RGBM\](https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/RGBMLoader.js) is a comparable alternative but it has the following disadvantages:
> 1. HDR range is limited to 3-4 stops, after that the technique starts fo to fall apart. 
> 
> Gain maps have no such limitations and are able to represent the full un-clipped HDR range (as far as Half Float precision goes).
> 2. Requires a javascript PNG parser which is not very fast, big \`rgbm\` images can take a long time to parse.
> 
> \`jpeg\` and \`webp\` Gain maps leverage the browser built-in decoding and the reconstruction of the HDR image is
> \[accomplished with a custom shader\](https://github.com/MONOGRID/gainmap-js/blob/main/src/materials/GainMapDecoderMaterial.ts), which is near instant.
> 3. PNG compression is not as good as \`jpeg\` and \`webp\`, file size is still an issue sometimes.
> 
> \[LogLuv\](https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/LogLuvLoader.js) is also a comparable alternative but:
> 1. File size is not comparable to gain maps, does not really resolves the file size issue we are trying to address.
> 2. like for RGBM, requires manual decoding in javascript, which can be slow for large images.
> 
> \### Additional context
> 
> Google \[is adopting the gain map technology in Android 14\](https://support.google.com/photos/answer/14159275) but it refers to it as \*\*Ultra HDR Image Format\*\* and a JPEG file with embedded gain map is called \[JPEGR\](https://github.com/google/libultrahdr/blob/main/lib/jpegr.cpp) in their terminology.
> 
> Hence the terms \`Ultra HDR\` and \`Gain Map\` are effectively synonyms, this can be a little confusing but the technology is still evolving and standard names are not established yet.
> 
> \[Chrome has support for native JPEG gain map decoding in chrome\](https://source.chromium.org/chromium/chromium/src/+/127fc8e18e96578c510e6269f013d9f4e28f8ab5) (with initial \`avif\` gain maps support behind a flag \`chrome://flags/#avif-gainmap-hdr-images\`). This allows HDR displays users to visualize HDR content compressed in JPEG or AVIF. 
> 
> Is is unclear if, in the future, Chrome's JS APIs will allow for natively obtain \`Uint16Array\` buffers starting from gain map images, for the moment we do it ourselves with our library.
> 
> References:
> \* \[Adobe Gan map specification version 1.0 draft 14\](https://helpx.adobe.com/content/dam/help/en/camera-raw/using/gain-map/jcr\_content/root/content/flex/items/position/position-par/table/row-io13dug-column-4a63daf/download\_section/download-1/Gain\_Map\_1\_0d14.pdf)
> \* \[Ultra HDR Image Format v1.0 Specification\](https://developer.android.com/guide/topics/media/platform/hdr-image-format)
