Skip to content

Commit

Permalink
fix line-trim-offset shader (#12017) (#12018)
Browse files Browse the repository at this point in the history
* fix line-trim-offset shader

* fix line-trim-offset check

Co-authored-by: Stepan Kuzmin <[email protected]>
  • Loading branch information
ansis and stepankuzmin authored Jun 20, 2022
1 parent 9fc5327 commit e46f4a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/render/program/line_program.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,11 @@ const lineDefinesValues = (layer: LineStyleLayer): LineDefinesType[] => {
const values = [];
if (hasDash(layer)) values.push('RENDER_LINE_DASH');
if (layer.paint.get('line-gradient')) values.push('RENDER_LINE_GRADIENT');
if (layer.paint.get('line-trim-offset')) values.push('RENDER_LINE_TRIM_OFFSET');

const trimOffset = layer.paint.get('line-trim-offset');
if (trimOffset[0] !== 0 || trimOffset[1] !== 0) {
values.push('RENDER_LINE_TRIM_OFFSET');
}

const hasPattern = layer.paint.get('line-pattern').constantOr((1: any));
const hasOpacity = layer.paint.get('line-opacity').constantOr(1.0) !== 1.0;
Expand Down
9 changes: 7 additions & 2 deletions src/shaders/line.fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,13 @@ void main() {
// Mark the pixel to be transparent when:
// 1. trim_offset range is valid
// 2. line_progress is within trim_offset range
if (trim_end > trim_start && (line_progress <= trim_end && line_progress >= trim_start)) {
out_color = vec4(0, 0, 0, 0);

// Nested conditionals fixes the issue
// https://github.com/mapbox/mapbox-gl-js/issues/12013
if (trim_end > trim_start) {
if (line_progress <= trim_end && line_progress >= trim_start) {
out_color = vec4(0, 0, 0, 0);
}
}
#endif

Expand Down

0 comments on commit e46f4a2

Please sign in to comment.