Expand description
GPU-friendly per-fragment erosion filter for Bevy.
WGSL port of Rune Skovbo Johansen’s erosion noise from https://www.shadertoy.com/view/wXcfWn. The shader library can be imported into your own Bevy materials, and this crate also provides a pure-Rust CPU implementation for offline baking and parity testing.
§WGSL usage
Add ErosionFilterPlugin to your app, then in your shader:
#import bevy_erosion_filter::erosion::{
fbm, erosion_filter, erosion_filter_params_default,
}
// Get base height + analytical gradient from your own height function:
let base = fbm(uv, 3.0, 4, 2.0, 0.5);
let fade_target = clamp(base.x / 0.1, -1.0, 1.0);
let filtered = erosion_filter(uv, base, fade_target, erosion_filter_params_default());
let height = base.x + filtered.delta.x;
let grad = base.yz + filtered.delta.yz;
let ridge_map = filtered.ridge_map;§CPU usage
use bevy_erosion_filter::cpu;
use glam::Vec2;
let p = Vec2::new(1.0, 2.0);
let base = cpu::fbm(p, 3.0, 4, 2.0, 0.5);
let params = cpu::ErosionFilterParams::default();
let filtered = cpu::erosion_filter(p, base, base.x.clamp(-1.0, 1.0), ¶ms);
println!("eroded height = {}", base.x + filtered.delta.x);§Cargo features
bevy (default) — pulls in Bevy and registers the WGSL shader library
plus the ErosionFilterParamsGpu uniform layout. Disable with
default-features = false to use only the pure-Rust cpu module from
non-Bevy crates.
Modules§
- cpu
- Pure-Rust port of the erosion filter, mirroring the WGSL implementation in
assets/shaders/erosion.wgslnumerically. Useful for offline baking, parity tests, and applications that need to evaluate the same field on both CPU and GPU.
Structs§
- Erosion
Filter Params Gpu - GPU uniform layout matching the WGSL
ErosionFilterParamsstruct. - Erosion
Filter Plugin - Bevy plugin that registers the erosion WGSL as a shader library.