[Solved] The problem with terrain depth shadows - ...

Problems building or running the engine, queries about how to use features etc.
Post Reply
MasterD
Kobold
Posts: 26
Joined: Tue Jun 29, 2010 9:00 pm
x 1

[Solved] The problem with terrain depth shadows - ...

Post by MasterD »

For quite a while now, I'm trying to get some terrain depth shadows working (1.8 RC1).

I always wondered, why the terrain sample is producing such nice shadows and I just don't get it running. Now I modified the sample just a tiny little bit - and it produces immediately similar errors as I have (see http://www.ogre3d.org/forums/viewtopic.php?f=2&t=68686).

To summarize the errors:
- Shadows only appear when viewing nearly exact the direction of the light.
- Shadows disappear, when closer to the geometry.
Look also at the attachement.

For this to reproduce, I modified the sample as follows:
- initialize with depth shadow mode
- directly after terrain creation, activate that shadow mode
to be exact:

Code: Select all

--- C:/dev/Ogre/ogre_src_v1-8-0RC1/Samples/Terrain/include/Terrain_1.8_Rc1.h	Sa Feb 18 15:02:37 2012
+++ C:/dev/Ogre/ogre_src_v1-8-0RC1/Samples/Terrain/include/Terrain.h	Sa Feb 18 15:02:38 2012
@@ -54,6 +54,7 @@
 		, mTerrainsImported(false)
 
 	{
+		this->mShadowMode = SHADOWS_DEPTH;
 		mInfo["Title"] = "Terrain";
 		mInfo["Description"] = "Demonstrates use of the terrain rendering plugin.";
 		mInfo["Thumbnail"] = "thumb_terrain.png";
@@ -744,7 +745,7 @@
 		mShadowsMenu->addItem("None");
 		mShadowsMenu->addItem("Colour Shadows");
 		mShadowsMenu->addItem("Depth Shadows");
-		mShadowsMenu->selectItem(0);  // no edit mode
+		mShadowsMenu->selectItem(2);  // depth shadow mode
 
 		// a friendly reminder
 		StringVector names;
@@ -827,6 +828,7 @@
 
 		mTerrainGroup->freeTemporaryResources();
 
+		changeShadows();
 
 
 		// create a few entities on the terrain
Even if the shadow mode is now switched at runtime back and forth, the errors persist.

Interestingly, when the call to changeShadows() is made after the other scene entities have been setup, meaning it will be the last instruction in setupContents(), everything is working as expected.

What is going on here? Can anybody confirm this behavior? How do you setup the terrain shadows, do you immediatly configure the terrain material profile (SM2Profile) to include shadows or after some specific time / calls / something else?
Attachments
Terrain shadow problems
Terrain shadow problems
ogre_terrain.jpg (49.07 KiB) Viewed 3216 times
Last edited by MasterD on Mon Feb 20, 2012 6:51 pm, edited 2 times in total.
Yet Another Space Shooter --- www.yass-engine.de
MasterD
Kobold
Posts: 26
Joined: Tue Jun 29, 2010 9:00 pm
x 1

Re: The problem with terrain depth shadows - is it the order

Post by MasterD »

The problem with the terrain example is the following:

When configuring the shadows, the material PSSM/shadow_caster (1) is set as, guess what, the shadow's caster material via smgr->setShadowTextureCasterMaterial.

What is not written there, is that this one is not used.

Used is another one, hidden quietly in the declaration of the Ogre/shadow/depth/integrated/pssm, via the statement shadow_caster_material Ogre/shadow/depth/caster (2).

If you now compare those two implementations of a shadow caster shader, you see that (1) produces pixels in the range of [0,1]. However, (2) takes into account the scene_depth_range which seems to be crucial for the correct execution of the SM2Profile terrain shader.

Taking this into account I was able to get nice(r) shadows not only when looking alongside the light's direction.

One problem is still remaining: currently the shadow is cast by objects below the terrain. But, as I now see something, I should be able to come up with a solution for that nasty bugger.
Yet Another Space Shooter --- www.yass-engine.de
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: [Solved] The problem with terrain depth shadows - ...

Post by bstone »

That's really interesting. So you basically mean that the new initialization code you mentioned makes the material generator use PSSM/shadow_caster? But otherwise it would use Ogre/shadow/depth/integrated/pssm? Correct?
MasterD
Kobold
Posts: 26
Joined: Tue Jun 29, 2010 9:00 pm
x 1

Re: [Solved] The problem with terrain depth shadows - ...

Post by MasterD »

Exactly. Due to the change of the initialization order, it happened that the three houses had their basic material, which does not override the shadow caster shader (and don't include shadowing, but that doesn't matter for the sake of that test).

So, without any change of C++ code and only writing shadow_caster_material PSSM/shadow_caster or removing that statement, the terrain's received shadows are broken.
Yet Another Space Shooter --- www.yass-engine.de
bstone
OGRE Expert User
OGRE Expert User
Posts: 1920
Joined: Sun Feb 19, 2012 9:24 pm
Location: Russia
x 201

Re: [Solved] The problem with terrain depth shadows - ...

Post by bstone »

Makes sense. Thanks for figuring that out. I'd definitely hit my head against that wall in a few days.
Post Reply