Skip to content
Draft
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,044 changes: 866 additions & 1,178 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ cuda = ["dep:processing_cuda", "processing_cuda/cuda"]
[workspace]
resolver = "3"
members = ["crates/*", "tools/*"]
# TEMP(bevy-020): bevy_seedling pins bevy 0.19
exclude = ["crates/processing_audio"]

[workspace.package]
rust-version = "1.95"
rust-version = "1.100"

[workspace.lints.clippy]
type_complexity = "allow"
Expand Down Expand Up @@ -52,17 +54,16 @@ bevy = { git = "https://github.com/processing/bevy", branch = "main", default-fe
"wayland",
"webgl2",
"x11",
"shader_format_wesl",
"free_camera",
"pan_camera",

# image formats Processing loads
"jpeg",
] }
bevy_naga_reflect = { git = "https://github.com/tychedelia/bevy_naga_reflect" }
bevy_naga_reflect = { git = "https://github.com/tychedelia/bevy_naga_reflect", branch = "bevy-020-fixes" }
bevy_cuda = { git = "https://github.com/tychedelia/bevy_cuda" }
naga = { version = "29", features = ["wgsl-in"] }
wesl = { version = "0.3", default-features = false }
wesl = { version = "0.6", features = ["naga-ext"] }
pyo3 = { git = "https://github.com/PyO3/pyo3", branch = "main" }
pyo3-introspection = { git = "https://github.com/PyO3/pyo3", branch = "main" }
processing = { path = "." }
Expand All @@ -71,7 +72,8 @@ processing_cuda = { path = "crates/processing_cuda" }
processing_pyo3 = { path = "crates/processing_pyo3" }
processing_render = { path = "crates/processing_render" }
processing_midi = { path = "crates/processing_midi" }
processing_audio = { path = "crates/processing_audio" }
# TEMP(bevy-020): bevy_seedling pins bevy 0.19
# processing_audio = { path = "crates/processing_audio" }
processing_input = { path = "crates/processing_input" }
processing_glfw = { path = "crates/processing_glfw" }
processing_webcam = { path = "crates/processing_webcam" }
Expand All @@ -83,7 +85,8 @@ bevy = { workspace = true }
processing_core = { workspace = true }
processing_render = { workspace = true }
processing_midi = { workspace = true }
processing_audio = { workspace = true }
# TEMP(bevy-020): bevy_seedling pins bevy 0.19
# processing_audio = { workspace = true }
processing_input = { workspace = true }
processing_webcam = { workspace = true, optional = true }
processing_cuda = { workspace = true, optional = true }
Expand Down
4 changes: 2 additions & 2 deletions assets/shaders/custom_vertex.wesl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { processing::VertexOutput };
import { processing::mesh::{Vertex, vertex_output} };
import { processing::mesh::{Vertex, vertex_input, vertex_output} };

@group(3) @binding(0) var<uniform> bulge: f32;

@vertex
fn vertex(vertex_in: Vertex) -> VertexOutput {
var vertex = vertex_in;
var vertex = vertex_input(vertex_in);
// `sphere()` draws a unit sphere scaled by its transform
vertex.position += vertex.normal * bulge * sin(vertex.position.y * 12.0);
return vertex_output(vertex);
Expand Down
2 changes: 1 addition & 1 deletion crates/processing_midi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ rust-version.workspace = true
[dependencies]
bevy = { workspace = true }
processing_core = { workspace = true }
nannou_midi = { git = "https://github.com/nannou-org/nannou", branch = "bevy-refactor" }
nannou_midi = { git = "https://github.com/tychedelia/nannou", branch = "bevy-020" }

[target.'cfg(target_os = "macos")'.dependencies]
midir = { version = "0.11", features = ["coremidi_send_timestamped"] }
Expand Down
14 changes: 13 additions & 1 deletion crates/processing_pyo3/examples/Demos/Tests/first_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
from random import seed, uniform

points = None
instances = None
instance = None
mat = None


def setup():
global points, mat
global points, instances, instance, mat
size(800, 600)
mode_3d()

Expand All @@ -25,6 +27,13 @@ def setup():
positions.append([220 + uniform(-60, 60), 120 + uniform(-60, 60), uniform(-60, 60)])
points.buffer("position").write(positions)

instances = create_particles(7, attributes=[Attribute.position()])
positions = []
for i in range(7):
positions.append([-150 + i * 50, -30, 0])
instances.buffer("position").write(positions)
instance = Geometry.sphere(16, 12, 8)


def draw():
camera_position(0.0, 0.0, 500.0)
Expand Down Expand Up @@ -71,5 +80,8 @@ def draw():
# particle points
particles(points)

# instanced particles
particles(instances, instance)


run()
6 changes: 6 additions & 0 deletions crates/processing_pyo3/src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ fn components(color: &Color) -> [f32; 4] {
Color::Lcha(c) => c.to_f32_array(),
Color::Oklaba(c) => c.to_f32_array(),
Color::Oklcha(c) => c.to_f32_array(),
Color::Okhsla(c) => c.to_f32_array(),
Color::Okhsva(c) => c.to_f32_array(),
Color::Okhwba(c) => c.to_f32_array(),
Color::Xyza(c) => c.to_f32_array(),
}
}
Expand All @@ -148,6 +151,9 @@ fn components_no_alpha(color: &Color) -> [f32; 3] {
Color::Lcha(c) => c.to_f32_array_no_alpha(),
Color::Oklaba(c) => c.to_f32_array_no_alpha(),
Color::Oklcha(c) => c.to_f32_array_no_alpha(),
Color::Okhsla(c) => c.to_f32_array_no_alpha(),
Color::Okhsva(c) => c.to_f32_array_no_alpha(),
Color::Okhwba(c) => c.to_f32_array_no_alpha(),
Color::Xyza(c) => c.to_f32_array_no_alpha(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/processing_render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ x11 = ["bevy/x11"]
bevy = { workspace = true }
bevy_naga_reflect = { workspace = true }
# direct wgpu dep to reach `wgpu::util::TextureBlitter` (unifies to bevy's wgpu)
wgpu = "29"
wgpu = "30"
naga = { workspace = true }
wesl = { workspace = true }
lyon = "1.0"
Expand All @@ -32,7 +32,7 @@ png = "0.18"
processing_core = { workspace = true }

[build-dependencies]
wesl = { workspace = true, features = ["package"] }
serde_json = "1"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
bevy = { workspace = true, features = ["file_watcher"] }
Expand Down
164 changes: 138 additions & 26 deletions crates/processing_render/build.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,147 @@
use std::fmt::Write;
use std::path::Path;

// packages wesl libraries for processing and lygia
// note that bevy does not (as of yet) understand how to use these packages
// they are, instead, used by us as part of shader pre-processing in the
// processing_render crate
// Embeds the `processing` and `lygia` WESL packages as tables of module sources; they are
// registered with bevy at startup, so any shader can import them.
fn main() {
wesl::PkgBuilder::new("processing")
.scan_root("shaders/processing")
.expect("failed to scan processing WESL files")
.build_artifact()
.expect("failed to build processing package artifact");
let mut code = String::new();
package(
&mut code,
"PROCESSING",
"processing",
Path::new("shaders/processing"),
);
package(&mut code, "LYGIA", "lygia", Path::new("../../lygia"));
engine(&mut code);
let out = Path::new(&std::env::var_os("OUT_DIR").unwrap()).join("shader_modules.rs");
std::fs::write(out, code).unwrap();
}

// Bevy's own shader modules that ours import, for editors to resolve those imports. A bevy
// module is named after its crate and its path under `src`.
fn engine(code: &mut String) {
let metadata = std::process::Command::new(std::env::var_os("CARGO").unwrap())
.args(["metadata", "--format-version", "1", "--locked", "--offline"])
.output()
.expect("cargo metadata");
assert!(
metadata.status.success(),
"cargo metadata failed: {}",
String::from_utf8_lossy(&metadata.stderr)
);
let metadata: serde_json::Value = serde_json::from_slice(&metadata.stdout).unwrap();
let crates: std::collections::BTreeMap<String, std::path::PathBuf> = metadata["packages"]
.as_array()
.unwrap()
.iter()
.filter_map(|package| {
let name = package["name"].as_str()?;
let manifest = Path::new(package["manifest_path"].as_str()?);
name.starts_with("bevy_")
.then(|| (name.to_string(), manifest.parent().unwrap().join("src")))
})
.collect();

// the crates our packages import, and the crates those import
let mut wanted: Vec<String> = Vec::new();
let mut sources: Vec<String> = ["shaders/processing.wesl", "shaders/processing"]
.iter()
.flat_map(|path| wesl_files(Path::new(path)))
.map(|path| std::fs::read_to_string(path).unwrap())
.collect();
let mut modules = Vec::new();
while let Some(source) = sources.pop() {
for name in crates.keys() {
if source.contains(&format!("{name}::")) && !wanted.contains(name) {
wanted.push(name.clone());
let mut found = Vec::new();
walk(&crates[name], name, "", &mut found);
for (_, _, path) in &found {
sources.push(std::fs::read_to_string(path).unwrap());
}
modules.extend(found);
}
}
}
modules.sort();
table(code, "ENGINE", modules);
}

fn wesl_files(path: &Path) -> Vec<std::path::PathBuf> {
if path.is_file() {
return vec![path.to_path_buf()];
}
let mut files = Vec::new();
for entry in std::fs::read_dir(path).into_iter().flatten().flatten() {
let path = entry.path();
if path.is_dir() || path.extension().is_some_and(|ext| ext == "wesl") {
files.extend(wesl_files(&path));
}
}
files
}

let mut lygia = wesl::PkgBuilder::new("lygia")
.scan_root("../../lygia")
.expect("failed to scan Lygia WESL files");
wesl_only(&mut lygia.root, Path::new("../../lygia"));
lygia.root.submodules.retain(|sub| sub.name != "test");
lygia
.build_artifact()
.expect("failed to build Lygia package artifact");
// A package is a directory of modules; its root module is the `.wesl` file beside it.
fn package(code: &mut String, table_name: &str, name: &str, dir: &Path) {
println!("cargo::rerun-if-changed={}", dir.display());
let mut modules = Vec::new();
let root = dir.with_extension("wesl");
if root.is_file() {
println!("cargo::rerun-if-changed={}", root.display());
modules.push((name.to_string(), "package.wesl".to_string(), root));
}
walk(dir, name, "", &mut modules);
modules.sort();
table(code, table_name, modules);
}

// lygia's manifest includes `**/*.wesl` only; the scan also picks up its legacy `.wgsl`
fn wesl_only(module: &mut wesl::Module, path: &Path) {
if !path.with_extension("wesl").is_file() {
module.source.clear();
fn table(code: &mut String, table: &str, modules: Vec<(String, String, std::path::PathBuf)>) {
writeln!(code, "pub static {table}: &[ShaderModule] = &[").unwrap();
for (path, file, source) in modules {
let source = std::fs::canonicalize(source).unwrap();
writeln!(
code,
" ShaderModule {{ path: {path:?}, file: {file:?}, source: include_str!({source:?}) }},"
)
.unwrap();
}
for sub in &mut module.submodules {
wesl_only(sub, &path.join(&sub.name));
writeln!(code, "];").unwrap();
}

fn walk(
dir: &Path,
module: &str,
file: &str,
modules: &mut Vec<(String, String, std::path::PathBuf)>,
) {
for entry in std::fs::read_dir(dir).unwrap().flatten() {
let path = entry.path();
let Some(stem) = path.file_stem().and_then(|stem| stem.to_str()) else {
continue;
};
// a module name has to be an identifier
let ident = stem.chars().all(|c| c.is_ascii_alphanumeric() || c == '_')
&& !stem.starts_with(|c: char| c.is_ascii_digit());
if !ident {
continue;
}
if path.is_dir() {
// lygia's own tests are not part of the package
if module == "lygia" && stem == "test" {
continue;
}
walk(
&path,
&format!("{module}::{stem}"),
&format!("{file}{stem}/"),
modules,
);
} else if path.extension().is_some_and(|ext| ext == "wesl") {
modules.push((
format!("{module}::{stem}"),
format!("{file}{stem}.wesl"),
path,
));
}
}
module
.submodules
.retain(|sub| !sub.source.is_empty() || !sub.submodules.is_empty());
}
11 changes: 3 additions & 8 deletions crates/processing_render/shaders/processing.wesl
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ struct Globals {
frame_count: u32,
}

@group(0) @binding(11) var<uniform> globals: Globals;
@group(0) @binding(8) var<uniform> globals: Globals;

struct VertexOutput {
@builtin(position) position: vec4<f32>,
@location(0) world_position: vec4<f32>,
@location(1) world_normal: vec3<f32>,
@location(2) uv: vec2<f32>,
@location(5) color: vec4<f32>,
}
// what a custom fragment stage receives: `world_position`, `world_normal`, `uv`, `color`
alias VertexOutput = bevy_pbr::render::forward_io::VertexOutput;
Loading
Loading