From d3d1313ca4fff7566d84ba4f3495977791d8c895 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 28 Jul 2016 12:27:24 +0200 Subject: [PATCH] Cycles: De-duplicate more checks around light emisive meshes Once again, should be no functional changes. --- intern/cycles/render/light.cpp | 58 +++++++++++++++------------------- intern/cycles/render/light.h | 4 +++ 2 files changed, 29 insertions(+), 33 deletions(-) diff --git a/intern/cycles/render/light.cpp b/intern/cycles/render/light.cpp index 41af209226d..d97c1aefc89 100644 --- a/intern/cycles/render/light.cpp +++ b/intern/cycles/render/light.cpp @@ -209,6 +209,23 @@ void LightManager::disable_ineffective_light(Device *device, Scene *scene) } } +bool LightManager::object_usable_as_light(Object *object) { + Mesh *mesh = object->mesh; + /* Skip if we are not visible for BSDFs. */ + if(!(object->visibility & (PATH_RAY_DIFFUSE|PATH_RAY_GLOSSY|PATH_RAY_TRANSMIT))) { + return false; + } + /* Skip motion blurred deforming meshes, not supported yet. */ + if(mesh->has_motion_blur()) { + return false; + } + /* Skip if we have no emission shaders. */ + if(!mesh->has_mis_emission) { + return false; + } + return true; +} + void LightManager::device_update_distribution(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress) { progress.set_status("Updating Lights", "Computing distribution"); @@ -226,23 +243,13 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen } foreach(Object *object, scene->objects) { - Mesh *mesh = object->mesh; + if(progress.get_cancel()) return; - /* Skip if we are not visible for BSDFs. */ - if(!(object->visibility & (PATH_RAY_DIFFUSE|PATH_RAY_GLOSSY|PATH_RAY_TRANSMIT))) - continue; - - /* Skip motion blurred deforming meshes, not supported yet. */ - if(mesh->has_motion_blur()) { + if(!object_usable_as_light(object)) { continue; } - - /* Skip if we have no emission shaders. */ - if(!mesh->has_mis_emission) { - continue; - } - /* Count triangles. */ + Mesh *mesh = object->mesh; size_t mesh_num_triangles = mesh->num_triangles(); for(size_t i = 0; i < mesh_num_triangles; i++) { int shader_index = mesh->shader[i]; @@ -270,27 +277,12 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen foreach(Object *object, scene->objects) { if(progress.get_cancel()) return; + if(!object_usable_as_light(object)) { + j++; + continue; + } + /* Sum area. */ Mesh *mesh = object->mesh; - - /* Skip if we are not visible for BSDFs. */ - if(!(object->visibility & (PATH_RAY_DIFFUSE|PATH_RAY_GLOSSY|PATH_RAY_TRANSMIT))) { - j++; - continue; - } - - /* Skip motion blurred deforming meshes, not supported yet. */ - if(mesh->has_motion_blur()) { - j++; - continue; - } - - /* Skip if we have no emission shaders. */ - if(!mesh->has_mis_emission) { - j++; - continue; - } - - /* sum area */ bool transform_applied = mesh->transform_applied; Transform tfm = object->tfm; int object_id = j; diff --git a/intern/cycles/render/light.h b/intern/cycles/render/light.h index 2f1df1c9417..745caa96159 100644 --- a/intern/cycles/render/light.h +++ b/intern/cycles/render/light.h @@ -28,6 +28,7 @@ CCL_NAMESPACE_BEGIN class Device; class DeviceScene; +class Object; class Progress; class Scene; class Shader; @@ -108,6 +109,9 @@ protected: DeviceScene *dscene, Scene *scene, Progress& progress); + + /* Check whether light manager can use the object as a light-emissive. */ + bool object_usable_as_light(Object *object); }; CCL_NAMESPACE_END