First complete shadow mapping solution ...
... conveniently wrapped in a single function
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.
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).
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.
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.
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 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.
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.
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.
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.
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:
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 is currently in the process of being published so it won't be available here for the time being. Here is the abstract:
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:
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.
Copy these files in your project and you can start using CSSM API. Zip file includes:
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:
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).
Camera Space Shadow Maps by Ivica Kolic is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License.
Email (remove underlines):
What can I tell you about me?
|© 2010 Ivica Kolić. All rights reserved.|