PDA

View Full Version : Something Strang with ARB_vertex_program on GF4 Ti



ze.destroy
02-11-2003, 01:25 AM
I've already written some vertex programs but only with NV_vertex_program and i would try to code with the ARB_vertex_program after reading the nvopenglspec.pdf !
I tried to code a very simple program which was supposed to calculate diffuse lighting with only N dot L in model space and eye space by using the state.matrix.modelview but without success !
I've passed in "local param" or "env param" the light in model space and the illumination works well ! So my problem is the state.matrix.modelview.inverse which doesnt seem to do HER job !!!

here the vertex program :

!!ARBvp1.0
ATTRIB iPos = vertex.position;
ATTRIB iNrml = vertex.normal;
PARAM mvp[4] = { state.matrix.mvp };
PARAM inv_mv[4] = { state.matrix.modelview.inverse };
PARAM eLight = program.local[0]; # eye space light
TEMP mLight;
OUTPUT oPos = result.position;
OUTPUT oCol = result.color;


DP4 oPos.x, mvp[0], iPos;
DP4 oPos.y, mvp[1], iPos;
DP4 oPos.z, mvp[2], iPos;
DP4 oPos.w, mvp[3], iPos;

# light in model space
DP3 mLight.x, inv_mv[0], eLight;
DP3 mLight.y, inv_mv[1], eLight;
DP3 mLight.z, inv_mv[2], eLight;

# vector L = l - vertex
SUB mLight, mLight, iPos;
DP3 mLight.w, mLight, mLight;
RSQ mLight.w, mLight.w;
MUL mLight.xyz, mLight.w, mLight;

DP3 oCol, mLight, iNrml;

END

Please help me, i want to sleep !
http://www.opengl.org/discussion_boards/ubb/confused.gif

[This message has been edited by ze.destroy (edited 02-11-2003).]

Tom Nuydens
02-11-2003, 01:36 AM
If you want to transform something from eye space back to model space, you have to multiply it with the entire inverse modelview matrix, not just with the first three rows and columns like you do here.

-- Tom

ze.destroy
02-11-2003, 01:41 AM
I've just tested it but without success !
My method works when i pass in parameter the inverse modelview matrix !

any idea ? or correction ?

Tom Nuydens
02-11-2003, 02:02 AM
I quickly tried modifying your vertex program so that it multiplies the vertex with both the modelview matrix and its inverse, in addition to the concatenated MVP matrix which was already there. The results were unchanged. Hence, the inverse matrix has to be correct.

Are you sure you don't have a math error somewhere? What you're doing sounds very unintuitive to me -- why would you want to go back from eye space to object space just to do simple lighting like this? Keep everything in the same space and you won't need to invert any matrices.

-- Tom

ze.destroy
02-11-2003, 02:09 AM
i've already tried to compute the normal and the vertex in eye space by multiplying with the inverse transpose modelview and the modelview respectively without success !
It's just a test to understand how it works, nothing at all !

this program works :

!!ARBvp1.0
ATTRIB iPos = vertex.position;
ATTRIB iNrml = vertex.normal;
PARAM mvp[4] = { state.matrix.mvp };
PARAM mv[4] = { state.matrix.modelview };
PARAM it_mv[4] = { state.matrix.modelview.invtrans };
PARAM eLight = program.local[0]; # eye space light
TEMP ePos, eNrml, eL;
OUTPUT oPos = result.position;
OUTPUT oCol = result.color;


# vertex in eye space
DP4 ePos.x, mv[0], iPos;
DP4 ePos.y, mv[1], iPos;
DP4 ePos.z, mv[2], iPos;

# normal in eye space
DP4 eNrml.x, it_mv[0], iNrml;
DP4 eNrml.y, it_mv[1], iNrml;
DP4 eNrml.z, it_mv[2], iNrml;

# vector L = l - vertex
SUB eL, eLight, ePos;
DP3 eL.w, eL, eL;
RSQ eL.w, eL.w;
MUL eL.xyz, eL.w, eL;

DP3 oCol, eL, eNrml;

DP4 oPos.x, mvp[0], iPos;
DP4 oPos.y, mvp[1], iPos;
DP4 oPos.z, mvp[2], iPos;
DP4 oPos.w, mvp[3], iPos;

END

Thanks for your fast answers !

[This message has been edited by ze.destroy (edited 02-11-2003).]

ze.destroy
02-11-2003, 03:03 AM
I've found the problem when i called glProgramEnvParameter4fARB i pass in parameter the light in x, y, z and w at 0 !!!
DAMNED !!! i need some sleep thanx for yout help !

Nutty
02-11-2003, 04:24 AM
Hehehe.. same thing got me a while back too.. most annoying.