├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSES ├── README.md ├── assets ├── fonts │ └── poly.ttf ├── shaders │ ├── clouds │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ ├── dancing_tree │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ ├── debugger │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ ├── dry_ice │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ ├── fire │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ ├── fire2 │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ ├── fluid │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ ├── image_load.wgsl │ ├── interactive_fluid_simulation │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ ├── liquid │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ ├── liquid_toy │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ ├── love_and_domination │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ ├── minimal │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ ├── mip_fluid │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ ├── mixing_liquid │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ ├── molecular_dynamics │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ ├── paint │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ ├── common.wgsl │ │ └── image.wgsl │ ├── paint2 │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ ├── common.wgsl │ │ ├── image.wgsl │ │ └── image2.wgsl │ ├── paint_streams │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ ├── paint_streams2 │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ ├── preludes │ │ └── image_prelude │ ├── protean_clouds │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ ├── seascape │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ ├── simpler_particles │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ ├── simplest_detailed_fluid │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ ├── soul │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ └── sunset │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl └── textures │ ├── blue_noise.png │ ├── font.png │ └── rgba_noise_256.png ├── bin ├── assets │ └── shaders │ │ ├── image_load.wgsl │ │ ├── interactive_fluid_simulation │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ │ ├── liquid │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ │ ├── minimal │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ │ ├── mixing_liquid │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ │ ├── paint │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ ├── common.wgsl │ │ └── image.wgsl │ │ ├── paint2 │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ ├── common.wgsl │ │ ├── image.wgsl │ │ └── image2.wgsl │ │ ├── paint_streams │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl │ │ ├── preludes │ │ └── image_prelude │ │ └── simplest_detailed_fluid │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ └── image.wgsl ├── examples │ ├── minimal │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ ├── common.wgsl │ │ └── image.wgsl │ ├── mixing_liquid │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ ├── common.wgsl │ │ └── image.wgsl │ ├── paint │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ ├── common.wgsl │ │ └── image.wgsl │ └── paint_streams │ │ ├── buffer_a.wgsl │ │ ├── buffer_b.wgsl │ │ ├── buffer_c.wgsl │ │ ├── buffer_d.wgsl │ │ ├── common.wgsl │ │ └── image.wgsl ├── main.rs ├── templates │ ├── buffer_a_template.wgsl │ ├── buffer_b_template.wgsl │ ├── buffer_c_template.wgsl │ ├── buffer_d_template.wgsl │ ├── common.wgsl │ ├── common_prelude.wgsl │ ├── image.wgsl │ └── image_template.wgsl ├── test_renderdoc ├── test_renderdoc.d ├── texture_a.rs ├── texture_b.rs ├── texture_c.rs └── texture_d.rs ├── examples ├── debugger │ ├── buffer_a.wgsl │ ├── buffer_b.wgsl │ ├── buffer_c.wgsl │ ├── buffer_d.wgsl │ ├── common.wgsl │ └── image.wgsl ├── dry_ice │ ├── buffer_a.wgsl │ ├── buffer_b.wgsl │ ├── buffer_c.wgsl │ ├── buffer_d.wgsl │ ├── common.wgsl │ ├── dry_ice.rs │ └── image.wgsl ├── fire │ ├── buffer_a.wgsl │ ├── buffer_b.wgsl │ ├── buffer_c.wgsl │ ├── buffer_d.wgsl │ ├── common.wgsl │ └── image.wgsl ├── fire2 │ ├── buffer_a.wgsl │ ├── buffer_b.wgsl │ ├── buffer_c.wgsl │ ├── buffer_d.wgsl │ ├── common.wgsl │ ├── fire2.rs │ └── image.wgsl ├── fluid │ ├── buffer_a.wgsl │ ├── buffer_b.wgsl │ ├── buffer_c.wgsl │ ├── buffer_d.wgsl │ ├── common.wgsl │ ├── fluid.rs │ └── image.wgsl ├── liquid_toy │ ├── buffer_a.wgsl │ ├── buffer_b.wgsl │ ├── buffer_c.wgsl │ ├── buffer_d.wgsl │ ├── common.wgsl │ ├── image.wgsl │ └── liquid_toy.rs ├── minimal │ ├── buffer_a.wgsl │ ├── buffer_b.wgsl │ ├── buffer_c.wgsl │ ├── buffer_d.wgsl │ ├── common.wgsl │ ├── image.wgsl │ └── minimal.rs ├── paint │ ├── buffer_a.wgsl │ ├── buffer_b.wgsl │ ├── buffer_c.wgsl │ ├── buffer_d.wgsl │ ├── common.wgsl │ ├── image.wgsl │ └── paint.rs ├── paint_streams │ ├── buffer_a.wgsl │ ├── buffer_b.wgsl │ ├── buffer_c.wgsl │ ├── buffer_d.wgsl │ ├── common.wgsl │ ├── image.wgsl │ └── paint_streams.rs ├── protean_clouds │ ├── buffer_a.wgsl │ ├── buffer_b.wgsl │ ├── buffer_c.wgsl │ ├── buffer_d.wgsl │ ├── common.wgsl │ ├── image.wgsl │ └── protean_clouds.rs ├── seascape │ ├── buffer_a.wgsl │ ├── buffer_b.wgsl │ ├── buffer_c.wgsl │ ├── buffer_d.wgsl │ ├── common.wgsl │ ├── image.wgsl │ └── seascape.rs ├── simpler_particles │ ├── buffer_a.wgsl │ ├── buffer_b.wgsl │ ├── buffer_c.wgsl │ ├── buffer_d.wgsl │ ├── common.wgsl │ ├── fps.rs │ ├── image.wgsl │ └── simpler_particles.rs ├── soul │ ├── buffer_a.wgsl │ ├── buffer_b.wgsl │ ├── buffer_c.wgsl │ ├── buffer_d.wgsl │ ├── common.wgsl │ ├── image.wgsl │ └── soul.rs └── sunset │ ├── buffer_a.wgsl │ ├── buffer_b.wgsl │ ├── buffer_c.wgsl │ ├── buffer_d.wgsl │ ├── common.wgsl │ ├── image.wgsl │ └── sunset.rs ├── showcase.gif └── src ├── lib.rs ├── templates ├── buffer_a_template.wgsl ├── buffer_b_template.wgsl ├── buffer_c_template.wgsl ├── buffer_d_template.wgsl ├── common.wgsl ├── common_prelude.wgsl ├── debugger.wgsl ├── image.wgsl └── image_template.wgsl ├── texture_a.rs ├── texture_b.rs ├── texture_c.rs └── texture_d.rs /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Generated by Cargo 3 | # will have compiled files and executables 4 | /target/ 5 | 6 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 7 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 8 | Cargo.lock 9 | 10 | # These are backup files generated by rustfmt 11 | **/*.rs.bk 12 | 13 | .cargo/config.toml -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "bevy_shadertoy_wgsl" 3 | version = "0.1.0" 4 | edition = "2021" 5 | authors = ["Eliot Bolduc"] 6 | 7 | [dependencies] 8 | bytemuck = "1.5" 9 | rand = "0.8" 10 | rand_pcg = "0.3" 11 | serde = { version = "1.0", features = ["derive"] } 12 | anyhow = "1.0" 13 | ron = "0.7" 14 | bitflags = "1.3" 15 | bevy = "0.8" 16 | crevice = "0.11" 17 | 18 | 19 | 20 | [[bin]] 21 | edition = "2021" 22 | name = "bevy_shadertoy_wgsl" 23 | path = "src/main.rs" 24 | 25 | # cargo build --release --target wasm32-unknown-unknown 26 | # wasm-bindgen --out-name wasm_shadertoy --out-dir wasm --target web target/wasm32-unknown-unknown/release/bevy_shadertoy_wgsl.wasm 27 | [[example]] 28 | name = "simpler_particles" 29 | path = "examples/simpler_particles/simpler_particles.rs" 30 | 31 | [[example]] 32 | name = "liquid_toy" 33 | path = "examples/liquid_toy/liquid_toy.rs" 34 | 35 | [[example]] 36 | name = "soul" 37 | path = "examples/soul/soul.rs" 38 | 39 | 40 | [[example]] 41 | name = "paint_streams" 42 | path = "examples/paint_streams/paint_streams.rs" 43 | 44 | [[example]] 45 | name = "minimal" 46 | path = "examples/minimal/minimal.rs" 47 | 48 | [[example]] 49 | name = "paint" 50 | path = "examples/paint/paint.rs" 51 | 52 | [[example]] 53 | name = "protean_clouds" 54 | path = "examples/protean_clouds/protean_clouds.rs" 55 | 56 | [[example]] 57 | name = "seascape" 58 | path = "examples/seascape/seascape.rs" 59 | 60 | [[example]] 61 | name = "fluid" 62 | path = "examples/fluid/fluid.rs" 63 | 64 | [[example]] 65 | name = "fire2" 66 | path = "examples/fire2/fire2.rs" 67 | 68 | [[example]] 69 | name = "fire" 70 | path = "examples/fire/fire.rs" 71 | 72 | [[example]] 73 | name = "dry_ice" 74 | path = "examples/dry_ice/dry_ice.rs" 75 | 76 | [[example]] 77 | name = "sunset" 78 | path = "examples/sunset/sunset.rs" -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bevy_shadertoy_wgsl 2 | 3 | A Shadertoy clone for the Bevy game engine, where the glsl language is replaced by wgsl. 4 | 5 | 6 | Clone the repo, and for example run the following command: 7 | ``` 8 | cargo run --release --features bevy/dynamic --example paint_streams 9 | ``` 10 | ![](showcase.gif) 11 | 12 | Here is a GLSL to WGLSL converter that might be helpful: [https://eliotbo.github.io/glsl2wgsl/](https://eliotbo.github.io/glsl2wgsl/) 13 | 14 | TODO: make compatible with WASM 15 | 16 | See the LICENSES file for the individual examples. 17 | -------------------------------------------------------------------------------- /assets/fonts/poly.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliotbo/bevy_shadertoy_wgsl/e3221a81dd6f1668d7d6695f06353b373db47979/assets/fonts/poly.ttf -------------------------------------------------------------------------------- /assets/shaders/clouds/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | iChannelTime: vec4; 11 | iChannelResolution: vec4; 12 | iDate: vec4; 13 | }; 14 | 15 | [[group(0), binding(0)]] 16 | var uni: CommonUniform; 17 | 18 | [[group(0), binding(1)]] 19 | var buffer_a: texture_storage_2d; 20 | 21 | [[group(0), binding(2)]] 22 | var buffer_b: texture_storage_2d; 23 | 24 | [[group(0), binding(3)]] 25 | var buffer_c: texture_storage_2d; 26 | 27 | [[group(0), binding(4)]] 28 | var buffer_d: texture_storage_2d; 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | [[stage(compute), workgroup_size(8, 8, 1)]] 37 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 38 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 39 | let color = vec4(0.5); 40 | textureStore(buffer_a, location, color); 41 | } -------------------------------------------------------------------------------- /assets/shaders/clouds/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | iChannelTime: vec4; 11 | iChannelResolution: vec4; 12 | iDate: vec4; 13 | }; 14 | 15 | [[group(0), binding(0)]] 16 | var uni: CommonUniform; 17 | 18 | [[group(0), binding(1)]] 19 | var buffer_a: texture_storage_2d; 20 | 21 | [[group(0), binding(2)]] 22 | var buffer_b: texture_storage_2d; 23 | 24 | [[group(0), binding(3)]] 25 | var buffer_c: texture_storage_2d; 26 | 27 | [[group(0), binding(4)]] 28 | var buffer_d: texture_storage_2d; 29 | 30 | 31 | 32 | 33 | 34 | [[stage(compute), workgroup_size(8, 8, 1)]] 35 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 36 | 37 | } -------------------------------------------------------------------------------- /assets/shaders/clouds/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | iChannelTime: vec4; 11 | iChannelResolution: vec4; 12 | iDate: vec4; 13 | }; 14 | 15 | [[group(0), binding(0)]] 16 | var uni: CommonUniform; 17 | 18 | [[group(0), binding(1)]] 19 | var buffer_a: texture_storage_2d; 20 | 21 | [[group(0), binding(2)]] 22 | var buffer_b: texture_storage_2d; 23 | 24 | [[group(0), binding(3)]] 25 | var buffer_c: texture_storage_2d; 26 | 27 | [[group(0), binding(4)]] 28 | var buffer_d: texture_storage_2d; 29 | 30 | 31 | 32 | 33 | 34 | [[stage(compute), workgroup_size(8, 8, 1)]] 35 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 36 | 37 | } -------------------------------------------------------------------------------- /assets/shaders/clouds/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | iChannelTime: vec4; 11 | iChannelResolution: vec4; 12 | iDate: vec4; 13 | }; 14 | 15 | [[group(0), binding(0)]] 16 | var uni: CommonUniform; 17 | 18 | [[group(0), binding(1)]] 19 | var buffer_a: texture_storage_2d; 20 | 21 | [[group(0), binding(2)]] 22 | var buffer_b: texture_storage_2d; 23 | 24 | [[group(0), binding(3)]] 25 | var buffer_c: texture_storage_2d; 26 | 27 | [[group(0), binding(4)]] 28 | var buffer_d: texture_storage_2d; 29 | 30 | 31 | 32 | 33 | 34 | [[stage(compute), workgroup_size(8, 8, 1)]] 35 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 36 | 37 | } 38 | -------------------------------------------------------------------------------- /assets/shaders/dancing_tree/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | 8 | iMouse: vec4; 9 | iResolution: vec2; 10 | 11 | 12 | 13 | iChannelTime: vec4; 14 | iChannelResolution: vec4; 15 | iDate: vec4; 16 | }; 17 | 18 | [[group(0), binding(0)]] 19 | var uni: CommonUniform; 20 | 21 | [[group(0), binding(1)]] 22 | var buffer_a: texture_storage_2d; 23 | 24 | [[group(0), binding(2)]] 25 | var buffer_b: texture_storage_2d; 26 | 27 | [[group(0), binding(3)]] 28 | var buffer_c: texture_storage_2d; 29 | 30 | [[group(0), binding(4)]] 31 | var buffer_d: texture_storage_2d; 32 | 33 | 34 | 35 | 36 | 37 | [[stage(compute), workgroup_size(8, 8, 1)]] 38 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 39 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 40 | let color = vec4(0.5); 41 | textureStore(buffer_a, location, color); 42 | } -------------------------------------------------------------------------------- /assets/shaders/dancing_tree/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | 8 | iMouse: vec4; 9 | iResolution: vec2; 10 | 11 | 12 | 13 | iChannelTime: vec4; 14 | iChannelResolution: vec4; 15 | iDate: vec4; 16 | }; 17 | 18 | [[group(0), binding(0)]] 19 | var uni: CommonUniform; 20 | 21 | [[group(0), binding(1)]] 22 | var buffer_a: texture_storage_2d; 23 | 24 | [[group(0), binding(2)]] 25 | var buffer_b: texture_storage_2d; 26 | 27 | [[group(0), binding(3)]] 28 | var buffer_c: texture_storage_2d; 29 | 30 | [[group(0), binding(4)]] 31 | var buffer_d: texture_storage_2d; 32 | 33 | 34 | 35 | [[stage(compute), workgroup_size(8, 8, 1)]] 36 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 37 | 38 | } -------------------------------------------------------------------------------- /assets/shaders/dancing_tree/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | 8 | iMouse: vec4; 9 | iResolution: vec2; 10 | 11 | 12 | 13 | iChannelTime: vec4; 14 | iChannelResolution: vec4; 15 | iDate: vec4; 16 | }; 17 | 18 | [[group(0), binding(0)]] 19 | var uni: CommonUniform; 20 | 21 | [[group(0), binding(1)]] 22 | var buffer_a: texture_storage_2d; 23 | 24 | [[group(0), binding(2)]] 25 | var buffer_b: texture_storage_2d; 26 | 27 | [[group(0), binding(3)]] 28 | var buffer_c: texture_storage_2d; 29 | 30 | [[group(0), binding(4)]] 31 | var buffer_d: texture_storage_2d; 32 | 33 | 34 | 35 | [[stage(compute), workgroup_size(8, 8, 1)]] 36 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 37 | 38 | } -------------------------------------------------------------------------------- /assets/shaders/dancing_tree/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | 8 | iMouse: vec4; 9 | iResolution: vec2; 10 | 11 | 12 | 13 | iChannelTime: vec4; 14 | iChannelResolution: vec4; 15 | iDate: vec4; 16 | }; 17 | 18 | [[group(0), binding(0)]] 19 | var uni: CommonUniform; 20 | 21 | [[group(0), binding(1)]] 22 | var buffer_a: texture_storage_2d; 23 | 24 | [[group(0), binding(2)]] 25 | var buffer_b: texture_storage_2d; 26 | 27 | [[group(0), binding(3)]] 28 | var buffer_c: texture_storage_2d; 29 | 30 | [[group(0), binding(4)]] 31 | var buffer_d: texture_storage_2d; 32 | 33 | 34 | 35 | [[stage(compute), workgroup_size(8, 8, 1)]] 36 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 37 | 38 | } 39 | -------------------------------------------------------------------------------- /assets/shaders/debugger/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | 8 | iMouse: vec4; 9 | iResolution: vec2; 10 | 11 | 12 | 13 | iChannelTime: vec4; 14 | iChannelResolution: vec4; 15 | iDate: vec4; 16 | }; 17 | 18 | [[group(0), binding(0)]] 19 | var uni: CommonUniform; 20 | 21 | [[group(0), binding(1)]] 22 | var buffer_a: texture_storage_2d; 23 | 24 | [[group(0), binding(2)]] 25 | var buffer_b: texture_storage_2d; 26 | 27 | [[group(0), binding(3)]] 28 | var buffer_c: texture_storage_2d; 29 | 30 | [[group(0), binding(4)]] 31 | var buffer_d: texture_storage_2d; 32 | 33 | // Converts a color from sRGB gamma to linear light gamma 34 | fn toLinear(sRGB: vec4) -> vec4 { 35 | let cutoff = vec4(sRGB < vec4(0.04045)); 36 | let higher = pow((sRGB + vec4(0.055)) / vec4(1.055), vec4(2.4)); 37 | let lower = sRGB / vec4(12.92); 38 | 39 | return mix(higher, lower, cutoff); 40 | } 41 | 42 | 43 | 44 | [[stage(compute), workgroup_size(8, 8, 1)]] 45 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 46 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 47 | let color = vec4(0.5); 48 | textureStore(buffer_a, location, color); 49 | } -------------------------------------------------------------------------------- /assets/shaders/debugger/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | 8 | iMouse: vec4; 9 | iResolution: vec2; 10 | 11 | 12 | 13 | iChannelTime: vec4; 14 | iChannelResolution: vec4; 15 | iDate: vec4; 16 | }; 17 | 18 | [[group(0), binding(0)]] 19 | var uni: CommonUniform; 20 | 21 | [[group(0), binding(1)]] 22 | var buffer_a: texture_storage_2d; 23 | 24 | [[group(0), binding(2)]] 25 | var buffer_b: texture_storage_2d; 26 | 27 | [[group(0), binding(3)]] 28 | var buffer_c: texture_storage_2d; 29 | 30 | [[group(0), binding(4)]] 31 | var buffer_d: texture_storage_2d; 32 | 33 | // Converts a color from sRGB gamma to linear light gamma 34 | fn toLinear(sRGB: vec4) -> vec4 { 35 | let cutoff = vec4(sRGB < vec4(0.04045)); 36 | let higher = pow((sRGB + vec4(0.055)) / vec4(1.055), vec4(2.4)); 37 | let lower = sRGB / vec4(12.92); 38 | 39 | return mix(higher, lower, cutoff); 40 | } 41 | 42 | [[stage(compute), workgroup_size(8, 8, 1)]] 43 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 44 | 45 | } -------------------------------------------------------------------------------- /assets/shaders/debugger/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | 8 | iMouse: vec4; 9 | iResolution: vec2; 10 | 11 | 12 | 13 | iChannelTime: vec4; 14 | iChannelResolution: vec4; 15 | iDate: vec4; 16 | }; 17 | 18 | [[group(0), binding(0)]] 19 | var uni: CommonUniform; 20 | 21 | [[group(0), binding(1)]] 22 | var buffer_a: texture_storage_2d; 23 | 24 | [[group(0), binding(2)]] 25 | var buffer_b: texture_storage_2d; 26 | 27 | [[group(0), binding(3)]] 28 | var buffer_c: texture_storage_2d; 29 | 30 | [[group(0), binding(4)]] 31 | var buffer_d: texture_storage_2d; 32 | 33 | // Converts a color from sRGB gamma to linear light gamma 34 | fn toLinear(sRGB: vec4) -> vec4 { 35 | let cutoff = vec4(sRGB < vec4(0.04045)); 36 | let higher = pow((sRGB + vec4(0.055)) / vec4(1.055), vec4(2.4)); 37 | let lower = sRGB / vec4(12.92); 38 | 39 | return mix(higher, lower, cutoff); 40 | } 41 | 42 | [[stage(compute), workgroup_size(8, 8, 1)]] 43 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 44 | 45 | } -------------------------------------------------------------------------------- /assets/shaders/debugger/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | 8 | iMouse: vec4; 9 | iResolution: vec2; 10 | 11 | 12 | 13 | iChannelTime: vec4; 14 | iChannelResolution: vec4; 15 | iDate: vec4; 16 | }; 17 | 18 | [[group(0), binding(0)]] 19 | var uni: CommonUniform; 20 | 21 | [[group(0), binding(1)]] 22 | var buffer_a: texture_storage_2d; 23 | 24 | [[group(0), binding(2)]] 25 | var buffer_b: texture_storage_2d; 26 | 27 | [[group(0), binding(3)]] 28 | var buffer_c: texture_storage_2d; 29 | 30 | [[group(0), binding(4)]] 31 | var buffer_d: texture_storage_2d; 32 | 33 | // Converts a color from sRGB gamma to linear light gamma 34 | fn toLinear(sRGB: vec4) -> vec4 { 35 | let cutoff = vec4(sRGB < vec4(0.04045)); 36 | let higher = pow((sRGB + vec4(0.055)) / vec4(1.055), vec4(2.4)); 37 | let lower = sRGB / vec4(12.92); 38 | 39 | return mix(higher, lower, cutoff); 40 | } 41 | 42 | [[stage(compute), workgroup_size(8, 8, 1)]] 43 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 44 | 45 | } 46 | -------------------------------------------------------------------------------- /assets/shaders/fire/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | iChannelTime: vec4; 11 | iChannelResolution: vec4; 12 | iDate: vec4; 13 | }; 14 | 15 | [[group(0), binding(0)]] 16 | var uni: CommonUniform; 17 | 18 | [[group(0), binding(1)]] 19 | var buffer_a: texture_storage_2d; 20 | 21 | [[group(0), binding(2)]] 22 | var buffer_b: texture_storage_2d; 23 | 24 | [[group(0), binding(3)]] 25 | var buffer_c: texture_storage_2d; 26 | 27 | [[group(0), binding(4)]] 28 | var buffer_d: texture_storage_2d; 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | [[stage(compute), workgroup_size(8, 8, 1)]] 37 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 38 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 39 | let color = vec4(0.5); 40 | textureStore(buffer_a, location, color); 41 | } -------------------------------------------------------------------------------- /assets/shaders/fire/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | iChannelTime: vec4; 11 | iChannelResolution: vec4; 12 | iDate: vec4; 13 | }; 14 | 15 | [[group(0), binding(0)]] 16 | var uni: CommonUniform; 17 | 18 | [[group(0), binding(1)]] 19 | var buffer_a: texture_storage_2d; 20 | 21 | [[group(0), binding(2)]] 22 | var buffer_b: texture_storage_2d; 23 | 24 | [[group(0), binding(3)]] 25 | var buffer_c: texture_storage_2d; 26 | 27 | [[group(0), binding(4)]] 28 | var buffer_d: texture_storage_2d; 29 | 30 | 31 | 32 | 33 | 34 | [[stage(compute), workgroup_size(8, 8, 1)]] 35 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 36 | 37 | } -------------------------------------------------------------------------------- /assets/shaders/fire/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | iChannelTime: vec4; 11 | iChannelResolution: vec4; 12 | iDate: vec4; 13 | }; 14 | 15 | [[group(0), binding(0)]] 16 | var uni: CommonUniform; 17 | 18 | [[group(0), binding(1)]] 19 | var buffer_a: texture_storage_2d; 20 | 21 | [[group(0), binding(2)]] 22 | var buffer_b: texture_storage_2d; 23 | 24 | [[group(0), binding(3)]] 25 | var buffer_c: texture_storage_2d; 26 | 27 | [[group(0), binding(4)]] 28 | var buffer_d: texture_storage_2d; 29 | 30 | 31 | 32 | 33 | 34 | [[stage(compute), workgroup_size(8, 8, 1)]] 35 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 36 | 37 | } -------------------------------------------------------------------------------- /assets/shaders/fire/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | iChannelTime: vec4; 11 | iChannelResolution: vec4; 12 | iDate: vec4; 13 | }; 14 | 15 | [[group(0), binding(0)]] 16 | var uni: CommonUniform; 17 | 18 | [[group(0), binding(1)]] 19 | var buffer_a: texture_storage_2d; 20 | 21 | [[group(0), binding(2)]] 22 | var buffer_b: texture_storage_2d; 23 | 24 | [[group(0), binding(3)]] 25 | var buffer_c: texture_storage_2d; 26 | 27 | [[group(0), binding(4)]] 28 | var buffer_d: texture_storage_2d; 29 | 30 | 31 | 32 | 33 | 34 | [[stage(compute), workgroup_size(8, 8, 1)]] 35 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 36 | 37 | } 38 | -------------------------------------------------------------------------------- /assets/shaders/fire2/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | @compute @workgroup_size(8, 8, 1) 42 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 43 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 44 | let color = vec4(0.5); 45 | textureStore(buffer_a, location, color); 46 | } -------------------------------------------------------------------------------- /assets/shaders/fire2/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } -------------------------------------------------------------------------------- /assets/shaders/fire2/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } -------------------------------------------------------------------------------- /assets/shaders/fire2/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } 43 | -------------------------------------------------------------------------------- /assets/shaders/fluid/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } 43 | 44 | -------------------------------------------------------------------------------- /assets/shaders/fluid/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } 43 | 44 | -------------------------------------------------------------------------------- /assets/shaders/fluid/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | let R: vec2 = uni.iResolution.xy; 42 | let y_inverted_location = vec2(i32(invocation_id.x), i32(R.y) - i32(invocation_id.y)); 43 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 44 | 45 | var fragColor: vec4; 46 | var fragCoord = vec2(f32(location.x), f32(location.y) ); 47 | 48 | var p: vec4 = textureLoad(buffer_d, vec2(fragCoord)); 49 | if (uni.iMouse.z > 0.) { 50 | if (p.z > 0.) { 51 | fragColor = vec4(uni.iMouse.xy, p.xy); 52 | } else { 53 | fragColor = vec4(uni.iMouse.xy, uni.iMouse.xy); 54 | } 55 | } else { 56 | fragColor = vec4(-uni.iResolution.xy, -uni.iResolution.xy); 57 | } 58 | 59 | textureStore(buffer_d, location, fragColor); 60 | } 61 | 62 | 63 | -------------------------------------------------------------------------------- /assets/shaders/interactive_fluid_simulation/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | 17 | 18 | [[group(0), binding(0)]] 19 | var uni: CommonUniform; 20 | 21 | [[group(0), binding(1)]] 22 | var buffer_a: texture_storage_2d; 23 | 24 | [[stage(compute), workgroup_size(8, 8, 1)]] 25 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 26 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 27 | let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 28 | 29 | let color = vec4(0.0); 30 | 31 | textureStore(buffer_a, location, color); 32 | } 33 | 34 | 35 | [[stage(compute), workgroup_size(8, 8, 1)]] 36 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 37 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 38 | 39 | // textureStore(buffer_a, location, vec4(0.094)); 40 | 41 | if (uni.iTime > 1.0) { 42 | textureStore(buffer_a, location, vec4(0.95)); 43 | } 44 | } -------------------------------------------------------------------------------- /assets/shaders/interactive_fluid_simulation/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | 2 | struct CommonUniform { 3 | iTime: f32; 4 | iTimeDelta: f32; 5 | iFrame: i32; 6 | iSampleRate: i32; 7 | 8 | iChannelTime: vec4; 9 | iChannelResolution: vec4; 10 | iDate: vec4; 11 | 12 | iResolution: vec2; 13 | iMouse: vec2; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | [[stage(compute), workgroup_size(8, 8, 1)]] 26 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 27 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 28 | let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 29 | 30 | let color = vec4(0.0); 31 | 32 | textureStore(buffer_b, location, color); 33 | } 34 | 35 | 36 | [[stage(compute), workgroup_size(8, 8, 1)]] 37 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 38 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 39 | 40 | // textureStore(buffer_b, location, vec4(0.85)); 41 | 42 | 43 | // if (uni.iTime > 1.0) { 44 | // textureStore(buffer_b, location, vec4(0.95)); 45 | // } 46 | } -------------------------------------------------------------------------------- /assets/shaders/interactive_fluid_simulation/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | [[group(0), binding(3)]] 26 | var buffer_c: texture_storage_2d; 27 | 28 | [[stage(compute), workgroup_size(8, 8, 1)]] 29 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 30 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 31 | let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 32 | 33 | let color = vec4(0.0); 34 | 35 | textureStore(buffer_c, location, color); 36 | } 37 | 38 | 39 | [[stage(compute), workgroup_size(8, 8, 1)]] 40 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 41 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 42 | 43 | // textureStore(buffer_c, location, vec4(0.95)); 44 | 45 | // if (uni.iTime > 1.0) { 46 | // textureStore(buffer_c, location, vec4(0.95)); 47 | // } 48 | } -------------------------------------------------------------------------------- /assets/shaders/interactive_fluid_simulation/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | 17 | [[group(0), binding(0)]] 18 | var uni: CommonUniform; 19 | 20 | [[group(0), binding(1)]] 21 | var buffer_a: texture_storage_2d; 22 | 23 | [[group(0), binding(2)]] 24 | var buffer_b: texture_storage_2d; 25 | 26 | [[group(0), binding(3)]] 27 | var buffer_c: texture_storage_2d; 28 | 29 | [[group(0), binding(4)]] 30 | var buffer_d: texture_storage_2d; 31 | 32 | [[stage(compute), workgroup_size(8, 8, 1)]] 33 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 34 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 35 | 36 | let color = vec4(0.60); 37 | 38 | textureStore(buffer_d, location, color); 39 | } 40 | 41 | [[stage(compute), workgroup_size(8, 8, 1)]] 42 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 43 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 44 | 45 | // textureStore(buffer_d, location, vec4(0.7)); 46 | 47 | // let p: vec4 = texture(iChannel0, fragCoord/iResolution.xy); 48 | // if (uni.iMouse.z>0.) { 49 | // if (p.z>0.) { fragColor = vec4(uni.iMouse.xy, p.xy); 50 | // } else { fragColor = vec4(uni.iMouse.xy, uni.iMouse.xy); 51 | // } 52 | 53 | // } else { fragColor = vec4(-uni.iResolution.xy, -uni.iResolution.xy); 54 | // } 55 | 56 | 57 | if (uni.iTime > 1.0) { 58 | storageBarrier(); 59 | textureStore(buffer_d, location, vec4(0.95)); 60 | } 61 | 62 | // storageBarrier(); 63 | } 64 | 65 | // fn mainImage( fragColor: vec4, fragCoord: vec2) -> () { 66 | // let p: vec4 = texture(iChannel0, fragCoord/iResolution.xy); 67 | // if (iMouse.z>0.) { 68 | // if (p.z>0.) { fragColor = vec4(iMouse.xy, p.xy); 69 | // } else { fragColor = vec4(iMouse.xy, iMouse.xy); 70 | // } 71 | 72 | // } else { fragColor = vec4(-iResolution.xy, -iResolution.xy); 73 | // } 74 | 75 | // } -------------------------------------------------------------------------------- /assets/shaders/liquid/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | 2 | struct CommonUniform { 3 | iTime: f32; 4 | iTimeDelta: f32; 5 | iFrame: i32; 6 | iSampleRate: i32; 7 | 8 | iChannelTime: vec4; 9 | iChannelResolution: vec4; 10 | iDate: vec4; 11 | 12 | iResolution: vec2; 13 | iMouse: vec2; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | [[stage(compute), workgroup_size(8, 8, 1)]] 26 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 27 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 28 | let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 29 | 30 | let color = vec4(0.0); 31 | 32 | textureStore(buffer_b, location, color); 33 | } 34 | 35 | 36 | [[stage(compute), workgroup_size(8, 8, 1)]] 37 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 38 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 39 | 40 | // textureStore(buffer_b, location, vec4(0.85)); 41 | 42 | 43 | // if (uni.iTime > 1.0) { 44 | // textureStore(buffer_b, location, vec4(0.95)); 45 | // } 46 | } -------------------------------------------------------------------------------- /assets/shaders/liquid/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | [[group(0), binding(3)]] 26 | var buffer_c: texture_storage_2d; 27 | 28 | [[stage(compute), workgroup_size(8, 8, 1)]] 29 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 30 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 31 | let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 32 | 33 | let color = vec4(0.0); 34 | 35 | textureStore(buffer_c, location, color); 36 | } 37 | 38 | 39 | [[stage(compute), workgroup_size(8, 8, 1)]] 40 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 41 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 42 | 43 | // textureStore(buffer_c, location, vec4(0.95)); 44 | 45 | // if (uni.iTime > 1.0) { 46 | // textureStore(buffer_c, location, vec4(0.95)); 47 | // } 48 | } -------------------------------------------------------------------------------- /assets/shaders/liquid/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | 17 | [[group(0), binding(0)]] 18 | var uni: CommonUniform; 19 | 20 | [[group(0), binding(1)]] 21 | var buffer_a: texture_storage_2d; 22 | 23 | [[group(0), binding(2)]] 24 | var buffer_b: texture_storage_2d; 25 | 26 | [[group(0), binding(3)]] 27 | var buffer_c: texture_storage_2d; 28 | 29 | [[group(0), binding(4)]] 30 | var buffer_d: texture_storage_2d; 31 | 32 | [[stage(compute), workgroup_size(8, 8, 1)]] 33 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 34 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 35 | 36 | let color = vec4(0.60); 37 | 38 | textureStore(buffer_d, location, color); 39 | } 40 | 41 | [[stage(compute), workgroup_size(8, 8, 1)]] 42 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 43 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 44 | 45 | // textureStore(buffer_d, location, vec4(0.7)); 46 | 47 | if (uni.iTime > 1.0) { 48 | storageBarrier(); 49 | textureStore(buffer_d, location, vec4(0.95)); 50 | } 51 | 52 | // storageBarrier(); 53 | } -------------------------------------------------------------------------------- /assets/shaders/liquid_toy/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } -------------------------------------------------------------------------------- /assets/shaders/liquid_toy/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } -------------------------------------------------------------------------------- /assets/shaders/liquid_toy/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } 43 | -------------------------------------------------------------------------------- /assets/shaders/love_and_domination/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | [[group(0), binding(3)]] 26 | var buffer_c: texture_storage_2d; 27 | 28 | [[group(0), binding(4)]] 29 | var buffer_d: texture_storage_2d; 30 | 31 | let s2 = 30.; 32 | 33 | let BLUR_DEPTH = 25.; 34 | 35 | let SPEED = 2.; 36 | 37 | let MOUSE_SIZE = 60.; 38 | 39 | let texture_const = 255.; 40 | 41 | 42 | 43 | var R: vec2; 44 | fn A(location: vec2) -> vec4 { 45 | return textureLoad(buffer_a, vec2(location)) * texture_const; 46 | } 47 | 48 | 49 | [[stage(compute), workgroup_size(8, 8, 1)]] 50 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 51 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 52 | 53 | let U = vec2(f32(location.x), f32(location.y)); 54 | 55 | 56 | // fn mainImage( Q: vec4, U: vec2) -> () { 57 | R = uni.iResolution.xy; 58 | var Q = vec4(0.); 59 | 60 | for (var i: f32 = -BLUR_DEPTH; i <= BLUR_DEPTH; i = i + 1.) { 61 | let a: vec4 = A(U + vec2(i, 0.)); 62 | let c: vec4 = a.z * smoothStep(1., 0.5, length(U + vec2(i, 0.) - a.xy)) 63 | * vec4(f32(a.w == 0.), f32(a.w == 1.), f32(a.w == 2.), 0.); 64 | Q = Q + (c * sqrt(s2) / s2 * exp(-i * i * 0.5 / s2)); 65 | 66 | } 67 | 68 | textureStore(buffer_b, location, Q / texture_const); 69 | 70 | // Q = textureLoad(buffer_a, vec2(location)); 71 | // textureStore(buffer_b, location, Q); 72 | } 73 | 74 | -------------------------------------------------------------------------------- /assets/shaders/love_and_domination/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | [[group(0), binding(3)]] 26 | var buffer_c: texture_storage_2d; 27 | 28 | [[group(0), binding(4)]] 29 | var buffer_d: texture_storage_2d; 30 | 31 | let s2 = 30.; 32 | 33 | let BLUR_DEPTH = 25.; 34 | 35 | let SPEED = 2.; 36 | 37 | let MOUSE_SIZE = 60.; 38 | 39 | let texture_const = 255.; 40 | 41 | 42 | 43 | var R: vec2; 44 | // fn A(location: vec2) -> vec4 { 45 | // return textureLoad(buffer_a, vec2(location)) * texture_const; 46 | // } 47 | 48 | fn B(location: vec2)-> vec4 { 49 | return textureLoad(buffer_b, vec2(location)) * texture_const; 50 | } 51 | 52 | fn C(location: vec2) -> vec4 { 53 | return textureLoad(buffer_c, vec2(location)) * texture_const; 54 | } 55 | 56 | 57 | 58 | [[stage(compute), workgroup_size(8, 8, 1)]] 59 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 60 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 61 | // } 62 | 63 | // fn mainImage( Q: vec4, U: vec2) -> () { 64 | 65 | let U = vec2(f32(location.x), f32(location.y)); 66 | R = uni.iResolution.xy; 67 | var Q = vec4(0.); 68 | for (var i: f32 = -BLUR_DEPTH; i <= BLUR_DEPTH; i = i + 1.) { 69 | let c: vec4 = B(U + vec2(0., i)); 70 | Q = Q + (2. * c * sqrt(s2) / s2 * exp(-i * i * 0.5 / s2)); 71 | 72 | } 73 | Q = mix(Q, C(U), 0.1); 74 | textureStore(buffer_c, location, Q / texture_const); 75 | 76 | 77 | // Q = textureLoad(buffer_b, vec2(location)); 78 | // textureStore(buffer_c, location, Q); 79 | 80 | 81 | } 82 | 83 | -------------------------------------------------------------------------------- /assets/shaders/love_and_domination/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | [[group(0), binding(3)]] 26 | var buffer_c: texture_storage_2d; 27 | 28 | [[group(0), binding(4)]] 29 | var buffer_d: texture_storage_2d; 30 | 31 | let s2 = 30.; 32 | 33 | let BLUR_DEPTH = 25.; 34 | 35 | let SPEED = 2.; 36 | 37 | let MOUSE_SIZE = 60.; 38 | 39 | let texture_const = 255.; 40 | 41 | 42 | 43 | var R: vec2; 44 | fn A(location: vec2) -> vec4 { 45 | return textureLoad(buffer_a, vec2(location)) * texture_const; 46 | } 47 | 48 | // fn B(location: vec2)-> vec4 { 49 | // return textureLoad(buffer_b, vec2(location)) * texture_const; 50 | // } 51 | 52 | fn C(location: vec2) -> vec4 { 53 | return textureLoad(buffer_c, vec2(location)) * texture_const; 54 | } 55 | 56 | [[stage(compute), workgroup_size(8, 8, 1)]] 57 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 58 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 59 | let U = vec2(f32(location.x), f32(location.y)); 60 | // } 61 | 62 | // fn mainImage( Q: vec4, U: vec2) -> () { 63 | R = uni.iResolution.xy; 64 | let c: vec4 = C(U); 65 | let n: vec4 = C(U + vec2(0., 1.)); 66 | let e: vec4 = C(U + vec2(1., 0.)); 67 | let s: vec4 = C(U + vec2(0., -1.)); 68 | let w: vec4 = C(U + vec2(-1., 0.)); 69 | let a: vec4 = A(U); 70 | let r: f32 = smoothStep(1., 0.5, length(U - a.xy)); 71 | 72 | let f: vec4 = 73 | r * f32(a.w == 0.) * vec4(0.8, 0.6, 0.3, 1.) 74 | + r * f32(a.w == 1.) * vec4(0.9, 0.2, 0.4, 1.) 75 | + r * f32(a.w == 2.) * vec4(0.2, 0.7, 0.9, 1.); 76 | 77 | var Q = 2. * f * (0.5 + 0.5 * (n - s + e - w)); 78 | 79 | 80 | textureStore(buffer_d, location, Q / texture_const); 81 | 82 | // Q = textureLoad(buffer_c, vec2(location)); 83 | // textureStore(buffer_d, location, Q); 84 | } 85 | 86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /assets/shaders/minimal/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 42 | let color = vec4(0.5); 43 | textureStore(buffer_a, location, color); 44 | } -------------------------------------------------------------------------------- /assets/shaders/minimal/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } -------------------------------------------------------------------------------- /assets/shaders/minimal/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } -------------------------------------------------------------------------------- /assets/shaders/minimal/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } 43 | -------------------------------------------------------------------------------- /assets/shaders/minimal/image.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | @group(0) @binding(5) 38 | var texture: texture_storage_2d; 39 | 40 | // [[group(0), binding(6)]] 41 | // var font_texture: texture_storage_2d; 42 | 43 | @group(0) @binding(6) 44 | var font_texture: texture_2d; 45 | 46 | @group(0) @binding(7) 47 | var font_texture_sampler: sampler; 48 | 49 | @group(0) @binding(8) 50 | var rgba_noise_256_texture: texture_2d; 51 | 52 | @group(0) @binding(9) 53 | var rgba_noise_256_texture_sampler: sampler; 54 | 55 | @group(0) @binding(10) 56 | var blue_noise_texture: texture_2d; 57 | 58 | @group(0) @binding(11) 59 | var blue_noise_texture_sampler: sampler; 60 | 61 | 62 | 63 | 64 | 65 | 66 | // displays a gray screen by setting the color in buffer_a.wglsl and loading buffer_a 67 | // here 68 | 69 | @compute @workgroup_size(8, 8, 1) 70 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 71 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 72 | 73 | var O: vec4 = textureLoad(buffer_a, location); 74 | textureStore(texture, location, O); 75 | } -------------------------------------------------------------------------------- /assets/shaders/paint/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } -------------------------------------------------------------------------------- /assets/shaders/paint/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } -------------------------------------------------------------------------------- /assets/shaders/paint/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } 43 | -------------------------------------------------------------------------------- /assets/shaders/paint/common.wgsl: -------------------------------------------------------------------------------- 1 | // unused 2 | 3 | #define_import_path bevy_shadertoy_wgsl::assets::shaders::common 4 | 5 | struct CommonUniform { 6 | iTime: f32; 7 | iTimeDelta: f32; 8 | iFrame: f32; 9 | iSampleRate: f32; 10 | 11 | iMouse: vec4; 12 | iResolution: vec2; 13 | 14 | 15 | iChannelTime: vec4; 16 | iChannelResolution: vec4; 17 | iDate: vec4; 18 | }; -------------------------------------------------------------------------------- /assets/shaders/paint/image.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | @group(0) @binding(5) 38 | var texture: texture_storage_2d; 39 | 40 | // [[group(0), binding(6)]] 41 | // var font_texture: texture_storage_2d; 42 | 43 | @group(0) @binding(6) 44 | var font_texture: texture_2d; 45 | 46 | @group(0) @binding(7) 47 | var font_texture_sampler: sampler; 48 | 49 | @group(0) @binding(8) 50 | var rgba_noise_256_texture: texture_2d; 51 | 52 | @group(0) @binding(9) 53 | var rgba_noise_256_texture_sampler: sampler; 54 | 55 | @group(0) @binding(10) 56 | var blue_noise_texture: texture_2d; 57 | 58 | @group(0) @binding(11) 59 | var blue_noise_texture_sampler: sampler; 60 | 61 | 62 | 63 | 64 | 65 | 66 | @compute @workgroup_size(8, 8, 1) 67 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 68 | let R: vec2 = uni.iResolution.xy; 69 | let y_inverted_location = vec2(i32(invocation_id.x), i32(R.y) - i32(invocation_id.y)); 70 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 71 | 72 | // let location2 = vec2(i32(R.x) - i32(invocation_id.x), i32(invocation_id.y)); 73 | 74 | var alive = true; 75 | 76 | var q: f32; 77 | if (true) { 78 | q = 1.; 79 | } else { 80 | q = 4.; 81 | }; 82 | 83 | var O: vec4 = mix(textureLoad(buffer_a, location),vec4(0.5), 0.1); 84 | 85 | // var O: vec4 = vec4(0.5); 86 | 87 | textureStore(texture, y_inverted_location, O); 88 | } -------------------------------------------------------------------------------- /assets/shaders/paint2/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | 26 | 27 | [[stage(compute), workgroup_size(8, 8, 1)]] 28 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 29 | 30 | } -------------------------------------------------------------------------------- /assets/shaders/paint2/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | [[stage(compute), workgroup_size(8, 8, 1)]] 2 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /assets/shaders/paint2/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | [[stage(compute), workgroup_size(8, 8, 1)]] 2 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /assets/shaders/paint2/common.wgsl: -------------------------------------------------------------------------------- 1 | // unused 2 | 3 | #define_import_path bevy_shadertoy_wgsl::assets::shaders::common 4 | 5 | struct CommonUniform { 6 | iTime: f32; 7 | iTimeDelta: f32; 8 | iFrame: f32; 9 | iSampleRate: f32; 10 | 11 | iMouse: vec4; 12 | iResolution: vec2; 13 | 14 | 15 | iChannelTime: vec4; 16 | iChannelResolution: vec4; 17 | iDate: vec4; 18 | }; -------------------------------------------------------------------------------- /assets/shaders/paint2/image.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | [[group(0), binding(3)]] 26 | var buffer_c: texture_storage_2d; 27 | 28 | [[group(0), binding(4)]] 29 | var buffer_d: texture_storage_2d; 30 | 31 | [[group(0), binding(5)]] 32 | var texture: texture_storage_2d; 33 | 34 | // [[stage(compute), workgroup_size(8, 8, 1)]] 35 | // fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 36 | // let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 37 | // let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 38 | 39 | // let color = vec4(f32(0)); 40 | // textureStore(texture, location, color); 41 | // } 42 | 43 | 44 | [[stage(compute), workgroup_size(8, 8, 1)]] 45 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 46 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 47 | 48 | var alive = true; 49 | 50 | var O: vec4 = textureLoad(buffer_a, location); 51 | 52 | textureStore(texture, location, O); 53 | } -------------------------------------------------------------------------------- /assets/shaders/paint2/image2.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: i32; 5 | iSampleRate: i32; 6 | 7 | iChannelTime: vec4; 8 | iChannelResolution: vec4; 9 | iDate: vec4; 10 | 11 | iResolution: vec2; 12 | iMouse: vec2; 13 | }; 14 | 15 | [[group(0), binding(0)]] 16 | var uni: CommonUniform; 17 | 18 | [[group(0), binding(1)]] 19 | var buffer_a: texture_storage_2d; 20 | 21 | [[group(0), binding(2)]] 22 | var buffer_b: texture_storage_2d; 23 | 24 | [[group(0), binding(3)]] 25 | var buffer_c: texture_storage_2d; 26 | 27 | [[group(0), binding(4)]] 28 | var buffer_d: texture_storage_2d; 29 | 30 | [[group(0), binding(5)]] 31 | var texture: texture_storage_2d; 32 | 33 | [[stage(compute), workgroup_size(8, 8, 1)]] 34 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 35 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 36 | let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 37 | 38 | let color = vec4(f32(0)); 39 | textureStore(texture, location, color); 40 | } 41 | 42 | 43 | 44 | 45 | fn hash(value: u32) -> u32 { 46 | var state = value; 47 | state = state ^ 2747636419u; 48 | state = state * 2654435769u; 49 | state = state ^ state >> 16u; 50 | state = state * 2654435769u; 51 | state = state ^ state >> 16u; 52 | state = state * 2654435769u; 53 | return state; 54 | } 55 | fn randomFloat(value: u32) -> f32 { 56 | return f32(hash(value)) / 4294967295.0; 57 | } 58 | 59 | 60 | 61 | [[stage(compute), workgroup_size(8, 8, 1)]] 62 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 63 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 64 | 65 | var alive = true; 66 | 67 | var O: vec4 = textureLoad(buffer_a, location); 68 | // let color = vec4(O.x, 0.1, 0.12, 1.0); 69 | 70 | // storageBarrier(); 71 | 72 | // textureStore(texture, location, vec4(color)); 73 | textureStore(texture, location, O); 74 | } 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /assets/shaders/preludes/image_prelude: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iResolution: vec2; 8 | iMouse: vec2; 9 | 10 | iChannelTime: vec4; 11 | iChannelResolution: vec4; 12 | iDate: vec4; // change to vec4 when possible 13 | }; 14 | 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | [[group(0), binding(3)]] 26 | var buffer_c: texture_storage_2d; 27 | 28 | [[group(0), binding(4)]] 29 | var buffer_d: texture_storage_2d; 30 | 31 | [[group(0), binding(5)]] 32 | var texture: texture_storage_2d; 33 | 34 | {{IMAGE_CODE}} 35 | -------------------------------------------------------------------------------- /assets/shaders/protean_clouds/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 42 | 43 | } -------------------------------------------------------------------------------- /assets/shaders/protean_clouds/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } -------------------------------------------------------------------------------- /assets/shaders/protean_clouds/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } -------------------------------------------------------------------------------- /assets/shaders/protean_clouds/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } 43 | -------------------------------------------------------------------------------- /assets/shaders/seascape/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | 40 | @compute @workgroup_size(8, 8, 1) 41 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 42 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 43 | let color = vec4(0.5); 44 | textureStore(buffer_a, location, color); 45 | } -------------------------------------------------------------------------------- /assets/shaders/seascape/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } -------------------------------------------------------------------------------- /assets/shaders/seascape/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } -------------------------------------------------------------------------------- /assets/shaders/seascape/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } 43 | -------------------------------------------------------------------------------- /assets/shaders/simplest_detailed_fluid/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | 17 | 18 | [[group(0), binding(0)]] 19 | var uni: CommonUniform; 20 | 21 | [[group(0), binding(1)]] 22 | var buffer_a: texture_storage_2d; 23 | 24 | [[stage(compute), workgroup_size(8, 8, 1)]] 25 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 26 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 27 | let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 28 | 29 | let color = vec4(0.0); 30 | 31 | 32 | textureStore(buffer_a, location, color); 33 | } 34 | 35 | // https://www.shadertoy.com/view/7t3SDf 36 | 37 | fn t(i: vec2, location: vec2) -> vec4 { 38 | let O: vec4 = textureLoad(buffer_a, i + location ); 39 | return O; 40 | } 41 | 42 | [[stage(compute), workgroup_size(8, 8, 1)]] 43 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 44 | var location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 45 | // location = location + vec2(10); 46 | 47 | 48 | var r: vec4 = vec4(0.); 49 | 50 | for (var i: vec2 = vec2(-7); i.x < 7; i.x = i.x + 1 ) { 51 | 52 | for (i.y = -7; i.y < 7; i.y = i.y + 1 ) { 53 | 54 | let ii = i + 1; 55 | let a = 0; 56 | 57 | let v: vec2 = t(ii , location + a ).xy; 58 | let what = t(ii, location + a).z ; 59 | let fi = vec2(ii); 60 | 61 | r = r + ( what 62 | * exp(-dot(v+fi, v+fi)) / 3.14 63 | * vec4(mix(v+v+fi , v, t(ii, location + a ).z), 1., 1.) ); 64 | } 65 | } 66 | 67 | r.x = r.x / (r.z+0.000001); 68 | r.y = r.y / (r.z+0.000001); 69 | 70 | if (i32(uni.iFrame) % 500 == 1) { 71 | let u = vec2(location +0) ; 72 | let m: vec2 = 4.*u/vec2(uni.iResolution.xy) - 2.; 73 | r = r + (vec4(m, 1., 0.)*exp(-dot(m, m))); 74 | 75 | } 76 | 77 | textureStore(buffer_a, location , r); 78 | } 79 | 80 | -------------------------------------------------------------------------------- /assets/shaders/simplest_detailed_fluid/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | 17 | [[group(0), binding(0)]] 18 | var uni: CommonUniform; 19 | 20 | [[group(0), binding(1)]] 21 | var buffer_a: texture_storage_2d; 22 | 23 | [[group(0), binding(2)]] 24 | var buffer_b: texture_storage_2d; 25 | 26 | [[stage(compute), workgroup_size(8, 8, 1)]] 27 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 28 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 29 | let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 30 | 31 | let color = vec4(0.0); 32 | 33 | textureStore(buffer_b, location, color); 34 | } 35 | 36 | 37 | [[stage(compute), workgroup_size(8, 8, 1)]] 38 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 39 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 40 | 41 | // textureStore(buffer_b, location, vec4(0.85)); 42 | 43 | 44 | // if (uni.iTime > 1.0) { 45 | // textureStore(buffer_b, location, vec4(0.95)); 46 | // } 47 | } -------------------------------------------------------------------------------- /assets/shaders/simplest_detailed_fluid/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | 17 | [[group(0), binding(0)]] 18 | var uni: CommonUniform; 19 | 20 | [[group(0), binding(1)]] 21 | var buffer_a: texture_storage_2d; 22 | 23 | [[group(0), binding(2)]] 24 | var buffer_b: texture_storage_2d; 25 | 26 | [[group(0), binding(3)]] 27 | var buffer_c: texture_storage_2d; 28 | 29 | [[stage(compute), workgroup_size(8, 8, 1)]] 30 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 31 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 32 | let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 33 | 34 | let color = vec4(0.0); 35 | 36 | textureStore(buffer_c, location, color); 37 | } 38 | 39 | 40 | [[stage(compute), workgroup_size(8, 8, 1)]] 41 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 42 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 43 | 44 | // textureStore(buffer_c, location, vec4(0.95)); 45 | 46 | // if (uni.iTime > 1.0) { 47 | // textureStore(buffer_c, location, vec4(0.95)); 48 | // } 49 | } -------------------------------------------------------------------------------- /assets/shaders/simplest_detailed_fluid/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | 17 | [[group(0), binding(0)]] 18 | var uni: CommonUniform; 19 | 20 | [[group(0), binding(1)]] 21 | var buffer_a: texture_storage_2d; 22 | 23 | [[group(0), binding(2)]] 24 | var buffer_b: texture_storage_2d; 25 | 26 | [[group(0), binding(3)]] 27 | var buffer_c: texture_storage_2d; 28 | 29 | [[group(0), binding(4)]] 30 | var buffer_d: texture_storage_2d; 31 | 32 | [[stage(compute), workgroup_size(8, 8, 1)]] 33 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 34 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 35 | 36 | let color = vec4(0.60); 37 | 38 | textureStore(buffer_d, location, color); 39 | } 40 | 41 | [[stage(compute), workgroup_size(8, 8, 1)]] 42 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 43 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 44 | 45 | // textureStore(buffer_d, location, vec4(0.7)); 46 | 47 | if (uni.iTime > 1.0) { 48 | storageBarrier(); 49 | textureStore(buffer_d, location, vec4(0.95)); 50 | } 51 | 52 | // storageBarrier(); 53 | } -------------------------------------------------------------------------------- /assets/shaders/simplest_detailed_fluid/image.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | 17 | [[group(0), binding(0)]] 18 | var uni: CommonUniform; 19 | 20 | [[group(0), binding(1)]] 21 | var buffer_a: texture_storage_2d; 22 | 23 | [[group(0), binding(2)]] 24 | var buffer_b: texture_storage_2d; 25 | 26 | [[group(0), binding(3)]] 27 | var buffer_c: texture_storage_2d; 28 | 29 | [[group(0), binding(4)]] 30 | var buffer_d: texture_storage_2d; 31 | 32 | [[group(0), binding(5)]] 33 | var texture: texture_storage_2d; 34 | 35 | fn hash(value: u32) -> u32 { 36 | var state = value; 37 | state = state ^ 2747636419u; 38 | state = state * 2654435769u; 39 | state = state ^ state >> 16u; 40 | state = state * 2654435769u; 41 | state = state ^ state >> 16u; 42 | state = state * 2654435769u; 43 | return state; 44 | } 45 | fn randomFloat(value: u32) -> f32 { 46 | return f32(hash(value)) / 4294967295.0; 47 | } 48 | 49 | [[stage(compute), workgroup_size(8, 8, 1)]] 50 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 51 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 52 | let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 53 | 54 | let randomNumber = randomFloat(invocation_id.y * num_workgroups.x + invocation_id.x); 55 | let alive = randomNumber > 0.9; 56 | let color = vec4(f32(alive)); 57 | 58 | textureStore(texture, location, color); 59 | } 60 | 61 | 62 | [[stage(compute), workgroup_size(8, 8, 1)]] 63 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 64 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 65 | 66 | 67 | 68 | // var alive = true; 69 | 70 | 71 | // let value: vec4 = textureLoad(buffer_a, vec2(0,1)); 72 | // if (value.x > 0.79) { 73 | // alive = false; 74 | // } 75 | let r = 1.- textureLoad(buffer_a, location ).zzzz; 76 | 77 | storageBarrier(); 78 | textureStore(texture, location, r); 79 | 80 | 81 | // textureStore(texture, location, vec4(f32(alive))); 82 | } 83 | 84 | 85 | -------------------------------------------------------------------------------- /assets/shaders/soul/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 42 | let color = vec4(0.5); 43 | textureStore(buffer_a, location, color); 44 | } -------------------------------------------------------------------------------- /assets/shaders/soul/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } -------------------------------------------------------------------------------- /assets/shaders/soul/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } -------------------------------------------------------------------------------- /assets/shaders/soul/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | 36 | 37 | 38 | 39 | @compute @workgroup_size(8, 8, 1) 40 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 41 | 42 | } 43 | -------------------------------------------------------------------------------- /assets/shaders/sunset/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | 8 | iMouse: vec4; 9 | iResolution: vec2; 10 | 11 | 12 | 13 | iChannelTime: vec4; 14 | iChannelResolution: vec4; 15 | iDate: vec4; 16 | }; 17 | 18 | [[group(0), binding(0)]] 19 | var uni: CommonUniform; 20 | 21 | [[group(0), binding(1)]] 22 | var buffer_a: texture_storage_2d; 23 | 24 | [[group(0), binding(2)]] 25 | var buffer_b: texture_storage_2d; 26 | 27 | [[group(0), binding(3)]] 28 | var buffer_c: texture_storage_2d; 29 | 30 | [[group(0), binding(4)]] 31 | var buffer_d: texture_storage_2d; 32 | 33 | 34 | 35 | 36 | 37 | [[stage(compute), workgroup_size(8, 8, 1)]] 38 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 39 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 40 | let color = vec4(0.5); 41 | textureStore(buffer_a, location, color); 42 | } -------------------------------------------------------------------------------- /assets/shaders/sunset/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | 8 | iMouse: vec4; 9 | iResolution: vec2; 10 | 11 | 12 | 13 | iChannelTime: vec4; 14 | iChannelResolution: vec4; 15 | iDate: vec4; 16 | }; 17 | 18 | [[group(0), binding(0)]] 19 | var uni: CommonUniform; 20 | 21 | [[group(0), binding(1)]] 22 | var buffer_a: texture_storage_2d; 23 | 24 | [[group(0), binding(2)]] 25 | var buffer_b: texture_storage_2d; 26 | 27 | [[group(0), binding(3)]] 28 | var buffer_c: texture_storage_2d; 29 | 30 | [[group(0), binding(4)]] 31 | var buffer_d: texture_storage_2d; 32 | 33 | 34 | 35 | [[stage(compute), workgroup_size(8, 8, 1)]] 36 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 37 | 38 | } -------------------------------------------------------------------------------- /assets/shaders/sunset/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | 8 | iMouse: vec4; 9 | iResolution: vec2; 10 | 11 | 12 | 13 | iChannelTime: vec4; 14 | iChannelResolution: vec4; 15 | iDate: vec4; 16 | }; 17 | 18 | [[group(0), binding(0)]] 19 | var uni: CommonUniform; 20 | 21 | [[group(0), binding(1)]] 22 | var buffer_a: texture_storage_2d; 23 | 24 | [[group(0), binding(2)]] 25 | var buffer_b: texture_storage_2d; 26 | 27 | [[group(0), binding(3)]] 28 | var buffer_c: texture_storage_2d; 29 | 30 | [[group(0), binding(4)]] 31 | var buffer_d: texture_storage_2d; 32 | 33 | 34 | 35 | [[stage(compute), workgroup_size(8, 8, 1)]] 36 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 37 | 38 | } -------------------------------------------------------------------------------- /assets/shaders/sunset/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | 8 | iMouse: vec4; 9 | iResolution: vec2; 10 | 11 | 12 | 13 | iChannelTime: vec4; 14 | iChannelResolution: vec4; 15 | iDate: vec4; 16 | }; 17 | 18 | [[group(0), binding(0)]] 19 | var uni: CommonUniform; 20 | 21 | [[group(0), binding(1)]] 22 | var buffer_a: texture_storage_2d; 23 | 24 | [[group(0), binding(2)]] 25 | var buffer_b: texture_storage_2d; 26 | 27 | [[group(0), binding(3)]] 28 | var buffer_c: texture_storage_2d; 29 | 30 | [[group(0), binding(4)]] 31 | var buffer_d: texture_storage_2d; 32 | 33 | 34 | 35 | [[stage(compute), workgroup_size(8, 8, 1)]] 36 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 37 | 38 | } 39 | -------------------------------------------------------------------------------- /assets/textures/blue_noise.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliotbo/bevy_shadertoy_wgsl/e3221a81dd6f1668d7d6695f06353b373db47979/assets/textures/blue_noise.png -------------------------------------------------------------------------------- /assets/textures/font.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliotbo/bevy_shadertoy_wgsl/e3221a81dd6f1668d7d6695f06353b373db47979/assets/textures/font.png -------------------------------------------------------------------------------- /assets/textures/rgba_noise_256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliotbo/bevy_shadertoy_wgsl/e3221a81dd6f1668d7d6695f06353b373db47979/assets/textures/rgba_noise_256.png -------------------------------------------------------------------------------- /bin/assets/shaders/interactive_fluid_simulation/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | 17 | 18 | [[group(0), binding(0)]] 19 | var uni: CommonUniform; 20 | 21 | [[group(0), binding(1)]] 22 | var buffer_a: texture_storage_2d; 23 | 24 | [[stage(compute), workgroup_size(8, 8, 1)]] 25 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 26 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 27 | let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 28 | 29 | let color = vec4(0.0); 30 | 31 | textureStore(buffer_a, location, color); 32 | } 33 | 34 | 35 | [[stage(compute), workgroup_size(8, 8, 1)]] 36 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 37 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 38 | 39 | // textureStore(buffer_a, location, vec4(0.094)); 40 | 41 | if (uni.iTime > 1.0) { 42 | textureStore(buffer_a, location, vec4(0.95)); 43 | } 44 | } -------------------------------------------------------------------------------- /bin/assets/shaders/interactive_fluid_simulation/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | 2 | struct CommonUniform { 3 | iTime: f32; 4 | iTimeDelta: f32; 5 | iFrame: i32; 6 | iSampleRate: i32; 7 | 8 | iChannelTime: vec4; 9 | iChannelResolution: vec4; 10 | iDate: vec4; 11 | 12 | iResolution: vec2; 13 | iMouse: vec2; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | [[stage(compute), workgroup_size(8, 8, 1)]] 26 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 27 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 28 | let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 29 | 30 | let color = vec4(0.0); 31 | 32 | textureStore(buffer_b, location, color); 33 | } 34 | 35 | 36 | [[stage(compute), workgroup_size(8, 8, 1)]] 37 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 38 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 39 | 40 | // textureStore(buffer_b, location, vec4(0.85)); 41 | 42 | 43 | // if (uni.iTime > 1.0) { 44 | // textureStore(buffer_b, location, vec4(0.95)); 45 | // } 46 | } -------------------------------------------------------------------------------- /bin/assets/shaders/interactive_fluid_simulation/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | [[group(0), binding(3)]] 26 | var buffer_c: texture_storage_2d; 27 | 28 | [[stage(compute), workgroup_size(8, 8, 1)]] 29 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 30 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 31 | let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 32 | 33 | let color = vec4(0.0); 34 | 35 | textureStore(buffer_c, location, color); 36 | } 37 | 38 | 39 | [[stage(compute), workgroup_size(8, 8, 1)]] 40 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 41 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 42 | 43 | // textureStore(buffer_c, location, vec4(0.95)); 44 | 45 | // if (uni.iTime > 1.0) { 46 | // textureStore(buffer_c, location, vec4(0.95)); 47 | // } 48 | } -------------------------------------------------------------------------------- /bin/assets/shaders/interactive_fluid_simulation/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | 17 | [[group(0), binding(0)]] 18 | var uni: CommonUniform; 19 | 20 | [[group(0), binding(1)]] 21 | var buffer_a: texture_storage_2d; 22 | 23 | [[group(0), binding(2)]] 24 | var buffer_b: texture_storage_2d; 25 | 26 | [[group(0), binding(3)]] 27 | var buffer_c: texture_storage_2d; 28 | 29 | [[group(0), binding(4)]] 30 | var buffer_d: texture_storage_2d; 31 | 32 | [[stage(compute), workgroup_size(8, 8, 1)]] 33 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 34 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 35 | 36 | let color = vec4(0.60); 37 | 38 | textureStore(buffer_d, location, color); 39 | } 40 | 41 | [[stage(compute), workgroup_size(8, 8, 1)]] 42 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 43 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 44 | 45 | // textureStore(buffer_d, location, vec4(0.7)); 46 | 47 | // let p: vec4 = texture(iChannel0, fragCoord/iResolution.xy); 48 | // if (uni.iMouse.z>0.) { 49 | // if (p.z>0.) { fragColor = vec4(uni.iMouse.xy, p.xy); 50 | // } else { fragColor = vec4(uni.iMouse.xy, uni.iMouse.xy); 51 | // } 52 | 53 | // } else { fragColor = vec4(-uni.iResolution.xy, -uni.iResolution.xy); 54 | // } 55 | 56 | 57 | if (uni.iTime > 1.0) { 58 | storageBarrier(); 59 | textureStore(buffer_d, location, vec4(0.95)); 60 | } 61 | 62 | // storageBarrier(); 63 | } 64 | 65 | // fn mainImage( fragColor: vec4, fragCoord: vec2) -> () { 66 | // let p: vec4 = texture(iChannel0, fragCoord/iResolution.xy); 67 | // if (iMouse.z>0.) { 68 | // if (p.z>0.) { fragColor = vec4(iMouse.xy, p.xy); 69 | // } else { fragColor = vec4(iMouse.xy, iMouse.xy); 70 | // } 71 | 72 | // } else { fragColor = vec4(-iResolution.xy, -iResolution.xy); 73 | // } 74 | 75 | // } -------------------------------------------------------------------------------- /bin/assets/shaders/liquid/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | 2 | struct CommonUniform { 3 | iTime: f32; 4 | iTimeDelta: f32; 5 | iFrame: i32; 6 | iSampleRate: i32; 7 | 8 | iChannelTime: vec4; 9 | iChannelResolution: vec4; 10 | iDate: vec4; 11 | 12 | iResolution: vec2; 13 | iMouse: vec2; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | [[stage(compute), workgroup_size(8, 8, 1)]] 26 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 27 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 28 | let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 29 | 30 | let color = vec4(0.0); 31 | 32 | textureStore(buffer_b, location, color); 33 | } 34 | 35 | 36 | [[stage(compute), workgroup_size(8, 8, 1)]] 37 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 38 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 39 | 40 | // textureStore(buffer_b, location, vec4(0.85)); 41 | 42 | 43 | // if (uni.iTime > 1.0) { 44 | // textureStore(buffer_b, location, vec4(0.95)); 45 | // } 46 | } -------------------------------------------------------------------------------- /bin/assets/shaders/liquid/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | [[group(0), binding(3)]] 26 | var buffer_c: texture_storage_2d; 27 | 28 | [[stage(compute), workgroup_size(8, 8, 1)]] 29 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 30 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 31 | let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 32 | 33 | let color = vec4(0.0); 34 | 35 | textureStore(buffer_c, location, color); 36 | } 37 | 38 | 39 | [[stage(compute), workgroup_size(8, 8, 1)]] 40 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 41 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 42 | 43 | // textureStore(buffer_c, location, vec4(0.95)); 44 | 45 | // if (uni.iTime > 1.0) { 46 | // textureStore(buffer_c, location, vec4(0.95)); 47 | // } 48 | } -------------------------------------------------------------------------------- /bin/assets/shaders/liquid/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | 17 | [[group(0), binding(0)]] 18 | var uni: CommonUniform; 19 | 20 | [[group(0), binding(1)]] 21 | var buffer_a: texture_storage_2d; 22 | 23 | [[group(0), binding(2)]] 24 | var buffer_b: texture_storage_2d; 25 | 26 | [[group(0), binding(3)]] 27 | var buffer_c: texture_storage_2d; 28 | 29 | [[group(0), binding(4)]] 30 | var buffer_d: texture_storage_2d; 31 | 32 | [[stage(compute), workgroup_size(8, 8, 1)]] 33 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 34 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 35 | 36 | let color = vec4(0.60); 37 | 38 | textureStore(buffer_d, location, color); 39 | } 40 | 41 | [[stage(compute), workgroup_size(8, 8, 1)]] 42 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 43 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 44 | 45 | // textureStore(buffer_d, location, vec4(0.7)); 46 | 47 | if (uni.iTime > 1.0) { 48 | storageBarrier(); 49 | textureStore(buffer_d, location, vec4(0.95)); 50 | } 51 | 52 | // storageBarrier(); 53 | } -------------------------------------------------------------------------------- /bin/assets/shaders/minimal/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | 26 | 27 | 28 | 29 | [[stage(compute), workgroup_size(8, 8, 1)]] 30 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 31 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 32 | let color = vec4(0.5); 33 | textureStore(buffer_a, location, color); 34 | } -------------------------------------------------------------------------------- /bin/assets/shaders/minimal/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | 26 | 27 | [[stage(compute), workgroup_size(8, 8, 1)]] 28 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 29 | 30 | } -------------------------------------------------------------------------------- /bin/assets/shaders/minimal/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | 17 | [[group(0), binding(0)]] 18 | var uni: CommonUniform; 19 | 20 | [[group(0), binding(1)]] 21 | var buffer_a: texture_storage_2d; 22 | 23 | [[group(0), binding(2)]] 24 | var buffer_b: texture_storage_2d; 25 | 26 | [[group(0), binding(3)]] 27 | var buffer_c: texture_storage_2d; 28 | 29 | [[stage(compute), workgroup_size(8, 8, 1)]] 30 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 31 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 32 | let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 33 | 34 | let color = vec4(0.0); 35 | 36 | textureStore(buffer_c, location, color); 37 | } 38 | 39 | 40 | [[stage(compute), workgroup_size(8, 8, 1)]] 41 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 42 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 43 | 44 | // textureStore(buffer_c, location, vec4(0.95)); 45 | 46 | // if (uni.iTime > 1.0) { 47 | // textureStore(buffer_c, location, vec4(0.95)); 48 | // } 49 | } -------------------------------------------------------------------------------- /bin/assets/shaders/minimal/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | 17 | [[group(0), binding(0)]] 18 | var uni: CommonUniform; 19 | 20 | [[group(0), binding(1)]] 21 | var buffer_a: texture_storage_2d; 22 | 23 | [[group(0), binding(2)]] 24 | var buffer_b: texture_storage_2d; 25 | 26 | [[group(0), binding(3)]] 27 | var buffer_c: texture_storage_2d; 28 | 29 | [[group(0), binding(4)]] 30 | var buffer_d: texture_storage_2d; 31 | 32 | [[stage(compute), workgroup_size(8, 8, 1)]] 33 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 34 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 35 | 36 | let color = vec4(0.60); 37 | 38 | textureStore(buffer_d, location, color); 39 | } 40 | 41 | [[stage(compute), workgroup_size(8, 8, 1)]] 42 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 43 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 44 | 45 | // textureStore(buffer_d, location, vec4(0.7)); 46 | 47 | if (uni.iTime > 1.0) { 48 | storageBarrier(); 49 | textureStore(buffer_d, location, vec4(0.95)); 50 | } 51 | 52 | // storageBarrier(); 53 | } -------------------------------------------------------------------------------- /bin/assets/shaders/minimal/image.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | [[group(0), binding(3)]] 26 | var buffer_c: texture_storage_2d; 27 | 28 | [[group(0), binding(4)]] 29 | var buffer_d: texture_storage_2d; 30 | 31 | [[group(0), binding(5)]] 32 | var texture: texture_storage_2d; 33 | 34 | // [[stage(compute), workgroup_size(8, 8, 1)]] 35 | // fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 36 | // let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 37 | // let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 38 | 39 | // let color = vec4(f32(0)); 40 | // textureStore(texture, location, color); 41 | // } 42 | 43 | 44 | // displays a gray screen by setting the color in buffer_a.wglsl and loading buffer_a 45 | // here 46 | 47 | [[stage(compute), workgroup_size(8, 8, 1)]] 48 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 49 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 50 | 51 | var O: vec4 = textureLoad(buffer_a, location); 52 | textureStore(texture, location, O); 53 | } -------------------------------------------------------------------------------- /bin/assets/shaders/paint/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | [[group(0), binding(3)]] 26 | var buffer_c: texture_storage_2d; 27 | 28 | [[group(0), binding(4)]] 29 | var buffer_d: texture_storage_2d; 30 | 31 | 32 | 33 | [[stage(compute), workgroup_size(8, 8, 1)]] 34 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 35 | 36 | } -------------------------------------------------------------------------------- /bin/assets/shaders/paint/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | [[group(0), binding(3)]] 26 | var buffer_c: texture_storage_2d; 27 | 28 | [[stage(compute), workgroup_size(8, 8, 1)]] 29 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 30 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 31 | let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 32 | 33 | let color = vec4(0.0); 34 | 35 | textureStore(buffer_c, location, color); 36 | } 37 | 38 | 39 | [[stage(compute), workgroup_size(8, 8, 1)]] 40 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 41 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 42 | 43 | // textureStore(buffer_c, location, vec4(0.95)); 44 | 45 | // if (uni.iTime > 1.0) { 46 | // textureStore(buffer_c, location, vec4(0.95)); 47 | // } 48 | } -------------------------------------------------------------------------------- /bin/assets/shaders/paint/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | [[group(0), binding(3)]] 26 | var buffer_c: texture_storage_2d; 27 | 28 | [[group(0), binding(4)]] 29 | var buffer_d: texture_storage_2d; 30 | 31 | [[stage(compute), workgroup_size(8, 8, 1)]] 32 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 33 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 34 | 35 | let color = vec4(0.60); 36 | 37 | textureStore(buffer_d, location, color); 38 | } 39 | 40 | [[stage(compute), workgroup_size(8, 8, 1)]] 41 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 42 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 43 | 44 | // textureStore(buffer_d, location, vec4(0.7)); 45 | 46 | if (uni.iTime > 1.0) { 47 | storageBarrier(); 48 | textureStore(buffer_d, location, vec4(0.95)); 49 | } 50 | 51 | // storageBarrier(); 52 | } -------------------------------------------------------------------------------- /bin/assets/shaders/paint/common.wgsl: -------------------------------------------------------------------------------- 1 | // unused 2 | 3 | #define_import_path bevy_shadertoy_wgsl::assets::shaders::common 4 | 5 | struct CommonUniform { 6 | iTime: f32; 7 | iTimeDelta: f32; 8 | iFrame: f32; 9 | iSampleRate: f32; 10 | 11 | iMouse: vec4; 12 | iResolution: vec2; 13 | 14 | 15 | iChannelTime: vec4; 16 | iChannelResolution: vec4; 17 | iDate: vec4; 18 | }; -------------------------------------------------------------------------------- /bin/assets/shaders/paint/image.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | [[group(0), binding(3)]] 26 | var buffer_c: texture_storage_2d; 27 | 28 | [[group(0), binding(4)]] 29 | var buffer_d: texture_storage_2d; 30 | 31 | [[group(0), binding(5)]] 32 | var texture: texture_storage_2d; 33 | 34 | // [[stage(compute), workgroup_size(8, 8, 1)]] 35 | // fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 36 | // let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 37 | // let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 38 | 39 | // let color = vec4(f32(0)); 40 | // textureStore(texture, location, color); 41 | // } 42 | 43 | 44 | [[stage(compute), workgroup_size(8, 8, 1)]] 45 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 46 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 47 | 48 | var alive = true; 49 | 50 | var O: vec4 = textureLoad(buffer_a, location); 51 | 52 | textureStore(texture, location, O); 53 | } -------------------------------------------------------------------------------- /bin/assets/shaders/paint2/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | 26 | 27 | [[stage(compute), workgroup_size(8, 8, 1)]] 28 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 29 | 30 | } -------------------------------------------------------------------------------- /bin/assets/shaders/paint2/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | [[stage(compute), workgroup_size(8, 8, 1)]] 2 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /bin/assets/shaders/paint2/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | [[stage(compute), workgroup_size(8, 8, 1)]] 2 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /bin/assets/shaders/paint2/common.wgsl: -------------------------------------------------------------------------------- 1 | // unused 2 | 3 | #define_import_path bevy_shadertoy_wgsl::assets::shaders::common 4 | 5 | struct CommonUniform { 6 | iTime: f32; 7 | iTimeDelta: f32; 8 | iFrame: f32; 9 | iSampleRate: f32; 10 | 11 | iMouse: vec4; 12 | iResolution: vec2; 13 | 14 | 15 | iChannelTime: vec4; 16 | iChannelResolution: vec4; 17 | iDate: vec4; 18 | }; -------------------------------------------------------------------------------- /bin/assets/shaders/paint2/image.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | [[group(0), binding(3)]] 26 | var buffer_c: texture_storage_2d; 27 | 28 | [[group(0), binding(4)]] 29 | var buffer_d: texture_storage_2d; 30 | 31 | [[group(0), binding(5)]] 32 | var texture: texture_storage_2d; 33 | 34 | // [[stage(compute), workgroup_size(8, 8, 1)]] 35 | // fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 36 | // let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 37 | // let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 38 | 39 | // let color = vec4(f32(0)); 40 | // textureStore(texture, location, color); 41 | // } 42 | 43 | 44 | [[stage(compute), workgroup_size(8, 8, 1)]] 45 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 46 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 47 | 48 | var alive = true; 49 | 50 | var O: vec4 = textureLoad(buffer_a, location); 51 | 52 | textureStore(texture, location, O); 53 | } -------------------------------------------------------------------------------- /bin/assets/shaders/paint2/image2.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: i32; 5 | iSampleRate: i32; 6 | 7 | iChannelTime: vec4; 8 | iChannelResolution: vec4; 9 | iDate: vec4; 10 | 11 | iResolution: vec2; 12 | iMouse: vec2; 13 | }; 14 | 15 | [[group(0), binding(0)]] 16 | var uni: CommonUniform; 17 | 18 | [[group(0), binding(1)]] 19 | var buffer_a: texture_storage_2d; 20 | 21 | [[group(0), binding(2)]] 22 | var buffer_b: texture_storage_2d; 23 | 24 | [[group(0), binding(3)]] 25 | var buffer_c: texture_storage_2d; 26 | 27 | [[group(0), binding(4)]] 28 | var buffer_d: texture_storage_2d; 29 | 30 | [[group(0), binding(5)]] 31 | var texture: texture_storage_2d; 32 | 33 | [[stage(compute), workgroup_size(8, 8, 1)]] 34 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 35 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 36 | let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 37 | 38 | let color = vec4(f32(0)); 39 | textureStore(texture, location, color); 40 | } 41 | 42 | 43 | 44 | 45 | fn hash(value: u32) -> u32 { 46 | var state = value; 47 | state = state ^ 2747636419u; 48 | state = state * 2654435769u; 49 | state = state ^ state >> 16u; 50 | state = state * 2654435769u; 51 | state = state ^ state >> 16u; 52 | state = state * 2654435769u; 53 | return state; 54 | } 55 | fn randomFloat(value: u32) -> f32 { 56 | return f32(hash(value)) / 4294967295.0; 57 | } 58 | 59 | 60 | 61 | [[stage(compute), workgroup_size(8, 8, 1)]] 62 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 63 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 64 | 65 | var alive = true; 66 | 67 | var O: vec4 = textureLoad(buffer_a, location); 68 | // let color = vec4(O.x, 0.1, 0.12, 1.0); 69 | 70 | // storageBarrier(); 71 | 72 | // textureStore(texture, location, vec4(color)); 73 | textureStore(texture, location, O); 74 | } 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /bin/assets/shaders/preludes/image_prelude: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iResolution: vec2; 8 | iMouse: vec2; 9 | 10 | iChannelTime: vec4; 11 | iChannelResolution: vec4; 12 | iDate: vec4; // change to vec4 when possible 13 | }; 14 | 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; 18 | 19 | [[group(0), binding(1)]] 20 | var buffer_a: texture_storage_2d; 21 | 22 | [[group(0), binding(2)]] 23 | var buffer_b: texture_storage_2d; 24 | 25 | [[group(0), binding(3)]] 26 | var buffer_c: texture_storage_2d; 27 | 28 | [[group(0), binding(4)]] 29 | var buffer_d: texture_storage_2d; 30 | 31 | [[group(0), binding(5)]] 32 | var texture: texture_storage_2d; 33 | 34 | {{IMAGE_CODE}} 35 | -------------------------------------------------------------------------------- /bin/assets/shaders/simplest_detailed_fluid/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | 17 | 18 | [[group(0), binding(0)]] 19 | var uni: CommonUniform; 20 | 21 | [[group(0), binding(1)]] 22 | var buffer_a: texture_storage_2d; 23 | 24 | [[stage(compute), workgroup_size(8, 8, 1)]] 25 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 26 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 27 | let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 28 | 29 | let color = vec4(0.0); 30 | 31 | 32 | textureStore(buffer_a, location, color); 33 | } 34 | 35 | // https://www.shadertoy.com/view/7t3SDf 36 | 37 | fn t(i: vec2, location: vec2) -> vec4 { 38 | let O: vec4 = textureLoad(buffer_a, i + location ); 39 | return O; 40 | } 41 | 42 | [[stage(compute), workgroup_size(8, 8, 1)]] 43 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 44 | var location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 45 | // location = location + vec2(10); 46 | 47 | 48 | var r: vec4 = vec4(0.); 49 | 50 | for (var i: vec2 = vec2(-7); i.x < 7; i.x = i.x + 1 ) { 51 | 52 | for (i.y = -7; i.y < 7; i.y = i.y + 1 ) { 53 | 54 | let ii = i + 1; 55 | let a = 0; 56 | 57 | let v: vec2 = t(ii , location + a ).xy; 58 | let what = t(ii, location + a).z ; 59 | let fi = vec2(ii); 60 | 61 | r = r + ( what 62 | * exp(-dot(v+fi, v+fi)) / 3.14 63 | * vec4(mix(v+v+fi , v, t(ii, location + a ).z), 1., 1.) ); 64 | } 65 | } 66 | 67 | r.x = r.x / (r.z+0.000001); 68 | r.y = r.y / (r.z+0.000001); 69 | 70 | if (i32(uni.iFrame) % 500 == 1) { 71 | let u = vec2(location +0) ; 72 | let m: vec2 = 4.*u/vec2(uni.iResolution.xy) - 2.; 73 | r = r + (vec4(m, 1., 0.)*exp(-dot(m, m))); 74 | 75 | } 76 | 77 | textureStore(buffer_a, location , r); 78 | } 79 | 80 | -------------------------------------------------------------------------------- /bin/assets/shaders/simplest_detailed_fluid/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | 17 | [[group(0), binding(0)]] 18 | var uni: CommonUniform; 19 | 20 | [[group(0), binding(1)]] 21 | var buffer_a: texture_storage_2d; 22 | 23 | [[group(0), binding(2)]] 24 | var buffer_b: texture_storage_2d; 25 | 26 | [[stage(compute), workgroup_size(8, 8, 1)]] 27 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 28 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 29 | let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 30 | 31 | let color = vec4(0.0); 32 | 33 | textureStore(buffer_b, location, color); 34 | } 35 | 36 | 37 | [[stage(compute), workgroup_size(8, 8, 1)]] 38 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 39 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 40 | 41 | // textureStore(buffer_b, location, vec4(0.85)); 42 | 43 | 44 | // if (uni.iTime > 1.0) { 45 | // textureStore(buffer_b, location, vec4(0.95)); 46 | // } 47 | } -------------------------------------------------------------------------------- /bin/assets/shaders/simplest_detailed_fluid/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | 17 | [[group(0), binding(0)]] 18 | var uni: CommonUniform; 19 | 20 | [[group(0), binding(1)]] 21 | var buffer_a: texture_storage_2d; 22 | 23 | [[group(0), binding(2)]] 24 | var buffer_b: texture_storage_2d; 25 | 26 | [[group(0), binding(3)]] 27 | var buffer_c: texture_storage_2d; 28 | 29 | [[stage(compute), workgroup_size(8, 8, 1)]] 30 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 31 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 32 | let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 33 | 34 | let color = vec4(0.0); 35 | 36 | textureStore(buffer_c, location, color); 37 | } 38 | 39 | 40 | [[stage(compute), workgroup_size(8, 8, 1)]] 41 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 42 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 43 | 44 | // textureStore(buffer_c, location, vec4(0.95)); 45 | 46 | // if (uni.iTime > 1.0) { 47 | // textureStore(buffer_c, location, vec4(0.95)); 48 | // } 49 | } -------------------------------------------------------------------------------- /bin/assets/shaders/simplest_detailed_fluid/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | 17 | [[group(0), binding(0)]] 18 | var uni: CommonUniform; 19 | 20 | [[group(0), binding(1)]] 21 | var buffer_a: texture_storage_2d; 22 | 23 | [[group(0), binding(2)]] 24 | var buffer_b: texture_storage_2d; 25 | 26 | [[group(0), binding(3)]] 27 | var buffer_c: texture_storage_2d; 28 | 29 | [[group(0), binding(4)]] 30 | var buffer_d: texture_storage_2d; 31 | 32 | [[stage(compute), workgroup_size(8, 8, 1)]] 33 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 34 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 35 | 36 | let color = vec4(0.60); 37 | 38 | textureStore(buffer_d, location, color); 39 | } 40 | 41 | [[stage(compute), workgroup_size(8, 8, 1)]] 42 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 43 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 44 | 45 | // textureStore(buffer_d, location, vec4(0.7)); 46 | 47 | if (uni.iTime > 1.0) { 48 | storageBarrier(); 49 | textureStore(buffer_d, location, vec4(0.95)); 50 | } 51 | 52 | // storageBarrier(); 53 | } -------------------------------------------------------------------------------- /bin/assets/shaders/simplest_detailed_fluid/image.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | 17 | [[group(0), binding(0)]] 18 | var uni: CommonUniform; 19 | 20 | [[group(0), binding(1)]] 21 | var buffer_a: texture_storage_2d; 22 | 23 | [[group(0), binding(2)]] 24 | var buffer_b: texture_storage_2d; 25 | 26 | [[group(0), binding(3)]] 27 | var buffer_c: texture_storage_2d; 28 | 29 | [[group(0), binding(4)]] 30 | var buffer_d: texture_storage_2d; 31 | 32 | [[group(0), binding(5)]] 33 | var texture: texture_storage_2d; 34 | 35 | fn hash(value: u32) -> u32 { 36 | var state = value; 37 | state = state ^ 2747636419u; 38 | state = state * 2654435769u; 39 | state = state ^ state >> 16u; 40 | state = state * 2654435769u; 41 | state = state ^ state >> 16u; 42 | state = state * 2654435769u; 43 | return state; 44 | } 45 | fn randomFloat(value: u32) -> f32 { 46 | return f32(hash(value)) / 4294967295.0; 47 | } 48 | 49 | [[stage(compute), workgroup_size(8, 8, 1)]] 50 | fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 51 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 52 | let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 53 | 54 | let randomNumber = randomFloat(invocation_id.y * num_workgroups.x + invocation_id.x); 55 | let alive = randomNumber > 0.9; 56 | let color = vec4(f32(alive)); 57 | 58 | textureStore(texture, location, color); 59 | } 60 | 61 | 62 | [[stage(compute), workgroup_size(8, 8, 1)]] 63 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 64 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 65 | 66 | 67 | 68 | // var alive = true; 69 | 70 | 71 | // let value: vec4 = textureLoad(buffer_a, vec2(0,1)); 72 | // if (value.x > 0.79) { 73 | // alive = false; 74 | // } 75 | let r = 1.- textureLoad(buffer_a, location ).zzzz; 76 | 77 | storageBarrier(); 78 | textureStore(texture, location, r); 79 | 80 | 81 | // textureStore(texture, location, vec4(f32(alive))); 82 | } 83 | 84 | 85 | -------------------------------------------------------------------------------- /bin/examples/minimal/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | [[stage(compute), workgroup_size(8, 8, 1)]] 4 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 5 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 6 | let color = vec4(0.5); 7 | textureStore(buffer_a, location, color); 8 | } -------------------------------------------------------------------------------- /bin/examples/minimal/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | [[stage(compute), workgroup_size(8, 8, 1)]] 2 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /bin/examples/minimal/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | [[stage(compute), workgroup_size(8, 8, 1)]] 2 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /bin/examples/minimal/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | [[stage(compute), workgroup_size(8, 8, 1)]] 2 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /bin/examples/minimal/common.wgsl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliotbo/bevy_shadertoy_wgsl/e3221a81dd6f1668d7d6695f06353b373db47979/bin/examples/minimal/common.wgsl -------------------------------------------------------------------------------- /bin/examples/minimal/image.wgsl: -------------------------------------------------------------------------------- 1 | // displays a gray screen by setting the color in buffer_a.wglsl and loading buffer_a 2 | // here 3 | 4 | [[stage(compute), workgroup_size(8, 8, 1)]] 5 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 6 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 7 | 8 | var O: vec4 = textureLoad(buffer_a, location); 9 | textureStore(texture, location, O); 10 | } -------------------------------------------------------------------------------- /bin/examples/mixing_liquid/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | [[stage(compute), workgroup_size(8, 8, 1)]] 4 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 5 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 6 | // let color = vec4(0.5); 7 | // textureStore(buffer_a, location, color); 8 | // } 9 | 10 | 11 | // fn mainImage( U: vec4, pos: vec2) -> () { 12 | let pos: vec2 = vec2(location); 13 | 14 | R = uni.iResolution.xy; 15 | time = uni.iTime; 16 | Mouse = uni.iMouse; 17 | let p: vec2 = location; 18 | 19 | // let data: vec4 = texel(ch0, pos); 20 | 21 | // buffer_b is set as the channel 0 in Buffer A of the paint 22 | // streams inside shadertoy 23 | let data: vec4 = textureLoad(buffer_b, location); 24 | 25 | var P: particle = Reintegration(buffer_b, pos); 26 | 27 | // if (uni.iFrame < 4.0) { 28 | # ifdef INIT 29 | let rand: vec3 = hash32(pos); 30 | if (rand.z < 0.) { 31 | P.X = pos; 32 | P.V = 0.5 * (rand.xy - 0.5) + vec2(0., 0.); 33 | P.M = vec2(mass, 0.); 34 | 35 | } else { 36 | P.X = pos; 37 | P.V = vec2(0.); 38 | P.M = vec2(0.000001); 39 | 40 | } 41 | # endif 42 | // } 43 | 44 | textureStore(buffer_a, location, saveParticle(P, pos)); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /bin/examples/mixing_liquid/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | [[stage(compute), workgroup_size(8, 8, 1)]] 2 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 3 | 4 | // } 5 | 6 | // fn mainImage( U: vec4, pos: vec2) -> () { 7 | 8 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 9 | 10 | let pos: vec2 = vec2(location); 11 | 12 | R = uni.iResolution.xy; 13 | time = uni.iTime; 14 | Mouse = uni.iMouse; 15 | let p: vec2 = location; 16 | 17 | 18 | // let data: vec4 = texel(buffer_a, pos); 19 | let data: vec4 = textureLoad(buffer_a, location); 20 | 21 | var P: particle = getParticle(data, pos); 22 | 23 | if (P.M.x != 0.) { 24 | P = Simulation(buffer_a, P, pos); 25 | } 26 | 27 | if (length(P.X - R * vec2(0.8, 0.9)) < 10.) { 28 | P.X = pos; 29 | P.V = 0.5 * Dir(-PI * 0.25 - PI * 0.5 + 0.3 * sin(0.4 * time)); 30 | P.M = mix(P.M, vec2(fluid_rho, 1.), 0.4); 31 | } 32 | 33 | if (length(P.X - R * vec2(0.2, 0.9)) < 10.) { 34 | P.X = pos; 35 | P.V = 0.5 * Dir(-PI * 0.25 + 0.3 * sin(0.3 * time)); 36 | P.M = mix(P.M, vec2(fluid_rho, 0.), 0.4); 37 | } 38 | 39 | // U = saveParticle(P, pos); 40 | textureStore(buffer_b, location, saveParticle(P, pos)); 41 | } 42 | 43 | -------------------------------------------------------------------------------- /bin/examples/mixing_liquid/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | [[stage(compute), workgroup_size(8, 8, 1)]] 2 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 3 | 4 | // fn mainImage( fragColor: vec4, pos: vec2) -> () { 5 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 6 | R = uni.iResolution.xy; 7 | time = uni.iTime; 8 | let pos = vec2(location); 9 | let p: vec2 = vec2(pos); 10 | 11 | let data: vec4 = textureLoad(buffer_a, location); 12 | 13 | var P: particle = getParticle(data, pos); 14 | 15 | // let data: vec4 = texel(ch0, pos); 16 | // let P: particle = getParticle(data, pos); 17 | 18 | var rho: vec4 = vec4(0.); 19 | for (var i: i32 = -1; i <= 1; i = i + 1) { 20 | for (var j: i32 = -1; j <= 1; j = j + 1) { 21 | let ij: vec2 = vec2(i, j); 22 | 23 | // let data: vec4 = texel(ch0, pos + ij); 24 | let data: vec4 = textureLoad(buffer_a, location + ij); 25 | 26 | var P0: particle = getParticle(data, pos + vec2(ij)); 27 | let x0: vec2 = P0.X; 28 | rho = rho + (1. * vec4(P.V, P.M) * G((pos - x0) / 0.75)); 29 | 30 | } 31 | } 32 | 33 | textureStore(buffer_c, location, rho); 34 | 35 | } 36 | 37 | -------------------------------------------------------------------------------- /bin/examples/mixing_liquid/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | [[stage(compute), workgroup_size(8, 8, 1)]] 2 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /bin/examples/paint/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | [[stage(compute), workgroup_size(8, 8, 1)]] 2 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /bin/examples/paint/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | [[stage(compute), workgroup_size(8, 8, 1)]] 2 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /bin/examples/paint/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | [[stage(compute), workgroup_size(8, 8, 1)]] 2 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /bin/examples/paint/common.wgsl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliotbo/bevy_shadertoy_wgsl/e3221a81dd6f1668d7d6695f06353b373db47979/bin/examples/paint/common.wgsl -------------------------------------------------------------------------------- /bin/examples/paint/image.wgsl: -------------------------------------------------------------------------------- 1 | [[stage(compute), workgroup_size(8, 8, 1)]] 2 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 3 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 4 | 5 | var alive = true; 6 | 7 | var O: vec4 = textureLoad(buffer_a, location); 8 | 9 | textureStore(texture, location, O); 10 | } -------------------------------------------------------------------------------- /bin/examples/paint_streams/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | [[stage(compute), workgroup_size(8, 8, 1)]] 2 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 3 | 4 | // fn mainImage( fragColor: vec4, pos: vec2) -> () { 5 | // let R = uni.iResolution.xy; 6 | 7 | let R2 = uni.iResolution.xy; 8 | let location = vec2(i32(invocation_id.x), i32(R2.y) - i32(invocation_id.y)); 9 | // R = uni.iResolution.xy; 10 | // time = uni.iTime; 11 | let pos = vec2(location); 12 | let p: vec2 = vec2(pos); 13 | 14 | let data: vec4 = textureLoad(buffer_a, location); 15 | 16 | var P: particle = getParticle(data, pos); 17 | 18 | // let data: vec4 = texel(ch0, pos); 19 | // let P: particle = getParticle(data, pos); 20 | 21 | var rho: vec4 = vec4(0.); 22 | for (var i: i32 = -1; i <= 1; i = i + 1) { 23 | for (var j: i32 = -1; j <= 1; j = j + 1) { 24 | let ij: vec2 = vec2(i, j); 25 | 26 | // let data: vec4 = texel(ch0, pos + ij); 27 | let data: vec4 = textureLoad(buffer_a, location + ij); 28 | 29 | var P0: particle = getParticle(data, pos + vec2(ij)); 30 | let x0: vec2 = P0.X; 31 | rho = rho + (1. * vec4(P.V, P.M) * G((pos - x0) / 0.75)); 32 | 33 | } 34 | } 35 | 36 | textureStore(buffer_c, location, rho); 37 | 38 | } 39 | 40 | -------------------------------------------------------------------------------- /bin/examples/paint_streams/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | [[stage(compute), workgroup_size(8, 8, 1)]] 2 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /bin/templates/buffer_a_template.wgsl: -------------------------------------------------------------------------------- 1 | {{COMMON_PRELUDE}} 2 | 3 | [[group(0), binding(1)]] 4 | var buffer_a: texture_storage_2d; 5 | 6 | [[group(0), binding(2)]] 7 | var buffer_b: texture_storage_2d; 8 | 9 | [[group(0), binding(3)]] 10 | var buffer_c: texture_storage_2d; 11 | 12 | [[group(0), binding(4)]] 13 | var buffer_d: texture_storage_2d; 14 | 15 | {{COMMON}} 16 | 17 | {{CODE_BLOCK}} -------------------------------------------------------------------------------- /bin/templates/buffer_b_template.wgsl: -------------------------------------------------------------------------------- 1 | {{COMMON_PRELUDE}} 2 | 3 | [[group(0), binding(1)]] 4 | var buffer_a: texture_storage_2d; 5 | 6 | [[group(0), binding(2)]] 7 | var buffer_b: texture_storage_2d; 8 | 9 | [[group(0), binding(3)]] 10 | var buffer_c: texture_storage_2d; 11 | 12 | [[group(0), binding(4)]] 13 | var buffer_d: texture_storage_2d; 14 | 15 | {{COMMON}} 16 | 17 | {{CODE_BLOCK}} -------------------------------------------------------------------------------- /bin/templates/buffer_c_template.wgsl: -------------------------------------------------------------------------------- 1 | {{COMMON_PRELUDE}} 2 | 3 | [[group(0), binding(1)]] 4 | var buffer_a: texture_storage_2d; 5 | 6 | [[group(0), binding(2)]] 7 | var buffer_b: texture_storage_2d; 8 | 9 | [[group(0), binding(3)]] 10 | var buffer_c: texture_storage_2d; 11 | 12 | [[group(0), binding(4)]] 13 | var buffer_d: texture_storage_2d; 14 | 15 | {{COMMON}} 16 | 17 | {{CODE_BLOCK}} -------------------------------------------------------------------------------- /bin/templates/buffer_d_template.wgsl: -------------------------------------------------------------------------------- 1 | 2 | {{COMMON_PRELUDE}} 3 | 4 | [[group(0), binding(1)]] 5 | var buffer_a: texture_storage_2d; 6 | 7 | [[group(0), binding(2)]] 8 | var buffer_b: texture_storage_2d; 9 | 10 | [[group(0), binding(3)]] 11 | var buffer_c: texture_storage_2d; 12 | 13 | [[group(0), binding(4)]] 14 | var buffer_d: texture_storage_2d; 15 | 16 | {{COMMON}} 17 | 18 | {{CODE_BLOCK}} 19 | -------------------------------------------------------------------------------- /bin/templates/common.wgsl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliotbo/bevy_shadertoy_wgsl/e3221a81dd6f1668d7d6695f06353b373db47979/bin/templates/common.wgsl -------------------------------------------------------------------------------- /bin/templates/common_prelude.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iTime: f32; 3 | iTimeDelta: f32; 4 | iFrame: f32; 5 | iSampleRate: f32; 6 | 7 | iMouse: vec4; 8 | iResolution: vec2; 9 | 10 | 11 | iChannelTime: vec4; 12 | iChannelResolution: vec4; 13 | iDate: vec4; 14 | }; 15 | 16 | [[group(0), binding(0)]] 17 | var uni: CommonUniform; -------------------------------------------------------------------------------- /bin/templates/image.wgsl: -------------------------------------------------------------------------------- 1 | fn hash(value: u32) -> u32 { 2 | var state = value; 3 | state = state ^ 2747636419u; 4 | state = state * 2654435769u; 5 | state = state ^ state >> 16u; 6 | state = state * 2654435769u; 7 | state = state ^ state >> 16u; 8 | state = state * 2654435769u; 9 | return state; 10 | } 11 | fn randomFloat(value: u32) -> f32 { 12 | return f32(hash(value)) / 4294967295.0; 13 | } 14 | 15 | 16 | 17 | // fn get(location: vec2, offset_x: i32, offset_y: i32) -> i32 { 18 | // let value: vec4 = textureLoad(texture, location + vec2(offset_x, offset_y)); 19 | // return i32(value.x); 20 | // } 21 | 22 | // fn count_alive(location: vec2) -> i32 { 23 | // return get(location, -1, -1) + 24 | // get(location, -1, 0) + 25 | // get(location, -1, 1) + 26 | // get(location, 0, -1) + 27 | // get(location, 0, 1) + 28 | // get(location, 1, -1) + 29 | // get(location, 1, 0) + 30 | // get(location, 1, 1); 31 | // } 32 | 33 | [[stage(compute), workgroup_size(8, 8, 1)]] 34 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 35 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 36 | 37 | // let n_alive = count_alive(location); 38 | // let color = vec4(f32(n_alive) / 8.0); 39 | 40 | // var alive: bool; 41 | // if (n_alive == 3) { 42 | // alive = true; 43 | // } else if (n_alive == 2) { 44 | // let currently_alive = get(location, 0, 0); 45 | // alive = bool(currently_alive); 46 | // } else { 47 | // alive = false; 48 | // } 49 | 50 | var alive = true; 51 | 52 | // let value: vec4 = textureLoad(buffer_a, vec2(0,1)); 53 | // if (value.x > 0.51) { 54 | // alive = false; 55 | // } 56 | 57 | // let value: vec4 = textureLoad(buffer_b, vec2(0,1)); 58 | // if (value.x > 0.74) { 59 | // alive = false; 60 | // } 61 | 62 | // let value: vec4 = textureLoad(buffer_c, vec2(0,1)); 63 | // if (value.x > 0.61) { 64 | // alive = false; 65 | // } 66 | 67 | let value: vec4 = textureLoad(buffer_a, vec2(0,1)); 68 | if (value.x > 0.79) { 69 | alive = false; 70 | } 71 | 72 | // if (ga > 2) { 73 | // alive = true; 74 | // } 75 | 76 | // if (uni.iTime > 1.0) { 77 | // alive = false; 78 | // } 79 | 80 | // alive = false; 81 | 82 | storageBarrier(); 83 | 84 | textureStore(texture, location, vec4(f32(alive))); 85 | } -------------------------------------------------------------------------------- /bin/templates/image_template.wgsl: -------------------------------------------------------------------------------- 1 | {{COMMON_PRELUDE}} 2 | 3 | [[group(0), binding(1)]] 4 | var buffer_a: texture_storage_2d; 5 | 6 | [[group(0), binding(2)]] 7 | var buffer_b: texture_storage_2d; 8 | 9 | [[group(0), binding(3)]] 10 | var buffer_c: texture_storage_2d; 11 | 12 | [[group(0), binding(4)]] 13 | var buffer_d: texture_storage_2d; 14 | 15 | [[group(0), binding(5)]] 16 | var texture: texture_storage_2d; 17 | 18 | // [[stage(compute), workgroup_size(8, 8, 1)]] 19 | // fn init([[builtin(global_invocation_id)]] invocation_id: vec3, [[builtin(num_workgroups)]] num_workgroups: vec3) { 20 | // let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 21 | // let location_f32 = vec2(f32(invocation_id.x), f32(invocation_id.y)); 22 | 23 | // let color = vec4(f32(0)); 24 | // textureStore(texture, location, color); 25 | // } 26 | 27 | {{COMMON}} 28 | 29 | 30 | {{CODE_BLOCK}} -------------------------------------------------------------------------------- /bin/test_renderdoc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliotbo/bevy_shadertoy_wgsl/e3221a81dd6f1668d7d6695f06353b373db47979/bin/test_renderdoc -------------------------------------------------------------------------------- /bin/test_renderdoc.d: -------------------------------------------------------------------------------- 1 | /home/eliotbolduc/Documents/rust/bevy_shadertoy_wgsl/target/release/test_renderdoc: /home/eliotbolduc/Documents/rust/bevy_shadertoy_wgsl/src/main.rs /home/eliotbolduc/Documents/rust/bevy_shadertoy_wgsl/src/templates/buffer_a_template.wgsl /home/eliotbolduc/Documents/rust/bevy_shadertoy_wgsl/src/templates/buffer_b_template.wgsl /home/eliotbolduc/Documents/rust/bevy_shadertoy_wgsl/src/templates/buffer_c_template.wgsl /home/eliotbolduc/Documents/rust/bevy_shadertoy_wgsl/src/templates/buffer_d_template.wgsl /home/eliotbolduc/Documents/rust/bevy_shadertoy_wgsl/src/templates/common_prelude.wgsl /home/eliotbolduc/Documents/rust/bevy_shadertoy_wgsl/src/templates/image_template.wgsl /home/eliotbolduc/Documents/rust/bevy_shadertoy_wgsl/src/texture_a.rs /home/eliotbolduc/Documents/rust/bevy_shadertoy_wgsl/src/texture_b.rs /home/eliotbolduc/Documents/rust/bevy_shadertoy_wgsl/src/texture_c.rs /home/eliotbolduc/Documents/rust/bevy_shadertoy_wgsl/src/texture_d.rs 2 | -------------------------------------------------------------------------------- /examples/debugger/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 4 | let color = vec4(0.5); 5 | textureStore(buffer_a, location, color); 6 | } -------------------------------------------------------------------------------- /examples/debugger/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/debugger/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/debugger/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/debugger/common.wgsl: -------------------------------------------------------------------------------- 1 | // Converts a color from sRGB gamma to linear light gamma 2 | fn toLinear(sRGB: vec4) -> vec4 { 3 | let cutoff = vec4(sRGB < vec4(0.04045)); 4 | let higher = pow((sRGB + vec4(0.055)) / vec4(1.055), vec4(2.4)); 5 | let lower = sRGB / vec4(12.92); 6 | 7 | return mix(higher, lower, cutoff); 8 | } -------------------------------------------------------------------------------- /examples/dry_ice/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | 2 | @compute @workgroup_size(8, 8, 1) 3 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 4 | let R: vec2 = uni.iResolution.xy; 5 | let y_inverted_location = vec2(i32(invocation_id.x), i32(R.y) - i32(invocation_id.y)); 6 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 7 | 8 | var fragColor: vec4; 9 | var fragCoord = vec2(f32(location.x), f32(location.y) ); 10 | 11 | let icoord: vec2 = vec2(fragCoord); 12 | let vel_x_left: f32 = textureLoad(buffer_a, vec2(icoord + vec2(-1, 0))).x; 13 | let vel_x_right: f32 = textureLoad(buffer_a, vec2(icoord + vec2(1, 0))).x; 14 | let vel_y_bottom: f32 = textureLoad(buffer_a, vec2(icoord + vec2(0, -1))).y; 15 | let vel_y_top: f32 = textureLoad(buffer_a, vec2(icoord + vec2(0, 1))).y; 16 | let divergence: f32 = (vel_x_right - vel_x_left + vel_y_top - vel_y_bottom) * 0.5; 17 | fragColor = vec4(divergence, vec3(1.)); 18 | textureStore(buffer_b, location, fragColor); 19 | } 20 | 21 | // [[stage(compute), workgroup_size(8, 8, 1)]] 22 | // fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 23 | // let R: vec2 = uni.iResolution.xy; 24 | // let y_inverted_location = vec2(i32(invocation_id.x), i32(R.y) - i32(invocation_id.y)); 25 | // let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 26 | 27 | // var fragColor: vec4 = vec4(0.0, 0.0, 0.0, 1.0); 28 | // var fragCoord = vec2(f32(location.x), f32(location.y) ); 29 | 30 | // let icoord: vec2 = vec2(fragCoord); 31 | // let vel_x_left: f32 = sample_texture(buffer_a, vec2(icoord + vec2(-1, 0))).x; 32 | // let vel_x_right: f32 = sample_texture(buffer_a, vec2(icoord + vec2(1, 0))).x; 33 | // let vel_y_bottom: f32 = sample_texture(buffer_a, vec2(icoord + vec2(0, -1))).y; 34 | // let vel_y_top: f32 = sample_texture(buffer_a, vec2(icoord + vec2(0, 1))).y; 35 | // let divergence: f32 = (vel_x_right - vel_x_left + vel_y_top - vel_y_bottom) * 0.5; 36 | // fragColor = vec4(divergence, vec3(1.)); 37 | // textureStore(buffer_b, location, fragColor); 38 | 39 | 40 | // } 41 | 42 | -------------------------------------------------------------------------------- /examples/dry_ice/dry_ice.rs: -------------------------------------------------------------------------------- 1 | // https://www.shadertoy.com/view/WlVyRV 2 | // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 3 | // orignal GLSL code by David Gallardo - xjorma/2020 4 | 5 | use bevy::{ 6 | diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, 7 | prelude::*, 8 | }; 9 | 10 | use bevy_shadertoy_wgsl::*; 11 | 12 | fn main() { 13 | let mut app = App::new(); 14 | 15 | app.insert_resource(ClearColor(Color::GRAY)) 16 | .insert_resource(WindowDescriptor { 17 | width: 960., 18 | height: 600., 19 | cursor_visible: true, 20 | // present_mode: PresentMode::Immediate, // uncomment for unthrottled FPS 21 | ..default() 22 | }) 23 | .insert_resource(ShadertoyCanvas { 24 | width: (960.0_f32 * 1.0).floor() as u32, 25 | height: (600.0_f32 * 1.0).floor() as u32, 26 | borders: 0., 27 | position: Vec3::new(0.0, 0.0, 0.0), 28 | }) 29 | .add_plugins(DefaultPlugins) 30 | .add_plugin(ShadertoyPlugin) 31 | .add_plugin(FrameTimeDiagnosticsPlugin::default()) 32 | .add_plugin(LogDiagnosticsPlugin::default()) 33 | .add_startup_system(setup) 34 | // .add_system(update_common_uniform) 35 | .run(); 36 | } 37 | 38 | fn setup( 39 | mut commands: Commands, 40 | asset_server: Res, 41 | mut st_res: ResMut, 42 | ) { 43 | let example = "dry_ice"; 44 | st_res.include_debugger = false; 45 | 46 | let all_shader_handles: ShaderHandles = 47 | make_and_load_shaders2(example, &asset_server, st_res.include_debugger); 48 | 49 | commands.insert_resource(all_shader_handles); 50 | } 51 | -------------------------------------------------------------------------------- /examples/fire/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 4 | let color = vec4(0.5); 5 | textureStore(buffer_a, location, color); 6 | } -------------------------------------------------------------------------------- /examples/fire/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/fire/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/fire/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/fire/common.wgsl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliotbo/bevy_shadertoy_wgsl/e3221a81dd6f1668d7d6695f06353b373db47979/examples/fire/common.wgsl -------------------------------------------------------------------------------- /examples/fire/image.wgsl: -------------------------------------------------------------------------------- 1 | // https://www.shadertoy.com/view/XsXSWS 2 | // no licence 3 | 4 | fn hash(p: vec2) -> vec2 { 5 | var p_var = p; 6 | p_var = vec2(dot(p_var, vec2(127.1, 311.7)), dot(p_var, vec2(269.5, 183.3))); 7 | return -1. + 2. * fract(sin(p_var) * 43758.547); 8 | } 9 | 10 | fn noise(p: vec2) -> f32 { 11 | let K1: f32 = 0.36602542; 12 | let K2: f32 = 0.21132487; 13 | let i: vec2 = floor(p + (p.x + p.y) * K1); 14 | var a: vec2 = p - i + (i.x + i.y) * K2; 15 | var o: vec2; 16 | if (a.x > a.y) { o = vec2(1., 0.); } else { o = vec2(0., 1.); }; 17 | let b: vec2 = a - o + K2; 18 | var c: vec2 = a - 1. + 2. * K2; 19 | let h: vec3 = max(0.5 - vec3(dot(a, a), dot(b, b), dot(c, c)), vec3(0.)); 20 | var n: vec3 = h * h * h * h * vec3(dot(a, hash(i + 0.)), dot(b, hash(i + o)), dot(c, hash(i + 1.))); 21 | return dot(n, vec3(70.)); 22 | } 23 | 24 | fn fbm(uv_in: vec2) -> f32 { 25 | var f: f32; 26 | var uv = uv_in; 27 | let m: mat2x2 = mat2x2(1.6, 1.2, -1.2, 1.6); 28 | f = 0.5 * noise(uv); 29 | uv = m * uv; 30 | f = f + (0.25 * noise(uv)); 31 | uv = m * uv; 32 | f = f + (0.125 * noise(uv)); 33 | uv = m * uv; 34 | f = f + (0.0625 * noise(uv)); 35 | uv = m * uv; 36 | f = 0.5 + 0.5 * f; 37 | return f; 38 | } 39 | 40 | @compute @workgroup_size(8, 8, 1) 41 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 42 | let R: vec2 = uni.iResolution.xy; 43 | let y_inverted_location = vec2(i32(invocation_id.x), i32(R.y) - i32(invocation_id.y)); 44 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 45 | 46 | var fragColor: vec4; 47 | var fragCoord = vec2(f32(location.x), f32(location.y) ); 48 | let uv: vec2 = fragCoord.xy / uni.iResolution.xy; 49 | var q: vec2 = uv; 50 | q.x = q.x * (5.); 51 | q.y = q.y * (2.); 52 | let strength: f32 = floor(q.x + 1.); 53 | let T3: f32 = max(3., 1.25 * strength) * uni.iTime; 54 | q.x = (q.x % 1.) - 0.5; 55 | q.y = q.y - (0.25); 56 | let n: f32 = fbm(strength * q - vec2(0., T3)); 57 | let c: f32 = 1. - 16. * pow(max(0., length(q * vec2(1.8 + q.y * 1.5, 0.75)) - n * max(0., q.y + 0.25)), 1.2); 58 | var c1: f32 = n * c * (1.5 - pow(2.5 * uv.y, 4.)); 59 | c1 = clamp(c1, 0., 1.); 60 | let col: vec3 = vec3(1.5 * c1, 1.5 * c1 * c1 * c1, c1 * c1 * c1 * c1 * c1 * c1); 61 | let a: f32 = c * (1. - pow(uv.y, 3.)); 62 | fragColor = vec4(mix(vec3(0.), col, a), 1.); 63 | 64 | textureStore(texture, y_inverted_location, fragColor); 65 | } 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /examples/fire2/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | @compute @workgroup_size(8, 8, 1) 4 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 5 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 6 | let color = vec4(0.5); 7 | textureStore(buffer_a, location, color); 8 | } -------------------------------------------------------------------------------- /examples/fire2/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/fire2/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/fire2/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/fire2/common.wgsl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliotbo/bevy_shadertoy_wgsl/e3221a81dd6f1668d7d6695f06353b373db47979/examples/fire2/common.wgsl -------------------------------------------------------------------------------- /examples/fire2/fire2.rs: -------------------------------------------------------------------------------- 1 | // https://www.shadertoy.com/view/MlKSWm 2 | // by Ian McEwan, Ashima Arts. 3 | // MIT License 4 | 5 | use bevy::{ 6 | diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, 7 | prelude::*, 8 | }; 9 | 10 | use bevy_shadertoy_wgsl::*; 11 | 12 | fn main() { 13 | let mut app = App::new(); 14 | 15 | app.insert_resource(ClearColor(Color::GRAY)) 16 | .insert_resource(WindowDescriptor { 17 | width: 960., 18 | height: 600., 19 | cursor_visible: true, 20 | // present_mode: PresentMode::Immediate, // uncomment for unthrottled FPS 21 | ..default() 22 | }) 23 | .insert_resource(ShadertoyCanvas { 24 | width: 960. as u32, 25 | height: 600.0 as u32, 26 | borders: 0., 27 | position: Vec3::new(0.0, 0.0, 0.0), 28 | }) 29 | .add_plugins(DefaultPlugins) 30 | .add_plugin(ShadertoyPlugin) 31 | .add_plugin(FrameTimeDiagnosticsPlugin::default()) 32 | .add_plugin(LogDiagnosticsPlugin::default()) 33 | .add_startup_system(setup) 34 | .run(); 35 | } 36 | 37 | fn setup( 38 | mut commands: Commands, 39 | asset_server: Res, 40 | mut st_res: ResMut, 41 | ) { 42 | let example = "fire2"; 43 | st_res.include_debugger = false; 44 | 45 | let all_shader_handles: ShaderHandles = 46 | make_and_load_shaders2(example, &asset_server, st_res.include_debugger); 47 | 48 | commands.insert_resource(all_shader_handles); 49 | } 50 | -------------------------------------------------------------------------------- /examples/fluid/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } 5 | 6 | -------------------------------------------------------------------------------- /examples/fluid/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } 5 | 6 | -------------------------------------------------------------------------------- /examples/fluid/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | let R: vec2 = uni.iResolution.xy; 4 | let y_inverted_location = vec2(i32(invocation_id.x), i32(R.y) - i32(invocation_id.y)); 5 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 6 | 7 | var fragColor: vec4; 8 | var fragCoord = vec2(f32(location.x), f32(location.y) ); 9 | 10 | var p: vec4 = textureLoad(buffer_d, vec2(fragCoord)); 11 | if (uni.iMouse.z > 0.) { 12 | if (p.z > 0.) { 13 | fragColor = vec4(uni.iMouse.xy, p.xy); 14 | } else { 15 | fragColor = vec4(uni.iMouse.xy, uni.iMouse.xy); 16 | } 17 | } else { 18 | fragColor = vec4(-uni.iResolution.xy, -uni.iResolution.xy); 19 | } 20 | 21 | textureStore(buffer_d, location, fragColor); 22 | } 23 | 24 | -------------------------------------------------------------------------------- /examples/fluid/common.wgsl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliotbo/bevy_shadertoy_wgsl/e3221a81dd6f1668d7d6695f06353b373db47979/examples/fluid/common.wgsl -------------------------------------------------------------------------------- /examples/fluid/fluid.rs: -------------------------------------------------------------------------------- 1 | // https://www.shadertoy.com/view/XtGcDK 2 | // by Wyatt 3 | // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License 4 | 5 | use bevy::{ 6 | diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, 7 | prelude::*, 8 | window::PresentMode, 9 | }; 10 | 11 | use bevy_shadertoy_wgsl::*; 12 | 13 | fn main() { 14 | let mut app = App::new(); 15 | 16 | app.insert_resource(ClearColor(Color::GRAY)) 17 | .insert_resource(WindowDescriptor { 18 | width: 960., 19 | height: 600., 20 | cursor_visible: true, 21 | present_mode: PresentMode::Immediate, // uncomment for unthrottled FPS 22 | ..default() 23 | }) 24 | .insert_resource(ShadertoyCanvas { 25 | width: (960.0_f32 * 1.0).floor() as u32, 26 | height: (600.0_f32 * 1.0).floor() as u32, 27 | borders: 0., 28 | position: Vec3::new(0.0, 0.0, 0.0), 29 | }) 30 | .add_plugins(DefaultPlugins) 31 | .add_plugin(ShadertoyPlugin) 32 | .add_plugin(FrameTimeDiagnosticsPlugin::default()) 33 | .add_plugin(LogDiagnosticsPlugin::default()) 34 | .add_startup_system(setup) 35 | // .add_system(update_common_uniform) 36 | .run(); 37 | } 38 | 39 | fn setup( 40 | mut commands: Commands, 41 | asset_server: Res, 42 | mut st_res: ResMut, 43 | ) { 44 | let example = "fluid"; 45 | st_res.include_debugger = false; 46 | 47 | let all_shader_handles: ShaderHandles = 48 | make_and_load_shaders2(example, &asset_server, st_res.include_debugger); 49 | 50 | commands.insert_resource(all_shader_handles); 51 | } 52 | -------------------------------------------------------------------------------- /examples/fluid/image.wgsl: -------------------------------------------------------------------------------- 1 | fn t(v: vec2) -> vec4 { 2 | return textureLoad(buffer_a, vec2(v )); 3 | } 4 | 5 | fn toLinear(sRGB: vec4) -> vec4 { 6 | let cutoff = vec4(sRGB < vec4(0.04045)); 7 | let higher = pow((sRGB + vec4(0.055)) / vec4(1.055), vec4(2.4)); 8 | let lower = sRGB / vec4(12.92); 9 | 10 | return mix(higher, lower, cutoff); 11 | } 12 | 13 | @compute @workgroup_size(8, 8, 1) 14 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 15 | let R: vec2 = uni.iResolution.xy; 16 | let y_inverted_location = vec2(i32(invocation_id.x), i32(R.y) - i32(invocation_id.y)); 17 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 18 | 19 | var C: vec4; 20 | let U = vec2( f32(location.x), f32(location.y) ); 21 | 22 | var me: vec4 = t(U); 23 | me.z = me.z - (1.); 24 | C = 1. - 3. * me.wwww; 25 | 26 | let d: vec3 = vec3( 27 | t(U + vec2(1., 0.)).w - t(U - vec2(1., 0.)).w, 28 | t(U + vec2(0., 1.)).w - t(U - vec2(0., 1.)).w, 29 | 2. 30 | ); 31 | 32 | var Cxyz = C.xyz; 33 | Cxyz = C.xyz - ( 34 | max( 35 | vec3(0.), 36 | sin(vec3( 37 | 100. * length(me.xy), 38 | -5. * me.z, 39 | 368. * d.y 40 | ) * me.w) 41 | )); 42 | 43 | C.x = Cxyz.x; 44 | C.y = Cxyz.y; 45 | C.z = Cxyz.z; 46 | C.a = 1.; 47 | 48 | // let col_debug_info = show_debug_info(location, C.xyz); 49 | 50 | // textureStore(texture, y_inverted_location, toLinear(col_debug_info)); 51 | 52 | textureStore(texture, y_inverted_location, (C)); 53 | // textureStore(texture, y_inverted_location, t(U)); 54 | } -------------------------------------------------------------------------------- /examples/liquid_toy/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/liquid_toy/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/liquid_toy/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/liquid_toy/common.wgsl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliotbo/bevy_shadertoy_wgsl/e3221a81dd6f1668d7d6695f06353b373db47979/examples/liquid_toy/common.wgsl -------------------------------------------------------------------------------- /examples/liquid_toy/liquid_toy.rs: -------------------------------------------------------------------------------- 1 | // Original shader by leon 2 | // https://www.shadertoy.com/view/fljBWc 3 | // Attribution-NonCommercial 2.0 Generic (CC BY-NC 2.0) 4 | 5 | use bevy::{ 6 | diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, 7 | prelude::*, 8 | // window::PresentMode, 9 | }; 10 | 11 | use bevy_shadertoy_wgsl::*; 12 | 13 | fn main() { 14 | let mut app = App::new(); 15 | 16 | app.insert_resource(ClearColor(Color::GRAY)) 17 | .insert_resource(WindowDescriptor { 18 | width: 960., 19 | height: 600., 20 | cursor_visible: true, 21 | // present_mode: PresentMode::Immediate, // uncomment for unthrottled FPS 22 | ..default() 23 | }) 24 | .insert_resource(ShadertoyCanvas { 25 | width: 960. as u32, 26 | height: 600.0 as u32, 27 | borders: 0.0, 28 | position: Vec3::new(0.0, 0.0, 0.0), 29 | }) 30 | .add_plugins(DefaultPlugins) 31 | .add_plugin(ShadertoyPlugin) 32 | .add_plugin(FrameTimeDiagnosticsPlugin::default()) 33 | .add_plugin(LogDiagnosticsPlugin::default()) 34 | .add_startup_system(setup) 35 | .run(); 36 | } 37 | 38 | fn setup( 39 | mut commands: Commands, 40 | asset_server: Res, 41 | mut st_res: ResMut, 42 | ) { 43 | let example = "liquid_toy"; 44 | st_res.include_debugger = false; 45 | 46 | let all_shader_handles: ShaderHandles = 47 | make_and_load_shaders2(example, &asset_server, st_res.include_debugger); 48 | 49 | commands.insert_resource(all_shader_handles); 50 | } 51 | -------------------------------------------------------------------------------- /examples/minimal/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 4 | let color = vec4(0.5); 5 | textureStore(buffer_a, location, color); 6 | } -------------------------------------------------------------------------------- /examples/minimal/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/minimal/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/minimal/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/minimal/common.wgsl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliotbo/bevy_shadertoy_wgsl/e3221a81dd6f1668d7d6695f06353b373db47979/examples/minimal/common.wgsl -------------------------------------------------------------------------------- /examples/minimal/image.wgsl: -------------------------------------------------------------------------------- 1 | // displays a gray screen by setting the color in buffer_a.wglsl and loading buffer_a 2 | // here 3 | 4 | @compute @workgroup_size(8, 8, 1) 5 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 6 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 7 | 8 | var O: vec4 = textureLoad(buffer_a, location); 9 | textureStore(texture, location, O); 10 | } -------------------------------------------------------------------------------- /examples/minimal/minimal.rs: -------------------------------------------------------------------------------- 1 | use bevy::{ 2 | diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, 3 | prelude::*, 4 | }; 5 | 6 | use bevy_shadertoy_wgsl::*; 7 | 8 | fn main() { 9 | let mut app = App::new(); 10 | 11 | app.insert_resource(ClearColor(Color::GRAY)) 12 | .insert_resource(WindowDescriptor { 13 | width: 960., 14 | height: 600., 15 | cursor_visible: true, 16 | // present_mode: PresentMode::Immediate, // uncomment for unthrottled FPS 17 | ..default() 18 | }) 19 | .insert_resource(ShadertoyCanvas { 20 | width: 960. as u32, 21 | height: 600.0 as u32, 22 | borders: 0.0, 23 | position: Vec3::new(0.0, 0.0, 0.0), 24 | }) 25 | .add_plugins(DefaultPlugins) 26 | .add_plugin(ShadertoyPlugin) 27 | .add_plugin(FrameTimeDiagnosticsPlugin::default()) 28 | .add_plugin(LogDiagnosticsPlugin::default()) 29 | .add_startup_system(setup) 30 | .run(); 31 | } 32 | 33 | fn setup( 34 | mut commands: Commands, 35 | asset_server: Res, 36 | mut st_res: ResMut, 37 | ) { 38 | let example = "minimal"; 39 | st_res.include_debugger = false; 40 | 41 | let all_shader_handles: ShaderHandles = 42 | make_and_load_shaders2(example, &asset_server, st_res.include_debugger); 43 | 44 | commands.insert_resource(all_shader_handles); 45 | } 46 | -------------------------------------------------------------------------------- /examples/paint/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/paint/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/paint/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/paint/common.wgsl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliotbo/bevy_shadertoy_wgsl/e3221a81dd6f1668d7d6695f06353b373db47979/examples/paint/common.wgsl -------------------------------------------------------------------------------- /examples/paint/image.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | let R: vec2 = uni.iResolution.xy; 4 | let y_inverted_location = vec2(i32(invocation_id.x), i32(R.y) - i32(invocation_id.y)); 5 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 6 | 7 | // let location2 = vec2(i32(R.x) - i32(invocation_id.x), i32(invocation_id.y)); 8 | 9 | var alive = true; 10 | 11 | var q: f32; 12 | if (true) { 13 | q = 1.; 14 | } else { 15 | q = 4.; 16 | }; 17 | 18 | var O: vec4 = mix(textureLoad(buffer_a, location),vec4(0.5), 0.1); 19 | 20 | // var O: vec4 = vec4(0.5); 21 | 22 | textureStore(texture, y_inverted_location, O); 23 | } -------------------------------------------------------------------------------- /examples/paint/paint.rs: -------------------------------------------------------------------------------- 1 | use bevy::{ 2 | diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, 3 | prelude::*, 4 | window::PresentMode, 5 | }; 6 | 7 | use bevy_shadertoy_wgsl::*; 8 | 9 | fn main() { 10 | let mut app = App::new(); 11 | 12 | app.insert_resource(ClearColor(Color::GRAY)) 13 | .insert_resource(WindowDescriptor { 14 | width: 960., 15 | height: 600., 16 | cursor_visible: true, 17 | present_mode: PresentMode::Immediate, // uncomment for unthrottled FPS 18 | ..default() 19 | }) 20 | .insert_resource(ShadertoyCanvas { 21 | width: 960. as u32, 22 | height: 600.0 as u32, 23 | borders: 0.2, 24 | position: Vec3::new(0.0, 0.0, 0.0), 25 | }) 26 | .add_plugins(DefaultPlugins) 27 | .add_plugin(ShadertoyPlugin) 28 | .add_plugin(FrameTimeDiagnosticsPlugin::default()) 29 | .add_plugin(LogDiagnosticsPlugin::default()) 30 | .add_startup_system(setup) 31 | .run(); 32 | } 33 | 34 | fn setup( 35 | mut commands: Commands, 36 | asset_server: Res, 37 | mut st_res: ResMut, 38 | ) { 39 | let example = "paint"; 40 | st_res.include_debugger = false; 41 | 42 | let all_shader_handles: ShaderHandles = 43 | make_and_load_shaders2(example, &asset_server, st_res.include_debugger); 44 | 45 | commands.insert_resource(all_shader_handles); 46 | } 47 | -------------------------------------------------------------------------------- /examples/paint_streams/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | fn Reintegration(ch: texture_storage_2d, pos: vec2) -> particle { 2 | 3 | var P: particle = particle(vec2(0.0), vec2(0.0), vec2(0.0)); 4 | for (var i: i32 = -2; i <= 2; i = i + 1) { 5 | for (var j: i32 = -2; j <= 2; j = j + 1) { 6 | let tpos: vec2 = pos + vec2(f32(i), f32(j)); 7 | 8 | 9 | let data: vec4 = textureLoad(ch, vec2(tpos)); 10 | 11 | var P0: particle = getParticle(data, tpos); 12 | 13 | P0.X = P0.X + (P0.V * dt); //integrate position 14 | 15 | let difR: f32 = 0.9 + 0.21 * smoothstep(fluid_rho * 0., fluid_rho * 0.333, P0.M.x); 16 | 17 | let D: vec3 = distribution(P0.X, pos, difR); 18 | let m: f32 = P0.M.x * D.z; 19 | P.X = P.X + (D.xy * m); 20 | P.V = P.V + (P0.V * m); 21 | P.M.y = P.M.y + (P0.M.y * m); 22 | P.M.x = P.M.x + (m); 23 | } 24 | } 25 | 26 | 27 | if (P.M.x > 0.0000001) { 28 | P.X = P.X / (P.M.x); 29 | P.V = P.V / (P.M.x); 30 | P.M.y = P.M.y / (P.M.x); 31 | } 32 | 33 | return P; 34 | } 35 | 36 | 37 | @compute @workgroup_size(8, 8, 1) 38 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 39 | let R: vec2 = uni.iResolution.xy; 40 | // let y_inverted_location = vec2(i32(invocation_id.x), i32(R.y) - i32(invocation_id.y)); 41 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 42 | 43 | var U: vec4; 44 | var pos = vec2(f32(location.x), f32(location.y)); 45 | 46 | // R = uni.iResolution.xy; 47 | // time = uni.iTime; 48 | // Mouse = uni.iMouse; 49 | // let p: vec2 = vec2(pos); 50 | // let data: vec4 = texel(ch0, pos); 51 | // var P: particle; 52 | var P: particle = Reintegration(buffer_b, pos); 53 | 54 | // if (uni.iFrame < 1) { 55 | #ifdef INIT 56 | let rand: vec3 = hash32(pos); 57 | 58 | if (rand.z < 0.) { 59 | P.X = pos; 60 | P.V = 0.5 * (rand.xy - 0.5) + vec2(0., 0.); 61 | P.M = vec2(mass, 0.); 62 | } else { 63 | 64 | P.X = pos; 65 | P.V = vec2(0.); 66 | P.M = vec2(0.000001); 67 | } 68 | #endif 69 | // } 70 | 71 | U = saveParticle(P, pos); 72 | // U = clamp(U, vec4(0.), vec4(1.)); 73 | textureStore(buffer_a, location, U); 74 | } 75 | -------------------------------------------------------------------------------- /examples/paint_streams/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | R = uni.iResolution.xy; 4 | 5 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 6 | 7 | var fragColor: vec4; 8 | var pos = vec2(f32(location.x), f32(location.y)); 9 | 10 | // R = uni.iResolution.xy; 11 | time = uni.iTime; 12 | let p: vec2 = vec2(pos); 13 | // let data: vec4 = texel(ch0, pos); 14 | let data: vec4 = textureLoad(buffer_a, location); 15 | 16 | var P: particle = getParticle(data, pos); 17 | var rho: vec4 = vec4(0.); 18 | 19 | for (var i: i32 = -1; i <= 1; i = i + 1) { 20 | for (var j: i32 = -1; j <= 1; j = j + 1) { 21 | let ij: vec2 = vec2(i, j); 22 | // let data: vec4 = texel(ch0, pos + ij); 23 | let data: vec4 = textureLoad(buffer_a, location + ij); 24 | 25 | var P0: particle = getParticle(data, pos + vec2(ij)); 26 | let x0: vec2 = P0.X; 27 | rho = rho + (1. * vec4(P.V, P.M) * G((pos - x0) / 0.75)); 28 | } 29 | } 30 | 31 | // fragColor = rho;d 32 | // rho = clamp(rho, vec4(0.), vec4(1.)); 33 | textureStore(buffer_c, location, rho); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /examples/paint_streams/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/paint_streams/paint_streams.rs: -------------------------------------------------------------------------------- 1 | // https://www.shadertoy.com/view/WtfyDj 2 | // by michael0884 3 | // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License 4 | 5 | use bevy::{ 6 | app::ScheduleRunnerSettings, 7 | diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, 8 | prelude::*, 9 | utils::Duration, 10 | window::PresentMode, 11 | }; 12 | 13 | use bevy_shadertoy_wgsl::*; 14 | 15 | fn main() { 16 | let mut app = App::new(); 17 | 18 | app.insert_resource(ScheduleRunnerSettings::run_loop(Duration::from_secs_f64( 19 | 1.0 / 120.0, 20 | ))) 21 | .insert_resource(ClearColor(Color::GRAY)) 22 | .insert_resource(WindowDescriptor { 23 | width: 960., 24 | height: 600., 25 | cursor_visible: true, 26 | present_mode: PresentMode::Immediate, // uncomment for unthrottled FPS 27 | ..default() 28 | }) 29 | .insert_resource(ShadertoyCanvas { 30 | width: 960. as u32, 31 | height: 600.0 as u32, 32 | borders: 0.0, 33 | position: Vec3::new(0.0, 0.0, 0.0), 34 | }) 35 | .add_plugins(DefaultPlugins) 36 | .add_plugin(ShadertoyPlugin) 37 | .add_plugin(FrameTimeDiagnosticsPlugin::default()) 38 | .add_plugin(LogDiagnosticsPlugin::default()) 39 | .add_startup_system(setup) 40 | .add_system(match_window_size) 41 | .add_system(limit_fps) 42 | .run(); 43 | } 44 | 45 | fn setup( 46 | mut commands: Commands, 47 | asset_server: Res, 48 | mut st_res: ResMut, 49 | ) { 50 | let example = "paint_streams"; 51 | st_res.include_debugger = true; 52 | 53 | let all_shader_handles: ShaderHandles = 54 | make_and_load_shaders2(example, &asset_server, st_res.include_debugger); 55 | 56 | commands.insert_resource(all_shader_handles); 57 | } 58 | 59 | fn match_window_size(windows: Res, mut canvas: ResMut) { 60 | let window = windows.get_primary().unwrap(); 61 | canvas.width = window.width() as u32; 62 | canvas.height = window.height() as u32; 63 | } 64 | 65 | use std::{thread, time}; 66 | 67 | fn limit_fps() { 68 | thread::sleep(time::Duration::from_millis(5)); 69 | } 70 | -------------------------------------------------------------------------------- /examples/protean_clouds/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 4 | 5 | } -------------------------------------------------------------------------------- /examples/protean_clouds/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/protean_clouds/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/protean_clouds/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/protean_clouds/common.wgsl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliotbo/bevy_shadertoy_wgsl/e3221a81dd6f1668d7d6695f06353b373db47979/examples/protean_clouds/common.wgsl -------------------------------------------------------------------------------- /examples/protean_clouds/protean_clouds.rs: -------------------------------------------------------------------------------- 1 | // https://www.shadertoy.com/view/3l23Rh 2 | // by nimitz 3 | // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License 4 | 5 | use bevy::{ 6 | diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, 7 | prelude::*, 8 | }; 9 | 10 | use bevy_shadertoy_wgsl::*; 11 | 12 | fn main() { 13 | let mut app = App::new(); 14 | 15 | app.insert_resource(ClearColor(Color::GRAY)) 16 | .insert_resource(WindowDescriptor { 17 | width: 960., 18 | height: 600., 19 | cursor_visible: true, 20 | // present_mode: PresentMode::Immediate, // uncomment for unthrottled FPS 21 | ..default() 22 | }) 23 | .insert_resource(ShadertoyCanvas { 24 | width: 960. as u32, 25 | height: 600.0 as u32, 26 | borders: 0.2, 27 | position: Vec3::new(0.0, 0.0, 0.0), 28 | }) 29 | .add_plugins(DefaultPlugins) 30 | .add_plugin(ShadertoyPlugin) 31 | .add_plugin(FrameTimeDiagnosticsPlugin::default()) 32 | .add_plugin(LogDiagnosticsPlugin::default()) 33 | .add_startup_system(setup) 34 | .run(); 35 | } 36 | 37 | fn setup( 38 | mut commands: Commands, 39 | asset_server: Res, 40 | mut st_res: ResMut, 41 | ) { 42 | let example = "protean_clouds"; 43 | st_res.include_debugger = false; 44 | 45 | let all_shader_handles: ShaderHandles = 46 | make_and_load_shaders2(example, &asset_server, st_res.include_debugger); 47 | 48 | commands.insert_resource(all_shader_handles); 49 | } 50 | -------------------------------------------------------------------------------- /examples/seascape/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | 2 | @compute @workgroup_size(8, 8, 1) 3 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 4 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 5 | let color = vec4(0.5); 6 | textureStore(buffer_a, location, color); 7 | } -------------------------------------------------------------------------------- /examples/seascape/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/seascape/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/seascape/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/seascape/common.wgsl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliotbo/bevy_shadertoy_wgsl/e3221a81dd6f1668d7d6695f06353b373db47979/examples/seascape/common.wgsl -------------------------------------------------------------------------------- /examples/seascape/seascape.rs: -------------------------------------------------------------------------------- 1 | // https://www.shadertoy.com/view/Ms2SD1 2 | // by TDM 3 | // License: Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. 4 | 5 | use bevy::{ 6 | diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, 7 | prelude::*, 8 | }; 9 | 10 | use bevy_shadertoy_wgsl::*; 11 | 12 | fn main() { 13 | let mut app = App::new(); 14 | 15 | app.insert_resource(ClearColor(Color::GRAY)) 16 | .insert_resource(WindowDescriptor { 17 | width: 960., 18 | height: 600., 19 | cursor_visible: true, 20 | // present_mode: PresentMode::Immediate, // uncomment for unthrottled FPS 21 | ..default() 22 | }) 23 | .insert_resource(ShadertoyCanvas { 24 | width: 960. as u32, 25 | height: 600.0 as u32, 26 | borders: 0.2, 27 | position: Vec3::new(0.0, 0.0, 0.0), 28 | }) 29 | .add_plugins(DefaultPlugins) 30 | .add_plugin(ShadertoyPlugin) 31 | .add_plugin(FrameTimeDiagnosticsPlugin::default()) 32 | .add_plugin(LogDiagnosticsPlugin::default()) 33 | .add_startup_system(setup) 34 | .run(); 35 | } 36 | 37 | fn setup( 38 | mut commands: Commands, 39 | asset_server: Res, 40 | mut st_res: ResMut, 41 | ) { 42 | let example = "seascape"; 43 | st_res.include_debugger = false; 44 | 45 | let all_shader_handles: ShaderHandles = 46 | make_and_load_shaders2(example, &asset_server, st_res.include_debugger); 47 | 48 | commands.insert_resource(all_shader_handles); 49 | } 50 | -------------------------------------------------------------------------------- /examples/simpler_particles/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | // RUST_LOG="wgpu=error,naga=warn,info" cargo run --release --example simpler_particles 2 | 3 | fn Integrate( 4 | ch: texture_storage_2d, 5 | P: ptr, 6 | pos: vec2 7 | ) { 8 | var I: i32 = 3; 9 | 10 | for (var i: i32 = -I; i <= I; i = i + 1) { 11 | for (var j: i32 = -I; j <= I; j = j + 1) { 12 | let tpos: vec2 = pos + vec2(f32(i), f32(j)); 13 | let data: vec4 = textureLoad(ch, vec2(tpos)); 14 | 15 | if (tpos.x < 0. || tpos.y < 0.) { continue; } 16 | 17 | var P0: particle = getParticle(data, tpos); 18 | 19 | if ( 20 | (P0.NX.x >= pos.x - 0.5 && P0.NX.x < pos.x + 0.5) 21 | && (P0.NX.y >= pos.y - 0.5) 22 | && (P0.NX.y < pos.y + 0.5) 23 | && (P0.M > 0.5) 24 | ) { 25 | var P0V: vec2 = (P0.NX - P0.X) / 2.; 26 | 27 | if (uni.iMouse.z > 0.) { 28 | let dm: vec2 = P0.NX - uni.iMouse.xy; 29 | let d: f32 = length(dm / 50.); 30 | P0V = P0V + (normalize(dm) * exp(-d * d) * 0.3); 31 | } 32 | 33 | P0V = P0V + (vec2(0., -0.005)); 34 | let v: f32 = length(P0V); 35 | var denom = 1.; 36 | if (v > 1.) { denom = v; } 37 | P0V = P0V / denom; 38 | P0.X = P0.NX; 39 | P0.NX = P0.NX + P0V * 2.; 40 | (*P) = P0; 41 | 42 | break; 43 | } 44 | } 45 | 46 | } 47 | 48 | } 49 | 50 | 51 | 52 | @compute @workgroup_size(8, 8, 1) 53 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 54 | // let R: vec2 = uni.iResolution.xy; 55 | let y_inverted_location = vec2(i32(invocation_id.x), i32(R.y) - i32(invocation_id.y)); 56 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 57 | 58 | // var U: vec4; 59 | var pos = vec2(f32(location.x), f32(location.y) ); 60 | 61 | R = uni.iResolution.xy; 62 | rng_initialize(pos, i32(uni.iFrame)); 63 | var P: particle; 64 | 65 | Integrate(buffer_d, &P, pos); 66 | 67 | // if (uni.iFrame == 0) { 68 | #ifdef INIT 69 | if (rand() > 0.992) { 70 | P.X = pos; 71 | P.NX = pos + (rand2() - 0.5) * 0.; 72 | let r: f32 = pow(rand(), 2.); 73 | P.M = mix(1., 4., r); 74 | P.R = mix(1., particle_size * 0.5, r); 75 | } else { 76 | P.X = pos; 77 | P.NX = pos; 78 | P.M = 0.; 79 | P.R = particle_size * 0.5; 80 | } 81 | // } 82 | #endif 83 | 84 | let U = saveParticle(P, pos); 85 | textureStore(buffer_a, location, U); 86 | 87 | } 88 | 89 | 90 | -------------------------------------------------------------------------------- /examples/simpler_particles/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | @compute @workgroup_size(8, 8, 1) 4 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 5 | // let R: vec2 = uni.iResolution.xy; 6 | let y_inverted_location = vec2(i32(invocation_id.x), i32(R.y) - i32(invocation_id.y)); 7 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 8 | 9 | // var U: vec4; 10 | var pos = vec2(f32(location.x), f32(location.y) ); 11 | 12 | R = uni.iResolution.xy; 13 | time = uni.iTime; 14 | Mouse = uni.iMouse; 15 | let data: vec4 = textureLoad(buffer_a, vec2(pos)); 16 | var P: particle = getParticle(data, pos); 17 | 18 | if (P.M > 0.) { Simulation(buffer_a, &P, pos); } 19 | 20 | let U = saveParticle(P, pos); 21 | textureStore(buffer_b, location, U); 22 | } 23 | 24 | -------------------------------------------------------------------------------- /examples/simpler_particles/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | // let R: vec2 = uni.iResolution.xy; 4 | // let y_inverted_location = vec2(i32(invocation_id.x), i32(R.y) - i32(invocation_id.y)); 5 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 6 | 7 | // var U: vec4; 8 | var pos = vec2(f32(location.x), f32(location.y) ); 9 | 10 | R = uni.iResolution.xy; 11 | time = uni.iTime; 12 | Mouse = uni.iMouse; 13 | let data: vec4 = textureLoad(buffer_b, vec2(pos)); 14 | var P: particle = getParticle(data, pos); 15 | if (P.M > 0.) { Simulation(buffer_b, &P, pos); } 16 | 17 | let U = saveParticle(P, pos); 18 | textureStore(buffer_c, location, U); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /examples/simpler_particles/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | // let R: vec2 = uni.iResolution.xy; 4 | // let y_inverted_location = vec2(i32(invocation_id.x), i32(R.y) - i32(invocation_id.y)); 5 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 6 | 7 | // var U: vec4; 8 | var pos = vec2(f32(location.x), f32(location.y) ); 9 | 10 | R = uni.iResolution.xy; 11 | time = uni.iTime; 12 | Mouse = uni.iMouse; 13 | let data: vec4 = textureLoad(buffer_c, vec2(pos)); 14 | var P: particle = getParticle(data, pos); 15 | 16 | if (P.M > 0.) { Simulation(buffer_c, &P, pos); } 17 | 18 | let U = saveParticle(P, pos); 19 | textureStore(buffer_d, location, U); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /examples/simpler_particles/simpler_particles.rs: -------------------------------------------------------------------------------- 1 | // https://www.shadertoy.com/view/Ms2SD1 2 | // by TDM 3 | // License: Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. 4 | 5 | use bevy::{ 6 | diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, 7 | prelude::*, 8 | }; 9 | 10 | use bevy_shadertoy_wgsl::*; 11 | 12 | mod fps; 13 | 14 | fn main() { 15 | let mut app = App::new(); 16 | 17 | app.insert_resource(ClearColor(Color::GRAY)) 18 | .insert_resource(WindowDescriptor { 19 | // width: 960., 20 | // height: 600., 21 | width: 1200., 22 | height: 800., 23 | cursor_visible: true, 24 | present_mode: bevy::window::PresentMode::Immediate, // uncomment for unthrottled FPS 25 | ..default() 26 | }) 27 | .insert_resource(ShadertoyCanvas { 28 | // width: 960. as u32, 29 | // height: 600.0 as u32, 30 | width: 1200, 31 | height: 800, 32 | borders: 0.02, 33 | position: Vec3::new(0.0, 0.0, 0.0), 34 | }) 35 | .add_plugin(fps::FPSPlugin) 36 | .add_plugins(DefaultPlugins) 37 | .add_plugin(ShadertoyPlugin) 38 | .add_plugin(FrameTimeDiagnosticsPlugin::default()) 39 | .add_plugin(LogDiagnosticsPlugin::default()) 40 | .add_startup_system(setup) 41 | .run(); 42 | } 43 | 44 | fn setup( 45 | mut commands: Commands, 46 | asset_server: Res, 47 | mut st_res: ResMut, 48 | ) { 49 | let example = "simpler_particles"; 50 | st_res.include_debugger = false; 51 | 52 | let all_shader_handles: ShaderHandles = 53 | make_and_load_shaders2(example, &asset_server, st_res.include_debugger); 54 | 55 | commands.insert_resource(all_shader_handles); 56 | } 57 | -------------------------------------------------------------------------------- /examples/soul/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 4 | let color = vec4(0.5); 5 | textureStore(buffer_a, location, color); 6 | } -------------------------------------------------------------------------------- /examples/soul/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/soul/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/soul/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/soul/common.wgsl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliotbo/bevy_shadertoy_wgsl/e3221a81dd6f1668d7d6695f06353b373db47979/examples/soul/common.wgsl -------------------------------------------------------------------------------- /examples/soul/soul.rs: -------------------------------------------------------------------------------- 1 | // Original shader by leon 2 | // https://www.shadertoy.com/view/3ltyRB 3 | // Attribution-NonCommercial 2.0 Generic (CC BY-NC 2.0) 4 | 5 | use bevy::{ 6 | diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, 7 | prelude::*, 8 | window::PresentMode, 9 | }; 10 | 11 | use bevy_shadertoy_wgsl::*; 12 | 13 | fn main() { 14 | let mut app = App::new(); 15 | 16 | app.insert_resource(ClearColor(Color::GRAY)) 17 | .insert_resource(WindowDescriptor { 18 | width: 960., 19 | height: 600., 20 | cursor_visible: true, 21 | present_mode: PresentMode::Immediate, // uncomment for unthrottled FPS 22 | ..default() 23 | }) 24 | .insert_resource(ShadertoyCanvas { 25 | width: 960. as u32, 26 | height: 600.0 as u32, 27 | borders: 0.0, 28 | position: Vec3::new(0.0, 0.0, 0.0), 29 | }) 30 | .add_plugins(DefaultPlugins) 31 | .add_plugin(ShadertoyPlugin) 32 | .add_plugin(FrameTimeDiagnosticsPlugin::default()) 33 | .add_plugin(LogDiagnosticsPlugin::default()) 34 | .add_startup_system(setup) 35 | .run(); 36 | } 37 | 38 | fn setup( 39 | mut commands: Commands, 40 | asset_server: Res, 41 | mut st_res: ResMut, 42 | ) { 43 | let example = "soul"; 44 | st_res.include_debugger = false; 45 | 46 | let all_shader_handles: ShaderHandles = 47 | make_and_load_shaders2(example, &asset_server, st_res.include_debugger); 48 | 49 | commands.insert_resource(all_shader_handles); 50 | } 51 | -------------------------------------------------------------------------------- /examples/sunset/buffer_a.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 4 | let color = vec4(0.5); 5 | textureStore(buffer_a, location, color); 6 | } -------------------------------------------------------------------------------- /examples/sunset/buffer_b.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/sunset/buffer_c.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/sunset/buffer_d.wgsl: -------------------------------------------------------------------------------- 1 | @compute @workgroup_size(8, 8, 1) 2 | fn update(@builtin(global_invocation_id) invocation_id: vec3) { 3 | 4 | } -------------------------------------------------------------------------------- /examples/sunset/common.wgsl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliotbo/bevy_shadertoy_wgsl/e3221a81dd6f1668d7d6695f06353b373db47979/examples/sunset/common.wgsl -------------------------------------------------------------------------------- /examples/sunset/sunset.rs: -------------------------------------------------------------------------------- 1 | // MIT License 2 | // Copyright (c) 2019 Dimas Leenman 3 | 4 | use bevy::{ 5 | diagnostic::{FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin}, 6 | prelude::*, 7 | }; 8 | 9 | use bevy_shadertoy_wgsl::*; 10 | 11 | fn main() { 12 | let mut app = App::new(); 13 | 14 | app.insert_resource(ClearColor(Color::GRAY)) 15 | .insert_resource(WindowDescriptor { 16 | width: 960., 17 | height: 600., 18 | cursor_visible: true, 19 | // present_mode: PresentMode::Immediate, // uncomment for unthrottled FPS 20 | ..default() 21 | }) 22 | .insert_resource(ShadertoyCanvas { 23 | width: 960. as u32, 24 | height: 600.0 as u32, 25 | borders: 0.0, 26 | position: Vec3::new(0.0, 0.0, 0.0), 27 | }) 28 | .add_plugins(DefaultPlugins) 29 | .add_plugin(ShadertoyPlugin) 30 | .add_plugin(FrameTimeDiagnosticsPlugin::default()) 31 | .add_plugin(LogDiagnosticsPlugin::default()) 32 | .add_startup_system(setup) 33 | // .add_system(update_common_uniform) 34 | .run(); 35 | } 36 | 37 | fn setup( 38 | mut commands: Commands, 39 | asset_server: Res, 40 | mut st_res: ResMut, 41 | ) { 42 | let example = "sunset"; 43 | st_res.include_debugger = false; 44 | 45 | let all_shader_handles: ShaderHandles = 46 | make_and_load_shaders2(example, &asset_server, st_res.include_debugger); 47 | 48 | commands.insert_resource(all_shader_handles); 49 | } 50 | 51 | // ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4 52 | // ffmpeg -ss 2 -t 27 -i output.mp4 -vf "fps=20,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 showcase.gif 53 | -------------------------------------------------------------------------------- /showcase.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliotbo/bevy_shadertoy_wgsl/e3221a81dd6f1668d7d6695f06353b373db47979/showcase.gif -------------------------------------------------------------------------------- /src/templates/buffer_a_template.wgsl: -------------------------------------------------------------------------------- 1 | {{COMMON_PRELUDE}} 2 | 3 | {{COMMON}} 4 | 5 | {{CODE_BLOCK}} -------------------------------------------------------------------------------- /src/templates/buffer_b_template.wgsl: -------------------------------------------------------------------------------- 1 | {{COMMON_PRELUDE}} 2 | 3 | {{COMMON}} 4 | 5 | {{CODE_BLOCK}} -------------------------------------------------------------------------------- /src/templates/buffer_c_template.wgsl: -------------------------------------------------------------------------------- 1 | {{COMMON_PRELUDE}} 2 | 3 | {{COMMON}} 4 | 5 | {{CODE_BLOCK}} -------------------------------------------------------------------------------- /src/templates/buffer_d_template.wgsl: -------------------------------------------------------------------------------- 1 | {{COMMON_PRELUDE}} 2 | 3 | {{COMMON}} 4 | 5 | {{CODE_BLOCK}} 6 | -------------------------------------------------------------------------------- /src/templates/common.wgsl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eliotbo/bevy_shadertoy_wgsl/e3221a81dd6f1668d7d6695f06353b373db47979/src/templates/common.wgsl -------------------------------------------------------------------------------- /src/templates/common_prelude.wgsl: -------------------------------------------------------------------------------- 1 | struct CommonUniform { 2 | iResolution: vec2, 3 | changed_window_size: f32, 4 | padding0: f32, 5 | 6 | iTime: f32, 7 | iTimeDelta: f32, 8 | iFrame: f32, 9 | iSampleRate: f32, 10 | 11 | iMouse: vec4, 12 | 13 | 14 | iChannelTime: vec4, 15 | iChannelResolution: vec4, 16 | iDate: vec4, 17 | }; 18 | 19 | 20 | @group(0) @binding(0) 21 | var uni: CommonUniform; 22 | 23 | @group(0) @binding(1) 24 | var buffer_a: texture_storage_2d; 25 | 26 | @group(0) @binding(2) 27 | var buffer_b: texture_storage_2d; 28 | 29 | @group(0) @binding(3) 30 | var buffer_c: texture_storage_2d; 31 | 32 | @group(0) @binding(4) 33 | var buffer_d: texture_storage_2d; 34 | 35 | -------------------------------------------------------------------------------- /src/templates/image.wgsl: -------------------------------------------------------------------------------- 1 | fn hash(value: u32) -> u32 { 2 | var state = value; 3 | state = state ^ 2747636419u; 4 | state = state * 2654435769u; 5 | state = state ^ state >> 16u; 6 | state = state * 2654435769u; 7 | state = state ^ state >> 16u; 8 | state = state * 2654435769u; 9 | return state; 10 | } 11 | fn randomFloat(value: u32) -> f32 { 12 | return f32(hash(value)) / 4294967295.0; 13 | } 14 | 15 | 16 | 17 | // fn get(location: vec2, offset_x: i32, offset_y: i32) -> i32 { 18 | // let value: vec4 = textureLoad(texture, location + vec2(offset_x, offset_y)); 19 | // return i32(value.x); 20 | // } 21 | 22 | // fn count_alive(location: vec2) -> i32 { 23 | // return get(location, -1, -1) + 24 | // get(location, -1, 0) + 25 | // get(location, -1, 1) + 26 | // get(location, 0, -1) + 27 | // get(location, 0, 1) + 28 | // get(location, 1, -1) + 29 | // get(location, 1, 0) + 30 | // get(location, 1, 1); 31 | // } 32 | 33 | [[stage(compute), workgroup_size(8, 8, 1)]] 34 | fn update([[builtin(global_invocation_id)]] invocation_id: vec3) { 35 | let location = vec2(i32(invocation_id.x), i32(invocation_id.y)); 36 | 37 | // let n_alive = count_alive(location); 38 | // let color = vec4(f32(n_alive) / 8.0); 39 | 40 | // var alive: bool; 41 | // if (n_alive == 3) { 42 | // alive = true; 43 | // } else if (n_alive == 2) { 44 | // let currently_alive = get(location, 0, 0); 45 | // alive = bool(currently_alive); 46 | // } else { 47 | // alive = false; 48 | // } 49 | 50 | var alive = true; 51 | 52 | // let value: vec4 = textureLoad(buffer_a, vec2(0,1)); 53 | // if (value.x > 0.51) { 54 | // alive = false; 55 | // } 56 | 57 | // let value: vec4 = textureLoad(buffer_b, vec2(0,1)); 58 | // if (value.x > 0.74) { 59 | // alive = false; 60 | // } 61 | 62 | // let value: vec4 = textureLoad(buffer_c, vec2(0,1)); 63 | // if (value.x > 0.61) { 64 | // alive = false; 65 | // } 66 | 67 | let value: vec4 = textureLoad(buffer_a, vec2(0,1)); 68 | if (value.x > 0.79) { 69 | alive = false; 70 | } 71 | 72 | // if (ga > 2) { 73 | // alive = true; 74 | // } 75 | 76 | // if (uni.iTime > 1.0) { 77 | // alive = false; 78 | // } 79 | 80 | // alive = false; 81 | 82 | storageBarrier(); 83 | 84 | textureStore(texture, location, vec4(f32(alive))); 85 | } -------------------------------------------------------------------------------- /src/templates/image_template.wgsl: -------------------------------------------------------------------------------- 1 | {{COMMON_PRELUDE}} 2 | 3 | @group(0) @binding(5) 4 | var texture: texture_storage_2d; 5 | 6 | // [[group(0), binding(6)]] 7 | // var font_texture: texture_storage_2d; 8 | 9 | @group(0) @binding(6) 10 | var font_texture: texture_2d; 11 | 12 | @group(0) @binding(7) 13 | var font_texture_sampler: sampler; 14 | 15 | @group(0) @binding(8) 16 | var rgba_noise_256_texture: texture_2d; 17 | 18 | @group(0) @binding(9) 19 | var rgba_noise_256_texture_sampler: sampler; 20 | 21 | @group(0) @binding(10) 22 | var blue_noise_texture: texture_2d; 23 | 24 | @group(0) @binding(11) 25 | var blue_noise_texture_sampler: sampler; 26 | 27 | 28 | {{DEBUGGER}} 29 | 30 | {{COMMON}} 31 | 32 | {{CODE_BLOCK}} --------------------------------------------------------------------------------