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_set_bump(ShaderData *sd, float *stack, uint c_offset, uint x_offset, uint y_offset)
25 #ifdef __RAY_DIFFERENTIALS__
26 float h_c = stack_load_float(stack, c_offset);
27 float h_x = stack_load_float(stack, x_offset);
28 float h_y = stack_load_float(stack, y_offset);
30 float3 Rx = cross(sd->dP.dy, sd->N);
31 float3 Ry = cross(sd->N, sd->dP.dx);
33 float det = dot(sd->dP.dx, Rx);
34 float3 surfgrad = (h_x - h_c)*Rx + (h_y - h_c)*Ry;
36 surfgrad *= 0.1f; /* todo: remove this factor */
38 sd->N = normalize(fabsf(det)*sd->N - signf(det)*surfgrad);
42 /* Displacement Node */
44 __device void svm_node_set_displacement(ShaderData *sd, float *stack, uint fac_offset)
46 float d = stack_load_float(stack, fac_offset);
47 sd->P += sd->N*d*0.1f; /* todo: get rid of this factor */