Blend Mode in Metal
Asked Answered
G

2

9

These are the two the blend-mode i used in OpenGL what is the conversion to the metal in IOS

glEnable(GL_BLEND);

glBlendFuncSeparate(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA);

glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_SRC_ALPHA, GL_ONE);
Gounod answered 18/7, 2018 at 9:33 Comment(0)
U
15

You configure blending on your render pipeline descriptor. I believe the equivalent configurations for your GL code are:

// glEnable(GL_BLEND)
renderPipelineDescriptor.colorAttachments[0].isBlendingEnabled = true

// glBlendFuncSeparate(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA,GL_ONE,GL_ONE_MINUS_SRC_ALPHA)
renderPipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = .sourceAlpha
renderPipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha
renderPipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .one
renderPipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .oneMinusSourceAlpha

// glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_SRC_ALPHA, GL_ONE)
renderPipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = .sourceAlpha
renderPipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = .one
renderPipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .sourceAlpha
renderPipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .one
Underwrite answered 19/7, 2018 at 4:58 Comment(1)
second works fine. but First one Still I am getting clear screen even I draw a Quad with Red colorGounod
I
-1
    // source: last draw.
    // destination: previous draw.
    // when use UIGraphicsGetCurrentContext() create UIImage from UIColor. alpha will be premultiplied to RGB.
    // RGB = (Source.rgb * Source.a) + (Dest.rgb * (1 - Source.a))
    // A = (Source.a * Source.a) + (Dest.a * (1 - Source.a))
    /*
    pipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = .sourceAlpha
    pipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .sourceAlpha
    pipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha
    pipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .oneMinusSourceAlpha
     */

    // source: last draw.
    // destination: previous draw.
    // when use UIGraphicsGetCurrentContext() create UIImage from UIColor. alpha will be premultiplied to RGB.
    // RGB = (Source.rgb * Source.a) + (Dest.rgb * (1 - Source.a))
    // A = (Source.a * Source.a) + (Dest.a * (1))
    pipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = .sourceAlpha
    pipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .sourceAlpha
    pipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha
    pipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .one
Illstarred answered 9/10, 2022 at 7:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.