[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [57284] trunk/blender/intern/cycles: Cycles: ray visibility options now work for lamps and mesh lights, with and without

Brecht Van Lommel brechtvanlommel at pandora.be
Fri Jun 7 20:59:23 CEST 2013


Revision: 57284
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=57284
Author:   blendix
Date:     2013-06-07 18:59:23 +0000 (Fri, 07 Jun 2013)
Log Message:
-----------
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.

Modified Paths:
--------------
    trunk/blender/intern/cycles/blender/addon/ui.py
    trunk/blender/intern/cycles/blender/blender_object.cpp
    trunk/blender/intern/cycles/kernel/kernel_accumulate.h
    trunk/blender/intern/cycles/kernel/kernel_emission.h
    trunk/blender/intern/cycles/kernel/kernel_light.h
    trunk/blender/intern/cycles/kernel/kernel_types.h
    trunk/blender/intern/cycles/render/film.cpp
    trunk/blender/intern/cycles/render/film.h
    trunk/blender/intern/cycles/render/light.cpp
    trunk/blender/intern/cycles/render/light.h

Modified: trunk/blender/intern/cycles/blender/addon/ui.py
===================================================================
--- trunk/blender/intern/cycles/blender/addon/ui.py	2013-06-07 16:09:52 UTC (rev 57283)
+++ trunk/blender/intern/cycles/blender/addon/ui.py	2013-06-07 18:59:23 UTC (rev 57284)
@@ -528,7 +528,7 @@
     @classmethod
     def poll(cls, context):
         ob = context.object
-        return CyclesButtonsPanel.poll(context) and ob and ob.type in {'MESH', 'CURVE', 'CURVE', 'SURFACE', 'FONT', 'META'}  # todo: 'LAMP'
+        return CyclesButtonsPanel.poll(context) and ob and ob.type in {'MESH', 'CURVE', 'CURVE', 'SURFACE', 'FONT', 'META', 'LAMP'}
 
     def draw(self, context):
         layout = self.layout

Modified: trunk/blender/intern/cycles/blender/blender_object.cpp
===================================================================
--- trunk/blender/intern/cycles/blender/blender_object.cpp	2013-06-07 16:09:52 UTC (rev 57283)
+++ trunk/blender/intern/cycles/blender/blender_object.cpp	2013-06-07 18:59:23 UTC (rev 57284)
@@ -159,6 +159,12 @@
 	light->use_mis = get_boolean(clamp, "use_multiple_importance_sampling");
 	light->samples = get_int(clamp, "samples");
 
+	/* visibility */
+	uint visibility = object_ray_visibility(b_ob);
+	light->use_diffuse = (visibility & PATH_RAY_DIFFUSE) != 0;
+	light->use_glossy = (visibility & PATH_RAY_GLOSSY) != 0;
+	light->use_transmission = (visibility & PATH_RAY_TRANSMIT) != 0;
+
 	/* tag */
 	light->tag_update(scene);
 }

Modified: trunk/blender/intern/cycles/kernel/kernel_accumulate.h
===================================================================
--- trunk/blender/intern/cycles/kernel/kernel_accumulate.h	2013-06-07 16:09:52 UTC (rev 57283)
+++ trunk/blender/intern/cycles/kernel/kernel_accumulate.h	2013-06-07 18:59:23 UTC (rev 57284)
@@ -232,12 +232,9 @@
 			L->direct_transmission += throughput*bsdf_eval->transmission*shadow;
 
 			if(is_lamp) {
-				float3 sum = throughput*(bsdf_eval->diffuse + bsdf_eval->glossy + bsdf_eval->transmission);
-
 				L->shadow.x += shadow.x*shadow_fac;
 				L->shadow.y += shadow.y*shadow_fac;
 				L->shadow.z += shadow.z*shadow_fac;
-				L->shadow.w += average(sum);
 			}
 		}
 		else {

Modified: trunk/blender/intern/cycles/kernel/kernel_emission.h
===================================================================
--- trunk/blender/intern/cycles/kernel/kernel_emission.h	2013-06-07 16:09:52 UTC (rev 57283)
+++ trunk/blender/intern/cycles/kernel/kernel_emission.h	2013-06-07 18:59:23 UTC (rev 57284)
@@ -102,8 +102,6 @@
 	if(is_zero(light_eval))
 		return false;
 
-	/* todo: use visibility flag to skip lights */
-
 	/* evaluate BSDF at shading point */
 	float bsdf_pdf;
 
@@ -117,6 +115,18 @@
 	
 	bsdf_eval_mul(eval, light_eval/ls.pdf);
 
+#ifdef __PASSES__
+	/* use visibility flag to skip lights */
+	if(ls.shader & SHADER_EXCLUDE_ANY) {
+		if(ls.shader & SHADER_EXCLUDE_DIFFUSE)
+			eval->diffuse = make_float3(0.0f, 0.0f, 0.0f);
+		if(ls.shader & SHADER_EXCLUDE_GLOSSY)
+			eval->glossy = make_float3(0.0f, 0.0f, 0.0f);
+		if(ls.shader & SHADER_EXCLUDE_TRANSMIT)
+			eval->transmission = make_float3(0.0f, 0.0f, 0.0f);
+	}
+#endif
+
 	if(bsdf_eval_is_zero(eval))
 		return false;
 
@@ -185,7 +195,19 @@
 
 	if(!lamp_light_eval(kg, lamp, ray->P, ray->D, ray->t, &ls))
 		return false;
-	
+
+#ifdef __PASSES__
+	/* use visibility flag to skip lights */
+	if(ls.shader & SHADER_EXCLUDE_ANY) {
+		if((ls.shader & SHADER_EXCLUDE_DIFFUSE) && (path_flag & PATH_RAY_DIFFUSE))
+			return false;
+		if((ls.shader & SHADER_EXCLUDE_GLOSSY) && (path_flag & PATH_RAY_GLOSSY))
+			return false;
+		if((ls.shader & SHADER_EXCLUDE_TRANSMIT) && (path_flag & PATH_RAY_TRANSMIT))
+			return false;
+	}
+#endif
+
 	/* todo: missing texture coordinates */
 	float u = 0.0f;
 	float v = 0.0f;

Modified: trunk/blender/intern/cycles/kernel/kernel_light.h
===================================================================
--- trunk/blender/intern/cycles/kernel/kernel_light.h	2013-06-07 16:09:52 UTC (rev 57283)
+++ trunk/blender/intern/cycles/kernel/kernel_light.h	2013-06-07 18:59:23 UTC (rev 57284)
@@ -558,11 +558,11 @@
 	if(prim >= 0) {
 		int object = __float_as_int(l.w);
 #ifdef __HAIR__
-		int segment = __float_as_int(l.z);
+		int segment = __float_as_int(l.z) & SHADER_MASK;
 #endif
 
 #ifdef __HAIR__
-		if (segment != (int)~0)
+		if (segment != SHADER_MASK)
 			curve_segment_light_sample(kg, prim, object, segment, randu, randv, time, ls);
 		else
 #endif
@@ -571,6 +571,7 @@
 		/* compute incoming direction, distance and pdf */
 		ls->D = normalize_len(ls->P - P, &ls->t);
 		ls->pdf = triangle_light_pdf(kg, ls->Ng, -ls->D, ls->t);
+		ls->shader |= __float_as_int(l.z) & (~SHADER_MASK);
 	}
 	else {
 		int lamp = -prim-1;

Modified: trunk/blender/intern/cycles/kernel/kernel_types.h
===================================================================
--- trunk/blender/intern/cycles/kernel/kernel_types.h	2013-06-07 16:09:52 UTC (rev 57283)
+++ trunk/blender/intern/cycles/kernel/kernel_types.h	2013-06-07 18:59:23 UTC (rev 57284)
@@ -326,8 +326,12 @@
 	SHADER_CAST_SHADOW = (1 << 30),
 	SHADER_AREA_LIGHT = (1 << 29),
 	SHADER_USE_MIS = (1 << 28),
+	SHADER_EXCLUDE_DIFFUSE = (1 << 27),
+	SHADER_EXCLUDE_GLOSSY = (1 << 26),
+	SHADER_EXCLUDE_TRANSMIT = (1 << 25),
+	SHADER_EXCLUDE_ANY = (SHADER_EXCLUDE_DIFFUSE|SHADER_EXCLUDE_GLOSSY|SHADER_EXCLUDE_TRANSMIT),
 
-	SHADER_MASK = ~(SHADER_SMOOTH_NORMAL|SHADER_CAST_SHADOW|SHADER_AREA_LIGHT|SHADER_USE_MIS)
+	SHADER_MASK = ~(SHADER_SMOOTH_NORMAL|SHADER_CAST_SHADOW|SHADER_AREA_LIGHT|SHADER_USE_MIS|SHADER_EXCLUDE_ANY)
 } ShaderFlag;
 
 /* Light Type */

Modified: trunk/blender/intern/cycles/render/film.cpp
===================================================================
--- trunk/blender/intern/cycles/render/film.cpp	2013-06-07 16:09:52 UTC (rev 57283)
+++ trunk/blender/intern/cycles/render/film.cpp	2013-06-07 18:59:23 UTC (rev 57284)
@@ -259,6 +259,8 @@
 	mist_depth = 100.0f;
 	mist_falloff = 1.0f;
 
+	use_light_visibility = false;
+
 	need_update = true;
 }
 
@@ -279,7 +281,7 @@
 	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;

Modified: trunk/blender/intern/cycles/render/film.h
===================================================================
--- trunk/blender/intern/cycles/render/film.h	2013-06-07 16:09:52 UTC (rev 57283)
+++ trunk/blender/intern/cycles/render/film.h	2013-06-07 18:59:23 UTC (rev 57284)
@@ -61,6 +61,8 @@
 	float mist_depth;
 	float mist_falloff;
 
+	bool use_light_visibility;
+
 	bool need_update;
 
 	Film();

Modified: trunk/blender/intern/cycles/render/light.cpp
===================================================================
--- trunk/blender/intern/cycles/render/light.cpp	2013-06-07 16:09:52 UTC (rev 57283)
+++ trunk/blender/intern/cycles/render/light.cpp	2013-06-07 18:59:23 UTC (rev 57284)
@@ -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 @@
 
 	cast_shadow = true;
 	use_mis = false;
+	use_diffuse = true;
+	use_glossy = true;
+	use_transmission = true;
 
 	shader = 0;
 	samples = 1;
@@ -221,17 +225,31 @@
 			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 @@
 				}
 			}
 
-			/*sample as light disabled for strands*/
+			/* sample as light disabled for strands */
 #if 0
 			size_t i = 0;
 
@@ -262,7 +280,7 @@
 					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 @@
 			}
 		}
 	}
+	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 @@
 		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;
 

Modified: trunk/blender/intern/cycles/render/light.h
===================================================================
--- trunk/blender/intern/cycles/render/light.h	2013-06-07 16:09:52 UTC (rev 57283)
+++ trunk/blender/intern/cycles/render/light.h	2013-06-07 18:59:23 UTC (rev 57284)
@@ -53,6 +53,9 @@
 
 	bool cast_shadow;
 	bool use_mis;
+	bool use_diffuse;
+	bool use_glossy;
+	bool use_transmission;
 
 	int shader;
 	int samples;




More information about the Bf-blender-cvs mailing list