Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify environment map workflow for image-based lighting #12074

Open
jjhembd opened this issue Jul 9, 2024 · 0 comments
Open

Simplify environment map workflow for image-based lighting #12074

jjhembd opened this issue Jul 9, 2024 · 0 comments

Comments

@jjhembd
Copy link
Contributor

jjhembd commented Jul 9, 2024

Feature

If users want to use image-based lighting, they currently need to do a lot of complicated pre-processing on the environment map image before Cesium can use it.

Current workflow

To use an environment map for image-based lighting, a user currently needs to do the following:

  1. Build KhronosGroup/glTF-IBL-Sampler from source (this brings the usual C++ dependency issues, cmake, etc)
  2. Use IBL-Sampler to generate a .ktx2 cubemap from the input image
  3. Load the .ktx2 in Cesium
  4. Install google/filament (this is relatively easy)
  5. Use filament to generate spherical harmonic (SH) coefficients
  6. Manually copy the coefficients into an array of Cartesian3 constructors

This process is described in the code comments in the Image-based lighting Sandcastle.

Potential improvements

It would be much simpler if we could use only 1 software. The options I can think of are:

  • Use KhronosGroup/glTF-IBL-Sampler for both specular and diffuse. It does not generate spherical harmonic coefficients, so we would have to switch Cesium over to using diffuse maps instead
  • Use google/filament for both specular and diffuse. It outputs KTX1 only, and Cesium only supports KTX2
  • Implement both parts inside Cesium, so a user could directly load an HDR or EXR environment map. The required shaders wouldn't be too hard, but we would lose the benefits of KTX2 compression

The optimum solution might be a combination of the above. Cesium could directly load HDR or EXR environment maps for quick testing. But Cesium would still accept pre-processed KTX files and SH coefficients, for users who want to optimize load times.

What other engines do

The glTF Sample Viewer provides a simple interface to "Add new HDR" (under "Display" --> "Image based lighting") which quietly takes care of all the required pre-processing of an uploaded .hdr file.

BabylonJS has an HDRCubeTexture constructor which handles all the required pre-processing of a .hdr file. However, the documentation recommends pre-processing to a .env or .dds file for faster load times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment