3D Graphics with Metal · Textures | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1258241-3d-graphics-with-metal/lessons/29
1 Like

Hi there!

For the textureLoaderOptions:

[.origin : MTKTextureLoader.Origin.bottomLeft]

Could you please help me understand what it’s saying by flipping images (flipping how?) to put their origin (who’s origin?) in the bottom-left corner (of?)

So many new concepts! :confounded::exploding_head:

https://developer.apple.com/documentation/metalkit/mtktextureloader/origin

Sometimes it’s trial and error. I think a few versions ago, MTKTextureLoader flipped the image on loading, and then a version later it didn’t. Or the other way around, so you had to specify the origin or your texture would be upside down on the model.

An origin is [0, 0]. Bottom left means that the first pixel should load at the bottom left.

One origin to be wary of in your future, is iOS UIView vs macOS NSView. UIView’s origin is at the top left, while NSView’s origin is at the bottom left.

Right. So sounds like it’s best to trial and error when building an app to make sure textures are loaded property, and go from there. Thanks!!

When running on iOS device, have to remove treefir because it does not have textures, otherwise whole screen will be black for me.

@lydonchandra - which chapter are you referring to? The texture chapter fragment shader will only work for models with textures. When you get to the following chapter, it should work again with treefir.

Turned out, on iOS, that the sampler used was the problem, and it had to be like this for me.

if( hasColorTexture ) {
    constexpr sampler textureSampler (mag_filter::linear,
                                      min_filter::linear);

    // Sample the texture to obtain a color
    const half4 colorSample = baseColorTexture.sample(textureSampler, in.uv);

    // return the color of the texture
    baseColor = float3(float4(colorSample));
    
}
1 Like

@lydonchandra Thank you for sharing your solution - much appreciated!