Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I was trying out a shadowmap. But all my shadow is white. I think there is some problem with my homogeneous component. Can anybody help me? The rest of my code is written in xna

Here is the hlsl code I used

float4x4 xWorld;
float4x4 xView;
float4x4 xProjection;

struct VertexToPixel
{
float4 Position         : POSITION;
float4 ScreenPos        : TEXCOORD1;
float Depth : TEXCOORD2;
};    
struct PixelToFrame
{
float4 Color            : COLOR0;
};

//------- Technique: ShadowMap --------
VertexToPixel MyVertexShader(float4 inPos: POSITION0, float3 inNormal: NORMAL0)
{
VertexToPixel Output = (VertexToPixel)0;    

float4x4 preViewProjection = mul(xView, xProjection);
float4x4 preWorldViewProjection = mul(xWorld, preViewProjection);
Output.Position =mul(inPos, mul(xWorld, preViewProjection)); 
Output.Depth = Output.Position.z / Output.Position.w;    
Output.ScreenPos = Output.Position;

return Output;
}

float4 MyPixelShader(VertexToPixel PSIn) : COLOR0
{
PixelToFrame Output = (PixelToFrame)0;      

Output.Color = PSIn.ScreenPos.z/PSIn.ScreenPos.w;   

return Output.Color;
}

technique ShadowMap
{
pass Pass0
{  
    VertexShader = compile vs_2_0 MyVertexShader();
    PixelShader  = compile ps_2_0 MyPixelShader();
}
}
share|improve this question

1 Answer 1

up vote 1 down vote accepted

I got it working, this is my solution. Why does this work? and the other one doesnt?

VertexToPixels MyVertexShaders(float4 inPos: POSITION0, float3 inNormal: NORMAL0)
{
VertexToPixels Output = (VertexToPixels)0;  

    Output.Position2D = mul(inPos, mul(xWorld,mul(xView,xProjection)));
Output.Depth  = Output.Position2D.zw;



return Output;
}


float4 MyPixelShaders(VertexToPixels PSIn) : COLOR0
{
PixelToFrames Output = (PixelToFrames)0;        

float4 color = float4(PSIn.Depth.x / PSIn.Depth.y, 0.0f, 0.0f, 1.0f);
return color;

}
technique ShadowMap
{
pass Pass0
{
    VertexShader = compile vs_2_0 MyVertexShaders();
    PixelShader  = compile ps_2_0 MyPixelShaders();
}
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.