[Bf-blender-cvs] [bd327e3bf3e] master: Fix: Sky models can return negative values

Sebastian Herholz noreply at git.blender.org
Thu Apr 28 18:14:16 CEST 2022


Commit: bd327e3bf3e0768aa2768949304571e0eb73ab80
Author: Sebastian Herholz
Date:   Thu Apr 28 18:00:41 2022 +0200
Branches: master
https://developer.blender.org/rBbd327e3bf3e0768aa2768949304571e0eb73ab80

Fix: Sky models can return negative values

When converting from XYZ to RGB it can happen, in some sky models, that the resulting RGB values are negative.
Atm, this is not considered and the returned values for the sky model can be negative.

This patch clamps the returned RGB values to be `= 0.f`

Reviewed By: brecht, sergey

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

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

M	intern/cycles/kernel/svm/sky.h
M	intern/cycles/kernel/util/color.h

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

diff --git a/intern/cycles/kernel/svm/sky.h b/intern/cycles/kernel/svm/sky.h
index a72d4dd3ba7..1638e783a69 100644
--- a/intern/cycles/kernel/svm/sky.h
+++ b/intern/cycles/kernel/svm/sky.h
@@ -55,7 +55,7 @@ ccl_device float3 sky_radiance_preetham(KernelGlobals kg,
 
   /* convert to RGB */
   float3 xyz = xyY_to_xyz(x, y, Y);
-  return xyz_to_rgb(kg, xyz);
+  return xyz_to_rgb_clamped(kg, xyz);
 }
 
 /*
@@ -107,7 +107,7 @@ ccl_device float3 sky_radiance_hosek(KernelGlobals kg,
   float z = sky_radiance_internal(config_z, theta, gamma) * radiance_z;
 
   /* convert to RGB and adjust strength */
-  return xyz_to_rgb(kg, make_float3(x, y, z)) * (M_2PI_F / 683);
+  return xyz_to_rgb_clamped(kg, make_float3(x, y, z)) * (M_2PI_F / 683);
 }
 
 /* Nishita improved sky model */
@@ -194,7 +194,7 @@ ccl_device float3 sky_radiance_nishita(KernelGlobals kg,
   }
 
   /* convert to RGB */
-  return xyz_to_rgb(kg, xyz);
+  return xyz_to_rgb_clamped(kg, xyz);
 }
 
 ccl_device_noinline int svm_node_tex_sky(
diff --git a/intern/cycles/kernel/util/color.h b/intern/cycles/kernel/util/color.h
index 28978d873d6..c85ef262d88 100644
--- a/intern/cycles/kernel/util/color.h
+++ b/intern/cycles/kernel/util/color.h
@@ -14,6 +14,11 @@ ccl_device float3 xyz_to_rgb(KernelGlobals kg, float3 xyz)
                      dot(float4_to_float3(kernel_data.film.xyz_to_b), xyz));
 }
 
+ccl_device float3 xyz_to_rgb_clamped(KernelGlobals kg, float3 xyz)
+{
+  return max(xyz_to_rgb(kg, xyz), zero_float3());
+}
+
 ccl_device float3 rec709_to_rgb(KernelGlobals kg, float3 rec709)
 {
   return (kernel_data.film.is_rec709) ?



More information about the Bf-blender-cvs mailing list