1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//! 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:
//!
//! ```wgsl
//! #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);
//! ```
//!
//! # Raw WGSL source
//!
//! [`EROSION_WGSL`] exposes the shader source as a `&'static str`, available
//! regardless of the `bevy` feature. Use this when you need to feed the WGSL
//! to `wgpu` (or another backend) directly, outside Bevy's asset/shader
//! loader — for example, offline bake CLIs that run compute pipelines without
//! a Bevy `App`.
//!
//! # 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 and
//! [`EROSION_WGSL`] from non-Bevy crates.
/// Raw WGSL source for the erosion shader library.
///
/// Identical to the file Bevy loads via `ErosionFilterPlugin` when the `bevy`
/// feature is enabled. Use this when you need to feed the shader to `wgpu`
/// directly, outside Bevy's asset pipeline.
pub const EROSION_WGSL: &str = include_str!;
pub use ;