Last active
February 15, 2018 11:30
-
-
Save yvan-sraka/ac642e416503f5cd5ec2d1ca2f9b2b4d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef GL_FRAGMENT_PRECISION_HIGH | |
precision highp float; | |
#else | |
precision mediump float; | |
#endif | |
uniform vec2 resolution; | |
uniform int pointerCount; | |
uniform vec3 pointers[10]; | |
uniform sampler2D backbuffer; | |
float get(float x, float y) { | |
return 2.0 * texture2D( | |
backbuffer, | |
(gl_FragCoord.xy + vec2(x, y)) / resolution).r; | |
} | |
vec3 evaluate(float sum) { | |
float a = 1.0 - abs(clamp(sum - 3.0, -1.0, 1.0)); | |
float b = 1.0 - abs(clamp(sum - 2.0, -1.0, 1.0)); | |
return vec3(a + b * get(0.0, 0.0)); | |
} | |
void main() { | |
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 * 2.0) { | |
sum = 3.0; | |
break; | |
} | |
} | |
gl_FragColor = vec4(0.5 * evaluate(sum), 1.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment