Skip to content

Commit ad4d71b

Browse files
committed
Add descriptorbuffer rust shader
1 parent ec005b8 commit ad4d71b

6 files changed

Lines changed: 67 additions & 0 deletions

File tree

shaders/rust/Cargo.lock

Lines changed: 7 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ members = [
7272
"computeheadless/headless",
7373
"debugprintf/toon",
7474
"pushdescriptors/cube",
75+
"descriptorbuffer/cube",
7576
]
7677

7778
[workspace.dependencies]
672 Bytes
Binary file not shown.
7.34 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 = "descriptorbuffer-cube"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
spirv-std = { workspace = true }
8+
9+
[lib]
10+
crate-type = ["dylib"]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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}, Image};
5+
use spirv_std::image::SampledImage;
6+
7+
#[repr(C)]
8+
#[derive(Copy, Clone)]
9+
pub struct UboCamera {
10+
pub projection: Mat4,
11+
pub view: Mat4,
12+
}
13+
14+
#[repr(C)]
15+
#[derive(Copy, Clone)]
16+
pub struct UboModel {
17+
pub matrix: Mat4,
18+
}
19+
20+
#[spirv(vertex)]
21+
pub fn main_vs(
22+
in_pos: Vec3,
23+
in_normal: Vec3,
24+
in_uv: Vec2,
25+
in_color: Vec3,
26+
#[spirv(uniform, descriptor_set = 0, binding = 0)] camera: &UboCamera,
27+
#[spirv(uniform, descriptor_set = 1, binding = 0)] model: &UboModel,
28+
#[spirv(position)] out_position: &mut Vec4,
29+
out_normal: &mut Vec3,
30+
out_color: &mut Vec3,
31+
out_uv: &mut Vec2,
32+
) {
33+
*out_normal = in_normal;
34+
*out_color = in_color;
35+
*out_uv = in_uv;
36+
*out_position = camera.projection * camera.view * model.matrix * vec4(in_pos.x, in_pos.y, in_pos.z, 1.0);
37+
}
38+
39+
#[spirv(fragment)]
40+
pub fn main_fs(
41+
_in_normal: Vec3,
42+
in_color: Vec3,
43+
in_uv: Vec2,
44+
#[spirv(descriptor_set = 2, binding = 0)] sampler_color_map: &SampledImage<Image!(2D, type=f32, sampled)>,
45+
out_frag_color: &mut Vec4,
46+
) {
47+
let texture_color = sampler_color_map.sample(in_uv);
48+
*out_frag_color = texture_color * vec4(in_color.x, in_color.y, in_color.z, 1.0);
49+
}

0 commit comments

Comments
 (0)