Volumetric Shadow Demo

From GameBrew

Revision as of 15:28, 8 November 2021 by HydeWing (talk | contribs)
Volumetric Shadow Demo
AuthorRob (silent_code, R.H.L.)
Last Updated2013/01/16

Volumetric Shadow Demo is a NDS tech demo program formerly know as the Stencil Shadow Demo, and later Volume Shadow Demo. This small open source program demonstrates, among other things, some of the NDS' graphics hardware capabilities.


  • Hardware accelerated volumetric shadowing.
  • Motion blur with video capture, using only one VRAM bank, at 60 FPS.
  • Hardware lighting, texturing, fogging, antialiasing etc.
  • Display brightness control.
  • Viewport scissoring (thanks to gabebear off the gbadev.org forum).
  • Loading binary and text files from disk (through libfat).
  • Converting .tga 24/32bit image data to 16bit nds textures.
  • Displaying a custom font and a text area over a background image, all loaded from disk.
  • Smooth touch input.
  • Simple frame rate counting and some other rendering status info.


Copy the .nds file to the root of your card.

You will see all (data) files are located in the vsd_data directory.

Copy them into the /data/ folder on the root of your card. Or alternatively, directly into the root.

Create the data directory, if not already present on your card.

Files that need to be copied:

vsd_###.nds (or vsd_###_fcsr.nds, in which case nothing else is needed)

Depending on your device, you may have to manually patch the .nds file to make it work with DLDI. Your card's manufacturer can help you with how to accomplish that.

User guide


Prepare the hardware by setting the flush mode to manual and w-depth sorting with:


Do so in the frame before the frame you will draw the shadows. Usually, you would set this up when initializing the application and flush each frame with those settings.

You might need to sort your translutient polygons/meshes. Remember, that certain volumetric shadow geometry configurations will cause artifacts.

Render volumetric shadows

These are the three basic steps you need to follow to render volumetric shadows.

1) Render all the shadow casting and receiving geometry as usually.

2) For every shadow geometry, draw the Stencil Mask. Shadow polygons must be translutient, so enable blending and render the shadow geometry's front using the following settings:


Alpha must be between 1 and 30 and ID also must be 0.

3) The Stencil Shadow: Now, finally draw the shadow geometry's back with these settings:


Again, alpha needs to be between 1 and 30, but this time ID must not be 0.

Now you should have a volume shadow on screen. Repeat steps two and three for all other shadow geometry.

Tutorials can be found at the official website.


During demo:

Touch (Stylus) - Look

D-Pad - Move the camera (forward/backward)

A/B/X/Y - Move the character

Start - Reset scene

Select+A - toggle shadowing

Select+B - toggle texturing

Select+X - toggle lighting

Select+Y - toggle capturing (motion blur)

R+D-Pad - Move a scissor box

L+D-Pad - Move the camera (up/down)

R+L+Up/Down - Change the brightness

R+L+Start - Reset the scene and the brightness


vsd2.png vsd3.png



When using FCSR, it is mostly compatible with no$gba 2.6 (the emulator is still missing some features). Other emulators are not supported.


Compatible with DLDI-able FAT cards, tested with SLOT1 M3 Real via the firmware's autopatching. Through FCSR, it is also compatible with older SLOT2 (GBA) NOR cartridges, tested with NeoFlash 512Mb.


Revision 6.0

  • Fixed the tutorial (thanks to zeruda at gabdev).
  • Fixed a typo in the readme (thanks to jello!) and updated it.
  • Cleaned up console initialization and proper use of libnds' definitions.
  • Fixed material/lighting bug.
  • Added and fixed come source comments.
  • Fixed initialization function.
  • Fixed the view class and its usage.
  • Replaced the floating point gluPerspective() whith its fixed point counterpart.
  • Reworked some parts of the mesh rendering.
  • Removed last bits of "useless stuff."

Revision 5.1

  • Refactored and fixed the scissor class.
  • Fixed fopen() usage.
  • Reduced file path to 31 (+ \0) characters and renamed some files.
  • Cleaned up glEnable() usage.
  • Added vertex and primitive list RAM usage display.
  • Added free render buffer lines display.
  • Readme has been fixed and updated.

Revision 5.0

  • Renamed to "Volumetric Shadow Demo".
  • Fixed input bug: textures could not be toggled.
  • Fixed: Single "include all" header style was remedied with only including and declaring what is needed in each compilation unit.
  • Restructured some source files.
  • Removed ARM7 source file and rearranged the project to ARM9 only (Using the default ARM7 binary).
  • Changed to unmodified default Makefile.
  • Changed the source usage "policy" a little bit.
  • Separated the tutorial from the readme.
  • Readme has been updated accordingly.

Revision 4.0

  • Did quite some source clean-up, rewriting and rearranging.
  • Added view and scissor box classes.
  • Added data directory support.
  • Added better error detection and handling.
  • Changed fog table generation.
  • Refactored a lot of variables and functions.
  • Added some more comments.
  • Fixed some typos in the readme and updated it.

Revision 3.0

  • Changed file system to libfat.
  • Added frame rate counter.
  • Added touch input smoothing (still need to fix the slight drifting).
  • Fixed the fog color.
  • Rearranged and cleaned up the sources.
  • Updated and fixed the readme.
  • Cleaned up and fixed the tutorial.

Revision 2.0

  • Moved to devkitARM R23b.
  • Updated to libnds 20071023.
  • Fixed the readme.
  • Slightly changed the .pbi format - old data and routines are incompatible.
  • Fixed "odd" loading routines.
  • Fixed some minor bugs.
  • Cleaned up the sources a little bit.
  • Added some info about the .tga format in "tgaloader.cpp".
  • Added an overview of controls to the bottom screen.

Revision 1.2

  • Fixed and rearranged some things in the readme.
  • Changed the term "shadow volumes" to the more precise term "volume shadows" in the readme.
  • Added a tutorial section.
  • Updated to libnds 20070503.
  • Added hardware fog.
  • Added capture support and a slight motion blur effect.
  • Added some new controls.

Revision 1.1

  • Fixed and rearranged some things in the readme.
  • Updated to libnds 2007050.
  • Removed my FIX versions of previously 'broken' libnds funktions.

Revision 1.0

  • Fixed and added things to the readme: additional thanks, change log, controls etc.
  • Replaced the shadow volume with a better suited (and simpler) one.
  • Fixed the controls.


  • Initial release.


It was built with devkitARM R23b, libnds 20071023 and libfat 20070127 from the libnds "touch_look" example (as a project kick-start), so credit and thanks go out to their respective authors.

Credit also goes to gabebear for the scissor pick matrix implementation.

Very special thanks go out to Larry E. and Brandon M. for helping with the hardware.

Special thanks to tepples, simonjhall and Alphanoob.

Also, greetings to everybody at the gbadev.org forums.

External links