|
5 | 5 | * http://stregasgate.com |
6 | 6 | */ |
7 | 7 |
|
| 8 | +import Shaders |
| 9 | + |
8 | 10 | /// A Scene is a drawing space with 3 dimensions and a perspective camera. |
9 | 11 | @MainActor public struct Scene: Drawable { |
10 | 12 | @usableFromInline internal var camera: Camera |
|
65 | 67 | _ geometry: Geometry, |
66 | 68 | withMaterial material: Material, |
67 | 69 | at transform: Transform3, |
| 70 | + blendMode: DrawCommand.Flags.BlendMode = .normal, |
68 | 71 | flags: SceneElementFlags = .default |
69 | 72 | ) { |
70 | | - self.insert(geometry, withMaterial: material, at: [transform], flags: flags) |
| 73 | + self.insert(geometry, withMaterial: material, at: [transform], blendMode: blendMode, flags: flags) |
71 | 74 | } |
72 | 75 |
|
73 | 76 | /** Adds geometry to the scene for rendering. |
|
89 | 92 | resource: .geometry(geometry), |
90 | 93 | transforms: transforms, |
91 | 94 | material: material, |
92 | | - vsh: .standard, |
93 | | - fsh: (material.channels.first?.texture != nil) ? .textureSample : .materialColor, |
| 95 | + vsh: (material.channels.first?.texture != nil) ? .standard : material.channels.first?.color == .vertexColors ? .vertexColors : .standard, |
| 96 | + fsh: (material.channels.first?.texture != nil) ? .textureSample : material.channels.first?.color == .vertexColors ? .vertexColor : .materialColor, |
94 | 97 | flags: flags.drawCommandFlags(withPrimitive: .triangle, blendMode: blendMode) |
95 | 98 | ) |
96 | 99 | self.insert(command) |
|
203 | 206 |
|
204 | 207 | /** Adds lines to the scene for rendering. |
205 | 208 | - parameter lines: The lines to draw. |
| 209 | + - parameter color: The color information used to draw the geometry. nil will use vertex color data. |
206 | 210 | - parameter transform: Describes how the lines instance should be positioned and scaled relative to the scene. |
207 | 211 | - parameter flags: Options to customize how drawing is handled. |
208 | 212 | - Explicitly instances the geometry as it's own batch. Use this for known instancing like particles. |
209 | 213 | */ |
210 | 214 | @_transparent |
211 | 215 | public mutating func insert( |
212 | 216 | _ lines: Lines, |
213 | | - at transform: Transform3, |
214 | | - flags: SceneElementFlags = .default |
215 | | - ) { |
216 | | - self.insert(lines, at: [transform], flags: flags) |
217 | | - } |
218 | | - |
219 | | - /** Adds lines to the scene for rendering. |
220 | | - - parameter lines: The lines to draw. |
221 | | - - parameter transforms: Describes how each lines instance should be positioned and scaled relative to the scene. |
222 | | - - parameter flags: Options to customize how drawing is handled. |
223 | | - - Explicitly instances the geometry as it's own batch. Use this for known instancing like particles. |
224 | | - */ |
225 | | - @inlinable @inline(__always) |
226 | | - public mutating func insert( |
227 | | - _ lines: Lines, |
228 | | - at transforms: [Transform3], |
229 | | - flags: SceneElementFlags = .default |
230 | | - ) { |
231 | | - let command = DrawCommand( |
232 | | - resource: .lines(lines), |
233 | | - transforms: transforms, |
234 | | - material: Material(color: .vertexColors), |
235 | | - vsh: .vertexColors, |
236 | | - fsh: .vertexColor, |
237 | | - flags: flags.drawCommandFlags(withPrimitive: .line) |
238 | | - ) |
239 | | - self.insert(command) |
240 | | - } |
241 | | - |
242 | | - /** Adds lines to the scene for rendering. |
243 | | - - parameter lines: The lines to draw. |
244 | | - - parameter color: The color information used to draw the geometry. |
245 | | - - parameter transform: Describes how the lines instance should be positioned and scaled relative to the scene. |
246 | | - - parameter flags: Options to customize how drawing is handled. |
247 | | - - Explicitly instances the geometry as it's own batch. Use this for known instancing like particles. |
248 | | - */ |
249 | | - @_transparent |
250 | | - public mutating func insert( |
251 | | - _ lines: Lines, |
252 | | - withColor color: Color, |
| 217 | + withColor color: Color? = nil, |
253 | 218 | at transform: Transform3, |
254 | 219 | flags: SceneElementFlags = .default |
255 | 220 | ) { |
|
258 | 223 |
|
259 | 224 | /** Adds lines to the scene for rendering. |
260 | 225 | - parameter lines: The lines to draw. |
261 | | - - parameter color: The color information used to draw the geometry. |
| 226 | + - parameter color: The color information used to draw the geometry. nil will use vertex color data. |
262 | 227 | - parameter transforms: Describes how each lines instance should be positioned and scaled relative to the scene. |
263 | 228 | - parameter flags: Options to customize how drawing is handled. |
264 | 229 | - Explicitly instances the geometry as it's own batch. Use this for known instancing like particles. |
265 | 230 | */ |
266 | 231 | @inlinable @inline(__always) |
267 | 232 | public mutating func insert( |
268 | 233 | _ lines: Lines, |
269 | | - withColor color: Color, |
| 234 | + withColor color: Color? = nil, |
270 | 235 | at transforms: [Transform3], |
271 | 236 | flags: SceneElementFlags = .default |
272 | 237 | ) { |
| 238 | + let useVertexColors: Bool = (color == nil) |
273 | 239 | let command = DrawCommand( |
274 | 240 | resource: .lines(lines), |
275 | 241 | transforms: transforms, |
276 | | - material: Material(color: color), |
277 | | - vsh: .standard, |
| 242 | + material: Material(color: useVertexColors ? .black : color!), |
| 243 | + vsh: useVertexColors ? .vertexColors : .materialColor, |
278 | 244 | fsh: .materialColor, |
279 | 245 | flags: flags.drawCommandFlags(withPrimitive: .line) |
280 | 246 | ) |
|
399 | 365 |
|
400 | 366 | @_transparent |
401 | 367 | public func matrices(withSize size: GameMath.Size2) -> Matrices { |
402 | | - self.camera.matricies(withAspectRatio: size.aspectRatio) |
| 368 | + self.camera.matricies(withViewportSize: size) |
403 | 369 | } |
404 | 370 | } |
405 | 371 |
|
|
0 commit comments