Skip to content

Commit c49d4e4

Browse files
committed
Add displacement rust shaders
1 parent 0d5179e commit c49d4e4

File tree

12 files changed

+148
-0
lines changed

12 files changed

+148
-0
lines changed

shaders/rust/Cargo.lock

Lines changed: 14 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ members = [
2828
"descriptorbuffer/cube",
2929
"descriptorindexing",
3030
"descriptorsets/cube",
31+
"displacement/base",
32+
"displacement/displacement",
3133
"distancefieldfonts/bitmap",
3234
"distancefieldfonts/sdf",
3335
"dynamicrendering/texture",
1.05 KB
Binary file not shown.
668 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 = "displacement-base"
3+
version = "0.1.0"
4+
edition.workspace = true
5+
6+
[dependencies]
7+
spirv-std = { workspace = true }
8+
9+
[lib]
10+
crate-type = ["dylib"]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#![cfg_attr(target_arch = "spirv", no_std)]
2+
#![allow(clippy::missing_safety_doc)]
3+
4+
use spirv_std::{spirv, glam::{vec4, Vec2, Vec3, Vec4}};
5+
6+
#[spirv(vertex)]
7+
pub fn main_vs(
8+
in_pos: Vec3,
9+
in_normal: Vec3,
10+
in_uv: Vec2,
11+
#[spirv(position)] out_position: &mut Vec4,
12+
out_normal: &mut Vec3,
13+
out_uv: &mut Vec2,
14+
) {
15+
*out_position = vec4(in_pos.x, in_pos.y, in_pos.z, 1.0);
16+
*out_uv = in_uv;
17+
*out_normal = in_normal;
18+
}
19+
20+
#[spirv(fragment)]
21+
pub fn main_fs(
22+
in_normal: Vec3,
23+
in_uv: Vec2,
24+
in_eye_pos: Vec3,
25+
in_light_vec: Vec3,
26+
#[spirv(descriptor_set = 0, binding = 1)] color_map: &spirv_std::image::SampledImage<spirv_std::Image!(2D, type=f32, sampled)>,
27+
out_frag_color: &mut Vec4,
28+
) {
29+
let _n = in_normal.normalize();
30+
let _l = Vec3::new(1.0, 1.0, 1.0).normalize();
31+
32+
let color = color_map.sample(in_uv);
33+
34+
let _eye = (-in_eye_pos).normalize();
35+
let _reflected = (-in_light_vec).reflect(in_normal).normalize();
36+
37+
let i_ambient = vec4(0.0, 0.0, 0.0, 1.0);
38+
let i_diffuse = vec4(1.0, 1.0, 1.0, 1.0) * in_normal.dot(in_light_vec).max(0.0);
39+
40+
*out_frag_color = (i_ambient + i_diffuse) * vec4(color.x, color.y, color.z, 1.0);
41+
}
2.43 KB
Binary file not shown.
7.87 KB
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "displacement-displacement"
3+
version = "0.1.0"
4+
edition.workspace = true
5+
6+
[dependencies]
7+
spirv-std = { workspace = true }
8+
9+
[lib]
10+
crate-type = ["dylib"]
11+
12+
[package.metadata.rust-gpu.build]
13+
capabilities = ["Tessellation"]
Binary file not shown.

0 commit comments

Comments
 (0)