[Bf-blender-cvs] [4429c392648] soc-2020-production-ready-light-tree-2: Cycles: Cleaning up light tree code.
Sam Kottler
noreply at git.blender.org
Wed Aug 19 21:02:29 CEST 2020
Commit: 4429c392648557c1439aaf19bff9645ca62eb5c6
Author: Sam Kottler
Date: Wed Aug 19 13:58:30 2020 -0500
Branches: soc-2020-production-ready-light-tree-2
https://developer.blender.org/rB4429c392648557c1439aaf19bff9645ca62eb5c6
Cycles: Cleaning up light tree code.
* removed unused update light picking code
* switched all light tree function parameters to be in the same P, V, t order
* renamed N_pick to V_pick since it is not always a normal
===================================================================
M intern/cycles/kernel/kernel_bake.h
M intern/cycles/kernel/kernel_emission.h
M intern/cycles/kernel/kernel_light.h
M intern/cycles/kernel/kernel_path.h
M intern/cycles/kernel/kernel_path_branched.h
M intern/cycles/kernel/kernel_path_subsurface.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/kernel/kernel_volume.h
M intern/cycles/kernel/split/kernel_direct_lighting.h
M intern/cycles/kernel/split/kernel_do_volume.h
===================================================================
diff --git a/intern/cycles/kernel/kernel_bake.h b/intern/cycles/kernel/kernel_bake.h
index 3a4c705a886..f849a3c8dd4 100644
--- a/intern/cycles/kernel/kernel_bake.h
+++ b/intern/cycles/kernel/kernel_bake.h
@@ -82,7 +82,7 @@ ccl_device_noinline void compute_light_pass(
while (ss_indirect.num_rays) {
kernel_path_subsurface_setup_indirect(kg, &ss_indirect, &state, &ray, L, &throughput);
indirect_sd.P_pick = sd->P_pick;
- indirect_sd.N_pick = sd->N_pick;
+ indirect_sd.V_pick = sd->V_pick;
indirect_sd.t_pick = sd->t_pick;
kernel_path_indirect(kg, &indirect_sd, emission_sd, &ray, throughput, &state, L);
}
@@ -101,7 +101,7 @@ ccl_device_noinline void compute_light_pass(
# endif
/* compute indirect light */
indirect_sd.P_pick = sd->P_pick;
- indirect_sd.N_pick = sd->N_pick;
+ indirect_sd.V_pick = sd->V_pick;
indirect_sd.t_pick = sd->t_pick;
kernel_path_indirect(kg, &indirect_sd, emission_sd, &ray, throughput, &state, L);
diff --git a/intern/cycles/kernel/kernel_emission.h b/intern/cycles/kernel/kernel_emission.h
index 6c6d8808753..2cbda30cea0 100644
--- a/intern/cycles/kernel/kernel_emission.h
+++ b/intern/cycles/kernel/kernel_emission.h
@@ -222,7 +222,7 @@ ccl_device_noinline_cpu float3 indirect_primitive_emission(
/* multiple importance sampling, get triangle light pdf,
* and compute weight with respect to BSDF pdf */
float pdf = triangle_light_pdf(kg, sd, t);
- pdf *= light_distribution_pdf(kg, sd->P_pick, sd->N_pick, sd->t_pick, sd->prim, sd->object);
+ pdf *= light_distribution_pdf(kg, sd->P_pick, sd->V_pick, sd->t_pick, sd->prim, sd->object);
float mis_weight = power_heuristic(bsdf_pdf, pdf);
return L * mis_weight;
@@ -280,7 +280,7 @@ ccl_device_noinline_cpu void indirect_lamp_emission(KernelGlobals *kg,
/* multiply with light picking probablity to pdf */
ls.pdf *= light_distribution_pdf(
- kg, emission_sd->P_pick, emission_sd->N_pick, emission_sd->t_pick, ~ls.lamp, -1);
+ kg, emission_sd->P_pick, emission_sd->V_pick, emission_sd->t_pick, ~ls.lamp, -1);
float mis_weight = power_heuristic(state->ray_pdf, ls.pdf);
lamp_L *= mis_weight;
}
diff --git a/intern/cycles/kernel/kernel_light.h b/intern/cycles/kernel/kernel_light.h
index 7675a24400a..5b80e4f91e0 100644
--- a/intern/cycles/kernel/kernel_light.h
+++ b/intern/cycles/kernel/kernel_light.h
@@ -37,67 +37,24 @@ typedef struct LightSample {
/* 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(KernelGlobals *kg,
- ShaderData *sd,
- ccl_addr_space PathState *state,
- Ray *ray)
+ * The importance calculation for the light tree is different for scattering events on a surface
+ * and in a volume. For volume events we need to know the point where the ray started and the point
+ * it scattered. To do this we keep track of the ray direction and length. For surface events we
+ * need the normal at the surface. In this case we set the ray length to -1 to mark that surface
+ * importance sampling should be used.
+ */
+ccl_device void kernel_update_light_picking(ShaderData *sd, Ray *ray)
{
if (ray) {
sd->P_pick = ray->P;
- sd->N_pick = ray->D;
+ sd->V_pick = ray->D;
sd->t_pick = ray->t;
- return;
- }
- sd->t_pick = -1.0f;
- bool transmission = false;
- bool reflective = false;
- bool glass = false;
- bool transparent = false;
- if (sd->num_closure < kernel_data.integrator.max_closures) {
- for (int i = 0; i < sd->num_closure; ++i) {
- const ShaderClosure *sc = &sd->closure[i];
- if (CLOSURE_IS_GLASS(sc->type)) {
- glass = true;
- }
- if (CLOSURE_IS_BSDF_TRANSMISSION(sc->type)) {
- transmission = true;
- }
- if (CLOSURE_IS_BSDF_DIFFUSE(sc->type) || CLOSURE_IS_BSDF_GLOSSY(sc->type)) {
- reflective = true;
- }
- if (CLOSURE_IS_BSDF_TRANSPARENT(sc->type)) {
- transparent = true;
- }
- }
- }
-
- if (glass || (reflective && transmission)) {
- sd->N_pick = make_float3(0.0f, 0.0f, 0.0f);
- }
- else if (!glass && !reflective && transmission) {
- sd->N_pick = -sd->N;
}
else {
- sd->N_pick = sd->N;
+ sd->P_pick = sd->P;
+ sd->V_pick = sd->N;
+ sd->t_pick = -1.0f;
}
-
- 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 BSDF but it is not this BSDF that is
- // sampled in surface_bounce() ?
-#endif
}
/* Regular Light */
@@ -721,9 +678,9 @@ ccl_device float calc_bbox_solid_angle(float3 P,
/* calculates the importance metric for the given node and shading point P */
ccl_device float calc_importance(KernelGlobals *kg,
- float t_max,
float3 P,
- float3 N,
+ float3 V,
+ float t_max,
float3 bboxMax,
float3 bboxMin,
float theta_o,
@@ -760,8 +717,8 @@ ccl_device float calc_importance(KernelGlobals *kg,
const float cos_theta_prime = fast_cosf(theta_prime);
/* f_a|cos(theta'_i)| -- diffuse approximation */
- if (N != make_float3(0.0f, 0.0f, 0.0f)) {
- const float cos_theta_i = dot(N, -centroid_to_P_dir);
+ if (V != make_float3(0.0f, 0.0f, 0.0f)) {
+ const float cos_theta_i = dot(V, -centroid_to_P_dir);
const float theta_i = fast_acosf(cos_theta_i);
const float theta_i_prime = fmaxf(theta_i - theta_u, 0.0f);
const float cos_theta_i_prime = fast_cosf(theta_i_prime);
@@ -778,12 +735,12 @@ ccl_device float calc_importance(KernelGlobals *kg,
else {
const float3 p_to_c = centroid - P;
/* find closest point to centroid */
- const float t = fminf(t_max, fmaxf(0.0f, dot(N, p_to_c)));
- const float3 geometry_point = P + N * t;
+ const float t = fminf(t_max, fmaxf(0.0f, dot(V, p_to_c)));
+ const float3 geometry_point = P + V * t;
const float d_min = len(centroid - geometry_point);
const float3 V0 = normalize(P - centroid);
- const float3 V1 = normalize(P + N * fminf(t_max, 1e12f) - centroid);
+ const float3 V1 = normalize(P + V * fminf(t_max, 1e12f) - centroid);
const float3 O0 = V0;
float3 O1, O2;
make_orthonormals_tangent(O0, V1, &O1, &O2);
@@ -822,7 +779,7 @@ ccl_device float calc_importance(KernelGlobals *kg,
* 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, float t_max, float3 P, float3 N, int node_offset, int light_offset)
+ KernelGlobals *kg, float3 P, float3 V, float t_max, 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);
@@ -844,14 +801,14 @@ ccl_device float calc_light_importance(
const float3 centroid = 0.5f * (bbox_max + bbox_min);
return calc_importance(
- kg, t_max, P, N, bbox_max, bbox_min, theta_o, theta_e, axis, energy, centroid);
+ kg, P, V, t_max, bbox_max, bbox_min, 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, float t_max, float3 P, float3 N, int node_offset)
+ KernelGlobals *kg, float3 P, float3 V, float t_max, int node_offset)
{
/* load the data for this node */
const float4 node0 = kernel_tex_fetch(__light_tree_nodes, node_offset + 0);
@@ -869,7 +826,7 @@ ccl_device float calc_node_importance(
const float3 centroid = 0.5f * (bbox_max + bbox_min);
return calc_importance(
- kg, t_max, P, N, bbox_max, bbox_min, theta_o, theta_e, axis, energy, centroid);
+ kg, P, V, t_max, bbox_max, bbox_min, theta_o, theta_e, axis, energy, centroid);
}
/* given a node offset, this function loads and decodes the minimum amount of
@@ -919,9 +876,9 @@ ccl_device void light_background_sample(
/* picks a light from the light tree and returns its index and the probability of
* picking this light. */
ccl_device void light_tree_sample(KernelGlobals *kg,
- float t_max,
float3 P,
- float3 N,
+ float3 V,
+ float t_max,
float *randu,
int *index,
float *pdf_factor)
@@ -963,7 +920,7 @@ ccl_device void light_tree_sample(KernelGlobals *kg,
* except not having an array to store the CDF in. */
float sum = 0.0f;
for (int i = 0; i < num_emitters; ++i) {
- sum += calc_light_importance(kg, t_max, P, N, offset, i);
+ sum += calc_light_importance(kg, P, V, t_max, offset, i);
}
if (sum == 0.0f) {
@@ -978,7 +935,7 @@ ccl_device void light_tree_sample(KernelGlobals
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list