0

I am trying to implement the method of drawing a smooth line through a large number of 3D points shown here --> https://ahmetkermen.com/simple-smooth-line-drawing-with-opengl.

I have a small quad at each point, with a billboard modelview matrix, that I render this image onto:

enter image description here

My blending options are defined like this:

// Allow alpha blending
pipelineDescriptor.colorAttachments[0].isBlendingEnabled = true
pipelineDescriptor.colorAttachments[0].rgbBlendOperation = .add
pipelineDescriptor.colorAttachments[0].alphaBlendOperation = .add
pipelineDescriptor.colorAttachments[0].sourceRGBBlendFactor = .sourceAlpha
pipelineDescriptor.colorAttachments[0].sourceAlphaBlendFactor = .oneMinusSourceAlpha
pipelineDescriptor.colorAttachments[0].destinationRGBBlendFactor = .sourceAlpha
pipelineDescriptor.colorAttachments[0].destinationAlphaBlendFactor = .oneMinusSourceAlpha

I am seeing that the alpha blending works with the rest of the scene as shown here:

enter image description here

But the blending does not work with the quads in the line themselves. Some quads show the sharp corner 'over' the next quad in the line:

enter image description here

Perhaps it is a z-order issue, however each point does have a unique position.

My fragment shader is only sampling the texture and setting the color:

fragment float4 frag_main(VertexOut fragmentIn [[stage_in]],
                              constant FragUniforms &uniforms [[buffer(0)]],
                              texture2d<float, access::sample> baseColorTexture [[texture(0)]],
                              sampler baseColorSampler [[sampler(0)]]
{
    
    // Sample the image
    float3 baseColor = baseColorTexture.sample(baseColorSampler, fragmentIn.texCoords).rgb;

    return float4(baseColor, 1.0);
    
}

What am I doing wrong and how can I get the blending to work so that the quads appear as a continuous and smooth line?

4
  • It looks to me like a problem with your MTLDepthStencilDescriptor.depthCompareFunction. What are you using for it?
    – user652038
    Commented Nov 28, 2022 at 16:16
  • Yeah, I think depthCompareFunction is the culprit. Also, depthWriteEnabled should probably be false for the pipeline you use to draw alpha-blended geometry
    – Spo1ler
    Commented Nov 28, 2022 at 17:04
  • Thanks for the comments - they helped me figure it out. It looks great now if I do the following: depthStencilDescriptor.depthCompareFunction = .lessEqual depthStencilDescriptor.isDepthWriteEnabled = false
    – PhilBot
    Commented Nov 28, 2022 at 19:03
  • I was using .less before.
    – PhilBot
    Commented Nov 28, 2022 at 19:03

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.