Use clamp instead of max(0, dot(normalized, normalized))

Should help GLSL compiler to optimize them.
This commit is contained in:
Vincent Lejeune
2014-12-05 17:48:56 +01:00
parent 8f3b8cf448
commit 1e2656dc88
6 changed files with 7 additions and 7 deletions

View File

@@ -35,7 +35,7 @@ void main(void)
vec3 eyedir = normalize(xpos.xyz);
// Inspired from http://http.developer.nvidia.com/GPUGems3/gpugems3_ch16.html
float fEdotL = max(0., dot(SunDir, eyedir));
float fEdotL = clamp(dot(SunDir, eyedir), 0., 1.);
float fPowEdotL = pow(fEdotL, 4.);
float fLdotNBack = max(0., - dot(nor, SunDir) * 0.6 + 0.4);

View File

@@ -41,7 +41,7 @@ void main(void)
vec3 eyedir = normalize(xpos.xyz);
// Inspired from http://http.developer.nvidia.com/GPUGems3/gpugems3_ch16.html
float fEdotL = max(0., dot(SunDir, eyedir));
float fEdotL = clamp(dot(SunDir, eyedir), 0., 1.);
float fPowEdotL = pow(fEdotL, 4.);
float fLdotNBack = max(0., - dot(nor, SunDir) * 0.6 + 0.4);

View File

@@ -35,7 +35,7 @@ void main()
// Light Direction
vec3 L = -normalize(xpos.xyz - light_pos);
float NdotL = max(0., dot(norm, L));
float NdotL = clamp(dot(norm, L), 0., 1.);
Diffuse = vec4(NdotL * light_col * att, 1.);
Specular = vec4(SpecularBRDF(norm, eyedir, L, light_col, roughness) * NdotL * att, 1.);

View File

@@ -46,7 +46,7 @@ void main() {
// Normalized on the cpu
vec3 L = direction;
float NdotL = max(0., dot(norm, L));
float NdotL = clamp(dot(norm, L), 0., 1.);
float angle = 3.14 * sunangle / 180.;
vec3 R = reflect(-eyedir, norm);

View File

@@ -60,7 +60,7 @@ void main() {
// Normalized on the cpu
vec3 L = direction;
float NdotL = max(0., dot(norm, L));
float NdotL = clamp(dot(norm, L), 0., 1.);
float angle = 3.14 * sunangle / 180.;
vec3 R = reflect(-eyedir, norm);

View File

@@ -4,8 +4,8 @@ vec3 SpecularBRDF(vec3 normal, vec3 eyedir, vec3 lightdir, vec3 color, float rou
float exponentroughness = exp2(10. * roughness + 1.);
// Half Light View direction
vec3 H = normalize(eyedir + lightdir);
float NdotH = max(0., dot(normal, H));
float NdotH = clamp(dot(normal, H), 0., 1.);
float normalisationFactor = (exponentroughness + 2.) / 8.;
vec3 FresnelSchlick = color + (1.0f - color) * pow(1.0f - max(0., (dot(eyedir, H))), 5);
vec3 FresnelSchlick = color + (1.0f - color) * pow(1.0f - clamp(dot(eyedir, H), 0., 1.), 5);
return max(pow(NdotH, exponentroughness) * FresnelSchlick * normalisationFactor, vec3(0.));
}