Skip to main content
deleted 8 characters in body
Source Link
Sunderam Dubey
  • 8.8k
  • 12
  • 24
  • 41

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? Thanks!

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? Thanks!

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?

Source Link
PhilBot
  • 30
  • 20
  • 90
  • 189

Metal Alpha Blending to create smooth line

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? Thanks!