Hi,
I'm hoping someone can help me with a problem I'm struggling with.
I have my one little engine going with deferred rendering and shadows etc. Now I'm trying to do a forward rendering pass for transparent models.
I've got as far as getting the models to render (and be transparent) but I don't seem able to work out how to use my depth map in the forward pass. I'm possibly getting lost in the various coordinate spaces.
Here's a screen shot of the problem (the barrel shouldn't be visible since its behind the wall)
The shader is pretty simple for rendering the barrel:
VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
VertexShaderOutput output;
float4 worldPosition = mul(float4(input.Position.xyz,1), World);
float4 viewPosition = mul(worldPosition, View);
output.Position = mul(viewPosition, Projection);
output.Depth.x = output.Position.z;
output.Depth.y = output.Position.w;
output.TexCoord = input.TexCoord;
?
return output;
}
struct PixelShaderOutput
{
half4 Color : COLOR0;
};
PixelShaderOutput PixelShaderFunction(VertexShaderOutput input)
{
//sample depth from depth map
float depthFromMap = tex2D(DepthMapSampler, input.TexCoord).r;
float depthOfPixel = input.Depth.x/input.Depth.y;
if (depthFromMap < depthOfPixel)
discard;
PixelShaderOutput output;
output.Color = tex2D(diffuseSampler, input.TexCoord);
output.Color.a = 0.1f;
return output;
}
And the shader for creating the depth map is:
VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
VertexShaderOutput output;
float4 worldPosition = mul(float4(input.Position.xyz,1), World);
float4 viewPosition = mul(worldPosition, View);
output.Depth.x = output.Position.z;
output.Depth.y = output.Position.w;
return output;
}
PixelShaderOutput PixelShaderFunction(VertexShaderOutput input)
{
PixelShaderOutput output;
output.Depth = input.Depth.x / input.Depth.y;
return output;
}
Which seems essentially the same. So what am I doing wrong, any ideas please?