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 bevypbr::meshvertex_output MeshVertexOutput

import bevyshaderutils::simplexnoise3d simplexnoise3d

struct Material { scale: f32 };

@group(1) @binding(0) var material: Material;

@fragment fn fragment( mesh: MeshVertexOutput ) -> @location(0) vec4 { let f: f32 = simplexnoise3d(material.scale * mesh.world_position.xyz);

let color_a = vec3(0.282, 0.51, 1.0);
let color_b = vec3(0.725, 0.816, 0.698);
let mixed = mix(color_a, color_b, f);
return vec4(mixed, 1.0);

} ```

The above shader is used by a material defined as such.

```rust

[derive(AsBindGroup, TypeUuid, Debug, Clone, Reflect)]

[uuid = "848b7711-3819-4525-bbba-91b474303778"]

pub struct ScreenshotSimplex3dMaterial { #[uniform(0)] scale: f32, }

impl Material for ScreenshotSimplex3dMaterial { fn fragmentshader() -> ShaderRef { "shaders/screenshotsimplex3d_material.wgsl".into() } } ```

Functions

Perlin noise

2-dimensional:

```wgsl

import bevyshaderutils::perlinnoise2d perlinnoise2d

var value = perlinNoise2(vec2(5.0, 6.0)) ```

3-dimensional:

```wgsl

import bevyshaderutils::perlinnoise3d perlinnoise3d

var value = perlinNoise3(vec3(5.0, 6.0, 7.0)) ```

Simplex noise

2-dimensional:

```wgsl

import bevyshaderutils::simplexnoise2d perlinnoise3d

var value = simplexNoise2(vec2(5.0, 6.0)) ```

3-dimensional:

```wgsl

import bevyshaderutils::simplexnoise3d perlinnoise3d

var value = simplexNoise3(vec3(5.0, 6.0, 7.0)) ```

Voronoise

Voronoi and Noise: https://iquilezles.org/articles/voronoise/

```wgsl

import bevyshaderutils::voronoise voronoise

var value = voronoise(vec2(5.0, 6.0), 0.0, 1.0) ```