Implementing stecil buffer

I am writing some API for a piece of new graphics hardware, I try to let it support stencil buffer, but the hardware itself only support scissor test, depth test, alpha test, and a strange destination alpha test, no direct stencil test. I need to make some effect such as reflection&shadow volumn, so I need the stencil buffer. Is there any way that I can implement stencil test in hardware?(software emulation is definitely too slow) I know there are some people that write display driver for the nVIDIA, can you kindly give me a hint?

[This message has been edited by Nil_z (edited 02-18-2001).]

Can you provide more information?
(how much dest. alpha bits do you have?
description of this dest. alpha test?
separate color/alpha buffer masks in hw?
etc…)

sorry, I ignored some details. the bit assign is RGBA 32bit, alpha in the most significant byte. the alpha test compare the fragment’s alpha with the alpha already in the colorbuffer, the compare function can be always, never, less, greater, equal… just like the alpha test in OpenGL. if a fragment pass, it is drawn to the colorbuffer(if it pass the other test). If it fails, I can control it NOT reject this fragment totally, but only reject the RGB part, the alpha part, or the Z part(do not update z buffer). The dest alpha test is strange, if the most significant bit of the dest alpha(the alpha already in the framebuf) is 1(or 0, I can control that), it will reject that fragment. the test order is : scissor test, alpha test, dest alpha test, depth test. Well, that is all I can tell, can you help me?

some funny piece of hw, huh?
does it support subtractive blending?

probably, it’s possible to implement some effects on this hw - but not full stencil buffer functionality.

> The dest alpha test is strange, if the most significant bit of the dest alpha(the alpha already in the framebuf) is 1(or 0, I can control that), it will reject that fragment.

as I remember, something similar was implemented in the old Cirrus Logic’s 3D chip (CL5464/5) - it has 1 bit dest. mask test.

For substractive blending, there a card named “RadeON” …

Originally posted by paddy:
For substractive blending, there a card named “RadeON” …

buzz off…

(or RadeOFF - if you like it better

Funny …
Anyway substractive blending works fine whatever you say. HW pixel shaders in DX8 too

Originally posted by paddy:
Funny …
Anyway substractive blending works fine whatever you say. HW pixel shaders in DX8 too

Good, I feel happy now.

Just explain one thing - I guess, your kindly wise suggestions are intended to help with this problem somehow. But I cannot understend - HOW?

If you want to say something like “Stop digging this crap. Throw away all of your inferior hardware and follow my way” - then my previous response was way too polite.

[This message has been edited by Serge K (edited 02-19-2001).]

can you tell me what is substractive blending? and by the way, what can I do with this dest alpha test? Till now, I have not find a way to use it. What is it for?

Subtractive blending is that you can subtract textures. On most card you can’t do that, I think Radeon is the only card that can do it.

No, I am not working on a Radeon. Anyone can help me implementing the stencil buffer?

Originally posted by Humus:
On most card you can’t do that, I think Radeon is the only card that can do it.

Bow before almighty Radeon! (j/k)

Actually, subtractive blending is available on:
Geforce,
Radeon,
Voodoo5,
Savage2000,
3Dlabs Oxygen VX/GVX
FireGL1/2/3
Wildcat 4105-5110

> Anyone can help me implementing the stencil buffer?

Stencil buffer cannot be emulated in your case.

You can implement some effects with dest. alpha test.
For example, you can use most significant bit as 1 bit mask similar to stencil buffer for reflections.
Shadow volume is more tricky - you need increment & decrement (last one need subtractive blending, or you can do full-screen alpha invert : A -> (255-A), so you can use increment only)
and you cannot mix it with alpha blending.

[This message has been edited by Serge K (edited 02-19-2001).]

I think I get what you mean. If I can use a negative alpha value when blending(is this substractive blending?), then I can increase and decrease the alpha in framebuffer, so I can use the dest alpha as stencil buffer. Am I right? I’ll look up the manual to see if it supports negative alpha.

Stenciling in OpenGL is very specific in what
it must allow you to do. It sounds like your
hardware simply doesn’t allow you to support
it in OpenGL, although that destination alpha
can probably allow you to fake some of the
same effects with a single bit (depending on
the needs of the effect).

If you have the ability, tell the hardware
folks to get their stuff together and tack on
8 bits of stencil on the 24 bits of depth
buffer. If you don’t, you won’t be able to
expose what OpenGL calls stenciling, although
you may be able to expose some extension to
give access to the limited functionality you
can provide.