Cycles / Ray Depth:
[blender.git] / intern / cycles / kernel / kernel_displace.h
1 /*
2  * Copyright 2011, Blender Foundation.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18
19 CCL_NAMESPACE_BEGIN
20
21 __device void kernel_shader_evaluate(KernelGlobals *kg, __global uint4 *input, __global float4 *output, ShaderEvalType type, int i)
22 {
23         ShaderData sd;
24         uint4 in = input[i];
25         float3 out;
26
27         if(type == SHADER_EVAL_DISPLACE) {
28                 /* setup shader data */
29                 int object = in.x;
30                 int prim = in.y;
31                 float u = __uint_as_float(in.z);
32                 float v = __uint_as_float(in.w);
33
34                 shader_setup_from_displace(kg, &sd, object, prim, u, v);
35
36                 /* evaluate */
37                 float3 P = sd.P;
38                 shader_eval_displacement(kg, &sd, SHADER_CONTEXT_MAIN);
39                 out = sd.P - P;
40         }
41         else { // SHADER_EVAL_BACKGROUND
42                 /* setup ray */
43                 Ray ray;
44                 float u = __uint_as_float(in.x);
45                 float v = __uint_as_float(in.y);
46
47                 ray.P = make_float3(0.0f, 0.0f, 0.0f);
48                 ray.D = equirectangular_to_direction(u, v);
49                 ray.t = 0.0f;
50 #ifdef __CAMERA_MOTION__
51                 ray.time = 0.5f;
52 #endif
53
54 #ifdef __RAY_DIFFERENTIALS__
55                 ray.dD = differential3_zero();
56                 ray.dP = differential3_zero();
57 #endif
58
59                 /* setup shader data */
60                 shader_setup_from_background(kg, &sd, &ray, 0);
61
62                 /* evaluate */
63                 int flag = 0; /* we can't know which type of BSDF this is for */
64                 out = shader_eval_background(kg, &sd, flag, SHADER_CONTEXT_MAIN);
65         }
66         
67         /* write output */
68         output[i] = make_float4(out.x, out.y, out.z, 0.0f);
69 }
70
71 CCL_NAMESPACE_END
72