Table of contents
Beware: Shadows is an advanced topic. But if you use them, you'd better take some time to read before trying to use them.
Be sure to read the How to get some shadows in your scene and the "chapter 7 Shadows" of the manual.
Once you've finished, and before you begin, make sure you know :
- How to enable stencil shadows, why it's a good universal solution, even if slow and not give soft shadows.
- How to disable shadow casting per entity, shadow receiving per material,
- How to enable and configure texture shadows, what light works best with texture shadows and which doesn't or are not the best, that Ogre let you customize Texture size and format, Camera Projection, Shadow Caster Shader, Shadow receiver Shader
Shadows... more specifically Texture Shadows
So, you know about stencil shadow, and the fact it's on CPU, it's hard shadow, and it use lots of CPU/GPU bandwidth.
Now once you've read basic, theory information on the subject, be sure to realize this statement :
All shadows are basically a hack - there's no such thing as a universal shadow system (yet). Having lots of different options (and Ogre has much more variants than any other engine) makes it possible to pick a combo which works best for your scene setup, but you will have to make some sacrifices one way or the other unless you can afford to aim at the latest cards.
Now, texture shadow are on GPU and can give very nice looking shadows... Now in Ogre in comes it two flavors :
Fixed-function texture shadows
They work by projecting the shadow texture from the light source, an the texture coordinates generated don't care about triangle facing or depth.
There are basically 3 problems:
- Back projection - that is, shadow texture projected behind the light in the opposite direction to the caster. You don't have that here, but if you had a roof on your world and looked up, you'd see it. The coping mechanism for that is normal to use shaders, to basically ignore the shadow texture if the texture Z is negative. You can also do it with fixed-function texture matrices but it's more of a pain.
- Through-projection on back-facing polygons. That's what you have on the side of your box there. Normally the coping mechanism is to use additive lighting, or only one light. That's because areas that are already in darkness won't show up the 'false' shadow on the surfaces facing away from a light. Modulative shadows are inherently inaccurate because they darken surfaces irrespective of the light incident to them, whilst additive light only adds masked light where the light would normally shine - so even if the shadow is projected there, it doesn't matter because no light is there to be masked.
- Through-projection on light-facing polygons, in front of the caster. This one is only solvable by using depth-shadow mapping or being clever about how you set up your shadow receivers.
Depth shadow mapping
Use a 2D depth buffer (called "depth" or "shadow" map) rendered from the light's point-of-view that will be by all rendered object/mesh/material rasterized to determine if each pixel is shadowed or not comparing its depth.
All 3 of these issues above are solved using Depth Shadow Mapping, but that requires a shader and floating point texture support. Eihort has a demo of this and you can see it gives you the accuracy of stencil shadows with the GPU-friendliness of texture shadows. They are the way of the future and advisable for recent cards.
Check Ogre Demo_Shadow for a nice demo of custom shadow caster that does depth shadow mapping. See the Depth Shadow Mapping page for a guide on how to get this working in your own project.
Here's how to do custom shadow mapping in Ogre : Custom Shadow Mapping and some more advanced and optimized custom shadowing in Ogre Parallel Split Shadow Mapping
Unfortunately if you're aiming at lower spec then texture shadows have some foibles. There's quite a nice middle ground available in Eihort with the 'integrated' texture shadow techniques, where you can include the shadow directly in your materials, and use relatively low-level shaders to eliminate 1 and 2. 3 you can only cheat with unless you use depth shadow mapping.
Here's some advanced demo/links/readings on the texture shadow topic, most of those papers/demo being implementable in Ogre due to the high level pluggable architecture of the Ogre shadow system:
Basics Slides (Must Read)
- Practical Shadows or here (2004)
Practical Shadow Mapping (by Michael Wimmer, broken link) (2006)
- Extremely Practical Shadows or here (2006)
- Yet More Shadowbuffers or here + demo (2007)
Paper + Demo + Sources
- Extended Perspective Shadow Maps (XPSM)
- Parallel-Split Shadow Maps (PSSM)
- variance shadow maps (VSM)
- Trapezoidal Shadow Maps (TSM)
- Parallel Split Shadow Maps For Large Scale Environments
- Logarithmic Perspective Shadow Maps
- Real-time Soft Shadow Mapping by Backprojection
- Soft Shadow Maps: Efficient Sampling of Light Source Visibility
- Realistic Soft Shadows by Penumbra-Wedges Blending
- Warping and Partitioning for Low Error Shadow Maps
- Rendering Soft Shadows using Multilayered Shadow Fins
- Multiple-Depth Shadow Maps
- Resolution Matched Shadow Maps
- High-Quality Adaptive Soft Shadow Mapping
- Percentage-Closer Soft Shadows (PCF)
- Smooth Penumbra Transitions
- Shadow Techniques for Relief Texture Mapped Objects
Most of this page is coming from Sinbad's replies posted in forums about shadows texture in Ogre.