This changes the include directive to use the standard C preprocessor `#include` directive. The regex to applied to all glsl sources is: `pragma BLENDER_REQUIRE\((\w+\.glsl)\)` `include "$1"` This allow C++ linter to parse the code and allow easier codebase traversal. However there is a small catch. While it does work like a standard include directive when the code is treated as C++, it doesn't when compiled by our shader backends. In this case, we still use our dependency concatenation approach instead of file injection. This means that included files will always be prepended when compiled to GLSL and a file cannot be appended more than once. This is why all GLSL lib file should have the `#pragma once` directive and always be included at the start of the file. These requirements are actually already enforced by our code-style in practice. On the implementation, the source needed to be mutated to comment the `#pragma once` and `#include`. This is needed to avoid GLSL compiler error out as this is an extension that not all vendor supports. Rel #127983 Pull Request: https://projects.blender.org/blender/blender/pulls/128076
73 lines
1.5 KiB
GLSL
73 lines
1.5 KiB
GLSL
/* SPDX-FileCopyrightText: 2022-2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#pragma once
|
|
|
|
#include "common_shape_lib.glsl"
|
|
|
|
/* ---------------------------------------------------------------------- */
|
|
/** \name Axis Aligned Bound Box
|
|
* \{ */
|
|
|
|
struct AABB {
|
|
vec3 min, max;
|
|
};
|
|
|
|
AABB shape_aabb(vec3 min, vec3 max)
|
|
{
|
|
AABB aabb;
|
|
aabb.min = min;
|
|
aabb.max = max;
|
|
return aabb;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
/** \} */
|