how to do "bvec4 & bvec4" in GLSL?

Recommended Posts

RPTD    340

A simple problem: calculate two limits for 4 points at the same time. Using GLSL this would look like this:

vec4 testPoint, limitA, limitB = ...

bvec4 result = lessThan( testPoint, limitA ) & greaterThan( testPoint, limitB)

Problem is, this is not possible in GLSL it looks like. Compiler says there is no operator for "bvec4 & bvec4". I tried also with && but the same, no operator for "bvec4 && bvec4". I even tried something like multiplication (since using 0 and 1 as false and true it would work with 0*0=0, 0*1=0, 1*0=0 and 1*1=1) but again no operator for "bvec4 * bvec4".

How is one supposed to make a component wise AND operation on two bvec4 in GLSL? Or has GLSL overlooked this very important operation?

Edited by RPTD

Share on other sites
Ashaman73    13715

How about using the step function ?

This checks if your testpoint is inside the limit.

vec4 result = step(limitA,testPoint) * step(testPoint,limitB);

This will check, if all 4 axis are inside.

bool is_inside = dot(result,result)==4;

More robust:

bool is_inside = dot(result,result)>3.5;

Edited by Ashaman73