Metal Tutorial with Swift 3 Part 3: Adding Texture

In part 3 of our Metal tutorial series, you will learn how to add textures to 3D objects using Apple’s built-in 3D graphics framework. By Andrew Kharchyshyn.

Leave a rating/review
Save for later
Share
You are currently viewing page 5 of 5 of this article. Click here to view the first page.

Where To Go From Here?

Here is the final example project from this Swift 3 Metal Tutorial.

Nicely done! Take a moment to review what you’ve done in this tutorial.

  1. You created BufferProvider to cleverly reuse uniform buffers instead of creating new buffers every time.
  2. You added MetalTexture and loaded a MTLTexture with it.
  3. You modified the structure of Vertex so it stores corresponding texture coordinates from MTLTexture.
  4. You modified Cube so it contains 24 vertices, each with its own texture coordinates.
  5. You modified the shaders to receive texture coordinates of the fragments, and then you read the corresponding texel using sample().
  6. You added a cool rotation UI effect with UIPanGestureRecognizer.
  7. You debugged the Metal frame and identified why it rendered a subpar image.
  8. You resized a drawable texture in viewDidLayoutSubviews to fix the rotation issue and improve the image’s quality.

Here are some great resources to deepen your understanding of Metal:

You also might enjoy the Beginning Metal course on our site, where we explain these same concepts in video form, but with even more detail.

Thank you for joining me for this tour through Metal. As you can see, it’s a powerful technology that’s relatively easy to implement once you understand how it works.

If you have questions, comments or Metal discoveries to share, please leave them in the comments below!

Andrew Kharchyshyn

Contributors

Andrew Kharchyshyn

Author

Over 300 content creators. Join our team.