# how to do "bvec4 & bvec4" in GLSL?

This topic is 1642 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

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

##### Share on other sites

This topic is 1642 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.