diff options
author | Sven Gothel <[email protected]> | 2023-09-30 01:28:59 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-09-30 01:28:59 +0200 |
commit | 297c48f4fefd1ab59800524ea5f0dd56684d6786 (patch) | |
tree | 02c1b8f65de349c9af3bc2a5b94e04e90d75c684 /src/jogl/classes/jogamp/graph/curve/opengl | |
parent | 2e46eb1bf06ef07801062122716aa99a6c871646 (diff) |
Bug 1465 - Graph / GraphUI: Render a Region's ColorTexture in proper aspect-ratio, letter-boxed or zoomed (config) + Bug 1466 Fix color mixing
Bug 1465: Region currently simply bloats a given texture to its region AABBox,
which renders textures with the wrong aspect ratio.
Add facility to program the texture-coordinates to either letter-box
or scaled-up (and cut) true aspect-ratio.
Default shall be zoom (scale-up and cut),
but user shall be able to set a flag in the Region for letter-box.
Have the shader clip texture coordinates properly,
best w/o branching to soothe performance.
See functions.glsl
+++
Bug 1466: Current color mix: texture * color_channel * color_static
is useless in GraphUI.
color_static shall modulate the texture, which works.
But in case of color_channel (attribute/varying)
we want it to be mixed so it can become the more dominant color
for e.g. a border.
Desired is:
color = vec4( mix( tex.rgb * gcu_ColorStatic.rgb, gcv_Color.rgb, gcv_Color.a ),
mix( tex.a * gcu_ColorStatic.a, 1, gcv_Color.a) );
Diffstat (limited to 'src/jogl/classes/jogamp/graph/curve/opengl')
9 files changed, 80 insertions, 72 deletions
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java index 73af4603d..c5b1e8309 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PMSAAES2.java @@ -50,7 +50,6 @@ import com.jogamp.opengl.FBObject.Attachment; import com.jogamp.opengl.util.GLArrayDataServer; import com.jogamp.opengl.util.glsl.ShaderProgram; import com.jogamp.opengl.util.texture.Texture; -import com.jogamp.opengl.util.texture.TextureCoords; import com.jogamp.opengl.util.texture.TextureSequence; public final class VBORegion2PMSAAES2 extends GLRegion { @@ -61,8 +60,8 @@ public final class VBORegion2PMSAAES2 extends GLRegion { // Pass-1: private final GLUniformData gcu_ColorTexUnit; - private final float[] colorTexBBox; // x0, y0, x1, y1 - private final GLUniformData gcu_ColorTexBBox; + private final float[] colorTexBBox; // minX/minY, maxX/maxY, texW/texH + private final GLUniformData gcu_ColorTexBBox; // vec2 gcu_ColorTexBBox[3] -> boxMin[2], boxMax[2] and texSize[2] private ShaderProgram spPass1 = null; // Pass-2: @@ -97,8 +96,8 @@ public final class VBORegion2PMSAAES2 extends GLRegion { if( hasColorTexture() ) { gcu_ColorTexUnit = new GLUniformData(UniformNames.gcu_ColorTexUnit, colorTexSeq.getTextureUnit()); - colorTexBBox = new float[4]; - gcu_ColorTexBBox = new GLUniformData(UniformNames.gcu_ColorTexBBox, 4, FloatBuffer.wrap(colorTexBBox)); + colorTexBBox = new float[6]; + gcu_ColorTexBBox = new GLUniformData(UniformNames.gcu_ColorTexBBox, 2, FloatBuffer.wrap(colorTexBBox)); } else { gcu_ColorTexUnit = null; colorTexBBox = null; @@ -148,21 +147,7 @@ public final class VBORegion2PMSAAES2 extends GLRegion { vpc_ileave.enableBuffer(gl, false); if( hasColorTexture && null != gcu_ColorTexUnit && colorTexSeq.isTextureAvailable() ) { - final TextureSequence.TextureFrame frame = colorTexSeq.getLastTexture(); - final Texture tex = frame.getTexture(); - final TextureCoords tc = tex.getImageTexCoords(); - final float tcSx = 1f / ( tc.right() - tc.left() ); - colorTexBBox[0] = box.getMinX() * tcSx; - colorTexBBox[2] = box.getMaxX() * tcSx; - if( tex.getMustFlipVertically() ) { - final float tcSy = 1f / ( tc.bottom() - tc.top() ); - colorTexBBox[1] = box.getMaxY() * tcSy; - colorTexBBox[3] = box.getMinY() * tcSy; - } else { - final float tcSy = 1f / ( tc.top() - tc.bottom() ); - colorTexBBox[1] = box.getMinY() * tcSy; - colorTexBBox[3] = box.getMaxY() * tcSy; - } + TextureSequence.setTexCoordBBox(colorTexSeq.getLastTexture().getTexture(), box, isColorTextureLetterbox(), colorTexBBox); } gca_FboVerticesAttr.seal(gl, false); { diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java index 9fad72881..b05a04802 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegion2PVBAAES2.java @@ -53,7 +53,6 @@ import com.jogamp.opengl.FBObject.TextureAttachment; import com.jogamp.opengl.util.GLArrayDataServer; import com.jogamp.opengl.util.glsl.ShaderProgram; import com.jogamp.opengl.util.texture.Texture; -import com.jogamp.opengl.util.texture.TextureCoords; import com.jogamp.opengl.util.texture.TextureSequence; public final class VBORegion2PVBAAES2 extends GLRegion { @@ -94,8 +93,9 @@ public final class VBORegion2PVBAAES2 extends GLRegion { // Pass-1: private final GLUniformData gcu_ColorTexUnit; - private final float[] colorTexBBox; // x0, y0, x1, y1 - private final GLUniformData gcu_ColorTexBBox; + private final float[] colorTexBBox; // minX/minY, maxX/maxY, texW/texH + private final GLUniformData gcu_ColorTexBBox; // vec2 gcu_ColorTexBBox[3] -> boxMin[2], boxMax[2] and texSize[2] + private ShaderProgram spPass1 = null; // Pass-2: @@ -193,8 +193,8 @@ public final class VBORegion2PVBAAES2 extends GLRegion { if( hasColorTexture() ) { gcu_ColorTexUnit = new GLUniformData(UniformNames.gcu_ColorTexUnit, colorTexSeq.getTextureUnit()); - colorTexBBox = new float[4]; - gcu_ColorTexBBox = new GLUniformData(UniformNames.gcu_ColorTexBBox, 4, FloatBuffer.wrap(colorTexBBox)); + colorTexBBox = new float[6]; + gcu_ColorTexBBox = new GLUniformData(UniformNames.gcu_ColorTexBBox, 2, FloatBuffer.wrap(colorTexBBox)); } else { gcu_ColorTexUnit = null; colorTexBBox = null; @@ -235,6 +235,7 @@ public final class VBORegion2PVBAAES2 extends GLRegion { @Override protected void updateImpl(final GL2ES2 gl, final int curRenderModes) { + @SuppressWarnings("unused") final boolean hasColorChannel = Region.hasColorChannel( curRenderModes ); final boolean hasColorTexture = Region.hasColorTexture( curRenderModes ); @@ -244,21 +245,7 @@ public final class VBORegion2PVBAAES2 extends GLRegion { vpc_ileave.seal(gl, true); vpc_ileave.enableBuffer(gl, false); if( hasColorTexture && null != gcu_ColorTexUnit && colorTexSeq.isTextureAvailable() ) { - final TextureSequence.TextureFrame frame = colorTexSeq.getLastTexture(); - final Texture tex = frame.getTexture(); - final TextureCoords tc = tex.getImageTexCoords(); - final float tcSx = 1f / ( tc.right() - tc.left() ); - colorTexBBox[0] = box.getMinX() * tcSx; - colorTexBBox[2] = box.getMaxX() * tcSx; - if( tex.getMustFlipVertically() ) { - final float tcSy = 1f / ( tc.bottom() - tc.top() ); - colorTexBBox[1] = box.getMaxY() * tcSy; - colorTexBBox[3] = box.getMinY() * tcSy; - } else { - final float tcSy = 1f / ( tc.top() - tc.bottom() ); - colorTexBBox[1] = box.getMinY() * tcSy; - colorTexBBox[3] = box.getMaxY() * tcSy; - } + TextureSequence.setTexCoordBBox(colorTexSeq.getLastTexture().getTexture(), box, isColorTextureLetterbox(), colorTexBBox); } gca_FboVerticesAttr.seal(gl, false); { diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java index a819f9267..634b53fe2 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java +++ b/src/jogl/classes/jogamp/graph/curve/opengl/VBORegionSPES2.java @@ -42,7 +42,6 @@ import com.jogamp.graph.curve.opengl.RegionRenderer; import com.jogamp.graph.curve.opengl.RenderState; import com.jogamp.opengl.util.glsl.ShaderProgram; import com.jogamp.opengl.util.texture.Texture; -import com.jogamp.opengl.util.texture.TextureCoords; import com.jogamp.opengl.util.texture.TextureSequence; public final class VBORegionSPES2 extends GLRegion { @@ -50,8 +49,8 @@ public final class VBORegionSPES2 extends GLRegion { // Pass-1: private final GLUniformData gcu_ColorTexUnit; - private final float[] colorTexBBox; // x0, y0, x1, y1 - private final GLUniformData gcu_ColorTexBBox; + private final float[] colorTexBBox; // minX/minY, maxX/maxY, texW/texH + private final GLUniformData gcu_ColorTexBBox; // vec2 gcu_ColorTexBBox[3] -> boxMin[2], boxMax[2] and texSize[2] private ShaderProgram spPass1 = null; public VBORegionSPES2(final GLProfile glp, final int renderModes, final TextureSequence colorTexSeq, @@ -65,8 +64,8 @@ public final class VBORegionSPES2 extends GLRegion { if( hasColorTexture() ) { gcu_ColorTexUnit = new GLUniformData(UniformNames.gcu_ColorTexUnit, colorTexSeq.getTextureUnit()); - colorTexBBox = new float[4]; - gcu_ColorTexBBox = new GLUniformData(UniformNames.gcu_ColorTexBBox, 4, FloatBuffer.wrap(colorTexBBox)); + colorTexBBox = new float[6]; + gcu_ColorTexBBox = new GLUniformData(UniformNames.gcu_ColorTexBBox, 2, FloatBuffer.wrap(colorTexBBox)); } else { gcu_ColorTexUnit = null; colorTexBBox = null; @@ -91,22 +90,7 @@ public final class VBORegionSPES2 extends GLRegion { vpc_ileave.seal(gl, true); vpc_ileave.enableBuffer(gl, false); if( hasColorTexture && null != gcu_ColorTexUnit && colorTexSeq.isTextureAvailable() ) { - final TextureSequence.TextureFrame frame = colorTexSeq.getLastTexture(); - final Texture tex = frame.getTexture(); - final TextureCoords tc = tex.getImageTexCoords(); - final float tcSx = 1f / ( tc.right() - tc.left() ); - colorTexBBox[0] = box.getMinX() * tcSx; - colorTexBBox[2] = box.getMaxX() * tcSx; - final float tcSy; - if( tex.getMustFlipVertically() ) { - tcSy = 1f / ( tc.bottom() - tc.top() ); - colorTexBBox[1] = box.getMaxY() * tcSy; - colorTexBBox[3] = box.getMinY() * tcSy; - } else { - tcSy = 1f / ( tc.top() - tc.bottom() ); - colorTexBBox[1] = box.getMinY() * tcSy; - colorTexBBox[3] = box.getMaxY() * tcSy; - } + TextureSequence.setTexCoordBBox(colorTexSeq.getLastTexture().getTexture(), box, isColorTextureLetterbox(), colorTexBBox); } indicesBuffer.seal(gl, true); indicesBuffer.enableBuffer(gl, false); diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.glsl index 447242438..6ff35df85 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1-curve_simple.glsl @@ -1,10 +1,15 @@ + // Copyright 2010-2023 JogAmp Community. All rights reserved. if( gcv_CurveParam.x == 0.0 && gcv_CurveParam.y == 0.0 ) { // pass-1: Lines #if defined(USE_COLOR_TEXTURE) && defined(USE_COLOR_CHANNEL) - mgl_FragColor = gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st) * gcv_Color * gcu_ColorStatic; + vec4 t = clip_coord(gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st), vec4(1), gcv_ColorTexCoord, vec2(0), gcv_ColorTexExt); + + mgl_FragColor = vec4( mix( t.rgb * gcu_ColorStatic.rgb, gcv_Color.rgb, gcv_Color.a ), + mix( t.a * gcu_ColorStatic.a, 1, gcv_Color.a) ); #elif defined(USE_COLOR_TEXTURE) - mgl_FragColor = gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st) * gcu_ColorStatic; + mgl_FragColor = clip_coord(gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st), vec4(1), gcv_ColorTexCoord, vec2(0), gcv_ColorTexExt) + * gcu_ColorStatic; #elif defined(USE_COLOR_CHANNEL) mgl_FragColor = gcv_Color * gcu_ColorStatic; #else @@ -22,10 +27,13 @@ float a = clamp(0.5 - ( position/length(f) ) * sign(gcv_CurveParam.y), 0.0, 1.0); #if defined(USE_COLOR_TEXTURE) && defined(USE_COLOR_CHANNEL) - vec4 t = gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st); - mgl_FragColor = vec4(t.rgb * gcv_Color.rgb * gcu_ColorStatic.rgb, t.a * gcv_Color.a * gcu_ColorStatic.a * a); + vec4 t = clip_coord(gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st), vec4(1), gcv_ColorTexCoord, vec2(0), gcv_ColorTexExt); + + mgl_FragColor = vec4( mix( t.rgb * gcu_ColorStatic.rgb, gcv_Color.rgb, gcv_Color.a ), + a * mix( t.a * gcu_ColorStatic.a, 1, gcv_Color.a) ); #elif defined(USE_COLOR_TEXTURE) - vec4 t = gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st); + vec4 t = clip_coord(gcuTexture2D(gcu_ColorTexUnit, gcv_ColorTexCoord.st), vec4(1), gcv_ColorTexCoord, vec2(0), gcv_ColorTexExt); + mgl_FragColor = vec4(t.rgb * gcu_ColorStatic.rgb, t.a * gcu_ColorStatic.a * a); #elif defined(USE_COLOR_CHANNEL) mgl_FragColor = vec4(gcv_Color.rgb * gcu_ColorStatic.rgb, gcv_Color.a * gcu_ColorStatic.a * a); diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1.vp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1.vp index c6ed4ca58..de41d9198 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1.vp +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-pass1.vp @@ -1,4 +1,4 @@ -//Copyright 2010 JogAmp Community. All rights reserved. +// Copyright 2010-2023 JogAmp Community. All rights reserved. #if __VERSION__ >= 130 #define attribute in @@ -24,8 +24,9 @@ void main(void) } #endif #ifdef USE_COLOR_TEXTURE - vec2 dim = vec2(gcu_ColorTexBBox.z - gcu_ColorTexBBox.x, gcu_ColorTexBBox.w - gcu_ColorTexBBox.y); - gcv_ColorTexCoord = vec2(gca_Vertices.x - gcu_ColorTexBBox.x, gca_Vertices.y - gcu_ColorTexBBox.y) / dim; + vec2 dim = vec2(gcu_ColorTexBBox[1].x - gcu_ColorTexBBox[0].x, gcu_ColorTexBBox[1].y - gcu_ColorTexBBox[0].y); + gcv_ColorTexCoord = vec2(gca_Vertices.x - gcu_ColorTexBBox[0].x, gca_Vertices.y - gcu_ColorTexBBox[0].y) / dim; + gcv_ColorTexExt = gcu_ColorTexBBox[2]; // texture-size #endif #ifdef USE_COLOR_CHANNEL gcv_Color = gca_Colors; diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-segment-head.fp b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-segment-head.fp index 05407a4e6..c88619154 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-segment-head.fp +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/curverenderer01-segment-head.fp @@ -1,4 +1,4 @@ -//Copyright 2010 JogAmp Community. All rights reserved. +// Copyright 2010-2023 JogAmp Community. All rights reserved. // // 2-pass shader w/o weight @@ -13,4 +13,3 @@ #endif #define GetSample(texUnit, texCoord, psize, cx, cy, offX, offY) texture2D(texUnit, texCoord + psize * vec2(cx+offX, cy+offY)) - diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/functions.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/functions.glsl new file mode 100644 index 000000000..eeab54ebf --- /dev/null +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/functions.glsl @@ -0,0 +1,42 @@ +// Copyright 2023 JogAmp Community. All rights reserved. + +#ifndef functions_glsl +#define functions_glsl + +/** Returns product of components. */ +float v_mul( vec2 v ) { + return v.x * v.y; +} +/** Returns component wise logical 'or' as float '0' or '1' using the components product and clamp. */ +float v_or( vec2 v ) { + return clamp(v.x * v.y, 0, 1); +} + +/** Returns sum of components. */ +float v_sum( vec2 v ) { + return v.x + v.y; +} +/** Returns component wise logical 'and' as float '0' or '1' using the components sum and clamp. */ +float v_and( vec2 v ) { + return clamp(v.x + v.y, 0, 1); +} + +/** + * Branch-less clipping function. + * <p> + * Returns either 'col_in' if the 'coord' is within ['low'..'high'] range, + * otherwise 'col_ex'. + * </p> + * <p> + * This is achieved via the build-in 'step' and 'mix' function + * as well as our own 'v_mul' and v_and' function, + * which flattens a 'vec2' to one float suitable to be used as the 'mix' criteria. + * </p> + */ +vec4 clip_coord(vec4 col_in, vec4 col_ex, vec2 coord, vec2 low, vec2 high) { + vec4 c = mix( col_ex, col_in, v_mul( step(low, coord) )); + return mix( c, col_ex, v_and( step(high, coord) )); +} + +#endif // functions_glsl + diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl index cd014b732..956c31d4b 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/uniforms.glsl @@ -7,7 +7,7 @@ uniform vec4 gcu_ColorStatic; uniform float gcu_Weight; #ifdef USE_COLOR_TEXTURE - uniform vec4 gcu_ColorTexBBox; + uniform vec2 gcu_ColorTexBBox[3]; // box-min[2], box-max[2] and tex-size[2] #endif uniform mat4 gcu_PMVMatrix02[3]; // P, Mv, and Mvi diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl index 265ab6915..a64b8ad4d 100644 --- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl +++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/varyings.glsl @@ -8,11 +8,13 @@ varying vec2 gcv_FboTexCoord; #ifdef USE_COLOR_TEXTURE varying vec2 gcv_ColorTexCoord; + varying vec2 gcv_ColorTexExt; #endif #ifdef USE_COLOR_CHANNEL varying vec4 gcv_Color; #endif + #endif // varyings_glsl |