CSSM  
     
     
  First complete shadow mapping solution ...
... conveniently wrapped in a single function
 
 
      HomeFeaturesSampleDocumentationDownloadsLicenseContact      
     

News
2010.07.01:
  • Problems with spot light removed
2010.08.10:
  • Added DX9 sample application
  • API relieved of all dependencies to ease cross compiling for other platforms
  • Directional light of DX10 sample application includes simple hardware PCF filtering
2010.08.17:
  • DX 10 sample suports filtering (simple PCF, complex PCF, Blurring with very little Bleeding)

Introduction
Goal of this project was to solve all of the shadow mapping problems (speed, quality, limited light type support) and define an new industrial standard for shadows in games. For this purpose, a new Camera Space Shadow Mapping algorithm was developed that is much simpler than existing perspective warping approaches and thus more suitable for solving special cases such as dueling frustum, border case and point (omni-directional) light.

API presented here handles all the cases (big/small, point/spot/directional) in a single rendering pass and with the single shadow map that is created free of wastage which guaranties maximal possible quality.

Palm TreeCartoon VillageCitadel


Short video presentation



Why is this fastest and first complete solution?
It is fastest because shadow map is created with using only one shadow map texture and in a single rendering pass.
It is complete solution, because every light type (and size) is supported and it works even with infinitely large scenes where camera is not limited by a far clipping plane. Highest quality is achieved because shadow map is created without wastage - it simply isn't possible to generically achieve higher quality.


Where can I get this API?
Go to the download section. There you'll find API files, and sample application (small deferred rendering engine).



Complete solutionComplete solution
Every light type is supported and solution works even with infinitely large scenes where camera is not far clipped.
Engines today have very limited shadow support. In most cases only one directional light is supported and few small spot lights. Even at this basic level of shadow support, programmers are faced with a lot work because every different light type and special case require different implementation both in code and shaders which can get very messy very quickly.
With CSSM there are no limitations like this. Designers can use any kind of light regardless how big or small it is, without worrying about performance or memory consumptions. Programmers can also be relived, because implementing CSSM API takes only few minutes.

FastFast
Solution is fast because shadow map is created in a single rendering pass which ensures speed.
With other approaches such as Cascaded and Parallel Split shadow maps usage of multiple shadow maps is very common, and some games use up to four or even five 2048x2048 shadow maps for just one light. This is probably the main reason why shadows are considered extremely expensive and number of "big" lights is almost always limited to one.
With CSSM, and single (and small) shadow map, there is finally no more reason not to use multiple "big" light sources.

Highest qualityHighest quality
Algorithm creates shadow map free of wastage which guaranties highest achievable quality. It simply isn't possible to achieve higher quality for the general case where information about the scene is not present. Special effort is also put on achieving great shadow quality for both near and far shadows which is a major problem for most other approaches.

Minimal system requirementsMinimal system requirements
Only one (relatively small) shadow map is required and there is no need for additional depth buffer.
Again, as an contrast, cascaded and parallel split shadow maps require multiple shadow maps for a single light. This memory consumption isn't especially problematic for today's graphic cards, but it can be if multiple lights are used and shadow is casted even on transparent geometry (which is rendered last). This of course means that every shadow map of every light has to be stored until the very end of the rendering process which can occupy significant amount of graphic memory.

DX9 compatibleDX9 compatible
Solution was designed with DirectX 9 in mind. Although original CSSM approach requires DX10 hardware for pixel accurate shadow map stretching, this feature was not included in the API to preserve DX9 compatibility. Alternative method for avoiding wastage was used.

SimpleSimple
One-line-of-code implementation. No more need for complex graphic engine implementations. Just call one function and render shadow map geometry in a single pass. Needless to say, it is very easy to implement CSSM into current engines.


Conclusion
The best thing is that writing graphic engine now becomes easy. Since there is no need for complex coding, entire shadow system can be completely handled by the shader. This means the if one wants to switch from shadow mapping to shadow volumes, only shader file has to be updated - graphic engine's code remains untouched.

For the complete overview, please consult documentation.
 

Sample Application
To simplify things, we've created an sample application that uses CSSM API for shadows. It is a relatively decent deferred rendering system that loads X files and allows flight-trough preview of the scene. Here is the screenshot of the interface:
Application Interface

User can load geometry, experiment with the shaders and change the light and shadow map information.
After geometry is loaded, simulation is started by clicking anywhere on the window, and stopped by pressing 'Esc'.

Source and binary files, together with sample models can be found in the downloads section.



Paper
Paper is currently in the process of being published so it won't be available here for the time being. Here is the abstract:
Abstract
This paper presents a new single-pass shadow mapping technique that improves upon the quality of the perspective-warping based approaches such as perspective, light-space and trapezoidal shadow maps. By performing operations in camera space, solution successfully handles general and dueling frustum case and produces high quality shadows even for extremely large scenes. This paper also presents fast shadow map stretching technique that enables full utilization of shadow map by eliminating wastage. When applied, unwanted perspective aliasing, common to all shadow mapping techniques, is reduced significantly. Complete shadow mapping API is presented to make implementing high quality shadows trivial.

API Instructions
One goal of the project was to make API usage as simple as possible. Driven by that goal, final solution was designed to use only one shadow map and a single function that calculates optimal shader parameters.

API is defined by the following files:
  • CSSM.dll (lib) - contains function GetOptimalCSSMParams
  • CSSM.h - contains definition of the function GetOptimalCSSMParams
  • CSMM(9/10).fx - shader file that contains two shader functions: GetDepthAndProj, GetDepthAndTexCoord
To use the API, application code must include CSSM.h and CSSM.dll files. Shaders should include CSSM(9/10).fx file.

In short, GetOptimalCSSMParams function is used to calculate optimal shader parameters for the current light/camera. GetDepthAndProj shader function is used for shadow map creation, and GetDephtAndTexCoord is used for shadow map application. Detail information about these three functions can be found in the documentation page.


API
Copy these files in your project and you can start using CSSM API. Zip file includes:
  • CSSM9.fx
  • CSSM10.fx
  • CSSM.h
  • CSSM.dll
  • CSSM.lib
NOTE: This is version 1.2. In this version problems with spot light have been completely removed, and DX9 shader added.

API for Linux, MAC OS X, Playstation 3, ...
ELF library for Linux, Mac OS X and Playstation 3 will be available soon. API code have been stripped from all dependencies  to make cross-compiling for any platform as simple as possible. If there is need for any other non-standard platform, please let us know.

DirectX 9 sample application
Here you will find sample DX9 application that demonstrates CSSM API. Project is available in VS 2005, VS 2008 and VS 2010 format.
NOTE 1: CSSM9.fx file is missing because it is already included in XShader9.fx file.
NOTE 2: Application uses faked DX10-like instancing because of generality (graphic utils). For more information on how to achieve this, please consult this this document. In regular DX9 application there won't be need for DX10 like instancing because all the projection and controlling matrices should be directly included in instancing vertex buffer.


DirectX 10 sample application - INCLUDES FILTERING!
Here you will found sample DX10 application that demonstrates CSSM API. Project is essentially identical to DX9 sample, with exception that it suports filtering. Three filtering methods are used: simple PCF, complex PCF (9 taps) and Selective Blurring where only pixelated shadow arreas are blurred (still requires some work on the aliasing detection).
NOTE: We've used DX10 instead of DX11 because DX11 (at the time of this writing) didn't have native support for effects. Effect system was included as an separate project that needed some corrections in order to work correctly on non DX11 hardware.


3D Modes (X files)
X files are currently the only format supported by the sample application. Every model available here has been downloaded from Google 3D Warehouse and converted to X format. Here is the list:

 


License

API is free for non-commercial use.
Commercial usage requires approval by me.

Actually, solution is free for indie game developers and small businesses. This means, if you are developing an application that will be sold in no more than ten copies  and at a price lower than $1000 US, you are not required to have an license.
On the other hand, professional game/engine development companies do need to buy one-time license (per game) or full license (per engine).

Creative Commons License
Camera Space Shadow Maps by Ivica Kolic is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License.





Contact information

Author:
Ivica Kolic

Email (remove underlines):
Ivica_._Kolic@gmail.com

About Ivica:
What can I tell you about me?

You've probably noticed by now that I like graphic programming. In fact, I like it so much that I've actually quit working for startup companies, took a not-so-overwhelming 9-17 job and now enjoy working on graphic in my free time (that I now have). Hopefully, you will see more of the pages like this about my work in the future.

Ivica Kolic

That is all.
 





     
     
     
  © 2010 Ivica Kolić. All rights reserved.