Jump to content

  • Log In with Google      Sign In   
  • Create Account


Deferred rendering issue


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
23 replies to this topic

#1 Noxil   Members   -  Reputation: 451

Like
0Likes
Like

Posted 30 March 2013 - 02:33 AM

Hello

 

I have an issue in my deferred renderer (Dx9).
As seen in the attached image between my meshes there is a small black line.
This line becomes visible depending on the distance between the camera and the meshes.

 

The problem seems to be in the point light shader.
Since if i remove the light output and just draw color on the screenquad everything looks fine.

 

GBuffer:

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;
 
    float4 worldPos  = mul( float4(input.Position.xyz, 1.0f), World );
    output.Position  = mul( worldPos, ViewProjection );
    output.UV  = input.UV;
    output.Normal = mul( input.Normal, World );
    output.Depth.x  = output.Position.z;
    output.Depth.y  = output.Position.w;
 
    return output;
}
 
PixelShaderOutput PixelShaderFunction(VertexShaderOutput input) : COLOR0
{ 
    PixelShaderOutput output;
 
    output.Color = tex2D( DiffuseMapSampler, input.UV );
 
    output.Normal.xyz = ( input.Normal + 1.0f ) * 0.5f;    
    output.Normal.a = 1.0f;
 
    float D = input.Depth.x / input.Depth.y;
    output.Depth = float4( D, D, D, 1.0f );
 
    output.Glow = tex2D( GlowMapSampler, input.UV );
 
    return output;
}

 

Point Light:

 
VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;
 
    float4 worldPos  = mul( float4(input.Position.xyz, 1.0f), World );
    output.Position  = mul( worldPos, ViewProjection );
    output.ScreenPosition  = output.Position;
 
    return output;
}
 
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{ 
    //obtain screen position
    input.ScreenPosition.xy /= input.ScreenPosition.w;
 
    //obtain textureCoordinates corresponding to the current pixel
    //the screen coordinates are in [-1,1]*[1,-1]
    //the texture coordinates need to be in [0,1]*[0,1]
    float2 uv = 0.5f * ( float2(input.ScreenPosition.x,-input.ScreenPosition.y) + 1.0f );
 
    //allign texels to pixels
    uv += HalfPixel;
 
    //get normal data from the normalMap
    float4 normalData = tex2D( NormalMapSampler, uv );
 
    //tranform normal back into [-1,1] range
    float3 normal = normalize( 2.0f * normalData.xyz - 1.0f );
 
    //read depth
    float depth = tex2D( DepthMapSampler, uv ).r;
 
    //compute screen-space position
    float4 position;
    position.xy = input.ScreenPosition.xy;
    position.z = depth;
    position.w = 1.0f;
 
    //transform to world space
    position = mul( position, InversedViewProjection );
    position /= position.w;
 
    //surface-to-light vector
    float3 lightVector = LightLocation - position;
 
    //compute attenuation based on distance - linear attenuation
    float attenuation = saturate( 1.0f - (length(lightVector) / LightRadius) );
 
    //normalize light vector
    lightVector = normalize( lightVector ); 
 
    //compute diffuse light
    float NdL = saturate( dot(normal, lightVector) );
    float3 diffuseLight = NdL * Color.rgb * Intensity;
 
    return float4( diffuseLight, 1.0f ) * attenuation;
}

 

Any help is much appreciated! smile.png

Attached Thumbnails

  • problem.png


Sponsor:

#2 EarthBanana   Members   -  Reputation: 700

Like
0Likes
Like

Posted 30 March 2013 - 03:09 AM

I think fisrt you should figure out how to get rid of the giant red lines...

 

screenRenderTarget -= redLines;

 

something like that

 

sorry I have to be an idiot every once in a while.. keeps me feeling healthy. I had a similar problem using open gl once and it was because my meshes were slightly overlapping creating strange artifacts.. maybe try and space the meshes apart slightly more



#3 Noxil   Members   -  Reputation: 451

Like
0Likes
Like

Posted 30 March 2013 - 02:52 PM

Hey thanks for the reply.


I have double and tripple checked.

The meshes dont overlap.


Any other suggestion?



#4 Megahertz   Members   -  Reputation: 285

Like
0Likes
Like

Posted 30 March 2013 - 03:45 PM

Whats the near and far clip set to?


-=[Megahertz]=-

#5 Noxil   Members   -  Reputation: 451

Like
0Likes
Like

Posted 30 March 2013 - 04:05 PM

They are set to 1.0f and 1000.0f



#6 EarthBanana   Members   -  Reputation: 700

Like
0Likes
Like

Posted 31 March 2013 - 12:42 AM

there are a couple things to try - first change your background color from black to something else and see if the lines change color with it or if they stay black and you can see them on the outside of the meshes also..

 

if this is the case (where the lines appear black even with a different background color) the problem is likely with the texture you are mapping to the mesh.

 

Try changing your texture filtering settings - and if that doesn't help try switching out the texture to something else. If you are sending the shader texture coords that don't match

with the texture then you can get these strange artifacts also.



#7 Noxil   Members   -  Reputation: 451

Like
0Likes
Like

Posted 31 March 2013 - 02:02 AM

Interesting, if i change the background to white and change the texture to for examplea striped texture and only draw the colorbuffer on the screen quad.
I can see a white line instead...

I dont understand..
The mesh halfwidth is 12f, 0.5f, 12.0f, so it super easy to hardcode in the positions to be exact.

 

[Edit]:

Forget what i just said...
I exported a new mesh, the previous mesh had problems with its uv.
The problem still remains with the point light.

I can see a black line, it still black no matter what the background color is.


Edited by Noxil, 31 March 2013 - 02:41 AM.


#8 Noxil   Members   -  Reputation: 451

Like
0Likes
Like

Posted 31 March 2013 - 02:59 PM

A friend of mine said it might be a problem with floating point loss.
That in the vertex shader i guess, a vertex that is supposed to be at 1.0f in Y might be in 0.99998f
and that might be causing the problem.

 

Can this be the issue, if so how can i go about fixing it?



#9 ~0ul   Members   -  Reputation: 514

Like
0Likes
Like

Posted 31 March 2013 - 03:23 PM

I've never had issues with precision in vertex shaders so don't think that would be the issue. Try rendering your scene in wireframe, it might bring some geometry issues to light.



#10 galop1n   Members   -  Reputation: 226

Like
0Likes
Like

Posted 01 April 2013 - 03:24 AM

Could you dump the surfaces of the g buffer ? At such a small scale, i doubt there is float issues except if you are doing something really bad.



#11 Noxil   Members   -  Reputation: 451

Like
0Likes
Like

Posted 01 April 2013 - 04:40 AM

Could you dump the surfaces of the g buffer ? At such a small scale, i doubt there is float issues except if you are doing something really bad.

 

Dump the surface? I dont understand.



#12 galop1n   Members   -  Reputation: 226

Like
0Likes
Like

Posted 01 April 2013 - 04:57 AM

You need to copy the render targets to a lockable surface ( create in the symem pool ) with UpdateTexture/UpdateSurface or GetRenderTargetData. Then call LockRect on it to read the data on CPU to write them in an image file ( TGA or DDS are simple format to create )



#13 Hodgman   Moderators   -  Reputation: 24266

Like
0Likes
Like

Posted 01 April 2013 - 05:26 AM

Another way to dump the surfaces is to perform a single frame capture in PIX, find the render target you're after, then right click and save it as DDS.



#14 Noxil   Members   -  Reputation: 451

Like
0Likes
Like

Posted 01 April 2013 - 07:42 AM

The problem seem to be in the lightshader..

If i only draw the gbuffer surface there is no problem.

But as soon as i apply the light the blackline is there.



#15 Hodgman   Moderators   -  Reputation: 24266

Like
0Likes
Like

Posted 01 April 2013 - 08:18 AM

Does the black line stay in the same position in the world when you move your camera? Which attributes in the gbuffer are changing at that location? Is there a triangle edge at that location? Are you using MSAA at all?
 
There's some shader operations that can result in NaN, like x/0, 0^0, x^y where y < 0, etc.
You can add some debug checks before these 'dangerous' operations when testing, e.g.
 ...
    if( position.w == 0 )
        return float4(1,0,0,1);//red for debugging
    position /= position.w;
...

Edited by Hodgman, 01 April 2013 - 08:24 AM.


#16 galop1n   Members   -  Reputation: 226

Like
0Likes
Like

Posted 01 April 2013 - 08:19 AM

Seem means i am not sure, so you can use a frame debugger ( pix, gpuperfstudio or nsight ) and debug the pixel shader on a black pixel by yourself, or give us more information because without more, it is a bit of a dead end.



#17 Noxil   Members   -  Reputation: 451

Like
0Likes
Like

Posted 01 April 2013 - 09:18 AM

The black line is right at the edge of the mesh, where the two meshes would intersect if they where to overlap.
The line flickers and become less and more visible if i move the camera around.

Im not using msaa.



#18 Waterlimon   Crossbones+   -  Reputation: 2128

Like
0Likes
Like

Posted 01 April 2013 - 10:33 AM

Add random checks to check for non-wanted values and then replace them with something else, so when you find a spot where this fixes the error, you can start moving the check to find out where it happens.


The lack of awesome free resource gathering building sandbox games capable of running an user made 8 bit computer in the world disturbs me.

#19 Noxil   Members   -  Reputation: 451

Like
0Likes
Like

Posted 01 April 2013 - 11:56 AM

Thanks for all your tips and feedback.
I think i have narrowed down the problem.

 

In my screenquad shader, if i only draw the normals from the gbuffer i get the black line.

So somehow when i draw the normals to the gbuffer, something goes wrong on a few pixels.



#20 Juliean   GDNet+   -  Reputation: 1929

Like
0Likes
Like

Posted 01 April 2013 - 12:07 PM

How do you calculate the normals? In the modeling program, manually or using some d3dx-function?






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