vtm/vtm/resources/assets/shaders/location_2.glsl
2017-03-29 13:28:04 +03:00

46 lines
1.2 KiB
GLSL

#ifdef GLES
precision mediump float;
#endif
uniform mat4 u_mvp;
uniform float u_phase;
uniform float u_scale;
attribute vec2 a_pos;
varying vec2 v_tex;
void main() {
gl_Position = u_mvp * vec4(a_pos * u_scale * u_phase, 0.0, 1.0);
v_tex = a_pos;
}
$$
#ifdef GLES
precision mediump float;
#endif
varying vec2 v_tex;
uniform float u_scale;
uniform float u_phase;
uniform vec2 u_dir;
uniform int u_mode;
void main() {
float len = 1.0 - length(v_tex);
if (u_mode == -1) {
gl_FragColor = vec4(0.2, 0.2, 0.8, 1.0) * len;
} else {
// outer ring
float a = smoothstep(0.0, 2.0 / u_scale, len);
// inner ring
float b = 0.8 * smoothstep(3.0 / u_scale, 4.0 / u_scale, len);
// center point
float c = 0.5 * (1.0 - smoothstep(14.0 / u_scale, 16.0 / u_scale, 1.0 - len));
vec2 dir = normalize(v_tex);
float d = dot(dir, u_dir);
// 0.5 width of viewshed
d = clamp(smoothstep(0.7, 0.7 + 2.0 / u_scale, d) * len, 0.0, 1.0);
// - subtract inner from outer to create the outline
// - multiply by viewshed
// - add center point
a = max(d, (a - (b + c)) + c) + (u_mode == 2 ? c : 0);
gl_FragColor = vec4(0.2, 0.2, 0.8, 1.0) * a;
}
}