Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Porting a simple shader from Qt5 to Qt6
Forum Updated to NodeBB v4.3 + New Features

Porting a simple shader from Qt5 to Qt6

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 467 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RobertB
    wrote on last edited by RobertB
    #1

    I found a shader somewhere that worked on Qt5 and makes everything pixelated. Trying to port it to Qt6.

    #version 440
    
    #ifdef GL_ES
        precision mediump float;
    #endif
    
    layout(location = 0) out vec2 coord;
    layout(location = 1) in float qt_Opacity;
    layout(location = 2) in flat int numberOfPixels;
    layout(binding = 1) uniform sampler2D src;
    
    layout(location = 3) out vec4 fragColor;
    
    void main() {
        float scale = float(numberOfPixels);
        fragColor = texture2D(src, floor(coord*scale)/scale)*qt_Opacity;
    }
    

    But it fails on line 16, where the texture2D() call is.

    QSpirvCompiler: Failed to parse shader
    Shader baking failed: ERROR: src/assets/shaders/shaderPixel.frag:16: 'sampler/image' : cannot construct this type

    No idea - shader noob here. Maybe someone knows the solution?

    The original version that I used in QML's ShaderEffect{} on Qt5:

    frag

    #ifdef GL_ES
        precision mediump float;
    #endif
    
    varying highp vec2 coord;
    uniform sampler2D src;
    uniform lowp float qt_Opacity;
    uniform int numberOfPixels;
    
    void main() {
        float scale = float(numberOfPixels);
        gl_FragColor = texture2D(src, floor(coord*scale)/scale)*qt_Opacity;
    }
    

    vert

    uniform highp mat4 qt_Matrix;
    attribute highp vec4 qt_Vertex;
    attribute highp vec2 qt_MultiTexCoord0;
    varying highp vec2 coord;
    void main() {
        coord = qt_MultiTexCoord0;
        gl_Position = qt_Matrix * qt_Vertex;
    }
    
    Chris KawaC 1 Reply Last reply
    0
    • R RobertB

      I found a shader somewhere that worked on Qt5 and makes everything pixelated. Trying to port it to Qt6.

      #version 440
      
      #ifdef GL_ES
          precision mediump float;
      #endif
      
      layout(location = 0) out vec2 coord;
      layout(location = 1) in float qt_Opacity;
      layout(location = 2) in flat int numberOfPixels;
      layout(binding = 1) uniform sampler2D src;
      
      layout(location = 3) out vec4 fragColor;
      
      void main() {
          float scale = float(numberOfPixels);
          fragColor = texture2D(src, floor(coord*scale)/scale)*qt_Opacity;
      }
      

      But it fails on line 16, where the texture2D() call is.

      QSpirvCompiler: Failed to parse shader
      Shader baking failed: ERROR: src/assets/shaders/shaderPixel.frag:16: 'sampler/image' : cannot construct this type

      No idea - shader noob here. Maybe someone knows the solution?

      The original version that I used in QML's ShaderEffect{} on Qt5:

      frag

      #ifdef GL_ES
          precision mediump float;
      #endif
      
      varying highp vec2 coord;
      uniform sampler2D src;
      uniform lowp float qt_Opacity;
      uniform int numberOfPixels;
      
      void main() {
          float scale = float(numberOfPixels);
          gl_FragColor = texture2D(src, floor(coord*scale)/scale)*qt_Opacity;
      }
      

      vert

      uniform highp mat4 qt_Matrix;
      attribute highp vec4 qt_Vertex;
      attribute highp vec2 qt_MultiTexCoord0;
      varying highp vec2 coord;
      void main() {
          coord = qt_MultiTexCoord0;
          gl_Position = qt_Matrix * qt_Vertex;
      }
      
      Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @RobertB texture2D function is deprecated in GLSL v440 and only available in compatibility profile. Replace it with generic texture function.

      R 1 Reply Last reply
      2
      • Chris KawaC Chris Kawa

        @RobertB texture2D function is deprecated in GLSL v440 and only available in compatibility profile. Replace it with generic texture function.

        R Offline
        R Offline
        RobertB
        wrote on last edited by
        #3

        @Chris-Kawa said in Porting a simple shader from Qt5 to Qt6:

        @RobertB texture2D function is deprecated in GLSL v440 and only available in compatibility profile. Replace it with generic texture function.

        That worked, thanks. Trying to port the vertex shader now, but can't get it to work. I don't know what are inputs, or outputs, and how both frag/vert variables interact with eachother (if at all). Ill give up on this :-)

        1 Reply Last reply
        0
        • R RobertB has marked this topic as solved on

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved