[英]Is iOS metal 3d texture sample method trilinear?
我正在使用顏色查找表創建 3d 紋理,並使用輸入顏色查找 output 顏色。 但我發現 output 顏色有一些中斷層。 此采樣器是否使用三線性采樣 3d 紋理?
這是我創建 3d 紋理的代碼
lutData是 r, g, b, a, r, g, b, a, ... 的數組。
lutSize是查找表的大小,它是 32 或 64。
func create3DTextureFromLutData(lutData: [Float], lutSize: Int) -> MTLTexture? {
let desc = MTLTextureDescriptor()
desc.textureType = .type3D
desc.pixelFormat = .rgba32Float
desc.width = lutSize
desc.height = lutSize
desc.depth = lutSize
desc.usage = .shaderRead
guard let texture = _device.makeTexture(descriptor: desc) else { return nil}
texture.replace(region: MTLRegion(origin: .init(x: 0, y: 0, z: 0), size: .init(width: lutSize, height: lutSize, depth: lutSize)), mipmapLevel: 0, slice: 0, withBytes: lutData, bytesPerRow: lutSize * MemoryLayout<Float>.size * 4, bytesPerImage: lutSize * lutSize * MemoryLayout<Float>.size * 4)
return texture
}
在我的着色器中,我只想像這樣對其進行采樣。
constexpr sampler textureSampler = sampler(mag_filter::linear, min_filter::linear, mip_filter::linear, address::clamp_to_edge);
half4 lutWith3dTexture(half4 inputColor, short lutSize, half lutStrength, texture3d<float, access::sample> lut3dTexture, sampler textureSampler) {
half4 originColor = inputColor;
float3 coor = float3(((inputColor.rgb * (lutSize - 1)) + 0.5) / lutSize);
half4 resultColor = half4(lut3dTexture.sample(textureSampler, coor));
return mix(originColor, resultColor, lutStrength);
}
我正在嘗試不同的 filter::xxxx 沒有任何幫助。
這是一個很好的結果,插值非常平滑。
這是 3d 紋理樣本的壞結果。
一般來說 - 是的,iOS 上的 Metal 支持三線性插值,但僅限於某些像素格式。 查看 功能集表,您可以看到 RGBA32Float(或通常在任何 Float32 紋理上)不支持過濾。 更改為 RGBA16Float 或 RGBA8Unorm 應該可以解決您的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.