-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Highlight node with ring on hover/click
- Loading branch information
Showing
11 changed files
with
358 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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,19 @@ | ||
precision mediump float; | ||
|
||
uniform vec4 color; | ||
uniform float width; | ||
|
||
varying vec2 pos; | ||
varying float isHighlighted; | ||
|
||
const float smoothing = 1.05; | ||
|
||
void main () { | ||
if (isHighlighted == 0.0) discard; | ||
|
||
vec2 cxy = pos; | ||
float r = dot(cxy, cxy); | ||
float opacity = smoothstep(r, r * smoothing, 1.0); | ||
float stroke = smoothstep(width, width * smoothing, r); | ||
gl_FragColor = vec4(color.rgb, opacity * stroke * color.a); | ||
} |
This file contains 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,50 @@ | ||
precision mediump float; | ||
|
||
attribute vec2 quad; | ||
|
||
uniform sampler2D positions; | ||
uniform sampler2D particleSize; | ||
uniform mat3 transform; | ||
uniform float pointsTextureSize; | ||
uniform float sizeScale; | ||
uniform float spaceSize; | ||
uniform vec2 screenSize; | ||
uniform bool scaleNodesOnZoom; | ||
uniform vec2 hoveredPointIndices; | ||
uniform float maxPointSize; | ||
uniform vec4 color; | ||
|
||
varying float isHighlighted; | ||
varying vec2 pos; | ||
|
||
float pointSize(float size) { | ||
float pSize; | ||
if (scaleNodesOnZoom) { | ||
pSize = size * transform[0][0]; | ||
} else { | ||
pSize = size * min(5.0, max(1.0, transform[0][0] * 0.01)); | ||
} | ||
return min(pSize, maxPointSize); | ||
} | ||
|
||
const float relativeRingRadius = 1.3; | ||
|
||
void main () { | ||
if (hoveredPointIndices.r < 0.0) isHighlighted = 0.0; | ||
else isHighlighted = 1.0; | ||
pos = quad; | ||
vec4 pointPosition = texture2D(positions, (hoveredPointIndices + 0.5) / pointsTextureSize); | ||
vec4 pSize = texture2D(particleSize, (hoveredPointIndices + 0.5) / pointsTextureSize); | ||
float size = (pointSize(pSize.r * sizeScale) * relativeRingRadius) / transform[0][0]; | ||
float radius = size * 0.5; | ||
vec2 a = pointPosition.xy; | ||
vec2 b = pointPosition.xy + vec2(0.0, radius); | ||
vec2 xBasis = b - a; | ||
vec2 yBasis = normalize(vec2(-xBasis.y, xBasis.x)); | ||
vec2 point = a + xBasis * quad.x + yBasis * radius * quad.y; | ||
vec2 p = 2.0 * point / spaceSize - 1.0; | ||
p *= spaceSize / screenSize; | ||
vec3 final = transform * vec3(p, 1); | ||
|
||
gl_Position = vec4(final.rg, 0, 1); | ||
} |
This file contains 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,9 @@ | ||
#ifdef GL_ES | ||
precision highp float; | ||
#endif | ||
|
||
varying vec4 rgba; | ||
|
||
void main() { | ||
gl_FragColor = rgba; | ||
} |
This file contains 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,55 @@ | ||
#ifdef GL_ES | ||
precision highp float; | ||
#endif | ||
|
||
uniform sampler2D position; | ||
uniform float pointsTextureSize; | ||
uniform sampler2D particleSize; | ||
uniform float sizeScale; | ||
uniform float spaceSize; | ||
uniform vec2 screenSize; | ||
uniform float ratio; | ||
uniform mat3 transform; | ||
uniform vec2 mousePosition; | ||
uniform bool scaleNodesOnZoom; | ||
uniform float maxPointSize; | ||
|
||
attribute vec2 indexes; | ||
|
||
varying vec4 rgba; | ||
|
||
float pointSize(float size) { | ||
float pSize; | ||
if (scaleNodesOnZoom) { | ||
pSize = size * ratio * transform[0][0]; | ||
} else { | ||
pSize = size * ratio * min(5.0, max(1.0, transform[0][0] * 0.01)); | ||
} | ||
return min(pSize, maxPointSize); | ||
} | ||
|
||
float euclideanDistance (float x1, float x2, float y1, float y2) { | ||
return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); | ||
} | ||
|
||
void main() { | ||
vec4 pointPosition = texture2D(position, (indexes + 0.5) / pointsTextureSize); | ||
vec2 p = 2.0 * pointPosition.rg / spaceSize - 1.0; | ||
p *= spaceSize / screenSize; | ||
vec3 final = transform * vec3(p, 1); | ||
|
||
vec4 pSize = texture2D(particleSize, indexes / pointsTextureSize); | ||
float size = pSize.r * sizeScale; | ||
float pointRadius = 0.5 * pointSize(size); | ||
|
||
vec2 pointScreenPosition = (final.xy + 1.0) * screenSize / 2.0; | ||
rgba = vec4(0.0); | ||
gl_Position = vec4(0.5, 0.5, 0.0, 1.0); | ||
if (euclideanDistance(pointScreenPosition.x, mousePosition.x, pointScreenPosition.y, mousePosition.y) < pointRadius) { | ||
float index = indexes.g * pointsTextureSize + indexes.r; | ||
rgba = vec4(index, pSize.r, pointPosition.xy); | ||
gl_Position = vec4(-0.5, -0.5, 0.0, 1.0); | ||
} | ||
|
||
gl_PointSize = 1.0; | ||
} |
Oops, something went wrong.