PDA

View Full Version : Stencil Buffer Replacement



bobGL
10-23-2008, 04:08 AM
Im working on a GL implementation that does not have shaders as well as stencil buffer... might sounds like a stupid question but is there any other relatively "simple" way to implement a stencil buffer in software? Can someone point me a direction here ...

Tks in advance,

Cheers,

Brolingstanz
10-23-2008, 05:00 AM
Can someone point me a direction here ...

http://www.opengl.org/documentation/specs/

There's enough information in the spec to write a complete software renderer, with stencil buffer support ;-)

ZbuffeR
10-23-2008, 05:48 AM
You may try with a pure addidive blend, adding a small color value, then you may copy this to texture and do thing according to the accumulated color value.
But it will hard to reproduce everything a stencil buffer can provide, and it will be even harder to make it fast.

Forget about the stencil : what precisely do you want to do ? Shadows ? Masks ? ... ?
And what is the target implementation : hardware / software ? embedded ? ...

_NK47
10-23-2008, 05:49 AM
there is mesa 3D, an OpenGL software implementation.
easy to download, make MSVS project and compile. hope that helps.
http://www.mesa3d.org/

i would be interested as well what hardware you are targeting.

bobGL
10-23-2008, 05:38 PM
Zbuffer: Shadows, carmack zfail... hard to do without a stencil buffer ;) since the hardware is limited, im planning to link like a really low version of the rendered one just for shadow purpose... and I can't use planar shadow

bobGL
10-23-2008, 05:39 PM
_NK47: iPhone & iPod Touch

sqrt[-1]
10-23-2008, 07:19 PM
As Zbuffer said, I have heard of some games (PS2?) using the color buffer to do "stencil" shadow volumes.

brinck
10-24-2008, 01:44 AM
Zbuffer: Shadows, carmack zfail... hard to do without a stencil buffer ;) since the hardware is limited, im planning to link like a really low version of the rendered one just for shadow purpose... and I can't use planar shadow

It's entirely possibly to implement both zpass/zfail shadows without a stencilbuffer.

For zfail set depthfunct to GL_GREATER and render all backfacing polygons with additive blending with the smallest available color value. Then render the frontfacing polygons with subtractive blending with the same small value. This will give you a shadow mask in the color buffer. Don't forget to turn of depth write.

I used this technique on the original xbox (not because it didn't have stencil buffers, it had), but because using the color buffer made it possible to render the shadows in one pass (the original xbox didn't have two sided stencil test). This worked because you could set a positive color on back facing polygons and negative color on front facing.

You also had to clear the color buffer with something like 127 before because the ordinary blending didn't wrap around. This isn't necessary when doing the blending in two passes though, in this case clearing with 0 is fine.

/A.B.

bobGL
10-25-2008, 04:37 PM
brinck: Ok I got the big picture but... Im don't understand what to do after I get the shadow mask in the color buffer, cuz I can only have access to 1 color buffer there's no color attachment available from the implementation... Any example, code snippet or reference that can help me on this matter?

Tks in advance,

Cheers,

OneSadCookie
10-27-2008, 01:11 AM
iPhone & iPT have render-to-texture via OES_framebuffer_object if that's what you're wanting?

bobGL
10-27-2008, 01:53 AM
Yeah I know that. Im just waiting for a pseudo-code of some kind that can help me to resolve this issue ;)

Cuz I understand the big picture (like I mention) but I have no clue how to implement it... I don't understand how can I use the color buffer for both drawing and stencil... Since I have only 1 color buffer available... this is why a "pseudo" code would help me...

Hampel
10-27-2008, 05:03 AM
you should use the "stencil color buffer" as a teexture; hence the reference to render-to-texture. you can use that additional texture with a full screen quad...

brinck
10-28-2008, 02:54 AM
iPhone & iPT have render-to-texture via OES_framebuffer_object if that's what you're wanting?

Yes, this should do the trick. Set up a frame buffer object and render the "stencil mask" to the alpha channel. Afterwards you should be able to use this frame buffer in conjuncture with alpha test (GL_NOTEQUAL and value set to 127, if this is what you've cleared the frame buffer object to begin with).

I guess you'll also have to set up a texture matrix to automatically generate the correct texture coordinates for the mask in the frame buffer object.

/A.B.