Porting a simple shader from Qt5 to Qt6
-
wrote on 5 Dec 2023, 18:44 last edited by RobertB 12 May 2023, 18:55
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 typeNo 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; }
-
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 typeNo 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; }
@RobertB
texture2D
function is deprecated in GLSL v440 and only available in compatibility profile. Replace it with generictexture
function. -
@RobertB
texture2D
function is deprecated in GLSL v440 and only available in compatibility profile. Replace it with generictexture
function.wrote on 5 Dec 2023, 20:07 last edited by@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 generictexture
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/3