Skip to main content

Crate bevy_noised

Crate bevy_noised 

Source
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 noise
  • fbm_simplex_2d_seeded: layered terrain-style noise
  • ridged_fbm_2d_seeded: mountain/ridge-heavy noise
  • *_derivative variants: return (value, gradient)

§Parameter guidance

  • frequency: world scale (0.0005 to 0.01 are common terrain ranges)
  • octaves: layer count (4 to 8 typical)
  • lacunarity: frequency multiplier per octave (usually around 2.0)
  • gain: amplitude multiplier per octave (0.4 to 0.6 common)
  • 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§

WGSL_NOISE_SOURCE

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.