浏览代码

Merge pull request #8346 from bhouston/minor_brdf_cleanup

minor brdf clean up - adopt pow2(x) and sqrt(x) were appropriate
Mr.doob 9 年之前
父节点
当前提交
f0d9801464
共有 1 个文件被更改,包括 4 次插入4 次删除
  1. 4 4
      src/renderers/shaders/ShaderChunk/bsdfs.glsl

+ 4 - 4
src/renderers/shaders/ShaderChunk/bsdfs.glsl

@@ -57,11 +57,11 @@ float G_GGX_Smith( const in float alpha, const in float dotNL, const in float do
 
 
 	// geometry term = G(l)⋅G(v) / 4(n⋅l)(n⋅v)
 	// geometry term = G(l)⋅G(v) / 4(n⋅l)(n⋅v)
 
 
-	float a2 = alpha * alpha;
+	float a2 = pow2( alpha );
 
 
-	float gl = dotNL + pow( a2 + ( 1.0 - a2 ) * pow2( dotNL ), 0.5 );
+	float gl = dotNL + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );
 
 
-	float gv = dotNV + pow( a2 + ( 1.0 - a2 ) * pow2( dotNV ), 0.5 );
+	float gv = dotNV + sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );
 
 
 	return 1.0 / ( gl * gv );
 	return 1.0 / ( gl * gv );
 
 
@@ -85,7 +85,7 @@ float D_GGX( const in float alpha, const in float dotNH ) {
 // GGX Distribution, Schlick Fresnel, GGX-Smith Visibility
 // GGX Distribution, Schlick Fresnel, GGX-Smith Visibility
 vec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {
 vec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {
 
 
-	float alpha = roughness * roughness; // UE4's roughness
+	float alpha = pow2( roughness ); // UE4's roughness
 
 
 	vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );
 	vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );