Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/blender/blender_object_cull.cpp
| Show All 28 Lines | : use_scene_camera_cull_(false), | ||||
| camera_cull_margin_(0.0f), | camera_cull_margin_(0.0f), | ||||
| use_scene_distance_cull_(false), | use_scene_distance_cull_(false), | ||||
| use_distance_cull_(false), | use_distance_cull_(false), | ||||
| distance_cull_margin_(0.0f) | distance_cull_margin_(0.0f) | ||||
| { | { | ||||
| if (b_scene.render().use_simplify()) { | if (b_scene.render().use_simplify()) { | ||||
| PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles"); | PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles"); | ||||
| use_scene_camera_cull_ = scene->camera->get_camera_type() != CAMERA_PANORAMA && | use_scene_camera_cull_ = scene->get_camera()->get_camera_type() != CAMERA_PANORAMA && | ||||
| !b_scene.render().use_multiview() && | !b_scene.render().use_multiview() && | ||||
| get_boolean(cscene, "use_camera_cull"); | get_boolean(cscene, "use_camera_cull"); | ||||
| use_scene_distance_cull_ = scene->camera->get_camera_type() != CAMERA_PANORAMA && | use_scene_distance_cull_ = scene->get_camera()->get_camera_type() != CAMERA_PANORAMA && | ||||
| !b_scene.render().use_multiview() && | !b_scene.render().use_multiview() && | ||||
| get_boolean(cscene, "use_distance_cull"); | get_boolean(cscene, "use_distance_cull"); | ||||
| camera_cull_margin_ = get_float(cscene, "camera_cull_margin"); | camera_cull_margin_ = get_float(cscene, "camera_cull_margin"); | ||||
| distance_cull_margin_ = get_float(cscene, "distance_cull_margin"); | distance_cull_margin_ = get_float(cscene, "distance_cull_margin"); | ||||
| if (distance_cull_margin_ == 0.0f) { | if (distance_cull_margin_ == 0.0f) { | ||||
| use_scene_distance_cull_ = false; | use_scene_distance_cull_ = false; | ||||
| Show All 9 Lines | void BlenderObjectCulling::init_object(Scene *scene, BL::Object &b_ob) | ||||
| PointerRNA cobject = RNA_pointer_get(&b_ob.ptr, "cycles"); | PointerRNA cobject = RNA_pointer_get(&b_ob.ptr, "cycles"); | ||||
| use_camera_cull_ = use_scene_camera_cull_ && get_boolean(cobject, "use_camera_cull"); | use_camera_cull_ = use_scene_camera_cull_ && get_boolean(cobject, "use_camera_cull"); | ||||
| use_distance_cull_ = use_scene_distance_cull_ && get_boolean(cobject, "use_distance_cull"); | use_distance_cull_ = use_scene_distance_cull_ && get_boolean(cobject, "use_distance_cull"); | ||||
| if (use_camera_cull_ || use_distance_cull_) { | if (use_camera_cull_ || use_distance_cull_) { | ||||
| /* Need to have proper projection matrix. */ | /* Need to have proper projection matrix. */ | ||||
| scene->camera->update(scene); | scene->get_camera()->update(scene); | ||||
| } | } | ||||
| } | } | ||||
| bool BlenderObjectCulling::test(Scene *scene, BL::Object &b_ob, Transform &tfm) | bool BlenderObjectCulling::test(Scene *scene, BL::Object &b_ob, Transform &tfm) | ||||
| { | { | ||||
| if (!use_camera_cull_ && !use_distance_cull_) { | if (!use_camera_cull_ && !use_distance_cull_) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| Show All 13 Lines | return ((camera_culled && distance_culled) || (camera_culled && !use_distance_cull_) || | ||||
| (distance_culled && !use_camera_cull_)); | (distance_culled && !use_camera_cull_)); | ||||
| } | } | ||||
| /* TODO(sergey): Not really optimal, consider approaches based on k-DOP in order | /* TODO(sergey): Not really optimal, consider approaches based on k-DOP in order | ||||
| * to reduce number of objects which are wrongly considered visible. | * to reduce number of objects which are wrongly considered visible. | ||||
| */ | */ | ||||
| bool BlenderObjectCulling::test_camera(Scene *scene, float3 bb[8]) | bool BlenderObjectCulling::test_camera(Scene *scene, float3 bb[8]) | ||||
| { | { | ||||
| Camera *cam = scene->camera; | Camera *cam = scene->get_camera(); | ||||
| const ProjectionTransform &worldtondc = cam->worldtondc; | const ProjectionTransform &worldtondc = cam->get_worldtondc(); | ||||
| float3 bb_min = make_float3(FLT_MAX, FLT_MAX, FLT_MAX), | float3 bb_min = make_float3(FLT_MAX, FLT_MAX, FLT_MAX), | ||||
| bb_max = make_float3(-FLT_MAX, -FLT_MAX, -FLT_MAX); | bb_max = make_float3(-FLT_MAX, -FLT_MAX, -FLT_MAX); | ||||
| bool all_behind = true; | bool all_behind = true; | ||||
| for (int i = 0; i < 8; ++i) { | for (int i = 0; i < 8; ++i) { | ||||
| float3 p = bb[i]; | float3 p = bb[i]; | ||||
| float4 b = make_float4(p.x, p.y, p.z, 1.0f); | float4 b = make_float4(p.x, p.y, p.z, 1.0f); | ||||
| float4 c = make_float4( | float4 c = make_float4( | ||||
| dot(worldtondc.x, b), dot(worldtondc.y, b), dot(worldtondc.z, b), dot(worldtondc.w, b)); | dot(worldtondc.x, b), dot(worldtondc.y, b), dot(worldtondc.z, b), dot(worldtondc.w, b)); | ||||
| Show All 12 Lines | if (all_behind) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| return (bb_min.x >= 1.0f + camera_cull_margin_ || bb_min.y >= 1.0f + camera_cull_margin_ || | return (bb_min.x >= 1.0f + camera_cull_margin_ || bb_min.y >= 1.0f + camera_cull_margin_ || | ||||
| bb_max.x <= -camera_cull_margin_ || bb_max.y <= -camera_cull_margin_); | bb_max.x <= -camera_cull_margin_ || bb_max.y <= -camera_cull_margin_); | ||||
| } | } | ||||
| bool BlenderObjectCulling::test_distance(Scene *scene, float3 bb[8]) | bool BlenderObjectCulling::test_distance(Scene *scene, float3 bb[8]) | ||||
| { | { | ||||
| float3 camera_position = transform_get_column(&scene->camera->get_matrix(), 3); | float3 camera_position = transform_get_column(&scene->get_camera()->get_matrix(), 3); | ||||
| float3 bb_min = make_float3(FLT_MAX, FLT_MAX, FLT_MAX), | float3 bb_min = make_float3(FLT_MAX, FLT_MAX, FLT_MAX), | ||||
| bb_max = make_float3(-FLT_MAX, -FLT_MAX, -FLT_MAX); | bb_max = make_float3(-FLT_MAX, -FLT_MAX, -FLT_MAX); | ||||
| /* Find min & max points for x & y & z on bounding box */ | /* Find min & max points for x & y & z on bounding box */ | ||||
| for (int i = 0; i < 8; ++i) { | for (int i = 0; i < 8; ++i) { | ||||
| float3 p = bb[i]; | float3 p = bb[i]; | ||||
| bb_min = min(bb_min, p); | bb_min = min(bb_min, p); | ||||
| bb_max = max(bb_max, p); | bb_max = max(bb_max, p); | ||||
| } | } | ||||
| float3 closest_point = max(min(bb_max, camera_position), bb_min); | float3 closest_point = max(min(bb_max, camera_position), bb_min); | ||||
| return (len_squared(camera_position - closest_point) > | return (len_squared(camera_position - closest_point) > | ||||
| distance_cull_margin_ * distance_cull_margin_); | distance_cull_margin_ * distance_cull_margin_); | ||||
| } | } | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||