Skip to content

Commit 479e4f8

Browse files
committed
Add debugutils rust shaders
1 parent f7ca4eb commit 479e4f8

14 files changed

Lines changed: 230 additions & 0 deletions

File tree

shaders/rust/Cargo.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shaders/rust/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ members = [
8484
"offscreen/quad",
8585
"offscreen/mirror",
8686
"offscreen/phong",
87+
"debugutils/colorpass",
88+
"debugutils/postprocess",
89+
"debugutils/toon",
8790
]
8891

8992
[workspace.dependencies]
416 Bytes
Binary file not shown.
4.45 KB
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "debugutils-colorpass"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
crate-type = ["dylib"]
8+
9+
[dependencies]
10+
spirv-std = { workspace = true }
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#![cfg_attr(target_arch = "spirv", no_std)]
2+
#![allow(clippy::missing_safety_doc)]
3+
4+
use spirv_std::{spirv, glam::{vec4, Mat4, Vec2, Vec3, Vec4}};
5+
6+
#[repr(C)]
7+
#[derive(Copy, Clone)]
8+
pub struct Ubo {
9+
pub projection: Mat4,
10+
pub model: Mat4,
11+
}
12+
13+
14+
#[spirv(vertex)]
15+
pub fn main_vs(
16+
in_pos: Vec4,
17+
_in_uv: Vec2,
18+
_in_normal: Vec3,
19+
in_color: Vec3,
20+
#[spirv(uniform, descriptor_set = 0, binding = 0)] ubo: &Ubo,
21+
#[spirv(position)] out_position: &mut Vec4,
22+
out_color: &mut Vec3,
23+
) {
24+
*out_color = in_color;
25+
*out_position = ubo.projection * ubo.model * in_pos;
26+
}
27+
28+
#[spirv(fragment)]
29+
pub fn main_fs(
30+
in_color: Vec3,
31+
out_frag_color: &mut Vec4,
32+
) {
33+
*out_frag_color = vec4(in_color.x, in_color.y, in_color.z, 1.0);
34+
}
2.41 KB
Binary file not shown.
816 Bytes
Binary file not shown.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "debugutils-postprocess"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
crate-type = ["dylib"]
8+
9+
[dependencies]
10+
spirv-std = { workspace = true }
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#![cfg_attr(target_arch = "spirv", no_std)]
2+
#![allow(clippy::missing_safety_doc)]
3+
4+
use spirv_std::{spirv, glam::{vec2, vec4, Vec2, Vec4}, Image, image::SampledImage};
5+
6+
#[spirv(vertex)]
7+
pub fn main_vs(
8+
#[spirv(vertex_index)] vert_idx: i32,
9+
#[spirv(position)] out_position: &mut Vec4,
10+
out_uv: &mut Vec2,
11+
) {
12+
*out_uv = vec2(
13+
((vert_idx << 1) & 2) as f32,
14+
(vert_idx & 2) as f32,
15+
);
16+
*out_position = vec4(
17+
out_uv.x * 2.0 - 1.0,
18+
out_uv.y * 2.0 - 1.0,
19+
0.0,
20+
1.0,
21+
);
22+
}
23+
24+
#[spirv(fragment)]
25+
pub fn main_fs(
26+
in_uv: Vec2,
27+
#[spirv(descriptor_set = 0, binding = 1)] sampler_color: &SampledImage<Image!(2D, type=f32, sampled)>,
28+
out_frag_color: &mut Vec4,
29+
) {
30+
// Single pass gauss blur
31+
let tex_offset = vec2(0.01, 0.01);
32+
33+
let tc0 = in_uv + vec2(-tex_offset.x, -tex_offset.y);
34+
let tc1 = in_uv + vec2(0.0, -tex_offset.y);
35+
let tc2 = in_uv + vec2(tex_offset.x, -tex_offset.y);
36+
let tc3 = in_uv + vec2(-tex_offset.x, 0.0);
37+
let tc4 = in_uv + vec2(0.0, 0.0);
38+
let tc5 = in_uv + vec2(tex_offset.x, 0.0);
39+
let tc6 = in_uv + vec2(-tex_offset.x, tex_offset.y);
40+
let tc7 = in_uv + vec2(0.0, tex_offset.y);
41+
let tc8 = in_uv + vec2(tex_offset.x, tex_offset.y);
42+
43+
let col0: Vec4 = sampler_color.sample(tc0);
44+
let col1: Vec4 = sampler_color.sample(tc1);
45+
let col2: Vec4 = sampler_color.sample(tc2);
46+
let col3: Vec4 = sampler_color.sample(tc3);
47+
let col4: Vec4 = sampler_color.sample(tc4);
48+
let col5: Vec4 = sampler_color.sample(tc5);
49+
let col6: Vec4 = sampler_color.sample(tc6);
50+
let col7: Vec4 = sampler_color.sample(tc7);
51+
let col8: Vec4 = sampler_color.sample(tc8);
52+
53+
let sum = (1.0 * col0 + 2.0 * col1 + 1.0 * col2 +
54+
2.0 * col3 + 4.0 * col4 + 2.0 * col5 +
55+
1.0 * col6 + 2.0 * col7 + 1.0 * col8) / 16.0;
56+
57+
*out_frag_color = vec4(sum.x, sum.y, sum.z, 1.0);
58+
}

0 commit comments

Comments
 (0)