@@ -7,63 +7,63 @@ pub mod shared_data;
7
7
8
8
#[ inline( always) ]
9
9
pub fn fs ( constants : & ShaderConstants , mut frag_coord : Vec2 ) -> Vec4 {
10
- let resolution = vec3 (
11
- constants. width as f32 as f32 ,
12
- constants. height as f32 as f32 ,
13
- 0.0 ,
14
- ) ;
15
- let time = constants. time ;
16
- let mut mouse = vec4 (
17
- constants. drag_end_x as f32 ,
18
- constants. drag_end_y as f32 ,
19
- constants. drag_start_x as f32 ,
20
- constants. drag_start_y as f32 ,
21
- ) ;
22
- if mouse != Vec4 :: ZERO {
23
- mouse. y = resolution. y - mouse. y ;
24
- mouse. w = resolution. y - mouse. w ;
25
- }
26
- if !( constants. mouse_left_pressed == 1 ) {
27
- mouse. z *= -1.0 ;
28
- }
29
- if !( constants. mouse_left_clicked == 1 ) {
30
- mouse. w *= -1.0 ;
31
- }
10
+ let resolution = vec3 (
11
+ constants. width as f32 as f32 ,
12
+ constants. height as f32 as f32 ,
13
+ 0.0 ,
14
+ ) ;
15
+ let time = constants. time ;
16
+ let mut mouse = vec4 (
17
+ constants. drag_end_x as f32 ,
18
+ constants. drag_end_y as f32 ,
19
+ constants. drag_start_x as f32 ,
20
+ constants. drag_start_y as f32 ,
21
+ ) ;
22
+ if mouse != Vec4 :: ZERO {
23
+ mouse. y = resolution. y - mouse. y ;
24
+ mouse. w = resolution. y - mouse. w ;
25
+ }
26
+ if !( constants. mouse_left_pressed == 1 ) {
27
+ mouse. z *= -1.0 ;
28
+ }
29
+ if !( constants. mouse_left_clicked == 1 ) {
30
+ mouse. w *= -1.0 ;
31
+ }
32
32
33
- frag_coord. x %= resolution. x ;
34
- frag_coord. y = resolution. y - frag_coord. y % resolution. y ;
33
+ frag_coord. x %= resolution. x ;
34
+ frag_coord. y = resolution. y - frag_coord. y % resolution. y ;
35
35
36
- let shader_input = ShaderInput {
37
- resolution,
38
- time,
39
- frag_coord,
40
- mouse,
41
- } ;
42
- let mut shader_output = & mut ShaderResult { color : Vec4 :: ZERO } ;
43
- shaders:: render_shader ( constants. shader_to_show , & shader_input, & mut shader_output) ;
44
- let color = shader_output. color ;
45
- Vec3 :: powf ( color. truncate ( ) , 2.2 ) . extend ( color. w )
36
+ let shader_input = ShaderInput {
37
+ resolution,
38
+ time,
39
+ frag_coord,
40
+ mouse,
41
+ } ;
42
+ let mut shader_output = & mut ShaderResult { color : Vec4 :: ZERO } ;
43
+ shaders:: render_shader ( constants. shader_to_show , & shader_input, & mut shader_output) ;
44
+ let color = shader_output. color ;
45
+ Vec3 :: powf ( color. truncate ( ) , 2.2 ) . extend ( color. w )
46
46
}
47
47
48
48
#[ allow( unused_attributes) ]
49
49
#[ spirv( fragment) ]
50
50
pub fn main_fs (
51
- #[ spirv( frag_coord) ] in_frag_coord : Vec4 ,
52
- #[ spirv( push_constant) ] constants : & ShaderConstants ,
53
- output : & mut Vec4 ,
51
+ #[ spirv( frag_coord) ] in_frag_coord : Vec4 ,
52
+ #[ spirv( push_constant) ] constants : & ShaderConstants ,
53
+ output : & mut Vec4 ,
54
54
) {
55
- let frag_coord = vec2 ( in_frag_coord. x , in_frag_coord. y ) ;
56
- let color = fs ( constants, frag_coord) ;
57
- * output = color;
55
+ let frag_coord = vec2 ( in_frag_coord. x , in_frag_coord. y ) ;
56
+ let color = fs ( constants, frag_coord) ;
57
+ * output = color;
58
58
}
59
59
60
60
#[ allow( unused_attributes) ]
61
61
#[ spirv( vertex) ]
62
62
pub fn main_vs ( #[ spirv( vertex_index) ] vert_idx : i32 , #[ spirv( position) ] builtin_pos : & mut Vec4 ) {
63
- // Create a "full screen triangle" by mapping the vertex index.
64
- // ported from https://www.saschawillems.de/blog/2016/08/13/vulkan-tutorial-on-rendering-a-fullscreen-quad-without-buffers/
65
- let uv = vec2 ( ( ( vert_idx << 1 ) & 2 ) as f32 , ( vert_idx & 2 ) as f32 ) ;
66
- let pos = 2.0 * uv - Vec2 :: ONE ;
63
+ // Create a "full screen triangle" by mapping the vertex index.
64
+ // ported from https://www.saschawillems.de/blog/2016/08/13/vulkan-tutorial-on-rendering-a-fullscreen-quad-without-buffers/
65
+ let uv = vec2 ( ( ( vert_idx << 1 ) & 2 ) as f32 , ( vert_idx & 2 ) as f32 ) ;
66
+ let pos = 2.0 * uv - Vec2 :: ONE ;
67
67
68
- * builtin_pos = pos. extend ( 0.0 ) . extend ( 1.0 ) ;
68
+ * builtin_pos = pos. extend ( 0.0 ) . extend ( 1.0 ) ;
69
69
}
0 commit comments