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 8 of 8

Thread: Relational Operators + Vectors: What's the deal?

  1. #1
    Senior Member OpenGL Pro
    Join Date
    Sep 2004
    Location
    Prombaatu
    Posts
    1,386

    Relational Operators + Vectors: What's the deal?

    Why are the relational operators not allowed to operate on vectors?

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Dec 2001
    Location
    Wellington, New Zealand
    Posts
    544

    Re: Relational Operators + Vectors: What's the deal?

    I assume because they thought < should return a single bool, and couldn't see what that meant for a vector? What's wrong with the lessThan function?

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Sep 2004
    Location
    Prombaatu
    Posts
    1,386

    Re: Relational Operators + Vectors: What's the deal?

    Well, there's nothing wrong with the lessThan function. Just seems to me it'd be more convenient and consistent to be able to use operators instead. We have all the arithmetic binary operators, which operate component by component, and they all return a vector of the same length.

    No big deal... thought maybe there might be a reason for this that might not be obvious (to me anyway).

  4. #4
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Relational Operators + Vectors: What's the deal?

    May be because this is not useful.

  5. #5
    Member Regular Contributor
    Join Date
    Mar 2001
    Posts
    469

    Re: Relational Operators + Vectors: What's the deal?

    Quote Originally Posted by CG reference manual
    Comparison operators may be applied to numeric vectors. Both operands must be vectors of the same size. The comparison operation is performed in elementwise fashion to produce a bool vector of the same size.
    It is useful, I use in some of my shaders, usually like this

    Code :
    if(any( float3(1,2,3) < float3(3,2,1)))
    {
       ...
    }

  6. #6
    Senior Member OpenGL Pro Zengar's Avatar
    Join Date
    Sep 2001
    Location
    Germany
    Posts
    1,932

    Re: Relational Operators + Vectors: What's the deal?

    Ok, what should such operator compare? Length? Or something like all(lessThen(x, y))? Or should it return a vector of bools?

  7. #7
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Relational Operators + Vectors: What's the deal?

    I think he want to compare each vectors component.

    If 2 vectors x and x' whose dimension is n:

    x = (e1, e2,..., en)
    x' = (e1', e2',..., en')

    x < x' = (e1 < e1'?, e2 < e2'?, ..., en < en'?) which is vector whose dimension is n

    But I am really curious to see a practical example of such operators in a shader.

  8. #8
    Member Regular Contributor
    Join Date
    Mar 2001
    Posts
    469

    Re: Relational Operators + Vectors: What's the deal?

    e.g. point inside axis aligned bounding box test?
    Code :
    float3 pos = ...;
     
    if( any(float3(0) < pos || pos > float3(1)))
    {   
       discard;
    }

Posting Permissions

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