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 3 of 3

Thread: Write Fragdepth to FBO

  1. #1
    Intern Newbie
    Join Date
    Jan 2018
    Posts
    42

    Write Fragdepth to FBO

    What do I need to divide/multiply/shift gl_FragDepth by to write it out to an FBO?




    I have never gotten it to work, and I need to use it.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,791
    Quote Originally Posted by Geklmin View Post
    What do I need to divide/multiply/shift gl_FragDepth by to write it out to an FBO?
    For a normalised (non-floating-point) depth buffer, gl_FragDepth needs to be between 0.0 and 1.0. The value of gl_FragDepth on entry to the fragment shader is unspecified, i.e. you shouldn't read it unless you've already written to it.

    If the shader doesn't include an assignment to gl_FragDepth, then gl_FragCoord.z will be used as the depth. If the shader conditionally assigns to gl_FragDepth, then any invocation which doesn't assign to it will result in an unspecified depth value being written (i.e. the determination of whether to use gl_FragDepth or gl_FragCoord.z is made when the code is compiled).

    Assigning to gl_FragDepth is incompatible with early depth tests (i.e. they won't be silently enabled as an optimisation, and if the shader explicitly enables them then any assignment to gl_FragDepth is ignored).

  3. #3
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,003
    What do I need to divide/multiply/shift gl_FragDepth by to write it out to an FBO?
    `gl_FragDepth` is directly hooked into the depth attachment of a framebuffer object. There is nothing you can do to change where it gets written. The only thing you can control is the image format of the texture that you attach as the depth attachment for the FBO.

Posting Permissions

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