title: Metal MTLTexture replaces semi-transparent areas with black when alpha values that aren't 1 or 0
body: <p>While using <a href="https://developer.apple.com/library/ios/samplecode/MetalTexturedQuad/Listings/MetalTexturedQuad_AAPLTexture_mm.html" rel="noreferrer">Apple's texture importer</a>, or my own, a white soft-edged circle drawn in software (with a transparent bg) or in Photoshop (saved as a PNG) when rendered will have its semi-transparent colors replaced with black when brought into Metal.</p>
  
  <p>Below is a screen grab from Xcode's Metal debugger, you can see the texture before being sent to shaders.</p>
  
  <p><a href="http://i.stack.imgur.com/hGDI8.png" rel="noreferrer">Image located here (I'm not high ranked enough to embed)</a></p>
  
  <p>In Xcode, finder, and when put into an UIImageView, the source texture does not have the ring. But somewhere along the UIImage -> CGContex -> MTLTexture process (I'm thinking specifically the MTLTexture part) the tranparent sections are darkened.</p>
  
  <p>I've been banging my head against the wall changing everything I could for the past couple of days but I can't figure it out.</p>
  
  <p>To be transparent (ha), here is my personal import code</p>
  
  <pre><code>import UIKit
  import CoreGraphics
  
  class MetalTexture {
  
      class func imageToTexture(imageNamed: String, device: MTLDevice) -&gt; MTLTexture {
          let bytesPerPixel = 4
          let bitsPerComponent = 8
  
          var image = UIImage(named: imageNamed)!
  
          let width = Int(image.size.width)
          let height = Int(image.size.height)
          let bounds = CGRectMake(0, 0, CGFloat(width), CGFloat(height))
  
          var rowBytes = width * bytesPerPixel
          var colorSpace = CGColorSpaceCreateDeviceRGB()
  
          let context = CGBitmapContextCreate(nil, width, height, bitsPerComponent, rowBytes, colorSpace, CGBitmapInfo(CGImageAlphaInfo.PremultipliedLast.rawValue))
  
          CGContextClearRect(context, bounds)
          CGContextTranslateCTM(context, CGFloat(width), CGFloat(height))
          CGContextScaleCTM(context, -1.0, -1.0)
          CGContextDrawImage(context, bounds, image.CGImage)
  
          var texDescriptor = MTLTextureDescriptor.texture2DDescriptorWithPixelFormat(.RGBA8Unorm, width: width, height: height, mipmapped: false)
  
          var texture = device.newTextureWithDescriptor(texDescriptor)
          texture.label = imageNamed
  
          var pixelsData = CGBitmapContextGetData(context)
  
          var region = MTLRegionMake2D(0, 0, width, height)
          texture.replaceRegion(region, mipmapLevel: 0, withBytes: pixelsData, bytesPerRow: rowBytes)
  
          return texture
      }
  }
  </code></pre>
  
  <p>But I don't think that's the problem (since it's a copy of Apple's in Swift, and I've used theirs instead with no differences).</p>
  
  <p>Any leads at all would be super helpful.</p>