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

Commit

Permalink
Merge pull request #3 from mapbox/fill-color-property-function
Browse files Browse the repository at this point in the history
Use pragmas for fill-color and fill-outline-color
  • Loading branch information
lucaswoj committed May 27, 2016
2 parents 4a567b4 + e4737bb commit 5d064aa
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/circle.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void main() {
float t = smoothstep(1.0 - u_blur, 1.0, length(v_extrude));
gl_FragColor = u_color * (1.0 - t) * u_opacity;
#else
#pragma mapbox: initialize color
#pragma mapbox: initialize color lowp

float t = smoothstep(1.0 - max(u_blur, v_antialiasblur), 1.0, length(v_extrude));
gl_FragColor = color * (1.0 - t) * u_opacity;
Expand Down
4 changes: 2 additions & 2 deletions src/circle.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ varying lowp float v_antialiasblur;
void main(void) {
#ifdef MAPBOX_GL_JS

#pragma mapbox: initialize color
#pragma mapbox: initialize radius
#pragma mapbox: initialize color lowp
#pragma mapbox: initialize radius mediump

#endif
// unencode the extrusion vector that we snuck into the a_pos vector
Expand Down
14 changes: 13 additions & 1 deletion src/fill.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@ precision mediump float;
#define highp
#endif

#ifdef MAPBOX_GL_JS
#pragma mapbox: define color lowp
#else
uniform lowp vec4 u_color;
#endif

uniform lowp float u_opacity;

void main() {
gl_FragColor = u_color * u_opacity;

#ifdef MAPBOX_GL_JS
#pragma mapbox: initialize color lowp
#else
lowp vec4 color = u_color;
#endif

gl_FragColor = color * u_opacity;

#ifdef OVERDRAW_INSPECTOR
gl_FragColor = vec4(1.0);
Expand Down
9 changes: 9 additions & 0 deletions src/fill.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ attribute vec2 a_pos;

uniform mat4 u_matrix;

#ifdef MAPBOX_GL_JS
#pragma mapbox: define color lowp
#endif

void main() {

#ifdef MAPBOX_GL_JS
#pragma mapbox: initialize color lowp
#endif

gl_Position = u_matrix * vec4(a_pos, 0, 1);
}
14 changes: 13 additions & 1 deletion src/outline.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,27 @@ precision mediump float;
#define highp
#endif

#ifdef MAPBOX_GL_JS
#pragma mapbox: define outline_color lowp
#else
uniform lowp vec4 u_color;
#endif

uniform lowp float u_opacity;

varying vec2 v_pos;

void main() {

#ifdef MAPBOX_GL_JS
#pragma mapbox: initialize outline_color lowp
#else
lowp vec4 outline_color = u_color;
#endif

float dist = length(v_pos - gl_FragCoord.xy);
float alpha = smoothstep(1.0, 0.0, dist);
gl_FragColor = u_color * (alpha * u_opacity);
gl_FragColor = outline_color * (alpha * u_opacity);

#ifdef OVERDRAW_INSPECTOR
gl_FragColor = vec4(1.0);
Expand Down
9 changes: 9 additions & 0 deletions src/outline.vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ uniform vec2 u_world;

varying vec2 v_pos;

#ifdef MAPBOX_GL_JS
#pragma mapbox: define outline_color lowp
#endif


void main() {
#ifdef MAPBOX_GL_JS
#pragma mapbox: initialize outline_color lowp
#endif

gl_Position = u_matrix * vec4(a_pos, 0, 1);
v_pos = (gl_Position.xy / gl_Position.w + 1.0) / 2.0 * u_world;
}

0 comments on commit 5d064aa

Please sign in to comment.