Search across packages, versions, files, declarations, and comments. Use multiple terms to narrow results (AND), and add @vertex, @fragment, or @compute to filter by shader stage.
1#import bevy_pbr::{
2 mesh_view_bindings,
3 forward_io::VertexOutput,
4}
6#import bevy_render::maths::PI
8#ifdef TONEMAP_IN_SHADER
9#import bevy_core_pipeline::tonemapping::tone_mapping
10#endif
12// Sweep across hues on y axis with value from 0.0 to +15EV across x axis
13// quantized into 24 steps for both axis.
14fn color_sweep(uv_input: vec2<f32>) -> vec3<f32> {
15 var uv = uv_input;
16 let steps = 24.0;
17 uv.y = uv.y * (1.0 + 1.0 / steps);
18 let ratio = 2.0;
20 let h = PI * 2.0 * floor(1.0 + steps * uv.y) / steps;
21 let L = floor(uv.x * steps * ratio) / (steps * ratio) - 0.5;
23 var color = vec3(0.0);
24 if uv.y < 1.0 {
25 color = cos(h + vec3(0.0, 1.0, 2.0) * PI * 2.0 / 3.0);
26 let maxRGB = max(color.r, max(color.g, color.b));
27 let minRGB = min(color.r, min(color.g, color.b));
28 color = exp(15.0 * L) * (color - minRGB) / (maxRGB - minRGB);
29 } else {
30 color = vec3(exp(15.0 * L));
31 }
32 return color;
35fn hsv_to_srgb(c: vec3<f32>) -> vec3<f32> {
36 let K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
37 let p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
38 return c.z * mix(K.xxx, clamp(p - K.xxx, vec3(0.0), vec3(1.0)), c.y);
41// Generates a continuous sRGB sweep.
42fn continuous_hue(uv: vec2<f32>) -> vec3<f32> {
43 return hsv_to_srgb(vec3(uv.x, 1.0, 1.0)) * max(0.0, exp2(uv.y * 9.0) - 1.0);
46@fragment
47fn fragment(
48 in: VertexOutput,
49) -> @location(0) vec4<f32> {
50 var uv = in.uv;
51 var out = vec3(0.0);
52 if uv.y > 0.5 {
53 uv.y = 1.0 - uv.y;
54 out = color_sweep(vec2(uv.x, uv.y * 2.0));
55 } else {
56 out = continuous_hue(vec2(uv.y * 2.0, uv.x));
57 }
58 var color = vec4(out, 1.0);
59#ifdef TONEMAP_IN_SHADER
60 color = tone_mapping(color, mesh_view_bindings::view.color_grading);
61#endif
62 return color;
Contents