-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scenes.swift
186 lines (182 loc) · 5.24 KB
/
Scenes.swift
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
//
// Scenes.swift
// MetalRayTracing
//
// Created by simon pellerin on 2023-04-04.
//
// an infinite glowing plane with a circle of blue cubes on top
@SceneBuilder func scene1() -> Renderable {
for i in -10..<10 {
Cube()
.scale(by: 0.25)
.translate(by: 1, onThe: .zAxis)
.rotate(by: (18 * i)°, aroundThe: .yAxis)
.color(.blue)
}
Cube() // light
.scale(by: 50, onThe: .xAxis)
.scale(by: 0.1, onThe: .yAxis)
.scale(by: 50, onThe: .zAxis)
.translate(by: -0.25, onThe: .yAxis)
.emit()
}
// a red cube in a white room with a rotated white glowing cube above
@SceneBuilder func scene2() -> Renderable {
Group {
Cube() // main boi
.scale(by: 0.5)
.rotate(by: 45°, aroundThe: .yAxis)
.translate(by: -0.4, onThe: .yAxis)
.color(.red)
Cube() // room
.reverseNormals()
.scale(by: 1.25)
Cube() // light
.scale(by: 0.25)
.rotate(by: 45°, aroundThe: .xAxis)
.rotate(by: 45°, aroundThe: .yAxis)
.rotate(by: 45°, aroundThe: .zAxis)
.translate(by: 0.4, onThe: .yAxis)
.emit()
}
.translate(by: 2, onThe: .zAxis)
}
// a white cube in a room with a red left wall, blue right wall,
// green floor, grey back, and white top
// with a light behind you
@SceneBuilder func scene3() -> Renderable {
Group {
Cube() // light
.scale(by: 50, onThe: .xAxis)
.scale(by: 50, onThe: .yAxis)
.scale(by: 0.1, onThe: .zAxis)
.translate(by: -2.1, onThe: .zAxis)
.emit()
// Cube() // main boi
// .scale(by: 0.5)
// .rotate(by: 45°, aroundThe: .yAxis)
// .translate(by: -0.4, onThe: .yAxis)
// Cube() // blue transparent
// .scale(by: 0.35)
// .rotate(by: 45°, aroundThe: .yAxis)
// .rotate(by: 45°, aroundThe: .xAxis)
// .translate(by: -0.1, onThe: .yAxis)
// .translate(by: -0.3, onThe: .zAxis)
// .color(.blue)
// .opacity(0.75)
// Mesh(.bigMonke)
// .scale(by: 0.25)
// .rotate(by: 90°, aroundThe: .xAxis)
// .rotate(by: 180°, aroundThe: .yAxis)
// .translate(by: -0.2, onThe: .yAxis)
// .translate(by: -0.15, onThe: .zAxis)
// .reflectiveness(1)
// Mesh(.imp)
// .scale(by: 0.3)
// .rotate(by: 90°, aroundThe: .xAxis)
// .rotate(by: -90°, aroundThe: .yAxis)
// .color(.red)
// .reflectiveness(0.9)
Mesh(.velociraptor)
.scale(by: 0.0007)
.translate(by: 0.1, onThe: .zAxis)
.rotate(by: 225°, aroundThe: .yAxis)
.translate(by: -0.3, onThe: .yAxis)
.translate(by: -0.55, onThe: .zAxis)
.translate(by: -0.05, onThe: .xAxis)
.reflectiveness(1)
Cube() // left wall
.scale(by: 0.01, onThe: .xAxis)
.scale(by: 1.25, onThe: .yAxis)
.scale(by: 1.25, onThe: .zAxis)
.translate(by: -0.625, onThe: .xAxis)
.color(.red)
Cube() // right wall
.scale(by: 0.01, onThe: .xAxis)
.scale(by: 1.25, onThe: .yAxis)
.scale(by: 1.25, onThe: .zAxis)
.translate(by: 0.625, onThe: .xAxis)
.color(.blue)
Cube() // floor
.scale(by: 1.25, onThe: .xAxis)
.scale(by: 0.01, onThe: .yAxis)
.scale(by: 1.25, onThe: .zAxis)
.translate(by: -0.625, onThe: .yAxis)
.color(.green)
Cube() // ceiling
.scale(by: 1.25, onThe: .xAxis)
.scale(by: 0.01, onThe: .yAxis)
.scale(by: 1.25, onThe: .zAxis)
.translate(by: 0.625, onThe: .yAxis)
Cube() // back
.scale(by: 1.25, onThe: .xAxis)
.scale(by: 1.25, onThe: .yAxis)
.scale(by: 0.01, onThe: .zAxis)
.translate(by: 0.625, onThe: .zAxis)
.color(.grey)
Cube() // front
.scale(by: 1.25, onThe: .xAxis)
.scale(by: 1.25, onThe: .yAxis)
.scale(by: 1.25, onThe: .zAxis)
.translate(by: 0.625, onThe: .zAxis)
.color(.grey)
}
.translate(by: 2, onThe: .zAxis)
}
// three spheres of varying reflectiveness
// in a room with a red left wall, blue right wall,
// green floor, white back, and white top
// with a white light in the ceiling
@SceneBuilder func scene4() -> Renderable {
Group {
Cube() // light
.scale(by: 0.5, onThe: .xAxis)
.scale(by: 0.02, onThe: .yAxis)
.scale(by: 0.5, onThe: .zAxis)
.translate(by: 0.625, onThe: .yAxis)
.emit(strength: 2)
Cube() // left wall
.scale(by: 0.01, onThe: .xAxis)
.scale(by: 1.25, onThe: .yAxis)
.scale(by: 1.25, onThe: .zAxis)
.translate(by: -1, onThe: .xAxis)
.color(.red)
Cube() // right wall
.scale(by: 0.01, onThe: .xAxis)
.scale(by: 1.25, onThe: .yAxis)
.scale(by: 1.25, onThe: .zAxis)
.translate(by: 1, onThe: .xAxis)
.color(.blue)
Cube() // floor
.scale(by: 2, onThe: .xAxis)
.scale(by: 0.01, onThe: .yAxis)
.scale(by: 1.25, onThe: .zAxis)
.translate(by: -0.625, onThe: .yAxis)
.color(.green)
Cube() // ceiling
.scale(by: 2, onThe: .xAxis)
.scale(by: 0.01, onThe: .yAxis)
.scale(by: 1.25, onThe: .zAxis)
.translate(by: 0.625, onThe: .yAxis)
Cube() // back wall
.scale(by: 2, onThe: .xAxis)
.scale(by: 1.25, onThe: .yAxis)
.scale(by: 0.01, onThe: .zAxis)
.translate(by: 0.625, onThe: .zAxis)
Cube() // front wall
.scale(by: 2.75)
.translate(by: -2, onThe: .zAxis)
Mesh(.bigSphere) // left sphere - 50% reflectiveness
.scale(by: 0.25)
.translate(by: -0.5, onThe: .xAxis)
.reflectiveness(0.5)
Mesh(.bigSphere) // middle sphere - 75% reflectiveness
.scale(by: 0.25)
.reflectiveness(0.75)
Mesh(.bigSphere) // right sphere - 100% reflectiveness
.scale(by: 0.25)
.translate(by: 0.5, onThe: .xAxis)
.reflectiveness(1)
}
.translate(by: 2, onThe: .zAxis)
}