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: Float Precision in GLSL 130

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2017
    Posts
    17

    Float Precision in GLSL 130

    Folks!

    I have calculated the normal and depth values from shader, however this result always is limited in 8-bit floating precision. I'm looking for 32-bit floating precision. Do you have any tips how can I increase this floating precision?
    I took a look on web and there is an extension to increase the precision on shaders (version 150 and GL_ARB_gpu_shader_fp64). Is it a good approach?

    Vertex:
    Code :
    #version 130
     
    out vec3 positionEyeSpace;
    out vec3 normalEyeSpace;
     
    void main() {
        gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
     
        // eye space
        positionEyeSpace = vec3(gl_ModelViewMatrix * gl_Vertex);
        normalEyeSpace = gl_NormalMatrix * gl_Normal;
    }


    Fragment:
    Code :
    #version 130
     
    in vec3 positionEyeSpace;
    in vec3 normalEyeSpace;
    uniform float farPlane;
    out vec4 output;
     
    void main() {
        vec3 nNormalEyeSpace = normalize(normalEyeSpace);
     
        // Depth calculation
        vec3 nPositionEyeSpace = normalize(-positionEyeSpace);
        float linearDepth = sqrt(positionEyeSpace.x * positionEyeSpace.x +
                                 positionEyeSpace.y * positionEyeSpace.y +
                                 positionEyeSpace.z * positionEyeSpace.z);
        linearDepth = linearDepth / farPlane;
        gl_FragDepth = linearDepth;
     
        // output the normal and depth data as matrix
        output = vec4(0, 0, 0, 1);
        if (linearDepth <= 1) {
            output.z = abs(dot(nPositionEyeSpace, nNormalEyeSpace));    // normal
            output.y = linearDepth;                                     // depth
        }
    }

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,359
    Quote Originally Posted by romulogcerqueira View Post
    I have calculated the normal and depth values from shader, however this result always is limited in 8-bit floating precision. I'm looking for 32-bit floating precision. Do you have any tips how can I increase this floating precision?
    Let's start with the basics.

    How are you inferring that the normal and depth precision you're getting is 8-bit floating point?

    What GPU and GL driver are you running with?

    I took a look on web and there is an extension to increase the precision on shaders (version 150 and GL_ARB_gpu_shader_fp64). Is it a good approach?
    Totally overkill at this point until we have more details on the table.

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,790
    Quote Originally Posted by romulogcerqueira View Post
    I have calculated the normal and depth values from shader, however this result always is limited in 8-bit floating precision. I'm looking for 32-bit floating precision. Do you have any tips how can I increase this floating precision?
    Use a floating-point format (e.g. GL_RGB32F) for the texture used for the colour buffer.

    GLSL itself (assuming you're talking about desktop OpenGL, not OpenGL ES) has the same floating-point precision as IEEE-754 single-precision: i.e. a 24-bit significand.

Posting Permissions

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