This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/draw/intern/shaders/common_aabb_lib.glsl
Clément Foucault 1226f5848d DRW: Add intersection and shape libraries for GLSL
These are meant to provide easy shape and AABB operation for culling.

They are currently incomplete but can be extended as one see fits.

The `common_debug_shape_lib.glsl` contains helper to draw thoses shapes.
2022-08-14 20:40:04 +02:00

60 lines
1.3 KiB
GLSL

#pragma BLENDER_REQUIRE(common_shape_lib.glsl)
/* ---------------------------------------------------------------------- */
/** \name Axis Aligned Bound Box
* \{ */
struct AABB {
vec3 min, max;
};
AABB aabb_init_min_max()
{
AABB aabb;
aabb.min = vec3(1.0e30);
aabb.max = vec3(-1.0e30);
return aabb;
}
void aabb_merge(inout AABB aabb, vec3 v)
{
aabb.min = min(aabb.min, v);
aabb.max = max(aabb.max, v);
}
/**
* Return true if there is any intersection.
*/
bool aabb_intersect(AABB a, AABB b)
{
return all(greaterThanEqual(min(a.max, b.max), max(a.min, b.min)));
}
/**
* Compute intersect intersection volume of \a a and \a b.
* Return true if the resulting volume is not empty.
*/
bool aabb_clip(AABB a, AABB b, out AABB c)
{
c.min = max(a.min, b.min);
c.max = min(a.max, b.max);
return all(greaterThanEqual(c.max, c.min));
}
Box aabb_to_box(AABB aabb)
{
Box box;
box.corners[0] = aabb.min;
box.corners[1] = vec3(aabb.max.x, aabb.min.y, aabb.min.z);
box.corners[2] = vec3(aabb.max.x, aabb.max.y, aabb.min.z);
box.corners[3] = vec3(aabb.min.x, aabb.max.y, aabb.min.z);
box.corners[4] = vec3(aabb.min.x, aabb.min.y, aabb.max.z);
box.corners[5] = vec3(aabb.max.x, aabb.min.y, aabb.max.z);
box.corners[6] = aabb.max;
box.corners[7] = vec3(aabb.min.x, aabb.max.y, aabb.max.z);
return box;
}
/** \} */