<p>I have the following code below, and it generates the following render. I am using a texture test image, and it looks like its just taking the bottom row of pixels of that image and repeating then. It looks like its correctly applied to the edge it starts on, at least. Any ideas?</p>
<pre><code>        // Create a sampler object
    let samplerDescriptor = MTLSamplerDescriptor()
    samplerDescriptor.minFilter = .linear
    samplerDescriptor.magFilter = .linear
    samplerDescriptor.mipFilter = .linear
    samplerDescriptor.sAddressMode = .clampToEdge
    samplerDescriptor.tAddressMode = .clampToEdge
    textureSamplerState = device.makeSamplerState(descriptor: samplerDescriptor)!

    // TEXTURES
    let textureLoader = MTKTextureLoader(device: device)
    try! textures.append(textureLoader.newTexture(name: &quot;test&quot;, scaleFactor: 1.0, bundle: nil, options: nil))
    
</code></pre>
<p>My shader is:</p>
<pre><code>fragment float4 fragmentShader(VertexOut vertexOut [[stage_in]],
                               metal::texture2d&lt;float&gt; texture [[texture(0)]],
                               metal::sampler textureSampler [[sampler(0)]])
{
    float4 color = texture.sample(textureSampler, vertexOut.texCoord);
    return color;
}
</code></pre>
<p><a href="https://i.sstatic.net/Zzof0.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Zzof0.png" alt="" /></a></p>

CC BY-SA 4.0
2023-02-20T15:52:57.533Z
What are the texture coordinates in your triangle vertices? What is the declaration of your vertex type/layout (both in CPU and GPU)? This is likely to be a problem with the texture coordinates, not the texture.
Kevin Reid
CC BY-SA 4.0
2023-02-21T16:29:50.860Z
Just to add to Kevin's comment - the fact you seem to have "clampToEdge" would suggest one of U or V  is set to something well outside [0,1]
Simon F
<texture><uv-mapping><metal>
Why is my texture stretched from 1 row of pixels? Metal/Swift
Bryan Potts
# Why is my texture stretched from 1 row of pixels? Metal/Swift

(Asked by: username_0 on 2023-02-20)

I have the following code below, and it generates the following render. I am using a texture test image, and it looks like its just taking the bottom row of pixels of that image and repeating then. It looks like its correctly applied to the edge it starts on, at least. Any ideas?

```
        // Create a sampler object
    let samplerDescriptor = MTLSamplerDescriptor()
    samplerDescriptor.minFilter = .linear
    samplerDescriptor.magFilter = .linear
    samplerDescriptor.mipFilter = .linear
    samplerDescriptor.sAddressMode = .clampToEdge
    samplerDescriptor.tAddressMode = .clampToEdge
    textureSamplerState = device.makeSamplerState(descriptor: samplerDescriptor)!

    // TEXTURES
    let textureLoader = MTKTextureLoader(device: device)
    try! textures.append(textureLoader.newTexture(name: "test", scaleFactor: 1.0, bundle: nil, options: nil))
    

```

My shader is:

```
fragment float4 fragmentShader(VertexOut vertexOut [[stage_in]],
                               metal::texture2d<float> texture [[texture(0)]],
                               metal::sampler textureSampler [[sampler(0)]])
{
    float4 color = texture.sample(textureSampler, vertexOut.texCoord);
    return color;
}

```

[![](https://i.sstatic.net/Zzof0.png)](https://i.sstatic.net/Zzof0.png)

**Tags:** texture, uv-mapping, metal

> **Comments:**
> **username_1**: What are the texture coordinates in your triangle vertices? What is the declaration of your vertex type/layout (both in CPU and GPU)? This is likely to be a problem with the texture coordinates, not the texture.  
> **username_2**: Just to add to username_1's comment - the fact you seem to have "clampToEdge" would suggest one of U or V  is set to something well outside [0,1]  

---

## 0 answers

