[Bf-blender-cvs] [05bdef7ce64] master: Fix T103094: Cycles ignores small suns in Nishita sky

Jeffrey Liu noreply at git.blender.org
Fri Jan 20 01:33:25 CET 2023


Commit: 05bdef7ce64fe3125b95d72d80f1f4f60c2b1274
Author: Jeffrey Liu
Date:   Thu Jan 19 18:22:47 2023 -0600
Branches: master
https://developer.blender.org/rB05bdef7ce64fe3125b95d72d80f1f4f60c2b1274

Fix T103094: Cycles ignores small suns in Nishita sky

The background evaluation samples the sky discretely, so if the sun is
too small, it can be missed in the evaluation. To solve this, the sun is
ignored during the background evaluation and its contribution is
computed separately.

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

M	intern/cycles/kernel/bake/bake.h
M	intern/cycles/kernel/integrator/shade_surface.h
M	intern/cycles/kernel/integrator/shade_volume.h
M	intern/cycles/kernel/osl/shaders/node_sky_texture.osl
M	intern/cycles/kernel/svm/sky.h
M	intern/cycles/kernel/svm/svm.h
M	intern/cycles/kernel/types.h
M	intern/cycles/scene/light.cpp
M	intern/cycles/scene/osl.cpp
M	intern/cycles/scene/shader_nodes.cpp
M	intern/cycles/scene/shader_nodes.h
M	release/scripts/addons

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

diff --git a/intern/cycles/kernel/bake/bake.h b/intern/cycles/kernel/bake/bake.h
index 384ca9168f0..899aa783289 100644
--- a/intern/cycles/kernel/bake/bake.h
+++ b/intern/cycles/kernel/bake/bake.h
@@ -63,8 +63,9 @@ ccl_device void kernel_background_evaluate(KernelGlobals kg,
   shader_setup_from_background(kg, &sd, ray_P, ray_D, ray_time);
 
   /* Evaluate shader.
-   * This is being evaluated for all BSDFs, so path flag does not contain a specific type. */
-  const uint32_t path_flag = PATH_RAY_EMISSION;
+   * This is being evaluated for all BSDFs, so path flag does not contain a specific type.
+   * However, we want to flag the ray visibility to ignore the sun in the background map. */
+  const uint32_t path_flag = PATH_RAY_EMISSION | PATH_RAY_IMPORTANCE_BAKE;
   surface_shader_eval<KERNEL_FEATURE_NODE_MASK_SURFACE_LIGHT &
                       ~(KERNEL_FEATURE_NODE_RAYTRACE | KERNEL_FEATURE_NODE_LIGHT_PATH)>(
       kg, INTEGRATOR_STATE_NULL, &sd, NULL, path_flag);
diff --git a/intern/cycles/kernel/integrator/shade_surface.h b/intern/cycles/kernel/integrator/shade_surface.h
index 21a6f2d4e36..09433caa063 100644
--- a/intern/cycles/kernel/integrator/shade_surface.h
+++ b/intern/cycles/kernel/integrator/shade_surface.h
@@ -264,7 +264,6 @@ ccl_device_forceinline void integrate_surface_direct_light(KernelGlobals kg,
 
   /* Copy state from main path to shadow path. */
   uint32_t shadow_flag = INTEGRATOR_STATE(state, path, flag);
-  shadow_flag |= (is_light) ? PATH_RAY_SHADOW_FOR_LIGHT : 0;
   const Spectrum unlit_throughput = INTEGRATOR_STATE(state, path, throughput);
   const Spectrum throughput = unlit_throughput * bsdf_eval_sum(&bsdf_eval);
 
diff --git a/intern/cycles/kernel/integrator/shade_volume.h b/intern/cycles/kernel/integrator/shade_volume.h
index 75962ce5499..98dc5603a78 100644
--- a/intern/cycles/kernel/integrator/shade_volume.h
+++ b/intern/cycles/kernel/integrator/shade_volume.h
@@ -838,7 +838,6 @@ ccl_device_forceinline void integrate_volume_direct_light(
   const uint16_t bounce = INTEGRATOR_STATE(state, path, bounce);
   const uint16_t transparent_bounce = INTEGRATOR_STATE(state, path, transparent_bounce);
   uint32_t shadow_flag = INTEGRATOR_STATE(state, path, flag);
-  shadow_flag |= (is_light) ? PATH_RAY_SHADOW_FOR_LIGHT : 0;
   const Spectrum throughput_phase = throughput * bsdf_eval_sum(&phase_eval);
 
   if (kernel_data.kernel_features & KERNEL_FEATURE_LIGHT_PASSES) {
diff --git a/intern/cycles/kernel/osl/shaders/node_sky_texture.osl b/intern/cycles/kernel/osl/shaders/node_sky_texture.osl
index 1373db04a31..763f73a35d7 100644
--- a/intern/cycles/kernel/osl/shaders/node_sky_texture.osl
+++ b/intern/cycles/kernel/osl/shaders/node_sky_texture.osl
@@ -135,8 +135,9 @@ color sky_radiance_nishita(vector dir, float nishita_data[10], string filename)
     float half_angular = angular_diameter / 2.0;
     float dir_elevation = M_PI_2 - direction[0];
 
-    /* if ray inside sun disc render it, otherwise render sky */
-    if (sun_dir_angle < half_angular && sun_disc == 1) {
+    /* if ray inside sun disc render it, otherwise render sky.
+     * alternatively, ignore the sun if we're evaluating the background texture. */
+    if (sun_dir_angle < half_angular && sun_disc == 1 && raytype("importance_bake") != 1) {
       /* get 2 pixels data */
       color pixel_bottom = color(nishita_data[0], nishita_data[1], nishita_data[2]);
       color pixel_top = color(nishita_data[3], nishita_data[4], nishita_data[5]);
diff --git a/intern/cycles/kernel/svm/sky.h b/intern/cycles/kernel/svm/sky.h
index 1638e783a69..92b292d660d 100644
--- a/intern/cycles/kernel/svm/sky.h
+++ b/intern/cycles/kernel/svm/sky.h
@@ -118,6 +118,7 @@ ccl_device float3 geographical_to_direction(float lat, float lon)
 
 ccl_device float3 sky_radiance_nishita(KernelGlobals kg,
                                        float3 dir,
+                                       uint32_t path_flag,
                                        float3 pixel_bottom,
                                        float3 pixel_top,
                                        ccl_private float *nishita_data,
@@ -140,8 +141,9 @@ ccl_device float3 sky_radiance_nishita(KernelGlobals kg,
     float half_angular = angular_diameter / 2.0f;
     float dir_elevation = M_PI_2_F - direction.x;
 
-    /* if ray inside sun disc render it, otherwise render sky */
-    if (sun_disc && sun_dir_angle < half_angular) {
+    /* if ray inside sun disc render it, otherwise render sky.
+     * alternatively, ignore the sun if we're evaluating the background texture. */
+    if (sun_disc && sun_dir_angle < half_angular && !(path_flag & PATH_RAY_IMPORTANCE_BAKE)) {
       /* get 2 pixels data */
       float y;
 
@@ -197,8 +199,12 @@ ccl_device float3 sky_radiance_nishita(KernelGlobals kg,
   return xyz_to_rgb_clamped(kg, xyz);
 }
 
-ccl_device_noinline int svm_node_tex_sky(
-    KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, uint4 node, int offset)
+ccl_device_noinline int svm_node_tex_sky(KernelGlobals kg,
+                                         ccl_private ShaderData *sd,
+                                         uint32_t path_flag,
+                                         ccl_private float *stack,
+                                         uint4 node,
+                                         int offset)
 {
   /* Load data */
   uint dir_offset = node.y;
@@ -310,7 +316,8 @@ ccl_device_noinline int svm_node_tex_sky(
     uint texture_id = __float_as_uint(data.z);
 
     /* Compute Sky */
-    f = sky_radiance_nishita(kg, dir, pixel_bottom, pixel_top, nishita_data, texture_id);
+    f = sky_radiance_nishita(
+        kg, dir, path_flag, pixel_bottom, pixel_top, nishita_data, texture_id);
   }
 
   stack_store_float3(stack, out_offset, f);
diff --git a/intern/cycles/kernel/svm/svm.h b/intern/cycles/kernel/svm/svm.h
index 3ca632c5f0b..96b2b82d8af 100644
--- a/intern/cycles/kernel/svm/svm.h
+++ b/intern/cycles/kernel/svm/svm.h
@@ -463,7 +463,7 @@ ccl_device void svm_eval_nodes(KernelGlobals kg,
       svm_node_tex_environment(kg, sd, stack, node);
       break;
       SVM_CASE(NODE_TEX_SKY)
-      offset = svm_node_tex_sky(kg, sd, stack, node, offset);
+      offset = svm_node_tex_sky(kg, sd, path_flag, stack, node, offset);
       break;
       SVM_CASE(NODE_TEX_GRADIENT)
       svm_node_tex_gradient(sd, stack, node);
diff --git a/intern/cycles/kernel/types.h b/intern/cycles/kernel/types.h
index 4075980076f..4fad62d757d 100644
--- a/intern/cycles/kernel/types.h
+++ b/intern/cycles/kernel/types.h
@@ -206,23 +206,24 @@ enum PathRayFlag : uint32_t {
   PATH_RAY_SINGULAR = (1U << 5U),
   PATH_RAY_TRANSPARENT = (1U << 6U),
   PATH_RAY_VOLUME_SCATTER = (1U << 7U),
+  PATH_RAY_IMPORTANCE_BAKE = (1U << 8U),
 
   /* Shadow ray visibility. */
-  PATH_RAY_SHADOW_OPAQUE = (1U << 8U),
-  PATH_RAY_SHADOW_TRANSPARENT = (1U << 9U),
+  PATH_RAY_SHADOW_OPAQUE = (1U << 9U),
+  PATH_RAY_SHADOW_TRANSPARENT = (1U << 10U),
   PATH_RAY_SHADOW = (PATH_RAY_SHADOW_OPAQUE | PATH_RAY_SHADOW_TRANSPARENT),
 
   /* Subset of flags used for ray visibility for intersection.
    *
    * NOTE: SHADOW_CATCHER macros below assume there are no more than
    * 16 visibility bits. */
-  PATH_RAY_ALL_VISIBILITY = ((1U << 10U) - 1U),
+  PATH_RAY_ALL_VISIBILITY = ((1U << 11U) - 1U),
 
   /* Special flag to tag unaligned BVH nodes.
    * Only set and used in BVH nodes to distinguish how to interpret bounding box information stored
    * in the node (either it should be intersected as AABB or as OBBU).
    * So this can overlap with path flags. */
-  PATH_RAY_NODE_UNALIGNED = (1U << 10U),
+  PATH_RAY_NODE_UNALIGNED = (1U << 11U),
 
   /* --------------------------------------------------------------------
    * Path flags.
@@ -230,60 +231,59 @@ enum PathRayFlag : uint32_t {
 
   /* Surface had transmission component at previous bounce. Used for light tree
    * traversal and culling to be consistent with MIS PDF at the next bounce. */
-  PATH_RAY_MIS_HAD_TRANSMISSION = (1U << 10U),
+  PATH_RAY_MIS_HAD_TRANSMISSION = (1U << 11U),
 
   /* Don't apply multiple importance sampling weights to emission from
    * lamp or surface hits, because they were not direct light sampled. */
-  PATH_RAY_MIS_SKIP = (1U << 11U),
+  PATH_RAY_MIS_SKIP = (1U << 12U),
 
   /* Diffuse bounce earlier in the path, skip SSS to improve performance
    * and avoid branching twice with disk sampling SSS. */
-  PATH_RAY_DIFFUSE_ANCESTOR = (1U << 12U),
+  PATH_RAY_DIFFUSE_ANCESTOR = (1U << 13U),
 
   /* Single pass has been written. */
-  PATH_RAY_SINGLE_PASS_DONE = (1U << 13U),
+  PATH_RAY_SINGLE_PASS_DONE = (1U << 14U),
 
   /* Zero background alpha, for camera or transparent glass rays. */
-  PATH_RAY_TRANSPARENT_BACKGROUND = (1U << 14U),
+  PATH_RAY_TRANSPARENT_BACKGROUND = (1U << 15U),
 
   /* Terminate ray immediately at next bounce. */
-  PATH_RAY_TERMINATE_ON_NEXT_SURFACE = (1U << 15U),
-  PATH_RAY_TERMINATE_IN_NEXT_VOLUME = (1U << 16U),
+  PATH_RAY_TERMINATE_ON_NEXT_SURFACE = (1U << 16U),
+  PATH_RAY_TERMINATE_IN_NEXT_VOLUME = (1U << 17U),
 
   /* Ray is to be terminated, but continue with transparent bounces and
    * emission as long as we encounter them. This is required to make the
    * MIS between direct and indirect light rays match, as shadow rays go
    * through transparent surfaces to reach emission too. */
-  PATH_RAY_TERMINATE_AFTER_TRANSPARENT = (1U << 17U),
+  PATH_RAY_TERMINATE_AFTER_TRANSPARENT = (1U << 18U),
 
   /* Terminate ray immediately after volume shading. */
-  PATH_RAY_TERMINATE_AFTER_VOLUME = (1U << 18U),
+  PATH_RAY_TERMINATE_AFTER_VOLUME = (1U << 19U),
 
   /* Ray is to be terminated. */
   PATH_RAY_TERMINATE = (PATH_RAY_TERMINATE_ON_NEXT_SURFACE | PATH_RAY_TERMINATE_IN_NEXT_VOLUME |
                         PATH_RAY_TERMINATE_AFTER_TRANSPARENT | PATH_RAY_TERMINATE_AFTER_VOLUME),
 
   /* Path and shader is being evaluated for direct lighting emission. */
-  PATH_RAY_EMISSION = (1U << 19U),
+  PATH_RAY_EMISSION = (1U << 20U),
 
   /* Perform subsurface scattering. */
-  PATH_RAY_SUBSURFACE_RANDOM_WALK = (1U << 20U),
-  PATH_RAY_SUBSURFACE_DISK = (1U << 21U),
-  PATH_RAY_SUBSURFACE_USE_FRESNEL = (1U << 22U),
-  PATH_RAY_SUBSURFACE_BACKFACING

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list