I've been struggling with this for awhile, and everything I find online says this SHOULD be working, but I apparently missed something.
I'm attempting to run Deferred Rendering in SharpDX on a Store App. I have a main effect that outputs my color, normal and depth in three render targets. My color and normal look good, but I can't get the depth to render properly, and I think it's my position calculations in the Vertex Buffer. Of course, when I debug this in VS2013 Graphics Analyzer, all the data is 'optimized' away, so I can't see my actual values.
As you can see in the Depth Target, every pixel is getting output as 1 in the red channel, instead of the actual depth values. The horizon you see is the 'ground' getting clipped by the farplane, so the depth target should show the full extent
Here's my effect
float4x4 World;
float4x4 View;
float4x4 Projection;
float specularIntensity = 0.8f;
float specularPower = 0.5f;
texture2D Texture;
SamplerState TextureSampler
{
AddressU = Wrap;
AddressV = Wrap;
};
struct VertexShaderInput
{
float4 Position : SV_POSITION;
float3 Normal : NORMAL0;
float2 TexCoord : TEXCOORD0;
};
struct VertexShaderOutput
{
float4 Position : SV_POSITION;
float2 TexCoord : TEXCOORD0;
float3 Normal : TEXCOORD1;
float2 Depth : TEXCOORD2;
};
VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
VertexShaderOutput output;
float4x4 wvp = mul(mul(World, View), Projection);
output.Position = mul(float4(input.Position), wvp);
output.TexCoord = input.TexCoord;
output.Normal = mul(input.Normal, World);
output.Depth.x = output.Position.z;
output.Depth.y = output.Position.w;
return output;
}
struct PixelShaderOutput
{
float4 Color : SV_TARGET0;
float4 Normal : SV_TARGET1;
float Depth : SV_TARGET2;
};
PixelShaderOutput PixelShaderFunction(VertexShaderOutput input)
{
PixelShaderOutput output;
output.Color = Texture.Sample(TextureSampler, input.TexCoord);
output.Color.a = specularIntensity;
output.Normal.rgb = 0.5f * (normalize(input.Normal) + 1.0f);
output.Normal.a = specularPower;
output.Depth = input.Depth.x / input.Depth.y;
return output;
}
technique Technique1
{
pass Pass1
{
VertexShader = compile vs_4_0 VertexShaderFunction();
PixelShader = compile ps_4_0 PixelShaderFunction();
}
}