48 lines
1.4 KiB
WebGPU Shading Language
48 lines
1.4 KiB
WebGPU Shading Language
#import bevy_sprite::mesh2d_vertex_output::VertexOutput
|
|
|
|
@group(2) @binding(0) var<uniform> u_time: f32;
|
|
@group(2) @binding(1) var<uniform> u_resolution: vec2f;
|
|
@group(2) @binding(2) var<uniform> u_mouse_position: vec2f;
|
|
|
|
fn lerp(v0: f32, v1: f32, t: f32) -> f32 {
|
|
return v0 + t * (v1 - v0);
|
|
}
|
|
|
|
@fragment
|
|
fn fragment(mesh: VertexOutput) -> @location(0) vec4f {
|
|
var uv = vec2f(lerp(-2, 0.47, mesh.uv.x), lerp(-1.12, 1.12, mesh.uv.y));
|
|
|
|
// Progressive time-based zoom toward the known interesting point
|
|
// c = -0.743643887037151 + 0.13182590420533i
|
|
let center = vec2f(-0.743643887037151, 0.13182590420533);
|
|
let zoomSpeed: f32 = 0.2; // tune this to control how fast we zoom
|
|
let zoom = exp(u_time * zoomSpeed); // zoom factor grows with time
|
|
let c = center + (uv - center) / zoom; // move coordinates toward center as zoom increases
|
|
|
|
var zx = 0.0;
|
|
var zy = 0.0;
|
|
let maxIter: i32 = 100 + i32(u_time);
|
|
var it: i32 = 0;
|
|
|
|
for (var i: i32 = 0; i < maxIter; i = i + 1) {
|
|
let x = zx * zx - zy * zy + c.x;
|
|
let y = 2.0 * zx * zy + c.y;
|
|
zx = x;
|
|
zy = y;
|
|
if (zx * zx + zy * zy > 4.0) {
|
|
it = i;
|
|
break;
|
|
}
|
|
}
|
|
|
|
let t = f32(it) / f32(maxIter);
|
|
|
|
let palette = vec3f(0.5) + 0.5 * cos(6.2831853 * (vec3f(0.0, 0.33, 0.66) + t * 1.5) + u_time * 0.2);
|
|
|
|
var color = vec3f(0, 0, 0);
|
|
if (t < 0.999999) {
|
|
color = palette;
|
|
}
|
|
|
|
return vec4f(color, 1);
|
|
}
|