Blender  V2.93
svm_vector_transform.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 /* Vector Transform */
20 
22  ShaderData *sd,
23  float *stack,
24  uint4 node)
25 {
26  uint itype, ifrom, ito;
27  uint vector_in, vector_out;
28 
29  svm_unpack_node_uchar3(node.y, &itype, &ifrom, &ito);
30  svm_unpack_node_uchar2(node.z, &vector_in, &vector_out);
31 
32  float3 in = stack_load_float3(stack, vector_in);
33 
37 
38  Transform tfm;
39  bool is_object = (sd->object != OBJECT_NONE);
40  bool is_direction = (type == NODE_VECTOR_TRANSFORM_TYPE_VECTOR ||
42 
43  /* From world */
46  tfm = kernel_data.cam.worldtocamera;
47  if (is_direction)
48  in = transform_direction(&tfm, in);
49  else
50  in = transform_point(&tfm, in);
51  }
52  else if (to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT && is_object) {
53  if (is_direction)
55  else
57  }
58  }
59 
60  /* From camera */
64  tfm = kernel_data.cam.cameratoworld;
65  if (is_direction)
66  in = transform_direction(&tfm, in);
67  else
68  in = transform_point(&tfm, in);
69  }
70  if (to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT && is_object) {
71  if (is_direction)
73  else
75  }
76  }
77 
78  /* From object */
82  is_object) {
83  if (is_direction)
84  object_dir_transform(kg, sd, &in);
85  else
86  object_position_transform(kg, sd, &in);
87  }
89  tfm = kernel_data.cam.worldtocamera;
90  if (is_direction)
91  in = transform_direction(&tfm, in);
92  else
93  in = transform_point(&tfm, in);
94  }
95  }
96 
97  /* Normalize Normal */
99  in = normalize(in);
100 
101  /* Output */
102  if (stack_valid(vector_out)) {
103  stack_store_float3(stack, vector_out, in);
104  }
105 }
106 
unsigned int uint
Definition: BLI_sys_types.h:83
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
ATTR_WARN_UNUSED_RESULT BMesh const char itype
OperationNode * node
StackEntry * from
ccl_device_inline void object_inverse_dir_transform(KernelGlobals *kg, const ShaderData *sd, float3 *D)
Definition: geom_object.h:190
ccl_device_inline void object_inverse_position_transform(KernelGlobals *kg, const ShaderData *sd, float3 *P)
Definition: geom_object.h:130
ccl_device_inline void object_position_transform(KernelGlobals *kg, const ShaderData *sd, float3 *P)
Definition: geom_object.h:116
ccl_device_inline void object_dir_transform(KernelGlobals *kg, const ShaderData *sd, float3 *D)
Definition: geom_object.h:178
CCL_NAMESPACE_BEGIN ccl_device_inline float3 stack_load_float3(float *stack, uint a)
ccl_device_forceinline void svm_unpack_node_uchar3(uint i, uint *x, uint *y, uint *z)
ccl_device_inline void stack_store_float3(float *stack, uint a, float3 f)
ccl_device_forceinline void svm_unpack_node_uchar2(uint i, uint *x, uint *y)
ccl_device_inline bool stack_valid(uint a)
#define kernel_data
#define ccl_device
#define CCL_NAMESPACE_END
#define OBJECT_NONE
Definition: kernel_types.h:59
ShaderData
NodeVectorTransformConvertSpace
Definition: svm_types.h:379
@ NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT
Definition: svm_types.h:381
@ NODE_VECTOR_TRANSFORM_CONVERT_SPACE_WORLD
Definition: svm_types.h:380
@ NODE_VECTOR_TRANSFORM_CONVERT_SPACE_CAMERA
Definition: svm_types.h:382
NodeVectorTransformType
Definition: svm_types.h:373
@ NODE_VECTOR_TRANSFORM_TYPE_NORMAL
Definition: svm_types.h:376
@ NODE_VECTOR_TRANSFORM_TYPE_VECTOR
Definition: svm_types.h:374
CCL_NAMESPACE_BEGIN ccl_device void svm_node_vector_transform(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node)
ccl_device_inline float2 normalize(const float2 &a)
ccl_device_inline float3 transform_direction(const Transform *t, const float3 a)
ccl_device_inline float3 transform_point(const Transform *t, const float3 a)