2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "scene/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 20:39:14 +02:00
|
|
|
#include "device/device.h"
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "scene/integrator.h"
|
2022-11-30 20:17:45 +01:00
|
|
|
#include "scene/light.h"
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "scene/scene.h"
|
|
|
|
|
#include "scene/shader.h"
|
|
|
|
|
#include "scene/shader_graph.h"
|
|
|
|
|
#include "scene/shader_nodes.h"
|
|
|
|
|
#include "scene/stats.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "util/math.h"
|
|
|
|
|
#include "util/time.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
2016-05-07 20:30:16 +02:00
|
|
|
NODE_DEFINE(Background)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2016-05-07 20:30:16 +02:00
|
|
|
NodeType *type = NodeType::add("background", create);
|
2012-02-28 16:45:08 +00:00
|
|
|
|
2016-05-07 20:30:16 +02:00
|
|
|
SOCKET_BOOLEAN(use_shader, "Use Shader", true);
|
2016-06-12 17:12:25 +02:00
|
|
|
SOCKET_UINT(visibility, "Visibility", PATH_RAY_ALL_VISIBILITY);
|
2018-01-11 20:03:31 +01:00
|
|
|
|
2016-05-07 20:30:16 +02:00
|
|
|
SOCKET_BOOLEAN(transparent, "Transparent", false);
|
2018-01-11 20:03:31 +01:00
|
|
|
SOCKET_BOOLEAN(transparent_glass, "Transparent Glass", false);
|
|
|
|
|
SOCKET_FLOAT(transparent_roughness_threshold, "Transparent Roughness Threshold", 0.0f);
|
2013-06-10 20:34:34 +00:00
|
|
|
|
2021-03-15 16:11:12 +01:00
|
|
|
SOCKET_NODE(shader, "Shader", Shader::get_node_type());
|
2016-05-08 00:18:32 +02:00
|
|
|
|
2022-04-02 00:11:11 +02:00
|
|
|
SOCKET_STRING(lightgroup, "Light Group", ustring());
|
|
|
|
|
|
2016-05-07 20:30:16 +02:00
|
|
|
return type;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-15 16:11:12 +01:00
|
|
|
Background::Background() : Node(get_node_type())
|
2016-05-07 20:30:16 +02:00
|
|
|
{
|
2024-12-26 17:53:55 +01:00
|
|
|
shader = nullptr;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Background::~Background()
|
|
|
|
|
{
|
2021-05-02 02:23:34 +02:00
|
|
|
dereference_all_used_nodes();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Background::device_update(Device *device, DeviceScene *dscene, Scene *scene)
|
|
|
|
|
{
|
2023-09-17 09:01:48 +10:00
|
|
|
if (!is_modified()) {
|
2011-04-27 11:58:34 +00:00
|
|
|
return;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-12-29 17:32:00 +01:00
|
|
|
const scoped_callback_timer timer([scene](double time) {
|
2020-10-01 23:16:01 +02:00
|
|
|
if (scene->update_stats) {
|
|
|
|
|
scene->update_stats->background.times.add_entry({"device_update", time});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
device_free(device, dscene);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-01-20 13:42:26 +01:00
|
|
|
Shader *bg_shader = get_shader(scene);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-08-28 13:55:59 +00:00
|
|
|
/* set shader index and transparent option */
|
2011-04-27 11:58:34 +00:00
|
|
|
KernelBackground *kbackground = &dscene->data.background;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-08-28 13:55:59 +00:00
|
|
|
kbackground->transparent = transparent;
|
2016-05-14 14:50:03 +02:00
|
|
|
kbackground->surface_shader = scene->shader_manager->get_shader_id(bg_shader);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-11 20:03:31 +01:00
|
|
|
if (transparent && transparent_glass) {
|
|
|
|
|
/* Square twice, once for principled BSDF convention, and once for
|
|
|
|
|
* faster comparison in kernel with anisotropic roughness. */
|
|
|
|
|
kbackground->transparent_roughness_squared_threshold = sqr(
|
|
|
|
|
sqr(transparent_roughness_threshold));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
kbackground->transparent_roughness_squared_threshold = -1.0f;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-09-17 09:01:48 +10:00
|
|
|
if (bg_shader->has_volume) {
|
2013-12-28 02:27:48 +01:00
|
|
|
kbackground->volume_shader = kbackground->surface_shader;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2014-03-29 13:03:47 +01:00
|
|
|
kbackground->volume_shader = SHADER_NONE;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-21 20:06:53 +01:00
|
|
|
/* No background node, make world shader invisible to all rays, to skip evaluation in kernel. */
|
2016-05-14 14:50:03 +02:00
|
|
|
if (bg_shader->graph->nodes.size() <= 1) {
|
2015-01-21 20:06:53 +01:00
|
|
|
kbackground->surface_shader |= SHADER_EXCLUDE_ANY;
|
|
|
|
|
}
|
|
|
|
|
/* Background present, check visibilities */
|
|
|
|
|
else {
|
2023-09-17 09:01:48 +10:00
|
|
|
if (!(visibility & PATH_RAY_DIFFUSE)) {
|
2015-01-21 20:06:53 +01:00
|
|
|
kbackground->surface_shader |= SHADER_EXCLUDE_DIFFUSE;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
|
|
|
|
if (!(visibility & PATH_RAY_GLOSSY)) {
|
2015-01-21 20:06:53 +01:00
|
|
|
kbackground->surface_shader |= SHADER_EXCLUDE_GLOSSY;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
|
|
|
|
if (!(visibility & PATH_RAY_TRANSMIT)) {
|
2015-01-21 20:06:53 +01:00
|
|
|
kbackground->surface_shader |= SHADER_EXCLUDE_TRANSMIT;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
|
|
|
|
if (!(visibility & PATH_RAY_VOLUME_SCATTER)) {
|
2015-01-21 20:06:53 +01:00
|
|
|
kbackground->surface_shader |= SHADER_EXCLUDE_SCATTER;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
|
|
|
|
if (!(visibility & PATH_RAY_CAMERA)) {
|
2015-01-21 20:06:53 +01:00
|
|
|
kbackground->surface_shader |= SHADER_EXCLUDE_CAMERA;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2015-01-21 20:06:53 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-04-02 00:11:11 +02:00
|
|
|
/* Light group. */
|
|
|
|
|
auto it = scene->lightgroups.find(lightgroup);
|
|
|
|
|
if (it != scene->lightgroups.end()) {
|
|
|
|
|
kbackground->lightgroup = it->second;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
kbackground->lightgroup = LIGHTGROUP_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-04 11:17:38 +01:00
|
|
|
clear_modified();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2023-03-29 16:50:54 +02:00
|
|
|
void Background::device_free(Device * /*device*/, DeviceScene * /*dscene*/) {}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
void Background::tag_update(Scene *scene)
|
|
|
|
|
{
|
2021-03-30 15:40:40 +02:00
|
|
|
Shader *bg_shader = get_shader(scene);
|
|
|
|
|
if (bg_shader && bg_shader->is_modified()) {
|
|
|
|
|
/* Tag as modified to update the KernelBackground visibility information.
|
|
|
|
|
* We only tag the use_shader socket as modified as it is related to the shader
|
|
|
|
|
* and to avoid doing unnecessary updates anywhere else. */
|
|
|
|
|
tag_use_shader_modified();
|
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2020-01-20 13:42:26 +01:00
|
|
|
Shader *Background::get_shader(const Scene *scene)
|
|
|
|
|
{
|
|
|
|
|
return (use_shader) ? ((shader) ? shader : scene->default_background) : scene->default_empty;
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|