Advertisement

Dot3 Bump mapping

Started by July 25, 2004 06:58 AM
3 comments, last by JazzD 20 years, 4 months ago
Hey guys, I always wanted to get dp3 bump mapping into my engine. So I looked at a lot tutorials and I never really understood how to realize that in my engine. On Friday I found an example on Ati's developer page called "simple Dot3 bump". I was able to insert their effect into my engine. And here is the first result: You get the tutorial here: http://www.ati.com/developer/sdk/RADEONSDK/Html/Samples/OpenGL/RADEONSimpleDOT3.html Anyway it works quite well, i didn't think i was able to get it done there. But there is one thing I don't really get. As they only use the bump mapping on one quad in there application they have a static tangent matrix. When I want to texture a cube like in my screenshot I need a tangent matrix for the face. Well I already have the face normal, how would I calculate a tangentMatrix for the current face that im using bump mapping on?

static GLfloat tangentMatrix[16] = {1.0, 0.0, 0.0, 0.0,
                                   0.0,1.0, 0.0, 0.0,
                                   0.0, 0.0, 1.0, 0.0,
                                   0.0, 0.0, 0.0, 1.0};
As you can see that's the ident matrix they use for a simple quad, looks very simple and has only one side that can be textured. Anyway I just need to calculate a matrix like that for my face. Would be nice if somebody was able to explain this to me :). Thanks guys!
www.prsoftware.de
The idea behind a tangent space is to represent the way the texture is applied to the face.. In this case it's pretty simple, hence the identity matrix.

If, though, you were to mirror the _texture_coordinates_ vertically, the the lighting would flip vertically as well, in this case the tangent space matrix would need to be scaled by 1,1,-1..

That, however, is just a really simple example. As this is a world space problem, then the only case an identiy matrix will be correct is extremly rare.

Rotate your quad around any axis, and bang, the lighting won't be correct anymore. So the tangent space needs to change (and by rotate the quad, I don't mean glRotate - I mean changes in vertices)

So as you said you need to generate tangent spaces. Usually per vertex (think of a non-trivial example like a player model), that doesn't use flat triangles (flat shading)...

A per-quad matrix isn't ideal. Per-vertex matrices are better, but also not quite ideal. The main reason is that you already have part of this matrix (the vertex normal) - and it's only a 3x3 matrix since it's just rotation. Also - unless the texture is scewed or mirrored, then the matrix will always be a rotation of the identity, so the final axis can be computed by cross-product.. Meaning you only need 2 vectors for the tangent space - the normal, and either U or V texture space direction. The other can be computed in a vertex shader.

have a look in this thread on the second page for a reply I did about bump mapping using tangent spaces.

As for actually calculating the tangent space vectors, you need to know what they are first, which I'm not sure you do.. In which case it's fairly dependant on how you actually store your world data. But it pretty much comes down to calculating U/V tangents for each triangle in the world, then adding those to each vertex one by one, then normalizing the vertex U/V coords, and creating a final tangent vector, similar to the vertex normal. (usually a 4float vector, with w being a -1/1 scaler)

It's complicated.
No, It's extremly complicated.

but it's by no means impossible.

You just need to know _exactly_ what the maths is doing. Otherwise you won't be able to understand whats happening when what is rendered is not what you expect..

As for resources on generating tangent space vectors, google it and you almost always find stuff, but as I've said it's no use unless you know exactly what they are.

yeah.

I would repeat myself a few more times but I'm lazy. :)
Advertisement
Hey JazzD ;).

Where'd you learn how to do bump-mapping? I haven't been able to find a good tutorial on it, although I admit I haven't tried too hard :).
Quote: Original post by baldurk
Hey JazzD ;).

Where'd you learn how to do bump-mapping? I haven't been able to find a good tutorial on it, although I admit I haven't tried too hard :).


It's perhaps a little dated, however I still think that "A Practicle and Robust BumpMapping Technique for Todays GPU's" by Mark Kilgard ( nvidia dev site ) is a brilliant paper. It uses register combiners, and the implementation is basically for a Geforce(2). The theory and mathematical background is still perfectly valid however, and this paper explains it thoroughly and well.
If at first you don't succeed, redefine success.
thanks for the great information, and baldurk, look at the ATI link I posted up there. Then you got paulsprojects and ronfrazier.net, I hope that's right, they have some information about ppxl and dp3.
www.prsoftware.de

This topic is closed to new replies.

Advertisement