diff options
author | Sebastian Herholz <sherholz> | 2022-04-28 19:00:41 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey@blender.org> | 2022-04-28 19:14:06 +0300 |
commit | bd327e3bf3e0768aa2768949304571e0eb73ab80 (patch) | |
tree | 7772168bd934fc648a663accffa06542c172b411 /intern/cycles | |
parent | 110eb2300526519681b44e154473b5fd087d191e (diff) |
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
Diffstat (limited to 'intern/cycles')
-rw-r--r-- | intern/cycles/kernel/svm/sky.h | 6 | ||||
-rw-r--r-- | intern/cycles/kernel/util/color.h | 5 |
2 files changed, 8 insertions, 3 deletions
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) ? |