金属融合

时间:2018-08-06 09:23:51

标签: ios swift metal metalkit

我正在使用四个顶点绘制四边形并附加图像纹理。 然后我绘制一个具有不同纹理的四边形。

我的第一个Quad管道描述符是

我想在两个四边形之间有一个减法/乘法的BlendMode,该怎么做才能提示想法。

pipelineDescriptor.colorAttachments[0].isBlendingEnabled = true
pipelineDescriptor.colorAttachments[0].rgbBlendOperation = .add
pipelineDescriptor.colorAttachments[0].alphaBlendOperation = .add
pipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = .sourceAlpha
pipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .one
pipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha
pipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .oneMinusSourceAlpha

着色器功能是

vertex VertexOutTexture vertex_shader_texture(const VertexInTexture vertices [[stage_in]])
{

    VertexOutTexture v;
    v.position =  float4(vertices.position,1);
    v.color = vertices.color;
    v.textureCoordinates = vertices.textureCoordinates;

    return v;

}

fragment half4 fragment_shader_texture(VertexOutTexture vIn [[stage_in]],
                                       texture2d<float> texture [[texture(0)]]){

    constexpr sampler defaultSampler;

    float4 color =  texture.sample(defaultSampler, vIn.textureCoordinates);


    return half4(half4(color.r,color.g,color.b,0.5));
}

0 个答案:

没有答案