Skip to content

Commit

Permalink
Enable property functions for text-halo-color
Browse files Browse the repository at this point in the history
  • Loading branch information
anandthakker committed Feb 2, 2017
1 parent 105d233 commit 61d8a16
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
3 changes: 2 additions & 1 deletion js/data/bucket/symbol_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ const symbolInterfaces = {
layoutVertexArrayType: layoutVertexArrayType,
elementArrayType: elementArrayType,
paintAttributes: [
{property: 'text-color', type: 'Uint8'}
{property: 'text-color', type: 'Uint8'},
{property: 'text-halo-color', type: 'Uint8'}
]
},
icon: {
Expand Down
2 changes: 2 additions & 0 deletions js/render/draw_symbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,12 @@ function drawTileSymbols(program, painter, layer, tile, buffers, isText, isSDF,
if (haloWidth) { // Draw halo underneath the text.
gl.uniform1f(program.u_gamma, (haloBlur * blurOffset / sdfPx + gamma) / gammaScale);
gl.uniform1f(program.u_buffer, (haloOffset - haloWidth / fontScale) / sdfPx);
gl.uniform1f(program.u_is_halo, 1);

drawSymbolElements(buffers, layer, gl, program);
}

gl.uniform1f(program.u_is_halo, 0);
gl.uniform1f(program.u_gamma, gamma / gammaScale);
gl.uniform1f(program.u_buffer, (256 - 64) / 256);
}
Expand Down
1 change: 1 addition & 0 deletions js/style-spec/reference/v8.json
Original file line number Diff line number Diff line change
Expand Up @@ -2675,6 +2675,7 @@
"default": "rgba(0, 0, 0, 0)",
"function": "interpolated",
"zoom-function": true,
"property-function": true,
"transition": true,
"doc": "The color of the text's halo, which helps it stand out from backgrounds.",
"requires": [
Expand Down
10 changes: 9 additions & 1 deletion shaders/symbol_sdf.fragment.glsl
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
#pragma mapbox: define lowp vec4 color
#pragma mapbox: define lowp vec4 halo_color

uniform sampler2D u_texture;
uniform sampler2D u_fadetexture;
uniform lowp float u_opacity;
uniform lowp float u_buffer;
uniform lowp float u_gamma;
uniform bool u_is_halo;

varying vec2 v_tex;
varying vec2 v_fade_tex;
varying float v_gamma_scale;

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

lowp vec4 color_to_use = color;
if (u_is_halo) {
color_to_use = halo_color;
}

lowp float dist = texture2D(u_texture, v_tex).a;
lowp float fade_alpha = texture2D(u_fadetexture, v_fade_tex).a;
lowp float gamma = u_gamma * v_gamma_scale;
lowp float alpha = smoothstep(u_buffer - gamma, u_buffer + gamma, dist) * fade_alpha;

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

#ifdef OVERDRAW_INSPECTOR
gl_FragColor = vec4(1.0);
Expand Down
2 changes: 2 additions & 0 deletions shaders/symbol_sdf.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ attribute vec2 a_texture_pos;
attribute vec4 a_data;

#pragma mapbox: define lowp vec4 color
#pragma mapbox: define lowp vec4 halo_color

// matrix is for the vertex position.
uniform mat4 u_matrix;
Expand All @@ -26,6 +27,7 @@ varying float v_gamma_scale;

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

vec2 a_tex = a_texture_pos.xy;
mediump float a_labelminzoom = a_data[0];
Expand Down

0 comments on commit 61d8a16

Please sign in to comment.