Blender V4.3
vector_transform.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
8
9/* Vector Transform */
10
13 ccl_private float *stack,
14 uint4 node)
15{
16 uint itype, ifrom, ito;
17 uint vector_in, vector_out;
18
19 svm_unpack_node_uchar3(node.y, &itype, &ifrom, &ito);
20 svm_unpack_node_uchar2(node.z, &vector_in, &vector_out);
21
22 float3 in = stack_load_float3(stack, vector_in);
23
27
28 Transform tfm;
29 bool is_object = (sd->object != OBJECT_NONE) || (sd->type == PRIMITIVE_LAMP);
30 bool is_normal = (type == NODE_VECTOR_TRANSFORM_TYPE_NORMAL);
31 bool is_direction = (type == NODE_VECTOR_TRANSFORM_TYPE_VECTOR);
32
33 /* From world */
36 if (is_normal) {
37 tfm = kernel_data.cam.cameratoworld;
39 }
40 else {
41 tfm = kernel_data.cam.worldtocamera;
42 in = is_direction ? transform_direction(&tfm, in) : transform_point(&tfm, in);
43 }
44 }
45 else if (to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT && is_object) {
46 if (is_normal) {
48 }
49 else if (is_direction) {
51 }
52 else {
54 }
55 }
56 }
57
58 /* From camera */
62 {
63 if (is_normal) {
64 tfm = kernel_data.cam.worldtocamera;
66 }
67 else {
68 tfm = kernel_data.cam.cameratoworld;
69 in = is_direction ? transform_direction(&tfm, in) : transform_point(&tfm, in);
70 }
71 }
72 if (to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT && is_object) {
73 if (is_normal) {
75 }
76 else if (is_direction) {
78 }
79 else {
81 }
82 }
83 }
84
85 /* From object */
89 is_object)
90 {
91 if (is_normal) {
92 object_normal_transform(kg, sd, &in);
93 }
94 else if (is_direction) {
95 object_dir_transform(kg, sd, &in);
96 }
97 else {
98 object_position_transform(kg, sd, &in);
99 }
100 }
102 if (is_normal) {
103 tfm = kernel_data.cam.cameratoworld;
105 }
106 else {
107 tfm = kernel_data.cam.worldtocamera;
108 if (is_direction) {
109 in = transform_direction(&tfm, in);
110 }
111 else {
112 in = transform_point(&tfm, in);
113 }
114 }
115 }
116 }
117
118 /* Output */
119 if (stack_valid(vector_out)) {
120 stack_store_float3(stack, vector_out, in);
121 }
122}
123
unsigned int uint
ATTR_WARN_UNUSED_RESULT BMesh const char itype
SIMD_FORCE_INLINE btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
Definition btVector3.h:303
#define kernel_data
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define ccl_private
#define ccl_device_noinline
#define CCL_NAMESPACE_END
ccl_device_inline void object_position_transform(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float3 *P)
ccl_device_inline void object_inverse_dir_transform(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float3 *D)
ccl_device_inline void object_inverse_position_transform(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float3 *P)
ccl_device_inline void object_dir_transform(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float3 *D)
ccl_device_inline void object_inverse_normal_transform(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float3 *N)
ccl_device_inline void object_normal_transform(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float3 *N)
ccl_device_inline void stack_store_float3(ccl_private float *stack, uint a, float3 f)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 stack_load_float3(ccl_private float *stack, uint a)
ccl_device_forceinline void svm_unpack_node_uchar3(uint i, ccl_private uint *x, ccl_private uint *y, ccl_private uint *z)
ccl_device_forceinline void svm_unpack_node_uchar2(uint i, ccl_private uint *x, ccl_private uint *y)
ccl_device_inline bool stack_valid(uint a)
NodeVectorTransformConvertSpace
@ NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT
@ NODE_VECTOR_TRANSFORM_CONVERT_SPACE_WORLD
@ NODE_VECTOR_TRANSFORM_CONVERT_SPACE_CAMERA
NodeVectorTransformType
@ NODE_VECTOR_TRANSFORM_TYPE_NORMAL
@ NODE_VECTOR_TRANSFORM_TYPE_VECTOR
@ PRIMITIVE_LAMP
#define OBJECT_NONE
ShaderData
ccl_device_inline float3 transform_direction(ccl_private const Transform *t, const float3 a)
Definition transform.h:94
ccl_device_inline float3 transform_direction_transposed(ccl_private const Transform *t, const float3 a)
Definition transform.h:123
CCL_NAMESPACE_END CCL_NAMESPACE_BEGIN ccl_device_inline float3 transform_point(ccl_private const Transform *t, const float3 a)
Definition transform.h:63
CCL_NAMESPACE_BEGIN ccl_device_noinline void svm_node_vector_transform(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, uint4 node)