PerPixelLighting using NV_vertex_program & NV_register_combiners

You beautiful, beautiful person!
Thank you very, very, very much!!!
Looks lovely now. Jesus, what an idiot I am.

Ok, thanks to david, I have some nice per-pixel lighting with bump mapping.
You can peruse some images, and look at the vertex_program & register_combiner code here, if you’ve got too much time on your hands:-

(yes, I know I have some texture mirroring problems with tangent space)

Hello again. I’ve got another problem.
I’ve uploaded another image, showing the problem - it’s the top image in grey scale…

Can anyone suggest to me why the facets are so obvious?
This is how I calculate the tangents (same goes for binormals):-

for (every vertex)
set each vertex’s tangent vector to zero

for (every triangle)
calculate surface tangent
add this surface tangent to each of the 3 vertices tangent vector

for (every vertex)
normalise tangent vector

This should give me a tangent vector for every vertex which is the average of all the triangles that share that vertex.

I generate all 3 tangent space axis this way (normal/tangent/binormal)

Am I doing something wrong?

I don’t get right what you mean by :
for (every triangle)
calculate surface tangent
add this surface tangent to each of the 3 vertices tangent vector

my questions :
1- how do you “calculate surface tangent” ? There is a generic way for calculating normals (ie cross product) but what algorithm do you use for tangents ?
2- do you sahre your vertices in the whole 3D model ? or does each triangle have 3 vertices independently to its neighbourhood ?

Well, I use the standard way of calculating the tangent space vectors. I calculate the tangent vector from the 1st vertex in the triangle to the other 2 vertices, then add this ‘surface’ vector to the current vector contained in each vertices tangent.

Yes, all the vertices are shared.

1- but there is an infinite number of solutions. Which criteria do you use to get the tangent ?

2- if vertices are shared, then you should NOT see the facets, unless shading is flat. Did you call glShadeModel(GL_FLAT) or glShadeModel(GL_SMOOTH) ?

vincoof, the tangent in the same direction as the s-coordinate of the texture coords of the bumpmap…

ok, s for tangent and t (or -t) for the binormal. It will work fine with the square assumption which is almost perfect for the torus and not so good with the teapot. Anyway, I don’t think that’s where the problem is.

nope… i think your tangentspace is okay… how you calculate the to-light and to-eye vector?

The register_combiner and vertex_program code is on that web page I linked to (at the bottom). This shows how I calculate the vertex-to-light vector and halfangle vector.
Bizarre - I thought this would just click with someone who’s had the same problem. Maybe I need to look further back into my engine for the problem.

Among the things I don’t like about ARB_vertex_program:

  • XPD instruction.
  • Attribute aliasing not required.
  • Constant and attrib register file #-of-ports limitations not enforced.
  • Somewhat excessive queriability of certain things.
  • Insufficient precision/special case behavior guarantees.

Which is not to say that NV_vertex_program is perfect; there are also things that are better in ARB_vertex_program. (For example, on the last item, about precision/special case guarantees, I’d say ARB_v_p guarantees far too little, while NV_v_p guarantees far too much.)

You know, you guys crack me up. I actually thought about adding a comment that my arguments were equally valid for EXT_vertex_shader, that is, that since there are drivers that support EXT_vertex_shader but not ARB_vertex_program, you should actually have your app support all three of NV_v_p, ARB_v_p, and EXT_v_s. It’s probably a lot easier and cheaper to support all three than to take tech support calls from people who don’t understand what a “driver” is, much less what “ARB_vertex_program” is.

If I was writing an OpenGL game today, I’d probably make sure to support all three.

In fact, you could even take the argument further and say that for a game whose release date is not a long ways into the future, you’d be better off supporting NV_v_p and EXT_v_s and not ARB_v_p, just to reduce testing burden.

Geez… what I get for not having time to look at this board in a while.

  • Matt

inept: I’m sorry if I’m repeating myself, but your problem really looks like you called glShadeModel(GL_FLAT) instead of glShadeModel(GL_SMOOTH). Did you call one of these ?

No, it’s definately glShadeModel(GL_SMOOTH).