Cycles: add Transparent Depth output to Light Path node.
[blender-staging.git] / intern / cycles / kernel / kernel_displace.h
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 ccl_device void kernel_shader_evaluate(KernelGlobals *kg, ccl_global uint4 *input, ccl_global float4 *output, ShaderEvalType type, int i)
20 {
21         ShaderData sd;
22         uint4 in = input[i];
23         float3 out;
24
25         if(type == SHADER_EVAL_DISPLACE) {
26                 /* setup shader data */
27                 int object = in.x;
28                 int prim = in.y;
29                 float u = __uint_as_float(in.z);
30                 float v = __uint_as_float(in.w);
31
32                 shader_setup_from_displace(kg, &sd, object, prim, u, v);
33
34                 /* evaluate */
35                 float3 P = sd.P;
36                 shader_eval_displacement(kg, &sd, SHADER_CONTEXT_MAIN);
37                 out = sd.P - P;
38         }
39         else { // SHADER_EVAL_BACKGROUND
40                 /* setup ray */
41                 Ray ray;
42                 float u = __uint_as_float(in.x);
43                 float v = __uint_as_float(in.y);
44
45                 ray.P = make_float3(0.0f, 0.0f, 0.0f);
46                 ray.D = equirectangular_to_direction(u, v);
47                 ray.t = 0.0f;
48 #ifdef __CAMERA_MOTION__
49                 ray.time = 0.5f;
50 #endif
51
52 #ifdef __RAY_DIFFERENTIALS__
53                 ray.dD = differential3_zero();
54                 ray.dP = differential3_zero();
55 #endif
56
57                 /* setup shader data */
58                 shader_setup_from_background(kg, &sd, &ray, 0, 0);
59
60                 /* evaluate */
61                 int flag = 0; /* we can't know which type of BSDF this is for */
62                 out = shader_eval_background(kg, &sd, flag, SHADER_CONTEXT_MAIN);
63         }
64         
65         /* write output */
66         output[i] = make_float4(out.x, out.y, out.z, 0.0f);
67 }
68
69 CCL_NAMESPACE_END
70