Jump to content
  • Advertisement
Sign in to follow this  
diginerd

bumpmapping in glsl without using a pre-generated normal map

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

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!