Suggestion for GLSL: "select"

The following suggestion is for GLSL and boolean’s. The main issue it aims to address is to use a common flag-set to select.



genType
select(genType a, getType b, bool S)

and

genType
select(genType a, getType b, bvecN S)

where N="dimension of vector type of a and b".

outputs, component-wise

a if S is false
b is S is true

i.e. kind of like a component size ?: operator.

One can emulate this behavior in many use cases using step() and mix(), but that just smells bad as often many chips out there have conditional assignment.

Do the ?: way, it’s supported in glsl compilers and should/must be producing the effect you want, and be optimized.

Do the ?: way, it’s supported in glsl compilers and should/must be producing the effect you want, and be optimized.

The exp of a=(exp)?b:c; must be bool:

I want a component wise kind of jazz, for example


bvecN exp;
vecN a, b, c;

exp=isLess(a, b);
c=select(a, b, exp);

would give same output as c=min(a,b), one can naturally emulate this via walking the components separately, but that makes picking up that it is the same operation applied to each data heck a harder to see.

What select would provide compare to mix in its boolean flavour?


genType mix (genType x,
                       genType y,
                        genBType a)
genDType mix (genDType x,
                          genDType y,
                          genBType a)
Selects which vector each returned component comes
from. For a component of a that is false, the
corresponding component of x is returned.  For a
component of a that is true, the corresponding
component of y is returned.  Components of x and y that
are not selected are allowed to be invalid floating point
values and will have no effect on the results.  Thus, this
provides different functionality than, for example,
    genType mix(genType x, genType y, genType(a))
where a is a Boolean vector

oh now I am truly embarrassed and that has been there since GLSL 1.3 (i.e. OpenGL 3.0).

The mix in it’s boolean flavors is exactly the select I am asking for. Truly embarrassing. Everyone move along, nothing to see here except someone that has been doing too much GLES2 work at work.

Please everyone ignore this in my shame :stuck_out_tongue:

I discovered 2 days ago that block matching by name actually match on block-name and not block-instance. Speaking about obvious stuff!

Way a minute… This doesn’t even work on some implementations…