Table of Contents
In his diploma thesis Nico Hempe has extended the ShadowMapViewport in OpenSG to include pretty much all current ShadowMap?-based shadowing algorithms. This includes hard as well as soft shadow versions. The soft shadows use different filters, leading to different quality/performance tradeoffs. But they all look pretty nice. :)
The soft shadow versions have a smoothing parameter to control the filter size. Depending on the algorithm, different results can be achieved:
PCSS - Percentage Closer Soft Shadows
PCF - Percentage Closer Filtering
Using shadow maps in your code
One of the goals of the shadow map code in OpenSG is to make using shadows very easy in standard OpenSG applications. Enabling shadow mapping is a two step process that requires very little code. First you need to create a shadow map viewport. This is the object that controls the shadowmap settings and does the rendering needed for the shadows. Second you attach this viewport to any standard rendering window where you want shadows to appear. See the code below. That is all it takes to enable shadow mapping for any scene. :)
#!cpp // Create the shadowmap viewport and set initial values ShadowViewportPtr svp = ShadowViewport::create(); beginEditCP(svp); svp->setBackground(SolidBackground::create()); svp->setRoot(rootNode); svp->setSize(0, 0, 1, 1); svp->setMapSize(1024); svp->setShadowMode(ShadowViewport::PCF_SHADOW_MAP); svp->setShadowSmoothness(0.5); // add light sources here svp->getLightNodes().push_back(dir1); svp->getLightNodes().push_back(dir2); endEditCP(svp); // Attach it to the glut window beginEditCP(gwin);//Window gwin->addPort(svp); endEditCP(gwin);
See the source code of the tutorial and the API docs for many more advanced capabilities such as auto finding lights, excluding nodes, and tweeking shadow parameters.
Demo: how to try it
The lastest 1.8 alpha nightly builds include a tutorial that uses this code. You can take a look at the http://opensg.cvs.sourceforge.net/opensg/OpenSG/Tutorials/24Shadows.cpp?view=markup source code for that application in the CVS repository.
To try the code out:
- Install it and run tutorial "24 Advanced Shadows". (beware, tutorial 21 is called Shadows, but it uses the older methods)
- Provide feedback on the OpenSG MailingLists if anything doesn't work for you.
Note: The linked papers where not necessarly the base for the shadow implementations above. The links were added to the wiki to explain the concepts.
- PCSS - Percentage Closer Soft Shadows: paper.
- PCF - Percentage Closer Filtering: paper.
- VSM - Variance Shadow maps: paper.
© by Nico Hempe and Fraunhofer IGD. Every usage of these images without prior written permission is strictly prohibited.
- mode_dither_shadow_map.jpg (89.5 KB) - added by anonymous 11 years ago.
- mode_pcss_shadow_map.jpg (81.2 KB) - added by dirk 11 years ago.
- mode_perspective_shadow_map.jpg (97.7 KB) - added by dirk 11 years ago.
- mode_std_shadow_map.jpg (90.8 KB) - added by dirk 11 years ago.
- mode_variance_shadow_map.jpg (68.1 KB) - added by dirk 11 years ago.
- smooth_pcf_00.jpg (82.0 KB) - added by dirk 11 years ago.
- smooth_pcf_05.jpg (72.8 KB) - added by dirk 11 years ago.
- smooth_pcf_10.jpg (68.8 KB) - added by dirk 11 years ago.
- smooth_pcss_00.jpg (109.2 KB) - added by dirk 11 years ago.
- smooth_pcss_05.jpg (86.7 KB) - added by dirk 11 years ago.
- smooth_pcss_10.jpg (81.2 KB) - added by dirk 11 years ago.
- smooth_variance_00.jpg (91.4 KB) - added by dirk 11 years ago.
- smooth_variance_05.jpg (72.5 KB) - added by dirk 11 years ago.
- smooth_variance_10.jpg (64.0 KB) - added by dirk 11 years ago.
(72.8 KB) -
added by dirk 9 years ago.
Fixed wrong PCF file (Thanks to Eric Haines for spotting it!)
Download all attachments as: .zip