From 4d00e95ee3ed91f86262bb218f1c5df901da724c Mon Sep 17 00:00:00 2001 From: Stefan Werner Date: Thu, 5 Jul 2018 12:37:52 +0200 Subject: Cycles: Adding native support for UINT16 textures. Textures in 16 bit integer format are sometimes used for displacement, bump and normal maps and can be exported by tools like Substance Painter. Without this patch, Cycles would promote those textures to single precision floating point, causing them to take up twice as much memory as needed. Reviewers: #cycles, brecht, sergey Reviewed By: #cycles, brecht, sergey Subscribers: sergey, dingto, #cycles Tags: #cycles Differential Revision: https://developer.blender.org/D3523 --- intern/cycles/util/util_image_impl.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'intern/cycles/util/util_image_impl.h') diff --git a/intern/cycles/util/util_image_impl.h b/intern/cycles/util/util_image_impl.h index 751f52aaa86..fb953a43ab2 100644 --- a/intern/cycles/util/util_image_impl.h +++ b/intern/cycles/util/util_image_impl.h @@ -53,6 +53,11 @@ inline float cast_to_float(uchar value) return (float)value / 255.0f; } template<> +inline float cast_to_float(uint16_t value) +{ + return (float)value / 65535.0f; +} +template<> inline float cast_to_float(half value) { return half_to_float(value); @@ -79,6 +84,17 @@ inline uchar cast_from_float(float value) return (uchar)((255.0f * value) + 0.5f); } template<> +inline uint16_t cast_from_float(float value) +{ + if(value < 0.0f) { + return 0; + } + else if(value >(1.0f - 0.5f / 65535.0f)) { + return 65535; + } + return (uchar)((65535.0f * value) + 0.5f); +} +template<> inline half cast_from_float(float value) { return float_to_half(value); -- cgit v1.2.3