Discover Metal for immersive apps - Example Code

Is there an example app?

Am writing a visual music app. It uses a custom SwiftUI menus over a UIKit (UIHostingController) canvas. The metal pipeline is custom.

A fully functional example app would be super helpful. Nothing fancy; an immersive hello triangle would be a great start.

Later, will need to port UITouches to draw and CMMotionManager to track pov within a Cubemap. Meanwhile, baby steps.

Thanks!

Replies

There is example code from Warren Moore found here using Apple's low level C API found here

Thanks warrenm!

However, I find the C++/ObjC++ APIs with super_long_snake_case_names to be obscure and non-idiomatic. So, am attempting to port to Swift. Already filed a Feedback requesting Swift APIs (FB12879060). And will post a separate question on some blockers in my attempt to refactor into idiomatic Swift.

  • I've closed FB12879060, as there is a new template in Beta 6 -- see answer from Apple Engineer, below.

Add a Comment

Full port of C++ to Swift is working. Code is here

  • I discovered this thread after porting WarrenM's C++ sample myself. In your code you have declared your uniforms both in ShaderTypes.h and Swift. I believe the correct method is to have a single declaration in ShaderTypes.h and import it into Swift using the bridging header. Apparently the Swift compiler uses different padding and alignment rules for structs. C/C++ have compiler options for altering struct padding and alignment so it's a common issue. Nevertheless, thanks for your sample.

Add a Comment

Xcode 15 (beta 6) has a template app for creating an Immersive app using Metal. You can find it if you create a new App for visionOS and set "Immersive Space Renderer" to Metal.

  • This is awesome -- thanks!

  • @Graphics and Games Engineer Thanks for that. The template, however, uses exclusively Swift code, not the C api shown in the talk. Could we also have a C/Objective-C template that only uses the minimal amount of Swift UI? The function names in the Swift API example seem very different too, so the correspondence to the C api isn’t obvious.

  • Hi. Please submit a report requesting a sample using C/Obj-C using Feedback Assistant app and post the Feedback ID here. Thanks.

Add a Comment