Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: gl_FragCoord.z confusion

  1. #1
    Junior Member Newbie
    Join Date
    May 2011
    Location
    Italy
    Posts
    22

    gl_FragCoord.z confusion

    Hello,

    my question is simple.

    Where do gl_FragCoord.z come from?

    Is it coming from the rasterizer ( the eventually new incoming depth buffer value ) or is it the actual value grabbed from the depth buffer?

  2. #2
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,214

    Re: gl_FragCoord.z confusion

    I'll give you an answer by asking you a question.
    Does fragment shader execution comes before writing to a framebuffer of after? If you don't change fragmet's depth some of early-z techniques would eliminate FS execution if they are sure it wouldn't generate a new value in the framebuffer.

  3. #3
    Junior Member Newbie
    Join Date
    May 2011
    Location
    Italy
    Posts
    22

    Re: gl_FragCoord.z confusion

    ok ok.

    I'm trying to figure out how to access depth buffer directly in the fragment shader. It seems that DX10 can do that via Shader Resource View without rendering into a texture and binding it again in the second pass.

    Does OpenGL exposes this feature too?

  4. #4
    Senior Member OpenGL Pro Aleksandar's Avatar
    Join Date
    Jul 2009
    Posts
    1,214

    Re: gl_FragCoord.z confusion

    Why do you need that? To write your own function that will decide whether to write new Z-value in the dept buffer or something else? If you need the final values of the depth buffer you would need a second pass anyway.

  5. #5
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,065

    Re: gl_FragCoord.z confusion

    I'm trying to figure out how to access depth buffer directly in the fragment shader.
    You don't.

    It seems that DX10 can do that via Shader Resource View without rendering into a texture and binding it again in the second pass.
    That's just because D3D10 requires you to create the equivalent to OpenGL's "default" buffers itself. Shader Resource View is just a way to bind parts of textures (particular mipmaps, groups of mipmaps, etc) as textures to fetch from.

  6. #6
    Junior Member Newbie
    Join Date
    May 2011
    Location
    Italy
    Posts
    22

    Re: gl_FragCoord.z confusion

    Yes i would like to write my custom depth testing when i need it ( to avoid Z-fighting for example ). So is not possible to access depth buffer in the fragment shader.
    Right?

    There is a similar problem with blending. You can't access color buffer in the fragment shader and write your custom blending function. Right?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •