-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathlight_casters_spotlight_soft.qml
189 lines (167 loc) · 4.24 KB
/
light_casters_spotlight_soft.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import QtQuick 2.9
import Qt3D.Core 2.0
import Qt3D.Render 2.0
import Qt3D.Input 2.0
import Qt3D.Extras 2.0
import VirtualKey 1.0
import "Components"
Scene2 {
id: scene
children: VirtualKeys {
target: scene
gameButtonsEnabled: false
color: "transparent"
centerItem: RowKeys {
keys: [
{text:"Space", key:Qt.Key_Space},
]
}
}
Entity {
id: root
RenderInputSettings0 {
id: renderInputSettings
mouseSensitivity: .5 / Units.dp
}
KeyboardDevice {
id: keyboardDevice
}
KeyboardHandler {
id: keyboardHandler
sourceDevice: keyboardDevice
focus: true
onSpacePressed: {
root.useSoftSpot = !root.useSoftSpot;
}
}
property bool useSoftSpot: true
property var cubePositions: [
Qt.vector3d( 0.0, 0.0, 0.0),
Qt.vector3d( 2.0, 5.0, -15.0),
Qt.vector3d(-1.5, -2.2, -2.5),
Qt.vector3d(-3.8, -2.0, -12.3),
Qt.vector3d( 2.4, -0.4, -3.5),
Qt.vector3d(-1.7, 3.0, -7.5),
Qt.vector3d( 1.3, -2.0, -2.5),
Qt.vector3d( 1.5, 2.0, -2.5),
Qt.vector3d( 1.5, 0.2, -1.5),
Qt.vector3d(-1.3, 1.0, -1.5),
]
property vector3d viewPos: renderInputSettings.camera.position
property color lightColor: "white"
property Entity material: Entity {
property Texture2D diffuseMap: Texture2D {
TextureImage {
source: Resources.texture("container2.png")
}
}
property Texture2D specularMap: Texture2D {
TextureImage {
source: Resources.texture("container2_specular.png")
}
}
property real shininess: 32.
}
QtObject {
id: light
property vector3d position: renderInputSettings.camera.position
property vector3d direction: renderInputSettings.camera.frontVector
property real cutOff: Math.cos(Geo.deg2rad(12.5))
property real outerCutOff: Math.cos(Geo.deg2rad(17.5))
// We set the diffuse intensity a bit higher; note that the right lighting conditions differ with each lighting method and environment.
// Each environment and lighting type requires some tweaking of these variables to get the best out of your environment.
property vector3d ambient: "0.1, 0.1, 0.1"
property vector3d diffuse: "0.8, 0.8, 0.8"
property vector3d specular: "1.0, 1.0, 1.0"
property real constantAttenuation: 1.
property real linearAttenuation: .09
property real quadraticAttenuation: .032
}
CuboidMesh {
id: mesh
}
Material {
id: ourMaterial
effect: Effect {
techniques: AutoTechnique {
renderPasses: RenderPass {
shaderProgram: AutoShaderProgram {
vertName: "lighting_maps"
fragName: root.useSoftSpot ?
"light_casters_spotlight_soft" :
"light_casters_spotlight_hard"
}
parameters: [
Parameter {
name: "viewPos"
value: root.viewPos
},
Parameter {
name: "material.diffuse"
value: root.material.diffuseMap
},
Parameter {
name: "material.specular"
value: root.material.specularMap
},
Parameter {
name: "material.shininess"
value: root.material.shininess
},
Parameter {
name: "light.position"
value: light.position
},
Parameter {
name: "light.direction"
value: light.direction
},
Parameter {
name: "light.cutOff"
value: light.cutOff
},
Parameter {
name: "light.outerCutOff"
value: light.outerCutOff
},
Parameter {
name: "light.ambient"
value: light.ambient
},
Parameter {
name: "light.diffuse"
value: light.diffuse
},
Parameter {
name: "light.specular"
value: light.specular
},
Parameter {
name: "light.constant"
value: light.constantAttenuation
},
Parameter {
name: "light.linear"
value: light.linearAttenuation
},
Parameter {
name: "light.quadratic"
value: light.quadraticAttenuation
}
]
}
}
}
}
NodeInstantiator {
model: root.cubePositions
delegate: Entity {
property Transform transform: Transform {
translation: modelData
rotation: fromAxisAndAngle(Qt.vector3d(0.5, 1.0, 0.0), 20 * index)
}
components: [mesh, ourMaterial, transform]
}
}
}
}