How can I "add" Depth information to the main frame buffer

Jean-Simon Brochu

Let's say I have this scene enter image description here

And I want to add depth information from a custom made fragment shader.

Now the intuitive thing to do would be to draw a quad over my teapot without depth test enabled but with glDepthMask( 1 ) and glColorMask( 0, 0, 0, 0 ). Write some fragments gl_FragDepth and discard some other fragments.

if ( gl_FragCoord.x < 100 )
    gl_FragDepth = 0.1;
else
    discard;

For some reason, on a NVidia Quadro 600 and K5000 it works as expected but on a NVidia K3000M and a Firepro(dont't remember which one), all the area covered by my discarded fragments is given the depth value of the quad.

Can't I leave the discarded fragments depth values unmodified?

EDIT I have found a solution to my problem. It turns out that as Andon M. Coleman and Matt Fishman pointed out, I have early_fragment_test enabled but not because I enabled it, but because I use imageStore, imageLoad.

With the little time I had to address the problem, I simply copied the content of my current depth buffer just before the "add depth pass" to a texture. Assigned it to a uniform sampler2D. And this is the code in my shader:

if ( gl_FragCoord.x < 100 )
    gl_FragDepth = 0.1;
else
{
    gl_FragDepth = texture( depthTex, gl_PointCoord ).r;
    color = vec4(0.0,0.0,0.0,0.0);
    return;
}

This writes a completely transparent pixel with an unchanged z value.

Matt Fichman

Well, it sounds like a driver bug to me -- discarded fragments should not hit the depth buffer. You could bind the original depth buffer as a texture, sample it using the gl_FragCoord, and then write the result back instead of using discard. That would add an extra texture lookup -- but it might be a suitable workaround.

EDIT: From section 6.4 of the GLSL 4.40 Specification:

The discard keyword is only allowed within fragment shaders. It can be used within a fragment shader to abandon the operation on the current fragment. This keyword causes the fragment to be discarded and no updates to any buffers will occur. Control flow exits the shader, and subsequent implicit or explicit derivatives are undefined when this exit is non-uniform. It would typically be used within a conditional statement, for example:

if (intensity < 0.0) discard;

A fragment shader may test a fragment’s alpha value and discard the fragment based on that test. However, it should be noted that coverage testing occurs after the fragment shader runs, and the coverage test can change the alpha value.if

(emphasis mine)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I add depth to a shape

From Dev

How can I add depth to a shape

From Dev

How to add a depth buffer in Moderngl EGL backend?

From Dev

How can I add columns in a data frame?

From Dev

OpenGL how can I attach a depth buffer to a framebuffer using a multisampled 2d texture

From Dev

How can I add EXIF information to geotag an Image in .NET?

From Dev

How can i add information to event in vuetify v-calendar?

From Dev

How can I add new directive information from a database?

From Dev

How can I add a shadow to actual screen frame on html?

From Dev

How can I add to select multiple values of subquery in main query

From Dev

How can I add to select multiple values of subquery in main query

From Dev

How do I add information from a data frame onto a US Map in R?

From Dev

How do I get WGL to create a 32 bit depth buffer?

From Dev

How can I return information after my main window closes in Qt?

From Dev

How can I return information after my main window closes in Qt?

From Dev

How to resolve a multisampled depth buffer to a depth texture?

From Dev

How can I tell the depth of a git repository?

From Dev

How can I convert char* buffer to unsigned char buffer

From Dev

How can I clear the buffer on a ReplaySubject?

From Dev

How can I rename a buffer to a similar name

From Dev

How can I fill this buffer faster in clojure

From Dev

How can I set Realtime WebSocket buffer?

From Dev

How can I check if a Vim buffer is modifiable?

From Dev

How can I tell if the pipe buffer is full?

From Dev

How can I tell if the pipe buffer is full?

From Dev

How can I separate signalsdata in buffer?

From Dev

How can I set Realtime WebSocket buffer?

From Java

How can a add a row to a data frame in R?

From Dev

How can I add a version/build information to my project and setup.py?

Related Related

  1. 1

    How can I add depth to a shape

  2. 2

    How can I add depth to a shape

  3. 3

    How to add a depth buffer in Moderngl EGL backend?

  4. 4

    How can I add columns in a data frame?

  5. 5

    OpenGL how can I attach a depth buffer to a framebuffer using a multisampled 2d texture

  6. 6

    How can I add EXIF information to geotag an Image in .NET?

  7. 7

    How can i add information to event in vuetify v-calendar?

  8. 8

    How can I add new directive information from a database?

  9. 9

    How can I add a shadow to actual screen frame on html?

  10. 10

    How can I add to select multiple values of subquery in main query

  11. 11

    How can I add to select multiple values of subquery in main query

  12. 12

    How do I add information from a data frame onto a US Map in R?

  13. 13

    How do I get WGL to create a 32 bit depth buffer?

  14. 14

    How can I return information after my main window closes in Qt?

  15. 15

    How can I return information after my main window closes in Qt?

  16. 16

    How to resolve a multisampled depth buffer to a depth texture?

  17. 17

    How can I tell the depth of a git repository?

  18. 18

    How can I convert char* buffer to unsigned char buffer

  19. 19

    How can I clear the buffer on a ReplaySubject?

  20. 20

    How can I rename a buffer to a similar name

  21. 21

    How can I fill this buffer faster in clojure

  22. 22

    How can I set Realtime WebSocket buffer?

  23. 23

    How can I check if a Vim buffer is modifiable?

  24. 24

    How can I tell if the pipe buffer is full?

  25. 25

    How can I tell if the pipe buffer is full?

  26. 26

    How can I separate signalsdata in buffer?

  27. 27

    How can I set Realtime WebSocket buffer?

  28. 28

    How can a add a row to a data frame in R?

  29. 29

    How can I add a version/build information to my project and setup.py?

HotTag

Archive