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

ShaderEffect renders text wrong

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P2: Important
    • Resolution: Unresolved
    • Affects Version/s: 5.15.2
    • Fix Version/s: None
    • Labels:
      None
    • Environment:
      Windows 10 - Qt 5.15.2

      Ubuntu 21.04 / X11 - Qt 5.15.2

      Arch Linux / X11 - Qt 5.15.2
    • Platform/s:
      Linux/X11, Windows

      Description

      When using a layer with a ShaderEffect on an item that contains text, the text renders incorrectly when the layer is enabled. Seems like a premultiplication issue but I'm not sure.

      I noticed the issue with a custom made shader but it can be replicated with a "native" ShaderEffect.

      Define a MyItem.qml file:

      import QtQuick 2.15
      import QtGraphicalEffects 1.15
      Item {
          id: root
          layer.enabled: true
          layer.samplerName: 'source'
          layer.effect: ShaderEffect {
              fragmentShader: "
                  #version 330 core // My whole application is using core 3.3 so that matches the global profile. Changing it back to default profile does not fix the issue anyways
                  uniform highp sampler2D source;
                  uniform lowp float qt_Opacity;
                  in highp vec2 qt_TexCoord0;
                  out highp vec4 out_color;
                  void main() { // Just pass the source texture through and apply opacity (does not change anything if I do not multiply by the opacity)
                      out_color = texture(source, qt_TexCoord0) * qt_Opacity;
                  }
              "
          }
      }
      

      And use it (in the screenshots it is used in an orange window)

      MyItem {
          width: 350
          height: 200
          Rectangle {
              width: 50
              height: 50
              x: 3
              y: 3
              gradient: Gradient {
                  GradientStop { position: 0.0; color: "red" }
                  GradientStop { position: 1.0; color: Qt.hsla(1.0, 0, 0, 0) }
              }
          }
      
          Text {
              text: 'This is a test text. See if the text looks "normal"'
              color: 'red'
          }
      }
      

      This shader is supposed to have no effect since it just passes the premultiplied source to the output that expects a premultiplied color. I should get the same result whether I enable or not the layer. But I get the results seen in the screenshots attached.

      Note that the same issue can be replicated by replacing my custom made shader by a ColorOverlay with "transparent" as color which preserves the input.

      Expected behavior: I should have not visual difference between enabled/disabled shader effects when the shader does not alter the source.

      Shader Effect Disabled Shader Effect Enabled

        Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

            Assignee:
            qt.team.graphics.and.multimedia Qt Graphics Team
            Reporter:
            ebatsin Bastien
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes