Experimentation with normalpacking and component precision.

This commit is contained in:
Shyotl
2012-10-14 04:00:02 -05:00
parent eb5b1312bb
commit e8ec81bf04
28 changed files with 354 additions and 46 deletions

View File

@@ -37,6 +37,17 @@ VARYING vec2 vary_texcoord0;
uniform float minimum_alpha;
vec3 pack(vec3 norm)
{
//#define PACK_NORMALS
#ifdef PACK_NORMALS
float p = sqrt(8.0*norm.z+8.0);
return vec3(norm.xy/p + 0.5, 0.0);
#else
return norm.xyz*0.5+0.5;
#endif
}
void main()
{
vec4 col = texture2D(diffuseMap, vary_texcoord0.xy);
@@ -48,5 +59,5 @@ void main()
frag_data[0] = vec4(vertex_color.rgb*col.rgb, 0.0);
frag_data[1] = vec4(0,0,0,0);
vec3 nvn = normalize(vary_normal);
frag_data[2] = vec4(nvn.xy * 0.5 + 0.5, nvn.z, 0.0);
frag_data[2] = vec4(pack(nvn),0.0);
}