27 : use_scene_camera_cull_(false),
28 use_camera_cull_(false),
29 camera_cull_margin_(0.0f),
30 use_scene_distance_cull_(false),
31 use_distance_cull_(false),
32 distance_cull_margin_(0.0f)
34 if (b_scene.render().use_simplify()) {
38 !b_scene.render().use_multiview() &&
41 !b_scene.render().use_multiview() &&
44 camera_cull_margin_ =
get_float(cscene,
"camera_cull_margin");
45 distance_cull_margin_ =
get_float(cscene,
"distance_cull_margin");
47 if (distance_cull_margin_ == 0.0f) {
48 use_scene_distance_cull_ =
false;
55 if (!use_scene_camera_cull_ && !use_scene_distance_cull_) {
61 use_camera_cull_ = use_scene_camera_cull_ &&
get_boolean(cobject,
"use_camera_cull");
62 use_distance_cull_ = use_scene_distance_cull_ &&
get_boolean(cobject,
"use_distance_cull");
64 if (use_camera_cull_ || use_distance_cull_) {
72 if (!use_camera_cull_ && !use_distance_cull_) {
78 BL::Array<float, 24> boundbox = b_ob.bound_box();
79 for (
int i = 0; i < 8; ++i) {
80 float3 p =
make_float3(boundbox[3 * i + 0], boundbox[3 * i + 1], boundbox[3 * i + 2]);
84 bool camera_culled = use_camera_cull_ && test_camera(
scene, bb);
85 bool distance_culled = use_distance_cull_ && test_distance(
scene, bb);
87 return ((camera_culled && distance_culled) || (camera_culled && !use_distance_cull_) ||
88 (distance_culled && !use_camera_cull_));
100 bool all_behind =
true;
101 for (
int i = 0; i < 8; ++i) {
105 dot(worldtondc.
x, b),
dot(worldtondc.
y, b),
dot(worldtondc.
z, b),
dot(worldtondc.
w, b));
111 if (
c.z >= -camera_cull_margin_) {
114 bb_min =
min(bb_min, p);
115 bb_max =
max(bb_max, p);
120 return (bb_min.
x >= 1.0f + camera_cull_margin_ || bb_min.
y >= 1.0f + camera_cull_margin_ ||
121 bb_max.x <= -camera_cull_margin_ || bb_max.y <= -camera_cull_margin_);
128 bb_max =
make_float3(-FLT_MAX, -FLT_MAX, -FLT_MAX);
131 for (
int i = 0; i < 8; ++i) {
133 bb_min =
min(bb_min, p);
134 bb_max =
max(bb_max, p);
139 distance_cull_margin_ * distance_cull_margin_);
static float get_float(PointerRNA &ptr, const char *name)
static bool get_boolean(PointerRNA &ptr, const char *name)
BlenderObjectCulling(Scene *scene, BL::Scene &b_scene)
void init_object(Scene *scene, BL::Object &b_ob)
bool test(Scene *scene, BL::Object &b_ob, Transform &tfm)
ccl_device_inline float3 camera_position(KernelGlobals *kg)
#define CCL_NAMESPACE_END
#define make_float4(x, y, z, w)
#define make_float3(x, y, z)
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
ProjectionTransform worldtondc
ccl_device_inline float3 float4_to_float3(const float4 a)
ccl_device_inline float dot(const float2 &a, const float2 &b)
ccl_device_inline float len_squared(const float3 a)