I guess there isn’t much I can do. I was trying to do Reflective bump mapping and below is the code for Cube mapping and Reflective BummpMapping:
CubeMapping:-
Vertex Shader:
varying vec3 N;
varying vec3 V;
void main(void)
{
gl_Position = ftransform();
vec3 vertex = vec3 (gl_ModelViewMatrix * gl_Vertex);
V = normalize(-vertex);
N = vec3 (gl_NormalMatrix * gl_Normal);
}
Fragment Shader:
uniform samplerCube cubeMapTexture;
varying vec3 N;
varying vec3 V;
void main(void)
{
vec3 view = normalize(V);
vec3 normal = normalize(N);
vec3 refVector = normalize(reflect(-view, normal));
vec3 refColor = vec3 (textureCube(cubeMapTexture, refVector));
gl_FragColor = vec4 (vec3(refColor), 1.0);
}
Reflective BumpMapping:_
Vertex Shader:
uniform vec3 light;
uniform vec3 camera;
attribute vec2 bumpMapTexCoord;
attribute vec3 tangent;
attribute vec3 binormal;
varying vec2 texCoord;
varying vec3 T, B, N;
varying vec3 V, L;
varying vec3 cmV;
void main(void)
{
gl_Position = ftransform();
vec3 vertex = vec3 (gl_Vertex);
vec3 lvec = normalize(light - vertex);
vec3 view = normalize(camera - vertex);
T = tangent;
B = binormal;
N = gl_Normal;
V = view;
L = lvec;
cmV = vec3 (gl_ModelViewMatrix * gl_Vertex);
cmV = normalize(-cmV);
texCoord = bumpMapTexCoord;
}
Fragment Shader:
uniform sampler2D decalTexture;
uniform sampler2D bumpMapTexture;
uniform samplerCube cubeMapTexture;
varying vec2 texCoord;
varying vec3 T, B, N;
varying vec3 V, L;
varying vec3 cmV;
void main(void)
{
T = normalize(T);
B = normalize(B);
N = normalize(N);
V = normalize(V);
L = normalize(L);
cmV = normalize(cmV);
vec3 view, light, half;
view.x = dot(T, V);
view.y = dot(B, V);
view.z = dot(N, V);
light.x = dot(T, L);
light.y = dot(B, L);
light.z = dot(N, L);
half = normalize(light + view);
vec3 decal = vec3 (texture2D(decalTexture, texCoord));
vec3 normal = vec3 (texture2D(bumpMapTexture, texCoord));
normal.x = 2.0 * normal.x - 1.0;
normal.y = 2.0 * normal.y - 1.0;
normal.z = 2.0 * normal.z - 1.0;
float ndotl = max(dot(normal, light), 0.0);
float ndoth = pow(max(dot(normal, half), 0.0), 60.0);
vec3 t = vec3(T.x, B.x, N.x);
vec3 b = vec3(T.y, B.y, N.y);
vec3 n = vec3(T.z, B.z, N.z);
t = normalize(t);
b = normalize(b);
n = normalize(n);
vec3 cmNormal;
cmNormal.x = dot(t, normal);
cmNormal.y = dot(b, normal);
cmNormal.z = dot(n, normal);
cmNormal = vec3 (gl_NormalMatrix * cmNormal);
cmNormal = normalize(cmNormal);
vec3 refVector = normalize(reflect(-cmV, cmNormal));
vec3 refColor = vec3 (textureCube(cubeMapTexture, refVector));
vec3 fColor;
fColor.x = ndotl * (decal.x + refColor.x) + ndoth;
fColor.y = ndotl * (decal.y + refColor.y) + ndoth;
fColor.z = ndotl * (decal.z + refColor.z) + ndoth;
gl_FragColor = vec4 (vec3(fColor), 1.0);
}
The Cube Mapping works perfect but the Reflective Bump Mapping doesn’t work well. Can some body look at the code and suggest something ?