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
|
|
|
|
* limitations under the License
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "device.h"
|
|
|
|
#include "integrator.h"
|
2012-06-13 11:44:48 +00:00
|
|
|
#include "light.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "scene.h"
|
|
|
|
#include "sobol.h"
|
|
|
|
|
2012-06-13 11:44:48 +00:00
|
|
|
#include "util_foreach.h"
|
2011-10-29 14:27:24 +00:00
|
|
|
#include "util_hash.h"
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
Integrator::Integrator()
|
|
|
|
{
|
2011-09-01 15:53:36 +00:00
|
|
|
min_bounce = 2;
|
|
|
|
max_bounce = 7;
|
|
|
|
|
|
|
|
max_diffuse_bounce = max_bounce;
|
|
|
|
max_glossy_bounce = max_bounce;
|
|
|
|
max_transmission_bounce = max_bounce;
|
2013-12-29 14:40:43 +00:00
|
|
|
max_volume_bounce = max_bounce;
|
2011-09-01 15:53:36 +00:00
|
|
|
|
|
|
|
transparent_min_bounce = min_bounce;
|
|
|
|
transparent_max_bounce = max_bounce;
|
|
|
|
transparent_shadows = false;
|
|
|
|
|
2014-02-05 15:33:51 +00:00
|
|
|
volume_homogeneous_sampling = 0;
|
2013-12-29 21:19:38 +00:00
|
|
|
volume_max_steps = 1024;
|
2014-05-02 21:22:14 +00:00
|
|
|
volume_step_size = 0.1f;
|
2013-12-29 21:19:38 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
no_caustics = false;
|
Cycles: merging features from tomato branch.
=== BVH build time optimizations ===
* BVH building was multithreaded. Not all building is multithreaded, packing
and the initial bounding/splitting is still single threaded, but recursive
splitting is, which was the main bottleneck.
* Object splitting now uses binning rather than sorting of all elements, using
code from the Embree raytracer from Intel.
http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/
* Other small changes to avoid allocations, pack memory more tightly, avoid
some unnecessary operations, ...
These optimizations do not work yet when Spatial Splits are enabled, for that
more work is needed. There's also other optimizations still needed, in
particular for the case of many low poly objects, the packing step and node
memory allocation.
BVH raytracing time should remain about the same, but BVH build time should be
significantly reduced, test here show speedup of about 5x to 10x on a dual core
and 5x to 25x on an 8-core machine, depending on the scene.
=== Threads ===
Centralized task scheduler for multithreading, which is basically the
CPU device threading code wrapped into something reusable.
Basic idea is that there is a single TaskScheduler that keeps a pool of threads,
one for each core. Other places in the code can then create a TaskPool that they
can drop Tasks in to be executed by the scheduler, and wait for them to complete
or cancel them early.
=== Normal ====
Added a Normal output to the texture coordinate node. This currently
gives the object space normal, which is the same under object animation.
In the future this might become a "generated" normal so it's also stable for
deforming objects, but for now it's already useful for non-deforming objects.
=== Render Layers ===
Per render layer Samples control, leaving it to 0 will use the common scene
setting.
Environment pass will now render environment even if film is set to transparent.
Exclude Layers" added. Scene layers (all object that influence the render,
directly or indirectly) are shared between all render layers. However sometimes
it's useful to leave out some object influence for a particular render layer.
That's what this option allows you to do.
=== Filter Glossy ===
When using a value higher than 0.0, this will blur glossy reflections after
blurry bounces, to reduce noise at the cost of accuracy. 1.0 is a good
starting value to tweak.
Some light paths have a low probability of being found while contributing much
light to the pixel. As a result these light paths will be found in some pixels
and not in others, causing fireflies. An example of such a difficult path might
be a small light that is causing a small specular highlight on a sharp glossy
material, which we are seeing through a rough glossy material. With path tracing
it is difficult to find the specular highlight, but if we increase the roughness
on the material the highlight gets bigger and softer, and so easier to find.
Often this blurring will be hardly noticeable, because we are seeing it through
a blurry material anyway, but there are also cases where this will lead to a
loss of detail in lighting.
2012-04-28 08:53:59 +00:00
|
|
|
filter_glossy = 0.0f;
|
2011-10-29 14:27:24 +00:00
|
|
|
seed = 0;
|
2011-12-21 20:51:43 +00:00
|
|
|
layer_flag = ~0;
|
2014-02-10 20:44:49 +00:00
|
|
|
sample_clamp_direct = 0.0f;
|
|
|
|
sample_clamp_indirect = 0.0f;
|
2012-04-30 12:49:26 +00:00
|
|
|
motion_blur = false;
|
2011-10-29 14:27:24 +00:00
|
|
|
|
2013-06-07 16:06:22 +00:00
|
|
|
aa_samples = 0;
|
2012-06-13 11:44:48 +00:00
|
|
|
diffuse_samples = 1;
|
|
|
|
glossy_samples = 1;
|
|
|
|
transmission_samples = 1;
|
|
|
|
ao_samples = 1;
|
|
|
|
mesh_light_samples = 1;
|
2013-04-01 20:26:52 +00:00
|
|
|
subsurface_samples = 1;
|
2013-12-29 14:40:43 +00:00
|
|
|
volume_samples = 1;
|
2013-08-23 14:34:34 +00:00
|
|
|
method = PATH;
|
2012-06-13 11:44:48 +00:00
|
|
|
|
2013-06-07 16:06:22 +00:00
|
|
|
sampling_pattern = SAMPLING_PATTERN_SOBOL;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Integrator::~Integrator()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-06-13 11:44:48 +00:00
|
|
|
void Integrator::device_update(Device *device, DeviceScene *dscene, Scene *scene)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
if(!need_update)
|
|
|
|
return;
|
|
|
|
|
|
|
|
device_free(device, dscene);
|
|
|
|
|
|
|
|
KernelIntegrator *kintegrator = &dscene->data.integrator;
|
|
|
|
|
|
|
|
/* integrator parameters */
|
2011-09-01 15:53:36 +00:00
|
|
|
kintegrator->max_bounce = max_bounce + 1;
|
2014-05-12 08:45:11 +00:00
|
|
|
kintegrator->min_bounce = min_bounce + 1;
|
2011-09-01 15:53:36 +00:00
|
|
|
|
|
|
|
kintegrator->max_diffuse_bounce = max_diffuse_bounce + 1;
|
|
|
|
kintegrator->max_glossy_bounce = max_glossy_bounce + 1;
|
|
|
|
kintegrator->max_transmission_bounce = max_transmission_bounce + 1;
|
|
|
|
|
2013-12-29 14:40:43 +00:00
|
|
|
if(kintegrator->use_volumes)
|
|
|
|
kintegrator->max_volume_bounce = max_volume_bounce + 1;
|
|
|
|
else
|
|
|
|
kintegrator->max_volume_bounce = 1;
|
|
|
|
|
2011-09-01 15:53:36 +00:00
|
|
|
kintegrator->transparent_max_bounce = transparent_max_bounce + 1;
|
2014-05-12 08:45:11 +00:00
|
|
|
kintegrator->transparent_min_bounce = transparent_min_bounce + 1;
|
2011-09-01 15:53:36 +00:00
|
|
|
|
2014-06-01 05:11:13 +00:00
|
|
|
/* At this point kintegrator->transparent_shadows is set automatically
|
|
|
|
* based on whether shaders use transparent shadows (see shader.cpp).
|
|
|
|
* If user doesn't want transparent shadows, force them off. */
|
|
|
|
if(!transparent_shadows)
|
|
|
|
kintegrator->transparent_shadows = false;
|
2011-09-01 15:53:36 +00:00
|
|
|
|
2014-02-05 15:33:51 +00:00
|
|
|
kintegrator->volume_homogeneous_sampling = volume_homogeneous_sampling;
|
2013-12-29 21:19:38 +00:00
|
|
|
kintegrator->volume_max_steps = volume_max_steps;
|
|
|
|
kintegrator->volume_step_size = volume_step_size;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
kintegrator->no_caustics = no_caustics;
|
Cycles: merging features from tomato branch.
=== BVH build time optimizations ===
* BVH building was multithreaded. Not all building is multithreaded, packing
and the initial bounding/splitting is still single threaded, but recursive
splitting is, which was the main bottleneck.
* Object splitting now uses binning rather than sorting of all elements, using
code from the Embree raytracer from Intel.
http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/
* Other small changes to avoid allocations, pack memory more tightly, avoid
some unnecessary operations, ...
These optimizations do not work yet when Spatial Splits are enabled, for that
more work is needed. There's also other optimizations still needed, in
particular for the case of many low poly objects, the packing step and node
memory allocation.
BVH raytracing time should remain about the same, but BVH build time should be
significantly reduced, test here show speedup of about 5x to 10x on a dual core
and 5x to 25x on an 8-core machine, depending on the scene.
=== Threads ===
Centralized task scheduler for multithreading, which is basically the
CPU device threading code wrapped into something reusable.
Basic idea is that there is a single TaskScheduler that keeps a pool of threads,
one for each core. Other places in the code can then create a TaskPool that they
can drop Tasks in to be executed by the scheduler, and wait for them to complete
or cancel them early.
=== Normal ====
Added a Normal output to the texture coordinate node. This currently
gives the object space normal, which is the same under object animation.
In the future this might become a "generated" normal so it's also stable for
deforming objects, but for now it's already useful for non-deforming objects.
=== Render Layers ===
Per render layer Samples control, leaving it to 0 will use the common scene
setting.
Environment pass will now render environment even if film is set to transparent.
Exclude Layers" added. Scene layers (all object that influence the render,
directly or indirectly) are shared between all render layers. However sometimes
it's useful to leave out some object influence for a particular render layer.
That's what this option allows you to do.
=== Filter Glossy ===
When using a value higher than 0.0, this will blur glossy reflections after
blurry bounces, to reduce noise at the cost of accuracy. 1.0 is a good
starting value to tweak.
Some light paths have a low probability of being found while contributing much
light to the pixel. As a result these light paths will be found in some pixels
and not in others, causing fireflies. An example of such a difficult path might
be a small light that is causing a small specular highlight on a sharp glossy
material, which we are seeing through a rough glossy material. With path tracing
it is difficult to find the specular highlight, but if we increase the roughness
on the material the highlight gets bigger and softer, and so easier to find.
Often this blurring will be hardly noticeable, because we are seeing it through
a blurry material anyway, but there are also cases where this will lead to a
loss of detail in lighting.
2012-04-28 08:53:59 +00:00
|
|
|
kintegrator->filter_glossy = (filter_glossy == 0.0f)? FLT_MAX: 1.0f/filter_glossy;
|
|
|
|
|
2011-10-29 14:27:24 +00:00
|
|
|
kintegrator->seed = hash_int(seed);
|
2011-12-21 20:51:43 +00:00
|
|
|
kintegrator->layer_flag = layer_flag << PATH_RAY_LAYER_SHIFT;
|
2011-10-29 14:27:24 +00:00
|
|
|
|
2012-02-28 16:45:08 +00:00
|
|
|
kintegrator->use_ambient_occlusion =
|
|
|
|
((dscene->data.film.pass_flag & PASS_AO) || dscene->data.background.ao_factor != 0.0f);
|
2012-04-05 15:17:45 +00:00
|
|
|
|
2014-02-10 20:44:49 +00:00
|
|
|
kintegrator->sample_clamp_direct = (sample_clamp_direct == 0.0f)? FLT_MAX: sample_clamp_direct*3.0f;
|
|
|
|
kintegrator->sample_clamp_indirect = (sample_clamp_indirect == 0.0f)? FLT_MAX: sample_clamp_indirect*3.0f;
|
2012-02-28 16:45:08 +00:00
|
|
|
|
2013-08-23 14:34:34 +00:00
|
|
|
kintegrator->branched = (method == BRANCHED_PATH);
|
2012-06-13 11:44:48 +00:00
|
|
|
kintegrator->diffuse_samples = diffuse_samples;
|
|
|
|
kintegrator->glossy_samples = glossy_samples;
|
|
|
|
kintegrator->transmission_samples = transmission_samples;
|
|
|
|
kintegrator->ao_samples = ao_samples;
|
|
|
|
kintegrator->mesh_light_samples = mesh_light_samples;
|
2013-04-01 20:26:52 +00:00
|
|
|
kintegrator->subsurface_samples = subsurface_samples;
|
2013-12-29 14:40:43 +00:00
|
|
|
kintegrator->volume_samples = volume_samples;
|
2014-03-15 16:36:44 +00:00
|
|
|
kintegrator->sample_all_lights_direct = sample_all_lights_direct;
|
2014-03-09 21:19:27 +00:00
|
|
|
kintegrator->sample_all_lights_indirect = sample_all_lights_indirect;
|
2012-06-13 11:44:48 +00:00
|
|
|
|
2013-06-07 16:06:22 +00:00
|
|
|
kintegrator->sampling_pattern = sampling_pattern;
|
2014-03-23 11:12:59 +00:00
|
|
|
kintegrator->aa_samples = aa_samples;
|
2013-06-07 16:06:22 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* sobol directions table */
|
2012-06-13 11:44:48 +00:00
|
|
|
int max_samples = 1;
|
|
|
|
|
2013-08-23 14:34:34 +00:00
|
|
|
if(method == BRANCHED_PATH) {
|
2012-06-13 11:44:48 +00:00
|
|
|
foreach(Light *light, scene->lights)
|
|
|
|
max_samples = max(max_samples, light->samples);
|
|
|
|
|
|
|
|
max_samples = max(max_samples, max(diffuse_samples, max(glossy_samples, transmission_samples)));
|
2013-04-14 19:22:12 +00:00
|
|
|
max_samples = max(max_samples, max(ao_samples, max(mesh_light_samples, subsurface_samples)));
|
2013-12-29 14:40:43 +00:00
|
|
|
max_samples = max(max_samples, volume_samples);
|
2012-06-13 11:44:48 +00:00
|
|
|
}
|
|
|
|
|
2013-09-01 14:10:40 +00:00
|
|
|
max_samples *= (max_bounce + transparent_max_bounce + 3);
|
2012-06-13 11:44:48 +00:00
|
|
|
|
|
|
|
int dimensions = PRNG_BASE_NUM + max_samples*PRNG_BOUNCE_NUM;
|
2012-09-19 17:09:11 +00:00
|
|
|
dimensions = min(dimensions, SOBOL_MAX_DIMENSIONS);
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
uint *directions = dscene->sobol_directions.resize(SOBOL_BITS*dimensions);
|
|
|
|
|
|
|
|
sobol_generate_direction_vectors((uint(*)[SOBOL_BITS])directions, dimensions);
|
|
|
|
|
|
|
|
device->tex_alloc("__sobol_directions", dscene->sobol_directions);
|
|
|
|
|
|
|
|
need_update = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Integrator::device_free(Device *device, DeviceScene *dscene)
|
|
|
|
{
|
|
|
|
device->tex_free(dscene->sobol_directions);
|
|
|
|
dscene->sobol_directions.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Integrator::modified(const Integrator& integrator)
|
|
|
|
{
|
2011-09-01 15:53:36 +00:00
|
|
|
return !(min_bounce == integrator.min_bounce &&
|
|
|
|
max_bounce == integrator.max_bounce &&
|
|
|
|
max_diffuse_bounce == integrator.max_diffuse_bounce &&
|
|
|
|
max_glossy_bounce == integrator.max_glossy_bounce &&
|
|
|
|
max_transmission_bounce == integrator.max_transmission_bounce &&
|
2013-12-29 14:40:43 +00:00
|
|
|
max_volume_bounce == integrator.max_volume_bounce &&
|
2011-09-01 15:53:36 +00:00
|
|
|
transparent_min_bounce == integrator.transparent_min_bounce &&
|
|
|
|
transparent_max_bounce == integrator.transparent_max_bounce &&
|
|
|
|
transparent_shadows == integrator.transparent_shadows &&
|
2014-02-05 15:33:51 +00:00
|
|
|
volume_homogeneous_sampling == integrator.volume_homogeneous_sampling &&
|
2013-12-29 21:19:38 +00:00
|
|
|
volume_max_steps == integrator.volume_max_steps &&
|
|
|
|
volume_step_size == integrator.volume_step_size &&
|
2011-04-27 11:58:34 +00:00
|
|
|
no_caustics == integrator.no_caustics &&
|
Cycles: merging features from tomato branch.
=== BVH build time optimizations ===
* BVH building was multithreaded. Not all building is multithreaded, packing
and the initial bounding/splitting is still single threaded, but recursive
splitting is, which was the main bottleneck.
* Object splitting now uses binning rather than sorting of all elements, using
code from the Embree raytracer from Intel.
http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/
* Other small changes to avoid allocations, pack memory more tightly, avoid
some unnecessary operations, ...
These optimizations do not work yet when Spatial Splits are enabled, for that
more work is needed. There's also other optimizations still needed, in
particular for the case of many low poly objects, the packing step and node
memory allocation.
BVH raytracing time should remain about the same, but BVH build time should be
significantly reduced, test here show speedup of about 5x to 10x on a dual core
and 5x to 25x on an 8-core machine, depending on the scene.
=== Threads ===
Centralized task scheduler for multithreading, which is basically the
CPU device threading code wrapped into something reusable.
Basic idea is that there is a single TaskScheduler that keeps a pool of threads,
one for each core. Other places in the code can then create a TaskPool that they
can drop Tasks in to be executed by the scheduler, and wait for them to complete
or cancel them early.
=== Normal ====
Added a Normal output to the texture coordinate node. This currently
gives the object space normal, which is the same under object animation.
In the future this might become a "generated" normal so it's also stable for
deforming objects, but for now it's already useful for non-deforming objects.
=== Render Layers ===
Per render layer Samples control, leaving it to 0 will use the common scene
setting.
Environment pass will now render environment even if film is set to transparent.
Exclude Layers" added. Scene layers (all object that influence the render,
directly or indirectly) are shared between all render layers. However sometimes
it's useful to leave out some object influence for a particular render layer.
That's what this option allows you to do.
=== Filter Glossy ===
When using a value higher than 0.0, this will blur glossy reflections after
blurry bounces, to reduce noise at the cost of accuracy. 1.0 is a good
starting value to tweak.
Some light paths have a low probability of being found while contributing much
light to the pixel. As a result these light paths will be found in some pixels
and not in others, causing fireflies. An example of such a difficult path might
be a small light that is causing a small specular highlight on a sharp glossy
material, which we are seeing through a rough glossy material. With path tracing
it is difficult to find the specular highlight, but if we increase the roughness
on the material the highlight gets bigger and softer, and so easier to find.
Often this blurring will be hardly noticeable, because we are seeing it through
a blurry material anyway, but there are also cases where this will lead to a
loss of detail in lighting.
2012-04-28 08:53:59 +00:00
|
|
|
filter_glossy == integrator.filter_glossy &&
|
2011-12-21 20:51:43 +00:00
|
|
|
layer_flag == integrator.layer_flag &&
|
2012-04-05 15:17:45 +00:00
|
|
|
seed == integrator.seed &&
|
2014-02-10 20:44:49 +00:00
|
|
|
sample_clamp_direct == integrator.sample_clamp_direct &&
|
|
|
|
sample_clamp_indirect == integrator.sample_clamp_indirect &&
|
2013-08-23 14:34:34 +00:00
|
|
|
method == integrator.method &&
|
2013-06-07 16:06:22 +00:00
|
|
|
aa_samples == integrator.aa_samples &&
|
2012-06-13 11:44:48 +00:00
|
|
|
diffuse_samples == integrator.diffuse_samples &&
|
|
|
|
glossy_samples == integrator.glossy_samples &&
|
|
|
|
transmission_samples == integrator.transmission_samples &&
|
|
|
|
ao_samples == integrator.ao_samples &&
|
|
|
|
mesh_light_samples == integrator.mesh_light_samples &&
|
2013-04-01 20:26:52 +00:00
|
|
|
subsurface_samples == integrator.subsurface_samples &&
|
2013-12-29 14:40:43 +00:00
|
|
|
volume_samples == integrator.volume_samples &&
|
2013-06-10 20:34:34 +00:00
|
|
|
motion_blur == integrator.motion_blur &&
|
2014-03-09 21:19:27 +00:00
|
|
|
sampling_pattern == integrator.sampling_pattern &&
|
2014-03-15 16:36:44 +00:00
|
|
|
sample_all_lights_direct == integrator.sample_all_lights_direct &&
|
2014-03-09 21:19:27 +00:00
|
|
|
sample_all_lights_indirect == integrator.sample_all_lights_indirect);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Integrator::tag_update(Scene *scene)
|
|
|
|
{
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|