@@ -187,6 +187,7 @@ struct Application : public OgreBites::ApplicationContext, public OgreBites::Inp
187
187
uint32_t h;
188
188
int key_pressed;
189
189
int flags;
190
+ Ogre::MaterialPtr casterMat;
190
191
191
192
Application (const Ogre::String& _title, const Size & sz, int _flags)
192
193
: OgreBites::ApplicationContext(" ovis" ), mainWin(NULL ), title(_title), w(sz.width),
@@ -287,6 +288,9 @@ struct Application : public OgreBites::ApplicationContext, public OgreBites::Inp
287
288
MaterialManager& matMgr = MaterialManager::getSingleton ();
288
289
matMgr.setDefaultTextureFiltering (TFO_ANISOTROPIC);
289
290
matMgr.setDefaultAnisotropy (16 );
291
+ casterMat = matMgr.create (" DepthCaster" , Ogre::RGN_INTERNAL);
292
+ casterMat->setLightingEnabled (false );
293
+ casterMat->setDepthBias (-1 , -1 );
290
294
}
291
295
};
292
296
@@ -318,6 +322,21 @@ class WindowSceneImpl : public WindowScene
318
322
RTShader::ShaderGenerator& shadergen = RTShader::ShaderGenerator::getSingleton ();
319
323
shadergen.addSceneManager (sceneMgr); // must be done before we do anything with the scene
320
324
325
+ if (flags & SCENE_SHADOWS)
326
+ {
327
+ sceneMgr->setShadowTechnique (SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED);
328
+ sceneMgr->setShadowTexturePixelFormat (PF_DEPTH32);
329
+ // arbitrary heuristic for shadowmap size
330
+ sceneMgr->setShadowTextureSize (std::max (sz.width , sz.height ) * 2 );
331
+ sceneMgr->setShadowCameraSetup (FocusedShadowCameraSetup::create ());
332
+ sceneMgr->setShadowTextureCasterMaterial (app->casterMat );
333
+
334
+ // inject shadowmap into materials
335
+ const auto & schemeName = RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME;
336
+ auto rs = shadergen.getRenderState (schemeName);
337
+ rs->addTemplateSubRenderState (shadergen.createSubRenderState (" SGX_IntegratedPSSM3" ));
338
+ }
339
+
321
340
sceneMgr->setAmbientLight (ColourValue (.1 , .1 , .1 ));
322
341
_createBackground ();
323
342
}
@@ -716,6 +735,13 @@ class WindowSceneImpl : public WindowScene
716
735
SceneNode& node = _getSceneNode (sceneMgr, name);
717
736
switch (prop)
718
737
{
738
+ case ENTITY_CAST_SHADOWS:
739
+ {
740
+ Entity* ent = dynamic_cast <Entity*>(node.getAttachedObject (name));
741
+ CV_Assert (ent && " invalid entity" );
742
+ ent->setCastShadows (bool (value[0 ]));
743
+ break ;
744
+ }
719
745
case ENTITY_SCALE:
720
746
{
721
747
node.setScale (value[0 ], value[1 ], value[2 ]);
0 commit comments