Depth Buffer Texture

Is there a way in the next version of panda to use the underlying API to get depth buffer textures. Its useful in a lot of algorithms and from what I understand a lot of cards support it.

There is a place to put the API for this, though it hasn’t actually been implemented yet. I assume you mean it is useful for pixel shader algorithms.


OK, turns out the code was mostly there already. I just checked in the last 2%.

tex = Texture()
buf ='buf', 256, 256, tex)


Using Panda 1.1.0 this works. But what is it returning? What percision is this? What are the values? When I use this texture in a shader it seems to give me a color from 0 to 1. So what is it scaled by?

I know using cg that tex2DProj(tex, float4) compares the 4th value with the value of buffer automatically if it’s a depth buffer. But somehow I don’t think this is happening as it is returning a the depth buffer color if you do o_color = tex2DProj(tex, tex_coord)

Is this wrong?

This “depth texture” is a copy of the Z-buffer. It contains clip-space Z values, rescaled from (-1, 1) to (0, 1). So in other words, if you extract the value from the depth texture, then multiply by two and subtract one, you have a clip-space Z value.

Just so you know, it’s possible to set up a window to render to two textures at the same time - a regular color texture, and a depth-texture. To do this, use “addRenderTexture”. The use of this function is demonstrated in the motion-blur sampler program.

David - Bei is a student at the ETC, he’s our most aggressive user of shaders. He’s written code that does true shadow maps, bumpmapping, and lots of fancy stuff. He’s a real resource.

  • Josh