First I create a cube texture (6 sides). I render my scene with the following shader:
float4x4 xLightWorldViewProjection;
float4x4 xLightWorldView;
float xMaxDepth;
struct SMapVertexToPixel
{
float4 Position : POSITION;
float3 Depth : TEXCOORD0;
};
struct SMapPixelToFrame
{
float4 Color : COLOR0;
};
SMapVertexToPixel ShadowMapVertexShader( float4 inPos : POSITION)
{
SMapVertexToPixel Output = (SMapVertexToPixel)0;
Output.Position = mul(inPos, xLightWorldViewProjection);
Output.Depth = length(mul(inPos, xLightWorldView).xyz);
return Output;
}
SMapPixelToFrame ShadowMapPixelShader(SMapVertexToPixel PSIn)
{
SMapPixelToFrame Output = (SMapPixelToFrame)0;
float fDepthValue = PSIn.Depth;
Output.Color = float4(fDepthValue, fDepthValue, fDepthValue, 1.0f);
return Output;
}
technique ShadowMap
{
pass Pass0
{
VertexShader = compile vs_2_0 ShadowMapVertexShader();
PixelShader = compile ps_2_0 ShadowMapPixelShader();
}
}
I've seen the cube texture and it's getting rendered. As I move the light around I see the white square moveing in and out of each texture.
Then, when I draw my scene again, I pass the CubeTexture to my shader and sample it:
float4 texel = 0.0f;
float4 LightDirection = 0.0f;
LightDirection.xyz = input.Position.xyz - LightPosition;
float Distance = length( LightDirection.xyz );
float DepthColour = texCUBE(ShadowMapSampler, normalize(LightDirection.xyz)).x;
if ((Distance + 0.001f) > DepthColour)
{
not in shadow
texel = tex2D(texsampler, input.TexCoords);
}
With this code, everything gets drawn as normal, no shadows though
I think my problem may be in the light shader but I'm not sure.