ShaderProgram QML Type
封装着色器程序。更多
Import Statement: | import Qt3D.Render 2.9 |
In C++: | QShaderProgram |
Status: | Deprecated |
属性
- computeShaderCode : string
- computeShaderGraph : string
- format : enumeration
- fragmentShaderCode : string
- fragmentShaderGraph : string
- geometryShaderCode : string
- geometryShaderGraph : string
- log : string
- status : enumeration
- tessellationControlShaderCode : string
- tessellationControlShaderGraph : string
- tessellationEvaluationShaderCode : string
- tessellationEvaluationShaderGraph : string
- vertexShaderCode : string
- vertexShaderGraph : string
方法
- string loadSource(url sourceUrl)
详细说明
ShaderProgram 类封装了着色器程序。着色器程序由多个不同的着色器(如顶点和片段着色器)组成。
如果在着色器检查阶段遇到默认制服,Qt3D 将自动填充一组默认制服。
默认着色器 | 相关 Qt3D 参数名称 | GLSL 声明 | |||
---|---|---|---|---|---|
模型矩阵 | 模型矩阵 | 统一 mat4 modelMatrix; | |||
视图矩阵 | viewMatrix | uniform mat4 viewMatrix; | |||
投影矩阵 | projectionMatrix | uniform mat4 projectionMatrix; | |||
模型视图矩阵 | 模型视图 | 统一 mat4 modelView.ViewProjectionMatrix | |||
视图投影矩阵 | viewProjectionMatrix | uniform mat4 viewProjectionMatrix; | |||
模型视图投影矩阵 | modelViewProjection mvp | uniform mat4 modelViewProjection; uniform mat4 mvp; | |||
反向模型矩阵 | inverseModelMatrix | uniform mat4 inverseModelMatrix; | |||
inverseViewMatrix | inverseViewMatrix | uniform mat4 inverseViewMatrix; | |||
反向投影矩阵 | inverseProjectionMatrix | uniform mat4 inverseProjectionMatrix; | |||
反向模型视图矩阵 | 逆模型视图矩阵 | uniform mat4 inverseModelView; | |||
InverseViewProjectionMatrix | inverseViewProjectionMatrix | uniform mat4 inverseViewProjectionMatrix; | |||
反向模型视图投影矩阵 | inverseModelViewProjection | uniform mat4 inverseModelViewProjection; | |||
模型法线矩阵 | modelNormalMatrix | uniform mat3 modelNormalMatrix; | |||
模型视图正态矩阵 | modelViewNormal | uniform mat3 modelViewNormal; | |||
视口矩阵 | viewportMatrix | uniform mat4 viewportMatrix; | |||
反向视口矩阵 | inverseViewportMatrix | uniform mat4 inverseViewportMatrix; | |||
宽高比 (表面宽/表面高 | 宽高比 | uniform float aspectRatio; | |||
曝光 | 曝光 | 统一浮点曝光; | |||
伽玛 | gamma | 均匀浮动伽马值; | |||
时间 (纳秒 | 时间 | 统一浮点时间; | |||
眼睛位置 | eyePosition | uniform vec3 eyePosition; | |||
蒙皮调色板 | skinningPalette[0] | const int maxJoints = 100; uniform mat4 skinningPalette[maxJoints]; |
支持 RHI
在编写与Qt 3D 的 RHI 后端一起使用的 GLSL 450 着色器代码时,默认制服将作为 2 个制服缓冲区对象提供。
这些对象的绑定位置设置为:RenderView 统一对象的绑定位置为 0,Command 统一对象的绑定位置为 1。
#version 450 core layout(location = 0) in vec3 vertexPosition; layout(std140, binding = 0) uniform qt3d_render_view_uniforms { mat4 viewMatrix; mat4 projectionMatrix; mat4 uncorrectedProjectionMatrix; mat4 clipCorrectionMatrix; mat4 viewProjectionMatrix; mat4 inverseViewMatrix; mat4 inverseProjectionMatrix; mat4 inverseViewProjectionMatrix; mat4 viewportMatrix; mat4 inverseViewportMatrix; vec4 textureTransformMatrix; vec3 eyePosition; float aspectRatio; float gamma; float exposure; float time; float yUpInNDC; float yUpInFBO; }; layout(std140, binding = 1) uniform qt3d_command_uniforms { mat4 modelMatrix; mat4 inverseModelMatrix; mat4 modelViewMatrix; mat3 modelNormalMatrix; mat4 inverseModelViewMatrix; mat4 modelViewProjection; mat4 inverseModelViewProjectionMatrix; }; void main() { gl_Position = (projectionMatrix * viewMatrix * modelMatrix * vertexPosition); }
对于用户定义的制服缓冲区对象,请使用从 2 开始的绑定或自动绑定,让Qt 3D 自动完成绑定。确保不同着色器阶段之间保持一致。
#version 450 core layout(std140, binding = auto) uniform my_uniforms { vec4 myColor; }; layout(location=0) out vec4 fragColor; void main() { fragColor = myColor; }
在向制服输入值时,不涉及任何更改。
在上述示例中,只需设置 myColor 即可:
Parameter { name: "myColor"; value: "blue" }
纹理仍需定义为独立的制服。
#version 450 core layout(binding=0) uniform sampler2D source; layout(location=0) out vec4 fragColor; void main() { fragColor = texture(source, vec2(0.5, 0.5)); }
属性文档
computeShaderCode : string |
保存此着色器程序使用的计算着色器代码。
computeShaderGraph : string |
保存此着色器程序生成器使用的计算着色器图形的 URL。
format : enumeration |
保存ShaderProgram 上提供的代码格式。默认为ShaderProgram.GLSL。
fragmentShaderCode : string |
保存此着色器程序使用的片段着色器代码。
fragmentShaderGraph : string |
保存此着色器程序生成器使用的片段着色器图形的 URL。
geometryShaderCode : string |
保存此着色器程序使用的几何着色器代码。
geometryShaderGraph : string |
保存此着色器程序生成器使用的几何着色器图形的 URL。
log : string |
保存当前着色器程序的日志。这有助于诊断着色器程序的编译失败。
status : enumeration |
当前着色器程序的状态。
tessellationControlShaderCode : string |
保存此着色器程序使用的细分控制着色器代码。
tessellationControlShaderGraph : string |
保存此着色器程序生成器使用的细分曲面控制着色器图形的 URL。
tessellationEvaluationShaderCode : string |
持有此着色器程序使用的网格评估着色器代码。
tessellationEvaluationShaderGraph : string |
保存此着色器程序生成器使用的网格评估着色器图形的 URL。
vertexShaderCode : string |
保存此着色器程序使用的顶点着色器代码。
vertexShaderGraph : string |
保存此着色器程序生成器使用的顶点着色器图形的 URL。
方法文档
© 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.