#version 430 layout(local_size_x = 1, local_size_y = 1) in; precision highp float; #include #include #include uniform float seconds = 0; layout(rgba8) uniform writeonly image2D output_image; uniform float antialiasing = 0.28; uniform bool enable_antialiasing = false; vec3 image(vec2 uv) { vec2 resolution = vec2(imageSize(output_image).xy); float aspect_ratio = resolution.y / resolution.x; vec3 color = vec3(1); vec2 p = uv + vec2(-0.99999, 0.75) * 0.25; vec2 gap = vec2(0.5, aspect_ratio * 0.5); vec2 id = round(p / gap); p -= id * gap; vec2 p1 = p; float tilt = 0.72; p1 *= mat2x2(cos(tilt), -sin(tilt), sin(tilt), cos(tilt)); vec2 q1 = vec2(-1, 1); vec2 q2 = vec2(0, 1); vec2 q3 = vec2(-1, 0); vec2 q4 = vec2(0, 0); vec2 p1h = p1 - vec2(-0.03, -0.16); float handle = sdf_box(p1h, vec2(0.02 + 0.004 * cos(p1h.y * 30 + 0.5), 0.06), 0.01); vec2 p1b = p1h - vec2(0.0170, 0.288); float blade = sdf_circle(p1b, 0.06); blade = max(blade, -sdf_circle(p1b - vec2(0.05, -0.05), 0.05)); float offset = sin((p1b.y + 0.20) * 6) * 0.0138; blade = min(blade, sdf_box(p1h - vec2(-offset, 0.18), vec2(0.018 + offset, 0.1), 0)); float hring = sdf_box(p1h - vec2(0, 0.07), vec2(0.018, 0.016), 0); if (id == q1) { const vec3 col_ring = srgb(0.11, 0.27, 0.57); const vec3 col_blade = srgb(0.18, 0.54, 0.18); const vec3 col_hand = srgb(0.65, 0.07, 0.21); vec3 col_bg = vec3(0.6, 0.8, 0.6); col_bg = mix(col_bg, vec3(0), 0.2 * fbm(p1 * 2000) * fbm(p1 * 800)); color = col_bg; float crayonnoise = (fbm(p1 * 500) - 0.28) * (fbm((p1 - 0.2) * 90000) - 0.2); float fillnoise = crayonnoise; float strokenoise = 0.01 * crayonnoise - fbm(p1 * 26) * 0.006; float scratchy = clamp(1.5 * fbm(p1 * 100) - (1 + sin(p1.y * 800)) / (1 - sin(p1.y * 800)), 0, 500); color = mix(color, mix(col_blade, color, step(fillnoise, 0)), step(blade + 0.006 + 0.002 * (1 + fbm((p1 + 5) * 100)) * scratchy, 0)); color = mix(color, col_blade, step(abs(blade + strokenoise) - 0.002, 0)); color = mix(color, mix(col_hand, color, step(fillnoise, 0)), step(handle + 0.004 + 0.004 * scratchy, 0)); color = mix(color, col_hand, step(abs(handle + strokenoise) - 0.002, 0)); color = mix(color, col_bg, step(hring, 0)); color = mix(color, mix(col_ring, color, step(fillnoise, 0)), step(hring + 0.003 + 0.008 * scratchy, 0)); color = mix(color, col_ring, step(abs(hring + strokenoise) - 0.002, 0)); } else if (id == q2) { const vec3 col_pencil = srgb(0.52, 0.52, 0.49); const vec3 col_rule1 = srgb(0.16, 0.57, 0.69); const vec3 col_rule2 = srgb(0.71, 0.53, 0.58); vec3 col_bg = srgb(0.96, 0.86, 1); float rulegap = 0.008; float rulethic = 0.0005; col_bg = mix(col_bg, col_rule1, 0.5 * step(abs(p.y + 0.001 - round(p.y / 0.04) * 0.04) - rulethic, 0)); col_bg = mix(col_bg, col_rule2, 0.5 * step(abs(p.y + 0.001 + rulegap - round((p.y + rulegap) / 0.04) * 0.04) - rulethic, 0)); col_bg = mix(col_bg, col_rule2, 0.5 * step(abs(p.y + 0.001 + rulegap * 2 - round((p.y + rulegap * 2) / 0.04) * 0.04) - rulethic, 0)); col_bg = mix(col_bg, col_rule1, 0.5 * step(abs(p.y + 0.001 + rulegap * 3 - round((p.y + rulegap * 3) / 0.04) * 0.04) - rulethic, 0)); color = col_bg; { vec2 fpp = (p - vec2(0.2, -0.1)) * 600; fpp *= mat2x2(cos(0.3), -sin(0.3), sin(0.3), cos(0.3)); float bounds = smoothstep(9., 10., length(fpp * vec2(0.74, 0.55))); float a = 0.; vec2 h = vec2(floor(7.), 0.); for (int i = 0; i < 50; i++) { float s = sign(h.x); h = fphash2(h) * vec2(15., 20.); a += s * atan(fpp.x - h.x, fpp.y - h.y); } fpp += 20. * abs(fphash2(h)); a += atan(fpp.y, fpp.x); float p = (1. - bounds) * 0.8; float s = min(0.3, p); float m = mod(length(fpp) + 0.319 * a, 2.); float v = (1. - smoothstep(2. - s, 2., m)) * smoothstep(p, p + s, m); color = mix(color, mix(color, srgb(0.47, 0.23, 0.58), 0.04), 1 - v); } float thicc = 0.001; float strokenoise = fbm(p1 * 5000) * 0.002 - fbm(p1 * 20) * 0.006; color = mix(color, col_pencil, step(abs(handle - strokenoise) - thicc, 0)); color = mix(color, col_pencil, step(abs(blade - strokenoise) - thicc, 0)); color = mix(color, col_bg, step(hring, 0)); float scribble = p1h.y - round(p1h.y / 0.005) * 0.005 - 0.001 * sin(p1h.x * 1000) + 0.0; color = mix(color, col_pencil, step(abs(scribble) - thicc, 0) * step(hring, 0)); color = mix(color, col_pencil, step(abs(hring - strokenoise) - thicc, 0)); } else if (id == q3) { const vec3 col_ink = srgb(0.24, 0.39, 0.84); const vec3 col_rule = srgb(0.8); vec3 col_bg = srgb(0.86, 0.86, 0.96); float rule = p.y - round(p.y / 0.02) * 0.02 + 0.001; col_bg = mix(col_bg, col_rule, step(abs(rule) - 0.0005, 0)); color = col_bg; float thicc = 0.001; color = mix(color, col_ink, step(abs(handle) - thicc, 0)); color = mix(color, col_ink, step(abs(blade) - thicc, 0)); color = mix(color, col_bg, step(hring, 0)); float scribble = sin(p.y * 2000); color = mix(color, col_ink, step(hring, 0) * step(scribble, 0)); color = mix(color, col_ink, step(abs(hring) - thicc, 0)); } else if (id == q4) { const vec3 col_handle = srgb(0.64, 0.53, 0.28); const vec3 col_blade = srgb(0.06, 0.05, 0.04); const vec3 col_bladeedge = srgb(0.52, 0.47, 0.41); const vec3 col_bladerust = srgb(0.58, 0.24, 0.12); const vec3 col_ring = srgb(0.77, 0.80, 0.76); vec3 col_bg = srgb(0.9, 0.72, 0.70); col_bg = mix(col_bg, vec3(0), 0.2 * fbm(p1 * 2000) * fbm(p1 * 800)); color = col_bg; color = mix(color, mix(color, vec3(0), 0.2), 1 - smoothstep(-0.013, -0., min(min(blade, hring), handle) - 0.01)); vec3 col_hshadow = mix(col_handle, vec3(0), 0.5); color = mix(color, col_handle, step(handle, 0)); color = mix(color, srgb(0.28, 0.11, 0.03), 0.1 * cos((p1.x + 0.06 * fbm(p1 * 5) - 0.004 * sin(p1.y * 50)) * 2000) * step(handle, 0)); color = mix(color, col_hshadow, smoothstep(-0.01, 0.02, handle) * step(handle, 0)); color = mix(color, col_hshadow, cos(p1.x * 80) * step(handle, 0)); color = mix(color, col_blade, step(blade, 0)); float tilt = -0.08; vec2 circutp = p1 * mat2x2(cos(tilt), -sin(tilt), sin(tilt), cos(tilt)); float circut = sdf_box(circutp - vec2(0.04, -0.04), vec2(0.07, 0.2), 0.075); color = mix(color, col_bladeedge, (1 - smoothstep(-0.02, 0.0, circut - 0.004 * fbm(circutp * 100))) * step(blade, 0)); color = mix(color, col_ring, step(hring, 0)); color = mix(color, mix(col_ring, vec3(0), 0.8), cos((p1.x) * 100) * step(hring, 0)); } color = mix(color, mix(color, vec3(0), 0.2), clamp(2 - smoothstep(-0.005, 0.005, abs(uv.x) - 0.001) - smoothstep(-0.005, 0.005, abs(uv.y) - 0.001), 0, 1)); return color; } vec3 antialiased_image(vec2 uv) { vec2 resolution = vec2(imageSize(output_image).xy); float s = antialiasing / max(resolution.x, resolution.y); vec3 sum = vec3(0); int count = 0; for (int i = -2; i < 2; i++) for (int j = -2; j < 2; j++, count++) sum += image(uv + vec2(i, j) * s); return sum / count; } void main() { vec2 resolution = vec2(imageSize(output_image).xy); float aspect_ratio = resolution.y / resolution.x; vec2 uv = (gl_GlobalInvocationID.xy - resolution / 2) * vec2(1.0, aspect_ratio) / resolution; vec3 color = enable_antialiasing ? antialiased_image(uv) : image(uv); imageStore(output_image, ivec2(gl_GlobalInvocationID.xy), vec4(color, 1)); }