WebGL-based Prefiltered Mipmaped Radiance Environment Map (PMREM) generator

Thanks to @WestLangley‘s Physical material, we now need a proper prefiltered mipmapped radiance environment map generator to generate both the prefiltered specular cube maps as well as the prefiltered irradiance/diffuse cube maps.

We can use this tool to create them off line, but it is very inconvenient also this tool is slow:

https://seblagarde.wordpress.com/2012/06/10/amd-cubemapgen-for-physically-based-rendering/

It would best if we could generate them using the GPU so that generate was fast. If generation becomes less than 50ms on most hardware, we can use this live rather than downloading the PMREMs. Having it run real-time would be incredibly useful for doing live LightProbes (that would be awesome!)

Requirements:

  • Float32 input textures in a cube map pattern (which cube map pattern doesn’t matter, because we can likely convert to any format from any format.)
  • Ability to generate guassian or cosine power filtered specular cube maps.
  • Ability to specify the set of filter sizes desired. Sometimes people want a full mipmap full, other times they just want 4 levels.
  • Ability to create an irradiance map (for DiffuseLightProbes)
  • Output should also be in a cubemap float32 format (we can convert to any format afterwards.)
  • We’ll want to have some utility methods to map one cubemap type to another – such as latlong to samplerCube, to 2D packed cubemap (i.e. cubeToUV), and eventually to the tetrahedral format. This will be useful for both the input and output conversion.

I highly recommend that we make the texture format RGBM encoding/decoding to be optional, because sometimes you want this and other times you do not.

My recommendation is that we use a samplerCube internally to this function to keep it simple.

BTW PlayCanvas has one of these here:

https://github.com/playcanvas/engine/blob/master/src/graphics/programlib/chunks/prefilterCubemap.frag

Does anyone want to try their hand at this?

Author: Fantashit

1 thought on “WebGL-based Prefiltered Mipmaped Radiance Environment Map (PMREM) generator

Comments are closed.