简体   繁体   English

将 Qt 着色器从 Qt 5.15 更新到 Qt 6.2

[英]Updating Qt Shader from Qt 5.15 to Qt 6.2

with the new Qt6.2 update, vertex and fragment shaders are required to be packaged in a.qsb file instead of embedded as strings in the ShaderEffect component.随着新的 Qt6.2 更新,顶点和片段着色器需要打包在 .qsb 文件中,而不是作为字符串嵌入到 ShaderEffect 组件中。

I'm trying to change my vertexShader to use the new standard.我正在尝试更改我的 vertexShader 以使用新标准。 Below is the code currently下面是目前的代码

vertexShader: "
                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;
                } 
"

How can I go about creating the.qsb file and using it in the ShaderEffect?我 go 如何创建 .qsb 文件并在 ShaderEffect 中使用它?

there are some link about how to create, use qsb files有一些关于如何创建、使用 qsb 文件的链接

QSB Manual质量标准局手册

ShaderEffect QML Type ShaderEffect QML 类型

Qt Shader Tools Qt 着色器工具

In CMake, you can use qt6_add_shaders to bake shaders into qsb files. CMake中可以使用qt6_add_shaders将shaders烘焙成qsb文件。 For example here is something I used in my project:例如,这是我在我的项目中使用的东西:

qt6_add_shaders(graph "graph-shaders"
  BATCHABLE
  PRECOMPILE
  OPTIMIZED
  PREFIX
  "/"
  FILES
  "shaders/cube/cube.frag"
  "shaders/cube/cube.vert"
  "shaders/line/line.frag"
  "shaders/line/line.vert"
  "shaders/noisy/noisy.frag"
  "shaders/noisy/noisy.vert"
  )

You can see that I have a folder where all of my shaders are located In there, and when I run CMake I receive the following information:您可以看到我有一个文件夹,我的所有着色器都位于其中,当我运行 CMake 时,我收到以下信息:

shaders/cube/cube.frag -> shaders/cube/cube.frag.qsb exposed as ://shaders/cube/cube.frag.qsb
shaders/cube/cube.vert -> shaders/cube/cube.vert.qsb exposed as ://shaders/cube/cube.vert.qsb
shaders/line/line.frag -> shaders/line/line.frag.qsb exposed as ://shaders/line/line.frag.qsb
shaders/line/line.vert -> shaders/line/line.vert.qsb exposed as ://shaders/line/line.vert.qsb
shaders/noisy/noisy.frag -> shaders/noisy/noisy.frag.qsb exposed as ://shaders/noisy/noisy.frag.qsb
shaders/noisy/noisy.vert -> shaders/noisy/noisy.vert.qsb exposed as ://shaders/noisy/noisy.vert.qsb

All of these compiled QSB files are located in the QT resource (which is included with the executable file).所有这些已编译的 QSB 文件都位于 QT 资源(包含在可执行文件中)中。 And Using it in QML or C++ is as simple as:在 QML 或 C++ 中使用它非常简单:

vertexShader: ":/shaders/noisy/noisy.vert.qsb"

It's so much cleaner now, as you can see:)如您所见,现在干净多了:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM