2013-07-31 21:18:23 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2013-07-31 21:18:23 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2013-07-31 21:18:23 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2013-07-31 21:18:23 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 01:50:24 +00:00
|
|
|
* limitations under the License.
|
2013-07-31 21:18:23 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/* Vector Transform */
|
|
|
|
|
2013-11-15 23:17:10 +00:00
|
|
|
ccl_device void svm_node_vector_transform(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node)
|
2013-07-31 21:18:23 +00:00
|
|
|
{
|
|
|
|
uint itype, ifrom, ito;
|
|
|
|
uint vector_in, vector_out;
|
|
|
|
|
|
|
|
decode_node_uchar4(node.y, &itype, &ifrom, &ito, NULL);
|
|
|
|
decode_node_uchar4(node.z, &vector_in, &vector_out, NULL, NULL);
|
|
|
|
|
|
|
|
float3 in = stack_load_float3(stack, vector_in);
|
|
|
|
|
|
|
|
NodeVectorTransformType type = (NodeVectorTransformType)itype;
|
|
|
|
NodeVectorTransformConvertSpace from = (NodeVectorTransformConvertSpace)ifrom;
|
|
|
|
NodeVectorTransformConvertSpace to = (NodeVectorTransformConvertSpace)ito;
|
|
|
|
|
|
|
|
Transform tfm;
|
2014-03-29 12:03:47 +00:00
|
|
|
bool is_object = (sd->object != OBJECT_NONE);
|
2013-07-31 21:40:52 +00:00
|
|
|
bool is_direction = (type == NODE_VECTOR_TRANSFORM_TYPE_VECTOR || type == NODE_VECTOR_TRANSFORM_TYPE_NORMAL);
|
2013-07-31 21:18:23 +00:00
|
|
|
|
|
|
|
/* From world */
|
|
|
|
if(from == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_WORLD) {
|
|
|
|
if(to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_CAMERA) {
|
|
|
|
tfm = kernel_data.cam.worldtocamera;
|
|
|
|
if(is_direction)
|
|
|
|
in = transform_direction(&tfm, in);
|
|
|
|
else
|
|
|
|
in = transform_point(&tfm, in);
|
|
|
|
}
|
|
|
|
else if (to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT && is_object) {
|
|
|
|
if(is_direction)
|
|
|
|
object_inverse_dir_transform(kg, sd, &in);
|
|
|
|
else
|
|
|
|
object_inverse_position_transform(kg, sd, &in);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* From camera */
|
|
|
|
else if (from == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_CAMERA) {
|
|
|
|
if(to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_WORLD || to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT) {
|
|
|
|
tfm = kernel_data.cam.cameratoworld;
|
|
|
|
if(is_direction)
|
|
|
|
in = transform_direction(&tfm, in);
|
|
|
|
else
|
|
|
|
in = transform_point(&tfm, in);
|
|
|
|
}
|
|
|
|
if(to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT && is_object) {
|
|
|
|
if(is_direction)
|
|
|
|
object_inverse_dir_transform(kg, sd, &in);
|
|
|
|
else
|
|
|
|
object_inverse_position_transform(kg, sd, &in);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* From object */
|
|
|
|
else if(from == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT) {
|
|
|
|
if((to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_WORLD || to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_CAMERA) && is_object) {
|
|
|
|
if(is_direction)
|
|
|
|
object_dir_transform(kg, sd, &in);
|
|
|
|
else
|
|
|
|
object_position_transform(kg, sd, &in);
|
|
|
|
}
|
|
|
|
if(to == NODE_VECTOR_TRANSFORM_CONVERT_SPACE_CAMERA) {
|
|
|
|
tfm = kernel_data.cam.worldtocamera;
|
|
|
|
if(is_direction)
|
|
|
|
in = transform_direction(&tfm, in);
|
|
|
|
else
|
|
|
|
in = transform_point(&tfm, in);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Normalize Normal */
|
|
|
|
if(type == NODE_VECTOR_TRANSFORM_TYPE_NORMAL)
|
|
|
|
in = normalize(in);
|
|
|
|
|
2014-05-04 16:19:08 +00:00
|
|
|
/* Output */
|
2013-07-31 21:18:23 +00:00
|
|
|
if(stack_valid(vector_out)) {
|
2014-05-04 16:19:08 +00:00
|
|
|
stack_store_float3(stack, vector_out, in);
|
2013-07-31 21:18:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|