diff --git a/modules/opengl-commons/src/main/resources/org/gephi/viz-engine/shaders/edge/edge-line-directed.vert b/modules/opengl-commons/src/main/resources/org/gephi/viz-engine/shaders/edge/edge-line-directed.vert index c29b53a..d12df49 100644 --- a/modules/opengl-commons/src/main/resources/org/gephi/viz-engine/shaders/edge/edge-line-directed.vert +++ b/modules/opengl-commons/src/main/resources/org/gephi/viz-engine/shaders/edge/edge-line-directed.vert @@ -29,6 +29,7 @@ attribute vec2 targetPosition; attribute float size;//It's the weight attribute vec4 sourceColor; attribute vec4 elementColor; +attribute float sourceSize; attribute float targetSize; varying vec4 fragColor; @@ -42,9 +43,10 @@ void main() { vec2 sideVector = vec2(-directionNormalized.y, directionNormalized.x) * thickness * 0.5; vec2 arrowHeight = directionNormalized * thickness * ARROW_HEIGHT * 2.0; - vec2 lineEnd = direction - directionNormalized * targetSize; + vec2 lineStart = directionNormalized * sourceSize; + vec2 lineLength = (direction - lineStart) - directionNormalized * targetSize; - vec2 edgeVert = lineEnd * vert.x + sideVector * vert.y + arrowHeight * vert.z; + vec2 edgeVert = lineStart + lineLength * vert.x + sideVector * vert.y + arrowHeight * vert.z; gl_Position = mvp * vec4(edgeVert + position, 0.0, 1.0); diff --git a/modules/opengl-commons/src/main/resources/org/gephi/viz-engine/shaders/edge/edge-line-undirected.vert b/modules/opengl-commons/src/main/resources/org/gephi/viz-engine/shaders/edge/edge-line-undirected.vert index 5d23c8a..d3360c4 100644 --- a/modules/opengl-commons/src/main/resources/org/gephi/viz-engine/shaders/edge/edge-line-undirected.vert +++ b/modules/opengl-commons/src/main/resources/org/gephi/viz-engine/shaders/edge/edge-line-undirected.vert @@ -29,6 +29,8 @@ attribute float size;//It's the weight attribute vec4 sourceColor; attribute vec4 targetColor; attribute vec4 elementColor; +attribute float sourceSize; +attribute float targetSize; varying vec4 fragColor; @@ -40,8 +42,10 @@ void main() { vec2 sideVector = vec2(-directionNormalized.y, directionNormalized.x) * thickness * 0.5; - vec2 lineEnd = direction; - vec2 edgeVert = lineEnd * vert.x + sideVector * vert.y; + vec2 lineStart = directionNormalized * sourceSize; + vec2 lineLength = (direction - lineStart) - directionNormalized * targetSize; + + vec2 edgeVert = lineStart + lineLength * vert.x + sideVector * vert.y; gl_Position = mvp * vec4(edgeVert + position, 0.0, 1.0); diff --git a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/models/EdgeLineModelDirected.java b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/models/EdgeLineModelDirected.java index b994aa0..b202c25 100644 --- a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/models/EdgeLineModelDirected.java +++ b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/models/EdgeLineModelDirected.java @@ -20,6 +20,7 @@ public class EdgeLineModelDirected { public static final int POSITION_TARGET_FLOATS = 2; public static final int SOURCE_COLOR_FLOATS = 1; public static final int COLOR_FLOATS = 1; + public static final int SOURCE_SIZE_FLOATS = 1; public static final int TARGET_SIZE_FLOATS = 1; public static final int SIZE_FLOATS = 1; @@ -28,6 +29,7 @@ public class EdgeLineModelDirected { + POSITION_TARGET_FLOATS + SOURCE_COLOR_FLOATS + COLOR_FLOATS + + SOURCE_SIZE_FLOATS + TARGET_SIZE_FLOATS + SIZE_FLOATS; @@ -67,6 +69,7 @@ private void initProgram(GL2ES2 gl) { .addAttribLocation(ATTRIB_NAME_SIZE, SHADER_SIZE_LOCATION) .addAttribLocation(ATTRIB_NAME_SOURCE_COLOR, SHADER_SOURCE_COLOR_LOCATION) .addAttribLocation(ATTRIB_NAME_COLOR, SHADER_COLOR_LOCATION) + .addAttribLocation(ATTRIB_NAME_SOURCE_SIZE, SHADER_SOURCE_SIZE_LOCATION) .addAttribLocation(ATTRIB_NAME_TARGET_SIZE, SHADER_TARGET_SIZE_LOCATION) .init(gl); @@ -84,6 +87,7 @@ private void initProgram(GL2ES2 gl) { .addAttribLocation(ATTRIB_NAME_SIZE, SHADER_SIZE_LOCATION) .addAttribLocation(ATTRIB_NAME_SOURCE_COLOR, SHADER_SOURCE_COLOR_LOCATION) .addAttribLocation(ATTRIB_NAME_COLOR, SHADER_COLOR_LOCATION) + .addAttribLocation(ATTRIB_NAME_SOURCE_SIZE, SHADER_SOURCE_SIZE_LOCATION) .addAttribLocation(ATTRIB_NAME_TARGET_SIZE, SHADER_TARGET_SIZE_LOCATION) .init(gl); @@ -101,6 +105,7 @@ private void initProgram(GL2ES2 gl) { .addAttribLocation(ATTRIB_NAME_SIZE, SHADER_SIZE_LOCATION) .addAttribLocation(ATTRIB_NAME_SOURCE_COLOR, SHADER_SOURCE_COLOR_LOCATION) .addAttribLocation(ATTRIB_NAME_COLOR, SHADER_COLOR_LOCATION) + .addAttribLocation(ATTRIB_NAME_SOURCE_SIZE, SHADER_SOURCE_SIZE_LOCATION) .addAttribLocation(ATTRIB_NAME_TARGET_SIZE, SHADER_TARGET_SIZE_LOCATION) .init(gl); } diff --git a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/models/EdgeLineModelUndirected.java b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/models/EdgeLineModelUndirected.java index f2d0013..0ff8246 100644 --- a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/models/EdgeLineModelUndirected.java +++ b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/models/EdgeLineModelUndirected.java @@ -22,6 +22,8 @@ public class EdgeLineModelUndirected { public static final int TARGET_COLOR_FLOATS = SOURCE_COLOR_FLOATS; public static final int COLOR_FLOATS = 1; public static final int SIZE_FLOATS = 1; + public static final int SOURCE_SIZE_FLOATS = 1; + public static final int TARGET_SIZE_FLOATS = 1; public static final int TOTAL_ATTRIBUTES_FLOATS = POSITION_SOURCE_FLOATS @@ -29,7 +31,9 @@ public class EdgeLineModelUndirected { + SOURCE_COLOR_FLOATS + TARGET_COLOR_FLOATS + COLOR_FLOATS - + SIZE_FLOATS; + + SIZE_FLOATS + + SOURCE_SIZE_FLOATS + + TARGET_SIZE_FLOATS; private static final int VERTEX_PER_TRIANGLE = 3; @@ -69,6 +73,8 @@ private void initProgram(GL2ES2 gl) { .addAttribLocation(ATTRIB_NAME_SOURCE_COLOR, SHADER_SOURCE_COLOR_LOCATION) .addAttribLocation(ATTRIB_NAME_TARGET_COLOR, SHADER_TARGET_COLOR_LOCATION) .addAttribLocation(ATTRIB_NAME_COLOR, SHADER_COLOR_LOCATION) + .addAttribLocation(ATTRIB_NAME_SOURCE_SIZE, SHADER_SOURCE_SIZE_LOCATION) + .addAttribLocation(ATTRIB_NAME_TARGET_SIZE, SHADER_TARGET_SIZE_LOCATION) .init(gl); 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) { .addAttribLocation(ATTRIB_NAME_SOURCE_COLOR, SHADER_SOURCE_COLOR_LOCATION) .addAttribLocation(ATTRIB_NAME_TARGET_COLOR, SHADER_TARGET_COLOR_LOCATION) .addAttribLocation(ATTRIB_NAME_COLOR, SHADER_COLOR_LOCATION) + .addAttribLocation(ATTRIB_NAME_SOURCE_SIZE, SHADER_SOURCE_SIZE_LOCATION) + .addAttribLocation(ATTRIB_NAME_TARGET_SIZE, SHADER_TARGET_SIZE_LOCATION) .init(gl); 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) { .addAttribLocation(ATTRIB_NAME_SOURCE_COLOR, SHADER_SOURCE_COLOR_LOCATION) .addAttribLocation(ATTRIB_NAME_TARGET_COLOR, SHADER_TARGET_COLOR_LOCATION) .addAttribLocation(ATTRIB_NAME_COLOR, SHADER_COLOR_LOCATION) + .addAttribLocation(ATTRIB_NAME_SOURCE_SIZE, SHADER_SOURCE_SIZE_LOCATION) + .addAttribLocation(ATTRIB_NAME_TARGET_SIZE, SHADER_TARGET_SIZE_LOCATION) .init(gl); } diff --git a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/common/AbstractEdgeData.java b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/common/AbstractEdgeData.java index 168727d..abe888d 100644 --- a/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/common/AbstractEdgeData.java +++ b/modules/opengl-jogl/src/main/java/org/gephi/viz/engine/jogl/pipeline/common/AbstractEdgeData.java @@ -569,6 +569,10 @@ protected void fillUndirectedEdgeAttributesDataWithoutSelection(final float[] bu fillUndirectedEdgeAttributesDataBase(buffer, edge, index); buffer[index + 7] = Float.intBitsToFloat(edge.getRGBA());//Color + + //Source and target size: + buffer[index + 8] = edge.getSource().size(); + buffer[index + 9] = edge.getTarget().size(); } 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 } else { buffer[index + 7] = Float.intBitsToFloat(edge.getRGBA());//Color } + + //Source and target size: + buffer[index + 8] = edge.getSource().size(); + buffer[index + 9] = edge.getTarget().size(); } protected void fillDirectedEdgeAttributesDataBase(final float[] buffer, final Edge edge, final int index) { @@ -638,8 +646,9 @@ protected void fillDirectedEdgeAttributesDataWithoutSelection(final float[] buff //Color: buffer[index + 6] = Float.intBitsToFloat(edge.getRGBA());//Color - //Target size: - buffer[index + 7] = edge.getTarget().size(); + //Source and target size: + buffer[index + 7] = edge.getSource().size(); + buffer[index + 8] = edge.getTarget().size(); } 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, buffer[index + 6] = Float.intBitsToFloat(edge.getRGBA());//Color } - //Target size: - buffer[index + 7] = target.size(); + //Source and target size: + buffer[index + 7] = source.size(); + buffer[index + 8] = target.size(); } private UndirectedEdgesVAO undirectedEdgesVAO; @@ -820,6 +830,12 @@ protected void configure(GL2ES2 gl) { offset += EdgeLineModelUndirected.TARGET_COLOR_FLOATS * Float.BYTES; gl.glVertexAttribPointer(SHADER_COLOR_LOCATION, EdgeLineModelUndirected.COLOR_FLOATS * Float.BYTES, GL_UNSIGNED_BYTE, false, stride, offset); + offset += EdgeLineModelUndirected.COLOR_FLOATS * Float.BYTES; + + gl.glVertexAttribPointer(SHADER_SOURCE_SIZE_LOCATION, EdgeLineModelDirected.SOURCE_SIZE_FLOATS, GL_FLOAT, false, stride, offset); + offset += EdgeLineModelDirected.SOURCE_SIZE_FLOATS * Float.BYTES; + + gl.glVertexAttribPointer(SHADER_TARGET_SIZE_LOCATION, EdgeLineModelDirected.TARGET_SIZE_FLOATS, GL_FLOAT, false, stride, offset); } attributesBuffer.unbind(gl); } @@ -833,7 +849,9 @@ protected int[] getUsedAttributeLocations() { SHADER_SIZE_LOCATION, SHADER_SOURCE_COLOR_LOCATION, SHADER_TARGET_COLOR_LOCATION, - SHADER_COLOR_LOCATION + SHADER_COLOR_LOCATION, + SHADER_SOURCE_SIZE_LOCATION, + SHADER_TARGET_SIZE_LOCATION }; } @@ -846,7 +864,9 @@ protected int[] getInstancedAttributeLocations() { SHADER_SIZE_LOCATION, SHADER_SOURCE_COLOR_LOCATION, SHADER_TARGET_COLOR_LOCATION, - SHADER_COLOR_LOCATION + SHADER_COLOR_LOCATION, + SHADER_SOURCE_SIZE_LOCATION, + SHADER_TARGET_SIZE_LOCATION }; } else { return null; @@ -891,6 +911,9 @@ protected void configure(GL2ES2 gl) { gl.glVertexAttribPointer(SHADER_COLOR_LOCATION, EdgeLineModelDirected.COLOR_FLOATS * Float.BYTES, GL_UNSIGNED_BYTE, false, stride, offset); offset += EdgeLineModelDirected.COLOR_FLOATS * Float.BYTES; + gl.glVertexAttribPointer(SHADER_SOURCE_SIZE_LOCATION, EdgeLineModelDirected.SOURCE_SIZE_FLOATS, GL_FLOAT, false, stride, offset); + offset += EdgeLineModelDirected.SOURCE_SIZE_FLOATS * Float.BYTES; + gl.glVertexAttribPointer(SHADER_TARGET_SIZE_LOCATION, EdgeLineModelDirected.TARGET_SIZE_FLOATS, GL_FLOAT, false, stride, offset); } attributesBuffer.unbind(gl); @@ -905,6 +928,7 @@ protected int[] getUsedAttributeLocations() { SHADER_SIZE_LOCATION, SHADER_SOURCE_COLOR_LOCATION, SHADER_COLOR_LOCATION, + SHADER_SOURCE_SIZE_LOCATION, SHADER_TARGET_SIZE_LOCATION }; } @@ -918,6 +942,7 @@ protected int[] getInstancedAttributeLocations() { SHADER_SIZE_LOCATION, SHADER_SOURCE_COLOR_LOCATION, SHADER_COLOR_LOCATION, + SHADER_SOURCE_SIZE_LOCATION, SHADER_TARGET_SIZE_LOCATION }; } else {