Mike,
The shader and a few more specimens:
'LIGHT MATERIAL AND CUBIC REFLECTION ALPHA SHADER
'================================================
'
vs[7]=
"
// User-specified uniforms
uniform vec3 CameraPosition;
varying vec3 vN;
varying vec3 v;
varying vec2 texCoord;
varying vec3 NormalDirection;
varying vec3 ViewDirection;
void main(void)
{
texCoord = gl_MultiTexCoord0;
v = vec3(gl_ModelViewMatrix * gl_Vertex);
vN = normalize(gl_NormalMatrix * gl_Normal);
NormalDirection = normalize(vec3(vec4(gl_Normal, 0.0) * gl_ModelViewMatrixInverse));
ViewDirection = vec3(gl_ModelViewMatrix * gl_Vertex
- vec4(CameraPosition, 1.0));
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
"
fs[7]=
"
uniform vec4 Tint;
uniform sampler2D TextureUnit;
uniform samplerCube CubeMap;
varying vec3 vN;
varying vec3 v;
varying vec2 texCoord;
//for cubic reflection
varying vec3 NormalDirection;
varying vec3 ViewDirection;
#define MAX_LIGHTS 3
void main (void)
{
vec3 N = normalize(vN);
vec4 finalColor = Tint;
float Alpha = Tint.a;
vec3 reflectedDirection = reflect(ViewDirection, NormalDirection);
for (int i=0;i<MAX_LIGHTS;i++)
{
vec3 L = normalize(gl_LightSource[i].position.xyz - v);
vec3 E = normalize(-v); // we are in Eye Coordinates, so EyePos is (0,0,0)
vec3 R = normalize(-reflect(L,N));
//calculate Ambient Term:
vec4 Iamb = gl_FrontLightProduct[i].ambient;
//calculate Diffuse Term:
vec4 Idiff = gl_FrontLightProduct[i].diffuse * max(dot(N,L), 0.0);
Idiff = clamp(Idiff, 0.0, 1.0);
// calculate Specular Term:
vec4 Ispec = gl_FrontLightProduct[i].specular
* pow(max(dot(R,E),0.0),0.3*gl_FrontMaterial.shininess);
Ispec = clamp(Ispec, 0.0, 1.0);
finalColor +=
Iamb
+Idiff
+Ispec;
}
finalColor *=
///texture2D(TextureUnit, texCoord);
textureCube(CubeMap, reflectedDirection);
gl_FragColor = vec4(vec3(finalColor),Alpha);
}
"
.