LYGIA Shader Library

inside (lygia/math/inside)

does the position lie within the triangle


bool inside(<float|vec2|vec3> value, <float|vec2|vec3> min, <float|vec2|vec3> max)
bool inside(<vec2|vec3> value, <vec4|AABB> aabb)

Check it on Github

#ifndef FNC_INSIDE
#define FNC_INSIDE
bool inside(float _x, float _min, float _max) {
    return !(_x < _min || _x > _max);

bool inside(vec2 _v, vec2 _min, vec2 _max) {
    return !(_v.x < _min.x || _v.x > _max.x || 
             _v.y < _min.y || _v.y > _max.y);

bool inside(vec3 _v, vec3 _min, vec3 _max) {
    return !(_v.x < _min.x || _v.x > _max.x || 
             _v.y < _min.y || _v.y > _max.y ||
             _v.z < _min.z || _v.z > _max.z);

bool inside(vec2 _v, vec4 _aabb) {
    return inside(_v, _aabb.xy,;

#ifdef STR_AABB
bool inside(vec3 _v, AABB _aabb) {
    return inside(_v, _aabb.min, _aabb.max);



LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.

Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).

It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.

Get the latest news and releases

Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository