SCATTER_FRAGMENT_SHADER

Constant SCATTER_FRAGMENT_SHADER 

Source
pub const SCATTER_FRAGMENT_SHADER: &str = r#"
struct VertexOutput {
    @builtin(position) clip_position: vec4<f32>,
    @location(0) color: vec4<f32>,
    @location(1) point_coord: vec2<f32>,
}

@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
    // Simple circular points - can be enhanced with distance field
    let center = vec2<f32>(0.5, 0.5);
    let dist = distance(in.point_coord, center);
    
    // Anti-aliased circle
    let radius = 0.5;
    let alpha = smoothstep(radius, radius - 0.05, dist);
    
    return vec4<f32>(in.color.rgb, in.color.a * alpha);
}
"#;
Expand description

Fragment shader for scatter plots (advanced, with anti-aliased circles)

Creates smooth circular points using distance field rendering:

  • Calculates distance from pixel to point center
  • Uses smoothstep for anti-aliased edges (no jagged pixels)
  • Pixels far from center are transparent (creates circle shape)

This produces much nicer looking scatter plots compared to square pixels.

Note: Currently not used - requires corresponding vertex shader setup.