Skip to content

Commit

Permalink
No longer using color bias to highlight selected elements because it …
Browse files Browse the repository at this point in the history
…depends on background color. Only mix un-selected elements with background color so they get dimmed
  • Loading branch information
eduramiba committed Jun 12, 2024
1 parent e70e3a9 commit 17dd7a4
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class Constants {
public static final String UNIFORM_NAME_BACKGROUND_COLOR = "backgroundColor";
public static final String UNIFORM_NAME_SIZE_MULTIPLIER = "sizeMultiplier";
public static final String UNIFORM_NAME_COLOR_LIGHTEN_FACTOR = "colorLightenFactor";
public static final String UNIFORM_NAME_COLOR_BIAS = "colorBias";
public static final String UNIFORM_NAME_COLOR_MULTIPLIER = "colorMultiplier";

//Rendering order:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@

uniform mat4 mvp;
//#if with_selection
//#if selected
uniform float colorBias;
uniform float colorMultiplier;
//#else
//#if !selected
uniform vec4 backgroundColor;
uniform float colorLightenFactor;
//#endif
Expand Down Expand Up @@ -60,9 +57,7 @@ void main() {
color = color / 255.0;

//#if with_selection
//#if selected
color.rgb = colorBias + color.rgb * colorMultiplier;
//#else
//#if !selected
color.rgb = mix(color.rgb, backgroundColor.rgb, colorLightenFactor);
//#endif
//#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@

uniform mat4 mvp;
//#if with_selection
//#if selected
uniform float colorBias;
uniform float colorMultiplier;
//#else
//#if !selected
uniform vec4 backgroundColor;
uniform float colorLightenFactor;
//#endif
Expand Down Expand Up @@ -59,9 +56,7 @@ void main() {
color = color / 255.0;

//#if with_selection
//#if selected
color.rgb = colorBias + color.rgb * colorMultiplier;
//#else
//#if !selected
color.rgb = mix(color.rgb, backgroundColor.rgb, colorLightenFactor);
//#endif
//#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ uniform mat4 mvp;
uniform float sizeMultiplier;
uniform float colorMultiplier;
//#if with_selection
//#if selected
uniform float colorBias;
//#else
//#if !selected
uniform vec4 backgroundColor;
uniform float colorLightenFactor;
//#endif
Expand All @@ -35,7 +33,7 @@ void main() {

//#if with_selection
//#if selected
color.rgb = colorBias + color.rgb * colorMultiplier;
color.rgb = color.rgb * colorMultiplier;
//#else
color.rgb = color.rgb * colorMultiplier;
color.rgb = mix(color.rgb, backgroundColor.rgb, colorLightenFactor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ private void initProgram(GL2ES2 gl) {

programWithSelectionSelected = new GLShaderProgram(SHADERS_ROOT, SHADERS_EDGE_LINE_SOURCE_WITH_SELECTION_SELECTED, SHADERS_EDGE_LINE_SOURCE)
.addUniformName(UNIFORM_NAME_MODEL_VIEW_PROJECTION)
.addUniformName(UNIFORM_NAME_COLOR_BIAS)
.addUniformName(UNIFORM_NAME_COLOR_MULTIPLIER)
.addUniformName(UNIFORM_NAME_EDGE_SCALE_MIN)
.addUniformName(UNIFORM_NAME_EDGE_SCALE_MAX)
Expand Down Expand Up @@ -131,9 +130,9 @@ public void useProgram(GL2ES2 gl, float[] mvpFloats, float scale, float minWeigh
prepareProgramData(gl, mvpFloats, scale, minWeight, maxWeight);
}

public void useProgramWithSelectionSelected(GL2ES2 gl, float[] mvpFloats, float scale, float minWeight, float maxWeight, float colorBias, float colorMultiplier) {
public void useProgramWithSelectionSelected(GL2ES2 gl, float[] mvpFloats, float scale, float minWeight, float maxWeight) {
programWithSelectionSelected.use(gl);
prepareProgramDataWithSelectionSelected(gl, mvpFloats, scale, minWeight, maxWeight, colorBias, colorMultiplier);
prepareProgramDataWithSelectionSelected(gl, mvpFloats, scale, minWeight, maxWeight);
}

public void useProgramWithSelectionUnselected(GL2ES2 gl, float[] mvpFloats, float scale, float minWeight, float maxWeight, float[] backgroundColorFloats, float colorLightenFactor) {
Expand All @@ -154,10 +153,8 @@ private void prepareProgramData(GL2ES2 gl, float[] mvpFloats, float scale, float
}
}

private void prepareProgramDataWithSelectionSelected(GL2ES2 gl, float[] mvpFloats, float scale, float minWeight, float maxWeight, float colorBias, float colorMultiplier) {
private void prepareProgramDataWithSelectionSelected(GL2ES2 gl, float[] mvpFloats, float scale, float minWeight, float maxWeight) {
gl.glUniformMatrix4fv(programWithSelectionSelected.getUniformLocation(UNIFORM_NAME_MODEL_VIEW_PROJECTION), 1, false, mvpFloats, 0);
gl.glUniform1f(programWithSelectionSelected.getUniformLocation(UNIFORM_NAME_COLOR_BIAS), colorBias);
gl.glUniform1f(programWithSelectionSelected.getUniformLocation(UNIFORM_NAME_COLOR_MULTIPLIER), colorMultiplier);
gl.glUniform1f(programWithSelectionSelected.getUniformLocation(UNIFORM_NAME_EDGE_SCALE_MIN), EDGE_SCALE_MIN * scale);
gl.glUniform1f(programWithSelectionSelected.getUniformLocation(UNIFORM_NAME_EDGE_SCALE_MAX), EDGE_SCALE_MAX * scale);
gl.glUniform1f(programWithSelectionSelected.getUniformLocation(UNIFORM_NAME_MIN_WEIGHT), minWeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ private void initProgram(GL2ES2 gl) {

programWithSelectionSelected = new GLShaderProgram(SHADERS_ROOT, SHADERS_EDGE_LINE_SOURCE_WITH_SELECTION_SELECTED, SHADERS_EDGE_LINE_SOURCE)
.addUniformName(UNIFORM_NAME_MODEL_VIEW_PROJECTION)
.addUniformName(UNIFORM_NAME_COLOR_BIAS)
.addUniformName(UNIFORM_NAME_COLOR_MULTIPLIER)
.addUniformName(UNIFORM_NAME_EDGE_SCALE_MIN)
.addUniformName(UNIFORM_NAME_EDGE_SCALE_MAX)
.addUniformName(UNIFORM_NAME_MIN_WEIGHT)
Expand Down Expand Up @@ -137,9 +135,9 @@ public void useProgram(GL2ES2 gl, float[] mvpFloats, float scale, float minWeigh
prepareProgramData(gl, mvpFloats, scale, minWeight, maxWeight);
}

public void useProgramWithSelectionSelected(GL2ES2 gl, float[] mvpFloats, float scale, float minWeight, float maxWeight, float colorBias, float colorMultiplier) {
public void useProgramWithSelectionSelected(GL2ES2 gl, float[] mvpFloats, float scale, float minWeight, float maxWeight) {
programWithSelectionSelected.use(gl);
prepareProgramDataWithSelectionSelected(gl, mvpFloats, scale, minWeight, maxWeight, colorBias, colorMultiplier);
prepareProgramDataWithSelectionSelected(gl, mvpFloats, scale, minWeight, maxWeight);
}

public void useProgramWithSelectionUnselected(GL2ES2 gl, float[] mvpFloats, float scale, float minWeight, float maxWeight, float[] backgroundColorFloats, float colorLightenFactor) {
Expand All @@ -164,10 +162,8 @@ private void prepareProgramData(GL2ES2 gl, float[] mvpFloats, float scale, float
}
}

private void prepareProgramDataWithSelectionSelected(GL2ES2 gl, float[] mvpFloats, float scale, float minWeight, float maxWeight, float colorBias, float colorMultiplier) {
private void prepareProgramDataWithSelectionSelected(GL2ES2 gl, float[] mvpFloats, float scale, float minWeight, float maxWeight) {
gl.glUniformMatrix4fv(programWithSelectionSelected.getUniformLocation(UNIFORM_NAME_MODEL_VIEW_PROJECTION), 1, false, mvpFloats, 0);
gl.glUniform1f(programWithSelectionSelected.getUniformLocation(UNIFORM_NAME_COLOR_BIAS), colorBias);
gl.glUniform1f(programWithSelectionSelected.getUniformLocation(UNIFORM_NAME_COLOR_MULTIPLIER), colorMultiplier);
gl.glUniform1f(programWithSelectionSelected.getUniformLocation(UNIFORM_NAME_EDGE_SCALE_MIN), EDGE_SCALE_MIN * scale);
gl.glUniform1f(programWithSelectionSelected.getUniformLocation(UNIFORM_NAME_EDGE_SCALE_MAX), EDGE_SCALE_MAX * scale);
gl.glUniform1f(programWithSelectionSelected.getUniformLocation(UNIFORM_NAME_MIN_WEIGHT), minWeight);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import static org.gephi.viz.engine.util.gl.Constants.SHADER_SIZE_LOCATION;
import static org.gephi.viz.engine.util.gl.Constants.SHADER_VERT_LOCATION;
import static org.gephi.viz.engine.util.gl.Constants.UNIFORM_NAME_BACKGROUND_COLOR;
import static org.gephi.viz.engine.util.gl.Constants.UNIFORM_NAME_COLOR_BIAS;
import static org.gephi.viz.engine.util.gl.Constants.UNIFORM_NAME_COLOR_LIGHTEN_FACTOR;
import static org.gephi.viz.engine.util.gl.Constants.UNIFORM_NAME_COLOR_MULTIPLIER;
import static org.gephi.viz.engine.util.gl.Constants.UNIFORM_NAME_MODEL_VIEW_PROJECTION;
Expand Down Expand Up @@ -62,7 +61,6 @@ public void initGLPrograms(GL2ES2 gl) {
programWithSelectionSelected = new GLShaderProgram(SHADERS_ROOT, SHADERS_NODE_CIRCLE_SOURCE_WITH_SELECTION_SELECTED, SHADERS_NODE_CIRCLE_SOURCE)
.addUniformName(UNIFORM_NAME_MODEL_VIEW_PROJECTION)
.addUniformName(UNIFORM_NAME_SIZE_MULTIPLIER)
.addUniformName(UNIFORM_NAME_COLOR_BIAS)
.addUniformName(UNIFORM_NAME_COLOR_MULTIPLIER)
.addAttribLocation(ATTRIB_NAME_VERT, SHADER_VERT_LOCATION)
.addAttribLocation(ATTRIB_NAME_POSITION, SHADER_POSITION_LOCATION)
Expand Down Expand Up @@ -101,13 +99,12 @@ public void drawIndirect(GL4 gl, int instanceCount, int instancesOffset) {
gl.glMultiDrawArraysIndirect(GL_TRIANGLES, (long) instancesOffset * INDIRECT_DRAW_COMMAND_BYTES, instanceCount, 0);
}

public void useProgramWithSelectionSelected(GL2ES2 gl, float[] mvpFloats, float sizeMultiplier, float colorBias, float colorMultiplier) {
public void useProgramWithSelectionSelected(GL2ES2 gl, float[] mvpFloats, float sizeMultiplier, float colorMultiplier) {
//Circle:
programWithSelectionSelected.use(gl);

gl.glUniformMatrix4fv(programWithSelectionSelected.getUniformLocation(UNIFORM_NAME_MODEL_VIEW_PROJECTION), 1, false, mvpFloats, 0);
gl.glUniform1f(programWithSelectionSelected.getUniformLocation(UNIFORM_NAME_SIZE_MULTIPLIER), sizeMultiplier);
gl.glUniform1f(programWithSelectionSelected.getUniformLocation(UNIFORM_NAME_COLOR_BIAS), colorBias);
gl.glUniform1f(programWithSelectionSelected.getUniformLocation(UNIFORM_NAME_COLOR_MULTIPLIER), colorMultiplier);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public void update(VizEngine engine, GraphIndexImpl spatialIndex) {

public void drawArrays(GL2ES2 gl, RenderingLayer layer, VizEngine engine, float[] mvpFloats) {
//First we draw outside circle (for border) and then inside circle:
//FIXME: all node parts should be drawn at the same time, otherwise internal parts of nodes can cover external parts!
drawArraysInternal(gl, layer, engine, mvpFloats, true);
drawArraysInternal(gl, layer, engine, mvpFloats, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected int setupShaderProgramForRenderingLayerUndirected(final GL2ES2 gl,
);

if (someSelection) {
if (someSelection && edgeSelectionColor) {
if (edgeSelectionColor) {
lineModelUndirected.useProgram(
gl,
mvpFloats,
Expand All @@ -142,17 +142,12 @@ protected int setupShaderProgramForRenderingLayerUndirected(final GL2ES2 gl,
maxWeight
);
} else {
final float colorBias = 0.5f;
final float colorMultiplier = 0.5f;

lineModelUndirected.useProgramWithSelectionSelected(
gl,
mvpFloats,
edgeScale,
minWeight,
maxWeight,
colorBias,
colorMultiplier
maxWeight
);
}
} else {
Expand Down Expand Up @@ -231,17 +226,12 @@ protected int setupShaderProgramForRenderingLayerDirected(final GL2ES2 gl,
maxWeight
);
} else {
final float colorBias = 0.5f;
final float colorMultiplier = 0.5f;

lineModelDirected.useProgramWithSelectionSelected(
gl,
mvpFloats,
edgeScale,
minWeight,
maxWeight,
colorBias,
colorMultiplier
maxWeight
);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,11 @@ protected int setupShaderProgramForRenderingLayer(final GL2ES2 gl,
instanceCount = instanceCounter.selectedCountToDraw;

if (someSelection) {
final float colorBias = isRenderingOutsideCircle ? 0f : 0.5f;
final float colorMultiplier = isRenderingOutsideCircle ? 1f : 0.5f;
final float colorMultiplier = isRenderingOutsideCircle ? NODER_BORDER_DARKEN_FACTOR : 1f;
diskModel.useProgramWithSelectionSelected(
gl,
mvpFloats,
sizeMultiplier,
colorBias,
colorMultiplier
);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public void update(VizEngine engine, GraphIndexImpl spatialIndex) {

public void drawIndirect(GL4 gl, RenderingLayer layer, VizEngine engine, float[] mvpFloats) {
//First we draw outside circle (for border) and then inside circle:
//FIXME: all node parts should be drawn at the same time, otherwise internal parts of nodes can cover external parts!
drawIndirectInternal(gl, layer, engine, mvpFloats, true);
drawIndirectInternal(gl, layer, engine, mvpFloats, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public void update(VizEngine engine, GraphIndexImpl spatialIndex) {

public void drawInstanced(GL2ES3 gl, RenderingLayer layer, VizEngine engine, float[] mvpFloats) {
//First we draw outside circle (for border) and then inside circle:
//FIXME: all node parts should be drawn at the same time, otherwise internal parts of nodes can cover external parts!
drawInstancedInternal(gl, layer, engine, mvpFloats, true);
drawInstancedInternal(gl, layer, engine, mvpFloats, false);
}
Expand Down

0 comments on commit 17dd7a4

Please sign in to comment.