Jump to content
  • Advertisement
Sign in to follow this  
cyrfer

stencil mask without depth test?

This topic is 2567 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

Hi,
I'm new to using the stencil buffer. Does it make sense / is it possible to mark pixels where my scene geometry is rendering so that I can do a (later) post-process pass affecting only those pixels marked (or conversely, the other pixels)? Because my post-process pass just needs to check if the stencil was marked, can I disable depth-testing? Does it make sense to do stencil tests without depth testing enabled?

If it is possible to mark and check for marked pixels, what operators should I use to mark the stencil buffer, and then read if it was marked? I was thinking about:
[clear pass]
stencil value = 0

[scene pass]
comp_func = always_pass
pass_op = replace
reference_value = 1


[post-process fill pass]
reference_value = 0
comp_func = greater // if greater than 0, shader will affect this pixel
//[converse situation]reference_value = 1
//[converse situation]comp_func = less // if less than 1, shader will affect this pixel
pass_op = keep // does this matter since this is my last pass?

Thanks for any help!

Share this post


Link to post
Share on other sites
Advertisement
Yes, it's totally legit to use stencil writes when depth tests/writes are disabled. Your plan for rendering masked pixels also looks fine. Later on if you have more things in the stencil buffer, you can also look into using read masks to make sure you only read the bit you're interested in when doing your post-process pass.

Also if you do need to enable depth test and still want to write stencil even for pixels where depth fails, you can set the depth-fail stencil op to the same as your stencil op and it will still write the ref value for all pixels.

Share this post


Link to post
Share on other sites
Sure, its how we excluded noise alpha-masked objects (foliage, chain link fences etc) from getting edge detection applied to them in Borderlands.

Just make sure depth or stencil writes are off when doing the tests (or you wont get the early reject at all)

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!