Stencil buffer question

Mintmaster

Veteran
Hi 3D experts, I've got a puzzle I can't figure out, and don't know if it's possible.

I want to set the stencil buffer renderstates so that I draw a fullscreen quad, and every non-zero stencil value now get set to 0x02.

Basically, I've stenciled out an area using shadow volumes, and so there are now areas with values greater than one depending on how many shadows overlap. I want to now set all areas with at least one shadow to the same value.

It seems like such a simple task, but I can't see the solution since there's only one reference value. Can anyone else figure it out?

EDIT: Well, in my particular case I found a solution, but it sort of sucks. I can set the reference to 0x01, use function LESS & stencilop REPLACE, then do a second pass with function EQUAL & stencilop INCR. There has got to be a better way though, especially if I wanted a different value.

EDIT2: While on the topic of stencil buffers, does anyone know why there isn't a stencil-fail-z-pass case to hold a separate op? I've come across a few situations when it would be useful.
 
Mintmaster said:
Hi 3D experts, I've got a puzzle I can't figure out, and don't know if it's possible.

I want to set the stencil buffer renderstates so that I draw a fullscreen quad, and every non-zero stencil value now get set to 0x02.

Basically, I've stenciled out an area using shadow volumes, and so there are now areas with values greater than one depending on how many shadows overlap. I want to now set all areas with at least one shadow to the same value.

It seems like such a simple task, but I can't see the solution since there's only one reference value. Can anyone else figure it out?

EDIT: Well, in my particular case I found a solution, but it sort of sucks. I can set the reference to 0x01, use function LESS & stencilop REPLACE, then do a second pass with function EQUAL & stencilop INCR. There has got to be a better way though, especially if I wanted a different value.
I guess you mean GREATER instead of LESS.
btw, I think a better way would be to use 0x02, GREATER and REPLACE followed by 0x01, EQUAL and INCR. This should be faster on an architecture with "early stencil" optimizations.

I don't see a way to do this in one pass either. But why do you need all the shadow pixels to have a value of 0x02? Maybe there's a way to do what you want with 0x01 instead.
 
Back
Top