## Sure… The shader I use to place the depth into the color buffer is this:

!!ARBfp1.0

TEMP dist;

MUL dist, fragment.position.z, fragment.position.w;

MUL result.color,dist, 100;

## END

## The vertex program for drawing the scene is this one: ( I’ve taken out all of the operations that don’t deal with lighting, bump/spec/paralax mapping to make it easier)

!!ARBvp1.0

OUTPUT smTexCoord = result.texcoord[5];

PARAM mvp[4]= {state.matrix.mvp};

PARAM mv[4] = {state.matrix.modelview};

DP4 result.position.x,vertex.position,mvp[0];

DP4 result.position.y,vertex.position,mvp[1];

DP4 result.position.z,vertex.position,mvp[2];

DP4 result.position.w,vertex.position,mvp[3];

DP4 smTexCoord.x,vertex.position,mv[0];

DP4 smTexCoord.y,vertex.position,mv[1];

DP4 smTexCoord.z,vertex.position,mv[2];

DP4 smTexCoord.w,vertex.position,mv[3];

## END

## The fragment program for renering w/ shadow map is: (‘smMatR*’) are the columns of the texture matrix that I compute outside of the fragment program.)

!!ARBfp1.0

PARAM smMatR1 = program.local[3];

PARAM smMatR2 = program.local[4];

PARAM smMatR3 = program.local[5];

PARAM smMatR4 = program.local[6];

ATTRIB smTexCoord = fragment.texcoord[5];

TEMP shadowDist, dist;

DP4 tempResult.x, smMatR1,smTexCoord;

DP4 tempResult.y, smMatR2,smTexCoord;

DP4 tempResult.z, smMatR3,smTexCoord;

DP4 tempResult.w, smMatR4,smTexCoord;

#texture[4] is the PBuffer depth tex

TXP shadowDist, tempResult, texture[4], 2D;

MUL dist,fragment.position.z, fragment.position.w;

MAD dist, dist, 100, .1;

SGE shadowDist, dist, shadowDist;

## …etc…

The texture matrix is:

texMat = scaleBias * lightProj * lightMV * modelViewInv;

Where the scaleBias is

[ .5 0 0 0 ]

[ 0 .5 0 0 ]

[ 0 0 .5 0 ]

[ .5 .5 .5 1 ]

If it would help, I will post how I compute all of the matricies, and/or example values for various positions.

Thanks,

Mike