Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Suggestion for GLSL: "select"

Hybrid View

  1. #1
    Advanced Member Frequent Contributor
    Join Date
    Apr 2009
    Posts
    529

    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.

    Code :
     
    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.

  2. #2
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,261

    Re: Suggestion for GLSL: "select"

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

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Apr 2009
    Posts
    529

    Re: Suggestion for GLSL: "select"

    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:

    Quote Originally Posted by GLSL 4.1 Spec, Section 4.1.2
    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

    Code :
    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.


  4. #4
    Super Moderator Frequent Contributor Groovounet's Avatar
    Join Date
    Jul 2004
    Posts
    936

    Re: Suggestion for GLSL: "select"

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

    Code :
    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

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Apr 2009
    Posts
    529

    Re: Suggestion for GLSL: "select"

    *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

  6. #6
    Super Moderator Frequent Contributor Groovounet's Avatar
    Join Date
    Jul 2004
    Posts
    936

    Re: Suggestion for GLSL: "select"

    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •