2013-12-28 01:56:53 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011-2013 Blender Foundation
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* 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 01:50:24 +00:00
|
|
|
* limitations under the License.
|
2013-12-28 01:56:53 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2014-04-19 15:02:30 +00:00
|
|
|
#ifdef __SHADOW_RECORD_ALL__
|
|
|
|
|
|
|
|
/* Shadow function to compute how much light is blocked, CPU variation.
|
|
|
|
*
|
|
|
|
* We trace a single ray. If it hits any opaque surface, or more than a given
|
|
|
|
* number of transparent surfaces is hit, then we consider the geometry to be
|
|
|
|
* entirely blocked. If not, all transparent surfaces will be recorded and we
|
|
|
|
* will shade them one by one to determine how much light is blocked. This all
|
|
|
|
* happens in one scene intersection function.
|
|
|
|
*
|
|
|
|
* Recording all hits works well in some cases but may be slower in others. If
|
|
|
|
* we have many semi-transparent hairs, one intersection may be faster because
|
|
|
|
* you'd be reinteresecting the same hairs a lot with each step otherwise. If
|
|
|
|
* however there is mostly binary transparency then we may be recording many
|
|
|
|
* unnecessary intersections when one of the first surfaces blocks all light.
|
|
|
|
*
|
|
|
|
* From tests in real scenes it seems the performance loss is either minimal,
|
|
|
|
* or there is a performance increase anyway due to avoiding the need to send
|
|
|
|
* two rays with transparent shadows.
|
|
|
|
*
|
|
|
|
* This is CPU only because of qsort, and malloc or high stack space usage to
|
|
|
|
* record all these intersections. */
|
|
|
|
|
|
|
|
#define STACK_MAX_HITS 64
|
|
|
|
|
2016-05-22 20:35:47 +00:00
|
|
|
ccl_device_inline bool shadow_blocked(KernelGlobals *kg, ShaderData *shadow_sd, PathState *state, Ray *ray, float3 *shadow)
|
2013-12-28 01:56:53 +00:00
|
|
|
{
|
|
|
|
*shadow = make_float3(1.0f, 1.0f, 1.0f);
|
|
|
|
|
2014-04-19 15:02:30 +00:00
|
|
|
if(ray->t == 0.0f)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
bool blocked;
|
|
|
|
|
|
|
|
if(kernel_data.integrator.transparent_shadows) {
|
2014-06-30 09:40:04 +00:00
|
|
|
/* check transparent bounces here, for volume scatter which can do
|
|
|
|
* lighting before surface path termination is checked */
|
2014-06-30 10:54:52 +00:00
|
|
|
if(state->transparent_bounce >= kernel_data.integrator.transparent_max_bounce)
|
2014-06-30 09:40:04 +00:00
|
|
|
return true;
|
|
|
|
|
2014-04-19 15:02:30 +00:00
|
|
|
/* intersect to find an opaque surface, or record all transparent surface hits */
|
|
|
|
Intersection hits_stack[STACK_MAX_HITS];
|
2014-06-30 09:40:04 +00:00
|
|
|
Intersection *hits = hits_stack;
|
2016-05-17 10:30:46 +00:00
|
|
|
const int transparent_max_bounce = kernel_data.integrator.transparent_max_bounce;
|
|
|
|
uint max_hits = transparent_max_bounce - state->transparent_bounce - 1;
|
2014-04-19 15:02:30 +00:00
|
|
|
|
|
|
|
/* prefer to use stack but use dynamic allocation if too deep max hits
|
|
|
|
* we need max_hits + 1 storage space due to the logic in
|
|
|
|
* scene_intersect_shadow_all which will first store and then check if
|
|
|
|
* the limit is exceeded */
|
2016-05-17 10:30:46 +00:00
|
|
|
if(max_hits + 1 > STACK_MAX_HITS) {
|
|
|
|
if(kg->transparent_shadow_intersections == NULL) {
|
|
|
|
kg->transparent_shadow_intersections =
|
|
|
|
(Intersection*)malloc(sizeof(Intersection)*(transparent_max_bounce + 1));
|
|
|
|
}
|
|
|
|
hits = kg->transparent_shadow_intersections;
|
|
|
|
}
|
2014-04-19 15:02:30 +00:00
|
|
|
|
|
|
|
uint num_hits;
|
2016-07-26 14:30:13 +00:00
|
|
|
blocked = scene_intersect_shadow_all(kg, ray, hits, max_hits, &num_hits);
|
2014-04-19 15:02:30 +00:00
|
|
|
|
|
|
|
/* if no opaque surface found but we did find transparent hits, shade them */
|
|
|
|
if(!blocked && num_hits > 0) {
|
|
|
|
float3 throughput = make_float3(1.0f, 1.0f, 1.0f);
|
|
|
|
float3 Pend = ray->P + ray->D*ray->t;
|
|
|
|
float last_t = 0.0f;
|
|
|
|
int bounce = state->transparent_bounce;
|
|
|
|
Intersection *isect = hits;
|
|
|
|
#ifdef __VOLUME__
|
|
|
|
PathState ps = *state;
|
|
|
|
#endif
|
|
|
|
|
2015-04-29 21:21:05 +00:00
|
|
|
qsort(hits, num_hits, sizeof(Intersection), intersections_compare);
|
2014-04-19 15:02:30 +00:00
|
|
|
|
|
|
|
for(int hit = 0; hit < num_hits; hit++, isect++) {
|
|
|
|
/* adjust intersection distance for moving ray forward */
|
|
|
|
float new_t = isect->t;
|
|
|
|
isect->t -= last_t;
|
|
|
|
|
|
|
|
/* skip hit if we did not move forward, step by step raytracing
|
|
|
|
* would have skipped it as well then */
|
|
|
|
if(last_t == new_t)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
last_t = new_t;
|
|
|
|
|
|
|
|
#ifdef __VOLUME__
|
|
|
|
/* attenuation between last surface and next surface */
|
|
|
|
if(ps.volume_stack[0].shader != SHADER_NONE) {
|
|
|
|
Ray segment_ray = *ray;
|
|
|
|
segment_ray.t = isect->t;
|
2016-05-22 20:35:47 +00:00
|
|
|
kernel_volume_shadow(kg, shadow_sd, &ps, &segment_ray, &throughput);
|
2014-04-19 15:02:30 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* setup shader data at surface */
|
2016-05-22 20:35:47 +00:00
|
|
|
shader_setup_from_ray(kg, shadow_sd, isect, ray);
|
2014-04-19 15:02:30 +00:00
|
|
|
|
|
|
|
/* attenuation from transparent surface */
|
2016-05-22 20:35:47 +00:00
|
|
|
if(!(shadow_sd->flag & SD_HAS_ONLY_VOLUME)) {
|
2016-01-06 22:38:13 +00:00
|
|
|
path_state_modify_bounce(state, true);
|
Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
2016-06-23 20:56:43 +00:00
|
|
|
shader_eval_surface(kg, shadow_sd, NULL, state, 0.0f, PATH_RAY_SHADOW, SHADER_CONTEXT_SHADOW);
|
2016-01-06 22:38:13 +00:00
|
|
|
path_state_modify_bounce(state, false);
|
|
|
|
|
2016-05-22 20:35:47 +00:00
|
|
|
throughput *= shader_bsdf_transparency(kg, shadow_sd);
|
2014-04-19 15:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* stop if all light is blocked */
|
|
|
|
if(is_zero(throughput)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* move ray forward */
|
2016-05-22 20:35:47 +00:00
|
|
|
ray->P = shadow_sd->P;
|
2016-09-21 09:50:11 +00:00
|
|
|
if(ray->t != FLT_MAX) {
|
2014-04-19 15:02:30 +00:00
|
|
|
ray->D = normalize_len(Pend - ray->P, &ray->t);
|
2016-09-21 09:50:11 +00:00
|
|
|
}
|
2014-04-19 15:02:30 +00:00
|
|
|
|
|
|
|
#ifdef __VOLUME__
|
|
|
|
/* exit/enter volume */
|
2016-05-22 20:35:47 +00:00
|
|
|
kernel_volume_stack_enter_exit(kg, shadow_sd, ps.volume_stack);
|
2014-04-19 15:02:30 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
bounce++;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __VOLUME__
|
|
|
|
/* attenuation for last line segment towards light */
|
|
|
|
if(ps.volume_stack[0].shader != SHADER_NONE)
|
2016-05-22 20:35:47 +00:00
|
|
|
kernel_volume_shadow(kg, shadow_sd, &ps, ray, &throughput);
|
2014-04-19 15:02:30 +00:00
|
|
|
#endif
|
|
|
|
|
2014-05-15 19:25:46 +00:00
|
|
|
*shadow = throughput;
|
|
|
|
|
|
|
|
return is_zero(throughput);
|
2014-04-19 15:02:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Intersection isect;
|
2016-10-02 12:48:39 +00:00
|
|
|
blocked = scene_intersect(kg, *ray, PATH_RAY_SHADOW_OPAQUE, &isect, NULL, 0.0f, 0.0f);
|
2014-04-19 15:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __VOLUME__
|
|
|
|
if(!blocked && state->volume_stack[0].shader != SHADER_NONE) {
|
|
|
|
/* apply attenuation from current volume shader */
|
2016-05-22 20:35:47 +00:00
|
|
|
kernel_volume_shadow(kg, shadow_sd, state, ray, shadow);
|
2014-04-19 15:02:30 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return blocked;
|
|
|
|
}
|
|
|
|
|
2014-09-26 08:22:11 +00:00
|
|
|
#undef STACK_MAX_HITS
|
|
|
|
|
2014-04-19 15:02:30 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
/* Shadow function to compute how much light is blocked, GPU variation.
|
|
|
|
*
|
|
|
|
* Here we raytrace from one transparent surface to the next step by step.
|
|
|
|
* To minimize overhead in cases where we don't need transparent shadows, we
|
|
|
|
* first trace a regular shadow ray. We check if the hit primitive was
|
|
|
|
* potentially transparent, and only in that case start marching. this gives
|
|
|
|
* one extra ray cast for the cases were we do want transparency. */
|
|
|
|
|
2016-01-14 09:53:05 +00:00
|
|
|
ccl_device_noinline bool shadow_blocked(KernelGlobals *kg,
|
2016-05-22 20:35:47 +00:00
|
|
|
ShaderData *shadow_sd,
|
2016-01-14 09:53:05 +00:00
|
|
|
ccl_addr_space PathState *state,
|
|
|
|
ccl_addr_space Ray *ray_input,
|
2016-01-14 14:58:22 +00:00
|
|
|
float3 *shadow)
|
2014-04-19 15:02:30 +00:00
|
|
|
{
|
2014-05-04 16:19:08 +00:00
|
|
|
*shadow = make_float3(1.0f, 1.0f, 1.0f);
|
2014-04-19 15:02:30 +00:00
|
|
|
|
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 14:34:30 +00:00
|
|
|
if(ray_input->t == 0.0f)
|
2013-12-28 01:56:53 +00:00
|
|
|
return false;
|
2013-12-28 15:56:19 +00:00
|
|
|
|
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 14:34:30 +00:00
|
|
|
#ifdef __SPLIT_KERNEL__
|
|
|
|
Ray private_ray = *ray_input;
|
|
|
|
Ray *ray = &private_ray;
|
|
|
|
#else
|
|
|
|
Ray *ray = ray_input;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __SPLIT_KERNEL__
|
2015-10-29 15:56:27 +00:00
|
|
|
Intersection *isect = &kg->isect_shadow[SD_THREAD];
|
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 14:34:30 +00:00
|
|
|
#else
|
|
|
|
Intersection isect_object;
|
|
|
|
Intersection *isect = &isect_object;
|
|
|
|
#endif
|
|
|
|
|
2016-10-02 12:48:39 +00:00
|
|
|
bool blocked = scene_intersect(kg, *ray, PATH_RAY_SHADOW_OPAQUE, isect, NULL, 0.0f, 0.0f);
|
2013-12-28 01:56:53 +00:00
|
|
|
|
|
|
|
#ifdef __TRANSPARENT_SHADOWS__
|
2014-04-19 15:02:30 +00:00
|
|
|
if(blocked && kernel_data.integrator.transparent_shadows) {
|
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 14:34:30 +00:00
|
|
|
if(shader_transparent_shadow(kg, isect)) {
|
2013-12-28 01:56:53 +00:00
|
|
|
float3 throughput = make_float3(1.0f, 1.0f, 1.0f);
|
|
|
|
float3 Pend = ray->P + ray->D*ray->t;
|
|
|
|
int bounce = state->transparent_bounce;
|
2013-12-28 15:56:19 +00:00
|
|
|
#ifdef __VOLUME__
|
2013-12-28 19:02:40 +00:00
|
|
|
PathState ps = *state;
|
2013-12-28 15:56:19 +00:00
|
|
|
#endif
|
|
|
|
|
2013-12-28 01:56:53 +00:00
|
|
|
for(;;) {
|
2014-04-19 15:02:30 +00:00
|
|
|
if(bounce >= kernel_data.integrator.transparent_max_bounce)
|
2013-12-28 01:56:53 +00:00
|
|
|
return true;
|
|
|
|
|
2016-10-02 12:48:39 +00:00
|
|
|
if(!scene_intersect(kg, *ray, PATH_RAY_SHADOW_TRANSPARENT, isect, NULL, 0.0f, 0.0f))
|
2014-05-04 16:19:08 +00:00
|
|
|
{
|
2013-12-28 15:56:19 +00:00
|
|
|
#ifdef __VOLUME__
|
|
|
|
/* attenuation for last line segment towards light */
|
2014-03-29 12:03:47 +00:00
|
|
|
if(ps.volume_stack[0].shader != SHADER_NONE)
|
2016-05-22 20:35:47 +00:00
|
|
|
kernel_volume_shadow(kg, shadow_sd, &ps, ray, &throughput);
|
2013-12-28 15:56:19 +00:00
|
|
|
#endif
|
|
|
|
|
2013-12-28 01:56:53 +00:00
|
|
|
*shadow *= throughput;
|
2014-04-19 15:02:30 +00:00
|
|
|
|
2013-12-28 01:56:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-09-21 09:50:11 +00:00
|
|
|
if(!shader_transparent_shadow(kg, isect)) {
|
2013-12-28 01:56:53 +00:00
|
|
|
return true;
|
2016-09-21 09:50:11 +00:00
|
|
|
}
|
2013-12-28 01:56:53 +00:00
|
|
|
|
2013-12-28 15:56:19 +00:00
|
|
|
#ifdef __VOLUME__
|
|
|
|
/* attenuation between last surface and next surface */
|
2014-03-29 12:03:47 +00:00
|
|
|
if(ps.volume_stack[0].shader != SHADER_NONE) {
|
2013-12-28 15:56:19 +00:00
|
|
|
Ray segment_ray = *ray;
|
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 14:34:30 +00:00
|
|
|
segment_ray.t = isect->t;
|
2016-05-22 20:35:47 +00:00
|
|
|
kernel_volume_shadow(kg, shadow_sd, &ps, &segment_ray, &throughput);
|
2013-12-28 15:56:19 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* setup shader data at surface */
|
2016-05-22 20:35:47 +00:00
|
|
|
shader_setup_from_ray(kg, shadow_sd, isect, ray);
|
2013-12-28 01:56:53 +00:00
|
|
|
|
2013-12-28 15:56:19 +00:00
|
|
|
/* attenuation from transparent surface */
|
2016-05-22 20:35:47 +00:00
|
|
|
if(!(ccl_fetch(shadow_sd, flag) & SD_HAS_ONLY_VOLUME)) {
|
2016-01-06 22:38:13 +00:00
|
|
|
path_state_modify_bounce(state, true);
|
Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
2016-06-23 20:56:43 +00:00
|
|
|
shader_eval_surface(kg, shadow_sd, NULL, state, 0.0f, PATH_RAY_SHADOW, SHADER_CONTEXT_SHADOW);
|
2016-01-06 22:38:13 +00:00
|
|
|
path_state_modify_bounce(state, false);
|
|
|
|
|
2016-05-22 20:35:47 +00:00
|
|
|
throughput *= shader_bsdf_transparency(kg, shadow_sd);
|
2013-12-28 15:56:19 +00:00
|
|
|
}
|
2013-12-28 01:56:53 +00:00
|
|
|
|
2016-09-21 09:50:11 +00:00
|
|
|
/* stop if all light is blocked */
|
|
|
|
if(is_zero(throughput)) {
|
2014-04-19 15:02:30 +00:00
|
|
|
return true;
|
2016-09-21 09:50:11 +00:00
|
|
|
}
|
2014-04-19 15:02:30 +00:00
|
|
|
|
2013-12-28 15:56:19 +00:00
|
|
|
/* move ray forward */
|
2016-05-22 20:35:47 +00:00
|
|
|
ray->P = ray_offset(ccl_fetch(shadow_sd, P), -ccl_fetch(shadow_sd, Ng));
|
2016-09-21 09:50:11 +00:00
|
|
|
if(ray->t != FLT_MAX) {
|
2013-12-28 01:56:53 +00:00
|
|
|
ray->D = normalize_len(Pend - ray->P, &ray->t);
|
2016-09-21 09:50:11 +00:00
|
|
|
}
|
2013-12-28 01:56:53 +00:00
|
|
|
|
2013-12-28 15:56:19 +00:00
|
|
|
#ifdef __VOLUME__
|
|
|
|
/* exit/enter volume */
|
2016-05-22 20:35:47 +00:00
|
|
|
kernel_volume_stack_enter_exit(kg, shadow_sd, ps.volume_stack);
|
2013-12-28 15:56:19 +00:00
|
|
|
#endif
|
|
|
|
|
2013-12-28 01:56:53 +00:00
|
|
|
bounce++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-28 15:56:19 +00:00
|
|
|
#ifdef __VOLUME__
|
2014-04-19 15:02:30 +00:00
|
|
|
else if(!blocked && state->volume_stack[0].shader != SHADER_NONE) {
|
2013-12-28 15:56:19 +00:00
|
|
|
/* apply attenuation from current volume shader */
|
2016-05-22 20:35:47 +00:00
|
|
|
kernel_volume_shadow(kg, shadow_sd, state, ray, shadow);
|
2013-12-28 15:56:19 +00:00
|
|
|
}
|
|
|
|
#endif
|
2013-12-28 01:56:53 +00:00
|
|
|
#endif
|
|
|
|
|
2014-04-19 15:02:30 +00:00
|
|
|
return blocked;
|
2013-12-28 01:56:53 +00:00
|
|
|
}
|
|
|
|
|
2014-04-19 15:02:30 +00:00
|
|
|
#endif
|
|
|
|
|
2013-12-28 01:56:53 +00:00
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|