#149054 - zeGouky - Mon Jan 14, 2008 8:35 am
Hi people,
i'm trying to cut a simple rendered quad by an another rendered only in the stencil buffer.
Here's what im doing :
1/ render a first quad using a poly shadow and poly ID at 0 (alpha =1 )
2/ render a quad just behind the 1st one
I wanted to have the #2 polygon cutted by the #1 (of course the #1 is not visible)
Anyone can help on this issue ?
Thanks.
#149075 - Cydrak - Mon Jan 14, 2008 8:10 pm
First off, if you only need rectangle clipping (aka scissoring), glViewport() works per-poly. You'll have to adjust the projection, but it could be faster/easier. In that case, search the forums on "scissor".
For stencils, try this:
Code: |
#define POLY_DEPTH_TEST_LESS (0<<14)
#define POLY_DEPTH_TEST_EQUAL (1<<14)
glPolyFmt(POLY_SHADOW | POLY_ALPHA(1) | POLY_DEPTH_TEST_EQUAL);
<draw stencil>
glPolyFmt(POLY_SHADOW | POLY_ALPHA(30) | POLY_ID(<nonzero>));
<draw quad>
|
Please note, the NDS is kinda grumpy about stencilling, unless you're doing shadows. So be prepared to fiddle around. I don't understand it too well, but I'll try to summarise what I saw:
- glFlush() needs GL_TRANS_MANUALSORT (for reliable draw order).
- Both stencil and quad need POLY_ALPHA < 31 (or they will be sorted anyway).
- Your quad is drawn where the stencil's depth test failed.
- Usually, GL_DEPTH_EQUAL will make it fail. If not, give Z a nudge.
- The first poly of each stencil, clears the stencil buffer beforehand.
- I haven't seen anything else clear it, not even vblank.
Finally, the most confusing part:
For reliable clears (and happy stencilling), each stencil must cover all scanlines of any "shadow" polys that it might affect. A single pixel line, per stencil, at edge of screen, should be enough. Sometimes a line of shadow is required too. (This is speculation--but mayhap because the clear won't happen if no polys exist to switch the mode on the same line?)
Failure to placate the renderer, on this last point, will give you "stencil barf." Have fun. :-)
#149117 - silent_code - Tue Jan 15, 2008 4:34 pm
as far as i know the "stencil buffer" can only be used for shadow polygons (as shadows or "fog cutout volumes" or even sort of "light volumes" when using propper colors for the volume, although it's not really a nice effect).
what restricts it's usability is the lack of stencil operation functions that affect the setting of stencil values. that's why we can only have z-pass shadow volumes (as of now).
so, i'm afraid you can't use it for csg style "clipping" or slicing. :^C
#149119 - Noda - Tue Jan 15, 2008 5:05 pm
silent_code wrote: |
as far as i know the "stencil buffer" can only be used for shadow polygons (as shadows or "fog cutout volumes" or even sort of "light volumes" when using propper colors for the volume, although it's not really a nice effect).
what restricts it's usability is the lack of stencil operation functions that affect the setting of stencil values. that's why we can only have z-pass shadow volumes (as of now).
so, i'm afraid you can't use it for csg style "clipping" or slicing. :^C |
I actually use it for slicing my projected shadows, it needs some trick but it's feasable ;)
#149315 - zeGouky - Fri Jan 18, 2008 8:23 am
Hi,
sorry was on vacation :-)
Thanks for the answers, Noda can you explain a bit on how you do that ?
Thanks !
#149339 - Noda - Fri Jan 18, 2008 6:08 pm
Check this other thread, it has already been discussed: http://forum.gbadev.org/viewtopic.php?t=14640
#149669 - silent_code - Wed Jan 23, 2008 5:56 pm
but you still use a "flat" shadow "volume" (or polygon/mesh), don't you? ;^P
greetings! :^D
#149676 - Noda - Wed Jan 23, 2008 7:21 pm
Nope, as I only draw the floor in the stencil once!
When using this little trick (the vertical line), you can use it like any 1 bit stencil buffer from what I tested.
#149927 - silent_code - Sun Jan 27, 2008 2:41 pm
very interesting!
so, would it be possible to implement z-fail shadow volumes then? (i guess no, because of the 1bit thing.)