Skip to content

Commit ee5c4a5

Browse files
committed
Add conservativeraster rust shaders
1 parent 44f0236 commit ee5c4a5

File tree

13 files changed

+129
-0
lines changed

13 files changed

+129
-0
lines changed

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
@@ -143,6 +143,9 @@ members = [
143143
"meshshader/meshshader",
144144
"terraintessellation/terrain",
145145
"terraintessellation/skysphere",
146+
"conservativeraster/triangle",
147+
"conservativeraster/triangleoverlay",
148+
"conservativeraster/fullscreen",
146149
]
147150

148151
[workspace.package]
576 Bytes
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 = "conservativeraster-fullscreen"
3+
version = "0.1.0"
4+
edition.workspace = true
5+
6+
[lib]
7+
crate-type = ["dylib"]
8+
9+
[dependencies]
10+
spirv-std = { workspace = true }
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#![no_std]
2+
3+
use spirv_std::glam::{Vec2, Vec4};
4+
use spirv_std::spirv;
5+
use spirv_std::{Image, Sampler};
6+
7+
#[spirv(vertex)]
8+
pub fn main_vs(
9+
#[spirv(vertex_index)] vertex_index: u32,
10+
#[spirv(position)] out_position: &mut Vec4,
11+
out_uv: &mut Vec2,
12+
) {
13+
*out_uv = Vec2::new(
14+
((vertex_index << 1) & 2) as f32,
15+
(vertex_index & 2) as f32,
16+
);
17+
*out_position = Vec4::new(
18+
out_uv.x * 2.0 - 1.0,
19+
out_uv.y * 2.0 - 1.0,
20+
0.0,
21+
1.0,
22+
);
23+
}
24+
25+
#[spirv(fragment)]
26+
pub fn main_fs(
27+
in_uv: Vec2,
28+
#[spirv(descriptor_set = 0, binding = 0)] sampler_color: &Image!(2D, type=f32, sampled),
29+
#[spirv(descriptor_set = 0, binding = 0)] sampler: &Sampler,
30+
out_frag_color: &mut Vec4,
31+
) {
32+
*out_frag_color = sampler_color.sample(*sampler, in_uv);
33+
}
416 Bytes
Binary file not shown.
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 = "conservativeraster-triangle"
3+
version = "0.1.0"
4+
edition.workspace = true
5+
6+
[lib]
7+
crate-type = ["dylib"]
8+
9+
[dependencies]
10+
spirv-std = { workspace = true }
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#![no_std]
2+
3+
use spirv_std::glam::{Mat4, Vec3, Vec4};
4+
use spirv_std::spirv;
5+
6+
#[repr(C)]
7+
#[derive(Copy, Clone)]
8+
pub struct UBO {
9+
pub projection: Mat4,
10+
pub model: Mat4,
11+
}
12+
13+
#[spirv(vertex)]
14+
pub fn main_vs(
15+
in_pos: Vec3,
16+
in_color: Vec3,
17+
#[spirv(uniform, descriptor_set = 0, binding = 0)] ubo: &UBO,
18+
#[spirv(position)] out_position: &mut Vec4,
19+
out_color: &mut Vec3,
20+
) {
21+
*out_color = in_color;
22+
*out_position = ubo.projection * ubo.model * Vec4::from((in_pos, 1.0));
23+
}
24+
25+
#[spirv(fragment)]
26+
pub fn main_fs(
27+
in_color: Vec3,
28+
out_frag_color: &mut Vec4,
29+
) {
30+
*out_frag_color = Vec4::new(in_color.x, in_color.y, in_color.z, 1.0);
31+
}

0 commit comments

Comments
 (0)