# 虛幻引擎公式推導中的重要性採樣（輻照度項）

``````float3 PrefilterEnvMap(float Roughness, float3 R )
{
float3 N = R;
float3 V = R;
float3 PrefilteredColor = 0;
const uint NumSamples = 1024;
for(uint i = 0; i < NumSamples; i++ )
{
float2 Xi = Hammersley( i, NumSamples );
float3 H = ImportanceSampleGGX( Xi, Roughness, N );
float3 L = 2 * dot  ( V, H ) * H - V;
float NoL =saturate( dot  ( N, L ) );
if ( NoL > 0 )
{
PrefilteredColor += EnvMap.SampleLevel( EnvMapSampler, L, 0 ).rgb * NoL;
TotalWeight += NoL;
}
}
return PrefilteredColor / TotalWeight;
}
``````

\$\$ p_i（wm，wo）= \ frac {D（wm）（wm \ cdot wg）} {4 | wo \ cdot wm |} \$\$

I just read notes on moving frostbite to pbr and I found the derivation of the method above. So I will just show the derivation here and quote some of the explanation.

One can notice an extra〈n·l〉in the LD term as well as a different weighting 1/(∑Ni〈n·l〉). These empirical terms have been introduce by Karis to allows to improve the reconstructed lighting integral which suffers from coarse hypothesis of separability of this integral. There is no mathematical derivation for these terms, goal was to have an exact match with a constant L(l).

So it turns out the pdf is weighted on the DFG term. As for dot(N,l), the term is introduced to minimize the error that is caused by split sum approximation. But I am actually still wondering what is the intuition on that empirical term.