DRW: Make intersect lib not dependent on common_view_lib.glsl

This declares view intersection functions only if the view lib if
required.
This commit is contained in:
Clément Foucault 2023-01-18 14:36:19 +01:00
parent 9e5ada315f
commit 534214e65c
2 changed files with 49 additions and 1 deletions

View File

@ -4,7 +4,6 @@
* Results are meant to be conservative.
*/
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_geom_lib.glsl)
#pragma BLENDER_REQUIRE(common_shape_lib.glsl)
@ -127,6 +126,8 @@ IsectFrustum isect_data_setup(Frustum shape)
/** \name View Intersection functions.
* \{ */
#ifdef COMMON_VIEW_LIB_GLSL
bool intersect_view(Pyramid pyramid)
{
bool intersects = true;
@ -276,6 +277,8 @@ bool intersect_view(Sphere sphere)
return intersects;
}
#endif
/** \} */
/* ---------------------------------------------------------------------- */
@ -327,6 +330,50 @@ bool intersect(IsectPyramid i_pyramid, Box box)
return intersects;
}
bool intersect(IsectPyramid i_pyramid, IsectBox i_box)
{
bool intersects = true;
/* Do Box vertices vs Pyramid planes. */
for (int p = 0; p < 5; ++p) {
bool is_any_vertex_on_positive_side = false;
for (int v = 0; v < 8; ++v) {
float test = dot(i_pyramid.planes[p], vec4(i_box.corners[v], 1.0));
if (test > 0.0) {
is_any_vertex_on_positive_side = true;
break;
}
}
bool all_vertex_on_negative_side = !is_any_vertex_on_positive_side;
if (all_vertex_on_negative_side) {
intersects = false;
break;
}
}
if (!intersects) {
return intersects;
}
/* Now do Pyramid vertices vs Box planes. */
for (int p = 0; p < 6; ++p) {
bool is_any_vertex_on_positive_side = false;
for (int v = 0; v < 5; ++v) {
float test = dot(i_box.planes[p], vec4(i_pyramid.corners[v], 1.0));
if (test > 0.0) {
is_any_vertex_on_positive_side = true;
break;
}
}
bool all_vertex_on_negative_side = !is_any_vertex_on_positive_side;
if (all_vertex_on_negative_side) {
intersects = false;
break;
}
}
return intersects;
}
bool intersect(IsectFrustum i_frustum, Pyramid pyramid)
{
bool intersects = true;

View File

@ -4,6 +4,7 @@
*/
/* TODO(fclem): This could be augmented by a 2 pass occlusion culling system. */
#pragma BLENDER_REQUIRE(common_view_lib.glsl)
#pragma BLENDER_REQUIRE(common_math_lib.glsl)
#pragma BLENDER_REQUIRE(common_intersect_lib.glsl)