Jump to content

  • Log In with Google      Sign In   
  • Create Account


Comparing Shadow Mapping Techniques with Shadow Explorer

By Alexey Rukhlinskiy and Quentin Froemke | Published Mar 21 2011 02:00 AM in Graphics Programming and Theory

shadow map light g_d3d filter explorer different cascade scene
If you find this article contains errors or problems rendering it unreadable (missing images or files, mangled code, improper text formatting, etc) please contact the editor so corrections can be made. Thank you for helping us improve this resource

This article brought to you by <a href="http://software.intel.com/en-us/visual-computing/?cid=sw:graphics192">Intel&reg; Visual Computing Developer Community</a>

Attached Image: 34427.jpg

Code Sample Download Page

<a href="http://software.intel.com/en-us/articles/shadowexplorer?cid=sw:graphics189">http://software.intel.com/en-us/articles/shadowexplorer/</a>

Download Article

Download <a href="http://software.intel.com/file/34452?cid=sw:graphics189">Comparing Shadow Mapping Techniques with Shadow Explorer</a> [PDF 990KB]


Most modern games use shadows to some degree. The challenge is to know which algorithm to use and what the tradeoffs are of different techniques-what combination of quality and performance is best suited for the game. This sample, Shadow Explorer, lets the user compare and contrast four different algorithms, adjust various parameters for each one, and observe the effects in real time. The shadow mapping algorithms presented are: simple, percentage closer filtered (PCF), variance (VSM), and exponential variance (EVSM).

Sample Usage

At the highest level, this sample allows the user to compare and contrast the quality and performance characteristics of the different shadowing algorithms. There are two scenes that each algorithm can be applied to: a city and a teapot. The city scene represents a "typical" setting that might be encountered in a game, consisting of a variety of object sizes, dimensions, and other characteristics. The teapot is a "worst case" scenario consisting primarily of thin primitives, casting shadows not only on themselves but also on curved surfaces and a flat plane.

Sample Architecture

Shadow Explorer is implemented as a Microsoft DirectX* application based on the DXUT framework. All four shadow mapping algorithms basically follow the same code path, except that different shaders are used and that VSM and EVSM run a filter over the shadow map before the scene is rendered. Listing 1 shows the basic flow of the source code for creating and using the shadow map. Every frame, the shadow map is created in <span style="font-family: courier;">RenderShadowMap()</span> which builds a standard cascaded shadow map by running the <i>SceneZ</i> shader. As mentioned, for VSM and EVSM the shadow map is then filtered using the <i>FilterV</i> and <i>FilterH</i> shaders. After the shadow map is created, the scene is rendered with the shader <i>SceneMain</i> which, depending on the algorithm selected, will call a different version of <span style="font-family: courier;">IsNotInShadow()</span>. This is done by simply including different .fxh files and recompiling the shaders when a new algorithm is selected. For example, if PCF is selected then <span style="font-family: courier;">IsNotInShadow()</span> will call the version in filter_PCF.fxh.

static void RenderShadowMap(...)
   // For each cascade
   for( int i = 0; i < iLayers; ++i )
	  // Set the Z only pass
	  SetRenderTargets( 0, NULL, g_d3d.pShadowMapDSV[i] );
	  g_d3d.pTechSceneZ->GetPassByIndex( 0 )->Apply( 0,
		 pd3dImmediateContext );
	  // Render the appropriate scene
	  g_pSelectedMesh->Render( pd3dImmediateContext );
   // VSM and EVSM techniques require additional filters
   if(Filter_Type_VSM || Filter_Type_EVSM)
	  // Use the shadow map just generated in the filters
	  g_d3d.pVarShadowTex->SetResource( g_d3d.pShadowMapSRV );

	  // Run the vertical filter
	  SetRenderTargets( 1, &pShadowMapRTV_vsm[0].p, NULL );
	  g_d3d.pTechFilter_V->GetPassByIndex( 0 )->Apply(...);

	  // Use the result of the vertical filter
	  g_d3d.pVarShadowTex->SetResource( g_d3d.pShadowMapSRV_vsm[0] );

	  // Run the horizontal filter
	  SetRenderTargets( 1, &pShadowMapRTV_vsm[1].p, NULL );
	  g_d3d.pTechFilter_H->GetPassByIndex( 0 )->Apply(...);

static void RenderScene(...)

   if(Filter_Type_VSM || Filter_Type_EVSM)
	  // Use the filtered shadow map
	  g_d3d.pVarShadowTex->SetResource( g_d3d.pShadowMapSRV_vsm[1] );
	  g_d3d.pVarShadowTex->SetResource( g_d3d.pShadowMapSRV );
<b>Listing 1 - </b><i>Basic flow of application code in Shadow Explorer</i>

The simplest technique presented is that of a basic, cascaded shadow map. This is obviously going to be the fastest method as it does the least amount of work, but leaves a lot to be desired in terms of quality. The next technique is PCF, which works off the same shadow map but samples the texture multiple times to alleviate aliasing problems and soften the shadow edges. Better results can be achieved by taking more samples, but with the expected tradeoff in performance. By using a non-uniformly distributed sample distribution, fewer samples need to be taken to achieve good results. Shadow Explorer uses a pre-calculated Halton sequence to calculate "random" offsets instead of a grid based offset. Even using the non-uniform method, PCF still requires a lot of sample look ups, making the algorithm fairly time consuming on the GPU.

The next technique, VSM, takes a different approach by storing both the depth and depth squared values into the shadow map. In Shadow Explorer, the shadow map is rendered normally and the depth squared value is added during a separate pass immediately after the z-pass is done. Additionally, this second pass runs a box filter over the data to soften the edges of the shadows. The main drawback to the VSM algorithm is the light bleeding effect when multiple occluders overlap each other and the ratio of their distances from the shadow receiver is high. This can be seen in <b>Figure 1</b>, where the shadow of the tall building in the background is outlined in light where it overlaps the shadows of the two smaller buildings in the foreground.

Attached Image: 34428.jpg

Figure 1 - VSM results in light bleeding artifacts

Depending on the scene, light bleeding may not be noticeable enough to be a problem. If it is, EVSM can be used to eliminate the problem, as can be seen in Figure 2. The main difference with VSM is that EVSM "warps" the depth value when storing and reading from the shadow map. This has the effect of bringing the relative distances of the occluders to the receiver closer together in order to minimize or eliminate light bleeding. Shadow Explorer does this in the shader function <span style="font-family: courier;">WarpDepth()</span>.

Attached Image: 34429.jpg
Figure 2 - EVSM fixes light bleeding


Shadow Explorer implements four shadow mapping techniques with runtime modification of various parameters so the user can compare both the performance and the quality of the methods. For each technique, care was taken to ensure optimal performance of the algorithms. Some of the optimizations done include using half floats instead of floats, unrolling loops in PCF, running the vertical filter before the horizontal filter, selecting the cascade Z interval instead of fitting to best cascade, and calculating shadows only for triangles oriented towards the light. Additional resources, including both binary and source code versions, are available for download at <a href="http://software.intel.com/en-us/articles/shadowexplorer?cid=sw:graphics189">http://software.intel.com/en-us/articles/shadowexplorer</a>.

Some areas for further development would be the addition of spot and point lights to demonstrate the flexibility of the shadow techniques. Animated objects could also be added to create an environment more representative of a game. Also, different algorithms could be used to more accurately place the split planes.


Shadow Explorer allows the user to change a variety of parameters to modify the shadow algorithms and change the shadow technique being used. Here is a list of the controls along with a brief description:
  • Toggle full screen - Turns full screen on/off
  • Change device - Change the d3d device
  • Scene drop down list - Change the scene being viewed
  • Align light to camera - Rotates the light along the light direction for optimal usage of shadow map space.
  • Algorithm drop down list - Change the filtering method being used
  • Shadow Map BPP - How many bits are used for each pixel in the shadow map
  • SM resolution - resolution of the shadow map
  • Filter size - The size of the filter used in PCF, VSM, and EVSM
  • Cascade layers - How many cascades are used
  • Cascade Factor - Adjusts how the split space is partitioned by split planes
  • Aperture - Spatial screen space filter aperture for PCF
  • Visualize Cascades - Visualize the different cascade levels
  • Visualize Light Space - Displays the scene from the light source's point of view.
  • Use Texture Array - Use texture array for cascades. Each cascade layer receives one texture, otherwise a texture atlas is used.
  • Z interval selection - How to determine which cascade a particular pixel is in. If enabled, then only the view space z distance is used. Otherwise, the world position of the pixel is tested against each cascade.
  • Deduce Z range - Calculates z-range from the current view. Otherwise uses the scene bounding box as the upper bound.
  • Deduce Res - Resolution of the render target used to calculate z range.
  • Downscale Factor - Every subsequent GPU deduce pass uses a render target texture of smaller size. This option determines the relation between texture sizes of subsequent passes.
  • Downscale Limit - Maximum texture size when Z-range deduction is performed on GPU. At some point it should be more efficient to pull the whole resource to the CPU and finish deduction there, saving several draw calls.
  • Williams, L. 1978. Casting curved shadows on curved surfaces. In Proc. SIGGRAPH, vol. 12, 270-274. http://portal.acm.or...n.cfm?id=807402
  • Donnelly, W. and Lauritzen, A. Variance shadow maps. In SI3D '06: Proceedings of the 2006 symposium on Interactive 3D graphics and games. 2006. pp. 161-165. New York, NY, USA: ACM Press. http://www.punkuser....m/vsm_paper.pdf
  • Lauritzen, Andrew and McCool, Michael. Layered variance shadow maps. Proceedings of graphics interface 2008, May 28-30, 2008, Windsor, Ontario, Canada. http://portal.acm.or...=GUIDE&dl=GUIDE
  • Isidoro, J. R. Shadow Mapping: GPU-based Tips and Techniques. Conference Session. GDC 2006. March 2006, San Jose, CA. http://developer.amd...adowMapping.pdf
  • The Halton Sequence. http://orion.math.ia...n_sequence.html
  • Engel, Wolfgang F. Section 4. Cascaded Shadow Maps. ShaderX 5, Advanced Rendering Techniques, Wolfgang F. Engel, Ed. Charles River Media, Boston, Massachusetts. 2006. pp. 197-206.
Read the Blog!

<a href="http://origin-software.intel.com/en-us/blogs/2011/02/23/another-gaming-and-graphics-sample-coming-to-a-download-near-you/?cid=sw:graphics191">http://origin-software.intel.com/en-us/blogs/2011/02/23/another-gaming-and-graphics-sample-coming-to-a-download-near-you/</a>

About the Author(s)

Alexey Rukhlinskiy is a Graphics Software Engineer with Intel's Advanced Visual Computing Division, and has been involved in professional graphics software development for over 10 years. Alexey received his MS degree in Computer Science from Novosibirsk State University in 2002.

Quentin Froemke has been plunking away at a keyboard for over 10 years and is currently ensconced in Intel's Visual Computing Software Division where he helps optimize and improve PC games.

There are no binaries at the download link, just source. Can someone post binaries? Thanks in advance.
I see that the page


has a source code link


does that not work for you?
let me restate, why cant you build the binaries from the source?
In the newest GPU Pro 2 I also described this technique (along with some others for alleviating light-bleeding) in an article entitled "Variance Shadow Maps Light-Bleeding Reduction Tricks". There is also a demo with really well-organized source code and shaders.
@Prune: There is a binary windows executable for both 32 and 64 bit inside the source code download.
PhilTaylor, it's because I'd have to install the DirectX SDK just for this (I use OpenGL not DX).
SpaXe, thanks for the link. It seems to require DX10.1 and so with my GTX-285 based card I had to run it in software emulation mode, though I don't know what hardware feature that DX10 lacks is needed for these shadow mapping algorithms...
In any case, it's unfortunate that there's VSM and EVSM but no ESM for comparison. Additionally, I have to ask, which method both provides smooth shadows and avoids the artifact seen here with EVSM (VSM is even worse): http://i56.tinypic.com/359gwu1.png
I thought that EVSM's purpose is exactly to avoid this sort of thing :(
Ii suggest next time if you dudes put an article up with ,,comparing shadow map techniques'', compare shadow map techniques in it (there is ~10 of them), instead of showing two variation of the same effect.

I've done a small specialization at my university about aliasing on shadow mapping, Its not top quality, but perhaps could be useful to someone else:


2016-3-22 leilei

gucci borse stephen curry shoes ralph lauren cartier glasses christian louboutin shoes canada goose uk converse sale coach outlet online coach factory outlet coach factory outlet coach factory outlet online ed hardy uk true religion jeans michael kors bags coach outlet ray ban sunglasses skechers outlet louis vuitton borse lacoste shoes ralph lauren outlet ray ban sunglasses jimmy choo outlet store christian louboutin uk polo ralph lauren outlet ugg outlet online instyler max timberland boots michael kors handbags polo ralph lauren polo ralph lauren outlet toms outlet louis vuitton pas cher ray ban sunglasses mont blanc pens prada uk longchamp levis 511 toms shoes ugg sale ray ban sunglasses nike blazer louis vuitton handbags rolex watches nike store uk toms shoes fitflops clearance nike air max 95 ray ban outlet cheap basketball shoes fitflop uk christian louboutin outlet converse uk louis vuitton handbags michael kors outlet ray bans under armour outlet michael kors handbags michael kors supra for sale true religion jeans michael kors handbags true religion michael kors outlet reebok classic michael kors outlet micahel kors adidas gazelle pandora jewelry adidas trainers omega speedmaster supra shoes kate spade outlet ralph lauren pas cher oakley outlet ray bans louis vuitton handbags michael kors watches discount oakley sunglasses coach purses on sale nike huarache ray ban outlet ghd hair straighteners oakley sunglasses nike roshe run michael kors bags coach outlet online cheap jordan shoes michael kors bags toms outlet air max 90 michael kors handbags reebok shoes michael kors louboutin calvin klein dresses coach outlet hollister uk prada handbags michael kors outlet online ghd flat iron omega watches white converse lacoste polo shirts lululemon sale coach outlet online lululemon outlet babyliss pro canada goose sale coach outlet online adidas superstars nike cortez shoes canada goose jackets canada goose sale hermes outlet burberry outlet coach factory outlet rolex daytona salvatore ferragamo sac longchamp michael kors outlet babyliss flat iron louboutin pas cher prada handbags mcm handbags fitflops outlet ray ban sunglasses asics gel kayano cheap oakley sunglasses prada outlet louboutin outlet adidas shoes mizuno running shoes converse shoes michael kors outlet coach outlet michael kors outlet coach outlet store online toms outlet store nike running shoes ralph lauren outlet longchamp outlet oakley store kate spade outlet burberry uk polo outlet kate spade outlet online michael kors outlet online ralph lauren uk fitflop shoes fitflops shoes true religion jeans ralph lauren hermes belt valentino store christian louboutin uk michael kors watches armani jeans louis vuitton bags michael kors handbags versace jimmy choo shoes asics shoes converse shoes nike free runs kate spade outlet michael kors outlet burberry outlet online burberry outlet cheap ray bans michael kors bags levis jeans gucci outlet online ray ban sunglasses outlet michael kors outlet clearance calvin klein outlet michael kors handbags sac longchamp pliage christian louboutin polo ralph lauren outlet ferragamo shoes longchamp bag nike air max 90 nike tn pas cher air max 90 michael kors outlet hollister clothing coach factory outlet air jordan shoes oakley sunglasses wholesale reebok outlet cheap oakley sunglasses cheap jordans timberland uk coach outlet online toms outlet pandora charms michael kors handbags ecco shoes coach outlet online ray ban outlet michael kors outlet online puma shoes louis vuitton kate spade handbags burberry outlet handbags coach factory outlet online coach outlet online ed hardy jordan pas cher armani exchange nike trainers reebok shoes designer handbags outlet coach outlet store online burberry michael kors coach outlet ugg outlet michael kors handbags oakley sunglasses sale coach outlet store online michael kors outlet michael kors outlet under armour shoes bottega veneta fitflops outlet burberry outlet valentino shoes coach factory outlet online new balance shoes kate spade outlet vans outlet rolex replica watches abercrombie & fitch coach outlet store canada goose uk converse sale vans shoes ralph lauren outlet coach factory online prada handbags on sale polo ralph lauren marc jacobs handbags jordan shoes coach outlet fitflops sale air max chaussure louboutin coach factory outlet ture religion outlet michael kors outlet hollister clothing store cartier watches chi flat iron nike force 1 true religion outlet


Note: Please offer only positive, constructive comments - we are looking to promote a positive atmosphere where collaboration is valued above all else.