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:
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:
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:
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?
MTLDepthStencilDescriptor.depthCompareFunction
. What are you using for it?depthCompareFunction
is the culprit. Also,depthWriteEnabled
should probably befalse
for the pipeline you use to draw alpha-blended geometry