Skip to content
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

Fix line offset antialiasing #9408

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions examples/get-started/pure-js/maplibre/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// Copyright (c) vis.gl contributors

import {MapboxOverlay as DeckOverlay} from '@deck.gl/mapbox';
import {GeoJsonLayer, ArcLayer} from '@deck.gl/layers';
import {GeoJsonLayer, ArcLayer } from '@deck.gl/layers';
import { PathStyleExtension } from "@deck.gl/extensions";
import maplibregl from 'maplibre-gl';
import 'maplibre-gl/dist/maplibre-gl.css';

Expand All @@ -17,9 +18,18 @@ const map = new maplibregl.Map({
center: [0.45, 51.47],
zoom: 4,
bearing: 0,
pitch: 30
pitch: 30,
antialias: true
});

// basic feature collection with line from london to zurcich
const line = {
type: 'FeatureCollection',
features: [
{ type: 'Feature', geometry: { type: 'LineString', coordinates: [[1.46, 52.46], [9.54, 48.37]] } }
]
};

const deckOverlay = new DeckOverlay({
interleaved: true,
layers: [
Expand Down Expand Up @@ -50,6 +60,22 @@ const deckOverlay = new DeckOverlay({
getSourceColor: [0, 128, 200],
getTargetColor: [200, 0, 80],
getWidth: 1
}),
new GeoJsonLayer({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of changing the example could you update the render tests with the new images?

id: 'line-og',
data: line,
getLineColor: [0, 128, 200],
getLineWidth: 7,
lineWidthMinPixels: 5
}),
new GeoJsonLayer({
id: 'line',
data: line,
getLineColor: [128, 0, 200],
getLineWidth: 7,
lineWidthMinPixels: 5,
getOffset: (f) => 3,
extensions: [new PathStyleExtension({ offset: true })],
})
]
});
Expand Down
1 change: 1 addition & 0 deletions examples/get-started/pure-js/maplibre/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"@deck.gl/core": "^9.0.0",
"@deck.gl/extensions": "^9.1.0",
"@deck.gl/layers": "^9.0.0",
"@deck.gl/mapbox": "^9.0.0",
"maplibre-gl": "^3.0.0"
Expand Down
14 changes: 9 additions & 5 deletions modules/extensions/src/path-style/shaders.glsl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,19 @@ in float instanceOffsets;
`,
'vs:#main-end': `
float offsetWidth = abs(instanceOffsets * 2.0) + 1.0;
float offsetDir = sign(instanceOffsets);
float offsetDir = -sign(instanceOffsets);
vPathPosition.x = (vPathPosition.x + offsetDir) * offsetWidth - offsetDir;
vPathPosition.y *= offsetWidth;
vPathLength *= offsetWidth;
`,
'fs:#main-start': `
float isInside;
isInside = step(-1.0, vPathPosition.x) * step(vPathPosition.x, 1.0);
if (isInside == 0.0) {
'fs:#main-start': `
float dist = abs(vPathPosition.x);
// Smooth transition at the edges (from 0.9 to 1.1 for a slightly wider antialiasing band)
float opacity = 1.0 - smoothstep(0.9, 1.1, dist);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than doing 1.0 - smoothstep just swap the parameters

`,
'fs:#main-end': `
fragColor.a *= opacity;
if (fragColor.a < 0.001) {
discard;
}
`
Expand Down
Loading
Loading