[Bf-blender-cvs] [6a3c91f7adc] master: Cycles: Clamp Sky Texture altitude to avoid numerical issues

Lukas Stockner noreply at git.blender.org
Mon Jul 13 03:15:38 CEST 2020


Commit: 6a3c91f7adc8005fc19c58a4e8a219ae22eab4c0
Author: Lukas Stockner
Date:   Mon Jul 13 01:53:02 2020 +0200
Branches: master
https://developer.blender.org/rB6a3c91f7adc8005fc19c58a4e8a219ae22eab4c0

Cycles: Clamp Sky Texture altitude to avoid numerical issues

Differential Revision: https://developer.blender.org/D8091

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

M	intern/cycles/render/nodes.cpp

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

diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index bc2384f2955..1a29663ec5e 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -828,13 +828,17 @@ void SkyTextureNode::compile(SVMCompiler &compiler)
   else if (type == NODE_SKY_HOSEK)
     sky_texture_precompute_hosek(&sunsky, sun_direction, turbidity, ground_albedo);
   else if (type == NODE_SKY_NISHITA) {
+    /* Clamp altitude to reasonable values.
+     * Below 1m causes numerical issues and above 60km is space. */
+    float clamped_altitude = clamp(altitude, 1.0f, 59999.0f);
+
     sky_texture_precompute_nishita(&sunsky,
                                    sun_disc,
                                    sun_size,
                                    sun_intensity,
                                    sun_elevation,
                                    sun_rotation,
-                                   altitude,
+                                   clamped_altitude,
                                    air_density,
                                    dust_density);
     /* precomputed texture image parameters */
@@ -846,7 +850,7 @@ void SkyTextureNode::compile(SVMCompiler &compiler)
     /* precompute sky texture */
     if (handle.empty()) {
       SkyLoader *loader = new SkyLoader(
-          sun_elevation, altitude, air_density, dust_density, ozone_density);
+          sun_elevation, clamped_altitude, air_density, dust_density, ozone_density);
       handle = image_manager->add_image(loader, impar);
     }
   }
@@ -920,13 +924,17 @@ void SkyTextureNode::compile(OSLCompiler &compiler)
   else if (type == NODE_SKY_HOSEK)
     sky_texture_precompute_hosek(&sunsky, sun_direction, turbidity, ground_albedo);
   else if (type == NODE_SKY_NISHITA) {
+    /* Clamp altitude to reasonable values.
+     * Below 1m causes numerical issues and above 60km is space. */
+    float clamped_altitude = clamp(altitude, 1.0f, 59999.0f);
+
     sky_texture_precompute_nishita(&sunsky,
                                    sun_disc,
                                    sun_size,
                                    sun_intensity,
                                    sun_elevation,
                                    sun_rotation,
-                                   altitude,
+                                   clamped_altitude,
                                    air_density,
                                    dust_density);
     /* precomputed texture image parameters */
@@ -938,7 +946,7 @@ void SkyTextureNode::compile(OSLCompiler &compiler)
     /* precompute sky texture */
     if (handle.empty()) {
       SkyLoader *loader = new SkyLoader(
-          sun_elevation, altitude, air_density, dust_density, ozone_density);
+          sun_elevation, clamped_altitude, air_density, dust_density, ozone_density);
       handle = image_manager->add_image(loader, impar);
     }
   }



More information about the Bf-blender-cvs mailing list