Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-21550

Incorrect blending of a QML Fragment Shader output onto the scene

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 4.7.4
    • None
    • Windows, Ubuntu, Various graphics cards

    Description

      The blending formula of the output of a fragment shader on the scene seems to be incorrect.

      If S is the output of the fragment shader, and D the surface to be blended in, the blending formula seems to be vec3(S.rgb*0.5 +D.rgb*0.5) * (1-S.a) + vec3(S.rgb) * S.a, instead of vec3(D.rgb) * (1-S.a) + vec3(S.rgb) * S.a. That means, that when the output of a fragment shader is transparent (aka alpha component of 0), the RBG components are added to the one of the destination (halved), instead of being ignored.

      Notice that when the output of a fragment shader is opaque, or if its RBG component is 0 when its alpha is 0, there are no problems, which may make the problem hard to detect.

      It can be tested simply by doing:

      gl_FragColor = vec4(1.0f, 0.0f, 0.0f, 0.0f);

      If you have a black background, the zone covered by the shader will be between red and black, if you have a background with a red component of 255 (like a white background), it will be unchanged.

      The fragment shader in the uploaded zip test case is supposed to blend red onto the source image where it's not transparent, and keep other pixels transparent.

      Attachments

        1. test_qml.png
          test_qml.png
          17 kB
        2. test_qml.zip
          8 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            kkalland Kim Motoyoshi Kalland (Inactive)
            coyotte508 coyotte508
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes