[Bf-blender-cvs] [2d6e1ddb94a] gsoc-2018-many-light-sampling: Cycles: Updated rescaling of random numbers
Erik Englesson
noreply at git.blender.org
Fri Jul 13 13:57:45 CEST 2018
Commit: 2d6e1ddb94a3bcedf3dae486c4c533b015e3311f
Author: Erik Englesson
Date: Tue Jul 10 11:32:14 2018 +0200
Branches: gsoc-2018-many-light-sampling
https://developer.blender.org/rB2d6e1ddb94a3bcedf3dae486c4c533b015e3311f
Cycles: Updated rescaling of random numbers
The new paper describes how they rescale the
random numbers in the tree traversal. We do
the same now.
===================================================================
M intern/cycles/kernel/kernel_light.h
M intern/cycles/kernel/kernel_path_surface.h
===================================================================
diff --git a/intern/cycles/kernel/kernel_light.h b/intern/cycles/kernel/kernel_light.h
index 5ded315881a..57f238425ee 100644
--- a/intern/cycles/kernel/kernel_light.h
+++ b/intern/cycles/kernel/kernel_light.h
@@ -1180,7 +1180,6 @@ ccl_device void light_bvh_sample(KernelGlobals *kg, float3 P, float randu,
if(num_emitters == 1){
sampled_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)num_emitters), num_emitters-1);
sampled_index = distribution_id +light;
*pdf_factor *= 1.0f / (float)num_emitters;
@@ -1196,11 +1195,16 @@ ccl_device void light_bvh_sample(KernelGlobals *kg, float3 P, float randu,
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
+ /* rescale random number */
+ randu = randu / P_L;
+
offset = child_offsetL;
*pdf_factor *= P_L;
} else { // Going down right node
+ /* rescale random number */
+ randu = (randu * (I_L + I_R) - I_L)/I_R;
+
offset = child_offsetR;
*pdf_factor *= 1.0f - P_L;
}
diff --git a/intern/cycles/kernel/kernel_path_surface.h b/intern/cycles/kernel/kernel_path_surface.h
index a344f43d786..da366bca530 100644
--- a/intern/cycles/kernel/kernel_path_surface.h
+++ b/intern/cycles/kernel/kernel_path_surface.h
@@ -126,9 +126,6 @@ ccl_device void accum_light_tree_contribution(KernelGlobals *kg, float randu,
ShaderData *sd, ShaderData *emission_sd,
int *num_lights)
{
- /* TODO: sort out randu and randv rescaling */
- light_distribution_sample(kg, &randu);
- light_distribution_sample(kg, &randv);
float3 P = sd->P;
float time = sd->time;
@@ -187,11 +184,17 @@ ccl_device void accum_light_tree_contribution(KernelGlobals *kg, float randu,
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);
- light_distribution_sample(kg, &randu);
+
if(randu <= P_L){ // Going down left node
+ /* rescale random number */
+ randu = randu / P_L;
+
offset = child_offsetL;
pdf_factor *= P_L;
} else { // Going down right node
+ /* rescale random number */
+ randu = (randu * (I_L + I_R) - I_L)/I_R;
+
offset = child_offsetR;
pdf_factor *= 1.0f - P_L;
}
More information about the Bf-blender-cvs
mailing list