Page 1 of 1
Shadows casted backwards?
Posted: Sat Dec 10, 2016 12:24 pm
by kubatp
Hi,
I have a strange problem with shadows. In my scene is just one directional light with this direction (0.4, -0.81, -0.40) - usual direction casting shadows on manual object (terrain) behind the entities. I use the depth shadow mapping. I have some animations which move (in the animation) the entity a bit below (sinking ship). For whatever reason the shadow of the sinking ship is casted on the terrain
.
Here is the video where you can see the problem.
https://youtu.be/w00Da4NZZY0
It seems to be a similar problem to this
http://ogre3d.org/forums/viewtopic.php?f=2&t=49584, unfortunately it is also without solution.
Does anyone have an idea how to solve this problem or at least on what solutions should I focus?
Thank you.
Re: Shadows casted backwards?
Posted: Mon Dec 12, 2016 6:31 pm
by kubatp
No ideas? Even ideas off the top of head would be appreciated.
Re: Shadows casted backwards?
Posted: Mon Dec 12, 2016 10:31 pm
by dark_sylinc
I'm confused: Are you using SHADOWTYPE_TEXTURE_ADDITIVE or SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED?
Because this is a typical limitation of SHADOWTYPE_TEXTURE_ADDITIVE. Receivers can't be casters and casters can't be receivers. Mark the terrain to not cast shadows. But even then I'm still not sure if that will fix it. It's been more than a decade since I don't use that technique.
If you're using SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED, then it's a whole different deal.
Re: Shadows casted backwards?
Posted: Tue Dec 13, 2016 12:13 am
by kubatp
Hello, thank you for reply.
I am using SHADOWTYPE_TEXTURE_ADDITIVE_INTEGRATED.
I am sorry for confusion.
Re: Shadows casted backwards?
Posted: Tue Dec 13, 2016 12:17 am
by dark_sylinc
If so then there must be a bug in either shadow pass' shaders or the receiver's. Or the receiver's bias an incredibly large value.
Most likely a mismatch in how the depth is written in caster (or expected to be read by the receiver).
Because this extremely depends on your shader code and material setup, it's virtually impossible to offer a solution. Best I can say is use PIX and Intel GPA to try to debug the problem.
Re: Shadows casted backwards?
Posted: Tue Dec 13, 2016 11:10 am
by kubatp
Hi Dark Sylinc,
thank you very much for your answer. I appreciate your will to help me. Frankly I am not familiar with shadows that much. I was able to get it to this point (as you can see from the video) with help of cg programmer but my knowledge of the shadows is limited.
dark_sylinc wrote:Most likely a mismatch in how the depth is written in caster (or expected to be read by the receiver).
This is something I am curious about. Do I have to set the SceneManager.SetShadowTextureCasterMaterial? I dont do it know at all. Basically I have pretty regular parent material for the units (e.g. ship) and material for terrain (which is a shadow receiver) which has this texture unit
Code: Select all
texture_unit shadow0
{
content_type shadow
tex_address_mode border
tex_border_colour 1 1 1 1
tex_coord_set 2
filtering anisotropic
max_anisotropy 3
}
where inside the fragment shader is
Code: Select all
tex2Dproj(shadowMap, vertex_output.lightSpacePos).x;
lightSpacePos is calculated in vertex shader
Code: Select all
output.lightSpacePos = mul( texViewProjMatrix, worldPos );
// make linear
output.lightSpacePos.z = (output.lightSpacePos.z - depthRange.x) * depthRange.w;
depthRange is taken from material declaration
Code: Select all
param_named_auto depthRange shadow_scene_depth_range 0
Like I said I am not that familiar with shadows, however I thought that the shadows are simply calculated out of the vertex shader of units and projected to the shadow texture which is used in the terrain. Am I wrong?
Re: Shadows casted backwards?
Posted: Fri Dec 16, 2016 3:15 pm
by kubatp
Noone can give me an advice in this?
Re: Shadows casted backwards?
Posted: Tue Apr 25, 2017 4:13 pm
by kubatp
Hi,
it has been a while but I was wondering if there is anyone who can give me a hand with this.
Basically I still have the problem with shadows (discussed below), which are casted "upwards" when they are below the shadow receiver. Here is a screenshot:
I think I have pretty basic materials, etc.:
Code: Select all
vertex_program shadowCaster_vs_cg cg
{
source shadow_caster.cg
entry_point mainVS
profiles vs_1_1 arbvp1
}
fragment_program shadowCaster_ps_cg cg
{
source shadow_caster.cg
entry_point main
profiles ps_2_0 arbfp1
}
Code: Select all
material shadowCaster
{
technique
{
pass
{
scene_blend alpha_blend
vertex_program_ref shadowCaster_vs_cg
{
param_named_auto worldViewProjMatrix worldviewproj_matrix
param_named_auto worldMatrix world_matrix
}
fragment_program_ref shadowCaster_ps_cg
{
}
}
}
}
Code: Select all
void mainVS(float4 position : POSITION,
float2 uv : TEXCOORD0,
out float4 oPosition : POSITION,
out float2 oUv : TEXCOORD0,
uniform float4x4 worldViewProjMatrix,
uniform float4x4 worldMatrix
)
{
oPosition = mul(worldViewProjMatrix, position);
float4 worldPos = mul( worldMatrix, position );
oUv[0] = step(worldPos.y, -0.1);
}
float4 main(
float2 oUv : TEXCOORD0,
uniform sampler2D texture
) : COLOR
{
if (oUv[0] == 1)
{
discard;
}
return float4(oUv[0],oUv[0],oUv[0],oUv[0]);
}
As you can see from the shader code, I created a workaround to get rid of the biggest issue - when objects are below -0.1 (on axe Y), I simply discard the shadow. It helped a bit, but the problem is that I still see some parts of shadows, which should not be seen (for example on hills, etc. which are higher than -0.1) because the model is partially "in" the surface (a.k.a. below the surface level).
I also set SetShadowTextureCasterMaterial("shadowCaster"); in the code.
Anyone who can tell me what can I try to fix it?
Re: Shadows casted backwards?
Posted: Sun May 14, 2017 10:13 am
by kubatp
Really no advices? I would be really grateful if someone helps me out here
Re: Shadows casted backwards?
Posted: Mon May 22, 2017 8:58 pm
by kubatp
I figured out one more interesting fact - when sceneManager.ShadowCasterRenderBackFaces is set to false, this isn't happening at all.
Unfortunately I cannot set it set to false, because there are some weird issues which are not there when ShadowCasterRenderBackFaces is set to true.
Any ideas?
Is there a way to set this some flag for ShadowCasterRenderBackFaces per entity? This would partially solve my problem...
Re: Shadows casted backwards?
Posted: Tue Jun 06, 2017 5:48 pm
by kubatp
I am not sure if anyone is reading this thread, because it seems like I am writing my own blog here:-D
Anyway, when I set ShadowCasterRenderBackFaces to false, the problem below is solved. The new issue which comes up is that all the entities are darkened
From the test and experiments I was running, it is pretty clear that the reason is that it is the shadow texture itself (And the shadow of each entity) which darken the entity - in short - when shadow of entity is applied, it is mapped to the entity itself.
Please, can somebody help me with this?
Any advices are appreciated!
Re: Shadows casted backwards?
Posted: Wed Jun 07, 2017 8:23 pm
by kubatp
There is really noone who would know something about it?
If someone help me solve this, I am able to pay for few hours which the advisor would spent on this. I am getting a bit desperate
