Relational Operators + Vectors: What's the deal?

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

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?

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

May be because this is not useful. :wink:

It is useful, I use in some of my shaders, usually like this

if(any( float3(1,2,3) < float3(3,2,1)))

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

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.

e.g. point inside axis aligned bounding box test?

float3 pos = ...;

if( any(float3(0) < pos || pos > float3(1)))

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.