diff options
author | Brecht Van Lommel <brecht@blender.org> | 2022-01-21 20:57:00 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2022-06-02 19:04:38 +0300 |
commit | 33f5e8f2391944acf8c6cc56bcc352bc10af016c (patch) | |
tree | dc18c07bdd6d7e257b92250cac1293f693be0325 /intern/cycles/util | |
parent | 10488d54d9836b04f36d95269552bd449dd97e7e (diff) |
Cycles: load 8 bit image textures as half float for some color spaces
For non-raw, non-sRGB color spaces, always use half float even if that uses
more memory. Otherwise the precision loss from conversion to scene linear or
sRGB (as natively understood by the texture sampling) can be too much.
This also required a change to do alpha association ourselves instead of OIIO,
because in OIIO alpha multiplication happens before conversion to half float
and that gives too much precision loss.
Ref T68926
Diffstat (limited to 'intern/cycles/util')
-rw-r--r-- | intern/cycles/util/image.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/intern/cycles/util/image.h b/intern/cycles/util/image.h index 9348125d072..17446a83e59 100644 --- a/intern/cycles/util/image.h +++ b/intern/cycles/util/image.h @@ -78,6 +78,26 @@ template<> inline half util_image_cast_from_float(float value) return float_to_half_image(value); } +/* Multiply image pixels in native data format. */ +template<typename T> inline T util_image_multiply_native(T a, T b); + +template<> inline float util_image_multiply_native(float a, float b) +{ + return a * b; +} +template<> inline uchar util_image_multiply_native(uchar a, uchar b) +{ + return ((uint32_t)a * (uint32_t)b) / 255; +} +template<> inline uint16_t util_image_multiply_native(uint16_t a, uint16_t b) +{ + return ((uint32_t)a * (uint32_t)b) / 65535; +} +template<> inline half util_image_multiply_native(half a, half b) +{ + return float_to_half_image(half_to_float_image(a) * half_to_float_image(b)); +} + CCL_NAMESPACE_END #endif /* __UTIL_IMAGE_H__ */ |