Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Werner <stefan.werner@tangent-animation.com>2018-07-05 13:37:52 +0300
committerStefan Werner <stefan.werner@tangent-animation.com>2018-07-05 14:53:34 +0300
commit4d00e95ee3ed91f86262bb218f1c5df901da724c (patch)
tree5d9af704609b38cca76a5786189c126ac7072332 /intern/cycles/util
parentcd17b3258327522b8c6f56a3ee7239a91f2be149 (diff)
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
Diffstat (limited to 'intern/cycles/util')
-rw-r--r--intern/cycles/util/CMakeLists.txt1
-rw-r--r--intern/cycles/util/util_half.h11
-rw-r--r--intern/cycles/util/util_image_impl.h16
-rw-r--r--intern/cycles/util/util_texture.h2
-rw-r--r--intern/cycles/util/util_types.h2
-rw-r--r--intern/cycles/util/util_types_ushort4.h36
6 files changed, 67 insertions, 1 deletions
diff --git a/intern/cycles/util/CMakeLists.txt b/intern/cycles/util/CMakeLists.txt
index 3b690860d53..508f44e7c4d 100644
--- a/intern/cycles/util/CMakeLists.txt
+++ b/intern/cycles/util/CMakeLists.txt
@@ -116,6 +116,7 @@ set(SRC_HEADERS
util_types_uint3_impl.h
util_types_uint4.h
util_types_uint4_impl.h
+ util_types_ushort4.h
util_types_vector3.h
util_types_vector3_impl.h
util_vector.h
diff --git a/intern/cycles/util/util_half.h b/intern/cycles/util/util_half.h
index 612228dd1c1..f6c507906f3 100644
--- a/intern/cycles/util/util_half.h
+++ b/intern/cycles/util/util_half.h
@@ -36,7 +36,16 @@ CCL_NAMESPACE_BEGIN
/* CUDA has its own half data type, no need to define then */
#ifndef __KERNEL_CUDA__
-typedef unsigned short half;
+/* Implementing this as a class rather than a typedef so that the compiler can tell it apart from unsigned shorts. */
+class half {
+public:
+ half() : v(0) {}
+ half(const unsigned short& i) : v(i) {}
+ operator unsigned short() { return v; }
+ half & operator =(const unsigned short& i) { v = i; return *this; }
+private:
+ unsigned short v;
+};
#endif
struct half4 { half x, y, z, w; };
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);
diff --git a/intern/cycles/util/util_texture.h b/intern/cycles/util/util_texture.h
index 4b5f630427d..f752e81128d 100644
--- a/intern/cycles/util/util_texture.h
+++ b/intern/cycles/util/util_texture.h
@@ -53,6 +53,8 @@ typedef enum ImageDataType {
IMAGE_DATA_TYPE_FLOAT = 3,
IMAGE_DATA_TYPE_BYTE = 4,
IMAGE_DATA_TYPE_HALF = 5,
+ IMAGE_DATA_TYPE_USHORT4 = 6,
+ IMAGE_DATA_TYPE_USHORT = 7,
IMAGE_DATA_NUM_TYPES
} ImageDataType;
diff --git a/intern/cycles/util/util_types.h b/intern/cycles/util/util_types.h
index 84206a7ba5a..4bbba649ff2 100644
--- a/intern/cycles/util/util_types.h
+++ b/intern/cycles/util/util_types.h
@@ -116,6 +116,8 @@ CCL_NAMESPACE_END
#include "util/util_types_uint3.h"
#include "util/util_types_uint4.h"
+#include "util/util_types_ushort4.h"
+
#include "util/util_types_float2.h"
#include "util/util_types_float3.h"
#include "util/util_types_float4.h"
diff --git a/intern/cycles/util/util_types_ushort4.h b/intern/cycles/util/util_types_ushort4.h
new file mode 100644
index 00000000000..fc234b8abe8
--- /dev/null
+++ b/intern/cycles/util/util_types_ushort4.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2011-2017 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __UTIL_TYPES_USHORT4_H__
+#define __UTIL_TYPES_USHORT4_H__
+
+#ifndef __UTIL_TYPES_H__
+# error "Do not include this file directly, include util_types.h instead."
+#endif
+
+CCL_NAMESPACE_BEGIN
+
+#ifndef __KERNEL_GPU__
+
+struct ushort4 {
+ uint16_t x, y, z, w;
+};
+
+#endif
+
+CCL_NAMESPACE_END
+
+#endif /* __UTIL_TYPES_USHORT4_H__ */