summaryrefslogtreecommitdiff
path: root/addons/snake_shader/snake.post.frag
diff options
context:
space:
mode:
Diffstat (limited to 'addons/snake_shader/snake.post.frag')
-rw-r--r--addons/snake_shader/snake.post.frag34
1 files changed, 34 insertions, 0 deletions
diff --git a/addons/snake_shader/snake.post.frag b/addons/snake_shader/snake.post.frag
new file mode 100644
index 00000000..226e98de
--- /dev/null
+++ b/addons/snake_shader/snake.post.frag
@@ -0,0 +1,34 @@
+#version 450
+layout(location = 0) in vec2 uv;
+layout(location = 0) out vec4 color;
+layout(set = 2, binding = 0) uniform sampler2D board;
+layout(std140, set = 3, binding = 0) uniform Clock { vec4 phase; } clock;
+
+vec3 bright(vec2 at) {
+ vec3 rgb = texture(board, at).rgb;
+ return rgb * smoothstep(.16, .65, max(rgb.r, max(rgb.g, rgb.b)));
+}
+vec3 mapColor(vec3 rgb) {
+ // Soft highlights with a cool shadow tint; retain the dark board floor.
+ rgb *= vec3(.98, 1.02, 1.06);
+ return clamp((rgb * (2.51 * rgb + .03)) / (rgb * (2.43 * rgb + .59) + .14), 0, 1);
+}
+void main() {
+ vec2 size = vec2(textureSize(board, 0));
+ vec2 pixel = uv * size;
+ vec2 pitch = vec2(3, 4);
+ vec2 sampleUV = (floor(pixel / pitch) + .5) * pitch / size;
+ vec4 source = texture(board, sampleUV);
+ vec3 bloom = vec3(0);
+ vec2 stepUV = vec2(4) / size;
+ for (int y = -1; y <= 1; y++) for (int x = -1; x <= 1; x++) {
+ float weight = float((x == 0 ? 2 : 1) * (y == 0 ? 2 : 1));
+ bloom += bright(sampleUV + vec2(x, y) * stepUV) * weight / 16;
+ }
+ vec3 rgb = mapColor(source.rgb + bloom * .24);
+ vec3 mask = vec3(.65);
+ mask[int(mod(floor(pixel.x), 3))] = 1.45;
+ float scanline = mix(.5, 1, smoothstep(.15, .35, fract(pixel.y / 4)));
+ float shimmer = 1 + .006 * sin(clock.phase.x * 18.849556 + pixel.y * .12);
+ color = vec4(rgb * mask * scanline * shimmer, source.a);
+}