Sign in to follow this  
littlekid

Can't understand Bump mapping

Recommended Posts

Hi, I am trying out some bump mapping and have went through some onlines tutorials and articles like Peter Germishuys tutorial. However I don't understand why are the normals from the normal map unpack using this formula? float3 Normal = 2.0f * tex2D(texSampler1, IN.tex1).rgb - 1.0f; And how do i get the Tangent, binormal, and normal to form the TBN matrix. Does it mean that each pixel will have its own TBN matrix since they will have different tangent, binormal and normal?

Share this post


Link to post
Share on other sites
well this formula
float3 Normal = 2.0f * tex2D(texSampler1, IN.tex1).rgb - 1.0f;
because colors ranges in 0..1 but you need a normal vector who range in -1..1 think of the range of the normal vector as a sphere ,if the range is 0..1 you will only use half of the sphere so the normal vector will never be negative (pointing backward ) , and for the second thing you can get the TBN matrix like this

float3x3 TBN
TBN[0]= mul(tangent,world);
TBN[1]=mul(binormal,world);//if you don't have binormal use cross(tangent,normal)
TBN[2]=mul(normal,world);
create the matrix in the vertex shader those normals tangents and binormal belongs to vertices not pixels , all you need from the pixel is the normal from the normal map , and the color from the color map , and maybe gloss from gloss map(for specular)

Share this post


Link to post
Share on other sites
Ahh I understand now, thanks.

But I still have some queries about the TBN matrix. A triangle has 3 vertex, thus when a pixel in the triangle goes through the pixel shader, which TBN matrix will it take from the 3 vertices?

Share this post


Link to post
Share on other sites
Quote:
Original post by littlekid
Ahh I understand now, thanks.

But I still have some queries about the TBN matrix. A triangle has 3 vertex, thus when a pixel in the triangle goes through the pixel shader, which TBN matrix will it take from the 3 vertices?


The same thing happens as with any vertex attribute. For example If each vertex was set to a different color, each pixel would be a color computed by interpolating the color at each vertex.

Similarly in the case of bump mapping, you supply a TBN Matrix at each vertex in the triangle as vertex attributes. Then for every pixel a specific TBN matrix is calculated by interpolating the TBN matrix at each vertex.



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