darbyjohnston / tlRender

tlRender is an open source library for building playback and review applications for visual effects, film, and animation.
BSD 3-Clause "New" or "Revised" License
193 stars 22 forks source link

Shader Clamping in imageFragmentSource() #135

Closed ggarra13 closed 7 months ago

ggarra13 commented 7 months ago

Currently, the "image" shader is clamping values between 0 and 1, causing problem on compositing out of range values. The "display" shader does not clamp as long as OCIO is not involved. With OCIO it also clamps, but not sure yet if that one is a bug.

Here's a sample test change in the shader code:

std::string imageFragmentSource()
        {
            return string::Format(
                "#version 410\n"
                "\n"
                "in vec2 fTexture;\n"
                "out vec4 outColor;\n"
                "\n"
                "{0}\n"
                "\n"
                "{1}\n"
                "\n"
                "{2}\n"
                "\n"
                "uniform vec4      color;\n"
                "uniform int       pixelType;\n"
                "uniform int       videoLevels;\n"
                "uniform vec4      yuvCoefficients;\n"
                "uniform int       imageChannels;\n"
                "uniform int       mirrorX;\n"
                "uniform int       mirrorY;\n"
                "uniform sampler2D textureSampler0;\n"
                "uniform sampler2D textureSampler1;\n"
                "uniform sampler2D textureSampler2;\n"
                "\n"
                "void main()\n"
                "{\n"
                "    vec2 t = fTexture;\n"
                "    if (1 == mirrorX)\n"
                "    {\n"
                "        t.x = 1.0 - t.x;\n"
                "    }\n"
                "    if (0 == mirrorY)\n"
                "    {\n"
                "        t.y = 1.0 - t.y;\n"
                "    }\n"
                "    outColor = sampleTexture(\n"
                "        t,\n"
                "        pixelType,\n"
                "        videoLevels,\n"
                "        yuvCoefficients,\n"
                "        imageChannels,\n"
                "        textureSampler0,\n"
                "        textureSampler1,\n"
                "        textureSampler2) *\n"
                "        color;\n"
                "\n"
                "    outColor.r = 3.0;\n"  // added for testing
                "\n"
                "}\n").
                arg(pixelType).
                arg(videoLevels).
                arg(sampleTexture);
        }

Do a glReadPixels() to get the value of the red channel or use mrv2's color picker to see the values clamping at 0..1.

ggarra13 commented 7 months ago

Found the new RenderOptions.offscreenColorType that fixes the problem.