shadows + vertex program + homogeneous divide

i implemented shadow volumes like nvidia proposed with w=0 to project the extruded vertices at infinity and using degenerated edges polys with vertex programs in mind.

now doing all on the cpu works fine… but when i used vertex programs for the task, i get some bugs due to the homogenous divide.

maybe someone more experienced with vertex programs can help me a bit…

PARAM mvp[4] = { state.matrix.mvp };
PARAM lightPos = program.env[0];
0.0}; # (object space)
PARAM zero = {0.0, 0.0, 0.0, 0.0};

ATTRIB vertexPos = vertex.position;
ATTRIB vertexNormal = vertex.normal;

OUTPUT oPos = result.position;

TEMP temp;
TEMP len;
TEMP res;
TEMP extrudedVertex;
TEMP toLight;
TEMP dot;

tolight = light - vertexpos

ADD toLight, lightPos, -vertexPos;

normalize tolight

DP3 temp, toLight, toLight;
RSQ len, temp.x;
MUL toLight, toLight, len;

dot = toLight . normal

DP3 dot, toLight, vertexNormal;

if(0 < dot) w = 0 else w = 1 (reverse extrude)

SLT w, zero, dot;

extrudedVertex = vertexPos - (w * lightpos)

MAD extrudedVertex, w, -lightPos, vertexPos;

extrudedVertex.w = w (set w=0)

MOV extrudedVertex.w, w.x;

transform vertex to clip coords

DP4 res.x, mvp[0], extrudedVertex;
DP4 res.y, mvp[1], extrudedVertex;
DP4 res.z, mvp[2], extrudedVertex;
DP4 res.w, mvp[3], extrudedVertex;

homogeneous divide

RCP temp.w, res.w;
MUL oPos, res, temp.w;


now if i do not divide by w=0 and scale the extrusion by some factor (not included above) it works as expected… so i think its something wrong with my way of doing the homogenous divide…

as i’m pretty lost now i hope someone can help! thanks in advance…


(sorry for any inconveniences due to posting this twice…)

’ 0.0}; # (object space) ’

should be removed of course… ! (lightPos is in objectspace)


A couple of questions:

Why are you doing the homogeneous divide?

Are you doing inifinite projection?
If so, it seems that you should be computing “ = w * vertexPos + (1-w) * (-tolight)” and “newpos.w = w.w”.
Then you just transform newpos by the MVP and you’re done.

Thanks -

thank you! i think i got something in my brain there… :>

insert “wrong”