Code refactor: nodify Cycles background and film.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Sat, 7 May 2016 18:30:16 +0000 (20:30 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Sun, 22 May 2016 15:29:25 +0000 (17:29 +0200)
Differential Revision: https://developer.blender.org/D2016

intern/cycles/app/cycles_xml.cpp
intern/cycles/blender/blender_session.cpp
intern/cycles/render/background.cpp
intern/cycles/render/background.h
intern/cycles/render/buffers.cpp
intern/cycles/render/buffers.h
intern/cycles/render/film.cpp
intern/cycles/render/film.h

index c2636a0e8c585b4033fc66b96cda6c1d867080c7..7f262c709e0d59784c782c4747e9da29c98263a0 100644 (file)
@@ -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);
index 7a5243d3234ad65fb9ca18c59b0fd3e51e18206d..80a16e0ef279ee45900541b333aa8b78688430bf 100644 (file)
@@ -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) {
index 89f90bc8dad53794a45ed807aae076b2719a1059..28ca04fe615b148dc092e873c0136e5c9d0db5ca 100644 (file)
 
 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;
-       shader = NULL;
+       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);
 
-       transparent = false;
+       return type;
+}
+
+Background::Background()
+: Node(node_type)
+{
+       shader = NULL;
        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);
index 645d002424e3b645fbb64bbd4daa6b42f67105f4..ae2ffe2b0781831f6e8624838506e19067411910 100644 (file)
@@ -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);
 };
 
index 558f5e59342617dcd11bef2c22aa38b72da77759..1e170d3a96ea3b768426dde043c8d9a2589b9a72 100644 (file)
@@ -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;
index 57ffd9630f50a3a8194922b9dc6aed46d2b598bd..c9c2a21079a2bd2ecbbbc32d7b4c20dcb796d7dd 100644 (file)
@@ -50,7 +50,7 @@ public:
        int full_height;
 
        /* passes */
-       vector<Pass> passes;
+       array<Pass> passes;
 
        /* functions */
        BufferParams();
index 95cb10ab13ba1301ede1c1d72381d4fda8edcb56..12dce6ad999dbc3cba973c4b655d70b8c6fdf99a 100644 (file)
@@ -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)
 {
-       exposure = 0.8f;
-       Pass::add(PASS_COMBINED, passes);
-       pass_alpha_threshold = 0.5f;
+       NodeType* type = NodeType::add("film", create);
 
-       filter_type = FILTER_BOX;
-       filter_width = 1.0f;
-       filter_table_offset = TABLE_OFFSET_INVALID;
+       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);
 
-       mist_start = 0.0f;
-       mist_depth = 100.0f;
-       mist_falloff = 1.0f;
+       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)
+{
+       Pass::add(PASS_COMBINED, passes);
 
        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);
index 966e00a8d1fa4a2ac469a7c1ef128cc9bfaa6ec4..9fa51c51f52bdbc9e8736dc80967b14cb1a5df71 100644 (file)
@@ -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);
 };