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 01:50:24 +00:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
2020-03-19 08:33:03 +00:00
|
|
|
#include "render/light.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 18:39:14 +00:00
|
|
|
#include "device/device.h"
|
2020-03-19 08:33:03 +00:00
|
|
|
#include "render/background.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 18:39:14 +00:00
|
|
|
#include "render/film.h"
|
2018-06-14 14:18:34 +00:00
|
|
|
#include "render/graph.h"
|
2020-03-19 08:33:03 +00:00
|
|
|
#include "render/integrator.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 18:39:14 +00:00
|
|
|
#include "render/mesh.h"
|
2018-06-14 14:18:34 +00:00
|
|
|
#include "render/nodes.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 18:39:14 +00:00
|
|
|
#include "render/object.h"
|
|
|
|
#include "render/scene.h"
|
|
|
|
#include "render/shader.h"
|
2020-10-01 21:16:01 +00:00
|
|
|
#include "render/stats.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 18:39:14 +00:00
|
|
|
#include "util/util_foreach.h"
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-26 22:46:37 +00:00
|
|
|
#include "util/util_hash.h"
|
2020-03-19 08:33:03 +00:00
|
|
|
#include "util/util_logging.h"
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-26 22:46:37 +00:00
|
|
|
#include "util/util_path.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 18:39:14 +00:00
|
|
|
#include "util/util_progress.h"
|
2020-06-05 09:39:11 +00:00
|
|
|
#include "util/util_task.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2018-06-14 14:18:34 +00:00
|
|
|
static void shade_background_pixels(Device *device,
|
|
|
|
DeviceScene *dscene,
|
|
|
|
int width,
|
|
|
|
int height,
|
|
|
|
vector<float3> &pixels,
|
|
|
|
Progress &progress)
|
2012-01-20 17:49:17 +00:00
|
|
|
{
|
|
|
|
/* create input */
|
2017-10-20 21:31:13 +00:00
|
|
|
device_vector<uint4> d_input(device, "background_input", MEM_READ_ONLY);
|
2017-10-24 21:23:16 +00:00
|
|
|
device_vector<float4> d_output(device, "background_output", MEM_READ_WRITE);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
uint4 *d_input_data = d_input.alloc(width * height);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
for (int y = 0; y < height; y++) {
|
|
|
|
for (int x = 0; x < width; x++) {
|
2016-11-06 18:12:45 +00:00
|
|
|
float u = (x + 0.5f) / width;
|
|
|
|
float v = (y + 0.5f) / height;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-02-28 16:44:54 +00:00
|
|
|
uint4 in = make_uint4(__float_as_int(u), __float_as_int(v), 0, 0);
|
2012-01-20 17:49:17 +00:00
|
|
|
d_input_data[x + y * width] = in;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
/* compute on device */
|
2017-10-20 23:09:59 +00:00
|
|
|
d_output.alloc(width * height);
|
|
|
|
d_output.zero_to_device();
|
|
|
|
d_input.copy_to_device();
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
device->const_copy_to("__data", &dscene->data, sizeof(dscene->data));
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
DeviceTask main_task(DeviceTask::SHADER);
|
|
|
|
main_task.shader_input = d_input.device_pointer;
|
|
|
|
main_task.shader_output = d_output.device_pointer;
|
|
|
|
main_task.shader_eval_type = SHADER_EVAL_BACKGROUND;
|
|
|
|
main_task.shader_x = 0;
|
|
|
|
main_task.shader_w = width * height;
|
2014-06-06 12:40:09 +00:00
|
|
|
main_task.num_samples = 1;
|
2014-01-02 21:05:07 +00:00
|
|
|
main_task.get_cancel = function_bind(&Progress::get_cancel, &progress);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-10-01 18:31:32 +00:00
|
|
|
/* disabled splitting for now, there's an issue with multi-GPU mem_copy_from */
|
2012-01-20 17:49:17 +00:00
|
|
|
list<DeviceTask> split_tasks;
|
2014-05-26 11:40:16 +00:00
|
|
|
main_task.split(split_tasks, 1, 128 * 128);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
foreach (DeviceTask &task, split_tasks) {
|
|
|
|
device->task_add(task);
|
|
|
|
device->task_wait();
|
2017-10-20 23:09:59 +00:00
|
|
|
d_output.copy_from_device(task.shader_x, 1, task.shader_w);
|
2012-01-20 17:49:17 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
d_input.free();
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2017-11-04 23:34:30 +00:00
|
|
|
float4 *d_output_data = d_output.data();
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
pixels.resize(width * height);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
for (int y = 0; y < height; y++) {
|
|
|
|
for (int x = 0; x < width; x++) {
|
|
|
|
pixels[y * width + x].x = d_output_data[y * width + x].x;
|
|
|
|
pixels[y * width + x].y = d_output_data[y * width + x].y;
|
|
|
|
pixels[y * width + x].z = d_output_data[y * width + x].z;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
d_output.free();
|
2012-01-20 17:49:17 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Light */
|
|
|
|
|
2016-05-07 22:18:32 +00:00
|
|
|
NODE_DEFINE(Light)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2016-05-07 22:18:32 +00:00
|
|
|
NodeType *type = NodeType::add("light", create);
|
|
|
|
|
|
|
|
static NodeEnum type_enum;
|
|
|
|
type_enum.insert("point", LIGHT_POINT);
|
2016-11-12 14:26:51 +00:00
|
|
|
type_enum.insert("distant", LIGHT_DISTANT);
|
2016-05-07 22:18:32 +00:00
|
|
|
type_enum.insert("background", LIGHT_BACKGROUND);
|
|
|
|
type_enum.insert("area", LIGHT_AREA);
|
|
|
|
type_enum.insert("spot", LIGHT_SPOT);
|
2020-11-04 10:17:38 +00:00
|
|
|
SOCKET_ENUM(light_type, "Type", type_enum, LIGHT_POINT);
|
2016-05-07 22:18:32 +00:00
|
|
|
|
2021-02-17 00:47:18 +00:00
|
|
|
SOCKET_COLOR(strength, "Strength", one_float3());
|
2019-05-12 11:41:23 +00:00
|
|
|
|
2021-02-17 00:47:18 +00:00
|
|
|
SOCKET_POINT(co, "Co", zero_float3());
|
2016-05-07 22:18:32 +00:00
|
|
|
|
2021-02-17 00:47:18 +00:00
|
|
|
SOCKET_VECTOR(dir, "Dir", zero_float3());
|
2016-05-07 22:18:32 +00:00
|
|
|
SOCKET_FLOAT(size, "Size", 0.0f);
|
2020-06-02 05:14:25 +00:00
|
|
|
SOCKET_FLOAT(angle, "Angle", 0.0f);
|
2011-09-27 20:37:24 +00:00
|
|
|
|
2021-02-17 00:47:18 +00:00
|
|
|
SOCKET_VECTOR(axisu, "Axis U", zero_float3());
|
2016-05-07 22:18:32 +00:00
|
|
|
SOCKET_FLOAT(sizeu, "Size U", 1.0f);
|
2021-02-17 00:47:18 +00:00
|
|
|
SOCKET_VECTOR(axisv, "Axis V", zero_float3());
|
2016-05-07 22:18:32 +00:00
|
|
|
SOCKET_FLOAT(sizev, "Size V", 1.0f);
|
Cycles/Eevee: Implement disk and ellipse shapes for area lamps
The implementation is pretty straightforward.
In Cycles, sampling the shapes is currently done w.r.t. area instead of solid angle.
There is a paper on solid angle sampling for disks [1], but the described algorithm is based on
simply sampling the enclosing square and rejecting samples outside of the disk, which is not exactly
great for Cycles' RNG (we'd need to setup a LCG for the repeated sampling) and for GPU divergence.
Even worse, the algorithm is only defined for disks. For ellipses, the basic idea still works, but a
way to analytically calculate the solid angle is required. This is technically possible [2], but the
calculation is extremely complex and still requires a lookup table for the Heuman Lambda function.
Therefore, I've decided to not implement that for now, we could still look into it later on.
In Eevee, the code uses the existing ltc_evaluate_disk to implement the lighting calculations.
[1]: "Solid Angle Sampling of Disk and Cylinder Lights"
[2]: "Analytical solution for the solid angle subtended at any point by an ellipse via a point source radiation vector potential"
Reviewers: sergey, brecht, fclem
Differential Revision: https://developer.blender.org/D3171
2018-05-24 01:50:16 +00:00
|
|
|
SOCKET_BOOLEAN(round, "Round", false);
|
2011-09-27 20:37:24 +00:00
|
|
|
|
2018-06-14 14:18:34 +00:00
|
|
|
SOCKET_INT(map_resolution, "Map Resolution", 0);
|
2011-09-27 20:37:24 +00:00
|
|
|
|
2016-05-07 22:18:32 +00:00
|
|
|
SOCKET_FLOAT(spot_angle, "Spot Angle", M_PI_4_F);
|
|
|
|
SOCKET_FLOAT(spot_smooth, "Spot Smooth", 0.0f);
|
2011-09-27 20:37:24 +00:00
|
|
|
|
2016-10-29 16:54:42 +00:00
|
|
|
SOCKET_TRANSFORM(tfm, "Transform", transform_identity());
|
|
|
|
|
2016-05-07 22:18:32 +00:00
|
|
|
SOCKET_BOOLEAN(cast_shadow, "Cast Shadow", true);
|
|
|
|
SOCKET_BOOLEAN(use_mis, "Use Mis", false);
|
|
|
|
SOCKET_BOOLEAN(use_diffuse, "Use Diffuse", true);
|
|
|
|
SOCKET_BOOLEAN(use_glossy, "Use Glossy", true);
|
|
|
|
SOCKET_BOOLEAN(use_transmission, "Use Transmission", true);
|
|
|
|
SOCKET_BOOLEAN(use_scatter, "Use Scatter", true);
|
2012-01-20 17:49:17 +00:00
|
|
|
|
2016-05-07 22:18:32 +00:00
|
|
|
SOCKET_INT(samples, "Samples", 1);
|
|
|
|
SOCKET_INT(max_bounces, "Max Bounces", 1024);
|
2017-11-05 20:59:17 +00:00
|
|
|
SOCKET_UINT(random_id, "Random ID", 0);
|
2012-06-04 17:17:10 +00:00
|
|
|
|
2016-05-07 22:18:32 +00:00
|
|
|
SOCKET_BOOLEAN(is_portal, "Is Portal", false);
|
|
|
|
SOCKET_BOOLEAN(is_enabled, "Is Enabled", true);
|
2013-01-30 15:57:15 +00:00
|
|
|
|
2016-05-07 22:18:32 +00:00
|
|
|
SOCKET_NODE(shader, "Shader", &Shader::node_type);
|
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-27 19:51:55 +00:00
|
|
|
|
2016-05-07 22:18:32 +00:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
Light::Light() : Node(node_type)
|
|
|
|
{
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Light::tag_update(Scene *scene)
|
|
|
|
{
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 14:01:26 +00:00
|
|
|
if (is_modified()) {
|
|
|
|
scene->light_manager->tag_update(scene, LightManager::LIGHT_MODIFIED);
|
2021-01-29 16:17:18 +00:00
|
|
|
|
|
|
|
if (samples_is_modified()) {
|
|
|
|
scene->integrator->tag_update(scene, Integrator::LIGHT_SAMPLES_MODIFIED);
|
|
|
|
}
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 14:01:26 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2015-06-25 15:00:32 +00:00
|
|
|
bool Light::has_contribution(Scene *scene)
|
|
|
|
{
|
2021-02-17 00:47:18 +00:00
|
|
|
if (strength == zero_float3()) {
|
2019-05-12 11:41:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-06-25 15:00:32 +00:00
|
|
|
if (is_portal) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-04 10:17:38 +00:00
|
|
|
if (light_type == LIGHT_BACKGROUND) {
|
2015-06-28 18:47:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-05-14 12:50:03 +00:00
|
|
|
return (shader) ? shader->has_surface_emission : scene->default_light->has_surface_emission;
|
2015-06-25 15:00:32 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Light Manager */
|
|
|
|
|
|
|
|
LightManager::LightManager()
|
|
|
|
{
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 14:01:26 +00:00
|
|
|
update_flags = UPDATE_ALL;
|
2020-05-14 15:41:37 +00:00
|
|
|
need_update_background = true;
|
2013-06-08 13:43:38 +00:00
|
|
|
use_light_visibility = false;
|
2020-05-14 15:41:37 +00:00
|
|
|
last_background_enabled = false;
|
|
|
|
last_background_resolution = 0;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LightManager::~LightManager()
|
|
|
|
{
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-26 22:46:37 +00:00
|
|
|
foreach (IESSlot *slot, ies_slots) {
|
|
|
|
delete slot;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-09-02 07:58:41 +00:00
|
|
|
bool LightManager::has_background_light(Scene *scene)
|
|
|
|
{
|
|
|
|
foreach (Light *light, scene->lights) {
|
2020-11-04 10:17:38 +00:00
|
|
|
if (light->light_type == LIGHT_BACKGROUND && light->is_enabled) {
|
2016-09-02 07:58:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-05-14 15:41:37 +00:00
|
|
|
void LightManager::test_enabled_lights(Scene *scene)
|
2016-02-06 19:43:44 +00:00
|
|
|
{
|
2016-02-06 21:21:38 +00:00
|
|
|
/* Make all lights enabled by default, and perform some preliminary checks
|
|
|
|
* needed for finer-tuning of settings (for example, check whether we've
|
|
|
|
* got portals or not).
|
2016-02-06 19:43:44 +00:00
|
|
|
*/
|
2016-02-06 21:21:38 +00:00
|
|
|
bool has_portal = false, has_background = false;
|
2016-02-06 19:43:44 +00:00
|
|
|
foreach (Light *light, scene->lights) {
|
2016-02-06 21:21:38 +00:00
|
|
|
light->is_enabled = light->has_contribution(scene);
|
|
|
|
has_portal |= light->is_portal;
|
2020-11-04 10:17:38 +00:00
|
|
|
has_background |= light->light_type == LIGHT_BACKGROUND;
|
2016-02-06 21:21:38 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-05-14 15:41:37 +00:00
|
|
|
bool background_enabled = false;
|
|
|
|
int background_resolution = 0;
|
|
|
|
|
2016-02-06 21:21:38 +00:00
|
|
|
if (has_background) {
|
|
|
|
/* Ignore background light if:
|
|
|
|
* - If unsupported on a device
|
|
|
|
* - If we don't need it (no HDRs etc.)
|
|
|
|
*/
|
2020-01-20 12:42:26 +00:00
|
|
|
Shader *shader = scene->background->get_shader(scene);
|
2019-10-29 15:32:53 +00:00
|
|
|
const bool disable_mis = !(has_portal || shader->has_surface_spatial_varying);
|
|
|
|
VLOG_IF(1, disable_mis) << "Background MIS has been disabled.\n";
|
|
|
|
foreach (Light *light, scene->lights) {
|
2020-11-04 10:17:38 +00:00
|
|
|
if (light->light_type == LIGHT_BACKGROUND) {
|
2019-10-29 15:32:53 +00:00
|
|
|
light->is_enabled = !disable_mis;
|
2020-05-14 15:41:37 +00:00
|
|
|
background_enabled = !disable_mis;
|
|
|
|
background_resolution = light->map_resolution;
|
2016-02-06 19:43:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-05-14 15:41:37 +00:00
|
|
|
|
|
|
|
if (last_background_enabled != background_enabled ||
|
|
|
|
last_background_resolution != background_resolution) {
|
|
|
|
last_background_enabled = background_enabled;
|
|
|
|
last_background_resolution = background_resolution;
|
|
|
|
need_update_background = true;
|
|
|
|
}
|
2016-02-06 19:43:44 +00:00
|
|
|
}
|
|
|
|
|
2016-07-28 10:27:24 +00:00
|
|
|
bool LightManager::object_usable_as_light(Object *object)
|
|
|
|
{
|
2020-11-04 10:17:38 +00:00
|
|
|
Geometry *geom = object->get_geometry();
|
|
|
|
if (geom->geometry_type != Geometry::MESH && geom->geometry_type != Geometry::VOLUME) {
|
2020-02-02 11:04:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-07-03 03:04:43 +00:00
|
|
|
/* Skip objects with NaNs */
|
2017-08-07 12:47:51 +00:00
|
|
|
if (!object->bounds.valid()) {
|
2017-07-03 03:04:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-07-28 10:27:24 +00:00
|
|
|
/* Skip if we are not visible for BSDFs. */
|
2020-11-04 10:17:38 +00:00
|
|
|
if (!(object->get_visibility() & (PATH_RAY_DIFFUSE | PATH_RAY_GLOSSY | PATH_RAY_TRANSMIT))) {
|
2016-07-28 10:27:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
/* Skip if we have no emission shaders. */
|
2016-07-28 10:37:44 +00:00
|
|
|
/* TODO(sergey): Ideally we want to avoid such duplicated loop, since it'll
|
2020-02-02 11:04:19 +00:00
|
|
|
* iterate all geometry shaders twice (when counting and when calculating
|
2016-07-28 10:37:44 +00:00
|
|
|
* triangle area.
|
|
|
|
*/
|
2020-11-04 10:17:38 +00:00
|
|
|
foreach (Node *node, geom->get_used_shaders()) {
|
|
|
|
Shader *shader = static_cast<Shader *>(node);
|
|
|
|
if (shader->get_use_mis() && shader->has_surface_emission) {
|
2016-07-28 10:37:44 +00:00
|
|
|
return true;
|
|
|
|
}
|
2016-07-28 10:27:24 +00:00
|
|
|
}
|
2016-07-28 10:37:44 +00:00
|
|
|
return false;
|
2016-07-28 10:27:24 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
void LightManager::device_update_distribution(Device *,
|
|
|
|
DeviceScene *dscene,
|
|
|
|
Scene *scene,
|
|
|
|
Progress &progress)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-01-20 17:49:17 +00:00
|
|
|
progress.set_status("Updating Lights", "Computing distribution");
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* count */
|
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-27 19:51:55 +00:00
|
|
|
size_t num_lights = 0;
|
2016-08-03 10:38:25 +00:00
|
|
|
size_t num_portals = 0;
|
2013-02-13 16:46:18 +00:00
|
|
|
size_t num_background_lights = 0;
|
2011-04-27 11:58:34 +00:00
|
|
|
size_t num_triangles = 0;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
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-27 19:51:55 +00:00
|
|
|
bool background_mis = false;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
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-27 19:51:55 +00:00
|
|
|
foreach (Light *light, scene->lights) {
|
2016-08-03 10:38:25 +00:00
|
|
|
if (light->is_enabled) {
|
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-27 19:51:55 +00:00
|
|
|
num_lights++;
|
2016-08-03 10:38:25 +00:00
|
|
|
}
|
|
|
|
if (light->is_portal) {
|
|
|
|
num_portals++;
|
|
|
|
}
|
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-27 19:51:55 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
foreach (Object *object, scene->objects) {
|
2016-07-28 10:27:24 +00:00
|
|
|
if (progress.get_cancel())
|
|
|
|
return;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-07-28 10:27:24 +00:00
|
|
|
if (!object_usable_as_light(object)) {
|
2016-07-28 10:20:47 +00:00
|
|
|
continue;
|
2011-09-02 16:15:18 +00:00
|
|
|
}
|
2020-02-02 11:04:19 +00:00
|
|
|
|
2016-07-28 10:20:47 +00:00
|
|
|
/* Count triangles. */
|
2020-11-04 10:17:38 +00:00
|
|
|
Mesh *mesh = static_cast<Mesh *>(object->get_geometry());
|
2016-07-28 10:20:47 +00:00
|
|
|
size_t mesh_num_triangles = mesh->num_triangles();
|
|
|
|
for (size_t i = 0; i < mesh_num_triangles; i++) {
|
2020-11-04 10:17:38 +00:00
|
|
|
int shader_index = mesh->get_shader()[i];
|
|
|
|
Shader *shader = (shader_index < mesh->get_used_shaders().size()) ?
|
|
|
|
static_cast<Shader *>(mesh->get_used_shaders()[shader_index]) :
|
2016-07-28 10:20:47 +00:00
|
|
|
scene->default_surface;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-11-04 10:17:38 +00:00
|
|
|
if (shader->get_use_mis() && shader->has_surface_emission) {
|
2016-07-28 10:20:47 +00:00
|
|
|
num_triangles++;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
}
|
|
|
|
|
2014-05-12 08:20:20 +00:00
|
|
|
size_t num_distribution = num_triangles + num_lights;
|
2016-07-28 10:13:11 +00:00
|
|
|
VLOG(1) << "Total " << num_distribution << " of light distribution primitives.";
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* emission area */
|
2018-03-07 23:15:41 +00:00
|
|
|
KernelLightDistribution *distribution = dscene->light_distribution.alloc(num_distribution + 1);
|
2011-04-27 11:58:34 +00:00
|
|
|
float totarea = 0.0f;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* triangles */
|
|
|
|
size_t offset = 0;
|
2012-01-18 22:36:12 +00:00
|
|
|
int j = 0;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
foreach (Object *object, scene->objects) {
|
2016-07-28 10:20:47 +00:00
|
|
|
if (progress.get_cancel())
|
|
|
|
return;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-07-28 10:27:24 +00:00
|
|
|
if (!object_usable_as_light(object)) {
|
2014-08-21 11:56:25 +00:00
|
|
|
j++;
|
2014-03-29 12:03:47 +00:00
|
|
|
continue;
|
2014-08-21 11:56:25 +00:00
|
|
|
}
|
2016-07-28 10:27:24 +00:00
|
|
|
/* Sum area. */
|
2020-11-04 10:17:38 +00:00
|
|
|
Mesh *mesh = static_cast<Mesh *>(object->get_geometry());
|
2016-07-28 10:20:47 +00:00
|
|
|
bool transform_applied = mesh->transform_applied;
|
2020-11-04 10:17:38 +00:00
|
|
|
Transform tfm = object->get_tfm();
|
2016-07-28 10:20:47 +00:00
|
|
|
int object_id = j;
|
|
|
|
int shader_flag = 0;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-11-04 10:17:38 +00:00
|
|
|
if (!(object->get_visibility() & PATH_RAY_DIFFUSE)) {
|
2016-07-28 10:20:47 +00:00
|
|
|
shader_flag |= SHADER_EXCLUDE_DIFFUSE;
|
|
|
|
use_light_visibility = true;
|
|
|
|
}
|
2020-11-04 10:17:38 +00:00
|
|
|
if (!(object->get_visibility() & PATH_RAY_GLOSSY)) {
|
2016-07-28 10:20:47 +00:00
|
|
|
shader_flag |= SHADER_EXCLUDE_GLOSSY;
|
|
|
|
use_light_visibility = true;
|
|
|
|
}
|
2020-11-04 10:17:38 +00:00
|
|
|
if (!(object->get_visibility() & PATH_RAY_TRANSMIT)) {
|
2016-07-28 10:20:47 +00:00
|
|
|
shader_flag |= SHADER_EXCLUDE_TRANSMIT;
|
|
|
|
use_light_visibility = true;
|
|
|
|
}
|
2020-11-04 10:17:38 +00:00
|
|
|
if (!(object->get_visibility() & PATH_RAY_VOLUME_SCATTER)) {
|
2016-07-28 10:20:47 +00:00
|
|
|
shader_flag |= SHADER_EXCLUDE_SCATTER;
|
|
|
|
use_light_visibility = true;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-07-28 10:20:47 +00:00
|
|
|
size_t mesh_num_triangles = mesh->num_triangles();
|
|
|
|
for (size_t i = 0; i < mesh_num_triangles; i++) {
|
2020-11-04 10:17:38 +00:00
|
|
|
int shader_index = mesh->get_shader()[i];
|
|
|
|
Shader *shader = (shader_index < mesh->get_used_shaders().size()) ?
|
|
|
|
static_cast<Shader *>(mesh->get_used_shaders()[shader_index]) :
|
2016-07-28 10:20:47 +00:00
|
|
|
scene->default_surface;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-11-04 10:17:38 +00:00
|
|
|
if (shader->get_use_mis() && shader->has_surface_emission) {
|
2018-03-07 23:15:41 +00:00
|
|
|
distribution[offset].totarea = totarea;
|
2020-02-02 11:04:19 +00:00
|
|
|
distribution[offset].prim = i + mesh->prim_offset;
|
2018-03-07 23:15:41 +00:00
|
|
|
distribution[offset].mesh_light.shader_flag = shader_flag;
|
|
|
|
distribution[offset].mesh_light.object_id = object_id;
|
2016-07-28 10:20:47 +00:00
|
|
|
offset++;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-07-28 10:20:47 +00:00
|
|
|
Mesh::Triangle t = mesh->get_triangle(i);
|
2020-11-04 10:17:38 +00:00
|
|
|
if (!t.valid(&mesh->get_verts()[0])) {
|
2017-10-18 10:19:53 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-11-04 10:17:38 +00:00
|
|
|
float3 p1 = mesh->get_verts()[t.v[0]];
|
|
|
|
float3 p2 = mesh->get_verts()[t.v[1]];
|
|
|
|
float3 p3 = mesh->get_verts()[t.v[2]];
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-07-28 10:20:47 +00:00
|
|
|
if (!transform_applied) {
|
|
|
|
p1 = transform_point(&tfm, p1);
|
|
|
|
p2 = transform_point(&tfm, p2);
|
|
|
|
p3 = transform_point(&tfm, p3);
|
2011-09-02 16:15:18 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-07-28 10:20:47 +00:00
|
|
|
totarea += triangle_area(p1, p2, p3);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
j++;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
float trianglearea = totarea;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* point lights */
|
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-27 19:51:55 +00:00
|
|
|
float lightarea = (totarea > 0.0f) ? totarea / num_lights : 1.0f;
|
2013-01-30 15:57:15 +00:00
|
|
|
bool use_lamp_mis = false;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
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-27 19:51:55 +00:00
|
|
|
int light_index = 0;
|
|
|
|
foreach (Light *light, scene->lights) {
|
2016-02-07 01:18:51 +00:00
|
|
|
if (!light->is_enabled)
|
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-27 19:51:55 +00:00
|
|
|
continue;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-07 23:15:41 +00:00
|
|
|
distribution[offset].totarea = totarea;
|
|
|
|
distribution[offset].prim = ~light_index;
|
|
|
|
distribution[offset].lamp.pad = 1.0f;
|
|
|
|
distribution[offset].lamp.size = light->size;
|
2012-06-13 11:44:48 +00:00
|
|
|
totarea += lightarea;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-11-04 10:17:38 +00:00
|
|
|
if (light->light_type == LIGHT_DISTANT) {
|
2019-05-15 12:45:33 +00:00
|
|
|
use_lamp_mis |= (light->angle > 0.0f && light->use_mis);
|
|
|
|
}
|
2020-11-04 10:17:38 +00:00
|
|
|
else if (light->light_type == LIGHT_POINT || light->light_type == LIGHT_SPOT) {
|
2019-05-15 12:45:33 +00:00
|
|
|
use_lamp_mis |= (light->size > 0.0f && light->use_mis);
|
|
|
|
}
|
2020-11-04 10:17:38 +00:00
|
|
|
else if (light->light_type == LIGHT_AREA) {
|
2019-05-15 12:45:33 +00:00
|
|
|
use_lamp_mis |= light->use_mis;
|
|
|
|
}
|
2020-11-04 10:17:38 +00:00
|
|
|
else if (light->light_type == LIGHT_BACKGROUND) {
|
2013-02-13 16:46:18 +00:00
|
|
|
num_background_lights++;
|
2019-05-15 12:45:33 +00:00
|
|
|
background_mis |= light->use_mis;
|
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-27 19:51:55 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
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-27 19:51:55 +00:00
|
|
|
light_index++;
|
|
|
|
offset++;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* normalize cumulative distribution functions */
|
2018-03-07 23:15:41 +00:00
|
|
|
distribution[num_distribution].totarea = totarea;
|
|
|
|
distribution[num_distribution].prim = 0.0f;
|
|
|
|
distribution[num_distribution].lamp.pad = 0.0f;
|
|
|
|
distribution[num_distribution].lamp.size = 0.0f;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (totarea > 0.0f) {
|
|
|
|
for (size_t i = 0; i < num_distribution; i++)
|
2018-03-07 23:15:41 +00:00
|
|
|
distribution[i].totarea /= totarea;
|
|
|
|
distribution[num_distribution].totarea = 1.0f;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (progress.get_cancel())
|
|
|
|
return;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* update device */
|
|
|
|
KernelIntegrator *kintegrator = &dscene->data.integrator;
|
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 18:27:10 +00:00
|
|
|
KernelBackground *kbackground = &dscene->data.background;
|
2013-02-13 16:46:18 +00:00
|
|
|
KernelFilm *kfilm = &dscene->data.film;
|
2012-06-13 11:44:48 +00:00
|
|
|
kintegrator->use_direct_light = (totarea > 0.0f);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-09-27 20:37:24 +00:00
|
|
|
if (kintegrator->use_direct_light) {
|
2011-04-27 11:58:34 +00:00
|
|
|
/* number of emissives */
|
2013-03-23 10:11:29 +00:00
|
|
|
kintegrator->num_distribution = num_distribution;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* precompute pdfs */
|
|
|
|
kintegrator->pdf_triangles = 0.0f;
|
|
|
|
kintegrator->pdf_lights = 0.0f;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-06-13 11:44:48 +00:00
|
|
|
/* sample one, with 0.5 probability of light or triangle */
|
|
|
|
kintegrator->num_all_lights = num_lights;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-06-13 11:44:48 +00:00
|
|
|
if (trianglearea > 0.0f) {
|
|
|
|
kintegrator->pdf_triangles = 1.0f / trianglearea;
|
2011-04-27 11:58:34 +00:00
|
|
|
if (num_lights)
|
2012-06-13 11:44:48 +00:00
|
|
|
kintegrator->pdf_triangles *= 0.5f;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-06-13 11:44:48 +00:00
|
|
|
if (num_lights) {
|
|
|
|
kintegrator->pdf_lights = 1.0f / num_lights;
|
|
|
|
if (trianglearea > 0.0f)
|
|
|
|
kintegrator->pdf_lights *= 0.5f;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2013-01-30 15:57:15 +00:00
|
|
|
kintegrator->use_lamp_mis = use_lamp_mis;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2013-02-13 16:46:18 +00:00
|
|
|
/* bit of an ugly hack to compensate for emitting triangles influencing
|
|
|
|
* amount of samples we get for this pass */
|
2013-02-20 12:10:05 +00:00
|
|
|
kfilm->pass_shadow_scale = 1.0f;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2013-02-20 12:10:05 +00:00
|
|
|
if (kintegrator->pdf_triangles != 0.0f)
|
|
|
|
kfilm->pass_shadow_scale *= 0.5f;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2013-02-13 16:46:18 +00:00
|
|
|
if (num_background_lights < num_lights)
|
|
|
|
kfilm->pass_shadow_scale *= (float)(num_lights - num_background_lights) / (float)num_lights;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* CDF */
|
2017-10-20 23:09:59 +00:00
|
|
|
dscene->light_distribution.copy_to_device();
|
2019-04-17 04:17:24 +00:00
|
|
|
|
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-27 19:51:55 +00:00
|
|
|
/* Portals */
|
2016-08-03 10:38:25 +00:00
|
|
|
if (num_portals > 0) {
|
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 18:27:10 +00:00
|
|
|
kbackground->portal_offset = light_index;
|
|
|
|
kbackground->num_portals = num_portals;
|
|
|
|
kbackground->portal_weight = 1.0f;
|
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-27 19:51:55 +00:00
|
|
|
}
|
|
|
|
else {
|
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 18:27:10 +00:00
|
|
|
kbackground->num_portals = 0;
|
|
|
|
kbackground->portal_offset = 0;
|
|
|
|
kbackground->portal_weight = 0.0f;
|
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-27 19:51:55 +00:00
|
|
|
}
|
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 18:27:10 +00:00
|
|
|
|
|
|
|
/* Map */
|
|
|
|
kbackground->map_weight = background_mis ? 1.0f : 0.0f;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2012-09-03 16:52:59 +00:00
|
|
|
else {
|
2017-10-20 23:09:59 +00:00
|
|
|
dscene->light_distribution.free();
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-09-03 16:52:59 +00:00
|
|
|
kintegrator->num_distribution = 0;
|
|
|
|
kintegrator->num_all_lights = 0;
|
|
|
|
kintegrator->pdf_triangles = 0.0f;
|
|
|
|
kintegrator->pdf_lights = 0.0f;
|
2013-01-30 15:57:15 +00:00
|
|
|
kintegrator->use_lamp_mis = false;
|
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 18:27:10 +00:00
|
|
|
|
|
|
|
kbackground->num_portals = 0;
|
|
|
|
kbackground->portal_offset = 0;
|
|
|
|
kbackground->portal_weight = 0.0f;
|
|
|
|
kbackground->sun_weight = 0.0f;
|
|
|
|
kbackground->map_weight = 0.0f;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2013-02-13 16:46:18 +00:00
|
|
|
kfilm->pass_shadow_scale = 1.0f;
|
2012-09-03 16:52:59 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2015-03-12 10:58:43 +00:00
|
|
|
static void background_cdf(
|
|
|
|
int start, int end, int res_x, int res_y, const vector<float3> *pixels, float2 *cond_cdf)
|
|
|
|
{
|
2018-06-14 14:18:34 +00:00
|
|
|
int cdf_width = res_x + 1;
|
2015-03-12 10:58:43 +00:00
|
|
|
/* Conditional CDFs (rows, U direction). */
|
|
|
|
for (int i = start; i < end; i++) {
|
2018-06-14 14:18:34 +00:00
|
|
|
float sin_theta = sinf(M_PI_F * (i + 0.5f) / res_y);
|
|
|
|
float3 env_color = (*pixels)[i * res_x];
|
2015-06-26 19:36:28 +00:00
|
|
|
float ave_luminance = average(env_color);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-06-14 14:18:34 +00:00
|
|
|
cond_cdf[i * cdf_width].x = ave_luminance * sin_theta;
|
|
|
|
cond_cdf[i * cdf_width].y = 0.0f;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-06-14 14:18:34 +00:00
|
|
|
for (int j = 1; j < res_x; j++) {
|
|
|
|
env_color = (*pixels)[i * res_x + j];
|
2015-06-26 19:36:28 +00:00
|
|
|
ave_luminance = average(env_color);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-06-14 14:18:34 +00:00
|
|
|
cond_cdf[i * cdf_width + j].x = ave_luminance * sin_theta;
|
|
|
|
cond_cdf[i * cdf_width + j].y = cond_cdf[i * cdf_width + j - 1].y +
|
|
|
|
cond_cdf[i * cdf_width + j - 1].x / res_x;
|
2015-03-12 10:58:43 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-11-30 11:21:44 +00:00
|
|
|
const float cdf_total = cond_cdf[i * cdf_width + res_x - 1].y +
|
|
|
|
cond_cdf[i * cdf_width + res_x - 1].x / res_x;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2015-03-12 10:58:43 +00:00
|
|
|
/* stuff the total into the brightness value for the last entry, because
|
|
|
|
* we are going to normalize the CDFs to 0.0 to 1.0 afterwards */
|
2018-06-14 14:18:34 +00:00
|
|
|
cond_cdf[i * cdf_width + res_x].x = cdf_total;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-11-30 11:21:44 +00:00
|
|
|
if (cdf_total > 0.0f) {
|
|
|
|
const float cdf_total_inv = 1.0f / cdf_total;
|
|
|
|
for (int j = 1; j < res_x; j++) {
|
2018-06-14 14:18:34 +00:00
|
|
|
cond_cdf[i * cdf_width + j].y *= cdf_total_inv;
|
2020-11-30 11:21:44 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-06-14 14:18:34 +00:00
|
|
|
cond_cdf[i * cdf_width + res_x].y = 1.0f;
|
2015-03-12 10:58:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-06 19:43:44 +00:00
|
|
|
void LightManager::device_update_background(Device *device,
|
|
|
|
DeviceScene *dscene,
|
|
|
|
Scene *scene,
|
2016-02-06 21:21:38 +00:00
|
|
|
Progress &progress)
|
2012-01-20 17:49:17 +00:00
|
|
|
{
|
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 18:27:10 +00:00
|
|
|
KernelBackground *kbackground = &dscene->data.background;
|
2012-01-20 17:49:17 +00:00
|
|
|
Light *background_light = NULL;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
/* find background light */
|
2016-02-06 21:21:38 +00:00
|
|
|
foreach (Light *light, scene->lights) {
|
2020-11-04 10:17:38 +00:00
|
|
|
if (light->light_type == LIGHT_BACKGROUND) {
|
2016-02-06 21:21:38 +00:00
|
|
|
background_light = light;
|
|
|
|
break;
|
2012-01-20 17:49:17 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
/* no background light found, signal renderer to skip sampling */
|
2016-02-06 21:21:38 +00:00
|
|
|
if (!background_light || !background_light->is_enabled) {
|
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 18:27:10 +00:00
|
|
|
kbackground->map_res_x = 0;
|
|
|
|
kbackground->map_res_y = 0;
|
|
|
|
kbackground->map_weight = 0.0f;
|
|
|
|
kbackground->sun_weight = 0.0f;
|
|
|
|
kbackground->use_mis = (kbackground->portal_weight > 0.0f);
|
2012-01-20 17:49:17 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
progress.set_status("Updating Lights", "Importance map");
|
2019-04-17 04:17:24 +00:00
|
|
|
|
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 18:27:10 +00:00
|
|
|
assert(dscene->data.integrator.use_direct_light);
|
|
|
|
|
|
|
|
int2 environment_res = make_int2(0, 0);
|
|
|
|
Shader *shader = scene->background->get_shader(scene);
|
|
|
|
int num_suns = 0;
|
|
|
|
foreach (ShaderNode *node, shader->graph->nodes) {
|
|
|
|
if (node->type == EnvironmentTextureNode::node_type) {
|
|
|
|
EnvironmentTextureNode *env = (EnvironmentTextureNode *)node;
|
|
|
|
ImageMetaData metadata;
|
|
|
|
if (!env->handle.empty()) {
|
|
|
|
ImageMetaData metadata = env->handle.metadata();
|
|
|
|
environment_res.x = max(environment_res.x, metadata.width);
|
|
|
|
environment_res.y = max(environment_res.y, metadata.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (node->type == SkyTextureNode::node_type) {
|
|
|
|
SkyTextureNode *sky = (SkyTextureNode *)node;
|
2020-11-04 10:17:38 +00:00
|
|
|
if (sky->get_sky_type() == NODE_SKY_NISHITA && sky->get_sun_disc()) {
|
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 18:27:10 +00:00
|
|
|
/* Ensure that the input coordinates aren't transformed before they reach the node.
|
|
|
|
* If that is the case, the logic used for sampling the sun's location does not work
|
|
|
|
* and we have to fall back to map-based sampling. */
|
|
|
|
const ShaderInput *vec_in = sky->input("Vector");
|
|
|
|
if (vec_in && vec_in->link && vec_in->link->parent) {
|
|
|
|
ShaderNode *vec_src = vec_in->link->parent;
|
|
|
|
if ((vec_src->type != TextureCoordinateNode::node_type) ||
|
|
|
|
(vec_in->link != vec_src->output("Generated"))) {
|
|
|
|
environment_res.x = max(environment_res.x, 4096);
|
|
|
|
environment_res.y = max(environment_res.y, 2048);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-12 23:52:07 +00:00
|
|
|
/* Determine sun direction from lat/long and texture mapping. */
|
2020-11-04 10:17:38 +00:00
|
|
|
float latitude = sky->get_sun_elevation();
|
|
|
|
float longitude = M_2PI_F - sky->get_sun_rotation() + M_PI_2_F;
|
2020-07-12 23:52:07 +00:00
|
|
|
float3 sun_direction = make_float3(
|
|
|
|
cosf(latitude) * cosf(longitude), cosf(latitude) * sinf(longitude), sinf(latitude));
|
|
|
|
Transform sky_transform = transform_inverse(sky->tex_mapping.compute_transform());
|
|
|
|
sun_direction = transform_direction(&sky_transform, sun_direction);
|
|
|
|
|
|
|
|
/* Pack sun direction and size. */
|
2020-08-17 15:48:53 +00:00
|
|
|
float half_angle = sky->get_sun_size() * 0.5f;
|
2020-07-12 23:52:07 +00:00
|
|
|
kbackground->sun = make_float4(
|
|
|
|
sun_direction.x, sun_direction.y, sun_direction.z, half_angle);
|
|
|
|
|
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 18:27:10 +00:00
|
|
|
kbackground->sun_weight = 4.0f;
|
|
|
|
environment_res.x = max(environment_res.x, 512);
|
|
|
|
environment_res.y = max(environment_res.y, 256);
|
|
|
|
num_suns++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If there's more than one sun, fall back to map sampling instead. */
|
|
|
|
if (num_suns != 1) {
|
|
|
|
kbackground->sun_weight = 0.0f;
|
|
|
|
environment_res.x = max(environment_res.x, 4096);
|
|
|
|
environment_res.y = max(environment_res.y, 2048);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable MIS for background sampling if any strategy is active. */
|
|
|
|
kbackground->use_mis = (kbackground->portal_weight + kbackground->map_weight +
|
|
|
|
kbackground->sun_weight) > 0.0f;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
/* get the resolution from the light's size (we stuff it in there) */
|
2018-06-14 14:18:34 +00:00
|
|
|
int2 res = make_int2(background_light->map_resolution, background_light->map_resolution / 2);
|
|
|
|
/* If the resolution isn't set manually, try to find an environment texture. */
|
2018-08-24 12:36:18 +00:00
|
|
|
if (res.x == 0) {
|
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 18:27:10 +00:00
|
|
|
res = environment_res;
|
2018-08-24 12:36:18 +00:00
|
|
|
if (res.x > 0 && res.y > 0) {
|
2018-06-14 14:18:34 +00:00
|
|
|
VLOG(2) << "Automatically set World MIS resolution to " << res.x << " by " << res.y << "\n";
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
}
|
2018-06-14 14:18:34 +00:00
|
|
|
/* If it's still unknown, just use the default. */
|
2018-08-24 12:36:18 +00:00
|
|
|
if (res.x == 0 || res.y == 0) {
|
2018-06-14 14:18:34 +00:00
|
|
|
res = make_int2(1024, 512);
|
|
|
|
VLOG(2) << "Setting World MIS resolution to default\n";
|
|
|
|
}
|
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 18:27:10 +00:00
|
|
|
kbackground->map_res_x = res.x;
|
|
|
|
kbackground->map_res_y = res.y;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
vector<float3> pixels;
|
2018-06-14 14:18:34 +00:00
|
|
|
shade_background_pixels(device, dscene, res.x, res.y, pixels, progress);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
if (progress.get_cancel())
|
|
|
|
return;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
/* build row distributions and column distribution for the infinite area environment light */
|
2018-06-14 14:18:34 +00:00
|
|
|
int cdf_width = res.x + 1;
|
|
|
|
float2 *marg_cdf = dscene->light_background_marginal_cdf.alloc(res.y + 1);
|
|
|
|
float2 *cond_cdf = dscene->light_background_conditional_cdf.alloc(cdf_width * res.y);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2015-03-12 10:58:43 +00:00
|
|
|
double time_start = time_dt();
|
2020-06-05 10:53:38 +00:00
|
|
|
|
|
|
|
/* Create CDF in parallel. */
|
|
|
|
const int rows_per_task = divide_up(10240, res.x);
|
|
|
|
parallel_for(blocked_range<size_t>(0, res.y, rows_per_task),
|
|
|
|
[&](const blocked_range<size_t> &r) {
|
|
|
|
background_cdf(r.begin(), r.end(), res.x, res.y, &pixels, cond_cdf);
|
|
|
|
});
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
/* marginal CDFs (column, V direction, sum of rows) */
|
2018-06-14 14:18:34 +00:00
|
|
|
marg_cdf[0].x = cond_cdf[res.x].x;
|
2012-01-20 17:49:17 +00:00
|
|
|
marg_cdf[0].y = 0.0f;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-06-14 14:18:34 +00:00
|
|
|
for (int i = 1; i < res.y; i++) {
|
|
|
|
marg_cdf[i].x = cond_cdf[i * cdf_width + res.x].x;
|
|
|
|
marg_cdf[i].y = marg_cdf[i - 1].y + marg_cdf[i - 1].x / res.y;
|
2012-01-20 17:49:17 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-06-14 14:18:34 +00:00
|
|
|
float cdf_total = marg_cdf[res.y - 1].y + marg_cdf[res.y - 1].x / res.y;
|
|
|
|
marg_cdf[res.y].x = cdf_total;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
if (cdf_total > 0.0f)
|
2018-06-14 14:18:34 +00:00
|
|
|
for (int i = 1; i < res.y; i++)
|
2012-01-20 17:49:17 +00:00
|
|
|
marg_cdf[i].y /= cdf_total;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-06-14 14:18:34 +00:00
|
|
|
marg_cdf[res.y].y = 1.0f;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2015-03-12 10:58:43 +00:00
|
|
|
VLOG(2) << "Background MIS build time " << time_dt() - time_start << "\n";
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
/* update device */
|
2017-10-20 23:09:59 +00:00
|
|
|
dscene->light_background_marginal_cdf.copy_to_device();
|
|
|
|
dscene->light_background_conditional_cdf.copy_to_device();
|
2012-01-20 17:49:17 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 23:09:59 +00:00
|
|
|
void LightManager::device_update_points(Device *, DeviceScene *dscene, Scene *scene)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2016-02-06 19:43:44 +00:00
|
|
|
int num_scene_lights = scene->lights.size();
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-08-03 10:38:25 +00:00
|
|
|
int num_lights = 0;
|
2016-07-27 21:09:38 +00:00
|
|
|
foreach (Light *light, scene->lights) {
|
2016-08-03 10:38:25 +00:00
|
|
|
if (light->is_enabled || light->is_portal) {
|
2016-07-27 21:09:38 +00:00
|
|
|
num_lights++;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-07 23:15:41 +00:00
|
|
|
KernelLight *klights = dscene->lights.alloc(num_lights);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-07-28 10:13:11 +00:00
|
|
|
if (num_lights == 0) {
|
|
|
|
VLOG(1) << "No effective light, ignoring points update.";
|
2011-04-27 11:58:34 +00:00
|
|
|
return;
|
2016-07-28 10:13:11 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
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-27 19:51:55 +00:00
|
|
|
int light_index = 0;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
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-27 19:51:55 +00:00
|
|
|
foreach (Light *light, scene->lights) {
|
2016-02-06 21:21:38 +00:00
|
|
|
if (!light->is_enabled) {
|
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-27 19:51:55 +00:00
|
|
|
continue;
|
2015-06-25 15:00:32 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-09-27 20:37:24 +00:00
|
|
|
float3 co = light->co;
|
2016-05-14 12:50:03 +00:00
|
|
|
Shader *shader = (light->shader) ? light->shader : scene->default_light;
|
|
|
|
int shader_id = scene->shader_manager->get_shader_id(shader);
|
2018-03-07 23:15:41 +00:00
|
|
|
int max_bounces = light->max_bounces;
|
2017-11-05 20:59:17 +00:00
|
|
|
float random = (float)light->random_id * (1.0f / (float)0xFFFFFFFF);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2011-09-27 20:37:24 +00:00
|
|
|
if (!light->cast_shadow)
|
|
|
|
shader_id &= ~SHADER_CAST_SHADOW;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2013-06-07 18:59:23 +00:00
|
|
|
if (!light->use_diffuse) {
|
|
|
|
shader_id |= SHADER_EXCLUDE_DIFFUSE;
|
2013-06-08 13:43:38 +00:00
|
|
|
use_light_visibility = true;
|
2013-06-07 18:59:23 +00:00
|
|
|
}
|
|
|
|
if (!light->use_glossy) {
|
|
|
|
shader_id |= SHADER_EXCLUDE_GLOSSY;
|
2013-06-08 13:43:38 +00:00
|
|
|
use_light_visibility = true;
|
2013-06-07 18:59:23 +00:00
|
|
|
}
|
|
|
|
if (!light->use_transmission) {
|
|
|
|
shader_id |= SHADER_EXCLUDE_TRANSMIT;
|
2013-06-08 13:43:38 +00:00
|
|
|
use_light_visibility = true;
|
2013-06-07 18:59:23 +00:00
|
|
|
}
|
2014-09-05 14:17:24 +00:00
|
|
|
if (!light->use_scatter) {
|
|
|
|
shader_id |= SHADER_EXCLUDE_SCATTER;
|
|
|
|
use_light_visibility = true;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-11-04 10:17:38 +00:00
|
|
|
klights[light_index].type = light->light_type;
|
2019-05-12 11:41:23 +00:00
|
|
|
klights[light_index].samples = light->samples;
|
|
|
|
klights[light_index].strength[0] = light->strength.x;
|
|
|
|
klights[light_index].strength[1] = light->strength.y;
|
|
|
|
klights[light_index].strength[2] = light->strength.z;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2020-11-04 10:17:38 +00:00
|
|
|
if (light->light_type == LIGHT_POINT) {
|
2011-09-27 20:37:24 +00:00
|
|
|
shader_id &= ~SHADER_AREA_LIGHT;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2013-01-09 21:09:20 +00:00
|
|
|
float radius = light->size;
|
|
|
|
float invarea = (radius > 0.0f) ? 1.0f / (M_PI_F * radius * radius) : 1.0f;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2013-01-30 15:57:15 +00:00
|
|
|
if (light->use_mis && radius > 0.0f)
|
|
|
|
shader_id |= SHADER_USE_MIS;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-07 23:15:41 +00:00
|
|
|
klights[light_index].co[0] = co.x;
|
|
|
|
klights[light_index].co[1] = co.y;
|
|
|
|
klights[light_index].co[2] = co.z;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-07 23:15:41 +00:00
|
|
|
klights[light_index].spot.radius = radius;
|
|
|
|
klights[light_index].spot.invarea = invarea;
|
2011-09-27 20:37:24 +00:00
|
|
|
}
|
2020-11-04 10:17:38 +00:00
|
|
|
else if (light->light_type == LIGHT_DISTANT) {
|
2011-09-27 20:37:24 +00:00
|
|
|
shader_id &= ~SHADER_AREA_LIGHT;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2019-05-15 12:45:33 +00:00
|
|
|
float angle = light->angle / 2.0f;
|
|
|
|
float radius = tanf(angle);
|
2013-01-09 21:09:20 +00:00
|
|
|
float cosangle = cosf(angle);
|
|
|
|
float area = M_PI_F * radius * radius;
|
|
|
|
float invarea = (area > 0.0f) ? 1.0f / area : 1.0f;
|
2013-08-05 14:22:07 +00:00
|
|
|
float3 dir = light->dir;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2014-11-08 12:35:21 +00:00
|
|
|
dir = safe_normalize(dir);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2013-01-30 15:57:15 +00:00
|
|
|
if (light->use_mis && area > 0.0f)
|
|
|
|
shader_id |= SHADER_USE_MIS;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-07 23:15:41 +00:00
|
|
|
klights[light_index].co[0] = dir.x;
|
|
|
|
klights[light_index].co[1] = dir.y;
|
|
|
|
klights[light_index].co[2] = dir.z;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-07 23:15:41 +00:00
|
|
|
klights[light_index].distant.invarea = invarea;
|
|
|
|
klights[light_index].distant.radius = radius;
|
|
|
|
klights[light_index].distant.cosangle = cosangle;
|
2011-09-27 20:37:24 +00:00
|
|
|
}
|
2020-11-04 10:17:38 +00:00
|
|
|
else if (light->light_type == LIGHT_BACKGROUND) {
|
|
|
|
uint visibility = scene->background->get_visibility();
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2012-01-20 17:49:17 +00:00
|
|
|
shader_id &= ~SHADER_AREA_LIGHT;
|
2013-01-30 15:57:15 +00:00
|
|
|
shader_id |= SHADER_USE_MIS;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2013-07-02 21:03:16 +00:00
|
|
|
if (!(visibility & PATH_RAY_DIFFUSE)) {
|
|
|
|
shader_id |= SHADER_EXCLUDE_DIFFUSE;
|
|
|
|
use_light_visibility = true;
|
|
|
|
}
|
|
|
|
if (!(visibility & PATH_RAY_GLOSSY)) {
|
|
|
|
shader_id |= SHADER_EXCLUDE_GLOSSY;
|
|
|
|
use_light_visibility = true;
|
|
|
|
}
|
|
|
|
if (!(visibility & PATH_RAY_TRANSMIT)) {
|
|
|
|
shader_id |= SHADER_EXCLUDE_TRANSMIT;
|
|
|
|
use_light_visibility = true;
|
|
|
|
}
|
2014-09-05 14:17:24 +00:00
|
|
|
if (!(visibility & PATH_RAY_VOLUME_SCATTER)) {
|
|
|
|
shader_id |= SHADER_EXCLUDE_SCATTER;
|
|
|
|
use_light_visibility = true;
|
|
|
|
}
|
2012-01-20 17:49:17 +00:00
|
|
|
}
|
2020-11-04 10:17:38 +00:00
|
|
|
else if (light->light_type == LIGHT_AREA) {
|
2011-09-27 20:37:24 +00:00
|
|
|
float3 axisu = light->axisu * (light->sizeu * light->size);
|
|
|
|
float3 axisv = light->axisv * (light->sizev * light->size);
|
2013-06-04 17:20:00 +00:00
|
|
|
float area = len(axisu) * len(axisv);
|
Cycles/Eevee: Implement disk and ellipse shapes for area lamps
The implementation is pretty straightforward.
In Cycles, sampling the shapes is currently done w.r.t. area instead of solid angle.
There is a paper on solid angle sampling for disks [1], but the described algorithm is based on
simply sampling the enclosing square and rejecting samples outside of the disk, which is not exactly
great for Cycles' RNG (we'd need to setup a LCG for the repeated sampling) and for GPU divergence.
Even worse, the algorithm is only defined for disks. For ellipses, the basic idea still works, but a
way to analytically calculate the solid angle is required. This is technically possible [2], but the
calculation is extremely complex and still requires a lookup table for the Heuman Lambda function.
Therefore, I've decided to not implement that for now, we could still look into it later on.
In Eevee, the code uses the existing ltc_evaluate_disk to implement the lighting calculations.
[1]: "Solid Angle Sampling of Disk and Cylinder Lights"
[2]: "Analytical solution for the solid angle subtended at any point by an ellipse via a point source radiation vector potential"
Reviewers: sergey, brecht, fclem
Differential Revision: https://developer.blender.org/D3171
2018-05-24 01:50:16 +00:00
|
|
|
if (light->round) {
|
|
|
|
area *= -M_PI_4_F;
|
|
|
|
}
|
|
|
|
float invarea = (area != 0.0f) ? 1.0f / area : 1.0f;
|
2013-08-05 14:22:07 +00:00
|
|
|
float3 dir = light->dir;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2014-11-08 12:35:21 +00:00
|
|
|
dir = safe_normalize(dir);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
Cycles/Eevee: Implement disk and ellipse shapes for area lamps
The implementation is pretty straightforward.
In Cycles, sampling the shapes is currently done w.r.t. area instead of solid angle.
There is a paper on solid angle sampling for disks [1], but the described algorithm is based on
simply sampling the enclosing square and rejecting samples outside of the disk, which is not exactly
great for Cycles' RNG (we'd need to setup a LCG for the repeated sampling) and for GPU divergence.
Even worse, the algorithm is only defined for disks. For ellipses, the basic idea still works, but a
way to analytically calculate the solid angle is required. This is technically possible [2], but the
calculation is extremely complex and still requires a lookup table for the Heuman Lambda function.
Therefore, I've decided to not implement that for now, we could still look into it later on.
In Eevee, the code uses the existing ltc_evaluate_disk to implement the lighting calculations.
[1]: "Solid Angle Sampling of Disk and Cylinder Lights"
[2]: "Analytical solution for the solid angle subtended at any point by an ellipse via a point source radiation vector potential"
Reviewers: sergey, brecht, fclem
Differential Revision: https://developer.blender.org/D3171
2018-05-24 01:50:16 +00:00
|
|
|
if (light->use_mis && area != 0.0f)
|
2013-01-30 15:57:15 +00:00
|
|
|
shader_id |= SHADER_USE_MIS;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-07 23:15:41 +00:00
|
|
|
klights[light_index].co[0] = co.x;
|
|
|
|
klights[light_index].co[1] = co.y;
|
|
|
|
klights[light_index].co[2] = co.z;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-07 23:15:41 +00:00
|
|
|
klights[light_index].area.axisu[0] = axisu.x;
|
|
|
|
klights[light_index].area.axisu[1] = axisu.y;
|
|
|
|
klights[light_index].area.axisu[2] = axisu.z;
|
|
|
|
klights[light_index].area.axisv[0] = axisv.x;
|
|
|
|
klights[light_index].area.axisv[1] = axisv.y;
|
|
|
|
klights[light_index].area.axisv[2] = axisv.z;
|
|
|
|
klights[light_index].area.invarea = invarea;
|
|
|
|
klights[light_index].area.dir[0] = dir.x;
|
|
|
|
klights[light_index].area.dir[1] = dir.y;
|
|
|
|
klights[light_index].area.dir[2] = dir.z;
|
2011-09-27 20:37:24 +00:00
|
|
|
}
|
2020-11-04 10:17:38 +00:00
|
|
|
else if (light->light_type == LIGHT_SPOT) {
|
2012-06-04 17:17:10 +00:00
|
|
|
shader_id &= ~SHADER_AREA_LIGHT;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2013-01-09 21:09:20 +00:00
|
|
|
float radius = light->size;
|
|
|
|
float invarea = (radius > 0.0f) ? 1.0f / (M_PI_F * radius * radius) : 1.0f;
|
2012-06-04 17:17:10 +00:00
|
|
|
float spot_angle = cosf(light->spot_angle * 0.5f);
|
|
|
|
float spot_smooth = (1.0f - spot_angle) * light->spot_smooth;
|
2013-08-05 14:22:07 +00:00
|
|
|
float3 dir = light->dir;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2014-11-08 12:35:21 +00:00
|
|
|
dir = safe_normalize(dir);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2013-01-30 15:57:15 +00:00
|
|
|
if (light->use_mis && radius > 0.0f)
|
|
|
|
shader_id |= SHADER_USE_MIS;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-07 23:15:41 +00:00
|
|
|
klights[light_index].co[0] = co.x;
|
|
|
|
klights[light_index].co[1] = co.y;
|
|
|
|
klights[light_index].co[2] = co.z;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-07 23:15:41 +00:00
|
|
|
klights[light_index].spot.radius = radius;
|
|
|
|
klights[light_index].spot.invarea = invarea;
|
|
|
|
klights[light_index].spot.spot_angle = spot_angle;
|
|
|
|
klights[light_index].spot.spot_smooth = spot_smooth;
|
|
|
|
klights[light_index].spot.dir[0] = dir.x;
|
|
|
|
klights[light_index].spot.dir[1] = dir.y;
|
|
|
|
klights[light_index].spot.dir[2] = dir.z;
|
2012-06-04 17:17:10 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-07 23:15:41 +00:00
|
|
|
klights[light_index].shader_id = shader_id;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-07 23:15:41 +00:00
|
|
|
klights[light_index].max_bounces = max_bounces;
|
|
|
|
klights[light_index].random = random;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-08 05:48:14 +00:00
|
|
|
klights[light_index].tfm = light->tfm;
|
|
|
|
klights[light_index].itfm = transform_inverse(light->tfm);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
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-27 19:51:55 +00:00
|
|
|
light_index++;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
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-27 19:51:55 +00:00
|
|
|
/* TODO(sergey): Consider moving portals update to their own function
|
|
|
|
* keeping this one more manageable.
|
|
|
|
*/
|
|
|
|
foreach (Light *light, scene->lights) {
|
|
|
|
if (!light->is_portal)
|
|
|
|
continue;
|
2020-11-04 10:17:38 +00:00
|
|
|
assert(light->light_type == LIGHT_AREA);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
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-27 19:51:55 +00:00
|
|
|
float3 co = light->co;
|
|
|
|
float3 axisu = light->axisu * (light->sizeu * light->size);
|
|
|
|
float3 axisv = light->axisv * (light->sizev * light->size);
|
|
|
|
float area = len(axisu) * len(axisv);
|
Cycles/Eevee: Implement disk and ellipse shapes for area lamps
The implementation is pretty straightforward.
In Cycles, sampling the shapes is currently done w.r.t. area instead of solid angle.
There is a paper on solid angle sampling for disks [1], but the described algorithm is based on
simply sampling the enclosing square and rejecting samples outside of the disk, which is not exactly
great for Cycles' RNG (we'd need to setup a LCG for the repeated sampling) and for GPU divergence.
Even worse, the algorithm is only defined for disks. For ellipses, the basic idea still works, but a
way to analytically calculate the solid angle is required. This is technically possible [2], but the
calculation is extremely complex and still requires a lookup table for the Heuman Lambda function.
Therefore, I've decided to not implement that for now, we could still look into it later on.
In Eevee, the code uses the existing ltc_evaluate_disk to implement the lighting calculations.
[1]: "Solid Angle Sampling of Disk and Cylinder Lights"
[2]: "Analytical solution for the solid angle subtended at any point by an ellipse via a point source radiation vector potential"
Reviewers: sergey, brecht, fclem
Differential Revision: https://developer.blender.org/D3171
2018-05-24 01:50:16 +00:00
|
|
|
if (light->round) {
|
|
|
|
area *= -M_PI_4_F;
|
|
|
|
}
|
|
|
|
float invarea = (area != 0.0f) ? 1.0f / area : 1.0f;
|
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-27 19:51:55 +00:00
|
|
|
float3 dir = light->dir;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
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-27 19:51:55 +00:00
|
|
|
dir = safe_normalize(dir);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-07 23:15:41 +00:00
|
|
|
klights[light_index].co[0] = co.x;
|
|
|
|
klights[light_index].co[1] = co.y;
|
|
|
|
klights[light_index].co[2] = co.z;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-07 23:15:41 +00:00
|
|
|
klights[light_index].area.axisu[0] = axisu.x;
|
|
|
|
klights[light_index].area.axisu[1] = axisu.y;
|
|
|
|
klights[light_index].area.axisu[2] = axisu.z;
|
|
|
|
klights[light_index].area.axisv[0] = axisv.x;
|
|
|
|
klights[light_index].area.axisv[1] = axisv.y;
|
|
|
|
klights[light_index].area.axisv[2] = axisv.z;
|
|
|
|
klights[light_index].area.invarea = invarea;
|
|
|
|
klights[light_index].area.dir[0] = dir.x;
|
|
|
|
klights[light_index].area.dir[1] = dir.y;
|
|
|
|
klights[light_index].area.dir[2] = dir.z;
|
2018-03-08 05:48:14 +00:00
|
|
|
klights[light_index].tfm = light->tfm;
|
|
|
|
klights[light_index].itfm = transform_inverse(light->tfm);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
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-27 19:51:55 +00:00
|
|
|
light_index++;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2016-02-06 19:43:44 +00:00
|
|
|
VLOG(1) << "Number of lights sent to the device: " << light_index;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2015-06-25 15:00:32 +00:00
|
|
|
VLOG(1) << "Number of lights without contribution: " << num_scene_lights - light_index;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
2018-03-07 23:15:41 +00:00
|
|
|
dscene->lights.copy_to_device();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LightManager::device_update(Device *device,
|
|
|
|
DeviceScene *dscene,
|
|
|
|
Scene *scene,
|
|
|
|
Progress &progress)
|
|
|
|
{
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 14:01:26 +00:00
|
|
|
if (!need_update())
|
2011-04-27 11:58:34 +00:00
|
|
|
return;
|
|
|
|
|
2020-10-01 21:16:01 +00:00
|
|
|
scoped_callback_timer timer([scene](double time) {
|
|
|
|
if (scene->update_stats) {
|
|
|
|
scene->update_stats->light.times.add_entry({"device_update", time});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-04-22 08:55:26 +00:00
|
|
|
VLOG(1) << "Total " << scene->lights.size() << " lights.";
|
|
|
|
|
2021-02-05 05:23:34 +00:00
|
|
|
/* Detect which lights are enabled, also determines if we need to update the background. */
|
2020-05-14 15:41:37 +00:00
|
|
|
test_enabled_lights(scene);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2020-05-14 15:41:37 +00:00
|
|
|
device_free(device, dscene, need_update_background);
|
2013-06-08 13:43:38 +00:00
|
|
|
|
2020-05-14 15:41:37 +00:00
|
|
|
use_light_visibility = false;
|
2016-02-06 21:21:38 +00:00
|
|
|
|
|
|
|
device_update_points(device, dscene, scene);
|
2011-04-27 11:58:34 +00:00
|
|
|
if (progress.get_cancel())
|
|
|
|
return;
|
|
|
|
|
|
|
|
device_update_distribution(device, dscene, scene, progress);
|
|
|
|
if (progress.get_cancel())
|
|
|
|
return;
|
|
|
|
|
2020-05-14 15:41:37 +00:00
|
|
|
if (need_update_background) {
|
|
|
|
device_update_background(device, dscene, scene, progress);
|
|
|
|
if (progress.get_cancel())
|
|
|
|
return;
|
|
|
|
}
|
2012-01-20 17:49:17 +00:00
|
|
|
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-26 22:46:37 +00:00
|
|
|
device_update_ies(dscene);
|
|
|
|
if (progress.get_cancel())
|
|
|
|
return;
|
|
|
|
|
2020-11-04 10:17:38 +00:00
|
|
|
scene->film->set_use_light_visibility(use_light_visibility);
|
2013-06-08 13:43:38 +00:00
|
|
|
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 14:01:26 +00:00
|
|
|
update_flags = UPDATE_NONE;
|
2020-05-14 15:41:37 +00:00
|
|
|
need_update_background = false;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2020-05-14 15:41:37 +00:00
|
|
|
void LightManager::device_free(Device *, DeviceScene *dscene, const bool free_background)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2017-10-20 23:09:59 +00:00
|
|
|
dscene->light_distribution.free();
|
2018-03-07 23:15:41 +00:00
|
|
|
dscene->lights.free();
|
2020-05-14 15:41:37 +00:00
|
|
|
if (free_background) {
|
|
|
|
dscene->light_background_marginal_cdf.free();
|
|
|
|
dscene->light_background_conditional_cdf.free();
|
|
|
|
}
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-26 22:46:37 +00:00
|
|
|
dscene->ies_lights.free();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 14:01:26 +00:00
|
|
|
void LightManager::tag_update(Scene * /*scene*/, uint32_t flag)
|
|
|
|
{
|
|
|
|
update_flags |= flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LightManager::need_update() const
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 14:01:26 +00:00
|
|
|
return update_flags != UPDATE_NONE;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 12:04:23 +00:00
|
|
|
int LightManager::add_ies_from_file(const string &filename)
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-26 22:46:37 +00:00
|
|
|
{
|
|
|
|
string content;
|
2018-05-27 21:46:02 +00:00
|
|
|
|
2018-05-27 15:14:01 +00:00
|
|
|
/* If the file can't be opened, call with an empty line */
|
|
|
|
if (filename.empty() || !path_read_text(filename.c_str(), content)) {
|
2018-05-27 21:46:02 +00:00
|
|
|
content = "\n";
|
2018-05-27 15:14:01 +00:00
|
|
|
}
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-26 22:46:37 +00:00
|
|
|
|
2019-08-14 12:04:23 +00:00
|
|
|
return add_ies(content);
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-26 22:46:37 +00:00
|
|
|
}
|
|
|
|
|
2019-08-14 12:04:23 +00:00
|
|
|
int LightManager::add_ies(const string &content)
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-26 22:46:37 +00:00
|
|
|
{
|
|
|
|
uint hash = hash_string(content.c_str());
|
2019-04-17 04:17:24 +00:00
|
|
|
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-26 22:46:37 +00:00
|
|
|
thread_scoped_lock ies_lock(ies_mutex);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-26 22:46:37 +00:00
|
|
|
/* Check whether this IES already has a slot. */
|
|
|
|
size_t slot;
|
|
|
|
for (slot = 0; slot < ies_slots.size(); slot++) {
|
|
|
|
if (ies_slots[slot]->hash == hash) {
|
|
|
|
ies_slots[slot]->users++;
|
|
|
|
return slot;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-26 22:46:37 +00:00
|
|
|
/* Try to find an empty slot for the new IES. */
|
|
|
|
for (slot = 0; slot < ies_slots.size(); slot++) {
|
|
|
|
if (ies_slots[slot]->users == 0 && ies_slots[slot]->hash == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-26 22:46:37 +00:00
|
|
|
/* If there's no free slot, add one. */
|
|
|
|
if (slot == ies_slots.size()) {
|
|
|
|
ies_slots.push_back(new IESSlot());
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-26 22:46:37 +00:00
|
|
|
ies_slots[slot]->ies.load(content);
|
|
|
|
ies_slots[slot]->users = 1;
|
|
|
|
ies_slots[slot]->hash = hash;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 14:01:26 +00:00
|
|
|
update_flags = UPDATE_ALL;
|
2020-05-14 15:41:37 +00:00
|
|
|
need_update_background = true;
|
2019-04-17 04:17:24 +00:00
|
|
|
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-26 22:46:37 +00:00
|
|
|
return slot;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LightManager::remove_ies(int slot)
|
|
|
|
{
|
|
|
|
thread_scoped_lock ies_lock(ies_mutex);
|
|
|
|
|
|
|
|
if (slot < 0 || slot >= ies_slots.size()) {
|
|
|
|
assert(false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(ies_slots[slot]->users > 0);
|
|
|
|
ies_slots[slot]->users--;
|
|
|
|
|
|
|
|
/* If the slot has no more users, update the device to remove it. */
|
Cycles: optimize device updates
This optimizes device updates (during user edits or frame changes in
the viewport) by avoiding unnecessary computations. To achieve this,
we use a combination of the sockets' update flags as well as some new
flags passed to the various managers when tagging for an update to tell
exactly what the tagging is for (e.g. shader was modified, object was
removed, etc.).
Besides avoiding recomputations, we also avoid resending to the devices
unmodified data arrays, thus reducing bandwidth usage. For OptiX and
Embree, BVH packing was also multithreaded.
The performance improvements may vary depending on the used device (CPU
or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive
subdivision or volumes) rendered using OptiX will benefit from this work
the most.
On average, for a variety of animated scenes, this gives a 3x speedup.
Reviewed By: #cycles, brecht
Maniphest Tasks: T79174
Differential Revision: https://developer.blender.org/D9555
2021-01-22 14:01:26 +00:00
|
|
|
if (ies_slots[slot]->users == 0) {
|
|
|
|
update_flags |= UPDATE_ALL;
|
|
|
|
need_update_background = true;
|
|
|
|
}
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-26 22:46:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void LightManager::device_update_ies(DeviceScene *dscene)
|
|
|
|
{
|
|
|
|
/* Clear empty slots. */
|
|
|
|
foreach (IESSlot *slot, ies_slots) {
|
|
|
|
if (slot->users == 0) {
|
|
|
|
slot->hash = 0;
|
|
|
|
slot->ies.clear();
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-26 22:46:37 +00:00
|
|
|
/* Shrink the slot table by removing empty slots at the end. */
|
|
|
|
int slot_end;
|
|
|
|
for (slot_end = ies_slots.size(); slot_end; slot_end--) {
|
|
|
|
if (ies_slots[slot_end - 1]->users > 0) {
|
|
|
|
/* If the preceding slot has users, we found the new end of the table. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* The slot will be past the new end of the table, so free it. */
|
|
|
|
delete ies_slots[slot_end - 1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ies_slots.resize(slot_end);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-26 22:46:37 +00:00
|
|
|
if (ies_slots.size() > 0) {
|
|
|
|
int packed_size = 0;
|
|
|
|
foreach (IESSlot *slot, ies_slots) {
|
|
|
|
packed_size += slot->ies.packed_size();
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-26 22:46:37 +00:00
|
|
|
/* ies_lights starts with an offset table that contains the offset of every slot,
|
|
|
|
* or -1 if the slot is invalid.
|
|
|
|
* Following that table, the packed valid IES lights are stored. */
|
|
|
|
float *data = dscene->ies_lights.alloc(ies_slots.size() + packed_size);
|
2019-04-17 04:17:24 +00:00
|
|
|
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-26 22:46:37 +00:00
|
|
|
int offset = ies_slots.size();
|
|
|
|
for (int i = 0; i < ies_slots.size(); i++) {
|
|
|
|
int size = ies_slots[i]->ies.packed_size();
|
|
|
|
if (size > 0) {
|
|
|
|
data[i] = __int_as_float(offset);
|
|
|
|
ies_slots[i]->ies.pack(data + offset);
|
|
|
|
offset += size;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
data[i] = __int_as_float(-1);
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
|
Cycles: Add Support for IES files as textures for light strength
This patch adds support for IES files, a file format that is commonly used to store the directional intensity distribution of light sources.
The new IES node is supposed to be plugged into the Strength input of the Emission node of the lamp.
Since people generating IES files do not really seem to care about the standard, the parser is flexible enough to accept all test files I have tried.
Some common weirdnesses are distributing values over multiple lines that should go into one line, using commas instead of spaces as delimiters and adding various useless stuff at the end of the file.
The user interface of the node is similar to the script node, the user can either select an internal Text or load a file.
Internally, IES files are handled similar to Image textures: They are stored in slots by the LightManager and each unique IES is assigned to one slot.
The local coordinate system of the lamp is used, so that the direction of the light can be changed. For UI reasons, it's usually best to add an area light,
rotate it and then change its type, since especially the point light does not immediately show its local coordinate system in the viewport.
Reviewers: #cycles, dingto, sergey, brecht
Reviewed By: #cycles, dingto, brecht
Subscribers: OgDEV, crazyrobinhood, secundar, cardboard, pisuke, intrah, swerner, micah_denn, harvester, gottfried, disnel, campbellbarton, duarteframos, Lapineige, brecht, juicyfruit, dingto, marek, rickyblender, bliblubli, lockal, sergey
Differential Revision: https://developer.blender.org/D1543
2018-05-26 22:46:37 +00:00
|
|
|
dscene->ies_lights.copy_to_device();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|