Sign in to follow this  
diginerd

bumpmapping in glsl without using a pre-generated normal map

Recommended Posts

Hey guys, I have a pre-generated height map and I need to calculate the perturbed normals for my bump-mapped lighting calculations. I understand the equations, I just don't know how to do the perturbed normal calculation in glsl. Here's the calculation as I understand it: t = tangent in direction of 'u' texture coordinate b = bitangent in direction of 'v' texture coordinate H(i,j) = height at texel (i,j) in height map t(i,j) = vec3( 1, 0, aH(i+1, j) - aH(i-1, j) ) b(i,j) = vec3( 0, 1, aH(i, j+1) - aH(i, j-1) ) n = normalize(cross(t,b)) My problem is that I don't know how to access the height values at the other texels inside the heightmap: Here, if I'm correct is how to get H(i,j): sampler2D texture; vec4 heightAtThisPixel = texture2D(texture, gl_TexCoord[0].st); I need to know how to get H(i+1,j), H(i-1,j), H(i,j+1), H(i,j-1). Can someone please help me?

Share this post


Link to post
Share on other sites
Quote:
Original post by diginerd
My problem is that I don't know how to access the height values at the other texels inside the heightmap:
Here, if I'm correct is how to get H(i,j):
sampler2D texture;
vec4 heightAtThisPixel = texture2D(texture, gl_TexCoord[0].st);
I need to know how to get H(i+1,j), H(i-1,j), H(i,j+1), H(i,j-1).
Can someone please help me?
How about something like this?
uniform vec2 pixel; // set to vec2( 1.0/texture_width, 1.0/texture_height )

texture2D( texture, gl_TexCoord[0].st + vec2( pixel.x, 0) );
texture2D( texture, gl_TexCoord[0].st + vec2(-pixel.x, 0) );
texture2D( texture, gl_TexCoord[0].st + vec2(0, pixel.y) );
texture2D( texture, gl_TexCoord[0].st + vec2(0,-pixel.y) );

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this