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.
1import bevy_pbr::render::{
2 mesh_view_bindings,
3 forward_io::VertexOutput,
4};
6import bevy_render::maths::PI;
8@if(TONEMAP_IN_SHADER)
9import bevy_core_pipeline::tonemapping::tone_mapping;
11/// Sweep across hues on y axis with value from 0.0 to +15EV across x axis
12/// quantized into 24 steps for both axis.
13fn color_sweep(uv_input: vec2<f32>) -> vec3<f32> {
14 var uv = uv_input;
15 let steps = 24.0;
16 uv.y = uv.y * (1.0 + 1.0 / steps);
17 let ratio = 2.0;
19 let h = PI * 2.0 * floor(1.0 + steps * uv.y) / steps;
20 let L = floor(uv.x * steps * ratio) / (steps * ratio) - 0.5;
22 var color = vec3(0.0);
23 if uv.y < 1.0 {
24 color = cos(h + vec3(0.0, 1.0, 2.0) * PI * 2.0 / 3.0);
25 let maxRGB = max(color.r, max(color.g, color.b));
26 let minRGB = min(color.r, min(color.g, color.b));
27 color = exp(15.0 * L) * (color - minRGB) / (maxRGB - minRGB);
28 } else {
29 color = vec3(exp(15.0 * L));
30 }
31 return color;
34fn hsv_to_srgb(c: vec3<f32>) -> vec3<f32> {
35 let K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
36 let p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
37 return c.z * mix(K.xxx, clamp(p - K.xxx, vec3(0.0), vec3(1.0)), c.y);
40/// Generates a continuous sRGB sweep.
41fn continuous_hue(uv: vec2<f32>) -> vec3<f32> {
42 return hsv_to_srgb(vec3(uv.x, 1.0, 1.0)) * max(0.0, exp2(uv.y * 9.0) - 1.0);
45@fragment
46fn fragment(
47 in: VertexOutput,
48) -> @location(0) vec4<f32> {
49 var uv = in.uv;
50 var out = vec3(0.0);
51 if uv.y > 0.5 {
52 uv.y = 1.0 - uv.y;
53 out = color_sweep(vec2(uv.x, uv.y * 2.0));
54 } else {
55 out = continuous_hue(vec2(uv.y * 2.0, uv.x));
56 }
57 var color = vec4(out, 1.0);
58 @if(TONEMAP_IN_SHADER)
59 color = tone_mapping(color, mesh_view_bindings::view.color_grading);
60 return color;
Contents