aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl
diff options
context:
space:
mode:
authorSven Göthel <[email protected]>2024-01-09 02:55:58 +0100
committerSven Göthel <[email protected]>2024-01-09 02:55:58 +0100
commitc87e89959e40ee8411cccc16fe0a5708f54a6c9f (patch)
treec79f5bfa5fb32fae061393f9a7b6ef3e53066dce /src/jogl
parent4db23616aca2f191b2685311dc676fdac739338a (diff)
Graph GLSL functions.glsl: Complete overload vec2 and vec3 variants; Fix 'and'/'or' semantic (swapped); Add EPSILON in clip_coord(..) and add is_inside(..) function
Complete overload vec2 and vec3 variants Fix 'and'/'or' semantic (swapped) - 'and' uses multiplication, i.e. all arguments must be > 0 (ideally 1) - 'or' uses addition, i.e. only one arguments must be > 0 (ideally 1) - both uses clamp [0..1] Add EPSILON in clip_coord(..) - Only 'coord > high+EPSILON' is outside Add is_inside(..) function - Similar to clip_coord(..) but returns float 0 or 1 instead of selecting color.
Diffstat (limited to 'src/jogl')
-rw-r--r--src/jogl/classes/jogamp/graph/curve/opengl/shader/functions.glsl60
1 files changed, 52 insertions, 8 deletions
diff --git a/src/jogl/classes/jogamp/graph/curve/opengl/shader/functions.glsl b/src/jogl/classes/jogamp/graph/curve/opengl/shader/functions.glsl
index eeab54ebf..41e65178e 100644
--- a/src/jogl/classes/jogamp/graph/curve/opengl/shader/functions.glsl
+++ b/src/jogl/classes/jogamp/graph/curve/opengl/shader/functions.glsl
@@ -1,4 +1,4 @@
-// Copyright 2023 JogAmp Community. All rights reserved.
+// Copyright 2023-2024 JogAmp Community. All rights reserved.
#ifndef functions_glsl
#define functions_glsl
@@ -7,35 +7,79 @@
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 ) {
+/** Returns product of components. */
+float v_mul( vec3 v ) {
+ return v.x * v.y * v.z;
+}
+/** Returns component wise logical 'and' as float '0' or '1' using the components product and clamp. */
+float v_and( vec2 v ) {
return clamp(v.x * v.y, 0, 1);
}
+/** Returns component wise logical 'and' as float '0' or '1' using the components product and clamp. */
+float v_and( vec3 v ) {
+ return clamp(v.x * v.y * v.z, 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 ) {
+/** Returns sum of components. */
+float v_sum( vec3 v ) {
+ return v.x + v.y + v.z;
+}
+/** Returns component wise logical 'or' as float '0' or '1' using the components sum and clamp. */
+float v_or( vec2 v ) {
return clamp(v.x + v.y, 0, 1);
}
+/** Returns component wise logical 'or' as float '0' or '1' using the components sum and clamp. */
+float v_or( vec3 v ) {
+ return clamp(v.x + v.y + v.z, 0, 1);
+}
+
+/** 32-bit float Epsilon value */
+const float EPSILON = 1.1920929E-7f;
/**
- * Branch-less clipping function.
+ * Branch-less clipping color selection.
* <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,
+ * as well as our own 'v_mul' and v_or' 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) ));
+ return mix( c, col_ex, v_or( step(high+EPSILON, coord) ));
+}
+/** Branch-less clipping color selection using vec3 coordinates and low/high clipping. */
+vec4 clip_coord(vec4 col_in, vec4 col_ex, vec3 coord, vec3 low, vec3 high) {
+ vec4 c = mix( col_ex, col_in, v_mul( step(low, coord) ));
+ return mix( c, col_ex, v_or( step(high+EPSILON, coord) ));
+}
+
+/**
+ * Branch-less clipping test.
+ * <p>
+ * Returns either '1' if the 'coord' is within ['low'..'high'] range,
+ * otherwise '0'.
+ * </p>
+ * <p>
+ * This is achieved via the build-in 'step' and 'mix' function
+ * as well as our own 'v_mul' and v_or' function,
+ * which flattens a 'vec2' to one float suitable to be used as the 'mix' criteria.
+ * </p>
+ */
+float is_inside(vec2 coord, vec2 low, vec2 high) {
+ return v_mul( step(low, coord) ) * ( 1 - v_or( step(high+EPSILON, coord) ) );
+}
+/** Branch-less clipping test using vec3 coordinates and low/high clipping. */
+float is_inside(vec3 coord, vec3 low, vec3 high) {
+ return v_mul( step(low, coord) ) * ( 1 - v_or( step(high+EPSILON, coord) ) );
}
#endif // functions_glsl