How to load MTLTexture without premultiplied alpha?

Hello all,

I need my texture to be not premultiplied alpha, because is use the alpha for some additional calculations in the fragment shader.

At the moment I load my texture like this

let textureLoader = MTKTextureLoader(device: sceneView.device!)
myTexture = try textureLoader.newTexture(URL: URL(fileURLWithPath: path!), options: [MTKTextureLoader.Option.SRGB: false])

because I need the raw RGBA values. But of course it gets premultiplied.

How can I turn off this behavior?

This is unexpected. newTexture(URL:options:) should not premultiply alpha. Can you tell us more about what you're trying to load (filetype, colorspace, etc)?

Yeah, my bad. It is loading correctly and displaying correctly. But my last question still has issues. I'll continue there.

Maybe you were trying to load a png from the asset catalog? Everything in the asset catalog uses SRGB, even if you try to turn it off. The SRGB processing includes premultiply.

The documentation for the "asset" function of MTLTextureLoader says that the SRGB option is ignored.

The solution for me was to move the png file out of the asset catalog, and load using its URL.

How to load MTLTexture without premultiplied alpha?
 
 
Q