Markus-

04-12-2003, 05:17 PM

hi..

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 as 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;

TEMP w;

# 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;

END

-----------------

now if i do not divide by w and scale the extrusion (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..

-Markus

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 as 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;

TEMP w;

# 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;

END

-----------------

now if i do not divide by w and scale the extrusion (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..

-Markus