From 0bf49a2bb0d75d9911217b9021ed7238cbea0bcb Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Tue, 28 May 2024 19:12:14 +0200 Subject: [PATCH] init --- README.md | 3 ++ binary_clock.glsl | 36 ++++++++++++++++++ interactive_game_of_life.glsl | 71 +++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+) create mode 100644 README.md create mode 100644 binary_clock.glsl create mode 100644 interactive_game_of_life.glsl diff --git a/README.md b/README.md new file mode 100644 index 0000000..2e026dd --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# android-shaders +GLSL shaders made in/for the [Shader Editor app](https://f-droid.org/en/packages/de.markusfisch.android.shadereditor/) on fdroid. + diff --git a/binary_clock.glsl b/binary_clock.glsl new file mode 100644 index 0000000..c943cab --- /dev/null +++ b/binary_clock.glsl @@ -0,0 +1,36 @@ +#version 300 es +#ifdef GL_FRAGMENT_PRECISION_HIGH +precision highp float; +#else +precision mediump float; +#endif + +uniform vec2 resolution; +uniform vec3 daytime; + +out vec3 col; + +void row(float h, float bits, int val) { + vec2 uv = gl_FragCoord.xy / resolution.x; + uv.x = 1.0 - uv.x; + int bit = int((uv.x) * bits); + vec2 c = vec2(float(bit) / bits + 0.5/bits, h); + float r = length(c - uv); + if (r < 0.05) { + int b = (val >> bit) & 1; + if (r > 0.04 || b == 1) + col = vec3(0.1, 1, 1); + } +} + +void main(void) { + col = vec3(0.1, 0.1, 0.1); + + int hour = int(daytime.x); + int minute = int(daytime.y); + int second = int(daytime.z); + + row(1.2, 5.0, hour); + row(1.0, 6.0, minute); + row(0.8, 6.0, second); +} \ No newline at end of file diff --git a/interactive_game_of_life.glsl b/interactive_game_of_life.glsl new file mode 100644 index 0000000..3baab36 --- /dev/null +++ b/interactive_game_of_life.glsl @@ -0,0 +1,71 @@ +#version 300 es +#ifdef GL_FRAGMENT_PRECISION_HIGH +precision highp float; +#else +precision mediump float; +#endif + +out vec4 fragColor; + +uniform vec2 resolution; +uniform int pointerCount; +uniform vec3 pointers[8]; +uniform sampler2D backbuffer; +uniform float time; +uniform sampler2D noise; +uniform int frame; + +float get(float x, float y) { + float val = texture(backbuffer, + (gl_FragCoord.xy + vec2(x, y)) / resolution).b; + val = step(0.01, val); + return val; +} + +float oneIfZero(float value) { + return step(abs(value), 0.1); +} + +float evaluate(float sum) { + float has3 = oneIfZero(sum - 3.0); + float has2 = oneIfZero(sum - 2.0); + // a cell is (or becomes) alive if it has 3 neighbors + // or if it has 2 neighbors *and* was alive already + return has3 + has2 * get(0.0, 0.0); +} + +void main() { + vec2 pos = gl_FragCoord.xy; + vec2 uv = pos / resolution.xy; + float sum = + get(-1.0, -1.0) + + get(-1.0, 0.0) + + get(-1.0, 1.0) + + get(0.0, -1.0) + + get(0.0, 1.0) + + get(1.0, -1.0) + + get(1.0, 0.0) + + get(1.0, 1.0); + + float tap = min(resolution.x, resolution.y) * 0.05; + for (int n = 0; n < pointerCount; ++n) { + if (distance(pointers[n].xy, gl_FragCoord.xy) < tap) { + sum = 3.0; + break; + } + } + + if (pos.x < 1.0 || pos.y < 1.0 || + pos.x > resolution.x - 1.0 || + pos.y > resolution.y - 1.0) { + float x = texture(noise, uv + time).r; + x = step(0.4, x) * 3.0; + sum = x; + } + + + vec3 col = vec3(uv, sin(time * 0.5)*0.2 + 0.7); + col *= evaluate(sum); + + fragColor = vec4(col, 1.0); +} \ No newline at end of file