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.
21 /* Direction Emission */
23 __device float3 direct_emissive_eval(KernelGlobals *kg, float rando,
24 LightSample *ls, float u, float v, float3 I)
26 /* setup shading at emitter */
29 shader_setup_from_sample(kg, &sd, ls->P, ls->Ng, I, ls->shader, ls->object, ls->prim, u, v);
32 /* no path flag, we're evaluating this for all closures. that's weak but
33 we'd have to do multiple evaluations otherwise */
34 shader_eval_surface(kg, &sd, rando, 0);
38 /* evaluate emissive closure */
39 if(sd.flag & SD_EMISSION)
40 eval = shader_emissive_eval(kg, &sd);
42 eval = make_float3(0.0f, 0.0f, 0.0f);
44 shader_release(kg, &sd);
49 __device bool direct_emission(KernelGlobals *kg, ShaderData *sd, int lindex,
50 float randt, float rando, float randu, float randv, Ray *ray, float3 *eval)
54 #ifdef __MULTI_LIGHT__
56 /* sample position on a specified light */
57 light_select(kg, lindex, randu, randv, sd->P, &ls);
62 /* sample a light and position on int */
63 light_sample(kg, randt, randu, randv, sd->P, &ls);
66 /* compute incoming direction and distance */
68 float3 omega_in = normalize_len(ls.P - sd->P, &t);
71 float pdf = light_sample_pdf(kg, &ls, -omega_in, t);
73 /* evaluate closure */
74 *eval = direct_emissive_eval(kg, rando, &ls, randu, randv, -omega_in);
76 if(is_zero(*eval) || pdf == 0.0f)
79 /* todo: use visbility flag to skip lights */
81 /* evaluate BSDF at shading point */
83 float3 bsdf_eval = shader_bsdf_eval(kg, sd, omega_in, &bsdf_pdf);
85 *eval *= bsdf_eval/pdf;
91 /* multiple importance sampling */
92 float mis_weight = power_heuristic(pdf, bsdf_pdf);
96 /* ensure point light works in Watts, this should be handled
97 * elsewhere but for now together with the diffuse emission
98 * closure it works out to the right value */
103 /* todo: implement this in light */
104 bool no_shadow = true;
112 ray->P = ray_offset(sd->P, sd->Ng);
113 ray->D = ray_offset(ls.P, ls.Ng) - ray->P;
114 ray->D = normalize_len(ray->D, &ray->t);
122 /* Indirect Emission */
124 __device float3 indirect_emission(KernelGlobals *kg, ShaderData *sd, float t, int path_flag, float bsdf_pdf)
126 /* evaluate emissive closure */
127 float3 L = shader_emissive_eval(kg, sd);
129 if(!(path_flag & PATH_RAY_SINGULAR)) {
130 /* multiple importance sampling */
131 float pdf = triangle_light_pdf(kg, sd->Ng, sd->I, t);
132 float mis_weight = power_heuristic(bsdf_pdf, pdf);