diff options
Diffstat (limited to 'src/jogl/classes/jogamp/graph/curve/opengl/shader')
6 files changed, 63 insertions, 11 deletions
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 |