CAMetalLayer transparency set invalid on VisionOS

Hi, I try to use CAMetalLayer to render a page on VisionOS, but the transparency of CAMetalLayer seems not displayed correctly. As the picture shown, the square background should be transparent, but it's not.

I have set the PipelineDescriptor and RenderPassDescriptor like this:

        let pipelineDescriptor = MTLRenderPipelineDescriptor()
        pipelineDescriptor.colorAttachments[0].pixelFormat = .bgra8Unorm
        pipelineDescriptor.colorAttachments[0].isBlendingEnabled = true
        pipelineDescriptor.colorAttachments[0].rgbBlendOperation = .add
        pipelineDescriptor.colorAttachments[0].alphaBlendOperation = .add
        pipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = .sourceAlpha
        pipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .sourceAlpha
        pipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = .oneMinusSourceAlpha
        pipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .oneMinusSourceAlpha
        let descriptor = MTLRenderPassDescriptor()
        descriptor.colorAttachments[0].texture = texture
        descriptor.colorAttachments[0].loadAction = .clear
        descriptor.colorAttachments[0].clearColor = MTLClearColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 0.0)
        descriptor.colorAttachments[0].storeAction = .store

  • file a bug report!!!

Add a Comment

Replies

And my shader is

typedef struct
{
    float3 position [[attribute(0)]];
} Vertex;

typedef struct
{
    float4 position [[position]];
} ColorInOut;

typedef struct
{
    matrix_float4x4 projectionMatrix;
    matrix_float4x4 modelViewMatrix;
} Uniforms;
vertex ColorInOut vertex_shader(device Vertex *vertices [[buffer(0)]],
                                uint vertexId [[vertex_id]],
                                constant Uniforms & uniforms [[ buffer(1) ]])
{
    ColorInOut out;
    Vertex in = vertices[vertexId];
    float4 position = float4(in.position, 1.0);
    out.position = uniforms.projectionMatrix * uniforms.modelViewMatrix * position;
    return out;
}
fragment float4 fragment_shader(ColorInOut in [[stage_in]])
{
    // Blue
    return float4(0, 0, 1, 1);
}