Browse Source

Merge pull request #22455 from WestLangley/shaders_sheen

Shaders: Refactored sheen BRDF
WestLangley 3 years ago
parent
commit
a3190d0dff

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

@@ -217,35 +217,38 @@ vec3 BRDF_BlinnPhong( const in IncidentLight incidentLight, const in GeometricCo
 
 #if defined( USE_SHEEN )
 
-// https://github.com/google/filament/blob/master/shaders/src/brdf.fs#L94
-float D_Charlie( float roughness, float NoH ) {
+// https://github.com/google/filament/blob/master/shaders/src/brdf.fs
+float D_Charlie( float roughness, float dotNH ) {
 
 	// Estevez and Kulla 2017, "Production Friendly Microfacet Sheen BRDF"
 	float invAlpha = 1.0 / roughness;
-	float cos2h = NoH * NoH;
+	float cos2h = dotNH * dotNH;
 	float sin2h = max( 1.0 - cos2h, 0.0078125 ); // 2^(-14/2), so sin2h^2 > 0 in fp16
 
 	return ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );
 
 }
 
-// https://github.com/google/filament/blob/master/shaders/src/brdf.fs#L136
-float V_Neubelt( float NoV, float NoL ) {
+// https://github.com/google/filament/blob/master/shaders/src/brdf.fs
+float V_Neubelt( float dotNV, float dotNL ) {
 
 	// Neubelt and Pettineo 2013, "Crafting a Next-gen Material Pipeline for The Order: 1886"
-	return saturate( 1.0 / ( 4.0 * ( NoL + NoV - NoL * NoV ) ) );
+	return saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );
 
 }
 
-vec3 BRDF_Sheen( const in float roughness, const in vec3 L, const in GeometricContext geometry, vec3 specularColor ) {
+vec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenTint, const in float sheenRoughness ) {
 
-	vec3 N = geometry.normal;
-	vec3 V = geometry.viewDir;
+	vec3 halfDir = normalize( lightDir + viewDir );
 
-	vec3 H = normalize( V + L );
-	float dotNH = saturate( dot( N, H ) );
+	float dotNL = saturate( dot( normal, lightDir ) );
+	float dotNV = saturate( dot( normal, viewDir ) );
+	float dotNH = saturate( dot( normal, halfDir ) );
+
+	float D = D_Charlie( sheenRoughness, dotNH );
+	float V = V_Neubelt( dotNV, dotNL );
 
-	return specularColor * D_Charlie( roughness, dotNH ) * V_Neubelt( dot(N, V), dot(N, L) );
+	return sheenTint * ( D * V );
 
 }
 

+ 1 - 1
src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js

@@ -132,7 +132,7 @@ void RE_Direct_Physical( const in IncidentLight directLight, const in GeometricC
 
 	#ifdef USE_SHEEN
 
-		reflectedLight.directSpecular += irradiance * BRDF_Sheen( material.roughness, directLight.direction, geometry, material.sheenTint );
+		reflectedLight.directSpecular += irradiance * BRDF_Sheen( directLight.direction, geometry.viewDir, geometry.normal, material.sheenTint, material.roughness );
 
 	#else