2011-04-27 11:58:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011, Blender Foundation.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/* Direction Emission */
|
|
|
|
|
2013-02-11 22:41:11 +00:00
|
|
|
__device_noinline float3 direct_emissive_eval(KernelGlobals *kg, float rando,
|
2013-05-03 05:24:05 +00:00
|
|
|
LightSample *ls, float u, float v, float3 I, differential3 dI, float t, float time)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
/* setup shading at emitter */
|
|
|
|
ShaderData sd;
|
|
|
|
float3 eval;
|
|
|
|
|
2012-01-26 19:45:59 +00:00
|
|
|
#ifdef __BACKGROUND_MIS__
|
2012-01-20 17:49:17 +00:00
|
|
|
if(ls->type == LIGHT_BACKGROUND) {
|
|
|
|
Ray ray;
|
|
|
|
ray.D = ls->D;
|
|
|
|
ray.P = ls->P;
|
2012-10-18 12:45:27 +00:00
|
|
|
ray.t = 1.0f;
|
|
|
|
#ifdef __OBJECT_MOTION__
|
|
|
|
ray.time = time;
|
|
|
|
#endif
|
2013-05-03 21:34:51 +00:00
|
|
|
ray.dP = differential3_zero();
|
2013-05-03 05:24:05 +00:00
|
|
|
ray.dD = dI;
|
2012-10-17 22:48:29 +00:00
|
|
|
#ifdef __CAMERA_MOTION__
|
|
|
|
ray.time = time;
|
|
|
|
#endif
|
2012-01-20 17:49:17 +00:00
|
|
|
shader_setup_from_background(kg, &sd, &ray);
|
2012-12-15 10:18:42 +00:00
|
|
|
eval = shader_eval_background(kg, &sd, 0, SHADER_CONTEXT_EMISSION);
|
2012-01-20 17:49:17 +00:00
|
|
|
}
|
2012-01-26 19:45:59 +00:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
2012-12-28 14:21:30 +00:00
|
|
|
#ifdef __HAIR__
|
|
|
|
if(ls->type == LIGHT_STRAND)
|
|
|
|
shader_setup_from_sample(kg, &sd, ls->P, ls->Ng, I, ls->shader, ls->object, ls->prim, u, v, t, time, ls->prim);
|
|
|
|
else
|
|
|
|
#endif
|
2013-05-09 14:05:40 +00:00
|
|
|
shader_setup_from_sample(kg, &sd, ls->P, ls->Ng, I, ls->shader, ls->object, ls->prim, u, v, t, time, ~0);
|
2012-12-28 14:21:30 +00:00
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
ls->Ng = sd.Ng;
|
|
|
|
|
|
|
|
/* no path flag, we're evaluating this for all closures. that's weak but
|
2012-06-09 17:22:52 +00:00
|
|
|
* we'd have to do multiple evaluations otherwise */
|
2012-12-15 10:18:42 +00:00
|
|
|
shader_eval_surface(kg, &sd, rando, 0, SHADER_CONTEXT_EMISSION);
|
2012-01-20 17:49:17 +00:00
|
|
|
|
|
|
|
/* evaluate emissive closure */
|
|
|
|
if(sd.flag & SD_EMISSION)
|
|
|
|
eval = shader_emissive_eval(kg, &sd);
|
|
|
|
else
|
|
|
|
eval = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
}
|
2013-01-09 21:09:20 +00:00
|
|
|
|
|
|
|
eval *= ls->eval_fac;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
return eval;
|
|
|
|
}
|
|
|
|
|
2013-02-11 22:41:11 +00:00
|
|
|
__device_noinline bool direct_emission(KernelGlobals *kg, ShaderData *sd, int lindex,
|
2012-03-28 10:39:21 +00:00
|
|
|
float randt, float rando, float randu, float randv, Ray *ray, BsdfEval *eval,
|
2013-01-30 17:04:51 +00:00
|
|
|
bool *is_lamp)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
LightSample ls;
|
|
|
|
|
2012-06-13 11:44:48 +00:00
|
|
|
#ifdef __NON_PROGRESSIVE__
|
2011-09-12 13:13:56 +00:00
|
|
|
if(lindex != -1) {
|
|
|
|
/* sample position on a specified light */
|
2013-01-09 21:09:20 +00:00
|
|
|
light_select(kg, lindex, randu, randv, sd->P, &ls);
|
2011-09-12 13:13:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
/* sample a light and position on int */
|
2013-01-09 21:09:20 +00:00
|
|
|
light_sample(kg, randt, randu, randv, sd->time, sd->P, &ls);
|
2011-09-12 13:13:56 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-01-09 21:09:20 +00:00
|
|
|
if(ls.pdf == 0.0f)
|
2012-01-20 17:49:17 +00:00
|
|
|
return false;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-05-03 05:24:05 +00:00
|
|
|
/* todo: implement */
|
2013-05-03 21:34:51 +00:00
|
|
|
differential3 dD = differential3_zero();
|
2013-05-03 05:24:05 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* evaluate closure */
|
2013-05-03 05:24:05 +00:00
|
|
|
float3 light_eval = direct_emissive_eval(kg, rando, &ls, randu, randv, -ls.D, dD, ls.t, sd->time);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
if(is_zero(light_eval))
|
2011-04-27 11:58:34 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* evaluate BSDF at shading point */
|
|
|
|
float bsdf_pdf;
|
|
|
|
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
shader_bsdf_eval(kg, sd, ls.D, eval, &bsdf_pdf);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-01-30 15:57:15 +00:00
|
|
|
if(ls.shader & SHADER_USE_MIS) {
|
2011-04-27 11:58:34 +00:00
|
|
|
/* multiple importance sampling */
|
2013-01-09 21:09:20 +00:00
|
|
|
float mis_weight = power_heuristic(ls.pdf, bsdf_pdf);
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
light_eval *= mis_weight;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
|
2013-01-09 21:09:20 +00:00
|
|
|
bsdf_eval_mul(eval, light_eval/ls.pdf);
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
|
2013-06-07 18:59:23 +00:00
|
|
|
#ifdef __PASSES__
|
|
|
|
/* use visibility flag to skip lights */
|
|
|
|
if(ls.shader & SHADER_EXCLUDE_ANY) {
|
|
|
|
if(ls.shader & SHADER_EXCLUDE_DIFFUSE)
|
|
|
|
eval->diffuse = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
if(ls.shader & SHADER_EXCLUDE_GLOSSY)
|
|
|
|
eval->glossy = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
if(ls.shader & SHADER_EXCLUDE_TRANSMIT)
|
|
|
|
eval->transmission = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
if(bsdf_eval_is_zero(eval))
|
|
|
|
return false;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-09-27 20:37:24 +00:00
|
|
|
if(ls.shader & SHADER_CAST_SHADOW) {
|
|
|
|
/* setup ray */
|
2012-01-30 18:34:01 +00:00
|
|
|
bool transmit = (dot(sd->Ng, ls.D) < 0.0f);
|
|
|
|
ray->P = ray_offset(sd->P, (transmit)? -sd->Ng: sd->Ng);
|
2011-09-12 13:13:56 +00:00
|
|
|
|
2011-09-27 20:37:24 +00:00
|
|
|
if(ls.t == FLT_MAX) {
|
|
|
|
/* distant light */
|
|
|
|
ray->D = ls.D;
|
|
|
|
ray->t = ls.t;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* other lights, avoid self-intersection */
|
|
|
|
ray->D = ray_offset(ls.P, ls.Ng) - ray->P;
|
2013-06-04 17:20:00 +00:00
|
|
|
ray->D = normalize_len(ray->D, &ray->t);
|
2011-09-27 20:37:24 +00:00
|
|
|
}
|
2013-05-03 21:34:51 +00:00
|
|
|
|
|
|
|
ray->dP = sd->dP;
|
|
|
|
ray->dD = differential3_zero();
|
2011-09-12 13:13:56 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-09-27 20:37:24 +00:00
|
|
|
/* signal to not cast shadow ray */
|
|
|
|
ray->t = 0.0f;
|
2011-09-12 13:13:56 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-01-30 17:04:51 +00:00
|
|
|
/* return if it's a lamp for shadow pass */
|
2013-02-13 16:46:18 +00:00
|
|
|
*is_lamp = (ls.prim == ~0 && ls.type != LIGHT_BACKGROUND);
|
2013-01-30 17:04:51 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-01-09 21:09:20 +00:00
|
|
|
/* Indirect Primitive Emission */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-02-11 22:41:11 +00:00
|
|
|
__device_noinline float3 indirect_primitive_emission(KernelGlobals *kg, ShaderData *sd, float t, int path_flag, float bsdf_pdf)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
/* evaluate emissive closure */
|
|
|
|
float3 L = shader_emissive_eval(kg, sd);
|
|
|
|
|
2012-12-28 14:21:30 +00:00
|
|
|
#ifdef __HAIR__
|
2013-01-03 12:09:09 +00:00
|
|
|
if(!(path_flag & PATH_RAY_MIS_SKIP) && (sd->flag & SD_SAMPLE_AS_LIGHT) && (sd->segment == ~0)) {
|
2012-12-28 14:21:30 +00:00
|
|
|
#else
|
2011-10-16 17:54:43 +00:00
|
|
|
if(!(path_flag & PATH_RAY_MIS_SKIP) && (sd->flag & SD_SAMPLE_AS_LIGHT)) {
|
2012-12-28 14:21:30 +00:00
|
|
|
#endif
|
2012-01-20 17:49:17 +00:00
|
|
|
/* multiple importance sampling, get triangle light pdf,
|
2012-06-09 17:22:52 +00:00
|
|
|
* and compute weight with respect to BSDF pdf */
|
2011-04-27 11:58:34 +00:00
|
|
|
float pdf = triangle_light_pdf(kg, sd->Ng, sd->I, t);
|
|
|
|
float mis_weight = power_heuristic(bsdf_pdf, pdf);
|
|
|
|
|
|
|
|
return L*mis_weight;
|
|
|
|
}
|
|
|
|
|
|
|
|
return L;
|
|
|
|
}
|
|
|
|
|
2013-01-09 21:09:20 +00:00
|
|
|
/* Indirect Lamp Emission */
|
|
|
|
|
2013-02-11 22:41:11 +00:00
|
|
|
__device_noinline bool indirect_lamp_emission(KernelGlobals *kg, Ray *ray, int path_flag, float bsdf_pdf, float randt, float3 *emission)
|
2013-01-09 21:09:20 +00:00
|
|
|
{
|
|
|
|
LightSample ls;
|
|
|
|
int lamp = lamp_light_eval_sample(kg, randt);
|
|
|
|
|
|
|
|
if(lamp == ~0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(!lamp_light_eval(kg, lamp, ray->P, ray->D, ray->t, &ls))
|
|
|
|
return false;
|
2013-06-07 18:59:23 +00:00
|
|
|
|
|
|
|
#ifdef __PASSES__
|
|
|
|
/* use visibility flag to skip lights */
|
|
|
|
if(ls.shader & SHADER_EXCLUDE_ANY) {
|
|
|
|
if((ls.shader & SHADER_EXCLUDE_DIFFUSE) && (path_flag & PATH_RAY_DIFFUSE))
|
|
|
|
return false;
|
|
|
|
if((ls.shader & SHADER_EXCLUDE_GLOSSY) && (path_flag & PATH_RAY_GLOSSY))
|
|
|
|
return false;
|
|
|
|
if((ls.shader & SHADER_EXCLUDE_TRANSMIT) && (path_flag & PATH_RAY_TRANSMIT))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-01-09 21:09:20 +00:00
|
|
|
/* todo: missing texture coordinates */
|
|
|
|
float u = 0.0f;
|
|
|
|
float v = 0.0f;
|
2013-05-03 05:24:05 +00:00
|
|
|
float3 L = direct_emissive_eval(kg, 0.0f, &ls, u, v, -ray->D, ray->dD, ls.t, ray->time);
|
2013-01-09 21:09:20 +00:00
|
|
|
|
|
|
|
if(!(path_flag & PATH_RAY_MIS_SKIP)) {
|
|
|
|
/* multiple importance sampling, get regular light pdf,
|
|
|
|
* and compute weight with respect to BSDF pdf */
|
|
|
|
float mis_weight = power_heuristic(bsdf_pdf, ls.pdf);
|
|
|
|
L *= mis_weight;
|
|
|
|
}
|
|
|
|
|
|
|
|
*emission = L;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
/* Indirect Background */
|
|
|
|
|
2013-02-11 22:41:11 +00:00
|
|
|
__device_noinline float3 indirect_background(KernelGlobals *kg, Ray *ray, int path_flag, float bsdf_pdf)
|
2012-01-20 17:49:17 +00:00
|
|
|
{
|
|
|
|
#ifdef __BACKGROUND__
|
|
|
|
/* evaluate background closure */
|
|
|
|
ShaderData sd;
|
|
|
|
shader_setup_from_background(kg, &sd, ray);
|
2012-12-15 10:18:42 +00:00
|
|
|
float3 L = shader_eval_background(kg, &sd, path_flag, SHADER_CONTEXT_EMISSION);
|
2012-01-20 17:49:17 +00:00
|
|
|
|
2012-01-26 19:45:59 +00:00
|
|
|
#ifdef __BACKGROUND_MIS__
|
2012-01-20 17:49:17 +00:00
|
|
|
/* check if background light exists or if we should skip pdf */
|
|
|
|
int res = kernel_data.integrator.pdf_background_res;
|
|
|
|
|
|
|
|
if(!(path_flag & PATH_RAY_MIS_SKIP) && res) {
|
|
|
|
/* multiple importance sampling, get background light pdf for ray
|
2012-06-09 17:22:52 +00:00
|
|
|
* direction, and compute weight with respect to BSDF pdf */
|
2012-01-20 17:49:17 +00:00
|
|
|
float pdf = background_light_pdf(kg, ray->D);
|
|
|
|
float mis_weight = power_heuristic(bsdf_pdf, pdf);
|
|
|
|
|
|
|
|
return L*mis_weight;
|
|
|
|
}
|
2012-01-26 19:45:59 +00:00
|
|
|
#endif
|
2012-01-20 17:49:17 +00:00
|
|
|
|
|
|
|
return L;
|
|
|
|
#else
|
|
|
|
return make_float3(0.8f, 0.8f, 0.8f);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|