瀏覽代碼

Fix a BRDF hack

Panagiotis Christopoulos Charitos 8 年之前
父節點
當前提交
fe703455e0
共有 3 個文件被更改,包括 4 次插入3 次删除
  1. 3 1
      shaders/Is.frag.glsl
  2. 0 1
      shaders/LightFunctions.glsl
  3. 1 1
      shaders/Pack.glsl

+ 3 - 1
shaders/Is.frag.glsl

@@ -176,7 +176,9 @@ void main()
 		appendDecalColors(decal, fragPos, diffCol, roughness);
 	}
 
-	float a2 = pow(roughness, 2.0);
+	// Don't allow zero a2 because we may end up with division with zero
+	float a2 = roughness * 0.9 + 0.1;
+	a2 *= a2;
 
 	// Ambient and emissive color
 	vec3 outC = diffCol * emission;

+ 0 - 1
shaders/LightFunctions.glsl

@@ -47,7 +47,6 @@ vec3 computeSpecularColorBrdf(vec3 v, // view dir
 	float noh = dot(n, h);
 	float D = noh * noh * (a2 - 1.0) + 1.0;
 	D = a2 / (PI * D * D);
-	D = clamp(D, EPSILON, 100.0); // Limit that because it may grow
 
 // G(l,v,h)/(4*dot(n,h)*dot(n,v)) aka Visibility term: Geometric shadowing divided by BRDF denominator
 #if 0

+ 1 - 1
shaders/Pack.glsl

@@ -137,7 +137,7 @@ void readGBuffer(in sampler2D rt0, in sampler2D rt1, in sampler2D rt2, in vec2 u
 
 	comp = textureLod(rt1, uv, lod);
 	g.specular = comp.xyz;
-	g.roughness = max(EPSILON, comp.w);
+	g.roughness = comp.w;
 
 	comp = textureLod(rt2, uv, lod);
 	g.normal = comp.xyz * 2.0 - 1.0;