Debian Codegraph @

tests/manual/rhi/ubo/main.qml

raw
1 // Copyright (C) 2020 Klaralvdalens Datakonsult AB (KDAB).
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 import QtQuick 2.15 as QQ2
5 import Qt3D.Core 2.15
6 import Qt3D.Render 2.15
7 import Qt3D.Input 2.15
8 import Qt3D.Extras 2.15
9
10 Entity {
11 id: sceneRoot
12
13 Camera {
14 id: camera
15 projectionType: CameraLens.PerspectiveProjection
16 fieldOfView: 45
17 aspectRatio: 16/9
18 nearPlane : 0.1
19 farPlane : 1000.0
20 position: Qt.vector3d( 0.0, 0.0, -40.0 )
21 upVector: Qt.vector3d( 0.0, 1.0, 0.0 )
22 viewCenter: Qt.vector3d( 0.0, 0.0, 0.0 )
23 }
24
25 OrbitCameraController {
26 camera: camera
27 }
28
29 components: [
30 RenderSettings {
31 activeFrameGraph: ForwardRenderer {
32 clearColor: Qt.rgba(0, 0.5, 1, 1)
33 camera: camera
34 showDebugOverlay: true
35 }
36 },
37 // Event Source will be set by the Qt3DQuickWindow
38 InputSettings { }
39 ]
40
41 Material {
42 id: material
43 effect: Effect {
44 techniques: [
45 Technique {
46 filterKeys: FilterKey {
47 name: "renderingStyle"
48 value: "forward"
49 }
50 graphicsApiFilter {
51 api: GraphicsApiFilter.RHI
52 majorVersion: 1
53 minorVersion: 0
54 }
55 renderPasses: RenderPass {
56 shaderProgram: ShaderProgram {
57 vertexShaderCode: "
58 #version 450
59
60 layout(location = 0) in vec3 vertexPosition;
61
62 layout(std140, binding = 0) uniform qt3d_render_view_uniforms {
63 mat4 viewMatrix;
64 mat4 projectionMatrix;
65 mat4 uncorrectedProjectionMatrix;
66 mat4 clipCorrectionMatrix;
67 mat4 viewProjectionMatrix;
68 mat4 inverseViewMatrix;
69 mat4 inverseProjectionMatrix;
70 mat4 inverseViewProjectionMatrix;
71 mat4 viewportMatrix;
72 mat4 inverseViewportMatrix;
73 vec4 textureTransformMatrix;
74 vec3 eyePosition;
75 float aspectRatio;
76 float gamma;
77 float exposure;
78 float time;
79 };
80
81 layout(std140, binding = 1) uniform qt3d_command_uniforms {
82 mat4 modelMatrix;
83 mat4 inverseModelMatrix;
84 mat4 modelViewMatrix;
85 mat3 modelNormalMatrix;
86 mat4 inverseModelViewMatrix;
87 mat4 modelViewProjection;
88 mat4 inverseModelViewProjectionMatrix;
89 };
90
91 void main()
92 {
93 gl_Position = modelViewProjection * vec4(vertexPosition, 1.0);
94 }
95 "
96
97 fragmentShaderCode: "
98 #version 450
99
100 layout(location = 0) out vec4 fragColor;
101
102 layout(std140, binding = 0) uniform qt3d_render_view_uniforms {
103 mat4 viewMatrix;
104 mat4 projectionMatrix;
105 mat4 uncorrectedProjectionMatrix;
106 mat4 clipCorrectionMatrix;
107 mat4 viewProjectionMatrix;
108 mat4 inverseViewMatrix;
109 mat4 inverseProjectionMatrix;
110 mat4 inverseViewProjectionMatrix;
111 mat4 viewportMatrix;
112 mat4 inverseViewportMatrix;
113 vec4 textureTransformMatrix;
114 vec3 eyePosition;
115 float aspectRatio;
116 float gamma;
117 float exposure;
118 float time;
119 };
120
121 struct MyStruct {
122 vec4 factor;
123 };
124
125 layout(std140, binding = 2) uniform CustomUBO1 {
126 vec4 baseColor;
127 };
128
129 layout(std140, binding = 3) uniform CustomUBO2 {
130 MyStruct innerStruct;
131 vec4 accentColor;
132 };
133
134 void main()
135 {
136 fragColor = baseColor * abs(sin(time)) + accentColor * innerStruct.factor;
137 }
138 "
139 }
140 }
141 }
142 ]
143 }
144
145 parameters: [
146 // User provided UBO
147 Parameter {
148 name: "CustomUBO1"
149 value: Buffer {
150 data: {
151 var bufferData = new Float32Array(4);
152 bufferData[0] = 0.5;
153 bufferData[1] = 0.5;
154 bufferData[2] = 0.5;
155 bufferData[3] = 1.0;
156 return bufferData
157 }
158 }
159 },
160 // Regular parameter that maps to UBO member
161 Parameter {
162 name: "accentColor"
163 value: "yellow"
164 },
165 Parameter {
166 name: "innerStruct"
167 value: ShaderData {
168 property vector4d factor: Qt.vector4d(0.5, 0.5, 0.5, 0.0)
169 }
170 }
171 ]
172 }
173
174 TorusMesh {
175 id: torusMesh
176 radius: 5
177 minorRadius: 1
178 rings: 100
179 slices: 20
180 }
181
182 Transform {
183 id: torusTransform
184 scale3D: Qt.vector3d(1.5, 1, 0.5)
185 rotation: fromAxisAndAngle(Qt.vector3d(1, 0, 0), 45)
186 }
187
188 Entity {
189 id: torusEntity
190 components: [ torusMesh, material, torusTransform ]
191 }
192
193 // QQ2.NumberAnimation {
194 // target: torusTransform
195 // property: "userAngle"
196 // duration: 10000
197 // from: 0
198 // to: 360
199
200 // loops: QQ2.Animation.Infinite
201 // running: true
202 // }
203 }