PDA

View Full Version : Questions on Depth buffering and fragment shader



Aaron
01-29-2007, 07:05 AM
I have a OpenGL program using a Z buffer for hidden surface removal with a Cg vertex and fragment shader. In the fragment shader, I added some code to pass the fragment depth, ex:

...
OUT.color = IN.color;
OUT.depth = IN.depth;
return OUT;
}

When I ran the code, the Z buffer acted as disabled. When I do not pass the depth, the resultant image is correct. When I pass the depth, did I effectively disable Z buffering?

In the Cg book it says if I do not overwrite the DEPTH the fragment shader just passes the depth value through.

Is there a away using single pass rendering that the fragment shader can access the pixel color and depth stored in the frame buffer to implements its own blending? Or is the alpha blending a pure hardware implementation so it cannot be done?

Thanks,

Aaron

zeoverlord
01-29-2007, 08:13 AM
I have no experience in cg as i use glsl, but i think they work the same.
Basically OUT.depth will override any previous value, so if you don't want to mess with the z-buffer, then leave it alone.

The simplest hidden surface removal method is simple to implement without using shaders
1. disable shaders/textures, mask out all colors and render all polygons
2. enable whatever shaders/textures you need, unmask the colors and render the scene normally.

k_szczech
01-29-2007, 12:43 PM
Is there a away using single pass rendering that the fragment shader can access the pixel color and depth stored in the frame buffer to implements its own blending?No. Shaders only provide color and depth value that will be used in depth testing, alpha testing and alpha blending. They do not override these operatoins. Neither do they affect stencl test.

Aaron
01-30-2007, 03:13 AM
Thanks for the information.