The shader for generating the shadow map is indeed extremely simple :
\#if OPENGL
#define SV_POSITION POSITION
#define VS_SHADERMODEL vs_3_0
#define PS_SHADERMODEL ps_3_0
\#else
#define VS_SHADERMODEL vs_4_0_level_9_3
#define PS_SHADERMODEL ps_4_0_level_9_3
\#endif
matrix WorldViewProjection;
struct InstancingVSinput
{
float4 Position : POSITION0;
};
struct InstancingVSoutput
{
float4 Position : POSITION0;
float Depth : TEXCOORD0;
};
InstancingVSoutput InstancingVS(InstancingVSinput input, float4 HighlightColor : TEXCOORD1, float4x4 World : TEXCOORD2)
{
InstancingVSoutput output;
float4 pos = mul(mul(input.Position, World), WorldViewProjection);
output.Position = pos;
output.Depth = pos.z / pos.w;
return output;
}
float4 InstancingPS(InstancingVSoutput input) : COLOR0
{
return float4(input.Depth, input.Depth, input.Depth, 1);
}
technique Instancing
{
pass P0
{
VertexShader = compile VS_SHADERMODEL InstancingVS();
PixelShader = compile PS_SHADERMODEL InstancingPS();
}
};
I found out one of my problems is that a spritebatch.Begin() was setting the blendstate to AlphaBlend. My guess is that it was messing with the culling of my objects, because when the blendstate is set to opaque, the shadowmap generates about twice as fast.
As of now, I am sending 150k triangles using instanciation to the gpu, on a 2048x2048 texture (SurfaceFormat = Single)
My GPU manages to draw them in 4.6ms, in the “worst case” scenario (most of my shadowmap texture is filled.
Does that sound about right, or should I look into it further?