Cycles: Make all #include statements relative to cycles source directory
[blender.git] / intern / cycles / blender / blender_shader.cpp
index 78a28b7feedccbbaf726c14540b372be9ad81561..0cd4b90340b2fdc016b323aef7c64dc2f1a0b866 100644 (file)
  * limitations under the License.
  */
 
-#include "background.h"
-#include "graph.h"
-#include "light.h"
-#include "nodes.h"
-#include "osl.h"
-#include "scene.h"
-#include "shader.h"
-
-#include "blender_texture.h"
-#include "blender_sync.h"
-#include "blender_util.h"
-
-#include "util_debug.h"
+#include "render/background.h"
+#include "render/graph.h"
+#include "render/light.h"
+#include "render/nodes.h"
+#include "render/osl.h"
+#include "render/scene.h"
+#include "render/shader.h"
+
+#include "blender/blender_texture.h"
+#include "blender/blender_sync.h"
+#include "blender/blender_util.h"
+
+#include "util/util_debug.h"
+#include "util/util_string.h"
+#include "util/util_task.h"
 
 CCL_NAMESPACE_BEGIN
 
 typedef map<void*, ShaderInput*> PtrInputMap;
 typedef map<void*, ShaderOutput*> PtrOutputMap;
-typedef map<std::string, ConvertNode*> ProxyMap;
+typedef map<string, ConvertNode*> ProxyMap;
 
 /* Find */
 
@@ -64,6 +66,14 @@ static VolumeInterpolation get_volume_interpolation(PointerRNA& ptr)
                                             VOLUME_INTERPOLATION_LINEAR);
 }
 
+static DisplacementMethod get_displacement_method(PointerRNA& ptr)
+{
+       return (DisplacementMethod)get_enum(ptr,
+                                           "displacement_method",
+                                           DISPLACE_NUM_METHODS,
+                                           DISPLACE_BUMP);
+}
+
 static int validate_enum_value(int value, int num_values, int default_value)
 {
        if(value >= num_values) {
@@ -393,6 +403,9 @@ static ShaderNode *add_node(Scene *scene,
                        case BL::ShaderNodeBsdfAnisotropic::distribution_GGX:
                                aniso->distribution = CLOSURE_BSDF_MICROFACET_GGX_ANISO_ID;
                                break;
+                       case BL::ShaderNodeBsdfAnisotropic::distribution_MULTI_GGX:
+                               aniso->distribution = CLOSURE_BSDF_MICROFACET_MULTI_GGX_ANISO_ID;
+                               break;
                        case BL::ShaderNodeBsdfAnisotropic::distribution_ASHIKHMIN_SHIRLEY:
                                aniso->distribution = CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ANISO_ID;
                                break;
@@ -437,7 +450,10 @@ static ShaderNode *add_node(Scene *scene,
                                glossy->distribution = CLOSURE_BSDF_MICROFACET_GGX_ID;
                                break;
                        case BL::ShaderNodeBsdfGlossy::distribution_ASHIKHMIN_SHIRLEY:
-                               glossy->distribution = CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ANISO_ID;
+                               glossy->distribution = CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID;
+                               break;
+                       case BL::ShaderNodeBsdfGlossy::distribution_MULTI_GGX:
+                               glossy->distribution = CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID;
                                break;
                }
                node = glossy;
@@ -455,6 +471,9 @@ static ShaderNode *add_node(Scene *scene,
                        case BL::ShaderNodeBsdfGlass::distribution_GGX:
                                glass->distribution = CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID;
                                break;
+                       case BL::ShaderNodeBsdfGlass::distribution_MULTI_GGX:
+                               glass->distribution = CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID;
+                               break;
                }
                node = glass;
        }
@@ -591,7 +610,8 @@ static ShaderNode *add_node(Scene *scene,
                        bool is_builtin = b_image.packed_file() ||
                                          b_image.source() == BL::Image::source_GENERATED ||
                                          b_image.source() == BL::Image::source_MOVIE ||
-                                         b_engine.is_preview();
+                                         (b_engine.is_preview() &&
+                                          b_image.source() != BL::Image::source_SEQUENCE);
 
                        if(is_builtin) {
                                /* for builtin images we're using image datablock name to find an image to
@@ -622,7 +642,8 @@ static ShaderNode *add_node(Scene *scene,
                                        image->filename.string(),
                                        image->builtin_data,
                                        get_image_interpolation(b_image_node),
-                                       get_image_extension(b_image_node));
+                                       get_image_extension(b_image_node),
+                                       image->use_alpha);
                        }
                }
                image->color_space = (NodeImageColorSpace)b_image_node.color_space();
@@ -643,7 +664,8 @@ static ShaderNode *add_node(Scene *scene,
                        bool is_builtin = b_image.packed_file() ||
                                          b_image.source() == BL::Image::source_GENERATED ||
                                          b_image.source() == BL::Image::source_MOVIE ||
-                                         b_engine.is_preview();
+                                         (b_engine.is_preview() &&
+                                          b_image.source() != BL::Image::source_SEQUENCE);
 
                        if(is_builtin) {
                                int scene_frame = b_scene.frame_current();
@@ -668,7 +690,8 @@ static ShaderNode *add_node(Scene *scene,
                                        env->filename.string(),
                                        env->builtin_data,
                                        get_image_interpolation(b_env_node),
-                                       EXTENSION_REPEAT);
+                                       EXTENSION_REPEAT,
+                                       env->use_alpha);
                        }
                }
                env->color_space = (NodeImageColorSpace)b_env_node.color_space();
@@ -805,7 +828,8 @@ static ShaderNode *add_node(Scene *scene,
                                point_density->filename.string(),
                                point_density->builtin_data,
                                point_density->interpolation,
-                               EXTENSION_CLIP);
+                               EXTENSION_CLIP,
+                               true);
                }
                node = point_density;
 
@@ -828,8 +852,10 @@ static ShaderNode *add_node(Scene *scene,
                }
        }
 
-       if(node)
+       if(node) {
+               node->name = b_node.name();
                graph->add(node);
+       }
 
        return node;
 }
@@ -1139,6 +1165,8 @@ void BlenderSync::sync_materials(bool update_all)
        /* material loop */
        BL::BlendData::materials_iterator b_mat;
 
+       TaskPool pool;
+
        for(b_data.materials.begin(b_mat); b_mat != b_data.materials.end(); ++b_mat) {
                Shader *shader;
 
@@ -1171,11 +1199,25 @@ void BlenderSync::sync_materials(bool update_all)
                        shader->heterogeneous_volume = !get_boolean(cmat, "homogeneous_volume");
                        shader->volume_sampling_method = get_volume_sampling(cmat);
                        shader->volume_interpolation_method = get_volume_interpolation(cmat);
+                       shader->displacement_method = (experimental) ? get_displacement_method(cmat) : DISPLACE_BUMP;
 
                        shader->set_graph(graph);
+
+                       /* By simplifying the shader graph as soon as possible, some redundant shader nodes
+                        * might be removed which prevents loading unneccessary attributes later.
+                        *
+                        * However, since graph simplification also accounts for e.g. mix weight, this would
+                        * cause frequent expensive resyncs in interactive sessions, so for those sessions
+                        * optimization is only performed right before compiling. */
+                       if(!preview) {
+                               pool.push(function_bind(&ShaderGraph::simplify, shader->graph, scene));
+                       }
+
                        shader->tag_update(scene);
                }
        }
+
+       pool.wait_work();
 }
 
 /* Sync World */