1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! Vertex type for SDF symbol / text rendering.
use bytemuck::{Pod, Zeroable};
/// A vertex for the symbol GPU pipeline.
///
/// Renders SDF glyphs and icons as textured quads. Each glyph is a quad
/// (4 vertices, 6 indices) that samples from an SDF glyph atlas texture.
/// The fragment shader thresholds the SDF to produce crisp, scalable text
/// with optional halo.
#[repr(C)]
#[derive(Debug, Clone, Copy, Pod, Zeroable)]
pub struct SymbolVertex {
/// Glyph anchor position `[x, y, z]` in camera-relative meters.
pub position: [f32; 3],
/// Glyph quad offset from anchor `[dx, dy]` in world-space meters.
pub glyph_offset: [f32; 2],
/// Texture coordinates `[u, v]` into the SDF atlas.
pub tex_coord: [f32; 2],
/// Text colour `[r, g, b, a]`.
pub color: [f32; 4],
/// Halo colour `[r, g, b, a]`.
pub halo_color: [f32; 4],
/// Symbol parameters: `[halo_width, gamma_scale, 0, 0]`.
pub params: [f32; 4],
}
impl SymbolVertex {
/// Vertex buffer layout for the symbol pipeline.
pub fn layout() -> wgpu::VertexBufferLayout<'static> {
wgpu::VertexBufferLayout {
array_stride: std::mem::size_of::<SymbolVertex>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &[
// position
wgpu::VertexAttribute {
offset: 0,
shader_location: 0,
format: wgpu::VertexFormat::Float32x3,
},
// glyph_offset
wgpu::VertexAttribute {
offset: 12,
shader_location: 1,
format: wgpu::VertexFormat::Float32x2,
},
// tex_coord
wgpu::VertexAttribute {
offset: 20,
shader_location: 2,
format: wgpu::VertexFormat::Float32x2,
},
// color
wgpu::VertexAttribute {
offset: 28,
shader_location: 3,
format: wgpu::VertexFormat::Float32x4,
},
// halo_color
wgpu::VertexAttribute {
offset: 44,
shader_location: 4,
format: wgpu::VertexFormat::Float32x4,
},
// params
wgpu::VertexAttribute {
offset: 60,
shader_location: 5,
format: wgpu::VertexFormat::Float32x4,
},
],
}
}
}