rustial-renderer-wgpu 0.0.1

Pure WGPU renderer for the rustial 2.5D map engine
Documentation
//! Vertex type for SDF circle rendering.

use bytemuck::{Pod, Zeroable};

/// A vertex for the SDF circle GPU pipeline.
///
/// Each circle is rendered as a screen-aligned quad (4 vertices, 6 indices).
/// The `quad_offset` attribute defines the corner of the quad in local space
/// (±1, ±1) and the fragment shader evaluates an SDF to produce anti-aliased
/// circles with optional stroke and blur.
#[repr(C)]
#[derive(Debug, Clone, Copy, Pod, Zeroable)]
pub struct CircleVertex {
    /// Circle centre position `[x, y, z]` in camera-relative meters.
    pub position: [f32; 3],
    /// Quad corner offset `[u, v]` in `[-1..1]` range.
    pub quad_offset: [f32; 2],
    /// Fill colour `[r, g, b, a]`.
    pub color: [f32; 4],
    /// Stroke colour `[r, g, b, a]`.
    pub stroke_color: [f32; 4],
    /// Circle parameters: `[radius, stroke_width, blur, 0]`.
    pub params: [f32; 4],
}

impl CircleVertex {
    /// Vertex buffer layout for the circle pipeline.
    pub fn layout() -> wgpu::VertexBufferLayout<'static> {
        wgpu::VertexBufferLayout {
            array_stride: std::mem::size_of::<CircleVertex>() as wgpu::BufferAddress,
            step_mode: wgpu::VertexStepMode::Vertex,
            attributes: &[
                // position
                wgpu::VertexAttribute {
                    offset: 0,
                    shader_location: 0,
                    format: wgpu::VertexFormat::Float32x3,
                },
                // quad_offset
                wgpu::VertexAttribute {
                    offset: 12,
                    shader_location: 1,
                    format: wgpu::VertexFormat::Float32x2,
                },
                // color
                wgpu::VertexAttribute {
                    offset: 20,
                    shader_location: 2,
                    format: wgpu::VertexFormat::Float32x4,
                },
                // stroke_color
                wgpu::VertexAttribute {
                    offset: 36,
                    shader_location: 3,
                    format: wgpu::VertexFormat::Float32x4,
                },
                // params (radius, stroke_width, blur, 0)
                wgpu::VertexAttribute {
                    offset: 52,
                    shader_location: 4,
                    format: wgpu::VertexFormat::Float32x4,
                },
            ],
        }
    }
}