rustial_renderer_wgpu/gpu/circle_vertex.rs
1//! Vertex type for SDF circle rendering.
2
3use bytemuck::{Pod, Zeroable};
4
5/// A vertex for the SDF circle GPU pipeline.
6///
7/// Each circle is rendered as a screen-aligned quad (4 vertices, 6 indices).
8/// The `quad_offset` attribute defines the corner of the quad in local space
9/// (±1, ±1) and the fragment shader evaluates an SDF to produce anti-aliased
10/// circles with optional stroke and blur.
11#[repr(C)]
12#[derive(Debug, Clone, Copy, Pod, Zeroable)]
13pub struct CircleVertex {
14 /// Circle centre position `[x, y, z]` in camera-relative meters.
15 pub position: [f32; 3],
16 /// Quad corner offset `[u, v]` in `[-1..1]` range.
17 pub quad_offset: [f32; 2],
18 /// Fill colour `[r, g, b, a]`.
19 pub color: [f32; 4],
20 /// Stroke colour `[r, g, b, a]`.
21 pub stroke_color: [f32; 4],
22 /// Circle parameters: `[radius, stroke_width, blur, 0]`.
23 pub params: [f32; 4],
24}
25
26impl CircleVertex {
27 /// Vertex buffer layout for the circle pipeline.
28 pub fn layout() -> wgpu::VertexBufferLayout<'static> {
29 wgpu::VertexBufferLayout {
30 array_stride: std::mem::size_of::<CircleVertex>() as wgpu::BufferAddress,
31 step_mode: wgpu::VertexStepMode::Vertex,
32 attributes: &[
33 // position
34 wgpu::VertexAttribute {
35 offset: 0,
36 shader_location: 0,
37 format: wgpu::VertexFormat::Float32x3,
38 },
39 // quad_offset
40 wgpu::VertexAttribute {
41 offset: 12,
42 shader_location: 1,
43 format: wgpu::VertexFormat::Float32x2,
44 },
45 // color
46 wgpu::VertexAttribute {
47 offset: 20,
48 shader_location: 2,
49 format: wgpu::VertexFormat::Float32x4,
50 },
51 // stroke_color
52 wgpu::VertexAttribute {
53 offset: 36,
54 shader_location: 3,
55 format: wgpu::VertexFormat::Float32x4,
56 },
57 // params (radius, stroke_width, blur, 0)
58 wgpu::VertexAttribute {
59 offset: 52,
60 shader_location: 4,
61 format: wgpu::VertexFormat::Float32x4,
62 },
63 ],
64 }
65 }
66}