[Bf-blender-cvs] [8e36d94be26] gsoc-2018-many-light-sampling: Cycles: Added more comments and renamed variables

Erik Englesson noreply at git.blender.org
Fri Aug 10 17:37:59 CEST 2018


Commit: 8e36d94be266dc64afd9861a6fd5aa9cbbecc0f5
Author: Erik Englesson
Date:   Wed Aug 8 16:57:59 2018 +0200
Branches: gsoc-2018-many-light-sampling
https://developer.blender.org/rB8e36d94be266dc64afd9861a6fd5aa9cbbecc0f5

Cycles: Added more comments and renamed variables

More code comments have been added to all code related to
the light tree. I also renamed all uses of "light BVH" to
use light tree instead to keep everything consistent.
Functions and variable names that used the camel case
naming convention has been changed to follow Blender's
code style. Also, unneeded includes were removed.

===================================================================

M	intern/cycles/blender/addon/presets.py
M	intern/cycles/blender/addon/properties.py
M	intern/cycles/blender/addon/ui.py
M	intern/cycles/blender/blender_sync.cpp
M	intern/cycles/kernel/kernel_light.h
M	intern/cycles/kernel/kernel_path_surface.h
M	intern/cycles/kernel/kernel_path_volume.h
M	intern/cycles/kernel/kernel_types.h
M	intern/cycles/render/integrator.cpp
M	intern/cycles/render/integrator.h
M	intern/cycles/render/light.cpp
M	intern/cycles/render/light_tree.cpp
M	intern/cycles/render/light_tree.h

===================================================================

diff --git a/intern/cycles/blender/addon/presets.py b/intern/cycles/blender/addon/presets.py
index 85e075a5167..33b153e275a 100644
--- a/intern/cycles/blender/addon/presets.py
+++ b/intern/cycles/blender/addon/presets.py
@@ -68,7 +68,7 @@ class AddPresetSampling(AddPresetBase, Operator):
         "cycles.subsurface_samples",
         "cycles.volume_samples",
         "cycles.use_square_samples",
-        "cycles.use_light_bvh",
+        "cycles.use_light_tree",
         "cycles.splitting_threshold",
         "cycles.progressive",
         "cycles.seed",
diff --git a/intern/cycles/blender/addon/properties.py b/intern/cycles/blender/addon/properties.py
index 974af6238d4..a5b535eb685 100644
--- a/intern/cycles/blender/addon/properties.py
+++ b/intern/cycles/blender/addon/properties.py
@@ -189,8 +189,8 @@ class CyclesRenderSettings(bpy.types.PropertyGroup):
                 default=False,
                 )
 
-        cls.use_light_bvh = BoolProperty(
-                name="Light BVH",
+        cls.use_light_tree = BoolProperty(
+                name="Light Tree",
                 description="Samples many lights more efficiently",
                 default=False,
                 )
diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py
index f7ceddba4a5..64a98d00fb1 100644
--- a/intern/cycles/blender/addon/ui.py
+++ b/intern/cycles/blender/addon/ui.py
@@ -213,8 +213,8 @@ class CYCLES_RENDER_PT_sampling(CyclesButtonsPanel, Panel):
 
         row = layout.row(align=True)
         row.label(text="Experimental:")
-        row.prop(cscene, "use_light_bvh", text="Light BVH")
-        if cscene.use_light_bvh and use_branched_path(context):
+        row.prop(cscene, "use_light_tree", text="Light Tree")
+        if cscene.use_light_tree and use_branched_path(context):
             row = layout.row(align=True)
             row.label(text="") # create empty column
             row.prop(cscene, "splitting_threshold", text="Splitting")
diff --git a/intern/cycles/blender/blender_sync.cpp b/intern/cycles/blender/blender_sync.cpp
index 8f9d8bc34d2..bb67099a0c2 100644
--- a/intern/cycles/blender/blender_sync.cpp
+++ b/intern/cycles/blender/blender_sync.cpp
@@ -281,7 +281,7 @@ void BlenderSync::sync_integrator()
 	                                                  Integrator::NUM_METHODS,
 	                                                  Integrator::PATH);
 
-	integrator->use_light_bvh = get_boolean(cscene, "use_light_bvh");
+	integrator->use_light_tree = get_boolean(cscene, "use_light_tree");
 	integrator->splitting_threshold = get_float(cscene, "splitting_threshold");
 	integrator->sample_all_lights_direct = get_boolean(cscene, "sample_all_lights_direct");
 	integrator->sample_all_lights_indirect = get_boolean(cscene, "sample_all_lights_indirect");
@@ -329,7 +329,7 @@ void BlenderSync::sync_integrator()
 	if(integrator->modified(previntegrator)) {
 		integrator->tag_update(scene);
 	}
-	if(integrator->use_light_bvh != previntegrator.use_light_bvh ||
+	if(integrator->use_light_tree != previntegrator.use_light_tree ||
 	   integrator->splitting_threshold != previntegrator.splitting_threshold)
 	{
 		scene->light_manager->tag_update(scene);
diff --git a/intern/cycles/kernel/kernel_light.h b/intern/cycles/kernel/kernel_light.h
index 26f93aba12a..1c6ca7a3c98 100644
--- a/intern/cycles/kernel/kernel_light.h
+++ b/intern/cycles/kernel/kernel_light.h
@@ -33,7 +33,15 @@ typedef struct LightSample {
 	LightType type;		/* type of light */
 } LightSample;
 
-/* This normal is used in the light picking when using the light tree */
+/* Updates the position and normal used to pick a light for direct lighting.
+ *
+ * The light tree importance metric contains a term that approximates the BSDF
+ * at the shading point. Currently, this is a diffuse approximation which will
+ * give a zero importance for all lights in the lower hemisphere. However, if
+ * it is possible to refract at the shading point then we do not want zero
+ * importance for the lights in the lower hemisphere. This is done by setting
+ * the normal to either [0,0,0] to indicate that it should not be used in the
+ * importance calculations or to flip the normal if we know it must refract. */
 ccl_device void kernel_update_light_picking(
 	ShaderData *sd,
 	ccl_addr_space PathState *state)
@@ -69,13 +77,13 @@ ccl_device void kernel_update_light_picking(
 	sd->P_pick = sd->P;
 
 #if defined(__LAMP_MIS__) || defined(__EMISSION__) || defined(__BACKGROUND_MIS__)
+	/* update ray_N to be the normal at the last non-transparent bounce */
 	if(!transparent){
 		state->ray_N = sd->N_pick;
 	}
-	// todo: what if there is a transparent but it is not this BSDF that is
+	// todo: what if there is a transparent BSDF but it is not this BSDF that is
 	// sampled in surface_bounce() ?
 #endif
-
 }
 
 /* Area light sampling */
@@ -545,6 +553,7 @@ ccl_device float spot_light_attenuation(float3 dir, float spot_angle, float spot
 	return attenuation;
 }
 
+/* returns the PDF of sampling a point on this lamp */
 ccl_device float lamp_light_pdf(KernelGlobals *kg, const float3 Ng, const float3 I, float t)
 {
 	float cos_pi = dot(Ng, I);
@@ -1125,6 +1134,7 @@ ccl_device bool light_select_reached_max_bounces(KernelGlobals *kg, int index, i
 	return (bounce > kernel_tex_fetch(__lights, index).max_bounces);
 }
 
+/* calculates the importance metric for the given node and shading point P */
 ccl_device float calc_importance(KernelGlobals *kg, float3 P, float3 N,
                                  float3 bboxMax, float theta_o, float theta_e,
                                  float3 axis, float energy, float3 centroid)
@@ -1139,10 +1149,10 @@ ccl_device float calc_importance(KernelGlobals *kg, float3 P, float3 N,
 	 *    \ /
 	 *     P
 	 * sin(th) = r/d <=> sin^2(th) = r^2 / d^2 */
-	const float3 centroidToP        = P - centroid;
-	const float3 centroidToPDir     = normalize(centroidToP);
-	const float r2                  = len_squared(bboxMax - centroid);
-	float d2                        = len_squared(centroidToP);
+	const float3 centroid_to_P     = P - centroid;
+	const float3 centroid_to_P_dir = normalize(centroid_to_P);
+	const float r2                 = len_squared(bboxMax - centroid);
+	float d2                       = len_squared(centroid_to_P);
 
 	/* based on comment in the implementation details of the paper */
 	const bool splitting = kernel_data.integrator.splitting_threshold != 0.0f;
@@ -1161,7 +1171,7 @@ ccl_device float calc_importance(KernelGlobals *kg, float3 P, float3 N,
 	}
 
 	/* cos(theta') */
-	const float theta       = fast_acosf(dot(axis, centroidToPDir));
+	const float theta       = fast_acosf(dot(axis, centroid_to_P_dir));
 	const float theta_prime = fmaxf(theta - theta_o - theta_u, 0.0f);
 	if (theta_prime >= theta_e){
 		return 0.0f;
@@ -1170,7 +1180,7 @@ ccl_device float calc_importance(KernelGlobals *kg, float3 P, float3 N,
 
 	/* f_a|cos(theta'_i)| -- diffuse approximation */
 	if(N != make_float3(0.0f, 0.0f, 0.0f)){
-		const float theta_i               = fast_acosf(dot(N, -centroidToPDir));
+		const float theta_i               = fast_acosf(dot(N, -centroid_to_P_dir));
 		const float theta_i_prime         = fmaxf(theta_i - theta_u, 0.0f);
 		const float cos_theta_i_prime     = fast_cosf(theta_i_prime);
 		const float abs_cos_theta_i_prime = fabsf(cos_theta_i_prime);
@@ -1184,54 +1194,75 @@ ccl_device float calc_importance(KernelGlobals *kg, float3 P, float3 N,
 	return energy * cos_theta_prime / d2;
 }
 
+/* the energy, spatial and orientation bounds for the light are loaded and decoded
+ * and then this information is used to calculate the importance for this light.
+ * This function is used to calculate the importance for a light in a node
+ * containing several lights. */
 ccl_device float calc_light_importance(KernelGlobals *kg, float3 P, float3 N,
                                        int node_offset, int light_offset)
 {
+	/* find offset into light_tree_leaf_emitters array */
 	int first_emitter = kernel_tex_fetch(__leaf_to_first_emitter, node_offset/4);
 	kernel_assert(first_emitter != -1);
 	int offset = first_emitter + light_offset*3;
 
-	const float4 node0 = kernel_tex_fetch(__light_tree_leaf_emitters, offset + 0);
-	const float4 node1 = kernel_tex_fetch(__light_tree_leaf_emitters, offset + 1);
-	const float4 node2 = kernel_tex_fetch(__light_tree_leaf_emitters, offset + 2);
-
-	const float3 bboxMin  = make_float3(node0.x, node0.y, node0.z);
-	const float3 bboxMax  = make_float3(node0.w, node1.x, node1.y);
-	const float  theta_o  = node1.z;
-	const float  theta_e  = node1.w;
-	const float3 axis     = make_float3(node2.x, node2.y, node2.z);
-	const float  energy   = node2.w;
-	const float3 centroid = 0.5f*(bboxMax + bboxMin);
-
-	return calc_importance(kg, P, N, bboxMax, theta_o, theta_e, axis, energy,
+	/* get relevant information to be able to calculate the importance */
+	const float4 data0 = kernel_tex_fetch(__light_tree_leaf_emitters, offset + 0);
+	const float4 data1 = kernel_tex_fetch(__light_tree_leaf_emitters, offset + 1);
+	const float4 data2 = kernel_tex_fetch(__light_tree_leaf_emitters, offset + 2);
+
+	/* decode data for this light */
+	const float3 bbox_min  = make_float3(data0.x, data0.y, data0.z);
+	const float3 bbox_max  = make_float3(data0.w, data1.x, data1.y);
+	const float  theta_o  = data1.z;
+	const float  theta_e  = data1.w;
+	const float3 axis     = make_float3(data2.x, data2.y, data2.z);
+	const float  energy   = data2.w;
+	const float3 centroid = 0.5f*(bbox_max + bbox_min);
+
+	return calc_importance(kg, P, N, bbox_max, theta_o, theta_e, axis, energy,
 	                       centroid);
 }
 
+/* the combined energy, spatial and orientation bounds for all the lights for the
+ * given node are loaded and decoded and then this information is used to
+ * calculate the importance for this node. */
 ccl_device float calc_node_importance(KernelGlobals *kg, float3 P, float3 N, int node_offset)
 {
+	/* load the data for this node */
 	const float4 node0 = kernel_tex_fetch(__light_tree_nodes, node_offset + 0);
 	const float4 node1 = kernel_tex_fetch(__light_tree_nodes, node_offset + 1);
 	const float4 node2 = kernel_tex_fetch(__light_tree_nodes, node_offset +

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list