Jump to content

  • Log In with Google      Sign In   
  • Create Account

Color pixels are being clipped at a different depth in GBuffer


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 CC Ricers   Members   -  Reputation: 623

Like
0Likes
Like

Posted 04 February 2013 - 01:15 PM

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.


My development blog: Electronic Meteor

Sponsor:

#2 phil_t   Crossbones+   -  Reputation: 3915

Like
0Likes
Like

Posted 04 February 2013 - 03:13 PM

It sounds like you might have alpha blending on (so the pixels with alpha > 0.5 end up being drawn, and you can still see the background through them). Turn it off for rendering to your G-buffer.
(if that's not the problem, perhaps you're using multisampling?)

#3 CC Ricers   Members   -  Reputation: 623

Like
0Likes
Like

Posted 04 February 2013 - 07:14 PM

I removed the line with the alpha clipping- it was a leftover from a non-terrain shader and don't really needed it for terrain anyways. I still don't see a difference in the visuals, though. The diffuse color buffer still stops drawing at a slightly closer distance. Here is a screenshot showing the problem:

 

dpyesdI.jpg


My development blog: Electronic Meteor

#4 phil_t   Crossbones+   -  Reputation: 3915

Like
0Likes
Like

Posted 04 February 2013 - 08:35 PM

The screenshot looks like it's after the final lighting pass. What do the individual buffers in the G buffer look like?
And you're sure alpha blending is off?

Edited by phil_t, 04 February 2013 - 08:36 PM.


#5 CC Ricers   Members   -  Reputation: 623

Like
0Likes
Like

Posted 04 February 2013 - 11:06 PM

In the individual buffers, the normal buffer and depth buffer both show the whole mountain, and in the diffuse color buffer, the mountain appears partly cut off, leaving that empty space that you see.

 

Right before I draw to the GBuffer, I clear the screen to black, set DepthStencilState to Default and BlendState to opaque. Then, to prepare it with default values, I fill the color buffer with black pixels, the normal buffer with gray, and depth buffer with white. Additive, not alpha, blending is used for the lighting pass, but I don't see how that would have any effect since the GBuffer is already created at that stage.

 

UPDATE: I just realized what it was. I was going to post a screenshot showing the individual buffers and also removed the skybox from the scene for visual clarity. After removing the skybox, I realized that the colors were being rendered correctly and nothing was clipped off prematurely. It seems that, although I put a restriction to render the skybox in its own depth range, I still needed to scale the skybox by a reasonable amount, or else it would cut into the scenery. So I changed the scaling amount from 20 to 200 and the colors aren't cut off anymore! And the skybox still appears the same size due to perspective.


Edited by CC Ricers, 04 February 2013 - 11:16 PM.

My development blog: Electronic Meteor




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS