[Bf-blender-cvs] [4b51c9da580] cycles_path_guiding: Merge branch 'master' into cycles_path_guiding
Brecht Van Lommel
noreply at git.blender.org
Thu Sep 1 19:27:15 CEST 2022
Commit: 4b51c9da5808521d76c4d0f8b142455c016dafad
Author: Brecht Van Lommel
Date: Thu Sep 1 18:23:44 2022 +0200
Branches: cycles_path_guiding
https://developer.blender.org/rB4b51c9da5808521d76c4d0f8b142455c016dafad
Merge branch 'master' into cycles_path_guiding
===================================================================
===================================================================
diff --cc intern/cycles/kernel/integrator/init_from_bake.h
index bca8cf8c33c,9897bc3d65c..d670f7bf331
--- a/intern/cycles/kernel/integrator/init_from_bake.h
+++ b/intern/cycles/kernel/integrator/init_from_bake.h
@@@ -112,8 -112,8 +112,8 @@@ ccl_device bool integrator_init_from_ba
int prim = __float_as_uint(primitive[1]);
if (prim == -1) {
/* Accumulate transparency for empty pixels. */
- kernel_accum_transparent(kg, state, 0, 1.0f, buffer);
+ film_accum_transparent(kg, state, 0, 1.0f, buffer);
- return false;
+ return true;
}
prim += kernel_data.bake.tri_offset;
diff --cc intern/cycles/kernel/integrator/shade_surface.h
index 74bcbcefd92,f3f8ed67713..d85d964d986
--- a/intern/cycles/kernel/integrator/shade_surface.h
+++ b/intern/cycles/kernel/integrator/shade_surface.h
@@@ -384,49 -362,10 +382,47 @@@ ccl_device_forceinline int integrate_su
float3 bsdf_omega_in ccl_optional_struct_init;
int label;
- label = shader_bsdf_sample_closure(kg, sd, sc, rand_bsdf, &bsdf_eval, &bsdf_omega_in, &bsdf_pdf);
+ float2 bsdf_sampled_roughness = make_float2(1.0f, 1.0f);
+ float bsdf_eta = 1.0f;
+
+#if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4
+ if (kernel_data.integrator.use_guiding) {
+ label = shader_guided_bsdf_sample_closure(kg,
+ state,
+ sd,
+ sc,
- bsdf_u,
- bsdf_v,
++ rand_bsdf,
+ &bsdf_eval,
+ &bsdf_omega_in,
+ &guided_bsdf_pdf,
+ &bsdf_pdf,
+ &bsdf_sampled_roughness,
+ &bsdf_eta);
+
+ if (guided_bsdf_pdf == 0.0f || bsdf_eval_is_zero(&bsdf_eval)) {
+ return LABEL_NONE;
+ }
- if (bsdf_pdf == 0.0f || bsdf_eval_is_zero(&bsdf_eval)) {
- return LABEL_NONE;
+ INTEGRATOR_STATE_WRITE(state, path, guiding_throughput) *= guided_bsdf_pdf / bsdf_pdf;
+ }
+ else
+#endif
+ {
+ label = shader_bsdf_sample_closure(kg,
+ sd,
+ sc,
- bsdf_u,
- bsdf_v,
++ rand_bsdf,
+ &bsdf_eval,
+ &bsdf_omega_in,
+ &bsdf_pdf,
+ &bsdf_sampled_roughness,
+ &bsdf_eta);
+
+ if (bsdf_pdf == 0.0f || bsdf_eval_is_zero(&bsdf_eval)) {
+ return LABEL_NONE;
+ }
+
+ guided_bsdf_pdf = bsdf_pdf;
}
if (label & LABEL_TRANSPARENT) {
diff --cc intern/cycles/kernel/integrator/shade_volume.h
index e7bc069b1d8,5e0584d4f98..5bb6bdd394b
--- a/intern/cycles/kernel/integrator/shade_volume.h
+++ b/intern/cycles/kernel/integrator/shade_volume.h
@@@ -711,49 -708,6 +710,49 @@@ ccl_device_forceinline bool integrate_v
return true;
}
+# if defined(__PATH_GUIDING__)
+/* Randomly sample a volume phase function proportional to ShaderClosure.sample_weight. */
+ccl_device_inline ccl_private const ShaderVolumeClosure *shader_volume_phase_pick(
- ccl_private const ShaderVolumePhases *phases, ccl_private float *randu)
++ ccl_private const ShaderVolumePhases *phases, ccl_private float2 *rand_phase)
+{
+ int sampled = 0;
+
+ if (phases->num_closure > 1) {
+ /* pick a phase closure based on sample weights */
+ float sum = 0.0f;
+
+ for (sampled = 0; sampled < phases->num_closure; sampled++) {
+ ccl_private const ShaderVolumeClosure *svc = &phases->closure[sampled];
+ sum += svc->sample_weight;
+ }
+
- float r = (*randu) * sum;
++ float r = (*rand_phase).x * sum;
+ float partial_sum = 0.0f;
+
+ for (sampled = 0; sampled < phases->num_closure; sampled++) {
+ ccl_private const ShaderVolumeClosure *svc = &phases->closure[sampled];
+ float next_sum = partial_sum + svc->sample_weight;
+
+ if (r <= next_sum) {
+ /* Rescale to reuse for volume phase direction sample. */
- *randu = (r - partial_sum) / svc->sample_weight;
++ (*rand_phase).x = (r - partial_sum) / svc->sample_weight;
+ break;
+ }
+
+ partial_sum = next_sum;
+ }
+
+ if (sampled == phases->num_closure) {
+ return NULL;
+ }
+ }
+
+ /* todo: this isn't quite correct, we don't weight anisotropy properly
+ * depending on color channels, even if this is perhaps not a common case */
+ return &phases->closure[sampled];
+}
+# endif
+
/* Path tracing: sample point on light and evaluate light shader, then
* queue shadow ray to be traced. */
ccl_device_forceinline void integrate_volume_direct_light(
@@@ -932,61 -862,18 +930,52 @@@ ccl_device_forceinline bool integrate_v
{
PROFILING_INIT(kg, PROFILING_SHADE_VOLUME_INDIRECT_LIGHT);
- float phase_u, phase_v;
- path_state_rng_2D(kg, rng_state, PRNG_BSDF_U, &phase_u, &phase_v);
- const float2 rand_phase = path_state_rng_2D(kg, rng_state, PRNG_VOLUME_PHASE);
++ float2 rand_phase = path_state_rng_2D(kg, rng_state, PRNG_VOLUME_PHASE);
+
+# if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4
- ccl_private const ShaderVolumeClosure *svc = shader_volume_phase_pick(phases, &phase_u);
++ ccl_private const ShaderVolumeClosure *svc = shader_volume_phase_pick(phases, &rand_phase);
+ if (!svc) {
+ return false;
+ }
+# endif
/* Phase closure, sample direction. */
- float phase_pdf;
+ float phase_pdf = 0.0f, guided_phase_pdf = 0.0f;
BsdfEval phase_eval ccl_optional_struct_init;
float3 phase_omega_in ccl_optional_struct_init;
+ float sampled_roughness = 1.0f;
+ int label;
+
+# if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4
+ if (kernel_data.integrator.use_guiding) {
+ label = shader_guided_volume_phase_sample(kg,
+ state,
+ sd,
+ svc,
- phase_u,
- phase_v,
++ rand_phase,
+ &phase_eval,
+ &phase_omega_in,
+ &guided_phase_pdf,
+ &phase_pdf,
+ &sampled_roughness);
+
+ if (guided_phase_pdf == 0.0f || bsdf_eval_is_zero(&phase_eval)) {
+ return false;
+ }
- const int label = shader_volume_phase_sample(
- kg, sd, phases, rand_phase, &phase_eval, &phase_omega_in, &phase_pdf);
+ INTEGRATOR_STATE_WRITE(state, path, guiding_throughput) *= guided_phase_pdf / phase_pdf;
+ }
+ else
+# endif
+ {
- label = shader_volume_phase_sample(kg,
- sd,
- phases,
- phase_u,
- phase_v,
- &phase_eval,
- &phase_omega_in,
- &phase_pdf,
- &sampled_roughness);
++ label = shader_volume_phase_sample(
++ kg, sd, phases, rand_phase, &phase_eval, &phase_omega_in, &phase_pdf, &sampled_roughness);
- if (phase_pdf == 0.0f || bsdf_eval_is_zero(&phase_eval)) {
- return false;
+ if (phase_pdf == 0.0f || bsdf_eval_is_zero(&phase_eval)) {
+ return false;
+ }
+
+ guided_phase_pdf = phase_pdf;
}
/* Setup ray. */
@@@ -1026,63 -907,6 +1015,63 @@@
return true;
}
+# if defined(__PATH_GUIDING__) && PATH_GUIDING_LEVEL >= 4
+ccl_device_inline void shader_prepare_volume_guiding(KernelGlobals kg,
+ IntegratorState state,
+ ccl_private ShaderData *sd,
+ ccl_private const RNGState *rng_state,
+ const float3 P,
+ const float3 W,
+ ccl_private const ShaderVolumePhases *phases,
+ const VolumeSampleMethod direct_sample_method)
+{
+ const bool guiding = kernel_data.integrator.use_guiding;
+ const bool volume_guiding = kernel_data.integrator.use_volume_guiding;
+ const float volume_guiding_probability = kernel_data.integrator.volume_guiding_probability;
+
+ float guiding_sampling_prob = 0.f;
+
+ float grand = 0.f;
+
+ bool useGuiding = false;
+
+ int num_phases = phases->num_closure;
+
+ if (guiding && volume_guiding && (direct_sample_method == VOLUME_SAMPLE_DISTANCE)) {
+
+ if (num_phases == 1) { // for now we only support a single phase function
+ ccl_private const ShaderVolumeClosure *svc = &phases->closure[0];
+ const float mean_cosine = svc->g;
+
+ // if (fabsf(mean_cosine) < 0.1f ) { // for now we only support HG phase function with very
+ // low anisotropy
+ if (true) {
- grand = path_state_rng_1D_hash(kg, rng_state, 0xa172f2f0);
++ grand = path_state_rng_1D(kg, rng_state, PRNG_VOLUME_PHASE_GUIDING);
+
+ pgl_point3f pgl_P = openpgl::cpp::Point3(P[0], P[1], P[2]);
+ pgl_point3f pgl_W = openpgl::cpp::Vector3(W[0], W[1], W[2]);
+
+ useGuiding = state->guiding.volume_sampling_distribution->Init(
+ kg->opgl_guiding_field, pgl_P,
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list