Skip to main content
GameDev.net gamedev.net
🔒 Locked

Stencilbuffer in Pixelshader

Started by cannonicus Aug 31, 2006 at 4:01 PM 4 replies 2.1k views
Original Post
cannonicus
cannonicus
Hello Is it possible to use a texture of format D3DFMT_D24S8 in a pixelshader? If so how will I access the depth/stencil data in the texture? Something like this?


//HLSL shader code

sampler Tex;
sampler DSTex;

...

vector ds = tex2D(DSTex, coord);

float depth = ds.r;   //This is the part im unsure about
int stenval = ds.b;




I am particularly interested in the stencil value, since thats what im planning to use. Thanks //Emil [Edited by - cannonicus on September 1, 2006 5:14:41 AM]
Emil Jonssonvild
ET3D
ET3D
There are some (chip dependent) ways to get depth data, but I don't know of a way to get stencil.
cannonicus
cannonicus
Are you sure?

I know there are no general ways of accessing the data of the current depth/stencil buffer, but thats not what im trying to do. Im passing a texture of format D3DFMT_D24S8 (which was used as depth/stencil buffer in an earlier rendering pass) to the pixel shader though multi-texturing, and thus accessing the data in this texture should be as simple as accessing any texture.

I thought that was possible but perhaps i was wrong.

//Emil
Emil Jonssonvild
ET3D
ET3D
I'm assuming that you're using NVIDIA hardware, because you can't create D3DFMT_D24S8 textures on other cards (or on the REF device, for this matter, which tells you that it's very much proprietary). On NVIDIA hardware, accessing such a texture has special meaning (i.e., is a hack): it compares the Z value in the texture with the Z value of the pixel. It doesn't actually return the Z value.

ATI hardware supports a way to define a depth texture that can be read in a pixel shader, but that doesn't include stencil.
cannonicus
cannonicus
Ok, to bad. Thanks for your help anyway.

I really need to buy a book on direct3d whose title doesnt include the words "beginning" or "for dummies"...

//Emil
Emil Jonssonvild
ET3D
ET3D
I'd suggest reading docs available on ATI's and NVIDIA's sites, and books like the ShaderX series and GPU Gems series (quite a few articles from them are available on NVIDIA's and ATI's sites).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.