Physically based rendering using LTASG-filtered environment maps.
Blinn-Phong approximates a Gaussian distribution as the specular exponent increases [Lyon1993]. [Olano2010] has shown the following relation in terms of the angle
This makes the spherical Gaussian blur an excellent and appropriate choice for generating environmental maps. By extending the Gaussian blur's separable property, it is possible to implement it in
Related Works
Pre-filtered Mipmapped Radiance Environment Maps
AMD's CubeMapGen has been a popular choice to generate pre-filtered environment maps. However, it is designed for a offline generation and is too slow for a real-time use.
In three.js, PMREMGenerator
is responsible for pre-filtering environment maps. It is implemented as a fragment shader that performs Monte Carlo sampling, and when the sample count is set as low as 32 it is capable of running at 60fps on Intel HD Graphics 40001 . [Colbert2007] describes a practical implementation of GPU-based importance sampling for environment map pre-filtering
Mapping Gloss Values to Mip Levels
I wanted to have a constant kernel radius of
Under this condition and given that the image size of the base mip level is
Algorithm
Separate Filtering
The basic idea of the separate Gaussian filter is decomposing a n-dimensional Gaussian filter into
This decomposition allows a
At cost of accuracy, this idea can be extended for a wider variety of filters that locally resemble a Gaussian filter, examples of which include a spatially varying anisotropic Gaussian filter [Zheng2011].
To apply this technique, one has to find the functions
In addition, from a practical perspective,
For a spherical Gaussian blur (
I propose the following axis functions (
Each of them represents a tangent vector along the latitude, assuming
the points
These axis functions are unambiguously derived by combining the following conditions: the tangential condition (they follow the surface of a sphere), the uniform blur condition, and the latitudinal condition (each of them follows a set of latitudinal lines surrounding a corresponding axis).
Implementation on Cube Map
For each one-dimensional filter (
is inside the face — In this case, the filter is implemented as a radial blur oriented toward the pole . is outside the face — In this case, the filter is implemented as a directional blur along the U or V direction.
We will only consider the positive Z cube face in the following discussion.
Given a texture coordinate
In the first case where
By projecting it on the plane
In the second case where
By projecting it on the plane
Demonstration
hyper3d-envmapgen implements the proposed algorithm using TypeScript, Rust, and WebAssembly. It uses a CPU to execute the algorithm, making it possible to generate a PMREM without hindering the main thread or a GPU. An interactive WebGL demo is available here.