[Bf-blender-cvs] [2f85295be65] gsoc-2018-many-light-sampling: Cleanup: Replaced space tabs with real tabs

Erik Englesson noreply at git.blender.org
Fri Jun 22 08:54:54 CEST 2018


Commit: 2f85295be657cf3361c0e97afe1e1b36ceb21eed
Author: Erik Englesson
Date:   Thu Jun 14 18:05:35 2018 +0200
Branches: gsoc-2018-many-light-sampling
https://developer.blender.org/rB2f85295be657cf3361c0e97afe1e1b36ceb21eed

Cleanup: Replaced space tabs with real tabs

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

M	intern/cycles/kernel/kernel_light.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/kernel/kernel_light.h b/intern/cycles/kernel/kernel_light.h
index 0719191d5f9..b77f9074717 100644
--- a/intern/cycles/kernel/kernel_light.h
+++ b/intern/cycles/kernel/kernel_light.h
@@ -1080,88 +1080,88 @@ ccl_device bool light_select_reached_max_bounces(KernelGlobals *kg, int index, i
 
 ccl_device float calc_node_importance(KernelGlobals *kg, float3 P, int node_offset)
 {
-    float4 node0 = kernel_tex_fetch(__light_tree_nodes, node_offset + 0);
-    float4 node1 = kernel_tex_fetch(__light_tree_nodes, node_offset + 1);
-    float4 node2 = kernel_tex_fetch(__light_tree_nodes, node_offset + 2);
-    float4 node3 = kernel_tex_fetch(__light_tree_nodes, node_offset + 3);
-
-    float energy = node0[0];
-    float3 bboxMin = make_float3( node1[0], node1[1], node1[2]);
-    float3 bboxMax = make_float3( node1[3], node2[0], node2[1]);
-    float theta_o = node2[2];
-    float theta_e = node2[3];
-    float3 axis = make_float3(node3[0], node3[1], node3[2]);
-    float3 centroid = 0.5f*(bboxMax + bboxMin);
-
-    float3 centroidToP = P-centroid;
-    float theta = acosf(dot(axis,normalize(centroidToP)));
-    float theta_u = 0; // TODO: Figure out how to calculate this one
-    float d2 = len_squared(centroidToP);
-
-    return energy * cosf(clamp(theta - theta_o - theta_u, 0.0, theta_e))/d2;
+	float4 node0 = kernel_tex_fetch(__light_tree_nodes, node_offset + 0);
+	float4 node1 = kernel_tex_fetch(__light_tree_nodes, node_offset + 1);
+	float4 node2 = kernel_tex_fetch(__light_tree_nodes, node_offset + 2);
+	float4 node3 = kernel_tex_fetch(__light_tree_nodes, node_offset + 3);
+
+	float energy = node0[0];
+	float3 bboxMin = make_float3( node1[0], node1[1], node1[2]);
+	float3 bboxMax = make_float3( node1[3], node2[0], node2[1]);
+	float theta_o = node2[2];
+	float theta_e = node2[3];
+	float3 axis = make_float3(node3[0], node3[1], node3[2]);
+	float3 centroid = 0.5f*(bboxMax + bboxMin);
+
+	float3 centroidToP = P-centroid;
+	float theta = acosf(dot(axis,normalize(centroidToP)));
+	float theta_u = 0; // TODO: Figure out how to calculate this one
+	float d2 = len_squared(centroidToP);
+
+	return energy * cosf(clamp(theta - theta_o - theta_u, 0.0, theta_e))/d2;
 }
 
 ccl_device void update_parent_node(KernelGlobals *kg, int node_offset,
                                    int *childOffset, int *distribution_id,
                                    int *nemitters)
 {
-    float4 node        = kernel_tex_fetch(__light_tree_nodes, node_offset);
-    (*childOffset)     = __float_as_int(node[1]);
-    (*distribution_id) = __float_as_int(node[2]);
-    (*nemitters)       = __float_as_int(node[3]);
+	float4 node        = kernel_tex_fetch(__light_tree_nodes, node_offset);
+	(*childOffset)     = __float_as_int(node[1]);
+	(*distribution_id) = __float_as_int(node[2]);
+	(*nemitters)       = __float_as_int(node[3]);
 }
 
 ccl_device int sample_light_bvh(KernelGlobals *kg, float3 P, float randu, float *pdf_factor)
 {
-    int index = -1;
-    *pdf_factor = 1.0f;
-
-    /* read in first part of root node of light BVH */
-    int secondChildOffset, distribution_id, nemitters;
-    update_parent_node(kg, 0, &secondChildOffset, &distribution_id, &nemitters);
-
-    int offset = 0;
-    do{
-
-        /* Found a leaf - Choose which light to use */
-        if(nemitters > 0){ // Found a leaf
-             if(nemitters == 1){
-                 index = distribution_id;
-             } else { // Leaf with several lights. Pick one randomly.
-                 light_distribution_sample(kg, &randu); // TODO: Rescale random number in a better way
-                 int light = min((int)(randu* (float)nemitters), nemitters-1);
-                 index = distribution_id +light;
-                 *pdf_factor *= 1.0f / (float)nemitters;
-             }
-             break;
-        } else { // Interior node, pick left or right randomly
-
-            /* calculate probability of going down left node */
-            int child_offsetL = offset + 4;
-            int child_offsetR = 4*secondChildOffset;
-            float I_L = calc_node_importance(kg, P, child_offsetL);
-            float I_R = calc_node_importance(kg, P, child_offsetR);
-            float P_L = I_L / ( I_L + I_R);
-
-            /* choose which node to go down */
-            light_distribution_sample(kg, &randu); // TODO: Rescale random number in a better way
-            if(randu <= P_L){ // Going down left node
-                offset = child_offsetL;
-                *pdf_factor *= P_L;
-            } else { // Going down right node
-                offset = child_offsetR;
-                *pdf_factor *= 1.0f - P_L;
-            }
-
-            /* update parent node info for next iteration */
-            update_parent_node(kg, offset, &secondChildOffset,
-                               &distribution_id, &nemitters);
-        }
-
-
-    } while(true);
-
-    return index;
+	int index = -1;
+	*pdf_factor = 1.0f;
+
+	/* read in first part of root node of light BVH */
+	int secondChildOffset, distribution_id, nemitters;
+	update_parent_node(kg, 0, &secondChildOffset, &distribution_id, &nemitters);
+
+	int offset = 0;
+	do{
+
+		/* Found a leaf - Choose which light to use */
+		if(nemitters > 0){ // Found a leaf
+			if(nemitters == 1){
+				index = distribution_id;
+			} else { // Leaf with several lights. Pick one randomly.
+				light_distribution_sample(kg, &randu); // TODO: Rescale random number in a better way
+				int light = min((int)(randu* (float)nemitters), nemitters-1);
+				index = distribution_id +light;
+				*pdf_factor *= 1.0f / (float)nemitters;
+			}
+			break;
+		} else { // Interior node, pick left or right randomly
+
+			/* calculate probability of going down left node */
+			int child_offsetL = offset + 4;
+			int child_offsetR = 4*secondChildOffset;
+			float I_L = calc_node_importance(kg, P, child_offsetL);
+			float I_R = calc_node_importance(kg, P, child_offsetR);
+			float P_L = I_L / ( I_L + I_R);
+
+			/* choose which node to go down */
+			light_distribution_sample(kg, &randu); // TODO: Rescale random number in a better way
+			if(randu <= P_L){ // Going down left node
+				offset = child_offsetL;
+				*pdf_factor *= P_L;
+			} else { // Going down right node
+				offset = child_offsetR;
+				*pdf_factor *= 1.0f - P_L;
+			}
+
+			/* update parent node info for next iteration */
+			update_parent_node(kg, offset, &secondChildOffset,
+			                   &distribution_id, &nemitters);
+		}
+
+
+	} while(true);
+
+	return index;
 }
 
 ccl_device_noinline bool light_sample(KernelGlobals *kg,
@@ -1182,6 +1182,10 @@ ccl_device_noinline bool light_sample(KernelGlobals *kg,
 		index = light_distribution_sample(kg, &randu);
 	}
 
+	// HERE: let sample_light_bvh be responsible for calc pdf of choosign this
+	// light. Change triangle_light_sample and lamp_light_sample to only calc
+	// PDF of position and direction similar to PBRT?
+
 	/* fetch light data */
 	const ccl_global KernelLightDistribution *kdistribution = &kernel_tex_fetch(__light_distribution, index);
 	int prim = kdistribution->prim;
diff --git a/intern/cycles/render/light.cpp b/intern/cycles/render/light.cpp
index 3ae25b7bb59..230ea56f799 100644
--- a/intern/cycles/render/light.cpp
+++ b/intern/cycles/render/light.cpp
@@ -250,290 +250,298 @@ bool LightManager::object_usable_as_light(Object *object) {
 
 void LightManager::device_update_distribution(Device *, DeviceScene *dscene, Scene *scene, Progress& progress)
 {
-    progress.set_status("Updating Lights", "Computing distribution");
-
-    /* count */
-    size_t num_lights = 0;
-    size_t num_portals = 0;
-    size_t num_background_lights = 0;
-    size_t num_triangles = 0;
-
-    bool background_mis = false;
-
-    /* The emissivePrims vector contains all emissive primitives in the scene,
-    * i.e., all mesh light triangles and all lamps. The order of the primitives
-    * in the vector is important since it has the same order as the
-    * light_distribution array.
-    *
-    * If using the light BVH then the order is important since the light BVH
-    * reordered the lights so lights in the same node are next to each other
-    * in memory.
-    *
-    * If NOT using the light BVH then the order is important since during
-    * sampling we assume all triangles are first in the array.
-    */
-    vector<Primitive> emissivePrims;
-    emissivePrims.reserve(scene->lights.size());
-
-    int light_index = 0;
-    foreach(Light *light, scene->lights) {
-        if(light->is_enabled) {
-            emissivePrims.push_back(Primitive(~light_index,-1));
-            num_lights++;
-            light_index++;
-        }
-        if(light->is_portal) {
-            num_portals++;
-        }
-    }
-
-    int object_id = 0;
-    foreach(Object *object, scene->objects) {
-        if(progress.get_cancel()) return;
-
-        if(!object_usable_as_light(object)) {
-            object_id++;
-            continue;
-        }
-        /* Count emissive 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];
-            Shader *shader = (shader_index < mesh->used_shaders.size())
-                                     ? mesh->used_shaders[shader_index]
-                                     : scene->default_surface;
-
-            if(shader->use_mis && shader->has_surface_emission) {
-                emissivePrims.push_back(Primitive(i + mesh->tri_offset, object_id));
-                num_triangles++;
-            }
-        }
-
-        object_id++;
-    }
-
-    size_t num_distribution = num_triangles + num_lights;
-    VLOG(1) << "Total " << num_distribution << " of light distribution primitives.";
-
-    if (scene->integrator->use_light_bvh) {
-
-        /* create light BVH */
-        double time_start = time_dt();
-        LightTree lightBVH(emissivePrims, scene->objects, scene->lights, 1);
-        VLOG(1) << "Light BVH build time: " << time_dt() - time_start;
-
-        /* the light BVH reorders the primitives so update emissivePrims */
-        const vector<Primitive>& orderedPrims = lightBVH.getPrimitives()

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list