[Bf-blender-cvs] [04420728155] cycles-x: Cleanup: minor renaming and adding const qualifiers

Brecht Van Lommel noreply at git.blender.org
Fri Jul 9 16:17:42 CEST 2021


Commit: 044207281559d54b6fa8c41389bcd465515b1f26
Author: Brecht Van Lommel
Date:   Wed Jul 7 20:53:24 2021 +0200
Branches: cycles-x
https://developer.blender.org/rB044207281559d54b6fa8c41389bcd465515b1f26

Cleanup: minor renaming and adding const qualifiers

===================================================================

M	intern/cycles/kernel/integrator/integrator_shade_volume.h
M	intern/cycles/kernel/integrator/integrator_volume_stack.h

===================================================================

diff --git a/intern/cycles/kernel/integrator/integrator_shade_volume.h b/intern/cycles/kernel/integrator/integrator_shade_volume.h
index 76eaa67003d..35cc480d50a 100644
--- a/intern/cycles/kernel/integrator/integrator_shade_volume.h
+++ b/intern/cycles/kernel/integrator/integrator_shade_volume.h
@@ -25,11 +25,11 @@ CCL_NAMESPACE_BEGIN
 
 /* Events for probalistic scattering */
 
-typedef enum VolumeIntegrateResult {
+typedef enum VolumeIntegrateEvent {
   VOLUME_PATH_SCATTERED = 0,
   VOLUME_PATH_ATTENUATED = 1,
   VOLUME_PATH_MISSED = 2
-} VolumeIntegrateResult;
+} VolumeIntegrateEvent;
 
 /* Ignore paths that have volume throughput below this value, to avoid unnecessary work
  * and precision issues.
@@ -236,19 +236,21 @@ ccl_device void volume_shadow_heterogeneous(INTEGRATOR_STATE_ARGS,
 /* Equi-angular sampling as in:
  * "Importance Sampling Techniques for Path Tracing in Participating Media" */
 
-ccl_device float volume_equiangular_sample(Ray *ray, float3 light_P, float xi, float *pdf)
+ccl_device float volume_equiangular_sample(const Ray *ccl_restrict ray,
+                                           const float3 light_P,
+                                           const float xi,
+                                           float *pdf)
 {
-  float t = ray->t;
-
-  float delta = dot((light_P - ray->P), ray->D);
-  float D = safe_sqrtf(len_squared(light_P - ray->P) - delta * delta);
+  const float t = ray->t;
+  const float delta = dot((light_P - ray->P), ray->D);
+  const float D = safe_sqrtf(len_squared(light_P - ray->P) - delta * delta);
   if (UNLIKELY(D == 0.0f)) {
     *pdf = 0.0f;
     return 0.0f;
   }
-  float theta_a = -atan2f(delta, D);
-  float theta_b = atan2f(t - delta, D);
-  float t_ = D * tanf((xi * theta_b) + (1 - xi) * theta_a);
+  const float theta_a = -atan2f(delta, D);
+  const float theta_b = atan2f(t - delta, D);
+  const float t_ = D * tanf((xi * theta_b) + (1 - xi) * theta_a);
   if (UNLIKELY(theta_b == theta_a)) {
     *pdf = 0.0f;
     return 0.0f;
@@ -258,7 +260,33 @@ ccl_device float volume_equiangular_sample(Ray *ray, float3 light_P, float xi, f
   return min(t, delta + t_); /* min is only for float precision errors */
 }
 
-ccl_device float volume_equiangular_pdf(Ray *ray, float3 light_P, float sample_t)
+ccl_device float volume_equiangular_pdf(const Ray *ccl_restrict ray,
+                                        const float3 light_P,
+                                        const float sample_t)
+{
+  const float delta = dot((light_P - ray->P), ray->D);
+  const float D = safe_sqrtf(len_squared(light_P - ray->P) - delta * delta);
+  if (UNLIKELY(D == 0.0f)) {
+    return 0.0f;
+  }
+
+  const float t = ray->t;
+  const float t_ = sample_t - delta;
+
+  const float theta_a = -atan2f(delta, D);
+  const float theta_b = atan2f(t - delta, D);
+  if (UNLIKELY(theta_b == theta_a)) {
+    return 0.0f;
+  }
+
+  const float pdf = D / ((theta_b - theta_a) * (D * D + t_ * t_));
+
+  return pdf;
+}
+
+ccl_device float volume_equiangular_cdf(const Ray *ccl_restrict ray,
+                                        const float3 light_P,
+                                        const float sample_t)
 {
   float delta = dot((light_P - ray->P), ray->D);
   float D = safe_sqrtf(len_squared(light_P - ray->P) - delta * delta);
@@ -266,18 +294,19 @@ ccl_device float volume_equiangular_pdf(Ray *ray, float3 light_P, float sample_t
     return 0.0f;
   }
 
-  float t = ray->t;
-  float t_ = sample_t - delta;
+  const float t = ray->t;
+  const float t_ = sample_t - delta;
 
-  float theta_a = -atan2f(delta, D);
-  float theta_b = atan2f(t - delta, D);
+  const float theta_a = -atan2f(delta, D);
+  const float theta_b = atan2f(t - delta, D);
   if (UNLIKELY(theta_b == theta_a)) {
     return 0.0f;
   }
 
-  float pdf = D / ((theta_b - theta_a) * (D * D + t_ * t_));
+  const float theta_sample = atan2f(t_, D);
+  const float cdf = (theta_sample - theta_a) / (theta_b - theta_a);
 
-  return pdf;
+  return cdf;
 }
 
 /* Distance sampling */
@@ -342,7 +371,7 @@ ccl_device float3 volume_emission_integrate(VolumeShaderCoefficients *coeff,
 #  if 0
 /* homogeneous volume: assume shader evaluation at the start gives
  * the volume shading coefficient for the entire line segment */
-ccl_device VolumeIntegrateResult
+ccl_device VolumeIntegrateEvent
 volume_integrate_homogeneous(INTEGRATOR_STATE_ARGS,
                              Ray *ccl_restrict ray,
                              ShaderData *ccl_restrict sd,
@@ -452,7 +481,7 @@ volume_integrate_homogeneous(INTEGRATOR_STATE_ARGS,
  * volume until we reach the end, get absorbed entirely, or run out of
  * iterations. this does probabilistically scatter or get transmitted through
  * for path tracing where we don't want to branch. */
-ccl_device VolumeIntegrateResult
+ccl_device VolumeIntegrateEvent
 volume_integrate_heterogeneous(INTEGRATOR_STATE_ARGS,
                                Ray *ccl_restrict ray,
                                ShaderData *ccl_restrict sd,
@@ -483,7 +512,7 @@ volume_integrate_heterogeneous(INTEGRATOR_STATE_ARGS,
   /* pick random color channel, we use the Veach one-sample
    * model with balance heuristic for the channels */
   float xi = path_state_rng_1D(kg, rng_state, PRNG_SCATTER_DISTANCE);
-  float rphase = path_state_rng_1D(kg, rng_state, PRNG_PHASE_CHANNEL);
+  const float rphase = path_state_rng_1D(kg, rng_state, PRNG_PHASE_CHANNEL);
   bool has_scatter = false;
 
   for (int i = 0; i < max_steps; i++) {
@@ -508,25 +537,25 @@ volume_integrate_heterogeneous(INTEGRATOR_STATE_ARGS,
         has_scatter = true;
 
         /* Sample channel, use MIS with balance heuristic. */
-        float3 albedo = safe_divide_color(coeff.sigma_s, coeff.sigma_t);
+        const float3 albedo = safe_divide_color(coeff.sigma_s, coeff.sigma_t);
         float3 channel_pdf;
-        int channel = volume_sample_channel(albedo, tp, rphase, &channel_pdf);
+        const int channel = volume_sample_channel(albedo, tp, rphase, &channel_pdf);
 
         /* compute transmittance over full step */
         transmittance = volume_color_transmittance(coeff.sigma_t, dt);
 
         /* decide if we will scatter or continue */
-        float sample_transmittance = volume_channel_get(transmittance, channel);
+        const float sample_transmittance = volume_channel_get(transmittance, channel);
 
         if (1.0f - xi >= sample_transmittance) {
           /* compute sampling distance */
-          float sample_sigma_t = volume_channel_get(coeff.sigma_t, channel);
-          float new_dt = -logf(1.0f - xi) / sample_sigma_t;
+          const float sample_sigma_t = volume_channel_get(coeff.sigma_t, channel);
+          const float new_dt = -logf(1.0f - xi) / sample_sigma_t;
           new_t = t + new_dt;
 
           /* transmittance and pdf */
-          float3 new_transmittance = volume_color_transmittance(coeff.sigma_t, new_dt);
-          float3 pdf = coeff.sigma_t * new_transmittance;
+          const float3 new_transmittance = volume_color_transmittance(coeff.sigma_t, new_dt);
+          const float3 pdf = coeff.sigma_t * new_transmittance;
 
           /* throughput */
           new_tp = tp * coeff.sigma_s * new_transmittance / dot(channel_pdf, pdf);
@@ -534,7 +563,7 @@ volume_integrate_heterogeneous(INTEGRATOR_STATE_ARGS,
         }
         else {
           /* throughput */
-          float pdf = dot(channel_pdf, transmittance);
+          const float pdf = dot(channel_pdf, transmittance);
           new_tp = tp * transmittance / pdf;
 
           /* remap xi so we can reuse it and keep thing stratified */
@@ -555,7 +584,7 @@ volume_integrate_heterogeneous(INTEGRATOR_STATE_ARGS,
 
       /* integrate emission attenuated by absorption */
       if (closure_flag & SD_EMISSION) {
-        float3 emission = volume_emission_integrate(&coeff, closure_flag, transmittance, dt);
+        const float3 emission = volume_emission_integrate(&coeff, closure_flag, transmittance, dt);
         kernel_accum_emission(INTEGRATOR_STATE_PASS, tp, emission, render_buffer);
       }
 
@@ -735,9 +764,9 @@ ccl_device_forceinline bool integrate_volume_phase_scatter(INTEGRATOR_STATE_ARGS
  * ray, with the assumption that there are no surfaces blocking light
  * between the endpoints. distance sampling is used to decide if we will
  * scatter or not. */
-ccl_device VolumeIntegrateResult volume_integrate(INTEGRATOR_STATE_ARGS,
-                                                  Ray *ccl_restrict ray,
-                                                  ccl_global float *ccl_restrict render_buffer)
+ccl_device VolumeIntegrateEvent volume_integrate(INTEGRATOR_STATE_ARGS,
+                                                 Ray *ccl_restrict ray,
+                                                 ccl_global float *ccl_restrict render_buffer)
 {
   ShaderData sd;
   shader_setup_from_volume(kg, &sd, ray);
@@ -752,7 +781,7 @@ ccl_device VolumeIntegrateResult volume_integrate(INTEGRATOR_STATE_ARGS,
     return integrator_state_read_volume_stack(INTEGRATOR_STATE_PASS, i);
   });
 
-  VolumeIntegrateResult result = volume_integrate_heterogeneous(
+  VolumeIntegrateEvent event = volume_integrate_heterogeneous(
       INTEGRATOR_STATE_PASS, ray, &sd, &throughput, &rng_state, render_buffer, step_size);
 
   /* Perform path termination. The intersect_closest will have already marked this path
@@ -766,7 +795,7 @@ ccl_device VolumeIntegrateResult volume_integrate(INTEGRATOR_STATE_ARGS,
   if (probability == 0.0f) {
     return VOLUME_PATH_MISSED;
   }
-  else if (result == VOLUME_PATH_SCATTERED) {
+  else if (event == VOLUME_PATH_SCATTERED) {
     /* Only divide throughput by probability if we scatter. For the attenuation
      * case the next surface will already do this division. */
     if (probability != 1.0f) {
@@ -776,7 +805,7 @@ ccl_device VolumeIntegrateResult volume_integrate(INTEGRATOR_STATE_ARGS,
 
   INTEGRATOR_STATE_WRITE(path, throughput) = throughput;
 
-  if (result == VOLUME_PATH_SCATTERED) {
+  if (event == VOLUME_PATH_SCATTERED) {
     /* Direct light. */
     integrate_volume_direct_light(INTEGRATOR_STATE_PASS, &sd, &rng_state);
 
@@ -786,7 +815,7 @@ ccl_device VolumeIntegrateResult volume_integrate(INTEGRATOR_STATE_

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list