Hi,
I follow the bump mapping example from the book “OpenGL Shading Language,” but the result looks very different from what it does in the book.
Please see the comparison here:
http://joe.phsiao.googlepages.com/bump.jpg
The left one is what I got in Shader Designer, and it does not bump . The right one is the result in the book.
Here is the code:
varying vec3 LightDir;
varying vec3 EyeDir;
attribute vec3 Tangent;
void main()
{
vec3 LightPosition = vec3(0,0,0);
EyeDir = vec3(gl_ModelViewMatrix * gl_Vertex);
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
vec3 n = normalize(gl_NormalMatrix * gl_Normal);
vec3 t = normalize(gl_NormalMatrix * Tangent);
vec3 b = cross(n, t);
vec3 v;
v.x = dot(vec3(gl_LightSource[0].position), t);
v.y = dot(vec3(gl_LightSource[0].position), b);
v.z = dot(vec3(gl_LightSource[0].position), n);
LightDir = normalize(v);
v.x = dot(EyeDir, t);
v.y = dot(EyeDir, b);
v.z = dot(EyeDir, n);
EyeDir = normalize(v);
}
varying vec3 LightDir;
varying vec3 EyeDir;
void main()
{
vec3 litColor;
vec2 c = 16.0 * gl_TexCoord[0].st;
vec2 p = fract(c) - vec2(0.5);
float d, f;
d = p.x * p.x + p.y * p.y;
f = 1.0 / sqrt(d+1.0);
if(d >= 0.15)
{
p = vec2(0.0); f = 1.0;
}
vec3 normDelta = vec3(p.x, p.y, 1.0)*f;
litColor = vec3(.7, .6, .18) * max(dot(normDelta, LightDir), 0.0);
vec3 reflectDir = reflect(LightDir, normDelta);
float spec = max(dot(EyeDir, reflectDir), 0.0);
spec = pow(spec, 6.0);
spec *= .5;
litColor = min(litColor + spec, vec3(1.0));
gl_FragColor = vec4(litColor, 1.0);
}
I just replaced all the uniform variables in the example to make it executable in the program Shader Designer. What is the problem?