Skip to content

Commit

Permalink
Fix issues in specular pre-filter convolution (missing PI in GGX dist…
Browse files Browse the repository at this point in the history
…ribution; wrong pdf calculation)
  • Loading branch information
TaaTT4 committed May 4, 2022
1 parent d426474 commit 58dfd9b
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@
float a = roughness * roughness;

float Phi = 2 * PI * Xi.x;
float CosTheta = sqrt( ( 1 - Xi.y ) / ( 1 + ( a * a - 1 ) * Xi.y ) );
// NOTE: (aa-1) == (a-1)(a+1) produces better fp accuracy
float CosTheta = sqrt( ( 1 - Xi.y ) / ( 1 + ( a + 1 ) * ( ( a - 1 ) * Xi.y ) ) );
float SinTheta = sqrt( 1 - CosTheta * CosTheta );

float3 H;
Expand All @@ -141,9 +142,11 @@
// Smoth GGX
INLINE float specularD( float roughness, float NoH )
{
float NoH2 = NoH * NoH;
float r2 = roughness * roughness;
return r2 / pow( NoH2 * ( r2 - 1.0 ) + 1.0, 2.0 );
float a = roughness * roughness;

// NOTE: (aa-1) == (a-1)(a+1) produces better fp accuracy
float f = ( a - 1 ) * ( ( a + 1 ) * ( NoH * NoH ) ) + 1;
return ( a * a ) / ( PI * f * f );
}

INLINE float4 importanceSample( float3 R PARAMS_ARG_DECL )
Expand All @@ -165,7 +168,7 @@
float NoL = max( dot( N, L ), 0.0 );
// float VoL = max( dot( V, L ), 0.0 );
float NoH = max( dot( N, H ), 0.0 );
float VoH = max( dot( V, H ), 0.0 );
// float VoH = max( dot( V, H ), 0.0 );
if( NoL > 0 )
{
//
Expand All @@ -174,7 +177,7 @@
// http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
//
float Dh = specularD( p_convolutionRoughness, NoH );
float pdf = Dh * NoH / ( 4 * VoH );
float pdf = Dh / 4;
float solidAngleTexel = 4 * PI / ( 6 * p_inputResolution.x * p_inputResolution.x );
float solidAngleSample = 1.0 / ( p_convolutionSampleCount * pdf );
float lod =
Expand Down

0 comments on commit 58dfd9b

Please sign in to comment.