-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathreset-2d.py
executable file
·37 lines (28 loc) · 1.17 KB
/
reset-2d.py
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
TWO2_SHADER_STARTER = """/// ***************************** ///
/// THIS IS THE DEFAULT 2D SHADER ///
/// You can always get back to this with `python3 scripts/reset-2d.py` ///
/// ***************************** ///
#import bevy_sprite::mesh2d_view_bindings::globals
#import shadplay::shader_utils::common::{NEG_HALF_PI, shader_toy_default, rotate2D, TWO_PI}
#import bevy_render::view::View
#import bevy_sprite::mesh2d_vertex_output::VertexOutput
@group(0) @binding(0) var<uniform> view: View;
const SPEED:f32 = 1.0;
@fragment
fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
// ensure our uv coords match shadertoy/the-lil-book-of-shaders
var uv = in.uv;
uv = (uv * 2.0) - 1.0;
let resolution = view.viewport.zw;
let t = globals.time * SPEED;
uv.x *= resolution.x / resolution.y;
uv *= rotate2D(NEG_HALF_PI);
return vec4f(shader_toy_default(t, uv), 0.3);
}
"""
# Define the file path
file_path = "./assets/shaders/myshader_2d.wgsl"
# Open the file in write mode and replace its contents
with open(file_path, "w") as file:
file.write(TWO2_SHADER_STARTER)
print(f"Content in {file_path} has been replaced with the provided shader code.")