Skip to content

Commit c5afb8b

Browse files
committed
Fix small visual issue edges would start from node center. Now they start from node border.
1 parent 4d1bd2c commit c5afb8b

File tree

5 files changed

+57
-11
lines changed

5 files changed

+57
-11
lines changed

modules/opengl-commons/src/main/resources/org/gephi/viz-engine/shaders/edge/edge-line-directed.vert

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ attribute vec2 targetPosition;
2929
attribute float size;//It's the weight
3030
attribute vec4 sourceColor;
3131
attribute vec4 elementColor;
32+
attribute float sourceSize;
3233
attribute float targetSize;
3334

3435
varying vec4 fragColor;
@@ -42,9 +43,10 @@ void main() {
4243
vec2 sideVector = vec2(-directionNormalized.y, directionNormalized.x) * thickness * 0.5;
4344
vec2 arrowHeight = directionNormalized * thickness * ARROW_HEIGHT * 2.0;
4445

45-
vec2 lineEnd = direction - directionNormalized * targetSize;
46+
vec2 lineStart = directionNormalized * sourceSize;
47+
vec2 lineLength = (direction - lineStart) - directionNormalized * targetSize;
4648

47-
vec2 edgeVert = lineEnd * vert.x + sideVector * vert.y + arrowHeight * vert.z;
49+
vec2 edgeVert = lineStart + lineLength * vert.x + sideVector * vert.y + arrowHeight * vert.z;
4850

4951
gl_Position = mvp * vec4(edgeVert + position, 0.0, 1.0);
5052

modules/opengl-commons/src/main/resources/org/gephi/viz-engine/shaders/edge/edge-line-undirected.vert

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ attribute float size;//It's the weight
2929
attribute vec4 sourceColor;
3030
attribute vec4 targetColor;
3131
attribute vec4 elementColor;
32+
attribute float sourceSize;
33+
attribute float targetSize;
3234

3335
varying vec4 fragColor;
3436

@@ -40,8 +42,10 @@ void main() {
4042

4143
vec2 sideVector = vec2(-directionNormalized.y, directionNormalized.x) * thickness * 0.5;
4244

43-
vec2 lineEnd = direction;
44-
vec2 edgeVert = lineEnd * vert.x + sideVector * vert.y;
45+
vec2 lineStart = directionNormalized * sourceSize;
46+
vec2 lineLength = (direction - lineStart) - directionNormalized * targetSize;
47+
48+
vec2 edgeVert = lineStart + lineLength * vert.x + sideVector * vert.y;
4549

4650
gl_Position = mvp * vec4(edgeVert + position, 0.0, 1.0);
4751

modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/models/EdgeLineModelDirected.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class EdgeLineModelDirected {
2020
public static final int POSITION_TARGET_FLOATS = 2;
2121
public static final int SOURCE_COLOR_FLOATS = 1;
2222
public static final int COLOR_FLOATS = 1;
23+
public static final int SOURCE_SIZE_FLOATS = 1;
2324
public static final int TARGET_SIZE_FLOATS = 1;
2425
public static final int SIZE_FLOATS = 1;
2526

@@ -28,6 +29,7 @@ public class EdgeLineModelDirected {
2829
+ POSITION_TARGET_FLOATS
2930
+ SOURCE_COLOR_FLOATS
3031
+ COLOR_FLOATS
32+
+ SOURCE_SIZE_FLOATS
3133
+ TARGET_SIZE_FLOATS
3234
+ SIZE_FLOATS;
3335

@@ -67,6 +69,7 @@ private void initProgram(GL2ES2 gl) {
6769
.addAttribLocation(ATTRIB_NAME_SIZE, SHADER_SIZE_LOCATION)
6870
.addAttribLocation(ATTRIB_NAME_SOURCE_COLOR, SHADER_SOURCE_COLOR_LOCATION)
6971
.addAttribLocation(ATTRIB_NAME_COLOR, SHADER_COLOR_LOCATION)
72+
.addAttribLocation(ATTRIB_NAME_SOURCE_SIZE, SHADER_SOURCE_SIZE_LOCATION)
7073
.addAttribLocation(ATTRIB_NAME_TARGET_SIZE, SHADER_TARGET_SIZE_LOCATION)
7174
.init(gl);
7275

@@ -84,6 +87,7 @@ private void initProgram(GL2ES2 gl) {
8487
.addAttribLocation(ATTRIB_NAME_SIZE, SHADER_SIZE_LOCATION)
8588
.addAttribLocation(ATTRIB_NAME_SOURCE_COLOR, SHADER_SOURCE_COLOR_LOCATION)
8689
.addAttribLocation(ATTRIB_NAME_COLOR, SHADER_COLOR_LOCATION)
90+
.addAttribLocation(ATTRIB_NAME_SOURCE_SIZE, SHADER_SOURCE_SIZE_LOCATION)
8791
.addAttribLocation(ATTRIB_NAME_TARGET_SIZE, SHADER_TARGET_SIZE_LOCATION)
8892
.init(gl);
8993

@@ -101,6 +105,7 @@ private void initProgram(GL2ES2 gl) {
101105
.addAttribLocation(ATTRIB_NAME_SIZE, SHADER_SIZE_LOCATION)
102106
.addAttribLocation(ATTRIB_NAME_SOURCE_COLOR, SHADER_SOURCE_COLOR_LOCATION)
103107
.addAttribLocation(ATTRIB_NAME_COLOR, SHADER_COLOR_LOCATION)
108+
.addAttribLocation(ATTRIB_NAME_SOURCE_SIZE, SHADER_SOURCE_SIZE_LOCATION)
104109
.addAttribLocation(ATTRIB_NAME_TARGET_SIZE, SHADER_TARGET_SIZE_LOCATION)
105110
.init(gl);
106111
}

modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/models/EdgeLineModelUndirected.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,18 @@ public class EdgeLineModelUndirected {
2222
public static final int TARGET_COLOR_FLOATS = SOURCE_COLOR_FLOATS;
2323
public static final int COLOR_FLOATS = 1;
2424
public static final int SIZE_FLOATS = 1;
25+
public static final int SOURCE_SIZE_FLOATS = 1;
26+
public static final int TARGET_SIZE_FLOATS = 1;
2527

2628
public static final int TOTAL_ATTRIBUTES_FLOATS
2729
= POSITION_SOURCE_FLOATS
2830
+ POSITION_TARGET_LOCATION
2931
+ SOURCE_COLOR_FLOATS
3032
+ TARGET_COLOR_FLOATS
3133
+ COLOR_FLOATS
32-
+ SIZE_FLOATS;
34+
+ SIZE_FLOATS
35+
+ SOURCE_SIZE_FLOATS
36+
+ TARGET_SIZE_FLOATS;
3337

3438
private static final int VERTEX_PER_TRIANGLE = 3;
3539

@@ -69,6 +73,8 @@ private void initProgram(GL2ES2 gl) {
6973
.addAttribLocation(ATTRIB_NAME_SOURCE_COLOR, SHADER_SOURCE_COLOR_LOCATION)
7074
.addAttribLocation(ATTRIB_NAME_TARGET_COLOR, SHADER_TARGET_COLOR_LOCATION)
7175
.addAttribLocation(ATTRIB_NAME_COLOR, SHADER_COLOR_LOCATION)
76+
.addAttribLocation(ATTRIB_NAME_SOURCE_SIZE, SHADER_SOURCE_SIZE_LOCATION)
77+
.addAttribLocation(ATTRIB_NAME_TARGET_SIZE, SHADER_TARGET_SIZE_LOCATION)
7278
.init(gl);
7379

7480
programWithSelectionSelected = new GLShaderProgram(SHADERS_ROOT, SHADERS_EDGE_LINE_SOURCE_WITH_SELECTION_SELECTED, SHADERS_EDGE_LINE_SOURCE)
@@ -86,6 +92,8 @@ private void initProgram(GL2ES2 gl) {
8692
.addAttribLocation(ATTRIB_NAME_SOURCE_COLOR, SHADER_SOURCE_COLOR_LOCATION)
8793
.addAttribLocation(ATTRIB_NAME_TARGET_COLOR, SHADER_TARGET_COLOR_LOCATION)
8894
.addAttribLocation(ATTRIB_NAME_COLOR, SHADER_COLOR_LOCATION)
95+
.addAttribLocation(ATTRIB_NAME_SOURCE_SIZE, SHADER_SOURCE_SIZE_LOCATION)
96+
.addAttribLocation(ATTRIB_NAME_TARGET_SIZE, SHADER_TARGET_SIZE_LOCATION)
8997
.init(gl);
9098

9199
programWithSelectionUnselected = new GLShaderProgram(SHADERS_ROOT, SHADERS_EDGE_LINE_SOURCE_WITH_SELECTION_UNSELECTED, SHADERS_EDGE_LINE_SOURCE)
@@ -103,6 +111,8 @@ private void initProgram(GL2ES2 gl) {
103111
.addAttribLocation(ATTRIB_NAME_SOURCE_COLOR, SHADER_SOURCE_COLOR_LOCATION)
104112
.addAttribLocation(ATTRIB_NAME_TARGET_COLOR, SHADER_TARGET_COLOR_LOCATION)
105113
.addAttribLocation(ATTRIB_NAME_COLOR, SHADER_COLOR_LOCATION)
114+
.addAttribLocation(ATTRIB_NAME_SOURCE_SIZE, SHADER_SOURCE_SIZE_LOCATION)
115+
.addAttribLocation(ATTRIB_NAME_TARGET_SIZE, SHADER_TARGET_SIZE_LOCATION)
106116
.init(gl);
107117
}
108118

modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/common/AbstractEdgeData.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,10 @@ protected void fillUndirectedEdgeAttributesDataWithoutSelection(final float[] bu
569569
fillUndirectedEdgeAttributesDataBase(buffer, edge, index);
570570

571571
buffer[index + 7] = Float.intBitsToFloat(edge.getRGBA());//Color
572+
573+
//Source and target size:
574+
buffer[index + 8] = edge.getSource().size();
575+
buffer[index + 9] = edge.getTarget().size();
572576
}
573577

574578
protected void fillUndirectedEdgeAttributesDataWithSelection(final float[] buffer, final Edge edge, final int index, final boolean selected) {
@@ -606,6 +610,10 @@ protected void fillUndirectedEdgeAttributesDataWithSelection(final float[] buffe
606610
} else {
607611
buffer[index + 7] = Float.intBitsToFloat(edge.getRGBA());//Color
608612
}
613+
614+
//Source and target size:
615+
buffer[index + 8] = edge.getSource().size();
616+
buffer[index + 9] = edge.getTarget().size();
609617
}
610618

611619
protected void fillDirectedEdgeAttributesDataBase(final float[] buffer, final Edge edge, final int index) {
@@ -638,8 +646,9 @@ protected void fillDirectedEdgeAttributesDataWithoutSelection(final float[] buff
638646
//Color:
639647
buffer[index + 6] = Float.intBitsToFloat(edge.getRGBA());//Color
640648

641-
//Target size:
642-
buffer[index + 7] = edge.getTarget().size();
649+
//Source and target size:
650+
buffer[index + 7] = edge.getSource().size();
651+
buffer[index + 8] = edge.getTarget().size();
643652
}
644653

645654
protected void fillDirectedEdgeAttributesDataWithSelection(final float[] buffer, final Edge edge, final int index, final boolean selected) {
@@ -678,8 +687,9 @@ protected void fillDirectedEdgeAttributesDataWithSelection(final float[] buffer,
678687
buffer[index + 6] = Float.intBitsToFloat(edge.getRGBA());//Color
679688
}
680689

681-
//Target size:
682-
buffer[index + 7] = target.size();
690+
//Source and target size:
691+
buffer[index + 7] = source.size();
692+
buffer[index + 8] = target.size();
683693
}
684694

685695
private UndirectedEdgesVAO undirectedEdgesVAO;
@@ -820,6 +830,12 @@ protected void configure(GL2ES2 gl) {
820830
offset += EdgeLineModelUndirected.TARGET_COLOR_FLOATS * Float.BYTES;
821831

822832
gl.glVertexAttribPointer(SHADER_COLOR_LOCATION, EdgeLineModelUndirected.COLOR_FLOATS * Float.BYTES, GL_UNSIGNED_BYTE, false, stride, offset);
833+
offset += EdgeLineModelUndirected.COLOR_FLOATS * Float.BYTES;
834+
835+
gl.glVertexAttribPointer(SHADER_SOURCE_SIZE_LOCATION, EdgeLineModelDirected.SOURCE_SIZE_FLOATS, GL_FLOAT, false, stride, offset);
836+
offset += EdgeLineModelDirected.SOURCE_SIZE_FLOATS * Float.BYTES;
837+
838+
gl.glVertexAttribPointer(SHADER_TARGET_SIZE_LOCATION, EdgeLineModelDirected.TARGET_SIZE_FLOATS, GL_FLOAT, false, stride, offset);
823839
}
824840
attributesBuffer.unbind(gl);
825841
}
@@ -833,7 +849,9 @@ protected int[] getUsedAttributeLocations() {
833849
SHADER_SIZE_LOCATION,
834850
SHADER_SOURCE_COLOR_LOCATION,
835851
SHADER_TARGET_COLOR_LOCATION,
836-
SHADER_COLOR_LOCATION
852+
SHADER_COLOR_LOCATION,
853+
SHADER_SOURCE_SIZE_LOCATION,
854+
SHADER_TARGET_SIZE_LOCATION
837855
};
838856
}
839857

@@ -846,7 +864,9 @@ protected int[] getInstancedAttributeLocations() {
846864
SHADER_SIZE_LOCATION,
847865
SHADER_SOURCE_COLOR_LOCATION,
848866
SHADER_TARGET_COLOR_LOCATION,
849-
SHADER_COLOR_LOCATION
867+
SHADER_COLOR_LOCATION,
868+
SHADER_SOURCE_SIZE_LOCATION,
869+
SHADER_TARGET_SIZE_LOCATION
850870
};
851871
} else {
852872
return null;
@@ -891,6 +911,9 @@ protected void configure(GL2ES2 gl) {
891911
gl.glVertexAttribPointer(SHADER_COLOR_LOCATION, EdgeLineModelDirected.COLOR_FLOATS * Float.BYTES, GL_UNSIGNED_BYTE, false, stride, offset);
892912
offset += EdgeLineModelDirected.COLOR_FLOATS * Float.BYTES;
893913

914+
gl.glVertexAttribPointer(SHADER_SOURCE_SIZE_LOCATION, EdgeLineModelDirected.SOURCE_SIZE_FLOATS, GL_FLOAT, false, stride, offset);
915+
offset += EdgeLineModelDirected.SOURCE_SIZE_FLOATS * Float.BYTES;
916+
894917
gl.glVertexAttribPointer(SHADER_TARGET_SIZE_LOCATION, EdgeLineModelDirected.TARGET_SIZE_FLOATS, GL_FLOAT, false, stride, offset);
895918
}
896919
attributesBuffer.unbind(gl);
@@ -905,6 +928,7 @@ protected int[] getUsedAttributeLocations() {
905928
SHADER_SIZE_LOCATION,
906929
SHADER_SOURCE_COLOR_LOCATION,
907930
SHADER_COLOR_LOCATION,
931+
SHADER_SOURCE_SIZE_LOCATION,
908932
SHADER_TARGET_SIZE_LOCATION
909933
};
910934
}
@@ -918,6 +942,7 @@ protected int[] getInstancedAttributeLocations() {
918942
SHADER_SIZE_LOCATION,
919943
SHADER_SOURCE_COLOR_LOCATION,
920944
SHADER_COLOR_LOCATION,
945+
SHADER_SOURCE_SIZE_LOCATION,
921946
SHADER_TARGET_SIZE_LOCATION
922947
};
923948
} else {

0 commit comments

Comments
 (0)