2016년 3월 27일 일요일

Incorrect naming in UE4 skylight source code.

Recently, I am reading UE4 skylight code. and found that they call projected SH coefficients as "IrradianceEnvironmentMap".

Actually, this naming is wrong.
They make this Irradiance SH Function by producting cosine lobe in the end. But until then it is projected "Radiance SH" not "Irradiance SH".

Let's recall basic rendering process using spherical harmonics.

1. Project SH coefficients from radiance cube map.
2. Convert Radiance SH to Irradiance SH by dot product with cosine lobe
(Ravi Ramamoorthi's paper)
3. Evaluate Irradiance env map with normal vector

Let's see two different shader code for SH shading.

Below code is hlsl from MJP in gamedev.net
This is easy to understand.
There is radiance SH, cosine lobe.



And below is code from Peter-Pike Sloan
This code seems to be just a sh evaluation code.
The secret is coefficient for cosine lobe is already producted to radiance SH(and it becomes Irradiance finally!)


Later code may be a lot faster(because use fewer shader instructions).

UE4 call value after 1 as IrradianceEnvironmentMap(it becomes irradiance in the end, but not at first).

Although final rendering is OK, But Incorrect naming confuse stupid reader like me.