Terrain pssm depth shadows

Problems building or running the engine, queries about how to use features etc.
Post Reply
Kenshido
Gremlin
Posts: 153
Joined: Tue Jun 09, 2009 9:31 am
Location: Russia
x 12
Contact:

Terrain pssm depth shadows

Post by Kenshido »

Hello!

What am I doing wrong using pssm depth shadows with terrain?

Shadows settings:

Code: Select all

	mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED);
	mSceneMgr->setShadowTextureCountPerLightType(Ogre::Light::LT_DIRECTIONAL, 3);
	mSceneMgr->setShadowTextureCount(3);
	mSceneMgr->setShadowTextureConfig(0, 512, 1024, Ogre::PF_FLOAT32_R);
	mSceneMgr->setShadowTextureConfig(1, 512, 512, Ogre::PF_FLOAT32_R);
	mSceneMgr->setShadowTextureConfig(2, 512, 512, Ogre::PF_FLOAT32_R);
	mSceneMgr->setShadowTextureSelfShadow(true);
	mSceneMgr->setShadowTextureCasterMaterial("Ogre/shadow/depth/caster");
	mSceneMgr->setShadowFarDistance(2000);
	 //shadow camera setup
	Ogre::PSSMShadowCameraSetup* pssmSetup = new Ogre::PSSMShadowCameraSetup();
	pssmSetup->calculateSplitPoints(3, mCamera->getNearClipDistance(), 2000);
	pssmSetup->setSplitPadding(mCamera->getNearClipDistance());
	Ogre::PSSMShadowCameraSetup::SplitPointList splitPointList = pssmSetup->getSplitPoints();
	splitPointList[0] = 1;
	splitPointList[1] = 100;
	splitPointList[2] = 500;
	splitPointList[3] = 2000;
	Ogre::Vector4 splitPoints;
    for (int i = 0; i < 3; ++i)   {
        splitPoints[i] = splitPointList[i];
    }
	pssmSetup->setSplitPoints(splitPointList);
	mSceneMgr->setShadowCasterRenderBackFaces(true);
	mSceneMgr->setShadowCameraSetup(Ogre::ShadowCameraSetupPtr(pssmSetup));
Terrain settings:

Code: Select all

	Ogre::TerrainMaterialGeneratorA::SM2Profile* matProfile =
		static_cast<Ogre::TerrainMaterialGeneratorA::SM2Profile*>(mTerrainGlobals->getDefaultMaterialGenerator()->getActiveProfile());
	if (matProfile)
	{
		matProfile->setLayerNormalMappingEnabled(false);
		matProfile->setLayerParallaxMappingEnabled(false);
		matProfile->setReceiveDynamicShadowsDepth(true);
		matProfile->setReceiveDynamicShadowsPSSM(mSettings->getPSSMSettings());
	}
Here's the result:
screenshot10192014_023823702.jpg
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5299
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1279
Contact:

Re: Terrain pssm depth shadows

Post by dark_sylinc »

You're overwritting the split points. That's a usually bad idea.
You should be using them after calling calculateSplitPoints.

Code: Select all

pssmSetup->setSplitPadding(mCamera->getNearClipDistance());// Call this first
pssmSetup->calculateSplitPoints(3, mCamera->getNearClipDistance(), 2000); //Call this last.
//pssmSetup->setSplitPoints(splitPointList); //Do NOT use this function.
pssmSetup->getSplitPoints() //Get the split points if you need them
Furthermore, your shadow far distance of 2000 is too large. Shadow mapping hardly has that good precision for that. Start with low values like 50 or 100 to achieve good results and discard precision as the problem.
If it looks as it should, then start increasing incrementally the shadow distance until quality starts to degrade. The lambda parameter in calculateSplitPoints also affects the quality. You'll have to play with both settings (distance and lambda) depending on your scene.
Kenshido
Gremlin
Posts: 153
Joined: Tue Jun 09, 2009 9:31 am
Location: Russia
x 12
Contact:

Re: Terrain pssm depth shadows

Post by Kenshido »

I've shanged code to this:

Code: Select all

	mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED);
	mSceneMgr->setShadowTextureCountPerLightType(Ogre::Light::LT_DIRECTIONAL, 3);
	mSceneMgr->setShadowTextureCount(3);
	mSceneMgr->setShadowTextureConfig(0, 512, 512, Ogre::PF_FLOAT32_R);
	mSceneMgr->setShadowTextureConfig(1, 512, 512, Ogre::PF_FLOAT32_R);
	mSceneMgr->setShadowTextureConfig(2, 512, 512, Ogre::PF_FLOAT32_R);
	mSceneMgr->setShadowTextureSelfShadow(true);
	mSceneMgr->setShadowTextureCasterMaterial("Ogre/shadow/depth/caster");
	mSceneMgr->setShadowFarDistance(100);
	 //shadow camera setup
	Ogre::PSSMShadowCameraSetup* pssmSetup = new Ogre::PSSMShadowCameraSetup();
	pssmSetup->calculateSplitPoints(3, mCamera->getNearClipDistance(), 100, 0.8f);
	pssmSetup->setSplitPadding(mCamera->getNearClipDistance());
	Ogre::PSSMShadowCameraSetup::SplitPointList splitPointList = pssmSetup->getSplitPoints();
	Ogre::Vector4 splitPoints;
    for (int i = 0; i < 3; ++i)   {
        splitPoints[i] = splitPointList[i];
    }
	//pssmSetup->setSplitPoints(splitPointList);
	mSceneMgr->setShadowCasterRenderBackFaces(true);
	mSceneMgr->setShadowCameraSetup(Ogre::ShadowCameraSetupPtr(pssmSetup));
and nothing's happened:
screenshot10192014_123432192.jpg
Kenshido
Gremlin
Posts: 153
Joined: Tue Jun 09, 2009 9:31 am
Location: Russia
x 12
Contact:

Re: Terrain pssm depth shadows

Post by Kenshido »

I don't understand, how caster works.

For example, how this stone:
screenshot10202014_194707019.jpg
can create this depth texture?
screenshot10202014_194632606.jpg
If I understand correctly, close polygons should cause close depth values?

The second question:

Code: Select all

	// Calculate the position of vertex in light space
	outp.lightSpacePos0 = mul(texWorldViewProjMatrix0, pos);
	outp.lightSpacePos1 = mul(texWorldViewProjMatrix1, pos);
	outp.lightSpacePos2 = mul(texWorldViewProjMatrix2, pos);

	// make linear
	outp.lightSpacePos0.z = (outp.lightSpacePos0.z - depthRange0.x) * depthRange0.w;
	outp.lightSpacePos1.z = (outp.lightSpacePos1.z - depthRange1.x) * depthRange1.w;
	outp.lightSpacePos2.z = (outp.lightSpacePos2.z - depthRange2.x) * depthRange2.w;
All lightSpacePos.z has always negative values, is this correct?
stasclick
Gnoblar
Posts: 16
Joined: Tue Oct 07, 2014 2:24 pm
Location: Russia. Moscow

Re: Terrain pssm depth shadows

Post by stasclick »

Kenshido wrote:What am I doing wrong using pssm depth shadows with terrain?
Maybe this can help. I had the same problem, it helps me:

Code: Select all

VS_OUT main_caster_vp(...)
{
    ...
    outp.depth = (outp.pos.z - depthRange.x) * depthRange.w;
    return outp;
}
float4 main_caster_fp(
   VS_OUT In, ...)
{
    return float4(In.depth.xxx, 1);
}
Kenshido
Gremlin
Posts: 153
Joined: Tue Jun 09, 2009 9:31 am
Location: Russia
x 12
Contact:

Re: Terrain pssm depth shadows

Post by Kenshido »

stasclick wrote:Maybe this can help. I had the same problem, it helps me:
Unfortunately, ogre's shader for depth shadows already uses this code...
Kenshido
Gremlin
Posts: 153
Joined: Tue Jun 09, 2009 9:31 am
Location: Russia
x 12
Contact:

Re: Terrain pssm depth shadows

Post by Kenshido »

The code, where comparison of depths (caster and object) processed:

Code: Select all

float calcDepthShadow(sampler2D shadowMap, float4 uv, float invShadowMapSize)
{
	// 4-sample PCF
	
	float shadow = 0.0;
	float offset = (NUM_SHADOW_SAMPLES_1D/2 - 0.5) * SHADOW_FILTER_SCALE;
	for (float y = -offset; y <= offset; y += SHADOW_FILTER_SCALE)
		for (float x = -offset; x <= offset; x += SHADOW_FILTER_SCALE)
		{
			float depth = tex2Dproj(shadowMap, offsetSample(uv, float2(x, y), invShadowMapSize)).x;
			if (depth >= 1 || depth >= uv.z)
				shadow += 1.0;
		}

	shadow /= SHADOW_SAMPLES;
	return shadow;
}
Where uv.z is lightSpacePos.z
I created pixel shader, whitch shows uv.z and depth values as texture.

uv.z:
uv.z is always negative and has very close values, so I used this code for representation: (uv.z + 0.3) * 10;
uv.z is always negative and has very close values, so I used this code for representation: (uv.z + 0.3) * 10;
Why uv.z from lightSpacePos0, lightSpacePos1 and lightSpacePos2 has different values?

depth:
screenshot10222014_165025383.jpg
Strange separation of trunk depth I can explan by different scene_depth (because of stone, placed behind of part of tree) (im I right?)
But I can't explain, why trunk's depth is the same from bottom to top? My light source has this direction:

Code: Select all

Ogre::Vector3 lightdir(0.5, -0.35, 0.5);
So, depth values from bottom should shoud have bigger values, then from top of trunk.
Kenshido
Gremlin
Posts: 153
Joined: Tue Jun 09, 2009 9:31 am
Location: Russia
x 12
Contact:

Re: Terrain pssm depth shadows

Post by Kenshido »

I've finally implemented depth shadows with terrain and PagedGeometry. Not PSSM, but CSM from this sample

screenshot11102014_231036410.jpg
screenshot11102014_231541942.jpg
screenshot11102014_232741123.jpg
Lax
Hobgoblin
Posts: 583
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 50

Re: Terrain pssm depth shadows

Post by Lax »

Hi Kenshido,

I'm also trying to integrate CSM shadows for terrain and pagedgeometry but without success. I do not know how to apply CSM for Ogre terrain.
Could you help me out? Could you show some code what needs to be done?

Thanks in advance
Regards
Lax

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

Post Reply