Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Creation shader to examples. #1105

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ jobs:
# Examples
- name: cargo check examples
if: ${{ matrix.target != 'aarch64-linux-android' }}
run: cargo check -p example-runner-ash -p example-runner-wgpu -p example-runner-cpu -p compute-shader -p mouse-shader -p simplest-shader -p sky-shader --no-default-features --features "use-installed-tools"
run: cargo check -p example-runner-ash -p example-runner-wgpu -p example-runner-cpu -p compute-shader -p mouse-shader -p simplest-shader -p creation-shader -p sky-shader --no-default-features --features "use-installed-tools"

- name: build example shaders
if: ${{ matrix.target != 'aarch64-linux-android' }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ clippy examples/runners/wgpu
clippy_no_features examples/runners/cpu
clippy_no_features examples/shaders/sky-shader
clippy_no_features examples/shaders/simplest-shader
clippy_no_features examples/shaders/creation-shader

# Custom lints

Expand Down
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"examples/shaders/reduce",
"examples/shaders/sky-shader",
"examples/shaders/simplest-shader",
"examples/shaders/creation-shader",
"examples/shaders/compute-shader",
"examples/shaders/mouse-shader",
"examples/multibuilder",
Expand Down
1 change: 1 addition & 0 deletions examples/runners/wgpu/builder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fn build_shader(path_to_crate: &str, codegen_names: bool) -> Result<(), Box<dyn
fn main() -> Result<(), Box<dyn Error>> {
build_shader("../../../shaders/sky-shader", true)?;
build_shader("../../../shaders/simplest-shader", false)?;
build_shader("../../../shaders/creation-shader", false)?;
build_shader("../../../shaders/compute-shader", false)?;
build_shader("../../../shaders/mouse-shader", false)?;
Ok(())
Expand Down
3 changes: 3 additions & 0 deletions examples/runners/wgpu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub enum RustGPUShader {
Simplest,
Sky,
Compute,
Creation,
Mouse,
}

Expand Down Expand Up @@ -138,6 +139,7 @@ fn maybe_watch(
std::env::set_var("PROFILE", env!("PROFILE"));
let crate_name = match options.shader {
RustGPUShader::Simplest => "simplest-shader",
RustGPUShader::Creation => "creation-shader",
RustGPUShader::Sky => "sky-shader",
RustGPUShader::Compute => "compute-shader",
RustGPUShader::Mouse => "mouse-shader",
Expand Down Expand Up @@ -202,6 +204,7 @@ fn maybe_watch(
wgpu::include_spirv_raw!(env!("simplest_shader.spv"))
}
RustGPUShader::Sky => wgpu::include_spirv_raw!(env!("sky_shader.spv")),
RustGPUShader::Creation => wgpu::include_spirv_raw!(env!("creation_shader.spv")),
RustGPUShader::Compute => wgpu::include_spirv_raw!(env!("compute_shader.spv")),
RustGPUShader::Mouse => wgpu::include_spirv_raw!(env!("mouse_shader.spv")),
};
Expand Down
15 changes: 15 additions & 0 deletions examples/shaders/creation-shader/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "creation-shader"
version = "0.0.0"
publish = false
authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true

[lib]
crate-type = ["dylib"]

[dependencies]
spirv-std = { workspace = true }
shared = { path = "../shared" }
60 changes: 60 additions & 0 deletions examples/shaders/creation-shader/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Ported from https://www.shadertoy.com/view/XsXXDn.
// Credits to Danilo Guanabara.

#![cfg_attr(target_arch = "spirv", no_std)]
// HACK(eddyb) can't easily see warnings otherwise from `spirv-builder` builds.
#![deny(warnings)]

use glam::{vec2, vec4, Vec2, Vec3, Vec4, Vec4Swizzles};
use shared::*;
#[allow(warnings)]
use spirv_std::num_traits::Float as _;
use spirv_std::spirv;

#[spirv(fragment)]
pub fn main_fs(
#[spirv(frag_coord)] in_frag_coord: Vec4,
#[spirv(push_constant)] constants: &ShaderConstants,
output: &mut Vec4,
) {
let t = constants.time;
let resolution = vec2(constants.width as f32, constants.height as f32);

let mut l = t;
let mut z = t;
let mut c = Vec3::ZERO;

for i in 0..3 {
let mut uv;
let mut p = in_frag_coord.xy() / resolution;
uv = p;
p -= 0.5;
p.x *= resolution.x / resolution.y;
z += 0.07;
l = p.length();
uv += p / l * (z.sin() + 1.0) * (l * 9.0 - z - z).sin().abs();

let tmp = (uv % 1.0) - 0.5;
let val = 0.01 / tmp.length();
match i {
0 => c.x = val,
1 => c.y = val,
2 => c.z = val,
_ => unreachable!(),
};
}

let tmp = c / l;

*output = vec4(tmp.x, tmp.y, tmp.z, t);
}

#[spirv(vertex)]
pub fn main_vs(#[spirv(vertex_index)] vert_idx: i32, #[spirv(position)] builtin_pos: &mut Vec4) {
// Create a "full screen triangle" by mapping the vertex index.
// ported from https://www.saschawillems.de/blog/2016/08/13/vulkan-tutorial-on-rendering-a-fullscreen-quad-without-buffers/
let uv = vec2(((vert_idx << 1) & 2) as f32, (vert_idx & 2) as f32);
let pos = 2.0 * uv - Vec2::ONE;

*builtin_pos = pos.extend(0.0).extend(1.0);
}
Loading