Cycles: add a Pass Node

The Pass struct is now a Node and the passes are moved from the Film
class to the Scene class.

The Pass Node only has `type` and `name` as sockets as those seem to be
the only properties settable by exporters (other properties are implicit
and depend on the pass type).

This is part of T79131.

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D8591
This commit is contained in:
Kévin Dietrich
2020-08-18 12:15:46 +02:00
parent 673b1930d8
commit 1da0685076
9 changed files with 101 additions and 28 deletions

View File

@@ -645,7 +645,7 @@ void BlenderSession::bake(BL::Depsgraph &b_depsgraph_,
/* Passes are identified by name, so in order to return the combined pass we need to set the
* name. */
Pass::add(PASS_COMBINED, scene->film->passes, "Combined");
Pass::add(PASS_COMBINED, scene->passes, "Combined");
session->read_bake_tile_cb = function_bind(&BlenderSession::read_render_tile, this, _1);
session->write_render_tile_cb = function_bind(&BlenderSession::write_render_tile, this, _1);
@@ -678,7 +678,7 @@ void BlenderSession::bake(BL::Depsgraph &b_depsgraph_,
BufferParams buffer_params;
buffer_params.width = bake_width;
buffer_params.height = bake_height;
buffer_params.passes = scene->film->passes;
buffer_params.passes = scene->passes;
/* Update session. */
session->tile_manager.set_samples(session_params.samples);

View File

@@ -372,8 +372,10 @@ void BlenderSync::sync_film(BL::SpaceView3D &b_v3d)
Film *film = scene->film;
Film prevfilm = *film;
vector<Pass> prevpasses = scene->passes;
if (b_v3d) {
film->display_pass = update_viewport_display_passes(b_v3d, film->passes);
film->display_pass = update_viewport_display_passes(b_v3d, scene->passes);
}
film->exposure = get_float(cscene, "film_exposure");
@@ -403,7 +405,11 @@ void BlenderSync::sync_film(BL::SpaceView3D &b_v3d)
if (film->modified(prevfilm)) {
film->tag_update(scene);
film->tag_passes_update(scene, prevfilm.passes, false);
}
if (!Pass::equals(prevpasses, scene->passes)) {
film->tag_passes_update(scene, prevpasses, false);
film->tag_update(scene);
}
}

View File

@@ -97,17 +97,17 @@ void BakeManager::set(Scene *scene,
type = type_;
pass_filter = shader_type_to_pass_filter(type_, pass_filter_);
Pass::add(PASS_BAKE_PRIMITIVE, scene->film->passes);
Pass::add(PASS_BAKE_DIFFERENTIAL, scene->film->passes);
Pass::add(PASS_BAKE_PRIMITIVE, scene->passes);
Pass::add(PASS_BAKE_DIFFERENTIAL, scene->passes);
if (type == SHADER_EVAL_UV) {
/* force UV to be available */
Pass::add(PASS_UV, scene->film->passes);
Pass::add(PASS_UV, scene->passes);
}
/* force use_light_pass to be true if we bake more than just colors */
if (pass_filter & ~BAKE_FILTER_COLOR) {
Pass::add(PASS_LIGHT, scene->film->passes);
Pass::add(PASS_LIGHT, scene->passes);
}
/* create device and update scene */

View File

@@ -38,6 +38,60 @@ static bool compare_pass_order(const Pass &a, const Pass &b)
return (a.components > b.components);
}
NODE_DEFINE(Pass)
{
NodeType *type = NodeType::add("pass", create);
static NodeEnum pass_type_enum;
pass_type_enum.insert("combined", PASS_COMBINED);
pass_type_enum.insert("depth", PASS_DEPTH);
pass_type_enum.insert("normal", PASS_NORMAL);
pass_type_enum.insert("uv", PASS_UV);
pass_type_enum.insert("object_id", PASS_OBJECT_ID);
pass_type_enum.insert("material_id", PASS_MATERIAL_ID);
pass_type_enum.insert("motion", PASS_MOTION);
pass_type_enum.insert("motion_weight", PASS_MOTION_WEIGHT);
#ifdef __KERNEL_DEBUG__
pass_type_enum.insert("traversed_nodes", PASS_BVH_TRAVERSED_NODES);
pass_type_enum.insert("traverse_instances", PASS_BVH_TRAVERSED_INSTANCES);
pass_type_enum.insert("bvh_intersections", PASS_BVH_INTERSECTIONS);
pass_type_enum.insert("ray_bounces", PASS_RAY_BOUNCES);
#endif
pass_type_enum.insert("render_time", PASS_RENDER_TIME);
pass_type_enum.insert("cryptomatte", PASS_CRYPTOMATTE);
pass_type_enum.insert("aov_color", PASS_AOV_COLOR);
pass_type_enum.insert("aov_value", PASS_AOV_VALUE);
pass_type_enum.insert("adaptive_aux_buffer", PASS_ADAPTIVE_AUX_BUFFER);
pass_type_enum.insert("sample_count", PASS_SAMPLE_COUNT);
pass_type_enum.insert("mist", PASS_MIST);
pass_type_enum.insert("emission", PASS_EMISSION);
pass_type_enum.insert("background", PASS_BACKGROUND);
pass_type_enum.insert("ambient_occlusion", PASS_AO);
pass_type_enum.insert("shadow", PASS_SHADOW);
pass_type_enum.insert("diffuse_direct", PASS_DIFFUSE_DIRECT);
pass_type_enum.insert("diffuse_indirect", PASS_DIFFUSE_INDIRECT);
pass_type_enum.insert("diffuse_color", PASS_DIFFUSE_COLOR);
pass_type_enum.insert("glossy_direct", PASS_GLOSSY_DIRECT);
pass_type_enum.insert("glossy_indirect", PASS_GLOSSY_INDIRECT);
pass_type_enum.insert("glossy_color", PASS_GLOSSY_COLOR);
pass_type_enum.insert("transmission_direct", PASS_TRANSMISSION_DIRECT);
pass_type_enum.insert("transmission_indirect", PASS_TRANSMISSION_INDIRECT);
pass_type_enum.insert("transmission_color", PASS_TRANSMISSION_COLOR);
pass_type_enum.insert("volume_direct", PASS_VOLUME_DIRECT);
pass_type_enum.insert("volume_indirect", PASS_VOLUME_INDIRECT);
pass_type_enum.insert("bake_primitive", PASS_BAKE_PRIMITIVE);
pass_type_enum.insert("bake_differential", PASS_BAKE_DIFFERENTIAL);
SOCKET_ENUM(type, "Type", pass_type_enum, PASS_COMBINED);
SOCKET_STRING(name, "Name", ustring());
return type;
}
Pass::Pass() : Node(node_type)
{
}
void Pass::add(PassType type, vector<Pass> &passes, const char *name)
{
for (size_t i = 0; i < passes.size(); i++) {
@@ -330,8 +384,6 @@ NODE_DEFINE(Film)
Film::Film() : Node(node_type)
{
Pass::add(PASS_COMBINED, passes);
use_light_visibility = false;
filter_table_offset = TABLE_OFFSET_INVALID;
cryptomatte_passes = CRYPT_NONE;
@@ -344,6 +396,11 @@ Film::~Film()
{
}
void Film::add_default(Scene *scene)
{
Pass::add(PASS_COMBINED, scene->passes);
}
void Film::device_update(Device *device, DeviceScene *dscene, Scene *scene)
{
if (!need_update)
@@ -371,8 +428,8 @@ void Film::device_update(Device *device, DeviceScene *dscene, Scene *scene)
bool have_cryptomatte = false;
for (size_t i = 0; i < passes.size(); i++) {
Pass &pass = passes[i];
for (size_t i = 0; i < scene->passes.size(); i++) {
Pass &pass = scene->passes[i];
if (pass.type == PASS_NONE) {
continue;
@@ -601,26 +658,26 @@ void Film::device_free(Device * /*device*/, DeviceScene * /*dscene*/, Scene *sce
bool Film::modified(const Film &film)
{
return !Node::equals(film) || !Pass::equals(passes, film.passes);
return !Node::equals(film);
}
void Film::tag_passes_update(Scene *scene, const vector<Pass> &passes_, bool update_passes)
{
if (Pass::contains(passes, PASS_UV) != Pass::contains(passes_, PASS_UV)) {
if (Pass::contains(scene->passes, PASS_UV) != Pass::contains(passes_, PASS_UV)) {
scene->geometry_manager->tag_update(scene);
foreach (Shader *shader, scene->shaders)
shader->need_update_geometry = true;
}
else if (Pass::contains(passes, PASS_MOTION) != Pass::contains(passes_, PASS_MOTION)) {
else if (Pass::contains(scene->passes, PASS_MOTION) != Pass::contains(passes_, PASS_MOTION)) {
scene->geometry_manager->tag_update(scene);
}
else if (Pass::contains(passes, PASS_AO) != Pass::contains(passes_, PASS_AO)) {
else if (Pass::contains(scene->passes, PASS_AO) != Pass::contains(passes_, PASS_AO)) {
scene->integrator->tag_update(scene);
}
if (update_passes) {
passes = passes_;
scene->passes = passes_;
}
}
@@ -629,10 +686,10 @@ void Film::tag_update(Scene * /*scene*/)
need_update = true;
}
int Film::get_aov_offset(string name, bool &is_color)
int Film::get_aov_offset(Scene *scene, string name, bool &is_color)
{
int num_color = 0, num_value = 0;
foreach (const Pass &pass, passes) {
foreach (const Pass &pass, scene->passes) {
if (pass.type == PASS_AOV_COLOR) {
num_color++;
}

View File

@@ -38,14 +38,18 @@ typedef enum FilterType {
FILTER_NUM_TYPES,
} FilterType;
class Pass {
class Pass : public Node {
public:
NODE_DECLARE
Pass();
PassType type;
int components;
bool filter;
bool exposure;
PassType divide_type;
string name;
ustring name;
static void add(PassType type, vector<Pass> &passes, const char *name = NULL);
static bool equals(const vector<Pass> &A, const vector<Pass> &B);
@@ -57,7 +61,6 @@ class Film : public Node {
NODE_DECLARE
float exposure;
vector<Pass> passes;
bool denoising_data_pass;
bool denoising_clean_pass;
bool denoising_prefiltered_pass;
@@ -88,6 +91,9 @@ class Film : public Node {
Film();
~Film();
/* add default passes to scene */
static void add_default(Scene *scene);
void device_update(Device *device, DeviceScene *dscene, Scene *scene);
void device_free(Device *device, DeviceScene *dscene, Scene *scene);
@@ -95,7 +101,7 @@ class Film : public Node {
void tag_passes_update(Scene *scene, const vector<Pass> &passes_, bool update_passes = true);
void tag_update(Scene *scene);
int get_aov_offset(string name, bool &is_color);
int get_aov_offset(Scene *scene, string name, bool &is_color);
};
CCL_NAMESPACE_END

View File

@@ -152,7 +152,7 @@ void Integrator::device_update(Device *device, DeviceScene *dscene, Scene *scene
kintegrator->seed = hash_uint2(seed, 0);
kintegrator->use_ambient_occlusion = ((Pass::contains(scene->film->passes, PASS_AO)) ||
kintegrator->use_ambient_occlusion = ((Pass::contains(scene->passes, PASS_AO)) ||
dscene->data.background.ao_factor != 0.0f);
kintegrator->sample_clamp_direct = (sample_clamp_direct == 0.0f) ? FLT_MAX :

View File

@@ -5910,9 +5910,9 @@ OutputAOVNode::OutputAOVNode() : ShaderNode(node_type)
void OutputAOVNode::simplify_settings(Scene *scene)
{
slot = scene->film->get_aov_offset(name.string(), is_color);
slot = scene->film->get_aov_offset(scene, name.string(), is_color);
if (slot == -1) {
slot = scene->film->get_aov_offset(name.string(), is_color);
slot = scene->film->get_aov_offset(scene, name.string(), is_color);
}
if (slot == -1 || is_color) {

View File

@@ -115,6 +115,8 @@ Scene::Scene(const SceneParams &params_, Device *device)
/* TODO(sergey): Check if it's indeed optimal value for the split kernel. */
max_closure_global = 1;
film->add_default(this);
/* OSL only works on the CPU */
if (device->info.has_osl)
shader_manager = ShaderManager::create(params.shadingsystem);
@@ -322,7 +324,7 @@ Scene::MotionType Scene::need_motion()
{
if (integrator->motion_blur)
return MOTION_BLUR;
else if (Pass::contains(film->passes, PASS_MOTION))
else if (Pass::contains(passes, PASS_MOTION))
return MOTION_PASS;
else
return MOTION_NONE;
@@ -339,7 +341,7 @@ float Scene::motion_shutter_time()
bool Scene::need_global_attribute(AttributeStandard std)
{
if (std == ATTR_STD_UV)
return Pass::contains(film->passes, PASS_UV);
return Pass::contains(passes, PASS_UV);
else if (std == ATTR_STD_MOTION_VERTEX_POSITION)
return need_motion() != MOTION_NONE;
else if (std == ATTR_STD_MOTION_VERTEX_NORMAL)

View File

@@ -19,6 +19,7 @@
#include "bvh/bvh_params.h"
#include "render/film.h"
#include "render/image.h"
#include "render/shader.h"
@@ -230,6 +231,7 @@ class Scene {
vector<Shader *> shaders;
vector<Light *> lights;
vector<ParticleSystem *> particle_systems;
vector<Pass> passes;
/* data managers */
ImageManager *image_manager;