Ogre::PSSMShadowCameraSetup blocky shadowing problem

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
User avatar
razi
Greenskin
Posts: 130
Joined: Tue Oct 14, 2008 5:54 pm
Location: Slovakia
x 17

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by razi »

one thing that I saw, you might want to have

Code: Select all

else if( depth <= pssmSplitPoints.w )
on last shadowmap otherwise you expect it to stretch to infinity

Then, you say all those buildings are bothsided polygons? If not then casterBackface turning true should help it, if yes then only biasing might help. And last, 16 bit is low for PSSM in my experience.
User avatar
Kaylx
Greenskin
Posts: 123
Joined: Sun May 22, 2011 10:45 pm
Location: Scotland
x 7

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by Kaylx »

razi wrote:one thing that I saw, you might want to have

Code: Select all

else if( depth <= pssmSplitPoints.w )
on last shadowmap otherwise you expect it to stretch to infinity

Then, you say all those buildings are bothsided polygons? If not then casterBackface turning true should help it, if yes then only biasing might help. And last, 16 bit is low for PSSM in my experience.
Adding the code above to my shader doesn't make a difference. The polygons aren't two-sided, it's two polygons basically sitting on top of each other effectively as each side uses a different material (e.g. brick wall exterior, plaster wall interior). I thought i was using 32 bit? :?

Code: Select all

mSceneManager->setShadowTextureSettings( 1024, numShadowMaps, Ogre::PF_FLOAT32_R );
User avatar
razi
Greenskin
Posts: 130
Joined: Tue Oct 14, 2008 5:54 pm
Location: Slovakia
x 17

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by razi »

Well if those two polygons dont have any room between each other it doesnt make any difference, there simply isnt enough precision. And sorry about bit precision, I was referring to your older post. Just add there simple box and see if the problem is due to polygons in buildings or something else.
User avatar
Kaylx
Greenskin
Posts: 123
Joined: Sun May 22, 2011 10:45 pm
Location: Scotland
x 7

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by Kaylx »

Just tried this, but i'm still getting the same issues...

Code: Select all

Ogre::Entity* cubeEntity = GetSceneManager()->createEntity( "Cube", Ogre::SceneManager::PrefabType::PT_CUBE );
cubeEntity->setMaterialName( "shadowmap_material" );
GetSceneManager()->getRootSceneNode()->attachObject( cubeEntity );
User avatar
razi
Greenskin
Posts: 130
Joined: Tue Oct 14, 2008 5:54 pm
Location: Slovakia
x 17

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by razi »

With mSceneMgr->setShadowCasterRenderBackFaces(true); i presume? If so it doesnt make sense, you shouldnt have Z fighting in front of box but behind, with shadow map rendering backfaces.
User avatar
Kaylx
Greenskin
Posts: 123
Joined: Sun May 22, 2011 10:45 pm
Location: Scotland
x 7

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by Kaylx »

It definitely looks like our 'thin wall' models are causing issues with z-fighting/depth biasing. Take a look below.
PSSM_2e.png
The ground plane (1 sided quad) is fully coloured (i.e. full red, green and blue) like it should be since there is no objects occluding it. However the darker coloured 'ground planes' are imported with the model and they're two sided (2x 1 sided quad). :( Does that mean i have to create two separate shadow materials - one for interior surfaces, another for exterior surfaces - and apply a difference depth bias to each, or can i do something in the shader, or do i have to do something else?
User avatar
razi
Greenskin
Posts: 130
Joined: Tue Oct 14, 2008 5:54 pm
Location: Slovakia
x 17

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by razi »

Unfortunately theres not much to do, you just need to be smart about it. Shadow texture cant get you enough precision, here is he problem explained:
Image
You get Z fighting in front of model because texture couldnt be precise enough. You can:
1. use normal models with thick walls and use mSceneMgr->setShadowCasterRenderBackFaces(true); =standard way in Ogre samples, you get light leaking from edges of walls indoor(once again for texture precision)
2. use your models and some good depth bias to minimize Z fighting and avoid big light leaking indoors

Actually stencil shadows would be good for such scenarios since they dont use any textures.
Tweaking shadows for your setup might be compicated, but its not standard to use walls with 0 thickness.
User avatar
Kaylx
Greenskin
Posts: 123
Joined: Sun May 22, 2011 10:45 pm
Location: Scotland
x 7

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by Kaylx »

Stencil shadows would be perfect if they didn't come with such a performance hit, they work straight out the box, but some of our scenes/models can get rather complex, and with stencil shadows on, the app either crashes or the performance hit makes it unusable. I can fix the crash easy enough via some scene management, but even then, the performance hit isn't acceptable. :(
That's why I started looking into texture shadows. Unfortunately we can't change the models (we have to support both thin wall and thick wall models), so some form of smart biasing looks like the only option. I just don't have a clue where to start.

I've been looking a loads and loads of material on shadow maps and shadow volumes. Here's two a looked at:
CC Shadow Volumes
Resolution-Matched Shadow Maps
Anno1989
Goblin
Posts: 299
Joined: Mon Aug 25, 2008 2:50 pm
Location: Germany
x 6
Contact:

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by Anno1989 »

I have similar problems with scaling and bad shadowmap results. With me its 1m = 100units and the results are only good at 2048er maps and higher... There must be other params which have to be scaled I think. :?
Whats with the extrusion distance, f.e. its default value is 10,000 units, with me this would only be 100 ingame metres. I wonder where the problem lies... :|
http://www.espadon-online.eu/ MMORPG using Ogre3D
User avatar
tod
Troll
Posts: 1394
Joined: Wed Aug 02, 2006 9:41 am
Location: Bucharest
x 94
Contact:

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by tod »

Hi Razi,
I copied your code for PSSM shadows and it somehow works.
As I am a complete noob that's great, but I also have a problem. I see the terrain doesn't get PSSM shadows (by debugging). I've tried to set setReceiveDynamicShadowsPSSM(pssmShadowCam) but your PSSMShadowCameraSetup2 doesn't really extends PSSMShadowCameraSetup, so I cannot pass that. Could you explain a bit what is the difference with your approach? P.M. if you want, I don't want to hijack this informative thread.
User avatar
Pyritie
Gnome
Posts: 363
Joined: Wed Feb 25, 2009 6:15 pm
Location: UK
x 8
Contact:

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by Pyritie »

if I wanted to implement the sort of thing Razi's got, what do I need?

Some sort of ShadowCameraSetup subclass with that code in it, and what else?
I use Mogre, BulletSharp, LuaNetInterface, irrKlang, and Miyagi! | Ponykart (Showcase)
Image
User avatar
tod
Troll
Posts: 1394
Joined: Wed Aug 02, 2006 9:41 am
Location: Bucharest
x 94
Contact:

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by tod »

For what it's worth I only got this:

Code: Select all

mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED);
	mSceneMgr->setShadowFarDistance(512);
	
	// 3 textures per directional light
	mSceneMgr->setShadowTextureCountPerLightType(Ogre::Light::LT_DIRECTIONAL, mSettingsManager->getShadowDirectionalTextureCount());
	mSceneMgr->setShadowTextureCount(mSettingsManager->getShadowDirectionalTextureCount());
	mSceneMgr->setShadowTextureConfig(0,1024,1024,PF_FLOAT32_R);
	for(int i = 1; i < mSettingsManager->getShadowDirectionalTextureCount(); i++)
	{
		mSceneMgr->setShadowTextureConfig(i,512,512,PF_FLOAT32_R);
	}
	
	//mSceneMgr->setShadowTextureSettings(512, 3, PF_FLOAT32_R);
	
	
	mSceneMgr->setShadowTextureSelfShadow(true);
	mSceneMgr->setShadowCasterRenderBackFaces(false);
	mSceneMgr->setShadowTextureFadeStart(0.3);
	// Set up caster material - this is just a standard depth/shadow map caster
	//mSceneMgr->setShadowTextureCasterMaterial("PSSM/shadow_caster");

	// shadow camera setup
	PSSMShadowCameraSetup* pssmSetup = new PSSMShadowCameraSetup();
	pssmSetup->calculateSplitPoints(mSettingsManager->getShadowDirectionalTextureCount(), 1.0, 512);
	pssmSetup->setSplitPadding(1.0);
	pssmSetup->setOptimalAdjustFactor(0, 2);
	pssmSetup->setOptimalAdjustFactor(1, 1);
	pssmSetup->setOptimalAdjustFactor(2, 0.5);
	pssmSetup->setUseSimpleOptimalAdjust(false);

	mSceneMgr->setShadowCameraSetup(ShadowCameraSetupPtr(pssmSetup));
And on for terrain I got this:

Code: Select all

mTerrainOptions = OGRE_NEW TerrainGlobalOptions();
	
	TerrainMaterialGeneratorA::SM2Profile* pMatProfile = 
		static_cast<TerrainMaterialGeneratorA::SM2Profile*>(mTerrainOptions->getDefaultMaterialGenerator()->getActiveProfile());
	pMatProfile->setLightmapEnabled(false);
	pMatProfile->setReceiveDynamicShadowsEnabled(true);	
	pMatProfile->setReceiveDynamicShadowsLowLod(false);
I get pretty looking shadows on terrain (by my standards), no self shadows on entities, at this point. No changes to my materials whatsoever.
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by Mind Calamity »

That ought to prove useful when I start messing with shadows, thanks tod, and razi too of course :)
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
User avatar
Pyritie
Gnome
Posts: 363
Joined: Wed Feb 25, 2009 6:15 pm
Location: UK
x 8
Contact:

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by Pyritie »

tod wrote:For what it's worth I only got this:

Code: Select all

mSceneMgr->setShadowTechnique(SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED);
	mSceneMgr->setShadowFarDistance(512);
	
	// 3 textures per directional light
	mSceneMgr->setShadowTextureCountPerLightType(Ogre::Light::LT_DIRECTIONAL, mSettingsManager->getShadowDirectionalTextureCount());
	mSceneMgr->setShadowTextureCount(mSettingsManager->getShadowDirectionalTextureCount());
	mSceneMgr->setShadowTextureConfig(0,1024,1024,PF_FLOAT32_R);
	for(int i = 1; i < mSettingsManager->getShadowDirectionalTextureCount(); i++)
	{
		mSceneMgr->setShadowTextureConfig(i,512,512,PF_FLOAT32_R);
	}
	
	//mSceneMgr->setShadowTextureSettings(512, 3, PF_FLOAT32_R);
	
	
	mSceneMgr->setShadowTextureSelfShadow(true);
	mSceneMgr->setShadowCasterRenderBackFaces(false);
	mSceneMgr->setShadowTextureFadeStart(0.3);
	// Set up caster material - this is just a standard depth/shadow map caster
	//mSceneMgr->setShadowTextureCasterMaterial("PSSM/shadow_caster");

	// shadow camera setup
	PSSMShadowCameraSetup* pssmSetup = new PSSMShadowCameraSetup();
	pssmSetup->calculateSplitPoints(mSettingsManager->getShadowDirectionalTextureCount(), 1.0, 512);
	pssmSetup->setSplitPadding(1.0);
	pssmSetup->setOptimalAdjustFactor(0, 2);
	pssmSetup->setOptimalAdjustFactor(1, 1);
	pssmSetup->setOptimalAdjustFactor(2, 0.5);
	pssmSetup->setUseSimpleOptimalAdjust(false);

	mSceneMgr->setShadowCameraSetup(ShadowCameraSetupPtr(pssmSetup));
Where does that go?
I use Mogre, BulletSharp, LuaNetInterface, irrKlang, and Miyagi! | Ponykart (Showcase)
Image
User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia
x 81

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by Mind Calamity »

@Pyritie:

Most likely before or after you create your scene, i.e. just put it somewhere in your createScene() method or whatever you have to create the scene, make sure you create and initialize the Scene Manager and Camera beforehand.
BitBucket username changed to iboshkov (from MindCalamity)
Do you need help? What have you tried?
- xavier
---------------------
HkOgre - a Havok Integration for OGRE | Simple SSAO | My Blog | My YouTube | My DeviantArt
User avatar
tod
Troll
Posts: 1394
Joined: Wed Aug 02, 2006 9:41 am
Location: Bucharest
x 94
Contact:

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by tod »

After you create the scene manager, before adding entities and stuff. Not sure if it's required, that's the way I use it.
Don't take this too literal, as I am completely new to shadows. I just provided it as a starting point, as I seem to be some of the luckiest people that manage to get some form of PSSM shadows working without a month's work.
EDIT:
P.S. mSettingsManager->getShadowDirectionalTextureCount() is 3
User avatar
Pyritie
Gnome
Posts: 363
Joined: Wed Feb 25, 2009 6:15 pm
Location: UK
x 8
Contact:

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by Pyritie »

doesn't seem to be working

Code: Select all

		void SetupShadows() {
			sceneMgr.ShadowTechnique = ShadowTechnique.SHADOWTYPE_TEXTURE_MODULATIVE;

			sceneMgr.SetShadowTextureCountPerLightType(Light.LightTypes.LT_DIRECTIONAL, 3);
			sceneMgr.ShadowTextureCount = 3;
			sceneMgr.SetShadowTextureConfig(0, 1024, 1024, PixelFormat.PF_FLOAT32_R);
			sceneMgr.SetShadowTextureConfig(1, 512, 512, PixelFormat.PF_FLOAT32_R);
			sceneMgr.SetShadowTextureConfig(2, 512, 512, PixelFormat.PF_FLOAT32_R);
			sceneMgr.ShadowTextureSelfShadow = true;
			sceneMgr.ShadowCasterRenderBackFaces = false;
			sceneMgr.ShadowFarDistance = 512;

			PSSMShadowCameraSetup pssm = new PSSMShadowCameraSetup();
			pssm.SplitPadding = 1.0f;
			pssm.CalculateSplitPoints(3, camera.NearClipDistance, 512);
			pssm.SetOptimalAdjustFactor(0, 5);
			pssm.SetOptimalAdjustFactor(1, 1);
			pssm.SetOptimalAdjustFactor(2, 0.5f);
			pssm.UseSimpleOptimalAdjust = false;

			sceneMgr.SetShadowCameraSetup(new ShadowCameraSetupPtr(pssm));
		}

Code: Select all

			// a directional light to cast shadows
			Light light = sceneMgr.CreateLight("sun");
			light.Type = Light.LightTypes.LT_DIRECTIONAL;
			light.Direction = new Vector3(0.5f, -1, -0.2f);
			light.Direction.Normalise();
			light.DiffuseColour = new ColourValue(0.7f, 0.7f, 0.7f);
			light.SpecularColour = new ColourValue(0.7f, 0.7f, 0.7f);
			light.CastShadows = true;

			// and a point light
			Light pointLight = sceneMgr.CreateLight("pointLight");
			pointLight.Type = Light.LightTypes.LT_POINT;
			pointLight.Position = new Vector3(-30, 100, 30);
			pointLight.DiffuseColour = ColourValue.Blue;
			pointLight.SpecularColour = ColourValue.Blue;
			pointLight.CastShadows = true;

			// and a spotlight
			Light spotLight = sceneMgr.CreateLight("spotLight");
			spotLight.Type = Light.LightTypes.LT_SPOTLIGHT;
			spotLight.DiffuseColour = ColourValue.Green;
			spotLight.SpecularColour = ColourValue.Green;
			spotLight.Direction = new Vector3(-1, -1, 0);
			spotLight.Position = new Vector3(100, 100, 0);
			spotLight.SetSpotlightRange(new Degree(35), new Degree(50));
			spotLight.CastShadows = true;
if I change the technique to any of the other texture ones, it's the same. The only one with a difference is SHADOWTYPE_TEXTURE_MODULATIVE and it makes the shadow of the point light and spotlight work, but not the directional light.

Image

^ with all three lights

Image

^ with just the directional light
I use Mogre, BulletSharp, LuaNetInterface, irrKlang, and Miyagi! | Ponykart (Showcase)
Image
User avatar
tod
Troll
Posts: 1394
Joined: Wed Aug 02, 2006 9:41 am
Location: Bucharest
x 94
Contact:

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by tod »

I think the shadow receiver must have some settings in the material also. I don't know what settings as I use the standard terrain that has them integrated.
User avatar
Pyritie
Gnome
Posts: 363
Joined: Wed Feb 25, 2009 6:15 pm
Location: UK
x 8
Contact:

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by Pyritie »

odd, it seems like the shadows only work when I have a directional, spot, and point light. Disabling any one of them also turns off the shadows

my material code just looks like this

Code: Select all

material brick
{
	receive_shadows on
	
	technique
	{
		pass
		{
			cull_hardware none
			
			texture_unit
			{
				texture checker.dds
			}
		}
	}
}
Attachments
I changed the directional light to red instead of white
I changed the directional light to red instead of white
I use Mogre, BulletSharp, LuaNetInterface, irrKlang, and Miyagi! | Ponykart (Showcase)
Image
User avatar
zarlox
Halfling
Posts: 70
Joined: Tue Apr 19, 2011 12:32 am
Location: Canada
x 2

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by zarlox »

Isee you use SHADOWTYPE_TEXTURE_MODULATIVE with a PSSM camera. Maybe i am wrong but i think you can only use INTEGRATED shadow type with PSSM.

If you try to use non integrated shadow types which do not require you to implement the receiver shaders, then i do not know what the result will be.

Edit:

Just linking a post from JabberWocky since this is where i remember reading about it :)

http://www.ogre3d.org/forums/viewtopic. ... =0#p409509
User avatar
Pyritie
Gnome
Posts: 363
Joined: Wed Feb 25, 2009 6:15 pm
Location: UK
x 8
Contact:

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by Pyritie »

If I use one of the integrated ones, then I get no shadows at all.

Jabberwocky says that INTEGRATED is for use with shaders, and I don't have any shaders at all. Could this be what's wrong with it?
I use Mogre, BulletSharp, LuaNetInterface, irrKlang, and Miyagi! | Ponykart (Showcase)
Image
User avatar
zarlox
Halfling
Posts: 70
Joined: Tue Apr 19, 2011 12:32 am
Location: Canada
x 2

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by zarlox »

Pyritie wrote:If I use one of the integrated ones, then I get no shadows at all.

Jabberwocky says that INTEGRATED is for use with shaders, and I don't have any shaders at all. Could this be what's wrong with it?
It could certainly be. The non integrated ones are the ones that Ogre3D can handle by itself within the fixed pipeline. And i really think PSSM was designed to be used via shaders only, probably because the fixed pipeline can not handle more than one shadow map.

I know the RTSS shader system can handle the PSSM shadows so you can try the realtime shader approach instead of the fixed pipeline. But i know its still a lot of changes :?

Edit:

I never used the RTSS system but i know it can emulate all of the same functionnalities as the fixed pipeline. As well as supporting PSSM shadows so it could be a good solution for you.
User avatar
Pyritie
Gnome
Posts: 363
Joined: Wed Feb 25, 2009 6:15 pm
Location: UK
x 8
Contact:

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by Pyritie »

What's RTSS? I'm not using the terrain thing (I'm still on 1.7 mogre which doesn't have that yet)

Also I can't find a "PSSM/shadow_caster" material anywhere in my ogre samples, which is the material name everyone seems to keep referring to

EDIT: never mind, found them through google
Last edited by Pyritie on Wed Oct 19, 2011 6:51 pm, edited 1 time in total.
I use Mogre, BulletSharp, LuaNetInterface, irrKlang, and Miyagi! | Ponykart (Showcase)
Image
User avatar
zarlox
Halfling
Posts: 70
Joined: Tue Apr 19, 2011 12:32 am
Location: Canada
x 2

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by zarlox »

Pyritie wrote:What's RTSS? I'm not using the terrain thing (I'm still on 1.7 mogre which doesn't have that yet)
RTSS is not hing to do with the terrain system. Its a framework that can create shaders programmatically instead of you having to write shaders for every combination of lights, effects, and materials that you needs.

However, if you are using mogre, the RTSS framework might not be available to you.
Pyritie wrote:Also I can't find a "PSSM/shadow_caster" material anywhere in my ogre samples, which is the material name everyone seems to keep referring to
Look at the wiki page here for infos about how to handle PSSM in shaders:
http://www.ogre3d.org/tikiwiki/Parallel ... e=Cookbook

However, i am pretty sure you do not need anything special for the caster. The only thing you need is to use setCastShadow(true) on your entity. You can even continue to render the caster entity with fixed pipeline (as long as it does not have to receive the shadow)

Only entities that receive shadow via the PSSM needs to be implemented with shaders. The shader usually need to look at the distance and use the proper split shadow texture. Again have a look at the wiki page above for further infos.

But the bottom line is that if changing your scene to use shaders is too much, then you should keep using normal texture shadow without the PSSM.

Hope this helps
User avatar
Pyritie
Gnome
Posts: 363
Joined: Wed Feb 25, 2009 6:15 pm
Location: UK
x 8
Contact:

Re: Ogre::PSSMShadowCameraSetup blocky shadowing problem

Post by Pyritie »

Alright I think I got it working now! It doesn't look like it'll change much in my actual game except for a bunch of texture rewriting

Only problem I'm seeing is that it doesn't seem to like having more than one light source enabled at a time - if I have two directional lights, it only does shadows for one of them instead of both. Not sure if this is intentional, if this is just a limitation of the basic PSSM shader, or if it's a problem on my end again.

Code: Select all

materialbrick : PSSM/base_receiver
{
	set $diffuse checker.dds
}
Last edited by Pyritie on Wed Oct 19, 2011 7:07 pm, edited 1 time in total.
I use Mogre, BulletSharp, LuaNetInterface, irrKlang, and Miyagi! | Ponykart (Showcase)
Image
Post Reply