I have a GBuffer shader in use with XNA to produce a typical output of diffuse/albedo, depth and normals. As all the vertex buffers are being batched and sent through with the same world, view and projection matrices for all render targets at once (and have no masked textures), I expected that they will all cover the same screen area for each render target. But the diffuse color component of the GBuffer appears to have the geometry cut off at a somewhat closer distance than the far clip plane of the camera.
When combined with the lighting, terrain at far distances has a transparent "trim" where you can see the lighting of the terrain, but not its color, so it shows the color of the background, skybox, etc behind it. So the depth and normal values are rendered at that distance, but not the diffuse color values. Indeed, I debug the render targets on PIX and in my program and there are less pixels being drawn to the diffuse component, as if it had its own far clipping value. I will post a screenshot of the problem later, until there here is my pixel shader GBuffer code.
struct VertexShaderOutput
{
float4 Position : POSITION0;
float2 TexCoord : TEXCOORD0;
float3 Depth : TEXCOORD1;
float3x3 TangentToWorld : TEXCOORD2;
};
struct PixelShaderOutput
{
half4 Color : COLOR0;
half4 Normal : COLOR1;
half4 Depth : COLOR2;
};
// First, relevant depth output code in the vertex shader
// wvp is the product of World, View and Projection matrices
output.Position = mul(input.Position, wvp);
output.Depth.x = output.Position.z;
output.Depth.y = output.Position.w;
// Complete GBuffer pixel shader
PixelShaderOutput PixelShaderGBuffer(VertexShaderOutput input)
{
PixelShaderOutput output;
// First check if this pixel is opaque
//output Color
output.Color = tex2D(diffuseSampler, input.TexCoord);
clip(output.Color.a - 0.5);
// Output the normal, in [0,1] space
float3 normalFromMap = tex2D(normalMapSampler, input.TexCoord);
normalFromMap = mul(normalFromMap, input.TangentToWorld);
output.Normal.rgb = 0.5f * (normalize(normalFromMap) + 1.0f);
// Output specular intensity
float4 specularAttributes = tex2D(specularSampler, input.TexCoord);
output.Normal.a = specularAttributes.r; //specularIntensity;
// Output Depth
output.Depth = input.Depth.x / input.Depth.y;
return output;
}
In this shader, the only pixels that I am clipping are the diffuse color texture, if the alpha value is less than 0.5. But this probably is not setting faraway pixels from being clipped, I hope.







