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$ Commented Feb 20, 2023 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$ Commented Feb 21, 2023 at 16:29

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.