SpriteKit, SceneKit or UnityBefore you get started, it’ll be helpful to understand how Metal compares to higher-level frameworks like SpriteKit, SceneKit or Unity.Metal is a low-level 3D graphics API, similar to OpenGL ES, but with lower overhead meaning better performance. To complete this tutorial, you’ll need an A7 device or newer. If you do have some prior 3D-programming or OpenGL experience, you’ll find things much easier, as many of the same concepts apply to Metal.Note: Metal apps do not run on the iOS simulator they require a device with an Apple A7 chip or later. In doing so, you’ll learn some of the most important classes in Metal, such as devices, command queues and more.This tutorial is designed so that anyone can go through it, regardless of your 3D graphics background — however, things will move along fairly quickly. Instead, it’s designed to be extremely efficient with Apple hardware, offering improved speed and low overhead compared to using OpenGL ES.In this tutorial, you’ll get hands-on experience using the Metal API to create a bare-bones app: drawing a simple triangle. The solution was to start the boot camp install in OS X, when it restarts.Metal is similar to OpenGL ES in that it’s a low-level API for interacting with 3D graphics hardware.The difference is that Metal is not cross-platform.It’s a great learning experience: Learning Metal teaches you a lot about 3D graphics, writing your own game engine, and how higher-level game frameworks work.If either of these sound like good reasons to you, keep reading! Metal vs. Push the hardware to its limits: Since Metal is at such a low level, it allows you to really push the hardware to its limits and have full control over how your game works. If this sounds like you, we have tons of tutorials to help you get started with Apple Game Frameworks or Unity.However, there are still two really good reasons to learn Metal: They provide much of the boilerplate code you normally need to write in a game, such as rendering a sprite or 3D model to the screen.If all you’re trying to do is make a game, you’ll probably use a higher-level game framework like SpriteKit, SceneKit or Unity most of the time because doing so will make your life much easier. The trade-off is that you have full power and control.Conversely, higher-level game frameworks like SpriteKit, SceneKit and Unity are built on top of a lower-level 3D graphics APIs like Metal or OpenGL ES.
![]() How Do You Use Metal For Osx Install In OSYou need to create a:Going through them one at a time. You’ll see an empty project with a single ViewController.There are seven steps required to set up Metal so that you can begin rendering. Once you have the files, open HelloMetal.xcodeproj in the HelloMetal_starter folder. This is because you’re going to put together a Metal app almost from scratch, so you can understand every step of the process.Download the files that you need for this tutorial using the Download Materials button at the top or bottom of this tutorial. This can result in some amazing effects — you may remember from the Zen Garden example in the WWDC 2014 keynote, as an example.Time to dig right in and see some Metal code! Getting StartedXcode’s iOS game template comes with a Metal option, but you won’t choose that here. That means you can write C++ OpenGL ES code, and, most of the time, with some small modifications, you can run it on other platforms, such as Android.Apple realized that, although the cross-platform support of OpenGL ES was nice, it was missing something fundamental to how Apple designs its products: the famous Apple integration of the operating system, hardware and software as a complete package.So Apple took a clean-room approach to see what it would look like if it were to design a graphics API specifically for Apple hardware with the goal of being extremely low overhead and performant, while supporting the latest and greatest features.The result is Metal, which can provide up to 10✕ the number of draw calls for your app compared to OpenGL ES. Remote desktop for mac os sierra2) Creating a CAMetalLayerIn iOS, everything you see on screen is backed by a CALayer. Since you know you’re definitely going to initialize it before you use it, you mark it as an implicitly unwrapped optional, for convenience purposes.Finally, add viewDidLoad() and initialize the device property, like this:MTLCreateSystemDefaultDevice returns a references to the default MTLDevice your code should use. You’ll create all the other Metal objects you need (like command queues, buffers and textures) using this MTLDevice.To do this, open ViewController.swift and add this import to the top of the file:This imports the Metal framework so that you can use Metal classes such as MTLDevice inside this file.Next, add this property to the ViewController:You’re going to initialize this property in viewDidLoad() rather than in an initializer, so it has to be an optional. ![]() In this app, you’re just going to draw one triangle, but even complex 3D shapes can be decomposed into a series of triangles.In Metal, the default coordinate system is the normalized coordinate system, which means that by default you’re looking at a 2x2x1 cube centered at (0, 0, 0.5).If you consider the Z=0 plane, then (-1, -1, 0) is the lower left, (0, 0, 0) is the center, and (1, 1, 0) is the upper right. Finally, you add the layer as a sublayer of the view’s main layer.Everything in Metal is a triangle. You set the frame of the layer to match the frame of the view. Most of the time, you don’t need to do this. Apple encourages you to set framebufferOnly to true for performance reasons unless you need to sample from the textures generated for this layer, or if you need to enable compute kernels on the layer drawable texture. Set the pixel format to bgra8Unorm, which is a fancy way of saying “8 bytes for Blue, Green, Red and Alpha, in that order — with normalized values between 0 and 1.” This is one of only two possible formats to use for a CAMetalLayer, so normally you’d just leave this as-is. ![]() You can also split your shaders across multiple Metal files if you would like, as Metal will load shaders from any Metal file included in your project. Enter Shaders.metal for the filename and click Create.Note: In Metal, you can include multiple shaders in a single Metal file. Go to File ▸ New ▸ File, choose iOS ▸ Source ▸ Metal File, and click Next. You pass an empty array for default configuration.The vertices that you created in the previous section will become the input to a little program that you’ll write called a vertex shader.A vertex shader is simply a tiny program that runs on the GPU, written in a C++-like language called the Metal Shading Language.A vertex shader is called once per vertex, and its job is to take that vertex’s information, such as position — and possibly other information such as color or texture coordinate — and return a potentially modified position and possibly other data.To keep things simple, your simple vertex shader will return the same position as the position passed in.The easiest way to understand vertex shaders is to see it yourself. You call makeBuffer(bytes:length:options:) on the MTLDevice to create a new buffer on the GPU, passing in the data from the CPU.
0 Comments
Leave a Reply. |
Details
AuthorAnnie ArchivesCategories |