View Full Version : Bump Mapping

Keenan Crane

05-04-2003, 12:13 PM

Here's what I'm doing to get bump mapping, but I'm not getting very good results -

-make a heightmap

-process it with nVidia's normalgen to get a normal map (and load it into my program)

-multiply the light vector by the inverse of the modelview matrix to get it into object space

-for each vertex, find the vector from the vertex to the transformed light vector

-normalize this new vector

-convert this vector into tangent space by multiplying by

[1, 0, 0, 0]

[0, -1, 0, 0]

[0, 0, 1, 0]

[0, 0, 0, 1]

-store the vector in the color value of the vertex

-then in my fragment program :

*sample the normal map into r0

*put dot product of r0 and color0 into r0

Most of my method is from following the ATI example on DOT3 bump mapping. It looks somewhat bumpy, but it looks like the light is coming from the wrong side and much of the time it looks very flat.

Any ideas?

Thanks,

Keenan Crane

kcrane@uiuc.edu

[This message has been edited by Keenan Crane (edited 05-04-2003).]

knackered

05-04-2003, 01:19 PM

-convert this vector into tangent space by multiplying by

[1, 0, 0, 0]

[0, -1, 0, 0]

[0, 0, 1, 0]

[0, 0, 0, 1]

What do you mean by this?

Why are you multiplying it by this matrix? Your object would have to be a single plane pointing back through the y axis, is this correct?

You need to construct the TBN (tangent/binormal/normal) matrix from the particular triangles that share that vertex (their normal vector, tangent vector and binormal vector).

Does any of this ring any bells? Or are you just blindly copying code from the ATI demo without knowing what the code does? (in which case, shame on you http://www.opengl.org/discussion_boards/ubb/smile.gif )

Keenan Crane

05-04-2003, 03:31 PM

You're right, I did just copy that part.

Here's what I'm doing now instead -

I'm doing all flat polygons (on a cube) so I say

tangent_vector = current_face.vertex0 - current_face.vertex1

binormal_vector = current_face.vertex0 - current_face.vertex2

normal_vector = crossproduct(tangent_vector, binormal_vector)

normalize(tangent_vector)

normalize(binormal_vector)

normalize(normal_vector)

and those vectors become my matrix to change the basis of the light vector (i.e., the vector from the vertex to the light in object space) into the tangent space of the current face (I find the change of basis matrix once for each face).

Still doesn't look right, however.

[This message has been edited by Keenan Crane (edited 05-04-2003).]

I can't say I know very much about bump mapping but according to mathworld the Binormal is...

B = T x N (See here) (http://mathworld.wolfram.com/BinormalVector.html)

Would that mean that the angle between B, T and N must be 90 degs? If so, would (could) there be a flaw in using vertices 0, 1 and 2 for your calculations? (I could be way off track here)

If your sides are created using quads then your binormal will end up being 45degs (for a perfect cube) from your tangent. If the binormal has to be 90degs then recalc the binormal as TxN and maybe that'll help.

Zengar

05-05-2003, 02:40 AM

Your tangent and binormal are wrong. This vectors represent texture axes(u, v or s, t). Look at gamedev.net cg bumpmapping tutoral to see how to compute them.

Keenan Crane

05-05-2003, 04:11 AM

Ah, that must be it - I thought I was using orthogonal edges but now I realize my vertex numbering isn't consistent (i.e., sometimes v1 and v2 are opposite, sometimes they're adjacent). Of course, this is a bad way to do it in general since I won't usually have orthogonal edge vectors. I'm guessing the gamedev article tells you to do Gram-Schmidt on the edge vectors (starting with the normal vector)? That should always work (I think?), but I'll take a look at the article.

Thanks again,

Keenan Crane

[This message has been edited by Keenan Crane (edited 05-05-2003).]

Zengar

05-05-2003, 05:44 AM

I don't know who is Graham Schmidt, so I can say neither yes nor no. The whole thing is, you should compute this vectors(tangent etc.) with respect to texture coordinates. Tangent space, or texture space(in this case) is matrix that maps texture onto your polygon. I'm not so good at vector math. But I managed it to work...

bakery2k

05-05-2003, 06:38 AM

He means Gram-Schmidt, the Orthonormalization process.

Look at the addendum to this tutorial to see how I compute the TBN matrix:

http://users.ox.ac.uk/~univ1234/tutorials/simplebump/simplebump.htm

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.