Page 3 of 3

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Posted: Fri Mar 29, 2013 3:50 pm
by scrawl
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).

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Posted: Fri Mar 29, 2013 4:00 pm
by Nodrev
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 :)

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Posted: Tue Sep 24, 2013 8:06 am
by yisky
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?

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Posted: Wed Feb 19, 2014 9:16 pm
by nickG
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

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Posted: Sat Feb 22, 2014 11:20 pm
by namwenio
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?

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Posted: Sun Mar 09, 2014 12:19 pm
by tod
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.

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Posted: Tue Apr 15, 2014 2:13 pm
by hyrppa95
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.

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Posted: Mon May 19, 2014 10:13 pm
by xelon
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:

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Posted: Tue May 20, 2014 6:03 am
by syedhs
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.

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Posted: Sat Jun 07, 2014 5:37 am
by Pulas
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?

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Posted: Sat Jun 07, 2014 3:12 pm
by nickG
Fixed for many light sources?

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Posted: Fri Jun 20, 2014 3:27 am
by starwind
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!

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Posted: Sat Jun 21, 2014 2:10 pm
by nickG
you need rewrite csm shader as pssm shader from ogre samples(you must rewrite global varibles on local)

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Posted: Mon Jul 14, 2014 1:33 am
by Mind Calamity
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.

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Posted: Fri Nov 21, 2014 7:35 am
by Kenshido
Is there a way to implement scene_depth_range with this technique?

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Posted: Wed Jul 15, 2015 8:27 am
by dgraisins
Anyone else having tourble integrating this to thier project? The shadows are not showing for me.

Re: Cascaded Shadow Mapping & Poisson Disk filtering

Posted: Tue Sep 26, 2017 2:43 pm
by tekron
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.