Apple の texture importer または私自身のテクスチャ インポーターを使用している場合、レンダリング時にソフトウェア (透明な背景を使用) または Photoshop (PNG として保存) で描画された白いソフト エッジの円は、Metal に取り込まれると半透明の色が黒に置き換えられます。 .
以下は、Xcode の Metal デバッガーからのスクリーン グラブです。シェーダーに送信される前のテクスチャを見ることができます。
画像はここにあります (私は埋め込むのに十分なランクではありません)
Xcode、ファインダー、および UIImageView に配置された場合、ソース テクスチャにリングがありません。しかし、UIImage -> CGContex -> MTLTexture プロセス (具体的には MTLTexture 部分を考えています) のどこかで、透明なセクションが暗くなります。
過去数日間、できる限りのことを変えようと頭を壁にぶつけてきましたが、それがわかりません。
わかりやすくするために (ha)、これが私の個人的なインポート コードです。
import UIKit
import CoreGraphics
class MetalTexture {
class func imageToTexture(imageNamed: String, device: MTLDevice) -> 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
}
}
しかし、私はそれが問題だとは思いません (これは Apple の Swift のコピーであり、私は代わりに彼らのものを使用しましたが、違いはありません)。
どんなリードでも非常に役に立ちます。