Created
March 3, 2024 20:14
-
-
Save patskovn/5b8c50f26d4d104ee4dd24e6395bcd06 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Color is (r, g, b, a) components | |
static func complexPlane() -> [VertexIn] { | |
var result: [VertexIn] = [] | |
let size = SIMD2<Float>(10, 2) | |
for x in stride(from: 0, to: size.x, by: 1) { | |
for y in stride(from: 0, to: size.y, by: 1) { | |
let position = SIMD3(.init(x / size.x, y).metal, 0) | |
result.append( | |
.init(position: .init(position, 1), | |
color: .init(1, 1, 1, 1)) | |
) | |
} | |
} | |
return result | |
} | |
private extension SIMD2<Float> { | |
// Converts from origin at topLeft to origin at center of the screen | |
var toMetalGeometry: SIMD2<Float> { | |
.init(x * 2 - 1, (1 - y) * 2 - 1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment