View Full Version : Writing to depth buffer within fragment program

09-01-2004, 01:02 PM

I have a gray scale texture which is being applied to an object. When the gray scale texture is rendered, I want it to also render into the depth buffer. I wrote the following fragment program to accomplish this:

TEMP tex0;

TEX tex0, fragment.texcoord[0], texture[0], 2D;

MOV result.depth, tex0.r;
MOV result.color, tex0;

ENDI tried this but it seems like any color that isn't 100% white is being written to the very front of the zbuffer.

I'm assuming that the values written to result.depth are not linearly mapped into the actual zbuffer. Does anybody know how to tranform the texture color so that it fits linearly into the zbuffer?

I've set the depth range from 0 to 1. I've also set the near and far clip planes to 0.1 and 100.

Thanks in advance,


09-01-2004, 02:55 PM
these chapters from the red book describe opengl transformations:

09-01-2004, 03:01 PM
also, a search cant hurt: