#143065 - silent_code - Tue Oct 16, 2007 2:29 pm
VOLUMETRIC SHADOW Mini-Tutorial
by silent_code (http://www.code-basement.net), 2007
Updated on July 7th 2008 (2013: Moved to a new domain.)
There are three basic steps you need to follow to render volumetric shadows, but first, lets see what we need to get started:
You can create all of the geometry with your favorite 3D modelling application and convert it to a format, that your base code can load and display on the NDS.
Alternatively, you could also compute any shadow geometry, but that is beyond the scope of this mini-tutorial.
Prepare volumetric shadow rendering by setting the "flush mode" to "manual transparency sorting" and "w-depth-sorting" and sort your translutient geometry - not on a per primitive base, just the translutient objects - as needed. Note, that this also includes shadow geometry!
To set the right flush mode, use the following setting in the frame before any shadow geometry is rendered. That means, whenever shadows are involved, use this:
Then do the following in each frame:
3) Finally, draw the shadow geometry's back (the "Stencil Shadow") with the next polygon format. Again, alpha must to be between 1 and 30, though this time the polygon ID must not be 0!
Now you should have volumetric shadowing on screen - all hardware accelerated and rendered. :^)
ADDITIONAL NOTES
That's everything!
Happy programming! :^)
PS: If this helped you, feel free to mention me and / or the URL to my web site (http://www.robs-basement.de) somewhere in your program or its documentation. :^)
Disclaimer: Use this information at your own risk. I can't be held liable for any damage, direct or indirect, of any sort, that might result from using this information.
Hereby I grant everyone the right to freely use (commercially or not, it doesn't matter) and distribute (in it's current form, not altered without the author's permission) this information.
Selling this information is strictly prohibited.
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.
Last edited by silent_code on Wed Jan 16, 2013 2:55 am; edited 15 times in total
by silent_code (http://www.code-basement.net), 2007
Updated on July 7th 2008 (2013: Moved to a new domain.)
There are three basic steps you need to follow to render volumetric shadows, but first, lets see what we need to get started:
- - Some geometry to receive shadows
- Some geometry to cast shadows (just regular geometry, like the "receivers" above)
- Some shadow volume(s) (also regular geometry)
- A working code base, that can load and render geometry, as well as "do other stuff" (input etc.) - or at least one of the examples available on the net (like the "Volumetric Shadow Demo" on my web site.)
You can create all of the geometry with your favorite 3D modelling application and convert it to a format, that your base code can load and display on the NDS.
Alternatively, you could also compute any shadow geometry, but that is beyond the scope of this mini-tutorial.
Prepare volumetric shadow rendering by setting the "flush mode" to "manual transparency sorting" and "w-depth-sorting" and sort your translutient geometry - not on a per primitive base, just the translutient objects - as needed. Note, that this also includes shadow geometry!
To set the right flush mode, use the following setting in the frame before any shadow geometry is rendered. That means, whenever shadows are involved, use this:
Code: |
glFlush(GL_TRANS_MANUALSORT | GL_WBUFFERING); |
Then do the following in each frame:
- 1) Render all shadow casting and receiving geometry as usually, then for each and all shadow volumes do the next two steps in exactly that order:
2) Shadow geometry must be translutient, so make sure you enable blending. Then render the shadow geometry's front (the "Stencil Mask") using the following polygon format. Note, that for the mask, alpha must be between 1 and 30 and the polygon ID must be 0!
Code: |
glPolyFmt(POLY_ALPHA(1) | POLY_CULL_FRONT | POLY_ID(0) | POLY_SHADOW); |
3) Finally, draw the shadow geometry's back (the "Stencil Shadow") with the next polygon format. Again, alpha must to be between 1 and 30, though this time the polygon ID must not be 0!
Code: |
glPolyFmt(POLY_ALPHA(20) | POLY_CULL_BACK | POLY_ID(63) | POLY_SHADOW); |
Now you should have volumetric shadowing on screen - all hardware accelerated and rendered. :^)
ADDITIONAL NOTES
- - This is NOT your usual PC stencil buffer! Actually, there is just a single line stencil buffer, which is not accessible by software. Shadow geometry must allways be transparent, as that's part of the "shadow polygon mode trigger" for the graphics hardware!
- If you're using hardware fogging, you also need to enable it in step 3's polygon format or you will get unfogged shadow areas.
You can do that on purpose, though. Just like with the flashlight in "Dementium - The Ward".
- Setting different polygon IDs for different shadow geometry will result in "overlapping" shadows, which create even darker areas. Of course, the that depends on the amount of blending used.
- Shadow geometry counts just like "regular" geometry, so watch the hardware limits!
- Shadow geometry can be colored (real world shadows are rarely black, too!)
- Use closed volumes! The algorithm the hardware is using (the only one available on the NDS), is called "z-pass". Penetrating shadow geometry with the "camera" (so the geometry gets clipped by the near plane) will break it and result in "shadow holes"! Thank you Creative Labs, for that damn "z-Fail" software patent! Really! X^C
- If the shadows are flickering or the scene isn't rendered at all, go back to the beginning. You probably forgot to set manual transparency sorting and w-sorting correctly.
- For an object to shadow itself, simply set the polygon ID for it's shadow geometry to something different, as it's regular geometry's polygon ID.
- ALLWAYS follow the three steps and especially step two and three for each shadow geometry! DO NOT draw all masks first and then all shadows! That's a bad idea!
That's everything!
Happy programming! :^)
PS: If this helped you, feel free to mention me and / or the URL to my web site (http://www.robs-basement.de) somewhere in your program or its documentation. :^)
Disclaimer: Use this information at your own risk. I can't be held liable for any damage, direct or indirect, of any sort, that might result from using this information.
Hereby I grant everyone the right to freely use (commercially or not, it doesn't matter) and distribute (in it's current form, not altered without the author's permission) this information.
Selling this information is strictly prohibited.
_________________
July 5th 08: "Volumetric Shadow Demo" 1.6.0 (final) source released
June 5th 08: "Zombie NDS" WIP released!
It's all on my page, just click WWW below.
Last edited by silent_code on Wed Jan 16, 2013 2:55 am; edited 15 times in total