Blender V5.0
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#include "kernel/svm/util.h"
9
11
12/* Vector Transform */
13
15 ccl_private ShaderData *sd,
16 ccl_private float *stack,
17 const uint4 node)
18{
19 uint itype;
20 uint ifrom;
21 uint ito;
22 uint vector_in;
23 uint vector_out;
24
25 svm_unpack_node_uchar3(node.y, &itype, &ifrom, &ito);
26 svm_unpack_node_uchar2(node.z, &vector_in, &vector_out);
27
28 float3 in = stack_load_float3(stack, vector_in);
29
33
34 Transform tfm;
35 const bool is_object = (sd->object != OBJECT_NONE);
36 const bool is_normal = (type == NODE_VECTOR_TRANSFORM_TYPE_NORMAL);
37 const bool is_direction = (type == NODE_VECTOR_TRANSFORM_TYPE_VECTOR);
38
39 /* From world */
42 if (is_normal) {
43 tfm = kernel_data.cam.cameratoworld;
45 }
46 else {
47 tfm = kernel_data.cam.worldtocamera;
48 in = is_direction ? transform_direction(&tfm, in) : transform_point(&tfm, in);
49 }
50 }
51 else if (to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT && is_object) {
52 if (is_normal) {
54 }
55 else if (is_direction) {
57 }
58 else {
60 }
61 }
62 }
63
64 /* From camera */
68 {
69 if (is_normal) {
70 tfm = kernel_data.cam.worldtocamera;
72 }
73 else {
74 tfm = kernel_data.cam.cameratoworld;
75 in = is_direction ? transform_direction(&tfm, in) : transform_point(&tfm, in);
76 }
77 }
78 if (to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT && is_object) {
79 if (is_normal) {
81 }
82 else if (is_direction) {
84 }
85 else {
87 }
88 }
89 }
90
91 /* From object */
95 is_object)
96 {
97 if (is_normal) {
99 }
100 else if (is_direction) {
101 object_dir_transform(kg, sd, &in);
102 }
103 else {
105 }
106 }
108 if (is_normal) {
109 tfm = kernel_data.cam.cameratoworld;
111 }
112 else {
113 tfm = kernel_data.cam.worldtocamera;
114 if (is_direction) {
115 in = transform_direction(&tfm, in);
116 }
117 else {
118 in = transform_point(&tfm, in);
119 }
120 }
121 }
122 }
123
124 /* Output */
125 if (stack_valid(vector_out)) {
126 stack_store_float3(stack, vector_out, in);
127 }
128}
129
unsigned int uint
BMesh const char itype
ccl_device_inline void stack_store_float3(ccl_private float *stack, const uint a, const float3 f)
ccl_device_forceinline void svm_unpack_node_uchar2(const uint i, ccl_private uint *x, ccl_private uint *y)
ccl_device_forceinline void svm_unpack_node_uchar3(const uint i, ccl_private uint *x, ccl_private uint *y, ccl_private uint *z)
ccl_device_inline bool stack_valid(const uint a)
CCL_NAMESPACE_BEGIN ccl_device_inline float3 stack_load_float3(const ccl_private float *stack, const uint a)
#define kernel_data
#define OBJECT_NONE
#define ccl_private
const ThreadKernelGlobalsCPU * KernelGlobals
#define ccl_device_noinline
#define CCL_NAMESPACE_END
#define in
VecBase< float, D > normalize(VecOp< float, D >) RET
ccl_device_inline void object_inverse_position_transform(KernelGlobals kg, const ccl_private ShaderData *sd, ccl_private float3 *P)
ccl_device_inline void object_dir_transform(KernelGlobals kg, const ccl_private ShaderData *sd, ccl_private float3 *D)
ccl_device_inline void object_normal_transform(KernelGlobals kg, const ccl_private ShaderData *sd, ccl_private float3 *N)
ccl_device_inline void object_position_transform(KernelGlobals kg, const ccl_private ShaderData *sd, ccl_private T *P)
ccl_device_inline void object_inverse_dir_transform(KernelGlobals kg, const ccl_private ShaderData *sd, ccl_private float3 *D)
ccl_device_inline void object_inverse_normal_transform(KernelGlobals kg, const ccl_private ShaderData *sd, ccl_private float3 *N)
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
uint y
Definition types_uint4.h:13
uint z
Definition types_uint4.h:13
ccl_device_inline float3 transform_direction(const ccl_private Transform *t, const float3 a)
Definition transform.h:127
ccl_device_inline float3 transform_direction_transposed(const ccl_private Transform *t, const float3 a)
Definition transform.h:149
ccl_device_inline float3 transform_point(const ccl_private Transform *t, const float3 a)
Definition transform.h:56
CCL_NAMESPACE_BEGIN ccl_device_noinline void svm_node_vector_transform(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *stack, const uint4 node)