From bd327e3bf3e0768aa2768949304571e0eb73ab80 Mon Sep 17 00:00:00 2001 From: Sebastian Herholz Date: Thu, 28 Apr 2022 18:00:41 +0200 Subject: 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 --- intern/cycles/kernel/svm/sky.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'intern/cycles/kernel/svm') 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( -- cgit v1.2.3