threecrate_visualization/
shaders.rs

1//! Shader utilities for 3D visualization
2
3/// Vertex shader for point cloud rendering
4pub const POINT_VERTEX_SHADER: &str = r#"
5#version 450
6
7layout(location = 0) in vec3 position;
8layout(location = 1) in vec3 color;
9
10layout(set = 0, binding = 0) uniform Uniforms {
11    mat4 view_proj;
12};
13
14layout(location = 0) out vec3 v_color;
15
16void main() {
17    gl_Position = view_proj * vec4(position, 1.0);
18    v_color = color;
19}
20"#;
21
22/// Fragment shader for point cloud rendering
23pub const POINT_FRAGMENT_SHADER: &str = r#"
24#version 450
25
26layout(location = 0) in vec3 v_color;
27layout(location = 0) out vec4 f_color;
28
29void main() {
30    f_color = vec4(v_color, 1.0);
31}
32"#;
33
34/// Vertex shader for mesh rendering
35pub const MESH_VERTEX_SHADER: &str = r#"
36#version 450
37
38layout(location = 0) in vec3 position;
39layout(location = 1) in vec3 normal;
40layout(location = 2) in vec3 color;
41
42layout(set = 0, binding = 0) uniform Uniforms {
43    mat4 view_proj;
44    mat4 model;
45    vec3 light_dir;
46};
47
48layout(location = 0) out vec3 v_color;
49layout(location = 1) out vec3 v_normal;
50
51void main() {
52    gl_Position = view_proj * model * vec4(position, 1.0);
53    v_color = color;
54    v_normal = normal;
55}
56"#;
57
58/// Fragment shader for mesh rendering
59pub const MESH_FRAGMENT_SHADER: &str = r#"
60#version 450
61
62layout(location = 0) in vec3 v_color;
63layout(location = 1) in vec3 v_normal;
64
65layout(set = 0, binding = 0) uniform Uniforms {
66    mat4 view_proj;
67    mat4 model;
68    vec3 light_dir;
69};
70
71layout(location = 0) out vec4 f_color;
72
73void main() {
74    float light = max(0.1, dot(normalize(v_normal), normalize(light_dir)));
75    f_color = vec4(v_color * light, 1.0);
76}
77"#;