The testing scene is a big model + the player being able to move on top on it. When one spotlight is being used, everything works fine. The player casts shadows on the model and vice versa, self shadows work too.
But as I added more lights i noticed strange shadows on the Player. So I added debug code to the reciever shader, you can see the result in the attachment.
The different colored squares on the floor are the spotlights view frustrum, I only check wether each pixel lies inside of the shadows UV coordinates [0..1].
On the floor all lights are visible, including the shadows (which is basically the same). But on the player... you can only see the blue light, but only the part which would get lit from the red spotlight.
If the player is inside the red spot, the shadow is nearly all the time drawn correctly (exept inside the overlapping parts of the lights), while this is not the case with any other light. But as I disabled it, the same behaviour occurred with the next nearest light. So I thought it was a error with not all passes of the multipass material being rendered. To test wether the material gets rendered for every light i just outputtet in each pass the light colour - and it worked like it should.
So I'm really confused now... if the Object is big enough for being visible for all lights, all lights are being rendered correctly. But if not, it seems like only the light it spawns at (or the light nearest to the origin?) is being renderd correctly.
Code: Select all
material TestMat
{
technique
{
pass
{
vertex_program_ref ambient_vs
{
}
fragment_program_ref ambient_ps
{
}
texture_unit
{
texture TestMap.png
}
}
pass
{
iteration once_per_light
scene_blend add
vertex_program_ref perLight_vs
{
}
fragment_program_ref perLight_ps
{
}
texture_unit
{
content_type shadow
filtering none
}
texture_unit
{
texture TestMap.png
}
}
}
}
Code: Select all
float4x4 WVPM;
float4x4 texViewProj;
float4x4 world;
struct VS_INPUT
{
float4 Position : POSITION0;
float2 UV : TEXCOORD0;
float3 Normal : NORMAL;
};
struct VS_OUTPUT
{
float4 Position : POSITION0;
float2 UV : TEXCOORD0;
float3 lightPos : TEXCOORD1;
float3 Normal : TEXCOORD2;
float4 ShadowUV : TEXCOORD3;
};
VS_OUTPUT perLight_vs( VS_INPUT Input )
{
VS_OUTPUT Output;
Output.Position = mul( WVPM, Input.Position );
Output.UV = Input.UV;
Output.lightPos = lightPos.xyz - Input.Position.xyz;
Output.Normal = Input.Normal;
float4 worldPos = mul(world, Input.Position);
Output.ShadowUV = mul( texViewProj, worldPos );
return( Output );
}
float4 lightColour;
float3 lightDir;
float4 spotParams;
sampler2D tex: register(s1);
sampler2D shadowMap: register(s0);
struct PS_INPUT
{
float2 UV : TEXCOORD0;
float3 relLightPos : TEXCOORD1;
float3 Normal : TEXCOORD2;
float4 ShadowUV : TEXCOORD3;
};
float4 perLight_ps( PS_INPUT Input ) : COLOR
{
Input.ShadowUV = Input.ShadowUV / Input.ShadowUV.w;
if (Input.ShadowUV.x > 0 && Input.ShadowUV.x < 1 && Input.ShadowUV.y > 0 && Input.ShadowUV.y < 1)
return tex2D( tex, Input.UV ) * (lightColour * LdotN / dSqr);
else
return float4(0,0,0,1);
}
It seems like everything works exept the UV coordinates of the Shadow map.