Blender V5.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
9#include "kernel/svm/util.h"
10
12
13/* Vector Transform */
14
17 ccl_private ShaderData *sd,
18 ccl_private float *ccl_restrict stack,
20{
21 float3 in = stack_load(stack, node.vector_in);
22
23 const NodeVectorTransformType type = node.transform_type;
24 const NodeVectorTransformConvertSpace from = node.convert_from;
25 const NodeVectorTransformConvertSpace to = node.convert_to;
26
27 Transform tfm;
28 const bool is_object = (sd->object != OBJECT_NONE);
29 const bool is_normal = (type == NODE_VECTOR_TRANSFORM_TYPE_NORMAL);
30 const bool is_direction = (type == NODE_VECTOR_TRANSFORM_TYPE_VECTOR);
31
32 /* From world */
35 if (is_normal) {
36 tfm = kernel_data.cam.cameratoworld;
38 }
39 else {
40 tfm = kernel_data.cam.worldtocamera;
41 in = is_direction ? transform_direction(&tfm, in) : transform_point(&tfm, in);
42 }
43 }
44 else if (to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT && is_object) {
45 if (is_normal) {
47 }
48 else if (is_direction) {
50 }
51 else {
53 }
54 }
55 }
56
57 /* From camera */
61 {
62 if (is_normal) {
63 tfm = kernel_data.cam.worldtocamera;
65 }
66 else {
67 tfm = kernel_data.cam.cameratoworld;
68 in = is_direction ? transform_direction(&tfm, in) : transform_point(&tfm, in);
69 }
70 }
71 if (to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT && is_object) {
72 if (is_normal) {
74 }
75 else if (is_direction) {
77 }
78 else {
80 }
81 }
82 }
83
84 /* From object */
88 is_object)
89 {
90 if (is_normal) {
92 }
93 else if (is_direction) {
94 object_dir_transform(kg, sd, &in);
95 }
96 else {
98 }
99 }
101 if (is_normal) {
102 tfm = kernel_data.cam.cameratoworld;
104 }
105 else {
106 tfm = kernel_data.cam.worldtocamera;
107 if (is_direction) {
108 in = transform_direction(&tfm, in);
109 }
110 else {
111 in = transform_point(&tfm, in);
112 }
113 }
114 }
115 }
116
117 /* Output */
118 if (stack_valid(node.vector_out_offset)) {
119 stack_store_float3(stack, node.vector_out_offset, in);
120 }
121}
122
ccl_device_inline void stack_store_float3(ccl_private float *stack, const uint a, const float3 f)
ccl_device_inline bool stack_valid(const uint a)
ccl_device_inline T stack_load(const ccl_private float *stack, const uint a)
#define kernel_data
#define ccl_restrict
#define OBJECT_NONE
#define ccl_private
#define ccl_global
#define ccl_device_noinline
#define CCL_NAMESPACE_END
VecBase< float, D > normalize(VecOp< float, D >) RET
float3 transform_direction(float3x3 mat, float3 direction)
float3 transform_point(float3x3 mat, float3 point)
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 T *N)
ccl_device_inline void object_inverse_position_transform(KernelGlobals kg, const ccl_private ShaderData *sd, ccl_private T *P)
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)
NodeVectorTransformType
@ NODE_VECTOR_TRANSFORM_TYPE_NORMAL
@ NODE_VECTOR_TRANSFORM_TYPE_VECTOR
NodeVectorTransformConvertSpace
@ NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT
@ NODE_VECTOR_TRANSFORM_CONVERT_SPACE_WORLD
@ NODE_VECTOR_TRANSFORM_CONVERT_SPACE_CAMERA
ccl_device_inline T transform_direction_transposed(const ccl_private Transform *t, const T a)
Definition transform.h:176
CCL_NAMESPACE_BEGIN ccl_device_noinline void svm_node_vector_transform(KernelGlobals kg, ccl_private ShaderData *sd, ccl_private float *ccl_restrict stack, const ccl_global SVMNodeVectorTransform &ccl_restrict node)