Skip to content

Instantly share code, notes, and snippets.

@polyfloyd
Created October 8, 2017 18:10
Show Gist options
  • Select an option

  • Save polyfloyd/a964141130e731522a72587c968f0ade to your computer and use it in GitHub Desktop.

Select an option

Save polyfloyd/a964141130e731522a72587c968f0ade to your computer and use it in GitHub Desktop.
A hollywood radar image rendered by a fragment shader for glslsandbox.com
#ifdef GL_ES
precision mediump float;
#endif
#extension GL_OES_standard_derivatives : enable
uniform float time;
uniform vec2 mouse;
uniform vec2 resolution;
const float PI = 3.1415;
const float TAU = PI * 2.;
float rand(float a, float b) {
return fract(sin(dot(vec2(a, b), vec2(12.9898,78.233))) * 43758.5453);
}
float grid(vec2 pos, float size) {
return min(step(mod(pos.x, size), 1.) + step(mod(pos.y, size), 1.), 1.);
}
float scanner(vec2 pos, vec2 center, float radius, float angrad, float linger) {
mat2 rotation = mat2(cos(angrad), -sin(angrad), sin(angrad), cos(angrad));
vec2 rpos = (pos - center) * rotation;
float scan = (-atan(rpos.x, rpos.y) + PI) / TAU;
float scantrace = -scan*PI + linger;
return clamp(scantrace, 0., 1.) * step(distance(pos, center), radius);
}
float detection(vec2 pos, vec2 center, float radius, vec2 obj, float size, float angrad) {
mat2 rotation = mat2(cos(angrad), -sin(angrad), sin(angrad), cos(angrad));
vec2 rpos = (pos - center) * rotation;
float scan = (atan(rpos.x, rpos.y) + PI) / TAU;
return (1. - clamp(distance(pos, center + obj) / size, 0., 1.)) * scan * step(distance(pos, center), radius);
}
void main(void) {
float angrad = time * 2.;
float radius = min(resolution.x, resolution.y) / 2.;
vec3 gr = vec3(0., grid(gl_FragCoord.xy, 24.) * .2, 0.);
vec3 scan = vec3(0., scanner(gl_FragCoord.xy, resolution / 2., radius, angrad, .5), 0.);
float det = 0.;
for (int i = 0; i < 20; i++) {
float rs = rand(float(i), float(i));
float rx = rand(rs, float(i));
float ry = rand(rs, rx);
float size = 10. + mod(rs * 30., 30.);
vec2 pos = vec2(mod(rx, 1.) * 2. - 1., mod(ry, 1.) * 2. - 1.);
det = clamp(det + detection(gl_FragCoord.xy, resolution / 2., radius, radius * pos, size, angrad), 0., 1.);
}
gl_FragColor.rgb = gr + scan + vec3(0., det, det);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment