Jump to content
  • Advertisement
Sign in to follow this  
cannonicus

Accessing Stencil/Depth buffer from pixelshader

This topic is 4775 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello Is it possible to (efficiently) read/write to the Stencil/Depth buffer from inside of a pixelshader? How is that done? //Emil

Share this post


Link to post
Share on other sites
Advertisement
Mebbe turning off colorwrite and putting out the homogenous (or whatever it is called when you multiply a vertex in object space by the wvp matrix) depth in the 4th component of the position output from vertex shader.
That is interpolated for the pixels but you can't write it yuself in the pixel shader.
Hope that helps

Share this post


Link to post
Share on other sites
If you only need to check if the stencil (or z) is larger than a certain amount, or smaller, or equals, you could use simple stencil testing (this takes a full pass per value you want to check).

If you need to actually read a specific value from it, this wouldn't be the way to go.

Share this post


Link to post
Share on other sites
ok, what im trying to do is to have a texture with some parts of it 100% transparent. It would be nice to have my pixelshader preventing values from beeing entered to the z-buffer where the texture is invisible.

But your saying this is impossible?

Share this post


Link to post
Share on other sites
Quote:
Original post by superpig
Just use alphakill for that.


Wrong platform [wink]

I suspect superpig means "alpha test" or "tex kill"

Share this post


Link to post
Share on other sites
Quote:
Original post by DrGUI
I know there's an instruction like that in asm, but is there something in HLSL?


Yep, that's what the clip() intrinsic does.


Re reading cannonicus's second comment: "It would be nice to have my pixelshader preventing values from beeing entered to the z-buffer where the texture is invisible."

Alpha test can be used for that: it tests the alpha value of the colour output from the pixel shader against a constant reference value (D3DRS_ALPHAREF) using a comparison function (D3DRS_ALPHAFUNC); if the alpha value fails the comparison, the pixel is discarded **before the Z buffer write takes place**

[Alphakill fits the OPs full description even more closely, but that isn't available on PC hardware]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!