|
|
|
@ -106,6 +106,7 @@ void PBR_ComputeDirectLight(vec3 normal, vec3 lightDir, vec3 viewDir, |
|
|
|
|
outSpecular = vec3(specular) * lightColor; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//https://knarkowicz.wordpress.com/2014/12/27/analytical-dfg-term-for-ibl/ |
|
|
|
|
vec3 EnvDFGPolynomial( vec3 specularColor, float roughness, float ndotv ){ |
|
|
|
|
float x = 1.0 - roughness; |
|
|
|
|
float y = ndotv; |
|
|
|
@ -128,7 +129,7 @@ vec3 EnvDFGPolynomial( vec3 specularColor, float roughness, float ndotv ){ |
|
|
|
|
float delta = clamp(( d0 + d1 * x + d2 * y + d3 * x * x + d4 * x * y + d5 * y * y + d6 * x * x * x ), 0.0, 1.0); |
|
|
|
|
float scale = delta - bias; |
|
|
|
|
|
|
|
|
|
bias *= clamp( 50.0 * specularColor.y, 0.0, 1.0 ); |
|
|
|
|
bias *= clamp( 2.5 / (roughness) * specularColor.y, 0.0, 1.0 ); |
|
|
|
|
return specularColor * scale + bias; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -142,8 +143,8 @@ vec3 ApproximateSpecularIBL(samplerCube envMap,sampler2D integrateBRDF, vec3 Spe |
|
|
|
|
|
|
|
|
|
vec3 ApproximateSpecularIBLPolynomial(samplerCube envMap, vec3 SpecularColor , float Roughness, float ndotv, vec3 refVec){ |
|
|
|
|
//TODO magic values should be replaced by defines. |
|
|
|
|
float Lod = log2(Roughness) * 1.5 + 6.0 - 1.0; |
|
|
|
|
vec3 PrefilteredColor = textureCubeLod(envMap, refVec.xyz,Lod).rgb; |
|
|
|
|
float Lod = log2(Roughness) * 1.1 + 6.0 - 1.0; |
|
|
|
|
vec3 PrefilteredColor = textureCubeLod(envMap, refVec.xyz, Lod).rgb; |
|
|
|
|
return PrefilteredColor * EnvDFGPolynomial(SpecularColor, Roughness, ndotv); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|