2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 02:50:24 +01:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
|
|
/* Direction Emission */
|
2019-08-22 17:36:54 +02:00
|
|
|
ccl_device_noinline_cpu float3 direct_emissive_eval(KernelGlobals *kg,
|
|
|
|
|
ShaderData *emission_sd,
|
|
|
|
|
LightSample *ls,
|
|
|
|
|
ccl_addr_space PathState *state,
|
|
|
|
|
float3 I,
|
|
|
|
|
differential3 dI,
|
|
|
|
|
float t,
|
|
|
|
|
float time)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
|
/* setup shading at emitter */
|
2021-02-17 01:47:18 +01:00
|
|
|
float3 eval = zero_float3();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-19 17:44:58 +01:00
|
|
|
if (shader_constant_emission_eval(kg, ls->shader, &eval)) {
|
2016-09-14 18:53:35 +02:00
|
|
|
if ((ls->prim != PRIM_NONE) && dot(ls->Ng, I) < 0.0f) {
|
|
|
|
|
ls->Ng = -ls->Ng;
|
|
|
|
|
}
|
2016-09-03 22:40:07 +02:00
|
|
|
}
|
2019-02-19 17:44:58 +01:00
|
|
|
else {
|
|
|
|
|
/* Setup shader data and call shader_eval_surface once, better
|
|
|
|
|
* for GPU coherence and compile times. */
|
|
|
|
|
#ifdef __BACKGROUND_MIS__
|
|
|
|
|
if (ls->type == LIGHT_BACKGROUND) {
|
|
|
|
|
Ray ray;
|
|
|
|
|
ray.D = ls->D;
|
|
|
|
|
ray.P = ls->P;
|
|
|
|
|
ray.t = 1.0f;
|
|
|
|
|
ray.time = time;
|
|
|
|
|
ray.dP = differential3_zero();
|
|
|
|
|
ray.dD = dI;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-19 17:44:58 +01:00
|
|
|
shader_setup_from_background(kg, emission_sd, &ray);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
shader_setup_from_sample(kg,
|
|
|
|
|
emission_sd,
|
|
|
|
|
ls->P,
|
|
|
|
|
ls->Ng,
|
|
|
|
|
I,
|
|
|
|
|
ls->shader,
|
|
|
|
|
ls->object,
|
|
|
|
|
ls->prim,
|
|
|
|
|
ls->u,
|
|
|
|
|
ls->v,
|
|
|
|
|
t,
|
|
|
|
|
time,
|
|
|
|
|
false,
|
|
|
|
|
ls->lamp);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-19 17:44:58 +01:00
|
|
|
ls->Ng = emission_sd->Ng;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-20 14:22:40 +01:00
|
|
|
/* No proper path flag, we're evaluating this for all closures. that's
|
|
|
|
|
* weak but we'd have to do multiple evaluations otherwise. */
|
2016-01-06 23:38:13 +01:00
|
|
|
path_state_modify_bounce(state, true);
|
2019-12-04 19:57:28 +01:00
|
|
|
shader_eval_surface(kg, emission_sd, state, NULL, PATH_RAY_EMISSION);
|
2016-01-06 23:38:13 +01:00
|
|
|
path_state_modify_bounce(state, false);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-19 17:44:58 +01:00
|
|
|
/* Evaluate closures. */
|
|
|
|
|
#ifdef __BACKGROUND_MIS__
|
|
|
|
|
if (ls->type == LIGHT_BACKGROUND) {
|
|
|
|
|
eval = shader_background_eval(emission_sd);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
#endif
|
|
|
|
|
{
|
|
|
|
|
eval = shader_emissive_eval(emission_sd);
|
|
|
|
|
}
|
2012-01-20 17:49:17 +00:00
|
|
|
}
|
2018-07-06 10:17:58 +02:00
|
|
|
|
2013-01-09 21:09:20 +00:00
|
|
|
eval *= ls->eval_fac;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-05-12 13:41:23 +02:00
|
|
|
if (ls->lamp != LAMP_NONE) {
|
|
|
|
|
const ccl_global KernelLight *klight = &kernel_tex_fetch(__lights, ls->lamp);
|
|
|
|
|
eval *= make_float3(klight->strength[0], klight->strength[1], klight->strength[2]);
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return eval;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-22 17:36:54 +02:00
|
|
|
ccl_device_noinline_cpu bool direct_emission(KernelGlobals *kg,
|
|
|
|
|
ShaderData *sd,
|
|
|
|
|
ShaderData *emission_sd,
|
|
|
|
|
LightSample *ls,
|
|
|
|
|
ccl_addr_space PathState *state,
|
|
|
|
|
Ray *ray,
|
|
|
|
|
BsdfEval *eval,
|
|
|
|
|
bool *is_lamp,
|
|
|
|
|
float rand_terminate)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2014-04-03 22:43:56 +02: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 */
|
Cycles: OpenCL kernel split
This commit contains all the work related on the AMD megakernel split work
which was mainly done by Varun Sundar, George Kyriazis and Lenny Wang, plus
some help from Sergey Sharybin, Martijn Berger, Thomas Dinges and likely
someone else which we're forgetting to mention.
Currently only AMD cards are enabled for the new split kernel, but it is
possible to force split opencl kernel to be used by setting the following
environment variable: CYCLES_OPENCL_SPLIT_KERNEL_TEST=1.
Not all the features are supported yet, and that being said no motion blur,
camera blur, SSS and volumetrics for now. Also transparent shadows are
disabled on AMD device because of some compiler bug.
This kernel is also only implements regular path tracing and supporting
branched one will take a bit. Branched path tracing is exposed to the
interface still, which is a bit misleading and will be hidden there soon.
More feature will be enabled once they're ported to the split kernel and
tested.
Neither regular CPU nor CUDA has any difference, they're generating the
same exact code, which means no regressions/improvements there.
Based on the research paper:
https://research.nvidia.com/sites/default/files/publications/laine2013hpg_paper.pdf
Here's the documentation:
https://docs.google.com/document/d/1LuXW-CV-sVJkQaEGZlMJ86jZ8FmoPfecaMdR-oiWbUY/edit
Design discussion of the patch:
https://developer.blender.org/T44197
Differential Revision: https://developer.blender.org/D1200
2015-05-09 19:34:30 +05:00
|
|
|
|
2016-01-14 19:58:22 +05:00
|
|
|
float3 light_eval = direct_emissive_eval(
|
2016-05-22 22:35:47 +02:00
|
|
|
kg, emission_sd, ls, state, -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 */
|
|
|
|
|
|
2013-12-29 15:40:43 +01:00
|
|
|
#ifdef __VOLUME__
|
2017-02-16 06:24:13 -05:00
|
|
|
if (sd->prim != PRIM_NONE)
|
2015-11-20 17:44:19 +01:00
|
|
|
shader_bsdf_eval(kg, sd, ls->D, eval, ls->pdf, ls->shader & SHADER_USE_MIS);
|
|
|
|
|
else {
|
|
|
|
|
float bsdf_pdf;
|
2014-04-03 22:43:56 +02:00
|
|
|
shader_volume_phase_eval(kg, sd, ls->D, eval, &bsdf_pdf);
|
2015-11-20 17:44:19 +01:00
|
|
|
if (ls->shader & SHADER_USE_MIS) {
|
|
|
|
|
/* Multiple importance sampling. */
|
|
|
|
|
float mis_weight = power_heuristic(ls->pdf, bsdf_pdf);
|
|
|
|
|
light_eval *= mis_weight;
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-29 15:40:43 +01:00
|
|
|
#else
|
2015-11-20 17:44:19 +01:00
|
|
|
shader_bsdf_eval(kg, sd, ls->D, eval, ls->pdf, ls->shader & SHADER_USE_MIS);
|
2013-12-29 15:40:43 +01:00
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2016-10-29 23:47:30 +02:00
|
|
|
bsdf_eval_mul3(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 */
|
2014-04-03 22:43:56 +02:00
|
|
|
if (ls->shader & SHADER_EXCLUDE_ANY) {
|
2020-02-14 12:20:12 +01:00
|
|
|
if (ls->shader & SHADER_EXCLUDE_DIFFUSE)
|
2021-02-17 01:47:18 +01:00
|
|
|
eval->diffuse = zero_float3();
|
2014-04-03 22:43:56 +02:00
|
|
|
if (ls->shader & SHADER_EXCLUDE_GLOSSY)
|
2021-02-17 01:47:18 +01:00
|
|
|
eval->glossy = zero_float3();
|
2014-04-03 22:43:56 +02:00
|
|
|
if (ls->shader & SHADER_EXCLUDE_TRANSMIT)
|
2021-02-17 01:47:18 +01:00
|
|
|
eval->transmission = zero_float3();
|
2014-09-05 16:17:24 +02:00
|
|
|
if (ls->shader & SHADER_EXCLUDE_SCATTER)
|
2021-02-17 01:47:18 +01:00
|
|
|
eval->volume = zero_float3();
|
2013-06-07 18:59:23 +00:00
|
|
|
}
|
|
|
|
|
#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
|
|
|
|
2017-02-09 14:19:01 +01:00
|
|
|
if (kernel_data.integrator.light_inv_rr_threshold > 0.0f
|
|
|
|
|
#ifdef __SHADOW_TRICKS__
|
|
|
|
|
&& (state->flag & PATH_RAY_SHADOW_CATCHER) == 0
|
|
|
|
|
#endif
|
|
|
|
|
) {
|
2017-03-20 14:48:37 +01:00
|
|
|
float probability = max3(fabs(bsdf_eval_sum(eval))) *
|
|
|
|
|
kernel_data.integrator.light_inv_rr_threshold;
|
2016-10-29 23:47:30 +02:00
|
|
|
if (probability < 1.0f) {
|
|
|
|
|
if (rand_terminate >= probability) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
bsdf_eval_mul(eval, 1.0f / probability);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-03 22:43:56 +02:00
|
|
|
if (ls->shader & SHADER_CAST_SHADOW) {
|
2011-09-27 20:37:24 +00:00
|
|
|
/* setup ray */
|
2017-02-16 06:24:13 -05:00
|
|
|
bool transmit = (dot(sd->Ng, ls->D) < 0.0f);
|
|
|
|
|
ray->P = ray_offset(sd->P, (transmit) ? -sd->Ng : sd->Ng);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-03 22:43:56 +02:00
|
|
|
if (ls->t == FLT_MAX) {
|
2011-09-27 20:37:24 +00:00
|
|
|
/* distant light */
|
2014-04-03 22:43:56 +02:00
|
|
|
ray->D = ls->D;
|
|
|
|
|
ray->t = ls->t;
|
2011-09-27 20:37:24 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* other lights, avoid self-intersection */
|
2014-04-03 22:43:56 +02:00
|
|
|
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
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-02-16 06:24:13 -05:00
|
|
|
ray->dP = sd->dP;
|
2013-05-03 21:34:51 +00:00
|
|
|
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
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-30 17:04:51 +00:00
|
|
|
/* return if it's a lamp for shadow pass */
|
2014-04-03 22:43:56 +02:00
|
|
|
*is_lamp = (ls->prim == PRIM_NONE && ls->type != LIGHT_BACKGROUND);
|
2019-04-17 06:17:24 +02: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
|
|
|
|
2019-08-22 17:36:54 +02:00
|
|
|
ccl_device_noinline_cpu float3 indirect_primitive_emission(
|
2013-11-16 00:17:10 +01:00
|
|
|
KernelGlobals *kg, ShaderData *sd, float t, int path_flag, float bsdf_pdf)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
|
/* evaluate emissive closure */
|
2019-02-19 17:44:58 +01:00
|
|
|
float3 L = shader_emissive_eval(sd);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-12-28 14:21:30 +00:00
|
|
|
#ifdef __HAIR__
|
2017-02-16 06:24:13 -05:00
|
|
|
if (!(path_flag & PATH_RAY_MIS_SKIP) && (sd->flag & SD_USE_MIS) &&
|
|
|
|
|
(sd->type & PRIMITIVE_ALL_TRIANGLE))
|
2012-12-28 14:21:30 +00:00
|
|
|
#else
|
2017-02-16 06:24:13 -05:00
|
|
|
if (!(path_flag & PATH_RAY_MIS_SKIP) && (sd->flag & SD_USE_MIS))
|
2012-12-28 14:21:30 +00:00
|
|
|
#endif
|
2014-05-05 02:19:08 +10:00
|
|
|
{
|
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 */
|
2017-08-17 12:44:09 +02:00
|
|
|
float pdf = triangle_light_pdf(kg, sd, t);
|
2011-04-27 11:58:34 +00:00
|
|
|
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 */
|
|
|
|
|
|
2019-12-08 21:19:37 +01:00
|
|
|
ccl_device_noinline_cpu void indirect_lamp_emission(KernelGlobals *kg,
|
2019-08-22 17:36:54 +02:00
|
|
|
ShaderData *emission_sd,
|
|
|
|
|
ccl_addr_space PathState *state,
|
2019-12-08 21:19:37 +01:00
|
|
|
PathRadiance *L,
|
2019-08-22 17:36:54 +02:00
|
|
|
Ray *ray,
|
2019-12-08 21:19:37 +01:00
|
|
|
float3 throughput)
|
2013-01-09 21:09:20 +00:00
|
|
|
{
|
2014-05-01 19:18:42 +02:00
|
|
|
for (int lamp = 0; lamp < kernel_data.integrator.num_all_lights; lamp++) {
|
2019-08-26 14:41:15 +02:00
|
|
|
LightSample ls ccl_optional_struct_init;
|
2014-05-01 19:18:42 +02:00
|
|
|
|
|
|
|
|
if (!lamp_light_eval(kg, lamp, ray->P, ray->D, ray->t, &ls))
|
|
|
|
|
continue;
|
2013-06-07 18:59:23 +00:00
|
|
|
|
|
|
|
|
#ifdef __PASSES__
|
2014-05-01 19:18:42 +02:00
|
|
|
/* use visibility flag to skip lights */
|
|
|
|
|
if (ls.shader & SHADER_EXCLUDE_ANY) {
|
|
|
|
|
if (((ls.shader & SHADER_EXCLUDE_DIFFUSE) && (state->flag & PATH_RAY_DIFFUSE)) ||
|
2015-03-25 14:48:41 +05:00
|
|
|
((ls.shader & SHADER_EXCLUDE_GLOSSY) &&
|
|
|
|
|
((state->flag & (PATH_RAY_GLOSSY | PATH_RAY_REFLECT)) ==
|
|
|
|
|
(PATH_RAY_GLOSSY | PATH_RAY_REFLECT))) ||
|
2014-09-05 16:17:24 +02:00
|
|
|
((ls.shader & SHADER_EXCLUDE_TRANSMIT) && (state->flag & PATH_RAY_TRANSMIT)) ||
|
|
|
|
|
((ls.shader & SHADER_EXCLUDE_SCATTER) && (state->flag & PATH_RAY_VOLUME_SCATTER)))
|
2014-05-01 19:18:42 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
2013-06-07 18:59:23 +00:00
|
|
|
#endif
|
|
|
|
|
|
2019-12-08 21:19:37 +01:00
|
|
|
float3 lamp_L = direct_emissive_eval(
|
2016-05-22 22:35:47 +02:00
|
|
|
kg, emission_sd, &ls, state, -ray->D, ray->dD, ls.t, ray->time);
|
2013-01-09 21:09:20 +00:00
|
|
|
|
2014-04-04 16:45:49 +02:00
|
|
|
#ifdef __VOLUME__
|
|
|
|
|
if (state->volume_stack[0].shader != SHADER_NONE) {
|
|
|
|
|
/* shadow attenuation */
|
|
|
|
|
Ray volume_ray = *ray;
|
|
|
|
|
volume_ray.t = ls.t;
|
2021-02-17 01:47:18 +01:00
|
|
|
float3 volume_tp = one_float3();
|
2016-05-22 22:35:47 +02:00
|
|
|
kernel_volume_shadow(kg, emission_sd, state, &volume_ray, &volume_tp);
|
2019-12-08 21:19:37 +01:00
|
|
|
lamp_L *= volume_tp;
|
2014-04-04 16:45:49 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2014-05-01 19:18:42 +02:00
|
|
|
if (!(state->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(state->ray_pdf, ls.pdf);
|
2019-12-08 21:19:37 +01:00
|
|
|
lamp_L *= mis_weight;
|
2014-05-01 19:18:42 +02:00
|
|
|
}
|
|
|
|
|
|
2019-12-08 21:19:37 +01:00
|
|
|
path_radiance_accum_emission(kg, L, state, throughput, lamp_L);
|
2013-01-09 21:09:20 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
/* Indirect Background */
|
|
|
|
|
|
2019-08-22 17:36:54 +02:00
|
|
|
ccl_device_noinline_cpu float3 indirect_background(KernelGlobals *kg,
|
|
|
|
|
ShaderData *emission_sd,
|
|
|
|
|
ccl_addr_space PathState *state,
|
2019-12-04 19:57:28 +01:00
|
|
|
ccl_global float *buffer,
|
2019-08-22 17:36:54 +02:00
|
|
|
ccl_addr_space Ray *ray)
|
2012-01-20 17:49:17 +00:00
|
|
|
{
|
|
|
|
|
#ifdef __BACKGROUND__
|
2013-12-28 02:27:48 +01:00
|
|
|
int shader = kernel_data.background.surface_shader;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-19 17:44:58 +01:00
|
|
|
/* Use visibility flag to skip lights. */
|
2013-06-10 20:34:34 +00:00
|
|
|
if (shader & SHADER_EXCLUDE_ANY) {
|
2014-04-21 17:51:51 +02:00
|
|
|
if (((shader & SHADER_EXCLUDE_DIFFUSE) && (state->flag & PATH_RAY_DIFFUSE)) ||
|
2015-03-25 14:48:41 +05:00
|
|
|
((shader & SHADER_EXCLUDE_GLOSSY) &&
|
|
|
|
|
((state->flag & (PATH_RAY_GLOSSY | PATH_RAY_REFLECT)) ==
|
|
|
|
|
(PATH_RAY_GLOSSY | PATH_RAY_REFLECT))) ||
|
2014-04-21 17:51:51 +02:00
|
|
|
((shader & SHADER_EXCLUDE_TRANSMIT) && (state->flag & PATH_RAY_TRANSMIT)) ||
|
2014-09-05 16:17:24 +02:00
|
|
|
((shader & SHADER_EXCLUDE_CAMERA) && (state->flag & PATH_RAY_CAMERA)) ||
|
|
|
|
|
((shader & SHADER_EXCLUDE_SCATTER) && (state->flag & PATH_RAY_VOLUME_SCATTER)))
|
2021-02-17 01:47:18 +01:00
|
|
|
return zero_float3();
|
2013-06-10 20:34:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-19 17:44:58 +01:00
|
|
|
/* Evaluate background shader. */
|
2021-02-17 01:47:18 +01:00
|
|
|
float3 L = zero_float3();
|
2019-02-19 17:44:58 +01:00
|
|
|
if (!shader_constant_emission_eval(kg, shader, &L)) {
|
2016-02-12 18:33:43 +01:00
|
|
|
# ifdef __SPLIT_KERNEL__
|
2019-02-19 17:44:58 +01:00
|
|
|
Ray priv_ray = *ray;
|
|
|
|
|
shader_setup_from_background(kg, emission_sd, &priv_ray);
|
2016-02-12 18:33:43 +01:00
|
|
|
# else
|
2019-02-19 17:44:58 +01:00
|
|
|
shader_setup_from_background(kg, emission_sd, ray);
|
2016-05-22 22:35:47 +02:00
|
|
|
# endif
|
2013-06-10 20:34:34 +00:00
|
|
|
|
2019-02-19 17:44:58 +01:00
|
|
|
path_state_modify_bounce(state, true);
|
2019-12-04 19:57:28 +01:00
|
|
|
shader_eval_surface(kg, emission_sd, state, buffer, state->flag | PATH_RAY_EMISSION);
|
2019-02-19 17:44:58 +01:00
|
|
|
path_state_modify_bounce(state, false);
|
|
|
|
|
|
|
|
|
|
L = shader_background_eval(emission_sd);
|
|
|
|
|
}
|
2012-01-20 17:49:17 +00:00
|
|
|
|
2019-02-19 17:44:58 +01:00
|
|
|
/* Background MIS weights. */
|
2012-01-26 19:45:59 +00:00
|
|
|
# ifdef __BACKGROUND_MIS__
|
2019-02-19 17:44:58 +01:00
|
|
|
/* Check if background light exists or if we should skip pdf. */
|
Cycles: Add new Sky Texture method including direct sunlight
This commit adds a new model to the Sky Texture node, which is based on a
method by Nishita et al. and works by basically simulating volumetric
scattering in the atmosphere.
By making some approximations (such as only considering single scattering),
we get a fairly simple and fast simulation code that takes into account
Rayleigh and Mie scattering as well as Ozone absorption.
This code is used to precompute a 512x128 texture which is then looked up
during render time, and is fast enough to allow real-time tweaking in the
viewport.
Due to the nature of the simulation, it exposes several parameters that
allow for lots of flexibility in choosing the look and matching real-world
conditions (such as Air/Dust/Ozone density and altitude).
Additionally, the same volumetric approach can be used to compute absorption
of the direct sunlight, so the model also supports adding direct sunlight.
This makes it significantly easier to set up Sun+Sky illumination where
the direction, intensity and color of the sun actually matches the sky.
In order to support properly sampling the direct sun component, the commit
also adds logic for sampling a specific area to the kernel light sampling
code. This is combined with portal and background map sampling using MIS.
This sampling logic works for the common case of having one Sky texture
going into the Background shader, but if a custom input to the Vector
node is used or if there are multiple Sky textures, it falls back to using
only background map sampling (while automatically setting the resolution to
4096x2048 if auto resolution is used).
More infos and preview can be found here:
https://docs.google.com/document/d/1gQta0ygFWXTrl5Pmvl_nZRgUw0mWg0FJeRuNKS36m08/view
Underlying model, implementation and documentation by Marco (@nacioss).
Improvements, cleanup and sun sampling by @lukasstockner.
Differential Revision: https://developer.blender.org/D7896
2020-06-17 20:27:10 +02:00
|
|
|
if (!(state->flag & PATH_RAY_MIS_SKIP) && kernel_data.background.use_mis) {
|
2012-01-20 17:49:17 +00:00
|
|
|
/* 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 */
|
Cycles: Added support for light portals
This patch adds support for light portals: objects that help sampling the
environment light, therefore improving convergence. Using them tor other
lights in a unidirectional pathtracer is virtually useless.
The sampling is done with the area-preserving code already used for area lamps.
MIS is used both for combination of different portals and for combining portal-
and envmap-sampling.
The direction of portals is considered, they aren't used if the sampling point
is behind them.
Reviewers: sergey, dingto, #cycles
Reviewed By: dingto, #cycles
Subscribers: Lapineige, nutel, jtheninja, dsisco11, januz, vitorbalbio, candreacchio, TARDISMaker, lichtwerk, ace_dragon, marcog, mib2berlin, Tunge, lopataasdf, lordodin, sergey, dingto
Differential Revision: https://developer.blender.org/D1133
2015-04-28 00:51:55 +05:00
|
|
|
float pdf = background_light_pdf(kg, ray->P, ray->D);
|
2014-04-21 17:51:51 +02:00
|
|
|
float mis_weight = power_heuristic(state->ray_pdf, pdf);
|
2012-01-20 17:49:17 +00:00
|
|
|
|
|
|
|
|
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
|