ScottManDeath
01-02-2002, 01:01 PM
Hi
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...
for example standard t&l:
// scene positioning
// local viewer, local light, no attenuation
glLoadIdentity();
glTranslatef(scene pos)// based upon user input
glRotatef(scene rot)// -""-
// light in object coorinates
glLightf(light position)
...
...
// draw some object
glPushMatrix()
glRotatef(object yrot ...)
glutSoloidTeapot
glPopMatrix();
// another object
glPushMatrix()
glTranslatef(object pos ...)
glutSoloidTeapot
glPopMatrix();
using vertexprograms:
scene and object positioning using matrices
glLoadIdentity();
glTranslatef(scene pos)// based upon user input
glRotatef(scene rot)// -""-
// light in object coorinates
//using vertex state program to calc lights eye coordinates using current modelview matrix
glExecuteProgramNV(...,lightpos);
...
...
glEnable(GL_VERTEX_PROGRAM_NV);
glEnable(GL_TEXTURE_2d);
// draw some object
glBindTExture(material one gradient)
glPushMatrix()
glRotatef(object yrot ...)
glutSoloidTeapot
glPopMatrix();
// another object
glBindTExture(material two gradient)
glPushMatrix()
glTranslatef(object pos ...)
glutSoloidTeapot
glPopMatrix();
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
matrix mult v[NRML] with MODELVIEW_INVERSE_TRANSPOSE
set length to 1
vector vertex --> light
set length to 1
dot product normal with vertex-->light vector
use as o[TEX0].x // 1D texture clamping active; GL_DECAL environment linear (greyscale)gradient -> should be equal do standard opengl t&l
Can anyone help ??
ScottManDeath
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...
for example standard t&l:
// scene positioning
// local viewer, local light, no attenuation
glLoadIdentity();
glTranslatef(scene pos)// based upon user input
glRotatef(scene rot)// -""-
// light in object coorinates
glLightf(light position)
...
...
// draw some object
glPushMatrix()
glRotatef(object yrot ...)
glutSoloidTeapot
glPopMatrix();
// another object
glPushMatrix()
glTranslatef(object pos ...)
glutSoloidTeapot
glPopMatrix();
using vertexprograms:
scene and object positioning using matrices
glLoadIdentity();
glTranslatef(scene pos)// based upon user input
glRotatef(scene rot)// -""-
// light in object coorinates
//using vertex state program to calc lights eye coordinates using current modelview matrix
glExecuteProgramNV(...,lightpos);
...
...
glEnable(GL_VERTEX_PROGRAM_NV);
glEnable(GL_TEXTURE_2d);
// draw some object
glBindTExture(material one gradient)
glPushMatrix()
glRotatef(object yrot ...)
glutSoloidTeapot
glPopMatrix();
// another object
glBindTExture(material two gradient)
glPushMatrix()
glTranslatef(object pos ...)
glutSoloidTeapot
glPopMatrix();
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
matrix mult v[NRML] with MODELVIEW_INVERSE_TRANSPOSE
set length to 1
vector vertex --> light
set length to 1
dot product normal with vertex-->light vector
use as o[TEX0].x // 1D texture clamping active; GL_DECAL environment linear (greyscale)gradient -> should be equal do standard opengl t&l
Can anyone help ??
ScottManDeath