Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'intern/cycles/blender/blender_shader.cpp')
-rw-r--r--intern/cycles/blender/blender_shader.cpp115
1 files changed, 66 insertions, 49 deletions
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index eb9968a85c2..d6e3f33fa9d 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -231,16 +231,10 @@ static void get_tex_mapping(TextureMapping *mapping,
mapping->max = get_float3(b_mapping.max());
}
-static bool is_output_node(BL::Node& b_node)
-{
- return (b_node.is_a(&RNA_ShaderNodeOutputMaterial)
- || b_node.is_a(&RNA_ShaderNodeOutputWorld)
- || b_node.is_a(&RNA_ShaderNodeOutputLamp));
-}
-
static ShaderNode *add_node(Scene *scene,
BL::RenderEngine& b_engine,
BL::BlendData& b_data,
+ BL::Depsgraph& b_depsgraph,
BL::Scene& b_scene,
const bool background,
ShaderGraph *graph,
@@ -841,6 +835,7 @@ static ShaderNode *add_node(Scene *scene,
node = uvm;
}
else if(b_node.is_a(&RNA_ShaderNodeTexPointDensity)) {
+ /* TODO: fix point density to work with new view layer depsgraph */
BL::ShaderNodeTexPointDensity b_point_density_node(b_node);
PointDensityTextureNode *point_density = new PointDensityTextureNode();
point_density->filename = b_point_density_node.name();
@@ -853,7 +848,7 @@ static ShaderNode *add_node(Scene *scene,
/* TODO(sergey): Use more proper update flag. */
if(true) {
- b_point_density_node.cache_point_density(b_scene, settings);
+ b_point_density_node.cache_point_density(b_depsgraph, settings);
scene->image_manager->tag_reload_image(
point_density->filename.string(),
point_density->builtin_data,
@@ -871,7 +866,7 @@ static ShaderNode *add_node(Scene *scene,
BL::Object b_ob(b_point_density_node.object());
if(b_ob) {
float3 loc, size;
- point_density_texture_space(b_scene,
+ point_density_texture_space(b_depsgraph,
b_point_density_node,
settings,
loc,
@@ -983,9 +978,35 @@ static ShaderOutput *node_find_output_by_name(ShaderNode *node,
return node->output(name.c_str());
}
+static BL::ShaderNode find_output_node(BL::ShaderNodeTree& b_ntree)
+{
+ BL::ShaderNodeTree::nodes_iterator b_node;
+ BL::ShaderNode output_node(PointerRNA_NULL);
+
+ for(b_ntree.nodes.begin(b_node); b_node != b_ntree.nodes.end(); ++b_node) {
+ BL::ShaderNodeOutputMaterial b_output_node(*b_node);
+
+ if (b_output_node.is_a(&RNA_ShaderNodeOutputMaterial) ||
+ b_output_node.is_a(&RNA_ShaderNodeOutputWorld) ||
+ b_output_node.is_a(&RNA_ShaderNodeOutputLamp)) {
+ /* regular Cycles output node */
+ if(b_output_node.is_active_output()) {
+ output_node = b_output_node;
+ break;
+ }
+ else if(!output_node.ptr.data) {
+ output_node = b_output_node;
+ }
+ }
+ }
+
+ return output_node;
+}
+
static void add_nodes(Scene *scene,
BL::RenderEngine& b_engine,
BL::BlendData& b_data,
+ BL::Depsgraph& b_depsgraph,
BL::Scene& b_scene,
const bool background,
ShaderGraph *graph,
@@ -1002,23 +1023,7 @@ static void add_nodes(Scene *scene,
BL::Node::outputs_iterator b_output;
/* find the node to use for output if there are multiple */
- bool found_active_output = false;
- BL::ShaderNode output_node(PointerRNA_NULL);
-
- for(b_ntree.nodes.begin(b_node); b_node != b_ntree.nodes.end(); ++b_node) {
- if(is_output_node(*b_node)) {
- BL::ShaderNodeOutputMaterial b_output_node(*b_node);
-
- if(b_output_node.is_active_output()) {
- output_node = b_output_node;
- found_active_output = true;
- break;
- }
- else if(!output_node.ptr.data && !found_active_output) {
- output_node = b_output_node;
- }
- }
- }
+ BL::ShaderNode output_node = find_output_node(b_ntree);
/* add nodes */
for(b_ntree.nodes.begin(b_node); b_node != b_ntree.nodes.end(); ++b_node) {
@@ -1088,6 +1093,7 @@ static void add_nodes(Scene *scene,
add_nodes(scene,
b_engine,
b_data,
+ b_depsgraph,
b_scene,
background,
graph,
@@ -1127,16 +1133,15 @@ static void add_nodes(Scene *scene,
else {
ShaderNode *node = NULL;
- if(is_output_node(*b_node)) {
- if(b_node->ptr.data == output_node.ptr.data) {
- node = graph->output();
- }
+ if(b_node->ptr.data == output_node.ptr.data) {
+ node = graph->output();
}
else {
BL::ShaderNode b_shader_node(*b_node);
node = add_node(scene,
b_engine,
b_data,
+ b_depsgraph,
b_scene,
background,
graph,
@@ -1200,6 +1205,7 @@ static void add_nodes(Scene *scene,
static void add_nodes(Scene *scene,
BL::RenderEngine& b_engine,
BL::BlendData& b_data,
+ BL::Depsgraph& b_depsgraph,
BL::Scene& b_scene,
const bool background,
ShaderGraph *graph,
@@ -1209,6 +1215,7 @@ static void add_nodes(Scene *scene,
add_nodes(scene,
b_engine,
b_data,
+ b_depsgraph,
b_scene,
background,
graph,
@@ -1219,17 +1226,22 @@ static void add_nodes(Scene *scene,
/* Sync Materials */
-void BlenderSync::sync_materials(bool update_all)
+void BlenderSync::sync_materials(BL::Depsgraph& b_depsgraph, bool update_all)
{
shader_map.set_default(scene->default_surface);
- /* material loop */
- BL::BlendData::materials_iterator b_mat;
-
TaskPool pool;
set<Shader*> updated_shaders;
- for(b_data.materials.begin(b_mat); b_mat != b_data.materials.end(); ++b_mat) {
+ /* material loop */
+ BL::BlendData::materials_iterator b_mat_orig;
+ for(b_data.materials.begin(b_mat_orig);
+ b_mat_orig != b_data.materials.end();
+ ++b_mat_orig)
+ {
+ /* TODO(sergey): Iterate over evaluated data rather than using mapping. */
+ BL::Material b_mat_(b_depsgraph.evaluated_id_get(*b_mat_orig));
+ BL::Material *b_mat = &b_mat_;
Shader *shader;
/* test if we need to sync */
@@ -1243,7 +1255,7 @@ void BlenderSync::sync_materials(bool update_all)
if(b_mat->use_nodes() && b_mat->node_tree()) {
BL::ShaderNodeTree b_ntree(b_mat->node_tree());
- add_nodes(scene, b_engine, b_data, b_scene, !preview, graph, b_ntree);
+ add_nodes(scene, b_engine, b_data, b_depsgraph, b_scene, !preview, graph, b_ntree);
}
else {
DiffuseBsdfNode *diffuse = new DiffuseBsdfNode();
@@ -1299,7 +1311,7 @@ void BlenderSync::sync_materials(bool update_all)
/* Sync World */
-void BlenderSync::sync_world(bool update_all)
+void BlenderSync::sync_world(BL::Depsgraph& b_depsgraph, bool update_all)
{
Background *background = scene->background;
Background prevbackground = *background;
@@ -1314,7 +1326,7 @@ void BlenderSync::sync_world(bool update_all)
if(b_world && b_world.use_nodes() && b_world.node_tree()) {
BL::ShaderNodeTree b_ntree(b_world.node_tree());
- add_nodes(scene, b_engine, b_data, b_scene, !preview, graph, b_ntree);
+ add_nodes(scene, b_engine, b_data, b_depsgraph, b_scene, !preview, graph, b_ntree);
/* volume */
PointerRNA cworld = RNA_pointer_get(&b_world.ptr, "cycles");
@@ -1382,8 +1394,8 @@ void BlenderSync::sync_world(bool update_all)
background->transparent_roughness_threshold = 0.0f;
}
- background->use_shader = render_layer.use_background_shader;
- background->use_ao = background->use_ao && render_layer.use_background_ao;
+ background->use_shader = view_layer.use_background_shader;
+ background->use_ao = background->use_ao && view_layer.use_background_ao;
if(background->modified(prevbackground))
background->tag_update(scene);
@@ -1391,14 +1403,19 @@ void BlenderSync::sync_world(bool update_all)
/* Sync Lamps */
-void BlenderSync::sync_lamps(bool update_all)
+void BlenderSync::sync_lamps(BL::Depsgraph& b_depsgraph, bool update_all)
{
shader_map.set_default(scene->default_light);
/* lamp loop */
- BL::BlendData::lamps_iterator b_lamp;
-
- for(b_data.lamps.begin(b_lamp); b_lamp != b_data.lamps.end(); ++b_lamp) {
+ BL::BlendData::lamps_iterator b_lamp_orig;
+ for(b_data.lamps.begin(b_lamp_orig);
+ b_lamp_orig != b_data.lamps.end();
+ ++b_lamp_orig)
+ {
+ /* TODO(sergey): Iterate over evaluated data rather than using mapping. */
+ BL::Lamp b_lamp_(b_depsgraph.evaluated_id_get(*b_lamp_orig));
+ BL::Lamp *b_lamp = &b_lamp_;
Shader *shader;
/* test if we need to sync */
@@ -1411,7 +1428,7 @@ void BlenderSync::sync_lamps(bool update_all)
BL::ShaderNodeTree b_ntree(b_lamp->node_tree());
- add_nodes(scene, b_engine, b_data, b_scene, !preview, graph, b_ntree);
+ add_nodes(scene, b_engine, b_data, b_depsgraph, b_scene, !preview, graph, b_ntree);
}
else {
float strength = 1.0f;
@@ -1438,7 +1455,7 @@ void BlenderSync::sync_lamps(bool update_all)
}
}
-void BlenderSync::sync_shaders()
+void BlenderSync::sync_shaders(BL::Depsgraph& b_depsgraph)
{
/* for auto refresh images */
bool auto_refresh_update = false;
@@ -1451,9 +1468,9 @@ void BlenderSync::sync_shaders()
shader_map.pre_sync();
- sync_world(auto_refresh_update);
- sync_lamps(auto_refresh_update);
- sync_materials(auto_refresh_update);
+ sync_world(b_depsgraph, auto_refresh_update);
+ sync_lamps(b_depsgraph, auto_refresh_update);
+ sync_materials(b_depsgraph, auto_refresh_update);
/* false = don't delete unused shaders, not supported */
shader_map.post_sync(false);