Kaleidoscope

09-26-2006, 10:51 PM

Hi all, this is my first post here and like almost all first posts the reason for this is a problem I had.

This is my first attempt to use GLSL, I was trying to obtain some bump mapping using shaders. After reading a lot of tutorials I decided that it was time to start writing something.

Unluckily my first attempt wasn't that good :( the problem as you might see from the image below is that I am able to light only the world ( the textured quad ;) forget about the box in the middle ) that lies under the light source (the white dot) and only one corner of it (the lower left on the pic). I don't really know what I'm doing wrong.

http://img.photobucket.com/albums/v70/_kali_/BumpMapping.jpg

here is my vertex program:

varying vec3 LightDir; //The transformed light direction, to pass to the fragment shader

varying vec2 TexCoords;

attribute vec3 Tangent;

void main()

{

gl_Position = ftransform();

vec3 n = normalize ( gl_NormalMatrix * gl_Normal);

vec3 t = normalize ( gl_NormalMatrix * Tangent);

vec3 b = cross (n, t);

vec3 lPos = gl_LightSource[0].position.xyz - vec3(gl_ModelViewMatrix * gl_Vertex);

lPos = normalize( lPos );

//Rotate the light into tangent space

vec3 v;

v.x = dot ( lPos , t);

v.y = dot ( lPos , b);

v.z = dot ( lPos , n);

LightDir = normalize( v );

TexCoords = gl_MultiTexCoord1.xy;

}and my fragment program:

uniform sampler2D Texture_Normal; //The bump-map

uniform sampler2D Texture_Color; //The texture

varying vec3 LightDir;

varying vec2 TexCoords;

void main()

{

vec3 lDir = normalize ( LightDir );

vec3 BumpNorm = vec3(texture2D(Texture_Normal, TexCoords));

vec3 DecalCol = vec3(texture2D(Texture_Color, TexCoords));

//Expand the bump-map into a normalized unsigned vector float

BumpNorm = (BumpNorm -0.5) * 2.0;

//Find the dot product between the light direction and the normal

float NdotL = max(dot(BumpNorm, lDir), 0.0);

vec3 diffuse = NdotL * vec3(1.0) * DecalCol;

//Set the color of the fragment...

gl_FragColor = vec4(diffuse, 1.0);

}Any hint will be really appreciated.

Edit:

solved... looks like there was a problem with my normal map :( Thank you for your help

This is my first attempt to use GLSL, I was trying to obtain some bump mapping using shaders. After reading a lot of tutorials I decided that it was time to start writing something.

Unluckily my first attempt wasn't that good :( the problem as you might see from the image below is that I am able to light only the world ( the textured quad ;) forget about the box in the middle ) that lies under the light source (the white dot) and only one corner of it (the lower left on the pic). I don't really know what I'm doing wrong.

http://img.photobucket.com/albums/v70/_kali_/BumpMapping.jpg

here is my vertex program:

varying vec3 LightDir; //The transformed light direction, to pass to the fragment shader

varying vec2 TexCoords;

attribute vec3 Tangent;

void main()

{

gl_Position = ftransform();

vec3 n = normalize ( gl_NormalMatrix * gl_Normal);

vec3 t = normalize ( gl_NormalMatrix * Tangent);

vec3 b = cross (n, t);

vec3 lPos = gl_LightSource[0].position.xyz - vec3(gl_ModelViewMatrix * gl_Vertex);

lPos = normalize( lPos );

//Rotate the light into tangent space

vec3 v;

v.x = dot ( lPos , t);

v.y = dot ( lPos , b);

v.z = dot ( lPos , n);

LightDir = normalize( v );

TexCoords = gl_MultiTexCoord1.xy;

}and my fragment program:

uniform sampler2D Texture_Normal; //The bump-map

uniform sampler2D Texture_Color; //The texture

varying vec3 LightDir;

varying vec2 TexCoords;

void main()

{

vec3 lDir = normalize ( LightDir );

vec3 BumpNorm = vec3(texture2D(Texture_Normal, TexCoords));

vec3 DecalCol = vec3(texture2D(Texture_Color, TexCoords));

//Expand the bump-map into a normalized unsigned vector float

BumpNorm = (BumpNorm -0.5) * 2.0;

//Find the dot product between the light direction and the normal

float NdotL = max(dot(BumpNorm, lDir), 0.0);

vec3 diffuse = NdotL * vec3(1.0) * DecalCol;

//Set the color of the fragment...

gl_FragColor = vec4(diffuse, 1.0);

}Any hint will be really appreciated.

Edit:

solved... looks like there was a problem with my normal map :( Thank you for your help