Group Group Group Group Group Group Group Group Group

raywenderlich.com Forums

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.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/719-metal-tutorial-with-swift-3-part-3-adding-texture

There seems to be a missing <float>. In the code box after:
“Open Shaders.metal and replace the entire file with the following:”
is the code:
#####################
// 3
fragment float4 basic_fragment(VertexOut interpolated [[stage_in]],
texture2d tex2D [[ texture(0) ]],
// 4
######################
This does not compile in my current Xcode/Swift. If I download your completed file, it appears to have replaced “texture2d” with "texture2d<float> ".

With this change, it appears to work.

In the section update upon device rotate, the code uses nativeScale instead of scale, and I know that for iPhone 6 the bounds is 320x568 and resolution is 640x1136 in zoomed display mode, which is automatically resampled from bound 375x667 and resolution 750x1334. Besides, the scale and nativeScale will be identical in standard mode. So the system will do the resample things for us, why you use nativeScale instead of scale?

In the section about optimizing by using semaphores and buffer re-use, my FPS numbers are actually larger after I make the change, not smaller. Why would that be?

also not really important but the word “Available” is misspelled throughout this code

I just want to know how to use more than one texture on a one verticesArray. Let’s say we have a verticesArray is having two cubes vertex data and we would like to apply first texture to first cube in array and second texture to the rest of the vertex data which draws second cube.

This tutorial is more than six months old so questions are no longer supported at the moment for it. We will update it as soon as possible. Thank you! :]