Skip to main content
GameDev.net gamedev.net
🔒 Locked

Issues with comparing depth textures

Started by Jossos Jan 20, 2016 at 2:22 PM 2 replies 1.9k views
Original Post
Jossos
Jossos

I'm following a tutorial, trying to blur the edges of water, but I'm getting weird jaggies which I just can't seem to get rid of:

nhZGCQy.jpg

This is caused by the depth texture ("depthMap") having a lower resolution than the screen, which I want for optimization. Here is the shader: http://pastebin.com/QfZHBttT

Noteable parts:


    float depth = texture2D(depthMap, refractUV).r;
    float floorDistance = 2.0 * near * far / (far + near - (2.0 * depth - 1.0) * (far - near));
    if (depth >= 1.0)
        discard;  // This never works
       
    depth = gl_FragCoord.z;
    float waterDistance = 2.0 * near * far / (far + near - (2.0 * depth - 1.0) * (far - near));
    float waterDepth = floorDistance - waterDistance;




FragColor.r = waterDepth;  // using this to show what's going on.

I am not sure how to fix this. I just need those edge pixels to be invisible. They appear at any time the resolution of the depth texture is lower than the screen.

Any help is appreciated.

HappyCoder
HappyCoder
Could you describe your pipeline? I can only gather so much from what you have but it seems like this is what you are doing.

1. Render underwater geometry at a lower resolution off screen
2. Render world geometry at full resolution
3. Render water at full resolution using off screen data from stage 1

Is this correct?
My current game project Platform RPG
Jossos
Jossos

Could you describe your pipeline? I can only gather so much from what you have but it seems like this is what you are doing.

1. Render underwater geometry at a lower resolution off screen
2. Render world geometry at full resolution
3. Render water at full resolution using off screen data from stage 1

Is this correct?

I think so. I have refraction/reflection textures rendered at 1/4 of the screen resolution, as well as the depth. I then render full screen at full resolution, comparing gl_fragcoords.z with the depth texture (which is at 1/4 resolution)

carl_cds
carl_cds

This sounds like it could be fixed by a cross bilateral-upsample shader.

see http://docs.nvidia.com/gameworks/content/gameworkslibrary/graphicssamples/opengl_samples/particleupsamplingsample.htm

for how a similar low-res/high-res buffer composition system works.

This technique helped with these artifacts when I composited a lower-resolution volume lighting buffer with a full resolution scene rendering.

- CStone

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.