Archived

This topic is now archived and is closed to further replies.

carlshe

How to render zbuffer to texture (Maybe OK)

Recommended Posts

I look up the way everywhere. Does any expert know how to render zbuffer to a texture? Thanks£¡ [edited by - carlshe on March 20, 2004 10:54:57 AM]

Share this post


Link to post
Share on other sites
It can be done to render a 3D scene to a texture.

but it seems no support to create a texture with Format of D32 or D16 (C#), which therotically is used as depth buffer.

Share this post


Link to post
Share on other sites
The idea is fired by a PDF located on:
http://developer.nvidia.com/docs/IO/8230/D3DTutorial_EffectsNV.pdf

Maybe the way is found. With ATI RenderMonkey I do some experiment. I think it will be easy to integrate it into program.

with VertexShader, the depth value can be encoded as RGB Color (COLORn) and then be returned as input to PixelShader. you shouldn't do any more process on that color inside PixelShader and then it can be rendered to render target which can be read, saved or ....

The key step is to compute depth for each vertex based on vertex position inside VertexShader.

1. computing depth value
2. encode depth into RGBA value as COLORn and return it as part of return value.

ok. it seems work.

Although it is a bit complicated but maybe it is the best way I found till now.



[edited by - carlshe on March 20, 2004 10:53:59 AM]

[edited by - carlshe on March 20, 2004 10:54:19 AM]

Share this post


Link to post
Share on other sites
Ok. I see what you''re trying to do. But you seem to have alredy figured out how to do it. Just in case, here''s how:

In your vertex shader, apply the world-view-proj transform. Your vertices are now in homogenous clip space. More importantly, the depth values are now [0..1]. Take this single depth value and output it as a color. You can either replicate the same depth value across all chanels of the color, or you can do something smart to split up the depth value and encode it across multipe channels of the color. It all depends on how much precision you need.

neneboricua

Share this post


Link to post
Share on other sites