rustial-renderer-wgpu 0.0.1

Pure WGPU renderer for the rustial 2.5D map engine
Documentation
//! Vertex type for dedicated line rendering with dash-pattern and SDF
//! cap/join antialiasing support.

use bytemuck::{Pod, Zeroable};

/// A vertex for the dedicated line GPU pipeline.
///
/// Extends the basic vector vertex with per-vertex distance along the
/// polyline centreline, an extrusion normal, and a cap/join flag.
/// The fragment shader uses the distance for dash-pattern evaluation
/// and the cap/join flag to switch between linear edge AA (ribbon body)
/// and SDF circle-based AA (round caps/joins).
#[repr(C)]
#[derive(Debug, Clone, Copy, Pod, Zeroable)]
pub struct LineVertex {
    /// Position `[x, y, z]` in camera-relative meters.
    pub position: [f32; 3],
    /// Per-vertex RGBA color.
    pub color: [f32; 4],
    /// Extrusion normal `[nx, ny]` perpendicular to the line centreline.
    ///
    /// For ribbon body vertices the magnitude is 1.0.  For round cap/join
    /// fan vertices the magnitude is slightly > 1.0 (circumscribed) so
    /// that the SDF clip at magnitude 1.0 traces a perfect circle.
    pub line_normal: [f32; 2],
    /// Distance along the polyline centreline (world-space meters).
    pub line_distance: f32,
    /// Cap/join flag: `1.0` for round cap/join fan vertices, `0.0` for
    /// ribbon body.  When > 0.5, the fragment shader uses SDF circle AA
    /// instead of linear edge AA and discards fragments beyond the
    /// ideal circle boundary.
    pub cap_join: f32,
}

impl LineVertex {
    /// Vertex buffer layout for the line pipeline.
    pub fn layout() -> wgpu::VertexBufferLayout<'static> {
        wgpu::VertexBufferLayout {
            array_stride: std::mem::size_of::<LineVertex>() as wgpu::BufferAddress,
            step_mode: wgpu::VertexStepMode::Vertex,
            attributes: &[
                // position
                wgpu::VertexAttribute {
                    offset: 0,
                    shader_location: 0,
                    format: wgpu::VertexFormat::Float32x3,
                },
                // color
                wgpu::VertexAttribute {
                    offset: 12,
                    shader_location: 1,
                    format: wgpu::VertexFormat::Float32x4,
                },
                // line_normal
                wgpu::VertexAttribute {
                    offset: 28,
                    shader_location: 2,
                    format: wgpu::VertexFormat::Float32x2,
                },
                // line_distance
                wgpu::VertexAttribute {
                    offset: 36,
                    shader_location: 3,
                    format: wgpu::VertexFormat::Float32,
                },
                // cap_join
                wgpu::VertexAttribute {
                    offset: 40,
                    shader_location: 4,
                    format: wgpu::VertexFormat::Float32,
                },
            ],
        }
    }
}