I wanted to see if there is a way to eliminate the per-fragment matrix multiplier in my EMBM shader. I admit I don’t really understand what is going on here, and I just tried different things until I found something that worked.
The part I am interested in is in the second block of code, but I included the first just so you could see what is happening.
Here is the part that gets the normal from the normal map:
#ifdef LW_BUMPMAP
#ifdef LW_LIGHTMAP
lightdir = gl_NormalMatrix * ( ( texture2D(radiositymap,gl_TexCoord[1].st).xyz - 0.5 ));
#else
#ifdef LW_LIGHTS
lightdir = BumpVector;
#else
lightdir = gl_NormalMatrix * ((BumpVector-0.5)*2.0);
#endif
#endif
bumpcolor = texture2D(bumpmap,basetexcoord);
vec3 halfvec = normalize(normalize(lightdir) + normalize(-ModelVertex));
normal = normalize(bumpcolor.xyz - 0.5);
normal = T * normal.x + B * normal.y + N * normal.z;
lightcolor = lightcolor * max(0.0,dot(normal,lightdir)) * 2.0;
specular = pow(max(0.0, dot(halfvec,normal)),8.0) * bumpcolor.w * 0.5;
#ifdef LW_EMBM
specular = 0.0;
#endif
#else
normal = N;
#endif
Here is the part that perturbs the cubemap coords by the normal:
#ifdef LW_EMBM
vec3 cubecoord = gl_TexCoord[3].xyz;
normal *= gl_NormalMatrix;
cubecoord += vec3(normal.x,-normal.y,-normal.z) * 100.0;
//vec3 cubecoord = gl_TexCoord[3].xyz * vec3(normal.x,normal.y,-normal.z) * 100.0;
gl_FragColor = gl_FragColor * alpha + textureCube( cubemap,cubecoord * vec3(1,1,-1) ) * (1.0 - alpha);
#else
gl_FragColor = gl_FragColor * alpha + textureCube( cubemap,gl_TexCoord[3].xyz * vec3(1,1,-1) ) * (1.0 - alpha);
#endif