2
* Copyright 2011-2013 Blender Foundation
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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
19
/* Vector Transform */
21
__device void svm_node_vector_transform(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node)
23
uint itype, ifrom, ito;
24
uint vector_in, vector_out;
26
decode_node_uchar4(node.y, &itype, &ifrom, &ito, NULL);
27
decode_node_uchar4(node.z, &vector_in, &vector_out, NULL, NULL);
29
float3 in = stack_load_float3(stack, vector_in);
31
NodeVectorTransformType type = (NodeVectorTransformType)itype;
32
NodeVectorTransformConvertSpace from = (NodeVectorTransformConvertSpace)ifrom;
33
NodeVectorTransformConvertSpace to = (NodeVectorTransformConvertSpace)ito;
36
bool is_object = (sd->object != ~0);
37
bool is_direction = (type == NODE_VECTOR_TRANSFORM_TYPE_VECTOR || type == NODE_VECTOR_TRANSFORM_TYPE_NORMAL);
40
if(from == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_WORLD) {
41
if(to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_CAMERA) {
42
tfm = kernel_data.cam.worldtocamera;
44
in = transform_direction(&tfm, in);
46
in = transform_point(&tfm, in);
48
else if (to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT && is_object) {
50
object_inverse_dir_transform(kg, sd, &in);
52
object_inverse_position_transform(kg, sd, &in);
57
else if (from == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_CAMERA) {
58
if(to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_WORLD || to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT) {
59
tfm = kernel_data.cam.cameratoworld;
61
in = transform_direction(&tfm, in);
63
in = transform_point(&tfm, in);
65
if(to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT && is_object) {
67
object_inverse_dir_transform(kg, sd, &in);
69
object_inverse_position_transform(kg, sd, &in);
74
else if(from == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT) {
75
if((to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_WORLD || to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_CAMERA) && is_object) {
77
object_dir_transform(kg, sd, &in);
79
object_position_transform(kg, sd, &in);
81
if(to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_CAMERA) {
82
tfm = kernel_data.cam.worldtocamera;
84
in = transform_direction(&tfm, in);
86
in = transform_point(&tfm, in);
90
/* Normalize Normal */
91
if(type == NODE_VECTOR_TRANSFORM_TYPE_NORMAL)
95
if(stack_valid(vector_out)) {
96
stack_store_float3(stack, vector_out, in);