Browse Source

Merge pull request #16559 from jsantell/roughness-dependent-fresnel

Use roughness-dependent fresnel when rendering with multiscattering
Mr.doob 6 years ago
parent
commit
2f054a30eb
1 changed files with 12 additions and 3 deletions
  1. 12 3
      src/renderers/shaders/ShaderChunk/bsdfs.glsl.js

+ 12 - 3
src/renderers/shaders/ShaderChunk/bsdfs.glsl.js

@@ -69,6 +69,17 @@ vec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {
 
 } // validated
 
+vec3 F_Schlick_RoughnessDependent( const in vec3 F0, const in float dotNV, const in float roughness ) {
+
+	// See F_Schlick
+	float fresnel = exp2( ( -5.55473 * dotNV - 6.98316 ) * dotNV );
+	vec3 Fr = max( vec3( 1.0 - roughness ), F0 ) - F0;
+
+	return Fr * fresnel + F0;
+
+}
+
+
 // Microfacet Models for Refraction through Rough Surfaces - equation (34)
 // http://graphicrants.blogspot.com/2013/08/specular-brdf-reference.html
 // alpha is "roughness squared" in Disney’s reparameterization
@@ -270,15 +281,13 @@ void BRDF_Specular_Multiscattering_Environment( const in GeometricContext geomet
 
 	float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );
 
-	vec3 F = F_Schlick( specularColor, dotNV );
+	vec3 F = F_Schlick_RoughnessDependent( specularColor, dotNV, roughness );
 	vec2 brdf = integrateSpecularBRDF( dotNV, roughness );
 	vec3 FssEss = F * brdf.x + brdf.y;
 
 	float Ess = brdf.x + brdf.y;
 	float Ems = 1.0 - Ess;
 
-	// Paper incorrect indicates coefficient is PI/21, and will
-	// be corrected to 1/21 in future updates.
 	vec3 Favg = specularColor + ( 1.0 - specularColor ) * 0.047619; // 1/21
 	vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );