-
Notifications
You must be signed in to change notification settings - Fork 82
Link sampling #195
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
Merged
+619
−18
Merged
Link sampling #195
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
740d3d6
feat: add link sampling API and demo story
Stukova cda2f44
feat(link-sampling): add angle to sampled links API and rotate labels
Stukova 569c032
fix: avoid zero-sized sampled links/points FBO when screenSize is [0,0]
Stukova 3983768
feat(link-sampling): tweak sampling distances and link sampling story
Stukova 232606f
docs: fix sampling distance defaults in configuration table (100, not…
Stukova a26fd14
feat(link-sampling): improve story and correct label placement on cur…
Stukova 9395152
Update css-labels dependency to 0.6.0
Stukova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import type { ShaderModule } from '@luma.gl/shadertools' | ||
|
|
||
| /** | ||
| * Shared GLSL for conic parametric curve (rational quadratic Bezier). | ||
| * Used by draw-curve-line.vert and fill-sampled-links.vert. | ||
| */ | ||
| const conicParametricCurveVS = /* glsl */ ` | ||
| vec2 conicParametricCurve(vec2 A, vec2 B, vec2 ControlPoint, float t, float w) { | ||
| vec2 divident = (1.0 - t) * (1.0 - t) * A + 2.0 * (1.0 - t) * t * w * ControlPoint + t * t * B; | ||
| float divisor = (1.0 - t) * (1.0 - t) + 2.0 * (1.0 - t) * t * w + t * t; | ||
| return divident / divisor; | ||
| } | ||
| ` | ||
|
|
||
| export const conicParametricCurveModule: ShaderModule = { | ||
| name: 'conicParametricCurve', | ||
| vs: conicParametricCurveVS, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #version 300 es | ||
| #ifdef GL_ES | ||
| precision highp float; | ||
| #endif | ||
|
|
||
| in vec4 rgba; | ||
|
|
||
| out vec4 fragColor; | ||
|
|
||
| void main() { | ||
| fragColor = rgba; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| #version 300 es | ||
| #ifdef GL_ES | ||
| precision highp float; | ||
| #endif | ||
|
|
||
| in vec2 pointA; | ||
| in vec2 pointB; | ||
| in float linkIndices; | ||
|
|
||
| uniform sampler2D positionsTexture; | ||
|
|
||
| #ifdef USE_UNIFORM_BUFFERS | ||
| layout(std140) uniform fillSampledLinksUniforms { | ||
| float pointsTextureSize; | ||
| mat4 transformationMatrix; | ||
| float spaceSize; | ||
| vec2 screenSize; | ||
| float curvedWeight; | ||
| float curvedLinkControlPointDistance; | ||
| float curvedLinkSegments; | ||
| } fillSampledLinks; | ||
|
|
||
| #define pointsTextureSize fillSampledLinks.pointsTextureSize | ||
| #define transformationMatrix fillSampledLinks.transformationMatrix | ||
| #define spaceSize fillSampledLinks.spaceSize | ||
| #define screenSize fillSampledLinks.screenSize | ||
| #define curvedWeight fillSampledLinks.curvedWeight | ||
| #define curvedLinkControlPointDistance fillSampledLinks.curvedLinkControlPointDistance | ||
| #define curvedLinkSegments fillSampledLinks.curvedLinkSegments | ||
| #else | ||
| uniform float pointsTextureSize; | ||
| uniform float spaceSize; | ||
| uniform vec2 screenSize; | ||
| uniform float curvedWeight; | ||
| uniform float curvedLinkControlPointDistance; | ||
| uniform float curvedLinkSegments; | ||
| uniform mat3 transformationMatrix; | ||
| #endif | ||
|
|
||
| out vec4 rgba; | ||
|
|
||
| void main() { | ||
| vec4 posA = texture(positionsTexture, (pointA + 0.5) / pointsTextureSize); | ||
| vec4 posB = texture(positionsTexture, (pointB + 0.5) / pointsTextureSize); | ||
| vec2 a = posA.rg; | ||
| vec2 b = posB.rg; | ||
|
|
||
| vec2 tangent = b - a; | ||
| float angle = -atan(tangent.y, tangent.x); | ||
|
|
||
| vec2 mid; | ||
| if (curvedLinkSegments <= 1.0) { | ||
| mid = (a + b) * 0.5; | ||
| } else if (curvedLinkControlPointDistance != 0.0 && curvedWeight != 0.0) { | ||
| vec2 xBasis = b - a; | ||
| vec2 yBasis = normalize(vec2(-xBasis.y, xBasis.x)); | ||
| float linkDist = length(xBasis); | ||
| float h = curvedLinkControlPointDistance; | ||
| vec2 controlPoint = (a + b) / 2.0 + yBasis * linkDist * h; | ||
| mid = conicParametricCurve(a, b, controlPoint, 0.5, curvedWeight); | ||
| } else { | ||
| mid = (a + b) * 0.5; | ||
| } | ||
|
|
||
| vec2 p = 2.0 * mid / spaceSize - 1.0; | ||
| p *= spaceSize / screenSize; | ||
| #ifdef USE_UNIFORM_BUFFERS | ||
| mat3 transformMat3 = mat3(transformationMatrix); | ||
| vec3 final = transformMat3 * vec3(p, 1); | ||
| #else | ||
| vec3 final = transformationMatrix * vec3(p, 1); | ||
| #endif | ||
|
|
||
| vec2 pointScreenPosition = (final.xy + 1.0) * screenSize / 2.0; | ||
| rgba = vec4(linkIndices, mid.x, mid.y, angle); | ||
| float i = (pointScreenPosition.x + 0.5) / screenSize.x; | ||
| float j = (pointScreenPosition.y + 0.5) / screenSize.y; | ||
| gl_Position = vec4(2.0 * vec2(i, j) - 1.0, 0.0, 1.0); | ||
|
|
||
| gl_PointSize = 1.0; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.