Blender V4.3
attribute_convert.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#ifndef __BLENDER_ATTRIBUTE_CONVERT_H__
6#define __BLENDER_ATTRIBUTE_CONVERT_H__
7
8#include "util/array.h"
9#include "util/color.h"
10#include "util/param.h"
11#include "util/types.h"
12
13#include "BLI_math_color.hh"
16
18
19template<typename BlenderT> struct AttributeConverter {
20 using CyclesT = void;
21};
22
23template<> struct AttributeConverter<float> {
24 using CyclesT = float;
25 static constexpr auto type_desc = TypeFloat;
26 static CyclesT convert(const float &value)
27 {
28 return value;
29 }
30};
31template<> struct AttributeConverter<int> {
32 using CyclesT = float;
33 static constexpr auto type_desc = TypeFloat;
34 static CyclesT convert(const int &value)
35 {
36 return float(value);
37 }
38};
39template<> struct AttributeConverter<blender::float2> {
40 using CyclesT = float2;
41 static constexpr auto type_desc = TypeFloat2;
42 static CyclesT convert(const blender::float2 &value)
43 {
44 return make_float2(value[0], value[1]);
45 }
46};
47template<> struct AttributeConverter<blender::float3> {
48 using CyclesT = float3;
49 static constexpr auto type_desc = TypeVector;
50 static CyclesT convert(const blender::float3 &value)
51 {
52 return make_float3(value[0], value[1], value[2]);
53 }
54};
55template<> struct AttributeConverter<blender::ColorGeometry4f> {
56 using CyclesT = float4;
57 static constexpr auto type_desc = TypeRGBA;
59 {
60 return make_float4(value[0], value[1], value[2], value[3]);
61 }
62};
63template<> struct AttributeConverter<blender::ColorGeometry4b> {
64 using CyclesT = float4;
65 static constexpr auto type_desc = TypeRGBA;
67 {
69 byte_to_float(value[1]),
70 byte_to_float(value[2]),
71 byte_to_float(value[3])));
72 }
73};
74template<> struct AttributeConverter<bool> {
75 using CyclesT = float;
76 static constexpr auto type_desc = TypeFloat;
77 static CyclesT convert(const bool &value)
78 {
79 return float(value);
80 }
81};
82template<> struct AttributeConverter<int8_t> {
83 using CyclesT = float;
84 static constexpr auto type_desc = TypeFloat;
85 static CyclesT convert(const int8_t &value)
86 {
87 return float(value);
88 }
89};
91 using CyclesT = float4;
92 static constexpr auto type_desc = TypeFloat4;
94 {
95 return make_float4(value.w, value.x, value.y, value.z);
96 }
97};
98
100
101#endif /* __BLENDER_ATTRIBUTE_CONVERT_H__ */
#define CCL_NAMESPACE_END
ccl_device_forceinline float4 make_float4(const float x, const float y, const float z, const float w)
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
ccl_device_forceinline float2 make_float2(const float x, const float y)
draw_view in_light_buf[] float
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
static constexpr TypeDesc TypeRGBA(TypeDesc::FLOAT, TypeDesc::VEC4, TypeDesc::COLOR)
CCL_NAMESPACE_BEGIN static OIIO_NAMESPACE_USING constexpr TypeDesc TypeFloat2(TypeDesc::FLOAT, TypeDesc::VEC2)
signed char int8_t
Definition stdint.h:75
static CyclesT convert(const blender::ColorGeometry4b &value)
static CyclesT convert(const blender::ColorGeometry4f &value)
static CyclesT convert(const blender::float2 &value)
static CyclesT convert(const blender::float3 &value)
static CyclesT convert(const blender::math::Quaternion &value)
static CyclesT convert(const bool &value)
static CyclesT convert(const float &value)
static CyclesT convert(const int8_t &value)
static CyclesT convert(const int &value)
ccl_device float4 color_srgb_to_linear_v4(float4 c)
Definition util/color.h:327
ccl_device float byte_to_float(uchar val)
Definition util/color.h:23