summaryrefslogtreecommitdiffstats
path: root/src/render/materialsystem/qshaderprogram.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/render/materialsystem/qshaderprogram.cpp')
-rw-r--r--src/render/materialsystem/qshaderprogram.cpp188
1 files changed, 188 insertions, 0 deletions
diff --git a/src/render/materialsystem/qshaderprogram.cpp b/src/render/materialsystem/qshaderprogram.cpp
index 1c5eed7f8..2ae20ac55 100644
--- a/src/render/materialsystem/qshaderprogram.cpp
+++ b/src/render/materialsystem/qshaderprogram.cpp
@@ -175,6 +175,101 @@
\li {3, 1} const int maxJoints = 100; \br uniform mat4 skinningPalette[maxJoints];
\endtable
+
+ \section1 RHI Support
+
+ When writing GLSL 450 shader code to use with Qt 3D's RHI backend,
+ the default uniforms will be provided as 2 uniform buffer objects.
+
+ The binding locations for these is set to bindings 0 for RenderView
+ uniforms and 1 for Command uniforms.
+
+ \badcode
+ #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);
+ }
+ \endcode
+
+ For user defined uniform buffer object, use binding starting at 2 or auto
+ to let Qt 3D work out the binding automatically. Make sure to remain
+ consistent between the different shader stages.
+
+
+ \badcode
+ #version 450 core
+
+ layout(std140, binding = auto) uniform my_uniforms {
+ vec4 myColor;
+ };
+
+ layout(location=0) out vec4 fragColor;
+
+ void main()
+ {
+ fragColor = myColor;
+ }
+ \endcode
+
+ There is no change involved when it comes to feeding values to uniforms.
+
+ For the above example, setting myColor could be done with:
+
+ \badcode
+ QParameter *parameter = new QParameter();
+ parameter->setName("myColor");
+ parameter->setValue(QVariant::fromValue(QColor(Qt::blue)));
+ \code
+
+ Textures still have to be defined as standalone uniforms.
+
+ \badcode
+ #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));
+ }
+ \code
*/
/*!
@@ -307,6 +402,99 @@
\li {3, 1} const int maxJoints = 100; \br uniform mat4 skinningPalette[maxJoints];
\endtable
+
+ \section1 RHI Support
+
+ When writing GLSL 450 shader code to use with Qt 3D's RHI backend,
+ the default uniforms will be provided as 2 uniform buffer objects.
+
+ The binding locations for these is set to bindings 0 for RenderView
+ uniforms and 1 for Command uniforms.
+
+ \badcode
+ #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);
+ }
+ \endcode
+
+ For user defined uniform buffer object, use binding starting at 2 or auto
+ to let Qt 3D work out the binding automatically. Make sure to remain
+ consistent between the different shader stages.
+
+
+ \badcode
+ #version 450 core
+
+ layout(std140, binding = auto) uniform my_uniforms {
+ vec4 myColor;
+ };
+
+ layout(location=0) out vec4 fragColor;
+
+ void main()
+ {
+ fragColor = myColor;
+ }
+ \endcode
+
+ There is no change involved when it comes to feeding values to uniforms.
+
+ For the above example, setting myColor could be done with:
+
+ \badcode
+ Parameter { name: "myColor"; value: "blue" }
+ \code
+
+ Textures still have to be defined as standalone uniforms.
+
+ \badcode
+ #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));
+ }
+ \code
*/
/*!