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:

#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:

#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
    }
}

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.

[QUOTE=romulogcerqueira;1291412]
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?[/QUOTE]
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.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.