Skip to content

Commit

Permalink
Merge pull request #23 from mapbox/property-function-line
Browse files Browse the repository at this point in the history
Add support for property functions in line-color
  • Loading branch information
lucaswoj authored Aug 18, 2016
2 parents de2ab00 + df16247 commit 7971dc1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/line.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ precision mediump float;
#define highp
#endif

uniform lowp vec4 u_color;
uniform lowp float u_opacity;
uniform float u_blur;

#pragma mapbox: define lowp vec4 color

varying vec2 v_linewidth;
varying vec2 v_normal;
varying float v_gamma_scale;

void main() {
#pragma mapbox: initialize lowp vec4 color

// Calculate the distance of the pixel from the line in pixels.
float dist = length(v_normal) * v_linewidth.s;

Expand All @@ -24,7 +27,7 @@ void main() {
float blur = u_blur * v_gamma_scale;
float alpha = clamp(min(dist - (v_linewidth.t - blur), v_linewidth.s - dist) / blur, 0.0, 1.0);

gl_FragColor = u_color * (alpha * u_opacity);
gl_FragColor = color * (alpha * u_opacity);

#ifdef OVERDRAW_INSPECTOR
gl_FragColor = vec4(1.0);
Expand Down
4 changes: 4 additions & 0 deletions src/line.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ varying vec2 v_normal;
varying vec2 v_linewidth;
varying float v_gamma_scale;

#pragma mapbox: define lowp vec4 color

void main() {
#pragma mapbox: initialize lowp vec4 color

vec2 a_extrude = a_data.xy - 128.0;
float a_direction = mod(a_data.z, 4.0) - 1.0;

Expand Down
7 changes: 5 additions & 2 deletions src/linesdfpattern.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ precision mediump float;
#define highp
#endif

uniform lowp vec4 u_color;
uniform lowp float u_opacity;

uniform float u_blur;
Expand All @@ -20,7 +19,11 @@ varying vec2 v_tex_a;
varying vec2 v_tex_b;
varying float v_gamma_scale;

#pragma mapbox: define lowp vec4 color

void main() {
#pragma mapbox: initialize lowp vec4 color

// Calculate the distance of the pixel from the line in pixels.
float dist = length(v_normal) * v_linewidth.s;

Expand All @@ -35,7 +38,7 @@ void main() {
float sdfdist = mix(sdfdist_a, sdfdist_b, u_mix);
alpha *= smoothstep(0.5 - u_sdfgamma, 0.5 + u_sdfgamma, sdfdist);

gl_FragColor = u_color * (alpha * u_opacity);
gl_FragColor = color * (alpha * u_opacity);

#ifdef OVERDRAW_INSPECTOR
gl_FragColor = vec4(1.0);
Expand Down
4 changes: 4 additions & 0 deletions src/linesdfpattern.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ varying vec2 v_tex_a;
varying vec2 v_tex_b;
varying float v_gamma_scale;

#pragma mapbox: define lowp vec4 color

void main() {
#pragma mapbox: initialize lowp vec4 color

vec2 a_extrude = a_data.xy - 128.0;
float a_direction = mod(a_data.z, 4.0) - 1.0;
float a_linesofar = (floor(a_data.z / 4.0) + a_data.w * 64.0) * LINE_DISTANCE_SCALE;
Expand Down

0 comments on commit 7971dc1

Please sign in to comment.