PDA

View Full Version : Dot3 vertex colors



halo
05-21-2006, 06:13 PM
Given a light source position, vertex position, and vertex normal, how do I calculate the rgb value to store in the color array for that vertex, for use with dot3 bumpmapping? I can do the calculations, but they don't really take the texture mapping into account. If the texture is flipped on one face, it will get incorrect values that result in odd normal mapping.

dorbie
05-21-2006, 10:05 PM
Well there's no standard way of doing this, the point is to support the same space in your vertex colors in tangent or object space that you do in your normal map, and derivatives of texture.

Things like mirroring can require an axis flip (because derivatives have been flipped).

Just be consistent and set up a simple test case to make sure you can get it right or at least can tweak your code until you do get it right.

halo
05-21-2006, 11:06 PM
I think the only possible way to do this must be to find another vertex this vertex connects to, and construct vectors from their positions and tex coords, then somehow construct a matrix from that. This is not a simple task. I was hoping that maybe there was a simpler method.

Humus
05-22-2006, 12:19 PM
Are you basically asking how to compute the tangent space? If so, I have some code for that in my framework:
http://www.humus.ca/index.php?page=3D

halo
05-25-2006, 10:10 AM
On brushes, this is easy, because they have texture mapping axes and a face normal. On arbitrary triangle meshes, it is a little more difficult. How do you usually set this up on arbitrary triangle meshes?

jide
05-25-2006, 10:19 AM
Well, at least as far as I know, you can't do any tangent space without having both normals and texture coordinates.

halo
05-25-2006, 10:42 AM
Right, of course you have normals and texcoords for each vertex in the triangle mesh. But it is quite a bit more complex than just setting it up for a flat coplanar surface with known texture mapping axes.

CrazyButcher
05-25-2006, 12:16 PM
http://www.terathon.com/code/tangent.html

works fine, however be aware that using mirrored UVs will create problems, needs some special preparation.
the meshmender lib from nvidia can take care of that (I am sure there is other libs too)

halo
05-25-2006, 02:14 PM
Cool, that looks pretty simple. Thanks.