Commit: 7ae7446f4a4f98ba52bbe8fb35480d017e7b04b8 Author: Sebastian Herholz Date: Mon Feb 6 12:38:15 2023 +0100 Branches: cycles_path_guiding https://developer.blender.org/rB7ae7446f4a4f98ba52bbe8fb35480d017e7b04b8
Guiding: Adding roughness threshold parameter and preparing for Open PGL 0.5 =================================================================== M intern/cycles/blender/addon/properties.py M intern/cycles/blender/addon/ui.py M intern/cycles/blender/sync.cpp M intern/cycles/integrator/guiding.h M intern/cycles/integrator/path_trace_work_cpu.cpp M intern/cycles/kernel/data_template.h M intern/cycles/kernel/integrator/guiding.h M intern/cycles/kernel/integrator/surface_shader.h M intern/cycles/scene/integrator.cpp M intern/cycles/scene/integrator.h =================================================================== diff --git a/intern/cycles/blender/addon/properties.py b/intern/cycles/blender/addon/properties.py index e0d7e1028de..93998416a96 100644 --- a/intern/cycles/blender/addon/properties.py +++ b/intern/cycles/blender/addon/properties.py @@ -638,6 +638,13 @@ class CyclesRenderSettings(bpy.types.PropertyGroup): default=True, ) + guiding_roughness_threshold: FloatProperty( + name="Guiding Roughness Threshold", + description="The minimal roughness value of a material to apply guiding", + min=0.0, max=1.0, + default=0.05, + ) + max_bounces: IntProperty( name="Max Bounces", description="Total maximum number of bounces", diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py index b75e2a0cc1b..2d262e48280 100644 --- a/intern/cycles/blender/addon/ui.py +++ b/intern/cycles/blender/addon/ui.py @@ -338,6 +338,7 @@ class CYCLES_RENDER_PT_sampling_path_guiding_debug(CyclesDebugButtonsPanel, Pane layout.active = cscene.use_guiding layout.prop(cscene, "guiding_distribution_type", text="Distribution Type") + layout.prop(cscene, "guiding_roughness_threshold") col = layout.column(align=True) col.prop(cscene, "surface_guiding_probability") diff --git a/intern/cycles/blender/sync.cpp b/intern/cycles/blender/sync.cpp index 37e1cd55c46..ec7f3092216 100644 --- a/intern/cycles/blender/sync.cpp +++ b/intern/cycles/blender/sync.cpp @@ -447,6 +447,7 @@ void BlenderSync::sync_integrator(BL::ViewLayer &b_view_layer, bool background) GUIDING_DIRECTIONAL_SAMPLING_NUM_TYPES, GUIDING_DIRECTIONAL_SAMPLING_TYPE_PRODUCT); integrator->set_guiding_directional_sampling_type(guiding_directional_sampling_type); + integrator->set_guiding_roughness_threshold(get_float(cscene, "guiding_roughness_threshold")); } DenoiseParams denoise_params = get_denoise_params(b_scene, b_view_layer, background); diff --git a/intern/cycles/integrator/guiding.h b/intern/cycles/integrator/guiding.h index 8aa61e3371d..15c8061dbc4 100644 --- a/intern/cycles/integrator/guiding.h +++ b/intern/cycles/integrator/guiding.h @@ -16,6 +16,7 @@ struct GuidingParams { GuidingDistributionType type = GUIDING_TYPE_PARALLAX_AWARE_VMM; GuidingDirectionalSamplingType sampling_type = GUIDING_DIRECTIONAL_SAMPLING_TYPE_PRODUCT; + float roughness_threshold = 0.05f; int training_samples = 128; bool deterministic = false; @@ -27,6 +28,7 @@ struct GuidingParams { (use_volume_guiding == other.use_volume_guiding) && (type == other.type) && (sampling_type == other.sampling_type) && (training_samples == other.training_samples) && + (roughness_threshold == other.roughness_threshold) && (deterministic == other.deterministic)); } }; diff --git a/intern/cycles/integrator/path_trace_work_cpu.cpp b/intern/cycles/integrator/path_trace_work_cpu.cpp index 188ec28cf65..9e612bc60a0 100644 --- a/intern/cycles/integrator/path_trace_work_cpu.cpp +++ b/intern/cycles/integrator/path_trace_work_cpu.cpp @@ -359,8 +359,13 @@ void PathTraceWorkCPU::guiding_push_sample_data_to_global_storage( # if PATH_GUIDING_LEVEL >= 2 const bool use_direct_light = kernel_data.integrator.use_guiding_direct_light; const bool use_mis_weights = kernel_data.integrator.use_guiding_mis_weights; +# if OPENPGL_VERSION_MINOR >= 5 + kg->opgl_path_segment_storage->PrepareSamples( + use_mis_weights, use_direct_light, false); +#else kg->opgl_path_segment_storage->PrepareSamples( false, nullptr, use_mis_weights, use_direct_light, false); +#endif # endif # ifdef WITH_CYCLES_DEBUG diff --git a/intern/cycles/kernel/data_template.h b/intern/cycles/kernel/data_template.h index 29bb98c99b6..16ac5c38e40 100644 --- a/intern/cycles/kernel/data_template.h +++ b/intern/cycles/kernel/data_template.h @@ -203,6 +203,7 @@ KERNEL_STRUCT_MEMBER(integrator, float, surface_guiding_probability) KERNEL_STRUCT_MEMBER(integrator, float, volume_guiding_probability) KERNEL_STRUCT_MEMBER(integrator, int, guiding_distribution_type) KERNEL_STRUCT_MEMBER(integrator, int, guiding_directional_sampling_type) +KERNEL_STRUCT_MEMBER(integrator, float, guiding_roughness_threshold) KERNEL_STRUCT_MEMBER(integrator, int, use_guiding) KERNEL_STRUCT_MEMBER(integrator, int, train_guiding) KERNEL_STRUCT_MEMBER(integrator, int, use_surface_guiding) @@ -211,7 +212,9 @@ 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_MEMBER(integrator, int, pad2) +KERNEL_STRUCT_MEMBER(integrator, int, pad3) KERNEL_STRUCT_END(KernelIntegrator) /* SVM. For shader specialization. */ diff --git a/intern/cycles/kernel/integrator/guiding.h b/intern/cycles/kernel/integrator/guiding.h index 93c80539140..c1384da0158 100644 --- a/intern/cycles/kernel/integrator/guiding.h +++ b/intern/cycles/kernel/integrator/guiding.h @@ -7,6 +7,8 @@ #include "kernel/closure/bsdf.h" #include "kernel/film/write.h" +#include <iostream> + CCL_NAMESPACE_BEGIN /* Utilities. */ @@ -454,11 +456,19 @@ ccl_device_forceinline bool guiding_bsdf_init(KernelGlobals kg, ccl_private float &rand) { #if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4 +# if OPENPGL_VERSION_MINOR >= 5 + if (kg->opgl_surface_sampling_distribution->Init( + kg->opgl_guiding_field, guiding_point3f(P), rand)) { + kg->opgl_surface_sampling_distribution->ApplyCosineProduct(guiding_point3f(N)); + return true; + } +#else if (kg->opgl_surface_sampling_distribution->Init( kg->opgl_guiding_field, guiding_point3f(P), rand, true)) { kg->opgl_surface_sampling_distribution->ApplyCosineProduct(guiding_point3f(N)); return true; } +#endif #endif return false; @@ -491,6 +501,17 @@ ccl_device_forceinline float guiding_bsdf_pdf(KernelGlobals kg, #endif } +ccl_device_forceinline float guiding_surface_incomming_radiance_pdf(KernelGlobals kg, + IntegratorState state, + const float3 wo) +{ +#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4 && OPENPGL_VERSION_MINOR >= 5 + return kg->opgl_surface_sampling_distribution->IncommingRadiancePDF(guiding_vec3f(wo)); +#else + return 0.0f; +#endif +} + /* Guided Volume Phases */ ccl_device_forceinline bool guiding_phase_init(KernelGlobals kg, @@ -505,13 +526,21 @@ ccl_device_forceinline bool guiding_phase_init(KernelGlobals kg, if (fabsf(g) >= 0.99f) { return false; } - +# if OPENPGL_VERSION_MINOR >= 5 + if (kg->opgl_volume_sampling_distribution->Init( + kg->opgl_guiding_field, guiding_point3f(P), rand)) { + kg->opgl_volume_sampling_distribution->ApplySingleLobeHenyeyGreensteinProduct(guiding_vec3f(D), + g); + return true; + } +#else if (kg->opgl_volume_sampling_distribution->Init( kg->opgl_guiding_field, guiding_point3f(P), rand, true)) { kg->opgl_volume_sampling_distribution->ApplySingleLobeHenyeyGreensteinProduct(guiding_vec3f(D), g); return true; } +#endif #endif return false; diff --git a/intern/cycles/kernel/integrator/surface_shader.h b/intern/cycles/kernel/integrator/surface_shader.h index 60eaed2c4ee..b0e065bacd0 100644 --- a/intern/cycles/kernel/integrator/surface_shader.h +++ b/intern/cycles/kernel/integrator/surface_shader.h @@ -22,7 +22,9 @@ CCL_NAMESPACE_BEGIN #define RIS_COSINE - +# if OPENPGL_VERSION_MINOR >= 5 +#define RIS_INCOMMING_RADIANCE +#endif /* Guiding */ #ifdef __PATH_GUIDING__ @@ -58,6 +60,7 @@ ccl_device_inline void surface_shader_prepare_guiding(KernelGlobals kg, const float surface_guiding_probability = kernel_data.integrator.surface_guiding_probability; const int guiding_directional_sampling_type = kernel_data.integrator.guiding_directional_sampling_type; + const float guiding_roughness_threshold = kernel_data.integrator.guiding_roughness_threshold; float rand_bsdf_guiding = path_state_rng_1D(kg, rng_state, PRNG_SURFACE_BSDF_GUIDING); /* Compute proportion of diffuse BSDF and BSSRDFs .*/ @@ -93,9 +96,9 @@ ccl_device_inline void surface_shader_prepare_guiding(KernelGlobals kg, } float avg_roughness = surface_shader_average_sample_weight_squared_roughness(sd); - + avg_roughness = safe_sqrtf(avg_roughness); /* Init guiding (diffuse BSDFs only for now). */ - if (!fully_opaque || avg_roughness <= 0.05f || + if (!fully_opaque || avg_roughness < guiding_roughness_threshold*guiding_roughness_threshold || ((guiding_directional_sampling_type == GUIDING_DIRECTIONAL_SAMPLING_TYPE_PRODUCT) && (diffuse_sampling_fraction <= 0.f)) || !guiding_bsdf_init(kg, state, sd->P, sd->N, rand_bsdf_guiding)) { @@ -620,6 +623,9 @@ ccl_device int surface_shader_bsdf_guided_sample_closure_ris(KernelGlobals kg, float3 omega_in_ris[2]; float ris_pdfs[2] = {0.f, 0.f}; float guide_pdfs[2] = {0.f, 0.f}; +#ifdef RIS_INCOMMING_RADIANCE + float incomming_radiance_pdfs[2] = {0.f, 0.f}; +#endif float bsdf_pdfs[2] = {0.f, 0.f}; float cosines[2] = {0.f, 0.f}; BsdfEval bsdf_evals[2]; @@ -653,6 +659,9 @@ ccl_device int surface_shader_bsdf_guided_sample_closure_ris(KernelGlobals kg, 3.0f; guide_pdfs[0] = guiding_bsdf_pdf(kg, state, omega_in_ris[0]); guide_pdfs[0] *= (1.0f - bssrdf_sampling_prob); +#ifdef RIS_INCOMMING_RADIANCE + incomming_radiance_pdfs[0] = guiding_surface_incomming_radiance_pdf(kg, state, omega_in_ris[0]); +#endif bsdf_pdfs[0] = max(0.f, bsdf_pdfs[0]); } @@ -661,6 +670,9 @@ ccl_device int surface_shader_bsdf_guided_sample_closure_ris(KernelGlobals kg, bsdf_eval_init(&bsdf_evals[1], CLOSURE_NONE_ID, eval); @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs