Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use Metal shader code in an iPad Swift Playground?

Is it possible to use custom Metal shader code in an iPad Swift Playground?

If so, how does one get the *.metal file or code (or its pre-compiled object) onto an iPad to use with a Playground and Swift code? Is the use of Xcode on a Mac required to help?

(this question is not about using the built-in performance shaders, or about running stuff in a Playground on a Mac)

like image 522
hotpaw2 Avatar asked Jun 21 '17 17:06

hotpaw2


1 Answers

You have two options: either create an iOS playground in Xcode and send it to your iPad but then you are not allowed to edit the .metal file, just read it, like in this example; or you can create your shaders file as a multiline string (now possible in Swift 4 and Xcode 9 beta) and create your library from that string. A more cumbersome way is to concatenate string lines in Xcode 8/Swift 3 like in this example.

like image 80
gpu3d Avatar answered Oct 03 '22 08:10

gpu3d