Code refactor: nodify Cycles background and film.

Differential Revision: https://developer.blender.org/D2016
This commit is contained in:
Brecht Van Lommel 2016-05-07 20:30:16 +02:00
parent 0062d9f58c
commit e7d13b8a1d
8 changed files with 84 additions and 85 deletions

@ -279,18 +279,6 @@ static ShaderSocketType xml_read_socket_type(pugi::xml_node node, const char *na
return SHADER_SOCKET_UNDEFINED;
}
/* Film */
static void xml_read_film(const XMLReadState& state, pugi::xml_node node)
{
Film *film = state.scene->film;
xml_read_float(&film->exposure, node, "exposure");
/* ToDo: Filter Type */
xml_read_float(&film->filter_width, node, "filter_width");
}
/* Camera */
static void xml_read_camera(const XMLReadState& state, pugi::xml_node node)
@ -839,15 +827,10 @@ static void xml_read_shader(const XMLReadState& state, pugi::xml_node node)
/* Background */
static void xml_read_background(const XMLReadState& state, pugi::xml_node node)
static void xml_read_background(XMLReadState& state, pugi::xml_node node)
{
/* Background Settings */
Background *bg = state.scene->background;
xml_read_float(&bg->ao_distance, node, "ao_distance");
xml_read_float(&bg->ao_factor, node, "ao_factor");
xml_read_bool(&bg->transparent, node, "transparent");
xml_read_node(state, state.scene->background, node);
/* Background Shader */
Shader *shader = state.scene->default_background;
@ -1185,7 +1168,7 @@ static void xml_read_scene(XMLReadState& state, pugi::xml_node scene_node)
{
for(pugi::xml_node node = scene_node.first_child(); node; node = node.next_sibling()) {
if(string_iequals(node.name(), "film")) {
xml_read_film(state, node);
xml_read_node(state, state.scene->film, node);
}
else if(string_iequals(node.name(), "integrator")) {
xml_read_node(state, state.scene->integrator, node);

@ -473,7 +473,7 @@ void BlenderSession::render()
BL::RenderLayer b_rlay = *b_single_rlay;
/* add passes */
vector<Pass> passes;
array<Pass> passes;
Pass::add(PASS_COMBINED, passes);
if(session_params.device.advanced_shading) {

@ -28,18 +28,25 @@
CCL_NAMESPACE_BEGIN
Background::Background()
NODE_DEFINE(Background)
{
ao_factor = 0.0f;
ao_distance = FLT_MAX;
NodeType* type = NodeType::add("background", create);
use_shader = true;
use_ao = false;
SOCKET_INT(ao_factor, "AO Factor", 0.0f);
SOCKET_FLOAT(ao_distance, "AO Distance", FLT_MAX);
visibility = PATH_RAY_ALL_VISIBILITY;
SOCKET_BOOLEAN(use_shader, "Use Shader", true);
SOCKET_BOOLEAN(use_ao, "Use AO", false);
SOCKET_INT(visibility, "Visibility", PATH_RAY_ALL_VISIBILITY);
SOCKET_BOOLEAN(transparent, "Transparent", false);
return type;
}
Background::Background()
: Node(node_type)
{
shader = NULL;
transparent = false;
need_update = true;
}
@ -108,16 +115,6 @@ void Background::device_free(Device * /*device*/, DeviceScene * /*dscene*/)
{
}
bool Background::modified(const Background& background)
{
return !(transparent == background.transparent &&
use_shader == background.use_shader &&
use_ao == background.use_ao &&
ao_factor == background.ao_factor &&
ao_distance == background.ao_distance &&
visibility == background.visibility);
}
void Background::tag_update(Scene *scene)
{
scene->integrator->tag_update(scene);

@ -17,6 +17,8 @@
#ifndef __BACKGROUND_H__
#define __BACKGROUND_H__
#include "node.h"
#include "util_types.h"
CCL_NAMESPACE_BEGIN
@ -26,8 +28,10 @@ class DeviceScene;
class Shader;
class Scene;
class Background {
class Background : public Node {
public:
NODE_DECLARE;
float ao_factor;
float ao_distance;
@ -46,7 +50,6 @@ public:
void device_update(Device *device, DeviceScene *dscene, Scene *scene);
void device_free(Device *device, DeviceScene *dscene);
bool modified(const Background& background);
void tag_update(Scene *scene);
};

@ -66,8 +66,8 @@ int BufferParams::get_passes_size()
{
int size = 0;
foreach(Pass& pass, passes)
size += pass.components;
for(size_t i = 0; i < passes.size(); i++)
size += passes[i].components;
return align_up(size, 4);
}
@ -160,7 +160,9 @@ bool RenderBuffers::get_pass_rect(PassType type, float exposure, int sample, int
{
int pass_offset = 0;
foreach(Pass& pass, params.passes) {
for(size_t j = 0; j < params.passes.size(); j++) {
Pass& pass = params.passes[j];
if(pass.type != type) {
pass_offset += pass.components;
continue;
@ -228,7 +230,8 @@ bool RenderBuffers::get_pass_rect(PassType type, float exposure, int sample, int
else if(pass.divide_type != PASS_NONE) {
/* RGB lighting passes that need to divide out color */
pass_offset = 0;
foreach(Pass& color_pass, params.passes) {
for(size_t k = 0; k < params.passes.size(); k++) {
Pass& color_pass = params.passes[k];
if(color_pass.type == pass.divide_type)
break;
pass_offset += color_pass.components;
@ -276,7 +279,8 @@ bool RenderBuffers::get_pass_rect(PassType type, float exposure, int sample, int
else if(type == PASS_MOTION) {
/* need to normalize by number of samples accumulated for motion */
pass_offset = 0;
foreach(Pass& color_pass, params.passes) {
for(size_t k = 0; k < params.passes.size(); k++) {
Pass& color_pass = params.passes[k];
if(color_pass.type == PASS_MOTION_WEIGHT)
break;
pass_offset += color_pass.components;

@ -50,7 +50,7 @@ public:
int full_height;
/* passes */
vector<Pass> passes;
array<Pass> passes;
/* functions */
BufferParams();

@ -39,10 +39,10 @@ static bool compare_pass_order(const Pass& a, const Pass& b)
return (a.components > b.components);
}
void Pass::add(PassType type, vector<Pass>& passes)
void Pass::add(PassType type, array<Pass>& passes)
{
foreach(Pass& existing_pass, passes)
if(existing_pass.type == type)
for(size_t i = 0; i < passes.size(); i++)
if(passes[i].type == type)
return;
Pass pass;
@ -169,17 +169,17 @@ void Pass::add(PassType type, vector<Pass>& passes)
#endif
}
passes.push_back(pass);
passes.push_back_slow(pass);
/* order from by components, to ensure alignment so passes with size 4
* come first and then passes with size 1 */
sort(passes.begin(), passes.end(), compare_pass_order);
sort(&passes[0], &passes[0] + passes.size(), compare_pass_order);
if(pass.divide_type != PASS_NONE)
Pass::add(pass.divide_type, passes);
}
bool Pass::equals(const vector<Pass>& A, const vector<Pass>& B)
bool Pass::equals(const array<Pass>& A, const array<Pass>& B)
{
if(A.size() != B.size())
return false;
@ -191,10 +191,10 @@ bool Pass::equals(const vector<Pass>& A, const vector<Pass>& B)
return true;
}
bool Pass::contains(const vector<Pass>& passes, PassType type)
bool Pass::contains(const array<Pass>& passes, PassType type)
{
foreach(const Pass& pass, passes)
if(pass.type == type)
for(size_t i = 0; i < passes.size(); i++)
if(passes[i].type == type)
return true;
return false;
@ -263,22 +263,37 @@ static vector<float> filter_table(FilterType type, float width)
/* Film */
Film::Film()
NODE_DEFINE(Film)
{
NodeType* type = NodeType::add("film", create);
SOCKET_FLOAT(exposure, "Exposure", 0.8f);
SOCKET_FLOAT(pass_alpha_threshold, "Pass Alpha Threshold", 0.5f);
static NodeEnum filter_enum;
filter_enum.insert("box", FILTER_BOX);
filter_enum.insert("gaussian", FILTER_GAUSSIAN);
filter_enum.insert("blackman_harris", FILTER_BLACKMAN_HARRIS);
SOCKET_ENUM(filter_type, "Filter Type", filter_enum, FILTER_BOX);
SOCKET_FLOAT(filter_width, "Filter Width", 1.0f);
SOCKET_FLOAT(mist_start, "Mist Start", 0.0f);
SOCKET_FLOAT(mist_depth, "Mist Depth", 100.0f);
SOCKET_FLOAT(mist_falloff, "Mist Falloff", 1.0f);
SOCKET_BOOLEAN(use_sample_clamp, "Use Sample Clamp", false);
return type;
}
Film::Film()
: Node(node_type)
{
exposure = 0.8f;
Pass::add(PASS_COMBINED, passes);
pass_alpha_threshold = 0.5f;
filter_type = FILTER_BOX;
filter_width = 1.0f;
filter_table_offset = TABLE_OFFSET_INVALID;
mist_start = 0.0f;
mist_depth = 100.0f;
mist_falloff = 1.0f;
use_light_visibility = false;
use_sample_clamp = false;
filter_table_offset = TABLE_OFFSET_INVALID;
need_update = true;
}
@ -302,7 +317,8 @@ void Film::device_update(Device *device, DeviceScene *dscene, Scene *scene)
kfilm->pass_stride = 0;
kfilm->use_light_pass = use_light_visibility || use_sample_clamp;
foreach(Pass& pass, passes) {
for(size_t i = 0; i < passes.size(); i++) {
Pass& pass = passes[i];
kfilm->pass_flag |= pass.type;
switch(pass.type) {
@ -449,18 +465,10 @@ void Film::device_free(Device * /*device*/,
bool Film::modified(const Film& film)
{
return !(exposure == film.exposure
&& Pass::equals(passes, film.passes)
&& pass_alpha_threshold == film.pass_alpha_threshold
&& use_sample_clamp == film.use_sample_clamp
&& filter_type == film.filter_type
&& filter_width == film.filter_width
&& mist_start == film.mist_start
&& mist_depth == film.mist_depth
&& mist_falloff == film.mist_falloff);
return Node::modified(film) || !Pass::equals(passes, film.passes);
}
void Film::tag_passes_update(Scene *scene, const vector<Pass>& passes_)
void Film::tag_passes_update(Scene *scene, const array<Pass>& passes_)
{
if(Pass::contains(passes, PASS_UV) != Pass::contains(passes_, PASS_UV)) {
scene->mesh_manager->tag_update(scene);

@ -22,6 +22,8 @@
#include "kernel_types.h"
#include "node.h"
CCL_NAMESPACE_BEGIN
class Device;
@ -44,15 +46,17 @@ public:
bool exposure;
PassType divide_type;
static void add(PassType type, vector<Pass>& passes);
static bool equals(const vector<Pass>& A, const vector<Pass>& B);
static bool contains(const vector<Pass>& passes, PassType);
static void add(PassType type, array<Pass>& passes);
static bool equals(const array<Pass>& A, const array<Pass>& B);
static bool contains(const array<Pass>& passes, PassType);
};
class Film {
class Film : public Node {
public:
NODE_DECLARE;
float exposure;
vector<Pass> passes;
array<Pass> passes;
float pass_alpha_threshold;
FilterType filter_type;
@ -75,7 +79,7 @@ public:
void device_free(Device *device, DeviceScene *dscene, Scene *scene);
bool modified(const Film& film);
void tag_passes_update(Scene *scene, const vector<Pass>& passes_);
void tag_passes_update(Scene *scene, const array<Pass>& passes_);
void tag_update(Scene *scene);
};