Created
April 17, 2024 21:59
-
-
Save jamesporter/1b33558b3fc2771b45630ba7e0ba5122 to your computer and use it in GitHub Desktop.
Metal and Swift(UI) Raymarching App
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
import SwiftUI | |
struct ContentView: View { | |
let startDate = Date() | |
var body: some View { | |
GeometryReader { gp in | |
TimelineView(.animation) { ctx in | |
Rectangle() | |
.ignoresSafeArea() | |
.colorEffect(ShaderLibrary.raymarchB( | |
.float2(gp.size.width, gp.size.height), | |
.float(startDate.timeIntervalSinceNow) | |
)) | |
} | |
} | |
} | |
} | |
#Preview { | |
ContentView() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jamesporter Thanks for the example. I am curious what the simplest way would be to composite raymarched visuals with rasterized geometry, including lighting and correct depth occlusion. You'd probably need your own Metal pipeline beyond the SwiftUI. It'd also require writing to the depth buffer at minimum. Inigo has an article on this, but translating it to Metal is a little unclear: https://iquilezles.org/articles/raypolys/
It would be great to have a full working example of that out there if you felt like playing with it. Apple provides something for hybrid raytraced reflections, but it's not the same use case.