Welcome to mirror list, hosted at ThFree Co, Russian Federation.

common_aabb_lib.glsl « shaders « intern « draw « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b5f664a6779519942faaeb882bb828b3b5abdc9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

#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;
}

/** \} */