-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable property functions for more symbol paint properties #4226
Changes from 5 commits
d9d6afd
c5fa36e
6ccb5ca
05bb0a2
16c0a63
2c07f03
7427148
8f3dce4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,19 @@ | ||
#define SDF_PX 8.0 | ||
#define BLUR_OFFSET 1.19 | ||
#define HALO_OFFSET 6.0 | ||
#define GAMMA 0.105/DEVICE_PIXEL_RATIO | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opinion Below 👇I find some of these constant names cryptic:
I prefer a very clear constant name (ideally googleable) to a magic number, and a magic number to a cryptic constant name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LOL, I totally agree with you that these names are cryptic. And here I must confess, I just did a lazy/dumb transcription from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you 🙇. If you can't come up with a meaningful name, feel free to inline. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @lucaswoj I inlined a couple of them, but chose to leave |
||
|
||
uniform bool u_is_halo; | ||
#pragma mapbox: define lowp vec4 fill_color | ||
#pragma mapbox: define lowp vec4 halo_color | ||
uniform bool u_is_halo; | ||
#pragma mapbox: define lowp float opacity | ||
#pragma mapbox: define lowp float halo_width | ||
#pragma mapbox: define lowp float halo_blur | ||
|
||
uniform sampler2D u_texture; | ||
uniform sampler2D u_fadetexture; | ||
uniform lowp float u_opacity; | ||
uniform lowp float u_buffer; | ||
uniform lowp float u_gamma; | ||
uniform lowp float u_font_scale; | ||
uniform lowp float u_gamma_scale; | ||
|
||
varying vec2 v_tex; | ||
varying vec2 v_fade_tex; | ||
|
@@ -15,18 +22,25 @@ varying float v_gamma_scale; | |
void main() { | ||
#pragma mapbox: initialize lowp vec4 fill_color | ||
#pragma mapbox: initialize lowp vec4 halo_color | ||
#pragma mapbox: initialize lowp float opacity | ||
#pragma mapbox: initialize lowp float halo_width | ||
#pragma mapbox: initialize lowp float halo_blur | ||
|
||
lowp vec4 color = fill_color; | ||
lowp float gamma = GAMMA / u_gamma_scale; | ||
lowp float buff = (256.0 - 64.0) / 256.0; | ||
if (u_is_halo) { | ||
color = halo_color; | ||
gamma = (halo_blur * BLUR_OFFSET / SDF_PX + GAMMA) / u_gamma_scale; | ||
buff = (HALO_OFFSET - halo_width / u_font_scale) / SDF_PX; | ||
} | ||
|
||
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; | ||
lowp float gamma_scaled = gamma * v_gamma_scale; | ||
lowp float alpha = smoothstep(buff - gamma_scaled, buff + gamma_scaled, dist) * fade_alpha; | ||
|
||
gl_FragColor = color * (alpha * u_opacity); | ||
gl_FragColor = color * (alpha * opacity); | ||
|
||
#ifdef OVERDRAW_INSPECTOR | ||
gl_FragColor = vec4(1.0); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
"version": 8, | ||
"metadata": { | ||
"test": { | ||
"width": 64, | ||
"height": 64, | ||
"skipped": { | ||
"native": "https://github.com/mapbox/mapbox-gl-native/issues/7866" | ||
} | ||
} | ||
}, | ||
"sources": { | ||
"geojson": { | ||
"type": "geojson", | ||
"data": { | ||
"type": "FeatureCollection", | ||
"features": [ | ||
{ | ||
"type": "Feature", | ||
"properties": { "x": 0 }, | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
0, | ||
-10 | ||
] | ||
} | ||
}, { | ||
"type": "Feature", | ||
"properties": { "x": 1 }, | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
0, | ||
10 | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"sprite": "local://sprites/sprite", | ||
"layers": [ | ||
{ | ||
"id": "symbol", | ||
"type": "symbol", | ||
"source": "geojson", | ||
"layout": { | ||
"icon-image": "dot.sdf" | ||
}, | ||
"paint": { | ||
"icon-halo-width": 3, | ||
"icon-halo-color": "green", | ||
"icon-halo-blur": { | ||
"property": "x", | ||
"stops": [ | ||
[ | ||
0, | ||
1 | ||
], | ||
[ | ||
1, | ||
3 | ||
] | ||
] | ||
} | ||
} | ||
} | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accidental
//
?