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:
authorAndrii Symkin <pembem22>2022-07-29 14:41:37 +0300
committerBrecht Van Lommel <brecht@blender.org>2022-08-09 17:49:34 +0300
commitd832d993c5b47b0de7ca24914ad9c064607830c7 (patch)
tree889b7cd9f135a40cbaccdb4537c8de1faa1c562f /intern/cycles/util
parent7921faa6519b9eb9062269b5d9c003c64ead2b8b (diff)
Cycles: add new Spectrum and PackedSpectrum types
These replace float3 and packed_float3 in various places in the kernel where a spectral color representation will be used in the future. That representation will require more than 3 channels and conversion to from/RGB. The kernel code was refactored to remove the assumption that Spectrum and RGB colors are the same thing. There are no functional changes, Spectrum is still a float3 and the conversion functions are no-ops. Differential Revision: https://developer.blender.org/D15535
Diffstat (limited to 'intern/cycles/util')
-rw-r--r--intern/cycles/util/CMakeLists.txt1
-rw-r--r--intern/cycles/util/defines.h3
-rw-r--r--intern/cycles/util/math.h28
-rw-r--r--intern/cycles/util/types.h2
-rw-r--r--intern/cycles/util/types_spectrum.h34
5 files changed, 54 insertions, 14 deletions
diff --git a/intern/cycles/util/CMakeLists.txt b/intern/cycles/util/CMakeLists.txt
index b33bad79e6c..e70f65e124c 100644
--- a/intern/cycles/util/CMakeLists.txt
+++ b/intern/cycles/util/CMakeLists.txt
@@ -116,6 +116,7 @@ set(SRC_HEADERS
types_int3_impl.h
types_int4.h
types_int4_impl.h
+ types_spectrum.h
types_uchar2.h
types_uchar2_impl.h
types_uchar3.h
diff --git a/intern/cycles/util/defines.h b/intern/cycles/util/defines.h
index d0df1a221fc..c7118ca09c9 100644
--- a/intern/cycles/util/defines.h
+++ b/intern/cycles/util/defines.h
@@ -136,4 +136,7 @@ template<typename T> static inline T decltype_helper(T x)
# define util_assert(statement)
#endif
+#define CONCAT_HELPER(a, ...) a##__VA_ARGS__
+#define CONCAT(a, ...) CONCAT_HELPER(a, __VA_ARGS__)
+
#endif /* __UTIL_DEFINES_H__ */
diff --git a/intern/cycles/util/math.h b/intern/cycles/util/math.h
index f6400cb879f..0585dcc8ad5 100644
--- a/intern/cycles/util/math.h
+++ b/intern/cycles/util/math.h
@@ -595,26 +595,26 @@ ccl_device_inline void make_orthonormals(const float3 N,
/* Color division */
-ccl_device_inline float3 safe_invert_color(float3 a)
+ccl_device_inline Spectrum safe_invert_color(Spectrum a)
{
- float x, y, z;
-
- x = (a.x != 0.0f) ? 1.0f / a.x : 0.0f;
- y = (a.y != 0.0f) ? 1.0f / a.y : 0.0f;
- z = (a.z != 0.0f) ? 1.0f / a.z : 0.0f;
+ FOREACH_SPECTRUM_CHANNEL (i) {
+ GET_SPECTRUM_CHANNEL(a, i) = (GET_SPECTRUM_CHANNEL(a, i) != 0.0f) ?
+ 1.0f / GET_SPECTRUM_CHANNEL(a, i) :
+ 0.0f;
+ }
- return make_float3(x, y, z);
+ return a;
}
-ccl_device_inline float3 safe_divide_color(float3 a, float3 b)
+ccl_device_inline Spectrum safe_divide_color(Spectrum a, Spectrum b)
{
- float x, y, z;
-
- x = (b.x != 0.0f) ? a.x / b.x : 0.0f;
- y = (b.y != 0.0f) ? a.y / b.y : 0.0f;
- z = (b.z != 0.0f) ? a.z / b.z : 0.0f;
+ FOREACH_SPECTRUM_CHANNEL (i) {
+ GET_SPECTRUM_CHANNEL(a, i) = (GET_SPECTRUM_CHANNEL(b, i) != 0.0f) ?
+ GET_SPECTRUM_CHANNEL(a, i) / GET_SPECTRUM_CHANNEL(b, i) :
+ 0.0f;
+ }
- return make_float3(x, y, z);
+ return a;
}
ccl_device_inline float3 safe_divide_even_color(float3 a, float3 b)
diff --git a/intern/cycles/util/types.h b/intern/cycles/util/types.h
index d0d8c2941d7..1ab6f76f9bc 100644
--- a/intern/cycles/util/types.h
+++ b/intern/cycles/util/types.h
@@ -109,6 +109,8 @@ ccl_device_inline void print_float(ccl_private const char *label, const float a)
#include "util/types_float4.h"
#include "util/types_float8.h"
+#include "util/types_spectrum.h"
+
/* Vectorized types implementation. */
#include "util/types_uchar2_impl.h"
#include "util/types_uchar3_impl.h"
diff --git a/intern/cycles/util/types_spectrum.h b/intern/cycles/util/types_spectrum.h
new file mode 100644
index 00000000000..c59230b83ae
--- /dev/null
+++ b/intern/cycles/util/types_spectrum.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: Apache-2.0
+ * Copyright 2022 Blender Foundation */
+
+#ifndef __UTIL_TYPES_SPECTRUM_H__
+#define __UTIL_TYPES_SPECTRUM_H__
+
+#ifndef __UTIL_TYPES_H__
+# error "Do not include this file directly, include util/types.h instead."
+#endif
+
+CCL_NAMESPACE_BEGIN
+
+#define SPECTRUM_CHANNELS 3
+#define SPECTRUM_DATA_TYPE float3
+#define PACKED_SPECTRUM_DATA_TYPE packed_float3
+
+using Spectrum = SPECTRUM_DATA_TYPE;
+using PackedSpectrum = PACKED_SPECTRUM_DATA_TYPE;
+
+#define make_spectrum(f) CONCAT(make_, SPECTRUM_DATA_TYPE(f))
+#define load_spectrum(f) CONCAT(load_, SPECTRUM_DATA_TYPE(f))
+#define store_spectrum(s, f) CONCAT(store_, SPECTRUM_DATA_TYPE((s), (f)))
+
+#define zero_spectrum CONCAT(zero_, SPECTRUM_DATA_TYPE)
+#define one_spectrum CONCAT(one_, SPECTRUM_DATA_TYPE)
+
+#define FOREACH_SPECTRUM_CHANNEL(counter) \
+ for (int counter = 0; counter < SPECTRUM_CHANNELS; counter++)
+
+#define GET_SPECTRUM_CHANNEL(v, i) (((ccl_private float *)(&(v)))[i])
+
+CCL_NAMESPACE_END
+
+#endif /* __UTIL_TYPES_SPECTRUM_H__ */