From 58a290234b0719ce48854e2f6744575b353bf7d3 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Fri, 7 Jun 2013 18:59:23 +0000 Subject: Cycles: ray visibility options now work for lamps and mesh lights, with and without multiple importance sampling, so you can disable them for diffuse/glossy/transmission. The Light Path node here is still weak and does not give this info. To make that work we'd need to evaluate the shader multiple times which is slow and we can't detect well enough when it is actually needed. --- intern/cycles/render/film.cpp | 4 +++- intern/cycles/render/film.h | 2 ++ intern/cycles/render/light.cpp | 38 +++++++++++++++++++++++++++++++++++--- intern/cycles/render/light.h | 3 +++ 4 files changed, 43 insertions(+), 4 deletions(-) (limited to 'intern/cycles/render') diff --git a/intern/cycles/render/film.cpp b/intern/cycles/render/film.cpp index 1fe30376adc..43aef755ba3 100644 --- a/intern/cycles/render/film.cpp +++ b/intern/cycles/render/film.cpp @@ -259,6 +259,8 @@ Film::Film() mist_depth = 100.0f; mist_falloff = 1.0f; + use_light_visibility = false; + need_update = true; } @@ -279,7 +281,7 @@ void Film::device_update(Device *device, DeviceScene *dscene, Scene *scene) kfilm->exposure = exposure; kfilm->pass_flag = 0; kfilm->pass_stride = 0; - kfilm->use_light_pass = 0; + kfilm->use_light_pass = use_light_visibility; foreach(Pass& pass, passes) { kfilm->pass_flag |= pass.type; diff --git a/intern/cycles/render/film.h b/intern/cycles/render/film.h index 1df0e95a48a..0147306c1e3 100644 --- a/intern/cycles/render/film.h +++ b/intern/cycles/render/film.h @@ -61,6 +61,8 @@ public: float mist_depth; float mist_falloff; + bool use_light_visibility; + bool need_update; Film(); diff --git a/intern/cycles/render/light.cpp b/intern/cycles/render/light.cpp index 1d2acf79b6c..71e1f57eb36 100644 --- a/intern/cycles/render/light.cpp +++ b/intern/cycles/render/light.cpp @@ -18,6 +18,7 @@ #include "device.h" #include "integrator.h" +#include "film.h" #include "light.h" #include "mesh.h" #include "object.h" @@ -116,6 +117,9 @@ Light::Light() cast_shadow = true; use_mis = false; + use_diffuse = true; + use_glossy = true; + use_transmission = true; shader = 0; samples = 1; @@ -221,17 +225,31 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen bool transform_applied = mesh->transform_applied; Transform tfm = object->tfm; int object_id = j; + int shader_id = SHADER_MASK; if(transform_applied) object_id = ~object_id; + if(!(object->visibility & PATH_RAY_DIFFUSE)) { + shader_id |= SHADER_EXCLUDE_DIFFUSE; + scene->film->use_light_visibility = true; + } + if(!(object->visibility & PATH_RAY_GLOSSY)) { + shader_id |= SHADER_EXCLUDE_GLOSSY; + scene->film->use_light_visibility = true; + } + if(!(object->visibility & PATH_RAY_TRANSMIT)) { + shader_id |= SHADER_EXCLUDE_TRANSMIT; + scene->film->use_light_visibility = true; + } + for(size_t i = 0; i < mesh->triangles.size(); i++) { Shader *shader = scene->shaders[mesh->shader[i]]; if(shader->sample_as_light && shader->has_surface_emission) { distribution[offset].x = totarea; distribution[offset].y = __int_as_float(i + mesh->tri_offset); - distribution[offset].z = __int_as_float(~0); + distribution[offset].z = __int_as_float(shader_id); distribution[offset].w = __int_as_float(object_id); offset++; @@ -250,7 +268,7 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen } } - /*sample as light disabled for strands*/ + /* sample as light disabled for strands */ #if 0 size_t i = 0; @@ -262,7 +280,7 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen for(int j = 0; j < curve.num_segments(); j++) { distribution[offset].x = totarea; distribution[offset].y = __int_as_float(i + mesh->curve_offset); // XXX fix kernel code - distribution[offset].z = __int_as_float(j); + distribution[offset].z = __int_as_float(j) & SHADER_MASK; distribution[offset].w = __int_as_float(object_id); offset++; @@ -493,6 +511,7 @@ void LightManager::device_update_points(Device *device, DeviceScene *dscene, Sce } } } + scene->film->use_light_visibility = false; for(size_t i = 0; i < scene->lights.size(); i++) { Light *light = scene->lights[i]; @@ -504,6 +523,19 @@ void LightManager::device_update_points(Device *device, DeviceScene *dscene, Sce if(!light->cast_shadow) shader_id &= ~SHADER_CAST_SHADOW; + if(!light->use_diffuse) { + shader_id |= SHADER_EXCLUDE_DIFFUSE; + scene->film->use_light_visibility = true; + } + if(!light->use_glossy) { + shader_id |= SHADER_EXCLUDE_GLOSSY; + scene->film->use_light_visibility = true; + } + if(!light->use_transmission) { + shader_id |= SHADER_EXCLUDE_TRANSMIT; + scene->film->use_light_visibility = true; + } + if(light->type == LIGHT_POINT) { shader_id &= ~SHADER_AREA_LIGHT; diff --git a/intern/cycles/render/light.h b/intern/cycles/render/light.h index acd1692a41f..0e833fdea1d 100644 --- a/intern/cycles/render/light.h +++ b/intern/cycles/render/light.h @@ -53,6 +53,9 @@ public: bool cast_shadow; bool use_mis; + bool use_diffuse; + bool use_glossy; + bool use_transmission; int shader; int samples; -- cgit v1.2.3