From 356dacea9095daa491d5deaa17772e7890e1a285 Mon Sep 17 00:00:00 2001 From: Karsten Weiss <> Date: Tue, 13 Dec 2016 10:15:40 +0100 Subject: Libmv: Fix copy-paste mistake in camera intrinsic parameters --- intern/libmv/intern/camera_intrinsics.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'intern') diff --git a/intern/libmv/intern/camera_intrinsics.cc b/intern/libmv/intern/camera_intrinsics.cc index 24a34ae40bb..c9aea30b893 100644 --- a/intern/libmv/intern/camera_intrinsics.cc +++ b/intern/libmv/intern/camera_intrinsics.cc @@ -179,7 +179,7 @@ void libmv_cameraIntrinsicsExtractOptions( camera_intrinsics_options->polynomial_k2 = polynomial_intrinsics->k2(); camera_intrinsics_options->polynomial_k3 = polynomial_intrinsics->k3(); camera_intrinsics_options->polynomial_p1 = polynomial_intrinsics->p1(); - camera_intrinsics_options->polynomial_p1 = polynomial_intrinsics->p2(); + camera_intrinsics_options->polynomial_p2 = polynomial_intrinsics->p2(); break; } -- cgit v1.2.3 From 9446b6809af4a55ddd2f822fefe3c3fd8e82f40a Mon Sep 17 00:00:00 2001 From: Karsten Weiss <> Date: Tue, 13 Dec 2016 10:16:20 +0100 Subject: Libmv: Fix typo in assert message --- intern/libmv/intern/camera_intrinsics.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'intern') diff --git a/intern/libmv/intern/camera_intrinsics.cc b/intern/libmv/intern/camera_intrinsics.cc index c9aea30b893..3b4cd1545df 100644 --- a/intern/libmv/intern/camera_intrinsics.cc +++ b/intern/libmv/intern/camera_intrinsics.cc @@ -195,7 +195,7 @@ void libmv_cameraIntrinsicsExtractOptions( } default: - assert(!"Uknown distortion model"); + assert(!"Unknown distortion model"); } } -- cgit v1.2.3 From fbcd51aef86a69fb99ae5cba51da6401f6c3dca4 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 14 Dec 2016 10:44:57 +0100 Subject: Fix T50243: libmv_panography_test is broken There was fully wrong logic in comparison: was actually accessing memory past the array boundary. Run test manually and the figure seems correct to me now. Spotted by @LazyDodo, thanks! --- intern/libmv/libmv/multiview/panography_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'intern') diff --git a/intern/libmv/libmv/multiview/panography_test.cc b/intern/libmv/libmv/multiview/panography_test.cc index f6faf0f6022..96d52acfc3c 100644 --- a/intern/libmv/libmv/multiview/panography_test.cc +++ b/intern/libmv/libmv/multiview/panography_test.cc @@ -48,7 +48,7 @@ TEST(Panography, PrintSomeSharedFocalEstimationValues) { // Assert we found a valid solution. EXPECT_EQ(1, fs.size()); - EXPECT_NEAR(1.01667, fs[1], 1e-3); + EXPECT_NEAR(3.47194, fs[0], 1e-3); } TEST(Panography, GetR_FixedCameraCenterWithIdentity) { -- cgit v1.2.3 From 72d18c195eea7aa6be43afbda7dab584893c1882 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 7 Dec 2016 10:53:07 +0100 Subject: Cycles: Tweak curve segment (un)pack to handle more curve segments There was 16 bits reserved for primitive type, while we only need 4. Reviewers: brecht Reviewed By: brecht Differential Revision: https://developer.blender.org/D2401 --- intern/cycles/kernel/kernel_types.h | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'intern') diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h index fd961836ec9..2563f1491b1 100644 --- a/intern/cycles/kernel/kernel_types.h +++ b/intern/cycles/kernel/kernel_types.h @@ -550,27 +550,29 @@ typedef ccl_addr_space struct Intersection { /* Primitives */ typedef enum PrimitiveType { - PRIMITIVE_NONE = 0, - PRIMITIVE_TRIANGLE = 1, - PRIMITIVE_MOTION_TRIANGLE = 2, - PRIMITIVE_CURVE = 4, - PRIMITIVE_MOTION_CURVE = 8, - /* Lamp primitive is not included below on purpose, since it is no real traceable primitive */ - PRIMITIVE_LAMP = 16, + PRIMITIVE_NONE = 0, + PRIMITIVE_TRIANGLE = (1 << 0), + PRIMITIVE_MOTION_TRIANGLE = (1 << 1), + PRIMITIVE_CURVE = (1 << 2), + PRIMITIVE_MOTION_CURVE = (1 << 3), + /* Lamp primitive is not included below on purpose, + * since it is no real traceable primitive. + */ + PRIMITIVE_LAMP = (1 << 4), PRIMITIVE_ALL_TRIANGLE = (PRIMITIVE_TRIANGLE|PRIMITIVE_MOTION_TRIANGLE), PRIMITIVE_ALL_CURVE = (PRIMITIVE_CURVE|PRIMITIVE_MOTION_CURVE), PRIMITIVE_ALL_MOTION = (PRIMITIVE_MOTION_TRIANGLE|PRIMITIVE_MOTION_CURVE), PRIMITIVE_ALL = (PRIMITIVE_ALL_TRIANGLE|PRIMITIVE_ALL_CURVE), - /* Total number of different primitives. + /* Total number of different traceable primitives. * NOTE: This is an actual value, not a bitflag. */ PRIMITIVE_NUM_TOTAL = 4, } PrimitiveType; -#define PRIMITIVE_PACK_SEGMENT(type, segment) ((segment << 16) | type) -#define PRIMITIVE_UNPACK_SEGMENT(type) (type >> 16) +#define PRIMITIVE_PACK_SEGMENT(type, segment) ((segment << PRIMITIVE_NUM_TOTAL) | (type)) +#define PRIMITIVE_UNPACK_SEGMENT(type) (type >> PRIMITIVE_NUM_TOTAL) /* Attributes */ -- cgit v1.2.3 From c4d6fd3ec04a93376d08e7baa89846732c01ec04 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 6 Dec 2016 15:57:16 +0100 Subject: Cycles: Consider GGX/Beckmann/Ashikhmin of 0 roughness a singular ray This matches behavior of Multiscatter GGX and could become handy later on when/if we decide it would be beneficial to replace on closure with another. Reviewers: lukasstockner97, brecht Reviewed By: brecht Differential Revision: https://developer.blender.org/D2413 --- intern/cycles/kernel/closure/bsdf_ashikhmin_shirley.h | 4 +++- intern/cycles/kernel/closure/bsdf_microfacet.h | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'intern') diff --git a/intern/cycles/kernel/closure/bsdf_ashikhmin_shirley.h b/intern/cycles/kernel/closure/bsdf_ashikhmin_shirley.h index 1cd8246aa71..b6c896c754b 100644 --- a/intern/cycles/kernel/closure/bsdf_ashikhmin_shirley.h +++ b/intern/cycles/kernel/closure/bsdf_ashikhmin_shirley.h @@ -143,6 +143,7 @@ ccl_device int bsdf_ashikhmin_shirley_sample(const ShaderClosure *sc, float3 Ng, { const MicrofacetBsdf *bsdf = (const MicrofacetBsdf*)sc; float3 N = bsdf->N; + int label = LABEL_REFLECT | LABEL_GLOSSY; float NdotI = dot(N, I); if(NdotI > 0.0f) { @@ -211,6 +212,7 @@ ccl_device int bsdf_ashikhmin_shirley_sample(const ShaderClosure *sc, float3 Ng, /* Some high number for MIS. */ *pdf = 1e6f; *eval = make_float3(1e6f, 1e6f, 1e6f); + label = LABEL_REFLECT | LABEL_SINGULAR; } else { /* leave the rest to eval_reflect */ @@ -224,7 +226,7 @@ ccl_device int bsdf_ashikhmin_shirley_sample(const ShaderClosure *sc, float3 Ng, #endif } - return LABEL_REFLECT|LABEL_GLOSSY; + return label; } diff --git a/intern/cycles/kernel/closure/bsdf_microfacet.h b/intern/cycles/kernel/closure/bsdf_microfacet.h index 0a8d14a00c2..72fffe6ff69 100644 --- a/intern/cycles/kernel/closure/bsdf_microfacet.h +++ b/intern/cycles/kernel/closure/bsdf_microfacet.h @@ -452,6 +452,7 @@ ccl_device int bsdf_microfacet_ggx_sample(KernelGlobals *kg, const ShaderClosure float alpha_y = bsdf->alpha_y; bool m_refractive = bsdf->type == CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID; float3 N = bsdf->N; + int label; float cosNO = dot(N, I); if(cosNO > 0) { @@ -477,6 +478,7 @@ ccl_device int bsdf_microfacet_ggx_sample(KernelGlobals *kg, const ShaderClosure /* reflection or refraction? */ if(!m_refractive) { float cosMO = dot(m, I); + label = LABEL_REFLECT | LABEL_GLOSSY; if(cosMO > 0) { /* eq. 39 - compute actual reflected direction */ @@ -487,6 +489,7 @@ ccl_device int bsdf_microfacet_ggx_sample(KernelGlobals *kg, const ShaderClosure /* some high number for MIS */ *pdf = 1e6f; *eval = make_float3(1e6f, 1e6f, 1e6f); + label = LABEL_REFLECT | LABEL_SINGULAR; } else { /* microfacet normal is visible to this ray */ @@ -549,6 +552,8 @@ ccl_device int bsdf_microfacet_ggx_sample(KernelGlobals *kg, const ShaderClosure } } else { + label = LABEL_TRANSMIT | LABEL_GLOSSY; + /* CAUTION: the i and o variables are inverted relative to the paper * eq. 39 - compute actual refractive direction */ float3 R, T; @@ -576,6 +581,7 @@ ccl_device int bsdf_microfacet_ggx_sample(KernelGlobals *kg, const ShaderClosure /* some high number for MIS */ *pdf = 1e6f; *eval = make_float3(1e6f, 1e6f, 1e6f); + label = LABEL_TRANSMIT | LABEL_SINGULAR; } else { /* eq. 33 */ @@ -607,7 +613,7 @@ ccl_device int bsdf_microfacet_ggx_sample(KernelGlobals *kg, const ShaderClosure } } } - return (m_refractive) ? LABEL_TRANSMIT|LABEL_GLOSSY : LABEL_REFLECT|LABEL_GLOSSY; + return label; } /* Beckmann microfacet with Smith shadow-masking from: @@ -815,6 +821,7 @@ ccl_device int bsdf_microfacet_beckmann_sample(KernelGlobals *kg, const ShaderCl float alpha_y = bsdf->alpha_y; bool m_refractive = bsdf->type == CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID; float3 N = bsdf->N; + int label; float cosNO = dot(N, I); if(cosNO > 0) { @@ -839,6 +846,7 @@ ccl_device int bsdf_microfacet_beckmann_sample(KernelGlobals *kg, const ShaderCl /* reflection or refraction? */ if(!m_refractive) { + label = LABEL_REFLECT | LABEL_GLOSSY; float cosMO = dot(m, I); if(cosMO > 0) { @@ -850,6 +858,7 @@ ccl_device int bsdf_microfacet_beckmann_sample(KernelGlobals *kg, const ShaderCl /* some high number for MIS */ *pdf = 1e6f; *eval = make_float3(1e6f, 1e6f, 1e6f); + label = LABEL_REFLECT | LABEL_SINGULAR; } else { /* microfacet normal is visible to this ray @@ -904,6 +913,8 @@ ccl_device int bsdf_microfacet_beckmann_sample(KernelGlobals *kg, const ShaderCl } } else { + label = LABEL_TRANSMIT | LABEL_GLOSSY; + /* CAUTION: the i and o variables are inverted relative to the paper * eq. 39 - compute actual refractive direction */ float3 R, T; @@ -931,6 +942,7 @@ ccl_device int bsdf_microfacet_beckmann_sample(KernelGlobals *kg, const ShaderCl /* some high number for MIS */ *pdf = 1e6f; *eval = make_float3(1e6f, 1e6f, 1e6f); + label = LABEL_TRANSMIT | LABEL_SINGULAR; } else { /* eq. 33 */ @@ -963,7 +975,7 @@ ccl_device int bsdf_microfacet_beckmann_sample(KernelGlobals *kg, const ShaderCl } } } - return (m_refractive) ? LABEL_TRANSMIT|LABEL_GLOSSY : LABEL_REFLECT|LABEL_GLOSSY; + return label; } CCL_NAMESPACE_END -- cgit v1.2.3 From 696721648558aef94e8488dbef13eff758abdf08 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 14 Dec 2016 12:47:28 +0100 Subject: Cycles: Fix indendation --- intern/cycles/blender/blender_object.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'intern') diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp index 681a22e1f07..22cc4e6f030 100644 --- a/intern/cycles/blender/blender_object.cpp +++ b/intern/cycles/blender/blender_object.cpp @@ -148,8 +148,8 @@ public: BL::Array boundbox = b_ob.bound_box(); for(int i = 0; i < 8; ++i) { float3 p = make_float3(boundbox[3 * i + 0], - boundbox[3 * i + 1], - boundbox[3 * i + 2]); + boundbox[3 * i + 1], + boundbox[3 * i + 2]); bb[i] = transform_point(&tfm, p); } @@ -203,7 +203,7 @@ private: { float3 camera_position = transform_get_column(&scene->camera->matrix, 3); 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 */ for(int i = 0; i < 8; ++i) { -- cgit v1.2.3 From 91bbffd37942f3c71b065b3c1365c771e1939f45 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 14 Dec 2016 13:01:33 +0100 Subject: Cycles: Move object culling helper to own files This is a stand-alone logic, which becomes quite comprehensive now. --- intern/cycles/blender/CMakeLists.txt | 2 + intern/cycles/blender/blender_object.cpp | 138 +----------------------- intern/cycles/blender/blender_object_cull.cpp | 149 ++++++++++++++++++++++++++ intern/cycles/blender/blender_object_cull.h | 49 +++++++++ 4 files changed, 201 insertions(+), 137 deletions(-) create mode 100644 intern/cycles/blender/blender_object_cull.cpp create mode 100644 intern/cycles/blender/blender_object_cull.h (limited to 'intern') diff --git a/intern/cycles/blender/CMakeLists.txt b/intern/cycles/blender/CMakeLists.txt index a79deca53e1..b57502b3b14 100644 --- a/intern/cycles/blender/CMakeLists.txt +++ b/intern/cycles/blender/CMakeLists.txt @@ -25,6 +25,7 @@ set(SRC blender_camera.cpp blender_mesh.cpp blender_object.cpp + blender_object_cull.cpp blender_particles.cpp blender_curves.cpp blender_logging.cpp @@ -35,6 +36,7 @@ set(SRC blender_texture.cpp CCL_api.h + blender_object_cull.h blender_sync.h blender_session.h blender_texture.h diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp index 22cc4e6f030..637cf7abda8 100644 --- a/intern/cycles/blender/blender_object.cpp +++ b/intern/cycles/blender/blender_object.cpp @@ -25,6 +25,7 @@ #include "particles.h" #include "shader.h" +#include "blender_object_cull.h" #include "blender_sync.h" #include "blender_util.h" @@ -88,143 +89,6 @@ static uint object_ray_visibility(BL::Object& b_ob) return flag; } -/* Culling */ - -class BlenderObjectCulling -{ -public: - BlenderObjectCulling(Scene *scene, BL::Scene& b_scene) - : use_scene_camera_cull(false), - use_camera_cull(false), - camera_cull_margin(0.0f), - use_scene_distance_cull(false), - use_distance_cull(false), - distance_cull_margin(0.0f) - { - if(b_scene.render().use_simplify()) { - PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles"); - - use_scene_camera_cull = scene->camera->type != CAMERA_PANORAMA && - !b_scene.render().use_multiview() && - get_boolean(cscene, "use_camera_cull"); - use_scene_distance_cull = scene->camera->type != CAMERA_PANORAMA && - !b_scene.render().use_multiview() && - get_boolean(cscene, "use_distance_cull"); - - camera_cull_margin = get_float(cscene, "camera_cull_margin"); - distance_cull_margin = get_float(cscene, "distance_cull_margin"); - - if (distance_cull_margin == 0.0f) { - use_scene_distance_cull = false; - } - } - } - - void init_object(Scene *scene, BL::Object& b_ob) - { - if(!use_scene_camera_cull && !use_scene_distance_cull) { - return; - } - - PointerRNA cobject = RNA_pointer_get(&b_ob.ptr, "cycles"); - - 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"); - - if(use_camera_cull || use_distance_cull) { - /* Need to have proper projection matrix. */ - scene->camera->update(); - } - } - - bool test(Scene *scene, BL::Object& b_ob, Transform& tfm) - { - if(!use_camera_cull && !use_distance_cull) { - return false; - } - - /* Compute world space bounding box corners. */ - float3 bb[8]; - BL::Array boundbox = b_ob.bound_box(); - for(int i = 0; i < 8; ++i) { - float3 p = make_float3(boundbox[3 * i + 0], - boundbox[3 * i + 1], - boundbox[3 * i + 2]); - bb[i] = transform_point(&tfm, p); - } - - bool camera_culled = use_camera_cull && test_camera(scene, bb); - bool distance_culled = use_distance_cull && test_distance(scene, bb); - - return ((camera_culled && distance_culled) || - (camera_culled && !use_distance_cull) || - (distance_culled && !use_camera_cull)); - } - -private: - /* TODO(sergey): Not really optimal, consider approaches based on k-DOP in order - * to reduce number of objects which are wrongly considered visible. - */ - bool test_camera(Scene *scene, float3 bb[8]) - { - Camera *cam = scene->camera; - Transform& worldtondc = cam->worldtondc; - float3 bb_min = make_float3(FLT_MAX, FLT_MAX, FLT_MAX), - bb_max = make_float3(-FLT_MAX, -FLT_MAX, -FLT_MAX); - bool all_behind = true; - for(int i = 0; i < 8; ++i) { - float3 p = bb[i]; - float4 b = make_float4(p.x, p.y, p.z, 1.0f); - float4 c = make_float4(dot(worldtondc.x, b), - dot(worldtondc.y, b), - dot(worldtondc.z, b), - dot(worldtondc.w, b)); - p = float4_to_float3(c / c.w); - if(c.z < 0.0f) { - p.x = 1.0f - p.x; - p.y = 1.0f - p.y; - } - if(c.z >= -camera_cull_margin) { - all_behind = false; - } - bb_min = min(bb_min, p); - bb_max = max(bb_max, p); - } - if(all_behind) { - return true; - } - 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); - } - - bool test_distance(Scene *scene, float3 bb[8]) - { - float3 camera_position = transform_get_column(&scene->camera->matrix, 3); - float3 bb_min = 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 */ - for(int i = 0; i < 8; ++i) { - float3 p = bb[i]; - bb_min = min(bb_min, p); - bb_max = max(bb_max, p); - } - - float3 closest_point = max(min(bb_max,camera_position),bb_min); - return (len_squared(camera_position - closest_point) > - distance_cull_margin * distance_cull_margin); - } - - bool use_scene_camera_cull; - bool use_camera_cull; - float camera_cull_margin; - bool use_scene_distance_cull; - bool use_distance_cull; - float distance_cull_margin; -}; - /* Light */ void BlenderSync::sync_light(BL::Object& b_parent, diff --git a/intern/cycles/blender/blender_object_cull.cpp b/intern/cycles/blender/blender_object_cull.cpp new file mode 100644 index 00000000000..b8582df0f93 --- /dev/null +++ b/intern/cycles/blender/blender_object_cull.cpp @@ -0,0 +1,149 @@ +/* + * Copyright 2011-2016 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "camera.h" + +#include "blender_object_cull.h" + +CCL_NAMESPACE_BEGIN + +BlenderObjectCulling::BlenderObjectCulling(Scene *scene, BL::Scene& b_scene) + : use_scene_camera_cull_(false), + use_camera_cull_(false), + camera_cull_margin_(0.0f), + use_scene_distance_cull_(false), + use_distance_cull_(false), + distance_cull_margin_(0.0f) +{ + if(b_scene.render().use_simplify()) { + PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles"); + + use_scene_camera_cull_ = scene->camera->type != CAMERA_PANORAMA && + !b_scene.render().use_multiview() && + get_boolean(cscene, "use_camera_cull"); + use_scene_distance_cull_ = scene->camera->type != CAMERA_PANORAMA && + !b_scene.render().use_multiview() && + get_boolean(cscene, "use_distance_cull"); + + camera_cull_margin_ = get_float(cscene, "camera_cull_margin"); + distance_cull_margin_ = get_float(cscene, "distance_cull_margin"); + + if (distance_cull_margin_ == 0.0f) { + use_scene_distance_cull_ = false; + } + } +} + +void BlenderObjectCulling::init_object(Scene *scene, BL::Object& b_ob) +{ + if(!use_scene_camera_cull_ && !use_scene_distance_cull_) { + return; + } + + PointerRNA cobject = RNA_pointer_get(&b_ob.ptr, "cycles"); + + 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"); + + if(use_camera_cull_ || use_distance_cull_) { + /* Need to have proper projection matrix. */ + scene->camera->update(); + } +} + +bool BlenderObjectCulling::test(Scene *scene, BL::Object& b_ob, Transform& tfm) +{ + if(!use_camera_cull_ && !use_distance_cull_) { + return false; + } + + /* Compute world space bounding box corners. */ + float3 bb[8]; + BL::Array boundbox = b_ob.bound_box(); + for(int i = 0; i < 8; ++i) { + float3 p = make_float3(boundbox[3 * i + 0], + boundbox[3 * i + 1], + boundbox[3 * i + 2]); + bb[i] = transform_point(&tfm, p); + } + + bool camera_culled = use_camera_cull_ && test_camera(scene, bb); + bool distance_culled = use_distance_cull_ && test_distance(scene, bb); + + return ((camera_culled && distance_culled) || + (camera_culled && !use_distance_cull_) || + (distance_culled && !use_camera_cull_)); +} + +/* TODO(sergey): Not really optimal, consider approaches based on k-DOP in order + * to reduce number of objects which are wrongly considered visible. + */ +bool BlenderObjectCulling::test_camera(Scene *scene, float3 bb[8]) +{ + Camera *cam = scene->camera; + Transform& worldtondc = cam->worldtondc; + float3 bb_min = make_float3(FLT_MAX, FLT_MAX, FLT_MAX), + bb_max = make_float3(-FLT_MAX, -FLT_MAX, -FLT_MAX); + bool all_behind = true; + for(int i = 0; i < 8; ++i) { + float3 p = bb[i]; + float4 b = make_float4(p.x, p.y, p.z, 1.0f); + float4 c = make_float4(dot(worldtondc.x, b), + dot(worldtondc.y, b), + dot(worldtondc.z, b), + dot(worldtondc.w, b)); + p = float4_to_float3(c / c.w); + if(c.z < 0.0f) { + p.x = 1.0f - p.x; + p.y = 1.0f - p.y; + } + if(c.z >= -camera_cull_margin_) { + all_behind = false; + } + bb_min = min(bb_min, p); + bb_max = max(bb_max, p); + } + if(all_behind) { + return true; + } + 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_); +} + +bool BlenderObjectCulling::test_distance(Scene *scene, float3 bb[8]) +{ + float3 camera_position = transform_get_column(&scene->camera->matrix, 3); + float3 bb_min = 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 */ + for(int i = 0; i < 8; ++i) { + float3 p = bb[i]; + bb_min = min(bb_min, p); + bb_max = max(bb_max, p); + } + + float3 closest_point = max(min(bb_max,camera_position),bb_min); + return (len_squared(camera_position - closest_point) > + distance_cull_margin_ * distance_cull_margin_); +} + +CCL_NAMESPACE_END + diff --git a/intern/cycles/blender/blender_object_cull.h b/intern/cycles/blender/blender_object_cull.h new file mode 100644 index 00000000000..b6f0ca5cd31 --- /dev/null +++ b/intern/cycles/blender/blender_object_cull.h @@ -0,0 +1,49 @@ +/* + * Copyright 2011-2016 Blender Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __BLENDER_OBJECT_CULL_H__ +#define __BLENDER_OBJECT_CULL_H__ + +#include "blender_sync.h" +#include "util_types.h" + +CCL_NAMESPACE_BEGIN + +class Scene; + +class BlenderObjectCulling +{ +public: + 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); + +private: + bool test_camera(Scene *scene, float3 bb[8]); + bool test_distance(Scene *scene, float3 bb[8]); + + bool use_scene_camera_cull_; + bool use_camera_cull_; + float camera_cull_margin_; + bool use_scene_distance_cull_; + bool use_distance_cull_; + float distance_cull_margin_; +}; + +CCL_NAMESPACE_END + +#endif /* __BLENDER_OBJECT_CULL_H__ */ -- cgit v1.2.3 From 525673b37b1718bf9973eecf1ec467d538a99607 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 14 Dec 2016 17:30:50 +0100 Subject: Cycles: Fix uninitialized variable issue after recent changes --- intern/cycles/kernel/closure/bsdf_microfacet.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'intern') diff --git a/intern/cycles/kernel/closure/bsdf_microfacet.h b/intern/cycles/kernel/closure/bsdf_microfacet.h index 72fffe6ff69..4a1316fd2a9 100644 --- a/intern/cycles/kernel/closure/bsdf_microfacet.h +++ b/intern/cycles/kernel/closure/bsdf_microfacet.h @@ -613,6 +613,9 @@ ccl_device int bsdf_microfacet_ggx_sample(KernelGlobals *kg, const ShaderClosure } } } + else { + label = (m_refractive) ? LABEL_TRANSMIT|LABEL_GLOSSY : LABEL_REFLECT|LABEL_GLOSSY; + } return label; } @@ -975,6 +978,9 @@ ccl_device int bsdf_microfacet_beckmann_sample(KernelGlobals *kg, const ShaderCl } } } + else { + label = (m_refractive) ? LABEL_TRANSMIT|LABEL_GLOSSY : LABEL_REFLECT|LABEL_GLOSSY; + } return label; } -- cgit v1.2.3 From 820709c14d3917db86c6c392df75a32d52c53ca2 Mon Sep 17 00:00:00 2001 From: Karsten Weiss <> Date: Thu, 15 Dec 2016 12:56:48 +1100 Subject: Fix STR_String Capitalize on non Win32 Harmless since its not used, but good to fix. --- intern/string/intern/STR_String.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'intern') diff --git a/intern/string/intern/STR_String.cpp b/intern/string/intern/STR_String.cpp index 4ea451311e4..4612c91b6a6 100644 --- a/intern/string/intern/STR_String.cpp +++ b/intern/string/intern/STR_String.cpp @@ -545,9 +545,9 @@ STR_String& STR_String::Capitalize() if (this->m_len > 1) _strlwr(this->m_data + 1); #else if (this->m_len > 0) - this->m_data[0] = (this->m_data[0] >= 'A' && this->m_data[0] <= 'A') ? this->m_data[0] + 'a' - 'A' : this->m_data[0]; + this->m_data[0] = (this->m_data[0] >= 'a' && this->m_data[0] <= 'z') ? this->m_data[0] + 'A' - 'a' : this->m_data[0]; for (int i = 1; i < this->m_len; i++) - this->m_data[i] = (this->m_data[i] >= 'a' && this->m_data[i] <= 'z') ? this->m_data[i] + 'A' - 'a' : this->m_data[i]; + this->m_data[i] = (this->m_data[i] >= 'A' && this->m_data[i] <= 'Z') ? this->m_data[i] + 'a' - 'A' : this->m_data[i]; #endif return *this; } -- cgit v1.2.3