Bevy Shader Utils
A utility package that provides a series of noise functions and other utilities for use in wgpu shaders.
Quick Start
Use the import at the top of your wgsl file and Bevy takes care of the rest.
```wgsl
import bevyshaderutils::perlinnoise3d
struct CustomMaterial {
color: vec4;
};
[[group(1), binding(0)]]
var material: CustomMaterial;
[[group(1), binding(1)]]
var basecolortexture: texture2d;
[[group(1), binding(2)]]
var basecolor_sampler: sampler;
[[stage(fragment)]]
fn fragment([[location(2)]] uv: vec2) -> [[location(0)]] vec4 {
var input: vec3 = vec3(uv.x * 40.0, uv.y * 40.0, 1.);
var noise = perlinNoise3(input);
var alpha = (noise + 1.0) / 2.0;
return material.color
* textureSample(basecolortexture, basecolorsampler, uv)
* vec4(1.0,1.0,1.0,alpha);
}
```
Functions
Perlin noise
2-dimensional:
```wgsl
import bevyshaderutils::perlinnoise2d
var value = perlinNoise2(vec2(5.0, 6.0))
```
3-dimensional:
```wgsl
import bevyshaderutils::perlinnoise3d
var value = perlinNoise3(vec3(5.0, 6.0, 7.0))
```
Simplex noise
2-dimensional:
```wgsl
import bevyshaderutils::simplexnoise2d
var value = simplexNoise2(vec2(5.0, 6.0))
```
3-dimensional:
```wgsl
import bevyshaderutils::simplexnoise3d
var value = simplexNoise3(vec3(5.0, 6.0, 7.0))
```
Fractal Brownian Motion
```wgsl
import bevyshaderutils::fbm
var value = fbm(vec2(5.0, 6.0))
```
Voronoise
Voronoi and Noise: https://iquilezles.org/articles/voronoise/
```wgsl
import bevyshaderutils::voronoise2d
var value = voroNoise2(vec2(5.0, 6.0), 0.0, 1.0)
```