View Full Version : Suggestion for GLSL: "select"

06-17-2011, 06:42 AM
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.

select(genType a, getType b, bool S)


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.

Ilian Dinev
06-17-2011, 01:43 PM
Do the ?: way, it's supported in glsl compilers and should/must be producing the effect you want, and be optimized.

06-18-2011, 08:32 AM
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:

Expressions used for conditional jumps (if, for, ?:, while, do-while) must evaluate to the type 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.

06-22-2011, 03:33 AM
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

06-22-2011, 02:05 PM
*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 :p

06-22-2011, 04:41 PM
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...