Skip to content

Instantly share code, notes, and snippets.

@demonixis
Created July 19, 2014 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save demonixis/e111048bd58a1f1155f3 to your computer and use it in GitHub Desktop.
Save demonixis/e111048bd58a1f1155f3 to your computer and use it in GitHub Desktop.
A shadow map shader to use in a XNA/MonoGame application.
float4x4 World;
float4x4 View;
float4x4 Projection;
struct VertexShaderInput
{
float4 Position : POSITION0;
};
struct VertexShaderOutput
{
float4 Position : POSITION0;
float2 depth:TEXCOORD0;
};
VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
VertexShaderOutput output;
float4 worldPosition = mul(input.Position, World);
float4 viewPosition = mul(worldPosition, View);
output.Position = mul(viewPosition, Projection);
output.depth = output.Position.zw;
return output;
}
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
return input.depth.x /input.depth.y;
}
technique Technique1
{
pass Pass1
{
#if SM4
VertexShader = compile vs_4_0_level_9_3 VertexShaderFunction();
PixelShader = compile ps_4_0_level_9_3 PixelShaderFunction();
#else
VertexShader = compile vs_3_0 VertexShaderFunction();
PixelShader = compile ps_3_0 PixelShaderFunction();
#endif
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment