I would like to replicate standard opengl's lighting calculation using vertex programs to modify the lightings color selecting. Instead of just linear interpolation between two vertices colors I would like to use a 1d texture map as a gradient(perhaps a 2d texture for additional specular gradients).
Texture coordinates would index the texture.
this would also be useful for doing toon shading. I tried it but i had some problems.
My goal is to use vertex and vertex state programs as easy and functional as gllightf...

I tested it in a program where I could switch between opengl lighting and vertex program lighting, but I recognized that both results were unequal.the light moved with the scene but when i rotated the scene the diffuse lighting changed, wether i wanted to stay the object const within my scene space.

tracking of MODELVIEW_PROJECTION
MODELVIEW
MODELVIEW, INVERSE_TRANSPOSE
in the vertex state program i do following

matrix multiplication program paramter v[0] with modelview matrix and storing it in constant register

the vertex program
matrix multiplication v[OPOS] with MODELVIEWPROJECTION and storing it in o[HPOS]

matrix multiplication v[OPOS] with MODELVIEW and storing it in a temporary register

Maybe you should show us the actual vertex program and the rest of your code rather than this pseudo-code. The actual bug is likely not in the code you've given us.

ScottManDeath

01-03-2002, 08:58 AM

[Hi

you are right, pseudo code seems not be very helpful
here are the important parts of my code.

I changed the light calculation form eye space to object space.

The vertex state program transform the light position v[0]
using the tracked modelview matrix temporary into eye space.

The vertex program uses the light position and converts it into object space by
applying the current inverse modelviewmatrix. then the diffuse dot product is
calculated by dotting the vertex' normal with the (normalized)vertex light vector
Now diffuse lighting works as espected. because I specified the lights psosition in the
current scene view space it stays as I move and rote the view .

For the specular part I have a problem. the specular highlight moves when I move the light or the object but not when
I rotate my scene view??

If all you want is a custom diffuse lighting solution, it's much easier to do that using NORMAL_MAP texgen mode and the appropriate texture matrix.

ScottManDeath

01-03-2002, 11:46 PM

Originally posted by jwatte:
If all you want is a custom diffuse lighting solution, it's much easier to do that using NORMAL_MAP texgen mode and the appropriate texture matrix.

Hi
that sounds interesting, what is that exactly. Which extension has to be used ?
This would be sufficient for diffuse lighting but what can I do for specular lighting ?

Bye
ScottManDeath

jwatte

01-04-2002, 12:16 PM

NORMAL_MAP texgen is a standard part of OpenGL 1.3 and later; it's part of the cubemap extension before that. You can set up the texture matrix to collapse the 3 coordinates to a 1D texture; you don't need to bind a cube map texture just because you're using NORMAL_MAP texgen mode.

I believe that the reflective environment map mode _might_ be used for specular with the right incantations, but I haven't delved into the math to see if that's right or not. Intuitively, you'd use the same trick of collapsing a 3D texture vector into a 1D texture using the matrix, and rotate that matrix by the half angle vector, perhaps?