【问题标题】:Correct blending mode for r8Unorm texturer8Unorm 纹理的正确混合模式
【发布时间】:2020-11-11 16:06:18
【问题描述】:

目标纹理和画笔纹理是r8Unorm。在这种情况下,什么是正确的混合模式?

画笔纹理是径向渐变的,看起来像这样:

在第一次绘制调用时,它看起来是正确的,但在下一次绘制调用时,它变成了没有任何渐变的完整红色圆圈。

我当前错误的混合设置如下所示:

private func createBrushDescriptor(library: MTLLibrary) -> MTLRenderPipelineDescriptor {
    let vertexDescriptor = MTLVertexDescriptor()
    vertexDescriptor.attributes[0].format = .float2
    vertexDescriptor.attributes[0].offset = 0
    vertexDescriptor.attributes[0].bufferIndex = 0

    vertexDescriptor.layouts[0].stride = 2 * MemoryLayout<simd_float1>.size
    vertexDescriptor.layouts[0].stepFunction = .perVertex
    vertexDescriptor.layouts[0].stepRate = 1
    
    let descriptor = MTLRenderPipelineDescriptor()
    descriptor.vertexFunction = library.makeFunction(name: "brush_vertex_function")
    descriptor.vertexDescriptor = vertexDescriptor
    descriptor.fragmentFunction = library.makeFunction(name: "brush_fragment_function")
    descriptor.colorAttachments[0].pixelFormat = .r8Unorm
    
    descriptor.colorAttachments[0].isBlendingEnabled = true
    descriptor.colorAttachments[0].rgbBlendOperation = .add
    descriptor.colorAttachments[0].sourceRGBBlendFactor = .one
    descriptor.colorAttachments[0].destinationRGBBlendFactor = .one
    
    descriptor.depthAttachmentPixelFormat = .invalid
    
    return descriptor
}

我使用MTLPrimitiveType.point 原语绘制画笔。

【问题讨论】:

    标签: macos metal blending


    【解决方案1】:

    我用这个配置解决了我的问题:

    descriptor.colorAttachments[0].isBlendingEnabled = true
    descriptor.colorAttachments[0].rgbBlendOperation = .max
    descriptor.colorAttachments[0].sourceRGBBlendFactor = .one
    descriptor.colorAttachments[0].destinationRGBBlendFactor = .one
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-25
      • 1970-01-01
      • 2014-10-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多