Skip to content
This repository has been archived by the owner on Mar 23, 2019. It is now read-only.

Commit

Permalink
Enabled data-driven styling for circle-radius
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Wojciechowski committed Apr 12, 2016
1 parent 714881a commit 4356e41
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion circle.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ uniform lowp float u_blur;

varying lowp vec4 v_color;
varying vec2 v_extrude;
varying lowp float v_antialiasblur;

void main() {
float t = smoothstep(1.0 - u_blur, 1.0, length(v_extrude));
float t = smoothstep(1.0 - max(u_blur, v_antialiasblur), 1.0, length(v_extrude));
gl_FragColor = v_color * (1.0 - t);
}
16 changes: 14 additions & 2 deletions circle.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ precision highp float;

uniform mat4 u_matrix;
uniform mat4 u_exmatrix;
uniform mediump float u_size;
uniform float u_devicepixelratio;

attribute vec2 a_pos;

Expand All @@ -12,14 +12,21 @@ attribute lowp vec4 a_color;
uniform lowp vec4 a_color;
#endif

#ifdef ATTRIBUTE_RADIUS
attribute mediump float a_radius;
#else
uniform mediump float a_radius;
#endif

varying vec2 v_extrude;
varying lowp vec4 v_color;
varying lowp float v_antialiasblur;

void main(void) {
// unencode the extrusion vector that we snuck into the a_pos vector
v_extrude = vec2(mod(a_pos, 2.0) * 2.0 - 1.0);

vec4 extrude = u_exmatrix * vec4(v_extrude * u_size, 0, 0);
vec4 extrude = u_exmatrix * vec4(v_extrude * a_radius / 10.0, 0, 0);
// multiply a_pos by 0.5, since we had it * 2 in order to sneak
// in extrusion data
gl_Position = u_matrix * vec4(floor(a_pos * 0.5), 0, 1);
Expand All @@ -29,4 +36,9 @@ void main(void) {
gl_Position += extrude * gl_Position.w;

v_color = a_color / 255.0;

// This is a minimum blur distance that serves as a faux-antialiasing for
// the circle. since blur is a ratio of the circle's size and the intent is
// to keep the blur at roughly 1px, the two are inversely related.
v_antialiasblur = 1.0 / u_devicepixelratio / (a_radius / 10.0);
}

0 comments on commit 4356e41

Please sign in to comment.