[Bf-blender-cvs] [2fe4e806486] cycles_path_guiding: Guiding: Adding first implementation of RIS directional guiding
Sebastian Herholz
noreply at git.blender.org
Thu Jan 26 20:15:06 CET 2023
Commit: 2fe4e806486debc9029f0ae8d3d4d7f754249164
Author: Sebastian Herholz
Date: Fri Jan 20 16:27:38 2023 +0100
Branches: cycles_path_guiding
https://developer.blender.org/rB2fe4e806486debc9029f0ae8d3d4d7f754249164
Guiding: Adding first implementation of RIS directional guiding
===================================================================
M intern/cycles/blender/addon/properties.py
M intern/cycles/blender/sync.cpp
M intern/cycles/integrator/guiding.h
M intern/cycles/kernel/data_template.h
M intern/cycles/kernel/integrator/shade_surface.h
M intern/cycles/kernel/integrator/surface_shader.h
M intern/cycles/kernel/types.h
M intern/cycles/scene/integrator.cpp
===================================================================
diff --git a/intern/cycles/blender/addon/properties.py b/intern/cycles/blender/addon/properties.py
index a90fd60a711..e0d7e1028de 100644
--- a/intern/cycles/blender/addon/properties.py
+++ b/intern/cycles/blender/addon/properties.py
@@ -209,11 +209,21 @@ enum_guiding_distribution = (
)
enum_guiding_directional_sampling_types = (
- ('PRODUCT', "Diffuse Product", "Guided diffuse BSDF component based on the incoming light distribution and the cosine product (closed form product)", 0),
- ('RIS', "Re-sampled Importance Sampling", "Perform RIS sampling to guided based on the product of the incoming light distribution and the BSDF", 1),
- ('ROUGHNESS', "Roughness-based", "Adjust the guiding probability based on the roughness of the material components", 2),
+ ('PRODUCT',
+ "Diffuse Product",
+ "Guided diffuse BSDF component based on the incoming light distribution and the cosine product (closed form product)",
+ 0),
+ ('RIS',
+ "Re-sampled Importance Sampling",
+ "Perform RIS sampling to guided based on the product of the incoming light distribution and the BSDF",
+ 1),
+ ('ROUGHNESS',
+ "Roughness-based",
+ "Adjust the guiding probability based on the roughness of the material components",
+ 2),
)
+
def enum_openimagedenoise_denoiser(self, context):
import _cycles
if _cycles.with_openimagedenoise:
diff --git a/intern/cycles/blender/sync.cpp b/intern/cycles/blender/sync.cpp
index 68ab3ad3cb4..37e1cd55c46 100644
--- a/intern/cycles/blender/sync.cpp
+++ b/intern/cycles/blender/sync.cpp
@@ -441,8 +441,11 @@ void BlenderSync::sync_integrator(BL::ViewLayer &b_view_layer, bool background)
GuidingDistributionType guiding_distribution_type = (GuidingDistributionType)get_enum(
cscene, "guiding_distribution_type", GUIDING_NUM_TYPES, GUIDING_TYPE_PARALLAX_AWARE_VMM);
integrator->set_guiding_distribution_type(guiding_distribution_type);
- GuidingDirectionalSamplingType guiding_directional_sampling_type = (GuidingDirectionalSamplingType)get_enum(
- cscene, "guiding_directional_sampling_type", GUIDING_DIRECTIONAL_SAMPLING_NUM_TYPES, GUIDING_DIRECTIONAL_SAMPLING_TYPE_PRODUCT);
+ GuidingDirectionalSamplingType guiding_directional_sampling_type =
+ (GuidingDirectionalSamplingType)get_enum(cscene,
+ "guiding_directional_sampling_type",
+ GUIDING_DIRECTIONAL_SAMPLING_NUM_TYPES,
+ GUIDING_DIRECTIONAL_SAMPLING_TYPE_PRODUCT);
integrator->set_guiding_directional_sampling_type(guiding_directional_sampling_type);
}
diff --git a/intern/cycles/integrator/guiding.h b/intern/cycles/integrator/guiding.h
index fa918d4ea4b..8aa61e3371d 100644
--- a/intern/cycles/integrator/guiding.h
+++ b/intern/cycles/integrator/guiding.h
@@ -25,7 +25,8 @@ struct GuidingParams {
{
return !((use == other.use) && (use_surface_guiding == other.use_surface_guiding) &&
(use_volume_guiding == other.use_volume_guiding) && (type == other.type) &&
- (sampling_type == other.sampling_type) && (training_samples == other.training_samples) &&
+ (sampling_type == other.sampling_type) &&
+ (training_samples == other.training_samples) &&
(deterministic == other.deterministic));
}
};
diff --git a/intern/cycles/kernel/data_template.h b/intern/cycles/kernel/data_template.h
index 93a1db64087..29bb98c99b6 100644
--- a/intern/cycles/kernel/data_template.h
+++ b/intern/cycles/kernel/data_template.h
@@ -211,7 +211,7 @@ KERNEL_STRUCT_MEMBER(integrator, int, use_guiding_direct_light)
KERNEL_STRUCT_MEMBER(integrator, int, use_guiding_mis_weights)
/* Padding. */
-//KERNEL_STRUCT_MEMBER(integrator, int, pad1)
+// KERNEL_STRUCT_MEMBER(integrator, int, pad1)
KERNEL_STRUCT_END(KernelIntegrator)
/* SVM. For shader specialization. */
diff --git a/intern/cycles/kernel/integrator/shade_surface.h b/intern/cycles/kernel/integrator/shade_surface.h
index 548867c7551..cc81dae8af0 100644
--- a/intern/cycles/kernel/integrator/shade_surface.h
+++ b/intern/cycles/kernel/integrator/shade_surface.h
@@ -367,21 +367,45 @@ ccl_device_forceinline int integrate_surface_bsdf_bssrdf_bounce(
float2 bsdf_sampled_roughness = make_float2(1.0f, 1.0f);
float bsdf_eta = 1.0f;
+ float mis_pdf = 1.0f;
#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4
if (kernel_data.integrator.use_surface_guiding) {
- label = surface_shader_bsdf_guided_sample_closure(kg,
- state,
- sd,
- sc,
- rand_bsdf,
- &bsdf_eval,
- &bsdf_wo,
- &bsdf_pdf,
- &unguided_bsdf_pdf,
- &bsdf_sampled_roughness,
- &bsdf_eta);
-
+ if (kernel_data.integrator.guiding_directional_sampling_type ==
+ GUIDING_DIRECTIONAL_SAMPLING_TYPE_PRODUCT) {
+ label = surface_shader_bsdf_guided_sample_closure_mis(kg,
+ state,
+ sd,
+ sc,
+ rand_bsdf,
+ &bsdf_eval,
+ &bsdf_wo,
+ &bsdf_pdf,
+ &unguided_bsdf_pdf,
+ &bsdf_sampled_roughness,
+ &bsdf_eta);
+ mis_pdf = (unguided_bsdf_pdf > 0.f) ? bsdf_pdf : 0.f;
+ }
+ else if (kernel_data.integrator.guiding_directional_sampling_type ==
+ GUIDING_DIRECTIONAL_SAMPLING_TYPE_RIS) {
+ label = surface_shader_bsdf_guided_sample_closure_ris(kg,
+ state,
+ sd,
+ sc,
+ rand_bsdf,
+ rng_state,
+ &bsdf_eval,
+ &bsdf_wo,
+ &bsdf_pdf,
+ &mis_pdf,
+ &unguided_bsdf_pdf,
+ &bsdf_sampled_roughness,
+ &bsdf_eta);
+ }
+ if (!(unguided_bsdf_pdf > 0.f)) {
+ bsdf_pdf = 0.f;
+ mis_pdf = 0.f;
+ }
if (bsdf_pdf == 0.0f || bsdf_eval_is_zero(&bsdf_eval)) {
return LABEL_NONE;
}
@@ -404,7 +428,7 @@ ccl_device_forceinline int integrate_surface_bsdf_bssrdf_bounce(
if (bsdf_pdf == 0.0f || bsdf_eval_is_zero(&bsdf_eval)) {
return LABEL_NONE;
}
-
+ mis_pdf = bsdf_pdf;
unguided_bsdf_pdf = bsdf_pdf;
}
@@ -440,7 +464,7 @@ ccl_device_forceinline int integrate_surface_bsdf_bssrdf_bounce(
/* Update path state */
if (!(label & LABEL_TRANSPARENT)) {
- INTEGRATOR_STATE_WRITE(state, path, mis_ray_pdf) = bsdf_pdf;
+ INTEGRATOR_STATE_WRITE(state, path, mis_ray_pdf) = mis_pdf;
INTEGRATOR_STATE_WRITE(state, path, mis_origin_n) = sd->N;
INTEGRATOR_STATE_WRITE(state, path, min_ray_pdf) = fminf(
unguided_bsdf_pdf, INTEGRATOR_STATE(state, path, min_ray_pdf));
diff --git a/intern/cycles/kernel/integrator/surface_shader.h b/intern/cycles/kernel/integrator/surface_shader.h
index ebca9810cbe..23e30c3e3f4 100644
--- a/intern/cycles/kernel/integrator/surface_shader.h
+++ b/intern/cycles/kernel/integrator/surface_shader.h
@@ -21,6 +21,8 @@
CCL_NAMESPACE_BEGIN
+//#define RIS_COSINE
+
/* Guiding */
#ifdef __PATH_GUIDING__
@@ -322,12 +324,19 @@ ccl_device_inline
kg, sd, wo, NULL, bsdf_eval, 0.0f, 0.0f, light_shader_flags);
#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4
- if (state->guiding.use_surface_guiding) {
+ if (pdf > 0.f && state->guiding.use_surface_guiding) {
const float guiding_sampling_prob = state->guiding.surface_guiding_sampling_prob;
const float bssrdf_sampling_prob = state->guiding.bssrdf_sampling_prob;
const float guide_pdf = guiding_bsdf_pdf(kg, state, wo);
- pdf = (guiding_sampling_prob * guide_pdf * (1.0f - bssrdf_sampling_prob)) +
- (1.0f - guiding_sampling_prob) * pdf;
+
+ if (kernel_data.integrator.guiding_directional_sampling_type ==
+ GUIDING_DIRECTIONAL_SAMPLING_TYPE_RIS) {
+ pdf = (0.5f * guide_pdf * (1.0f - bssrdf_sampling_prob)) + 0.5f * pdf;
+ }
+ else {
+ pdf = (guiding_sampling_prob * guide_pdf * (1.0f - bssrdf_sampling_prob)) +
+ (1.0f - guiding_sampling_prob) * pdf;
+ }
}
#endif
@@ -403,17 +412,17 @@ surface_shader_bssrdf_sample_weight(ccl_private const ShaderData *ccl_restrict s
/* Sample direction for picked BSDF, and return evaluation and pdf for all
* BSDFs combined using MIS. */
-ccl_device int surface_shader_bsdf_guided_sample_closure(KernelGlobals kg,
- IntegratorState state,
- ccl_private ShaderData *sd,
- ccl_private const ShaderClosure *sc,
- const float2 rand_bsdf,
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list