forked from SaschaWillems/Vulkan
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
51 lines (47 loc) · 1.24 KB
/
lib.rs
File metadata and controls
51 lines (47 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#![cfg_attr(target_arch = "spirv", no_std)]
#![allow(clippy::missing_safety_doc)]
use spirv_std::image::SampledImage;
use spirv_std::{
glam::{vec4, Vec2, Vec4},
spirv, Image,
};
// Push constants structure for UI overlay
#[repr(C)]
#[derive(Copy, Clone)]
pub struct PushConstants {
pub scale: Vec2,
pub translate: Vec2,
}
// UI overlay vertex shader with push constants
#[spirv(vertex)]
pub fn main_vs(
in_pos: Vec2,
in_uv: Vec2,
in_color: Vec4,
#[spirv(push_constant)] push_constants: &PushConstants,
#[spirv(position)] out_position: &mut Vec4,
out_uv: &mut Vec2,
out_color: &mut Vec4,
) {
*out_uv = in_uv;
*out_color = in_color;
*out_position = vec4(
in_pos.x * push_constants.scale.x + push_constants.translate.x,
in_pos.y * push_constants.scale.y + push_constants.translate.y,
0.0,
1.0,
);
}
// UI overlay fragment shader with texture sampling
#[spirv(fragment)]
pub fn main_fs(
in_uv: Vec2,
in_color: Vec4,
#[spirv(descriptor_set = 0, binding = 0)] font_sampler: &SampledImage<
Image!(2D, type=f32, sampled),
>,
out_frag_color: &mut Vec4,
) {
let tex_color = font_sampler.sample(in_uv);
*out_frag_color = in_color * tex_color;
}