Use the previously used code.
- After adding all the other code in the
createScene()
function, add the following line:mSceneMgr->setShadowTechnique(Ogre:: SHADOWTYPE_STENCIL_ADDITIVE);
- Compile and run the application.
With just one line, we added shadows to our scene. Ogre 3D does the rest of the work for us. Ogre 3D supports different shadow techniques. We used additive stencil shadows. Stencil means a special texture buffer used while rendering the scene. Additive implies that the scene is rendered once from the camera perspective and the contribution of each light is accumulated into the final render. This technique creates good results but is also really expensive because each light adds another rendering run. We won't go into details on how shadows work because this is a complex field. Many books could be written about this topic, and also, shadow techniques change rapidly and are heavily researched. If you are interested in this topic, you can find interesting articles in the NVIDIA book series GPU Gems, the ShaderX book series, and in the proceedings of the Siggraph conference (http://www.siggraph.org/).