Cycles: CUDA bicubic and tricubic texture interpolation support.
[blender.git] / intern / cycles / kernel / svm / svm_voxel.h
1 /*
2  * Copyright 2011-2015 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 /* TODO(sergey): Think of making it more generic volume-type attribute
20  * sampler.
21  */
22 ccl_device void svm_node_tex_voxel(KernelGlobals *kg,
23                                    ShaderData *sd,
24                                    float *stack,
25                                    uint4 node,
26                                    int *offset)
27 {
28         uint co_offset, density_out_offset, color_out_offset, space;
29         decode_node_uchar4(node.z, &co_offset, &density_out_offset, &color_out_offset, &space);
30 #ifdef __VOLUME__
31         int id = node.y;
32         float3 co = stack_load_float3(stack, co_offset);
33         if(space == NODE_TEX_VOXEL_SPACE_OBJECT) {
34                 co = volume_normalized_position(kg, sd, co);
35         }
36         else {
37                 kernel_assert(space == NODE_TEX_VOXEL_SPACE_WORLD);
38                 Transform tfm;
39                 tfm.x = read_node_float(kg, offset);
40                 tfm.y = read_node_float(kg, offset);
41                 tfm.z = read_node_float(kg, offset);
42                 tfm.w = read_node_float(kg, offset);
43                 co = transform_point(&tfm, co);
44         }
45
46         float4 r = kernel_tex_image_interp_3d(kg, id, co.x, co.y, co.z, INTERPOLATION_NONE);
47 #else
48         float4 r = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
49 #endif
50         if(stack_valid(density_out_offset))
51                 stack_store_float(stack, density_out_offset, r.w);
52         if(stack_valid(color_out_offset))
53                 stack_store_float3(stack, color_out_offset, make_float3(r.x, r.y, r.z));
54 }
55
56 CCL_NAMESPACE_END