0
$\begingroup$

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;
}

$\endgroup$
2
  • 2
    $\begingroup$ 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. $\endgroup$
    – Kevin Reid
    Feb 20 at 15:52
  • $\begingroup$ 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] $\endgroup$
    – Simon F
    Feb 21 at 16:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.