# bumpmapping in glsl without using a pre-generated normal map

This topic is 3725 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
Quote:
 Original post by diginerdMy 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 on other sites
That worked very well. Thank you very much!

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 28
• 16
• 10
• 10
• 11
• ### Forum Statistics

• Total Topics
634111
• Total Posts
3015573
×