Normalize normals when they are used to get more precision

This commit is contained in:
Vincent Lejeune 2014-01-27 22:21:16 +01:00
parent 5771dd98c7
commit 1c98cf0b61
5 changed files with 6 additions and 10 deletions

View File

@ -15,8 +15,6 @@ void main()
vec3 Frag_normal = normalize(cross(Frag_tangent, bitangent));
vec3 Frag_bitangent = cross(Frag_normal, Frag_tangent);
vec3 FragmentNormal = TS_normal.x * Frag_tangent + TS_normal.y * Frag_bitangent - TS_normal.z * Frag_normal;
FragmentNormal = normalize(FragmentNormal);
Normal = 0.5 * FragmentNormal + 0.5, gl_FragCoord.z;
vec3 FragmentNormal = TS_normal.x * Frag_tangent + TS_normal.y * Frag_bitangent - TS_normal.z * Frag_normal;
Normal = 0.5 * FragmentNormal + 0.5;
}

View File

@ -4,5 +4,5 @@ out vec3 Normal;
void main(void)
{
Normal = 0.5 * normalize(nor) + 0.5;
Normal = 0.5 * nor + 0.5;
}

View File

@ -9,6 +9,6 @@ void main() {
vec4 col = texture(tex, uv);
if (col.a < 0.5)
discard;
Normal = 0.5 * normalize(nor) + 0.5;
Normal = 0.5 * nor + 0.5;
}

View File

@ -16,8 +16,7 @@ out vec4 Specular;
void main() {
vec2 texc = uv;
float z = texture(dtex, texc).x;
vec3 norm = texture(ntex, texc).xyz;
norm = (norm - 0.5) * 2.0;
vec3 norm = normalize(2. * texture(ntex, texc).xyz - 1.);
vec4 xpos = 2.0 * vec4(texc, z, 1.0) - 1.0f;
xpos = invproj * xpos;

View File

@ -28,8 +28,7 @@ void main() {
return;
}
vec3 norm = texture(ntex, uv).xyz;
norm = (norm - 0.5) * 2.0;
vec3 norm = normalize(2. * texture(ntex, uv).xyz - 1.);
// Normalized on the cpu
vec3 L = direction;