Crates.io | bevy_shader_utils |
lib.rs | bevy_shader_utils |
version | 0.7.0 |
source | src |
created_at | 2022-07-08 05:09:29.139371 |
updated_at | 2024-03-26 11:51:27.477058 |
description | A utility package that provides a series of noise functions and other utilities for use in wgpu shaders. |
homepage | https://github.com/rust-adventure/bevy-examples/libs/bevy_shader_utils |
repository | https://github.com/rust-adventure/bevy-examples |
max_upload_size | |
id | 621622 |
size | 135,278 |
A utility package that provides a series of noise functions and other utilities for use in wgpu shaders.
Use the import at the top of your wgsl file and Bevy takes care of the rest.
#import bevy_pbr::forward_io::VertexOutput
#import bevy_shader_utils::simplex_noise_3d::simplex_noise_3d
struct Material {
scale: f32
};
@group(2) @binding(0)
var<uniform> material: Material;
@fragment
fn fragment(
mesh: VertexOutput
) -> @location(0) vec4<f32> {
let f: f32 = simplex_noise_3d(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.
#[derive(Asset, AsBindGroup, Debug, Clone, Reflect)]
pub struct ScreenshotSimplex3dMaterial {
#[uniform(0)]
scale: f32,
}
impl Material for ScreenshotSimplex3dMaterial {
fn fragment_shader() -> ShaderRef {
"shaders/screenshot_simplex3d_material.wgsl".into()
}
}
2-dimensional:
#import bevy_shader_utils::perlin_noise_2d::perlin_noise_2d
var value = perlin_noise_2d(vec2<f32>(5.0, 6.0))
3-dimensional:
#import bevy_shader_utils::perlin_noise_3d::perlin_noise_3d
var value = perlin_noise_3d(vec3<f32>(5.0, 6.0, 7.0))
2-dimensional:
#import bevy_shader_utils::simplex_noise_2d::simplex_noise_2d
var value = simplex_noise_2d(vec2<f32>(5.0, 6.0))
3-dimensional:
#import bevy_shader_utils::simplex_noise_3d::simplex_noise_3d
var value = simplex_noise_3d(vec3<f32>(5.0, 6.0, 7.0))
Voronoi and Noise: https://iquilezles.org/articles/voronoise/
#import bevy_shader_utils::voronoise::voronoise
var value = voronoise(vec2<f32>(5.0, 6.0), 0.0, 1.0)