wiki:Gallery/Shadows

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. :)

Modes

TemplInclude(Templ/GalleryThumbnailAT, project=Shadows, img=mode_std_shadow_map, type=jpg)?
Standard
TemplInclude(Templ/GalleryThumbnailAT, project=Shadows, img=mode_perspective_shadow_map, type=jpg)?
Perspective
TemplInclude(Templ/GalleryThumbnailAT, project=Shadows, img=mode_dither_shadow_map, type=jpg)?
Dither
TemplInclude(Templ/GalleryThumbnailAT, project=Shadows, img=mode_pcss_shadow_map, type=jpg)?
PCSS
TemplInclude(Templ/GalleryThumbnailAT, project=Shadows, img=mode_pcf_shadow_map, type=jpg)?
PCF
TemplInclude(Templ/GalleryThumbnailAT, project=Shadows, img=mode_variance_shadow_map, type=jpg)?
Variance

Smoothing

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

TemplInclude(Templ/GalleryThumbnailAT, project=Shadows, img=smooth_pcss_00, type=jpg)?
0.0
TemplInclude(Templ/GalleryThumbnailAT, project=Shadows, img=smooth_pcss_05, type=jpg)?
0.5
TemplInclude(Templ/GalleryThumbnailAT, project=Shadows, img=smooth_pcss_10, type=jpg)?
1.0

PCF - Percentage Closer Filtering

TemplInclude(Templ/GalleryThumbnailAT, project=Shadows, img=smooth_pcf_00, type=jpg)?
0.0
TemplInclude(Templ/GalleryThumbnailAT, project=Shadows, img=smooth_pcf_05, type=jpg)?
0.5
TemplInclude(Templ/GalleryThumbnailAT, project=Shadows, img=smooth_pcf_10, type=jpg)?
1.0

Variance

TemplInclude(Templ/GalleryThumbnailAT, project=Shadows, img=smooth_variance_00, type=jpg)?
0.0
TemplInclude(Templ/GalleryThumbnailAT, project=Shadows, img=smooth_variance_05, type=jpg)?
0.5
TemplInclude(Templ/GalleryThumbnailAT, project=Shadows, img=smooth_variance_10, type=jpg)?
1.0

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.

Reference

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.

© by Nico Hempe and Fraunhofer IGD. Every usage of these images without prior written permission is strictly prohibited.

Last modified 8 years ago Last modified on 01/18/10 02:31:29

Attachments (15)

Download all attachments as: .zip