[Bf-blender-cvs] [f9de9915040] soc-2022-many-lights-sampling: Refactor: better separate light tree and flat CDF building
Brecht Van Lommel
noreply at git.blender.org
Sat Nov 19 19:21:40 CET 2022
Commit: f9de991504042f562b66b156446867efcfbc2156
Author: Brecht Van Lommel
Date: Fri Nov 18 18:16:10 2022 +0100
Branches: soc-2022-many-lights-sampling
https://developer.blender.org/rBf9de991504042f562b66b156446867efcfbc2156
Refactor: better separate light tree and flat CDF building
Make it so their implementation can be in separate functions, move some shared
code to device_update_lights. Now we no longer build both a CDF and light tree.
===================================================================
M intern/cycles/kernel/data_template.h
M intern/cycles/kernel/integrator/intersect_closest.h
M intern/cycles/kernel/integrator/shade_background.h
M intern/cycles/kernel/light/background.h
M intern/cycles/kernel/light/light.h
M intern/cycles/kernel/light/tree.h
M intern/cycles/scene/light.cpp
M intern/cycles/scene/light.h
===================================================================
diff --git a/intern/cycles/kernel/data_template.h b/intern/cycles/kernel/data_template.h
index 30b326d27b0..67992e82c48 100644
--- a/intern/cycles/kernel/data_template.h
+++ b/intern/cycles/kernel/data_template.h
@@ -23,14 +23,11 @@ KERNEL_STRUCT_MEMBER(background, int, volume_shader)
KERNEL_STRUCT_MEMBER(background, float, volume_step_size)
KERNEL_STRUCT_MEMBER(background, int, transparent)
KERNEL_STRUCT_MEMBER(background, float, transparent_roughness_squared_threshold)
-/* Portal sampling. */
-KERNEL_STRUCT_MEMBER(background, float, portal_weight)
-KERNEL_STRUCT_MEMBER(background, int, num_portals)
-KERNEL_STRUCT_MEMBER(background, int, portal_offset)
/* Sun sampling. */
KERNEL_STRUCT_MEMBER(background, float, sun_weight)
/* Importance map sampling. */
KERNEL_STRUCT_MEMBER(background, float, map_weight)
+KERNEL_STRUCT_MEMBER(background, float, portal_weight)
KERNEL_STRUCT_MEMBER(background, int, map_res_x)
KERNEL_STRUCT_MEMBER(background, int, map_res_y)
/* Multiple importance sampling. */
@@ -39,9 +36,6 @@ KERNEL_STRUCT_MEMBER(background, int, use_mis)
KERNEL_STRUCT_MEMBER(background, int, lightgroup)
/* Light Index. */
KERNEL_STRUCT_MEMBER(background, int, light_index)
-/* Padding. */
-KERNEL_STRUCT_MEMBER(background, int, pad1)
-KERNEL_STRUCT_MEMBER(background, int, pad2)
KERNEL_STRUCT_END(KernelBackground)
/* BVH: own BVH2 if no native device acceleration struct used. */
@@ -148,12 +142,21 @@ KERNEL_STRUCT_END(KernelFilm)
KERNEL_STRUCT_BEGIN(KernelIntegrator, integrator)
/* Emission. */
KERNEL_STRUCT_MEMBER(integrator, int, use_direct_light)
-KERNEL_STRUCT_MEMBER(integrator, int, num_distribution)
+KERNEL_STRUCT_MEMBER(integrator, int, use_light_mis)
+KERNEL_STRUCT_MEMBER(integrator, int, use_light_tree)
+KERNEL_STRUCT_MEMBER(integrator, int, num_lights)
KERNEL_STRUCT_MEMBER(integrator, int, num_distant_lights)
-KERNEL_STRUCT_MEMBER(integrator, int, num_all_lights)
+KERNEL_STRUCT_MEMBER(integrator, int, num_background_lights)
+/* Portal sampling. */
+KERNEL_STRUCT_MEMBER(integrator, int, num_portals)
+KERNEL_STRUCT_MEMBER(integrator, int, portal_offset)
+/* Flat light distribution. */
+KERNEL_STRUCT_MEMBER(integrator, int, num_distribution)
KERNEL_STRUCT_MEMBER(integrator, float, distribution_pdf_triangles)
KERNEL_STRUCT_MEMBER(integrator, float, distribution_pdf_lights)
KERNEL_STRUCT_MEMBER(integrator, float, light_inv_rr_threshold)
+/* Light tree. */
+KERNEL_STRUCT_MEMBER(integrator, int, num_tree_lights)
/* Bounces. */
KERNEL_STRUCT_MEMBER(integrator, int, min_bounce)
KERNEL_STRUCT_MEMBER(integrator, int, max_bounce)
@@ -179,8 +182,6 @@ KERNEL_STRUCT_MEMBER(integrator, int, seed)
/* Clamp. */
KERNEL_STRUCT_MEMBER(integrator, float, sample_clamp_direct)
KERNEL_STRUCT_MEMBER(integrator, float, sample_clamp_indirect)
-/* MIS. */
-KERNEL_STRUCT_MEMBER(integrator, int, use_lamp_mis)
/* Caustics. */
KERNEL_STRUCT_MEMBER(integrator, int, use_caustics)
/* Sampling pattern. */
@@ -196,8 +197,6 @@ KERNEL_STRUCT_MEMBER(integrator, int, has_shadow_catcher)
KERNEL_STRUCT_MEMBER(integrator, int, filter_closures)
/* MIS debugging. */
KERNEL_STRUCT_MEMBER(integrator, int, direct_light_sampling_type)
-/* Light tree. */
-KERNEL_STRUCT_MEMBER(integrator, int, use_light_tree)
/* Path Guiding */
KERNEL_STRUCT_MEMBER(integrator, float, surface_guiding_probability)
KERNEL_STRUCT_MEMBER(integrator, float, volume_guiding_probability)
diff --git a/intern/cycles/kernel/integrator/intersect_closest.h b/intern/cycles/kernel/integrator/intersect_closest.h
index 1a0a0af5bbb..dc171885755 100644
--- a/intern/cycles/kernel/integrator/intersect_closest.h
+++ b/intern/cycles/kernel/integrator/intersect_closest.h
@@ -387,7 +387,7 @@ ccl_device void integrator_intersect_closest(KernelGlobals kg,
#endif /* __MNEE__ */
/* Light intersection for MIS. */
- if (kernel_data.integrator.use_lamp_mis) {
+ if (kernel_data.integrator.use_light_mis) {
/* NOTE: if we make lights visible to camera rays, we'll need to initialize
* these in the path_state_init. */
const int last_type = INTEGRATOR_STATE(state, isect, type);
diff --git a/intern/cycles/kernel/integrator/shade_background.h b/intern/cycles/kernel/integrator/shade_background.h
index 03626a78b66..6a6fd62dc84 100644
--- a/intern/cycles/kernel/integrator/shade_background.h
+++ b/intern/cycles/kernel/integrator/shade_background.h
@@ -85,7 +85,7 @@ ccl_device_inline void integrate_background(KernelGlobals kg,
#ifdef __MNEE__
if (INTEGRATOR_STATE(state, path, mnee) & PATH_MNEE_CULL_LIGHT_CONNECTION) {
if (kernel_data.background.use_mis) {
- for (int lamp = 0; lamp < kernel_data.integrator.num_all_lights; lamp++) {
+ for (int lamp = 0; lamp < kernel_data.integrator.num_lights; lamp++) {
/* This path should have been resolved with mnee, it will
* generate a firefly for small lights since it is improbable. */
const ccl_global KernelLight *klight = &kernel_data_fetch(lights, lamp);
@@ -133,7 +133,7 @@ ccl_device_inline void integrate_distant_lights(KernelGlobals kg,
const float3 ray_D = INTEGRATOR_STATE(state, ray, D);
const float ray_time = INTEGRATOR_STATE(state, ray, time);
LightSample ls ccl_optional_struct_init;
- for (int lamp = 0; lamp < kernel_data.integrator.num_all_lights; lamp++) {
+ for (int lamp = 0; lamp < kernel_data.integrator.num_lights; lamp++) {
if (distant_light_sample_from_intersection(kg, ray_D, lamp, &ls)) {
/* Use visibility flag to skip lights. */
#ifdef __PASSES__
diff --git a/intern/cycles/kernel/light/background.h b/intern/cycles/kernel/light/background.h
index 9bb6d105340..3fc9e0776a4 100644
--- a/intern/cycles/kernel/light/background.h
+++ b/intern/cycles/kernel/light/background.h
@@ -131,7 +131,7 @@ ccl_device float background_map_pdf(KernelGlobals kg, float3 direction)
ccl_device_inline bool background_portal_data_fetch_and_check_side(
KernelGlobals kg, float3 P, int index, ccl_private float3 *lightpos, ccl_private float3 *dir)
{
- int portal = kernel_data.background.portal_offset + index;
+ int portal = kernel_data.integrator.portal_offset + index;
const ccl_global KernelLight *klight = &kernel_data_fetch(lights, portal);
*lightpos = make_float3(klight->co[0], klight->co[1], klight->co[2]);
@@ -150,7 +150,7 @@ ccl_device_inline float background_portal_pdf(
float portal_pdf = 0.0f;
int num_possible = 0;
- for (int p = 0; p < kernel_data.background.num_portals; p++) {
+ for (int p = 0; p < kernel_data.integrator.num_portals; p++) {
if (p == ignore_portal)
continue;
@@ -164,7 +164,7 @@ ccl_device_inline float background_portal_pdf(
}
num_possible++;
- int portal = kernel_data.background.portal_offset + p;
+ int portal = kernel_data.integrator.portal_offset + p;
const ccl_global KernelLight *klight = &kernel_data_fetch(lights, portal);
float3 extentu = make_float3(
klight->area.extentu[0], klight->area.extentu[1], klight->area.extentu[2]);
@@ -208,7 +208,7 @@ ccl_device_inline float background_portal_pdf(
ccl_device int background_num_possible_portals(KernelGlobals kg, float3 P)
{
int num_possible_portals = 0;
- for (int p = 0; p < kernel_data.background.num_portals; p++) {
+ for (int p = 0; p < kernel_data.integrator.num_portals; p++) {
float3 lightpos, dir;
if (background_portal_data_fetch_and_check_side(kg, P, p, &lightpos, &dir))
num_possible_portals++;
@@ -232,7 +232,7 @@ ccl_device float3 background_portal_sample(KernelGlobals kg,
/* TODO(sergey): Some smarter way of finding portal to sample
* is welcome.
*/
- for (int p = 0; p < kernel_data.background.num_portals; p++) {
+ for (int p = 0; p < kernel_data.integrator.num_portals; p++) {
/* Search for the sampled portal. */
float3 lightpos, dir;
if (!background_portal_data_fetch_and_check_side(kg, P, p, &lightpos, &dir))
@@ -240,7 +240,7 @@ ccl_device float3 background_portal_sample(KernelGlobals kg,
if (portal == 0) {
/* p is the portal to be sampled. */
- int portal = kernel_data.background.portal_offset + p;
+ int portal = kernel_data.integrator.portal_offset + p;
const ccl_global KernelLight *klight = &kernel_data_fetch(lights, portal);
float3 extentu = make_float3(
klight->area.extentu[0], klight->area.extentu[1], klight->area.extentu[2]);
diff --git a/intern/cycles/kernel/light/light.h b/intern/cycles/kernel/light/light.h
index a944594c2ec..5d37aa3b53d 100644
--- a/intern/cycles/kernel/light/light.h
+++ b/intern/cycles/kernel/light/light.h
@@ -100,7 +100,7 @@ ccl_device bool lights_intersect(KernelGlobals kg,
const int last_type,
const uint32_t path_flag)
{
- for (int lamp = 0; lamp < kernel_data.integrator.num_all_lights; lamp++) {
+ for (int lamp = 0; lamp < kernel_data.integrator.num_lights; lamp++) {
const ccl_global KernelLight *klight = &kernel_data_fetch(lights, lamp);
if (path_flag & PATH_RAY_CAMERA) {
diff --git a/intern/cycles/kernel/light/tree.h b/intern/cycles/kernel/light/tree.h
index 185d184b3e7..d7b8ebad2cf 100644
--- a/intern/cycles/kernel/light/tree.h
+++ b/intern/cycles/kernel/light/tree.h
@@ -524,7 +524,7 @@ ccl_device bool light_tree_sample(KernelGlobals kg,
return false; /* both child nodes have zero importance */
}
- if (*randu <= left_probability) { /* go left */
+ if (*randu < left_probability) { /* go left */
node_index = left_index;
*randu /= left_probability;
*pdf_factor *= left_probability;
@@ -670,7 +670,7 @@ ccl_device float light_tree_pdf(
float distant_light_importance = light_tree_distant_light_importance<false>(
kg, N, has_transmission, kernel_data.integrator.num_distant_lights);
float light_tree_importance = 0.0f;
- if (kernel_data.integrator.num_distribution > kernel_data.integrator.num_distant_lights) {
+ if (kernel_data.integrator.num_tree_lights) {
const ccl_global KernelLightTreeNode *kroot = &kernel_data_fetch(light_tree_nodes, 0);
float discard;
light_tree_node_importance<false>(
@@ -757,7 +757,7 @@ ccl_device float light_tree_pdf_distant(
float d
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list