Expand description
Bevy-first 2D noise primitives for gameplay + rendering parity.
bevy_noised exposes matching CPU and WGSL noise functions so gameplay systems,
terrain generation, and shaders can sample the same fields with near-identical
numeric output.
The primary target workflow is shader-displaced terrain where CPU picking/raycast queries need to return the same heights as the rendered mesh.
Derivatives are key in this workflow because they let you compute normals from the same noise field driving vertex displacement, which keeps terrain lighting stable and consistent.
§Why this crate in a Bevy project?
- Deterministic seeded noise on CPU and GPU
- Analytical derivatives for slope/normal/flow style workflows
- Small API surface focused on common terrain and mask pipelines
§Picking a function
simplex_noise_2d_seeded: base coherent noisefbm_simplex_2d_seeded: layered terrain-style noiseridged_fbm_2d_seeded: mountain/ridge-heavy noise*_derivativevariants: return(value, gradient)
§Parameter guidance
frequency: world scale (0.0005to0.01are common terrain ranges)octaves: layer count (4to8typical)lacunarity: frequency multiplier per octave (usually around2.0)gain: amplitude multiplier per octave (0.4to0.6common)seed: deterministic variation source
§Example (CPU)
use bevy_math::{Vec2, Vec3};
use bevy_noised::fbm_simplex_2d_seeded_derivative;
let world_pos = Vec2::new(128.0, 256.0);
let (height, grad) = fbm_simplex_2d_seeded_derivative(world_pos, 0.001, 6, 2.0, 0.5, 42.0);
let normal = Vec3::new(-grad.x, 1.0, -grad.y).normalize_or_zero();
assert!(height.is_finite());
assert!(normal.is_finite());§WGSL source
Use WGSL_NOISE_SOURCE to embed this crate’s shader functions into your
Bevy shader source. WGSL derivative variants return vec3(value, dfdx, dfdy).
Attribution: simplex implementation adapted from MIT-licensed work by Ian McEwan, Stefan Gustavson, Munrocket, and Johan Helsing.
Constants§
Functions§
- fbm_
simplex_ 2d_ seeded - Fractal Brownian motion (fBm) built from seeded 2D simplex noise.
- fbm_
simplex_ 2d_ seeded_ derivative - Fractal Brownian motion plus analytical gradient.
- ridged_
fbm_ 2d_ seeded - Ridged fractal noise built from seeded 2D simplex noise.
- ridged_
fbm_ 2d_ seeded_ derivative - Ridged fractal noise plus analytical gradient.
- simplex_
noise_ 2d_ seeded - Seeded 2D simplex noise value.
- simplex_
noise_ 2d_ seeded_ derivative - Seeded 2D simplex noise value plus analytical gradient.