Fix #32796: cycles did not support image auto refresh option.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 21 Nov 2012 13:00:51 +0000 (13:00 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 21 Nov 2012 13:00:51 +0000 (13:00 +0000)
intern/cycles/blender/blender_shader.cpp
intern/cycles/blender/blender_sync.h
intern/cycles/render/image.cpp
intern/cycles/render/image.h
intern/cycles/render/nodes.cpp
intern/cycles/render/nodes.h

index 63cf719d010ccc7ef4b0b13faebfc606f8d6a2f2..da06f1d0a38b9e14babb8930383aac795abf095e 100644 (file)
@@ -500,8 +500,10 @@ static ShaderNode *add_node(Scene *scene, BL::BlendData b_data, BL::Scene b_scen
                        BL::Image b_image(b_image_node.image());
                        ImageTextureNode *image = new ImageTextureNode();
                        /* todo: handle generated/builtin images */
-                       if(b_image && b_image.source() != BL::Image::source_MOVIE)
+                       if(b_image && b_image.source() != BL::Image::source_MOVIE) {
                                image->filename = image_user_file_path(b_image_node.image_user(), b_image, b_scene.frame_current());
+                               image->animated = b_image_node.image_user().use_auto_refresh();
+                       }
                        image->color_space = ImageTextureNode::color_space_enum[(int)b_image_node.color_space()];
                        image->projection = ImageTextureNode::projection_enum[(int)b_image_node.projection()];
                        image->projection_blend = b_image_node.projection_blend();
@@ -513,8 +515,10 @@ static ShaderNode *add_node(Scene *scene, BL::BlendData b_data, BL::Scene b_scen
                        BL::ShaderNodeTexEnvironment b_env_node(b_node);
                        BL::Image b_image(b_env_node.image());
                        EnvironmentTextureNode *env = new EnvironmentTextureNode();
-                       if(b_image && b_image.source() != BL::Image::source_MOVIE)
+                       if(b_image && b_image.source() != BL::Image::source_MOVIE) {
                                env->filename = image_user_file_path(b_env_node.image_user(), b_image, b_scene.frame_current());
+                               env->animated = b_env_node.image_user().use_auto_refresh();
+                       }
                        env->color_space = EnvironmentTextureNode::color_space_enum[(int)b_env_node.color_space()];
                        env->projection = EnvironmentTextureNode::projection_enum[(int)b_env_node.projection()];
                        get_tex_mapping(&env->tex_mapping, b_env_node.texture_mapping());
@@ -821,7 +825,7 @@ static void add_nodes(Scene *scene, BL::BlendData b_data, BL::Scene b_scene, Sha
 
 /* Sync Materials */
 
-void BlenderSync::sync_materials()
+void BlenderSync::sync_materials(bool update_all)
 {
        shader_map.set_default(scene->shaders[scene->default_surface]);
 
@@ -832,7 +836,7 @@ void BlenderSync::sync_materials()
                Shader *shader;
                
                /* test if we need to sync */
-               if(shader_map.sync(&shader, *b_mat)) {
+               if(shader_map.sync(&shader, *b_mat) || update_all) {
                        ShaderGraph *graph = new ShaderGraph();
 
                        shader->name = b_mat->name().c_str();
@@ -868,14 +872,14 @@ void BlenderSync::sync_materials()
 
 /* Sync World */
 
-void BlenderSync::sync_world()
+void BlenderSync::sync_world(bool update_all)
 {
        Background *background = scene->background;
        Background prevbackground = *background;
 
        BL::World b_world = b_scene.world();
 
-       if(world_recalc || b_world.ptr.data != world_map) {
+       if(world_recalc || update_all || b_world.ptr.data != world_map) {
                Shader *shader = scene->shaders[scene->default_background];
                ShaderGraph *graph = new ShaderGraph();
 
@@ -922,7 +926,7 @@ void BlenderSync::sync_world()
 
 /* Sync Lamps */
 
-void BlenderSync::sync_lamps()
+void BlenderSync::sync_lamps(bool update_all)
 {
        shader_map.set_default(scene->shaders[scene->default_light]);
 
@@ -933,7 +937,7 @@ void BlenderSync::sync_lamps()
                Shader *shader;
                
                /* test if we need to sync */
-               if(shader_map.sync(&shader, *b_lamp)) {
+               if(shader_map.sync(&shader, *b_lamp) || update_all) {
                        ShaderGraph *graph = new ShaderGraph();
 
                        /* create nodes */
@@ -972,11 +976,20 @@ void BlenderSync::sync_lamps()
 
 void BlenderSync::sync_shaders()
 {
+       /* for auto refresh images */
+       bool auto_refresh_update = false;
+
+       if(preview) {
+               ImageManager *image_manager = scene->image_manager;
+               int frame = b_scene.frame_current();
+               auto_refresh_update = image_manager->set_animation_frame_update(frame);
+       }
+
        shader_map.pre_sync();
 
-       sync_world();
-       sync_lamps();
-       sync_materials();
+       sync_world(auto_refresh_update);
+       sync_lamps(auto_refresh_update);
+       sync_materials(auto_refresh_update);
 
        /* false = don't delete unused shaders, not supported */
        shader_map.post_sync(false);
index 71781bc5459a0d15cb6a0f4974584c11ce8488c1..d3d21fbdf72efecc268e89d20abcd4014f412c47 100644 (file)
@@ -68,14 +68,14 @@ public:
 
 private:
        /* sync */
-       void sync_lamps();
-       void sync_materials();
+       void sync_lamps(bool update_all);
+       void sync_materials(bool update_all);
        void sync_objects(BL::SpaceView3D b_v3d, int motion = 0);
        void sync_motion(BL::SpaceView3D b_v3d, BL::Object b_override);
        void sync_film();
        void sync_integrator();
        void sync_view();
-       void sync_world();
+       void sync_world(bool update_all);
        void sync_render_layers(BL::SpaceView3D b_v3d, const char *layer);
        void sync_shaders();
 
index 93c9e761f28b7bae70136058aa0fc88590747831..230a12f9ff208c84110dfc0c78c96f57117a2837 100644 (file)
@@ -36,6 +36,7 @@ ImageManager::ImageManager()
        need_update = true;
        pack_images = false;
        osl_texture_system = NULL;
+       animation_frame = 0;
 
        tex_num_images = TEX_NUM_IMAGES;
        tex_num_float_images = TEX_NUM_FLOAT_IMAGES;
@@ -67,6 +68,23 @@ void ImageManager::set_extended_image_limits(void)
        tex_image_byte_start = TEX_EXTENDED_IMAGE_BYTE_START;
 }
 
+bool ImageManager::set_animation_frame_update(int frame)
+{
+       if(frame != animation_frame) {
+               animation_frame = frame;
+
+               for(size_t slot = 0; slot < images.size(); slot++)
+                       if(images[slot] && images[slot]->animated)
+                               return true;
+
+               for(size_t slot = 0; slot < float_images.size(); slot++)
+                       if(float_images[slot] && float_images[slot]->animated)
+                               return true;
+       }
+       
+       return false;
+}
+
 bool ImageManager::is_float_image(const string& filename)
 {
        ImageInput *in = ImageInput::create(filename);
@@ -95,7 +113,7 @@ bool ImageManager::is_float_image(const string& filename)
        return is_float;
 }
 
-int ImageManager::add_image(const string& filename, bool& is_float)
+int ImageManager::add_image(const string& filename, bool animated, bool& is_float)
 {
        Image *img;
        size_t slot;
@@ -133,6 +151,7 @@ int ImageManager::add_image(const string& filename, bool& is_float)
                img = new Image();
                img->filename = filename;
                img->need_load = true;
+               img->animated = animated;
                img->users = 1;
 
                float_images[slot] = img;
@@ -166,6 +185,7 @@ int ImageManager::add_image(const string& filename, bool& is_float)
                img = new Image();
                img->filename = filename;
                img->need_load = true;
+               img->animated = animated;
                img->users = 1;
 
                images[slot] = img;
index 584448647d63aa1396c7f517ae7ea0efe6e5e8e8..4d177174971df0bc93c276e53f53d502cab50ea3 100644 (file)
@@ -51,7 +51,7 @@ public:
        ImageManager();
        ~ImageManager();
 
-       int add_image(const string& filename, bool& is_float);
+       int add_image(const string& filename, bool animated, bool& is_float);
        void remove_image(const string& filename);
        bool is_float_image(const string& filename);
 
@@ -60,8 +60,8 @@ public:
 
        void set_osl_texture_system(void *texture_system);
        void set_pack_images(bool pack_images_);
-
        void set_extended_image_limits(void);
+       bool set_animation_frame_update(int frame);
 
        bool need_update;
 
@@ -70,11 +70,13 @@ private:
        int tex_num_float_images;
        int tex_image_byte_start;
        thread_mutex device_mutex;
+       int animation_frame;
 
        struct Image {
                string filename;
 
                bool need_load;
+               bool animated;
                int users;
        };
 
index b297e6ea38c04054670a37336cb9de9a16306ecc..48a8565ed989698ef23bc2d6dec9f8f9958c1e98 100644 (file)
@@ -145,6 +145,7 @@ ImageTextureNode::ImageTextureNode()
        color_space = ustring("Color");
        projection = ustring("Flat");;
        projection_blend = 0.0f;
+       animated = false;
 
        add_input("Vector", SHADER_SOCKET_POINT, ShaderInput::TEXTURE_UV);
        add_output("Color", SHADER_SOCKET_COLOR);
@@ -175,7 +176,7 @@ void ImageTextureNode::compile(SVMCompiler& compiler)
        image_manager = compiler.image_manager;
        if(is_float == -1) {
                bool is_float_bool;
-               slot = image_manager->add_image(filename, is_float_bool);
+               slot = image_manager->add_image(filename, animated, is_float_bool);
                is_float = (int)is_float_bool;
        }
 
@@ -272,6 +273,7 @@ EnvironmentTextureNode::EnvironmentTextureNode()
        filename = "";
        color_space = ustring("Color");
        projection = ustring("Equirectangular");
+       animated = false;
 
        add_input("Vector", SHADER_SOCKET_VECTOR, ShaderInput::POSITION);
        add_output("Color", SHADER_SOCKET_COLOR);
@@ -302,7 +304,7 @@ void EnvironmentTextureNode::compile(SVMCompiler& compiler)
        image_manager = compiler.image_manager;
        if(slot == -1) {
                bool is_float_bool;
-               slot = image_manager->add_image(filename, is_float_bool);
+               slot = image_manager->add_image(filename, animated, is_float_bool);
                is_float = (int)is_float_bool;
        }
 
index d8f88cde2593be189a13af4e2a4f11c0c344febb..3e89c2286adec893006e046ffce77e26fb8fd846 100644 (file)
@@ -73,6 +73,7 @@ public:
        ustring color_space;
        ustring projection;
        float projection_blend;
+       bool animated;
 
        static ShaderEnum color_space_enum;
        static ShaderEnum projection_enum;
@@ -90,6 +91,7 @@ public:
        string filename;
        ustring color_space;
        ustring projection;
+       bool animated;
 
        static ShaderEnum color_space_enum;
        static ShaderEnum projection_enum;