Updating Single-Channel EXR Support?

Hi all!

This is my first bug report (or maybe it’s a feature request—I’m not totally sure). I’ve been experimenting with shaders in Babylon, specifically working with EXR textures because I need the extra precision. It’s a pretty niche use case, but first off, I just want to say I’m really excited that Babylon supports EXRs! I know this is a fairly recent feature, so maybe that’s why this issue hasn’t popped up yet.

The issue I’ve run into is with how Babylon handles single-channel EXR files.

Looking at the EXRLoader, specifically this line, it seems that single-channel EXRs are expected to use the “Y” channel.

However, since Babylon targets WebGL2, which requires OpenGL ES 3.0 (#version 300 es), using “Y” as a luminance mapping is problematic because luminance textures are deprecated in this version. (Reference: Luminance in OpenGL ES 3.0).

In practice, this creates an inconsistency: single-channel EXRs are forced to map to Y, but then the context maps that channel automatically to R in the shader, which can cause unexpected results.


Proposal:

The fix seems relatively straightforward. I’d be happy to submit a PR if this sounds reasonable. I could:

  • Maintain backward compatibility if there’s a need for Y channel support.
  • Add proper support for 1, 2, and 3-channel EXRs using R, G, B mappings, aligned with modern OpenGL/WebGL2 expectations.

Let me know if this direction makes sense or if there’s any guidance before I start! Appreciate the help and the great work on Babylon.

1 Like

That sounds like a perfect plan!!! Please send the PR :wink:

I opened up a PR here :slight_smile: Expanded support for EXR files by Slater-Victoroff · Pull Request #16539 · BabylonJS/Babylon.js · GitHub. I’m not sure if I did it right though.

1 Like

Excellent! thanks!