PDA

View Full Version : Writing to depth buffer within fragment program



farshizzo
09-01-2004, 01:02 PM
Hi,

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:
!!ARBfp1.0

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,

Farshid

09-01-2004, 02:55 PM
these chapters from the red book describe opengl transformations:
http://fly.cc.fer.hr/~unreal/theredbook/chapter03.html
http://fly.cc.fer.hr/~unreal/theredbook/appendixg.html

09-01-2004, 03:01 PM
also, a search cant hurt:
http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;f=3;t=012358