summaryrefslogtreecommitdiffstats
path: root/examples/qt3d
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2020-11-26 08:14:37 +0100
committerPaul Lemire <paul.lemire@kdab.com>2020-11-26 14:31:45 +0100
commit4ad2efac3e734f72c0c8d0ff9739106728fe6c98 (patch)
treeb076c1a96da7d4b6673f1db2669f7c8ffc7da230 /examples/qt3d
parent44cae613ffa934cc358b97994a65c54a9bc2d8a6 (diff)
simplecustommaterial example: add RHI support
Pick-to: 6.0 6.0.0 Change-Id: Id1dfc3c6a6f0c8090b5c5facc1a0dd9bb5a02bd6 Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'examples/qt3d')
-rw-r--r--examples/qt3d/simplecustommaterial/CMakeLists.txt2
-rw-r--r--examples/qt3d/simplecustommaterial/SimpleMaterial.qml20
-rw-r--r--examples/qt3d/simplecustommaterial/shaders.qrc2
-rw-r--r--examples/qt3d/simplecustommaterial/shaders/gl45/simpleColor.frag14
-rw-r--r--examples/qt3d/simplecustommaterial/shaders/gl45/simpleColor.vert23
5 files changed, 61 insertions, 0 deletions
diff --git a/examples/qt3d/simplecustommaterial/CMakeLists.txt b/examples/qt3d/simplecustommaterial/CMakeLists.txt
index 933c5ee12..ef54f734f 100644
--- a/examples/qt3d/simplecustommaterial/CMakeLists.txt
+++ b/examples/qt3d/simplecustommaterial/CMakeLists.txt
@@ -50,6 +50,8 @@ set(shaders_resource_files
"shaders/es2/simpleColor.vert"
"shaders/gl3/simpleColor.frag"
"shaders/gl3/simpleColor.vert"
+ "shaders/gl45/simpleColor.frag"
+ "shaders/gl45/simpleColor.vert"
)
qt6_add_resources(simplecustommaterial "shaders"
diff --git a/examples/qt3d/simplecustommaterial/SimpleMaterial.qml b/examples/qt3d/simplecustommaterial/SimpleMaterial.qml
index 2419362b6..e3f964e1e 100644
--- a/examples/qt3d/simplecustommaterial/SimpleMaterial.qml
+++ b/examples/qt3d/simplecustommaterial/SimpleMaterial.qml
@@ -71,6 +71,8 @@ Material {
//! [1]
property string vertex: "qrc:/shaders/gl3/simpleColor.vert"
property string fragment: "qrc:/shaders/gl3/simpleColor.frag"
+ property string vertexRHI: "qrc:/shaders/gl45/simpleColor.vert"
+ property string fragmentRHI: "qrc:/shaders/gl45/simpleColor.frag"
property string vertexES: "qrc:/shaders/es2/simpleColor.vert"
property string fragmentES: "qrc:/shaders/es2/simpleColor.frag"
//! [1]
@@ -92,6 +94,11 @@ Material {
vertexShaderCode: loadSource(parent.vertexES)
fragmentShaderCode: loadSource(parent.fragmentES)
}
+ ShaderProgram {
+ id: rhiShader
+ vertexShaderCode: loadSource(parent.vertexRHI)
+ fragmentShaderCode: loadSource(parent.fragmentRHI)
+ }
//! [2]
techniques: [
@@ -135,6 +142,19 @@ Material {
renderPasses: RenderPass {
shaderProgram: es2Shader
}
+ },
+ // RHI 1.0
+ Technique {
+ filterKeys: [forward]
+ graphicsApiFilter {
+ api: GraphicsApiFilter.RHI
+ profile: GraphicsApiFilter.NoProfile
+ majorVersion: 1
+ minorVersion: 0
+ }
+ renderPasses: RenderPass {
+ shaderProgram: rhiShader
+ }
}
]
}
diff --git a/examples/qt3d/simplecustommaterial/shaders.qrc b/examples/qt3d/simplecustommaterial/shaders.qrc
index 9881e224a..d46ea0a37 100644
--- a/examples/qt3d/simplecustommaterial/shaders.qrc
+++ b/examples/qt3d/simplecustommaterial/shaders.qrc
@@ -4,5 +4,7 @@
<file>shaders/gl3/simpleColor.vert</file>
<file>shaders/es2/simpleColor.frag</file>
<file>shaders/es2/simpleColor.vert</file>
+ <file>shaders/gl45/simpleColor.frag</file>
+ <file>shaders/gl45/simpleColor.vert</file>
</qresource>
</RCC>
diff --git a/examples/qt3d/simplecustommaterial/shaders/gl45/simpleColor.frag b/examples/qt3d/simplecustommaterial/shaders/gl45/simpleColor.frag
new file mode 100644
index 000000000..f2658621d
--- /dev/null
+++ b/examples/qt3d/simplecustommaterial/shaders/gl45/simpleColor.frag
@@ -0,0 +1,14 @@
+#version 450 core
+
+layout(std140, binding = 2) uniform custom_uniforms {
+ vec3 maincolor;
+};
+
+layout(location = 0) out vec4 fragColor;
+
+void main()
+{
+ //output color from material
+ fragColor = vec4(maincolor,1.0);
+}
+
diff --git a/examples/qt3d/simplecustommaterial/shaders/gl45/simpleColor.vert b/examples/qt3d/simplecustommaterial/shaders/gl45/simpleColor.vert
new file mode 100644
index 000000000..46948167a
--- /dev/null
+++ b/examples/qt3d/simplecustommaterial/shaders/gl45/simpleColor.vert
@@ -0,0 +1,23 @@
+#version 450 core
+
+layout(location = 0) in vec3 vertexPosition;
+layout(location = 0) out vec3 worldPosition;
+
+layout(std140, binding = 1) uniform qt3d_command_uniforms {
+ mat4 modelMatrix;
+ mat4 inverseModelMatrix;
+ mat4 modelViewMatrix;
+ mat3 modelNormalMatrix;
+ mat4 inverseModelViewMatrix;
+ mat4 modelViewProjection;
+ mat4 inverseModelViewProjectionMatrix;
+};
+
+void main()
+{
+ // Transform position, normal, and tangent to world coords
+ worldPosition = vec3(modelMatrix * vec4(vertexPosition, 1.0));
+
+ // Calculate vertex position in clip coordinates
+ gl_Position = modelViewProjection * vec4(worldPosition, 1.0);
+}