Cascaded Shadow Mapping & Poisson Disk filtering

A place to show off your latest screenshots and for people to comment on them. Only start a new thread here if you have some nice images to show off!
scrawl
OGRE Expert User
OGRE Expert User
Posts: 1119
Joined: Sat Jan 01, 2011 7:57 pm
x 2

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Post by scrawl » Fri Mar 29, 2013 3:50 pm

So, the first optimization that come to my mind was to render the four textures to a mrt in one pass (which saves lots of draw calls)
That is an interesting thought but definitely not possible.
Take a look (I borrowed duststorm's screenshot from the first page): http://www.ogre3d.org/forums/download/file.php?id=4486
The geometry positions in relation to the camera are different on each cascade.
What MRT can do is assign different colors to different outputs, but the rendered geometry itself is the same on all targets (they all render with the same camera).
0 x

Nodrev
Gremlin
Posts: 193
Joined: Fri Jan 25, 2008 6:55 pm
Location: Nantes / France

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Post by Nodrev » Fri Mar 29, 2013 4:00 pm

My though was to store "shadow camera view position" for each texture in vertex shader as texcoord, sending the "larger view texture" geometry. So, i was thinking it was doable as far as you do not use lod (because objects for which we want lot of details could have a lesser lod when taken from the wide range view), but indeed, different geometry is an obvious problem. Thanks for your fast answer :)
0 x

yisky
Gnoblar
Posts: 14
Joined: Tue Sep 17, 2013 12:06 pm

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Post by yisky » Tue Sep 24, 2013 8:06 am

I have wrote my demo as same as your demo project. But I can't see the shadow. And the shadow maps seem to be right. Why?
0 x

nickG
Greenskin
Posts: 122
Joined: Fri Jan 20, 2012 6:44 pm
Location: Russia,Moscow

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Post by nickG » Wed Feb 19, 2014 9:16 pm

if change

Code: Select all

mSceneMgr->setShadowTextureConfig(i, 1024, 1024, Ogre::PF_FLOAT16_R, 2);
to

Code: Select all

mSceneMgr->setShadowTextureConfig(i, 1024, 1024, Ogre::PF_FLOAT32_RGBA,0, 2);
the shadows are is not will blinking on small distance
0 x

namwenio
Halfling
Posts: 74
Joined: Fri Jun 21, 2013 2:12 am

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Post by namwenio » Sat Feb 22, 2014 11:20 pm

I'm trying to implement this technique, how can I modify the code to allow for alpha (like leaves) and also to accept a normal map?
0 x

User avatar
tod
Troll
Posts: 1394
Joined: Wed Aug 02, 2006 9:41 am
Location: Bucharest
Contact:

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Post by tod » Sun Mar 09, 2014 12:19 pm

Can someone explain to me how the fading works? I'm not able to see any correct results and I don't really understand the math.
0 x

hyrppa95
Gnoblar
Posts: 1
Joined: Tue Apr 15, 2014 1:59 pm

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Post by hyrppa95 » Tue Apr 15, 2014 2:13 pm

I discovered a little problem with shadow depth. The shader checks for shadow and camera depth, but due to some issue, it always passes. So everything is shadowed, even if the object casting shadow is under the receiver. I haven't found the reason yet, but i'm looking for it.
0 x

xelon
Halfling
Posts: 91
Joined: Mon Jan 07, 2013 4:24 am

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Post by xelon » Mon May 19, 2014 10:13 pm

Anyone managed to use this in a second pass on the same material?
I have a material that uses a vertex_program_ref and fragment_program_ref in one pass, and I want to add this shader into a second pass on the same material, anyone done that before? I'm not shaders expert, I con't find a way to tell the cascaded shadows that my texture is within the first pass inside a custom shader. :oops:

Edit: to clarify more the problem, my first pass is doing the triplanar calculations + lighting, second pass is the cascaded shadow mapping shader.
The example shows this

Code: Select all

material Examples/Athene/Basic : ShadowReceiver
{
	technique
	{
		pass
		{
			texture_unit Diffuse
			{
				texture athene.jpg 
			}
		}
	}
}
but what if I have this

Code: Select all

material Examples/Athene/Basic : ShadowReceiver
{
	technique
	{
		pass
		{
                        vertex_program_ref VP
			{
				
			}
			fragment_program_ref FP
			{
			
			}
			texture_unit Diffuse
			{
				texture athene.jpg 
			}
		}
	}
}
EDIT2: NVM I fixed the problem :D, after some heavy modifications to my existing shader, I have finally managed to mix both shaders together. I'm not that bad at shaders as I thought :lol:
0 x
Ludoria now on Kickstarter! Ludoria is now on KickStarter! https://www.kickstarter.com/projects/17 ... g-rpg-game
Ludoria's official website http://www.Ludoria.com
On Facebook https://www.facebook.com/pages/Ludoria/644733108967479
On Twitter https://twitter.com/LudoriaGame

User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2702
Joined: Mon Aug 29, 2005 3:24 pm
Location: Kuala Lumpur, Malaysia
x 3

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Post by syedhs » Tue May 20, 2014 6:03 am

Yes mixing two shaders are not that difficult.. provided firsthand, both are confirm to be in working order.. :mrgreen: Creating shader from zero is more dificult.
0 x
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me

Pulas
Halfling
Posts: 61
Joined: Sat Oct 29, 2011 9:39 am

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Post by Pulas » Sat Jun 07, 2014 5:37 am

Hi, thanks for sharing this amazing tech.
When I apply this tech with SceneManager::setCameraRelativeRendering(false), it works fine.
However, it doesn't work right with SceneManager::setCameraRelativeRendering(true).
How to adjust the original code to compatible with camera relative rendering?
0 x

nickG
Greenskin
Posts: 122
Joined: Fri Jan 20, 2012 6:44 pm
Location: Russia,Moscow

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Post by nickG » Sat Jun 07, 2014 3:12 pm

Fixed for many light sources?
0 x

starwind
Gnoblar
Posts: 2
Joined: Wed May 14, 2014 11:12 am

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Post by starwind » Fri Jun 20, 2014 3:27 am

Unfortunately, I encountered the same problem,When I Set the code SceneManager::setCameraRelativeRendering(true), The shadow doesn't work right! :( , ... any ideas would be appreciated very much!
0 x

nickG
Greenskin
Posts: 122
Joined: Fri Jan 20, 2012 6:44 pm
Location: Russia,Moscow

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Post by nickG » Sat Jun 21, 2014 2:10 pm

you need rewrite csm shader as pssm shader from ogre samples(you must rewrite global varibles on local)
0 x

User avatar
Mind Calamity
Ogre Magi
Posts: 1255
Joined: Sat Dec 25, 2010 2:55 pm
Location: Macedonia

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Post by Mind Calamity » Mon Jul 14, 2014 1:33 am

namwenio wrote:I'm trying to implement this technique, how can I modify the code to allow for alpha (like leaves) and also to accept a normal map?
Modified shadow caster shader to support alpha.
Well, a few months later here's your answer:

Replace or modify ShadowCaster.cg to this:

Code: Select all

/*  Copyright 2010-2012 Matthew Paul Reid
    This file is subject to the terms and conditions defined in
    file 'License.txt', which is part of this source code package.
*/

uniform sampler2D diffuseTexture : register(s0);

// Shadow caster vertex program.
void main_vp
(
	float4 position			: POSITION,
	float3 iTexCoord0		: TEXCOORD0,
	out float4 outPos		: POSITION,
	out float3 oTexCoord0	: TEXCOORD0,

	uniform float4x4 worldViewProj,
	uniform float4 texelOffsets
)
{
	outPos = mul(worldViewProj, position);

	// fix pixel / texel alignment
	outPos.xy += texelOffsets.zw * outPos.w;
	oTexCoord0 = iTexCoord0;
	oTexCoord0.z = outPos.z;
}

// Shadow caster fragment program for high-precision single-channel textures	
void main_fp
(
	float3 iTexCoord0		: TEXCOORD0,
	out float4 result		: COLOR
)
{
	float finalDepth = iTexCoord0.z;
	float4 diff = tex2D(diffuseTexture, iTexCoord0.xy);
	
	// Adjust 0.5 if you want more accurate alpha testing.
	if(diff.a < 0.5)
	{
		discard;
	}
	
	// If discarded, this shouldn't even matter.
	result = float4(finalDepth, finalDepth, finalDepth, 1);
}
You need to set the blend mode to alpha_blend and modify lines after 92 in ShadowReceiver.cg:

from

Code: Select all

//
oColor = tex2D(diffuseTexture, iTexCoord0.xy) * brightness;
oColor.a = 1;
to

Code: Select all

//
float4 diffuseTex = tex2D(diffuseTexture, iTexCoord0.xy);
oColor = diffuseTex * brightness;
oColor.a = diffuseTex.a;
If you have non-transparent materials at this point - add the discard condition to the fragment program in ShadowReceiver.cg.
0 x
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

Kenshido
Gremlin
Posts: 153
Joined: Tue Jun 09, 2009 9:31 am
Location: Russia
Contact:

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Post by Kenshido » Fri Nov 21, 2014 7:35 am

Is there a way to implement scene_depth_range with this technique?
0 x

dgraisins
Kobold
Posts: 38
Joined: Wed Jun 17, 2015 10:43 am

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Post by dgraisins » Wed Jul 15, 2015 8:27 am

Anyone else having tourble integrating this to thier project? The shadows are not showing for me.
0 x

tekron
Gnoblar
Posts: 1
Joined: Sun Sep 17, 2017 11:39 pm

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Post by tekron » Tue Sep 26, 2017 2:43 pm

duststorm wrote:
mail2ameen wrote:It looks like "shadow_caster_fragment_program_ref" is not available in "Cthugha" version.
It should be. Looks like that material statement has been around for quite some time already.
It should work with both 1.7 and 1.8
mail2ameen wrote:Is there any workaround for this?
I'm not sure what's causing it, but you could always create a shadow caster material, reference the VP and FP programs from there, and then reference to the shadow caster program using the "shadow_caster" option.
By creating a shadow caster material you can also simply set it on the scene manager for all entities (in code, using SceneManager::setShadowCasterMaterial()).
Hi, I'm trying to get this to work with 1.7 and apparently the link posted above already points to v1.8 upon checking the version with the same commit:
https://bitbucket.org/sinbad/ogre/src/6 ... ew-default

and so this attribute does not exist with 1.7

Code: Select all

shadow_caster_fragment_program_ref 
Any ideas? Also, how do you get this to work with hardware skinned meshes and terrain?

Thanks.
0 x

Post Reply