~ubuntu-branches/ubuntu/utopic/blender/utopic-proposed

« back to all changes in this revision

Viewing changes to intern/cycles/kernel/svm/svm_vector_transform.h

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-02-19 11:24:23 UTC
  • mfrom: (14.2.23 sid)
  • Revision ID: package-import@ubuntu.com-20140219112423-rkmaz2m7ha06d4tk
Tags: 2.69-3ubuntu1
* Merge with Debian; remaining changes:
  - Configure without OpenImageIO on armhf, as it is not available on
    Ubuntu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
17
CCL_NAMESPACE_BEGIN
 
18
 
 
19
/* Vector Transform */
 
20
 
 
21
__device void svm_node_vector_transform(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node)
 
22
{
 
23
        uint itype, ifrom, ito;
 
24
        uint vector_in, vector_out;
 
25
        
 
26
        decode_node_uchar4(node.y, &itype, &ifrom, &ito, NULL);
 
27
        decode_node_uchar4(node.z, &vector_in, &vector_out, NULL, NULL);
 
28
        
 
29
        float3 in = stack_load_float3(stack, vector_in);
 
30
        
 
31
        NodeVectorTransformType type = (NodeVectorTransformType)itype;
 
32
        NodeVectorTransformConvertSpace from = (NodeVectorTransformConvertSpace)ifrom;
 
33
        NodeVectorTransformConvertSpace to = (NodeVectorTransformConvertSpace)ito;
 
34
        
 
35
        Transform tfm;
 
36
        bool is_object = (sd->object != ~0);
 
37
        bool is_direction = (type == NODE_VECTOR_TRANSFORM_TYPE_VECTOR || type == NODE_VECTOR_TRANSFORM_TYPE_NORMAL);
 
38
        
 
39
        /* From world */
 
40
        if(from == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_WORLD) {
 
41
                if(to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_CAMERA) {
 
42
                        tfm = kernel_data.cam.worldtocamera;
 
43
                        if(is_direction)
 
44
                                in = transform_direction(&tfm, in);
 
45
                        else
 
46
                                in = transform_point(&tfm, in);
 
47
                }
 
48
                else if (to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT && is_object) {
 
49
                        if(is_direction)
 
50
                                object_inverse_dir_transform(kg, sd, &in);
 
51
                        else
 
52
                                object_inverse_position_transform(kg, sd, &in);
 
53
                }
 
54
        }
 
55
        
 
56
        /* From camera */
 
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;
 
60
                        if(is_direction)
 
61
                                in = transform_direction(&tfm, in);
 
62
                        else
 
63
                                in = transform_point(&tfm, in);
 
64
                }
 
65
                if(to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT && is_object) {
 
66
                        if(is_direction)
 
67
                                object_inverse_dir_transform(kg, sd, &in);
 
68
                        else
 
69
                                object_inverse_position_transform(kg, sd, &in);
 
70
                }
 
71
        }
 
72
        
 
73
        /* From object */
 
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) {
 
76
                        if(is_direction)
 
77
                                object_dir_transform(kg, sd, &in);
 
78
                        else
 
79
                                object_position_transform(kg, sd, &in);
 
80
                }
 
81
                if(to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_CAMERA) {
 
82
                        tfm = kernel_data.cam.worldtocamera;
 
83
                        if(is_direction)
 
84
                                in = transform_direction(&tfm, in);
 
85
                        else
 
86
                                in = transform_point(&tfm, in);
 
87
                }
 
88
        }
 
89
        
 
90
        /* Normalize Normal */
 
91
        if(type == NODE_VECTOR_TRANSFORM_TYPE_NORMAL)
 
92
                in = normalize(in);
 
93
        
 
94
        /* Output */    
 
95
        if(stack_valid(vector_out)) {
 
96
                        stack_store_float3(stack, vector_out, in);
 
97
        }
 
98
}
 
99
 
 
100
CCL_NAMESPACE_END
 
101