mirror of
https://github.com/bevyengine/bevy
synced 2024-12-20 01:53:12 +00:00
3c63c0dab7
# Objective - The functions added to utils.wgsl by the prepass assume that mesh_view_bindings are present, which isn't always the case - Fixes https://github.com/bevyengine/bevy/issues/7353 ## Solution - Move these functions to their own `prepass_utils.wgsl` file Co-authored-by: IceSentry <IceSentry@users.noreply.github.com>
27 lines
854 B
WebGPU Shading Language
27 lines
854 B
WebGPU Shading Language
#define_import_path bevy_pbr::utils
|
|
|
|
let PI: f32 = 3.141592653589793;
|
|
|
|
fn hsv2rgb(hue: f32, saturation: f32, value: f32) -> vec3<f32> {
|
|
let rgb = clamp(
|
|
abs(
|
|
((hue * 6.0 + vec3<f32>(0.0, 4.0, 2.0)) % 6.0) - 3.0
|
|
) - 1.0,
|
|
vec3<f32>(0.0),
|
|
vec3<f32>(1.0)
|
|
);
|
|
|
|
return value * mix(vec3<f32>(1.0), rgb, vec3<f32>(saturation));
|
|
}
|
|
|
|
fn random1D(s: f32) -> f32 {
|
|
return fract(sin(s * 12.9898) * 43758.5453123);
|
|
}
|
|
|
|
// returns the (0-1, 0-1) position within the given viewport for the current buffer coords .
|
|
// buffer coords can be obtained from `@builtin(position).xy`.
|
|
// the view uniform struct contains the current camera viewport in `view.viewport`.
|
|
// topleft = 0,0
|
|
fn coords_to_viewport_uv(position: vec2<f32>, viewport: vec4<f32>) -> vec2<f32> {
|
|
return (position - viewport.xy) / viewport.zw;
|
|
}
|