将 Shadertoy 特效移植到Qt Quick Effect Maker
您可以在Qt Quick Effect Maker 中使用 Shadertoy 创建的特效。使用 Shadertoy 特效时,请注意以下几点:
- Qt Quick Effect Maker 不支持以下 Shadertoy 功能:
- 多通道特效(缓冲选项卡)
- 音频
- 立方体贴图
- 三维纹理
- Shadertoy 仅支持片段着色器和内置纹理。为提高Qt Quick Effect Maker 中的效果性能,可将部分计算移至顶点着色器,并使用自定义图像来简化着色器代码。
- Shadertoy 和Qt Quick Effect Maker 的坐标系不同。在 Shadertoy 中,原点 (0,0) 位于左下角,而Qt Quick Effect Maker 的原点位于左上角。
使用 Shadertoy 特效Qt Quick Effect Maker
在Qt Quick Effect Maker 中使用 Shadertoy 效果:
- 在Qt Quick Effect Maker 中,创建一个新特效。
- 在节点编辑器中,选择Add node ,然后在Common 下选择Custom 。这将创建一个空节点。
- 在 Shadertoy 中,复制Image 选项卡中的所有代码。
- 在Qt Quick Effect Maker 中,双击节点编辑器中的Custom 节点。这将打开代码编辑器。
- 将 Shadertoy 代码粘贴到Frag 标签页。
- 在代码中找到
Main
函数,它看起来像这样:void mainImage( out vec4 fragColor, in vec2 fragCoord )
- 将这一行替换为
@main
注意: 不能将
@main
和下面的 { 放在同一行。 - 可选。如果效果取决于坐标系,则会出现上下颠倒的情况。要解决这个问题,您需要翻转 Y 坐标:
- 转到Vert 选项卡。
- 在下拉菜单中选择Main 。
- 找到
fragCoord
线,它应该看起来像这样:fragCoord = qt_Vertex.xy;
- 将这一行替换为
fragCoord = vec2(qt_Vertex.x, iResolution.y - qt_Vertex.y);
- 同样,您可能需要调整
texCoord
和iMouse
。
- 转到Vert 选项卡。
现在,该特效的运行和外观与 Shadertoy 特效相同。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.