how to do "bvec4 & bvec4" in GLSL?

Started by
0 comments, last by Ashaman73 10 years, 9 months ago

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?

Life's like a Hydra... cut off one problem just to have two more popping out.
Leader and Coder: Project Epsylon | Drag[en]gine Game Engine

Advertisement

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;

This topic is closed to new replies.

Advertisement