2 * Copyright 2011, Blender Foundation.
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.
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.
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.
23 __device void svm_node_light_path(ShaderData *sd, float *stack, uint type, uint out_offset, int path_flag)
28 case NODE_LP_camera: info = (path_flag & PATH_RAY_CAMERA)? 1.0f: 0.0f; break;
29 case NODE_LP_shadow: info = (path_flag & PATH_RAY_SHADOW)? 1.0f: 0.0f; break;
30 case NODE_LP_diffuse: info = (path_flag & PATH_RAY_DIFFUSE)? 1.0f: 0.0f; break;
31 case NODE_LP_glossy: info = (path_flag & PATH_RAY_GLOSSY)? 1.0f: 0.0f; break;
32 case NODE_LP_singular: info = (path_flag & PATH_RAY_SINGULAR)? 1.0f: 0.0f; break;
33 case NODE_LP_reflection: info = (path_flag & PATH_RAY_REFLECT)? 1.0f: 0.0f; break;
34 case NODE_LP_transmission: info = (path_flag & PATH_RAY_TRANSMIT)? 1.0f: 0.0f; break;
35 case NODE_LP_backfacing: info = (sd->flag & SD_BACKFACING)? 1.0f: 0.0f; break;
36 case NODE_LP_ray_length: info = sd->ray_length; break;
39 stack_store_float(stack, out_offset, info);
42 /* Light Falloff Node */
44 __device void svm_node_light_falloff(ShaderData *sd, float *stack, uint4 node)
46 uint strength_offset, out_offset, smooth_offset;
48 decode_node_uchar4(node.z, &strength_offset, &smooth_offset, &out_offset, NULL);
50 float strength = stack_load_float(stack, strength_offset);
54 case NODE_LIGHT_FALLOFF_QUADRATIC: break;
55 case NODE_LIGHT_FALLOFF_LINEAR: strength *= sd->ray_length; break;
56 case NODE_LIGHT_FALLOFF_CONSTANT: strength *= sd->ray_length*sd->ray_length; break;
59 float smooth = stack_load_float(stack, smooth_offset);
62 float squared = sd->ray_length*sd->ray_length;
63 strength *= squared/(smooth + squared);
66 stack_store_float(stack, out_offset, strength);