Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/blender/blender_shader.cpp
| Show First 20 Lines • Show All 229 Lines • ▼ Show 20 Lines | static void get_tex_mapping(TextureMapping *mapping, | ||||
| if(b_mapping.use_max()) | if(b_mapping.use_max()) | ||||
| mapping->max = get_float3(b_mapping.max()); | mapping->max = get_float3(b_mapping.max()); | ||||
| } | } | ||||
| static ShaderNode *add_node(Scene *scene, | static ShaderNode *add_node(Scene *scene, | ||||
| BL::RenderEngine& b_engine, | BL::RenderEngine& b_engine, | ||||
| BL::BlendData& b_data, | BL::BlendData& b_data, | ||||
| BL::Scene& b_scene, | BL::Scene& b_scene, | ||||
| BL::SceneLayer b_scene_layer, | BL::ViewLayer b_view_layer, | ||||
| const bool background, | const bool background, | ||||
| ShaderGraph *graph, | ShaderGraph *graph, | ||||
| BL::ShaderNodeTree& b_ntree, | BL::ShaderNodeTree& b_ntree, | ||||
| BL::ShaderNode& b_node) | BL::ShaderNode& b_node) | ||||
| { | { | ||||
| ShaderNode *node = NULL; | ShaderNode *node = NULL; | ||||
| /* existing blender nodes */ | /* existing blender nodes */ | ||||
| ▲ Show 20 Lines • Show All 580 Lines • ▼ Show 20 Lines | else if(b_node.is_a(&RNA_ShaderNodeTexPointDensity)) { | ||||
| point_density->interpolation = get_image_interpolation(b_point_density_node); | point_density->interpolation = get_image_interpolation(b_point_density_node); | ||||
| point_density->builtin_data = b_point_density_node.ptr.data; | point_density->builtin_data = b_point_density_node.ptr.data; | ||||
| /* 1 - render settings, 0 - vewport settings. */ | /* 1 - render settings, 0 - vewport settings. */ | ||||
| int settings = background ? 1 : 0; | int settings = background ? 1 : 0; | ||||
| /* TODO(sergey): Use more proper update flag. */ | /* TODO(sergey): Use more proper update flag. */ | ||||
| if(true) { | if(true) { | ||||
| b_point_density_node.cache_point_density(b_scene, b_scene_layer, settings); | b_point_density_node.cache_point_density(b_scene, b_view_layer, settings); | ||||
| scene->image_manager->tag_reload_image( | scene->image_manager->tag_reload_image( | ||||
| point_density->filename.string(), | point_density->filename.string(), | ||||
| point_density->builtin_data, | point_density->builtin_data, | ||||
| point_density->interpolation, | point_density->interpolation, | ||||
| EXTENSION_CLIP, | EXTENSION_CLIP, | ||||
| true); | true); | ||||
| } | } | ||||
| node = point_density; | node = point_density; | ||||
| /* Transformation form world space to texture space. | /* Transformation form world space to texture space. | ||||
| * | * | ||||
| * NOTE: Do this after the texture is cached, this is because getting | * NOTE: Do this after the texture is cached, this is because getting | ||||
| * min/max will need to access this cache. | * min/max will need to access this cache. | ||||
| */ | */ | ||||
| BL::Object b_ob(b_point_density_node.object()); | BL::Object b_ob(b_point_density_node.object()); | ||||
| if(b_ob) { | if(b_ob) { | ||||
| float3 loc, size; | float3 loc, size; | ||||
| point_density_texture_space(b_scene, b_scene_layer, | point_density_texture_space(b_scene, b_view_layer, | ||||
| b_point_density_node, | b_point_density_node, | ||||
| settings, | settings, | ||||
| loc, | loc, | ||||
| size); | size); | ||||
| point_density->tfm = | point_density->tfm = | ||||
| transform_translate(-loc) * transform_scale(size) * | transform_translate(-loc) * transform_scale(size) * | ||||
| transform_inverse(get_transform(b_ob.matrix_world())); | transform_inverse(get_transform(b_ob.matrix_world())); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | static BL::ShaderNode find_output_node(BL::ShaderNodeTree& b_ntree) | ||||
| return output_node; | return output_node; | ||||
| } | } | ||||
| static void add_nodes(Scene *scene, | static void add_nodes(Scene *scene, | ||||
| BL::RenderEngine& b_engine, | BL::RenderEngine& b_engine, | ||||
| BL::BlendData& b_data, | BL::BlendData& b_data, | ||||
| BL::Scene& b_scene, | BL::Scene& b_scene, | ||||
| BL::SceneLayer& b_scene_layer, | BL::ViewLayer& b_view_layer, | ||||
| const bool background, | const bool background, | ||||
| ShaderGraph *graph, | ShaderGraph *graph, | ||||
| BL::ShaderNodeTree& b_ntree, | BL::ShaderNodeTree& b_ntree, | ||||
| const ProxyMap &proxy_input_map, | const ProxyMap &proxy_input_map, | ||||
| const ProxyMap &proxy_output_map) | const ProxyMap &proxy_output_map) | ||||
| { | { | ||||
| /* add nodes */ | /* add nodes */ | ||||
| BL::ShaderNodeTree::nodes_iterator b_node; | BL::ShaderNodeTree::nodes_iterator b_node; | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | else if(b_node->is_a(&RNA_ShaderNodeGroup) || b_node->is_a(&RNA_NodeCustomGroup)) { | ||||
| output_map[b_output->ptr.data] = proxy->outputs[0]; | output_map[b_output->ptr.data] = proxy->outputs[0]; | ||||
| } | } | ||||
| if(b_group_ntree) { | if(b_group_ntree) { | ||||
| add_nodes(scene, | add_nodes(scene, | ||||
| b_engine, | b_engine, | ||||
| b_data, | b_data, | ||||
| b_scene, | b_scene, | ||||
| b_scene_layer, | b_view_layer, | ||||
| background, | background, | ||||
| graph, | graph, | ||||
| b_group_ntree, | b_group_ntree, | ||||
| group_proxy_input_map, | group_proxy_input_map, | ||||
| group_proxy_output_map); | group_proxy_output_map); | ||||
| } | } | ||||
| } | } | ||||
| else if(b_node->is_a(&RNA_NodeGroupInput)) { | else if(b_node->is_a(&RNA_NodeGroupInput)) { | ||||
| Show All 31 Lines | else { | ||||
| node = graph->output(); | node = graph->output(); | ||||
| } | } | ||||
| else { | else { | ||||
| BL::ShaderNode b_shader_node(*b_node); | BL::ShaderNode b_shader_node(*b_node); | ||||
| node = add_node(scene, | node = add_node(scene, | ||||
| b_engine, | b_engine, | ||||
| b_data, | b_data, | ||||
| b_scene, | b_scene, | ||||
| b_scene_layer, | b_view_layer, | ||||
| background, | background, | ||||
| graph, | graph, | ||||
| b_ntree, | b_ntree, | ||||
| b_shader_node); | b_shader_node); | ||||
| } | } | ||||
| if(node) { | if(node) { | ||||
| /* map node sockets for linking */ | /* map node sockets for linking */ | ||||
| ▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | if(output && input) | ||||
| graph->connect(output, input); | graph->connect(output, input); | ||||
| } | } | ||||
| } | } | ||||
| static void add_nodes(Scene *scene, | static void add_nodes(Scene *scene, | ||||
| BL::RenderEngine& b_engine, | BL::RenderEngine& b_engine, | ||||
| BL::BlendData& b_data, | BL::BlendData& b_data, | ||||
| BL::Scene& b_scene, | BL::Scene& b_scene, | ||||
| BL::SceneLayer& b_scene_layer, | BL::ViewLayer& b_view_layer, | ||||
| const bool background, | const bool background, | ||||
| ShaderGraph *graph, | ShaderGraph *graph, | ||||
| BL::ShaderNodeTree& b_ntree) | BL::ShaderNodeTree& b_ntree) | ||||
| { | { | ||||
| static const ProxyMap empty_proxy_map; | static const ProxyMap empty_proxy_map; | ||||
| add_nodes(scene, | add_nodes(scene, | ||||
| b_engine, | b_engine, | ||||
| b_data, | b_data, | ||||
| b_scene, | b_scene, | ||||
| b_scene_layer, | b_view_layer, | ||||
| background, | background, | ||||
| graph, | graph, | ||||
| b_ntree, | b_ntree, | ||||
| empty_proxy_map, | empty_proxy_map, | ||||
| empty_proxy_map); | empty_proxy_map); | ||||
| } | } | ||||
| /* Sync Materials */ | /* Sync Materials */ | ||||
| Show All 22 Lines | if(shader_map.sync(&shader, *b_mat) || update_all) { | ||||
| shader->name = b_mat->name().c_str(); | shader->name = b_mat->name().c_str(); | ||||
| shader->pass_id = b_mat->pass_index(); | shader->pass_id = b_mat->pass_index(); | ||||
| /* create nodes */ | /* create nodes */ | ||||
| if(b_mat->use_nodes() && b_mat->node_tree()) { | if(b_mat->use_nodes() && b_mat->node_tree()) { | ||||
| BL::ShaderNodeTree b_ntree(b_mat->node_tree()); | BL::ShaderNodeTree b_ntree(b_mat->node_tree()); | ||||
| add_nodes(scene, b_engine, b_data, b_scene, b_scene_layer, !preview, graph, b_ntree); | add_nodes(scene, b_engine, b_data, b_scene, b_view_layer, !preview, graph, b_ntree); | ||||
| } | } | ||||
| else { | else { | ||||
| DiffuseBsdfNode *diffuse = new DiffuseBsdfNode(); | DiffuseBsdfNode *diffuse = new DiffuseBsdfNode(); | ||||
| diffuse->color = get_float3(b_mat->diffuse_color()); | diffuse->color = get_float3(b_mat->diffuse_color()); | ||||
| graph->add(diffuse); | graph->add(diffuse); | ||||
| ShaderNode *out = graph->output(); | ShaderNode *out = graph->output(); | ||||
| graph->connect(diffuse->output("BSDF"), out->input("Surface")); | graph->connect(diffuse->output("BSDF"), out->input("Surface")); | ||||
| ▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | void BlenderSync::sync_world(bool update_all) | ||||
| if(world_recalc || update_all || b_world.ptr.data != world_map) { | if(world_recalc || update_all || b_world.ptr.data != world_map) { | ||||
| Shader *shader = scene->default_background; | Shader *shader = scene->default_background; | ||||
| ShaderGraph *graph = new ShaderGraph(); | ShaderGraph *graph = new ShaderGraph(); | ||||
| /* create nodes */ | /* create nodes */ | ||||
| if(b_world && b_world.use_nodes() && b_world.node_tree()) { | if(b_world && b_world.use_nodes() && b_world.node_tree()) { | ||||
| BL::ShaderNodeTree b_ntree(b_world.node_tree()); | BL::ShaderNodeTree b_ntree(b_world.node_tree()); | ||||
| add_nodes(scene, b_engine, b_data, b_scene, b_scene_layer, !preview, graph, b_ntree); | add_nodes(scene, b_engine, b_data, b_scene, b_view_layer, !preview, graph, b_ntree); | ||||
| /* volume */ | /* volume */ | ||||
| PointerRNA cworld = RNA_pointer_get(&b_world.ptr, "cycles"); | PointerRNA cworld = RNA_pointer_get(&b_world.ptr, "cycles"); | ||||
| shader->heterogeneous_volume = !get_boolean(cworld, "homogeneous_volume"); | shader->heterogeneous_volume = !get_boolean(cworld, "homogeneous_volume"); | ||||
| shader->volume_sampling_method = get_volume_sampling(cworld); | shader->volume_sampling_method = get_volume_sampling(cworld); | ||||
| shader->volume_interpolation_method = get_volume_interpolation(cworld); | shader->volume_interpolation_method = get_volume_interpolation(cworld); | ||||
| } | } | ||||
| else if(b_world) { | else if(b_world) { | ||||
| ▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | void BlenderSync::sync_world(bool update_all) | ||||
| * this is so because Blender's preview render routines are not able | * this is so because Blender's preview render routines are not able | ||||
| * to tweak all cycles's settings depending on different circumstances | * to tweak all cycles's settings depending on different circumstances | ||||
| */ | */ | ||||
| if(b_engine.is_preview() == false) | if(b_engine.is_preview() == false) | ||||
| background->transparent = get_boolean(cscene, "film_transparent"); | background->transparent = get_boolean(cscene, "film_transparent"); | ||||
| else | else | ||||
| background->transparent = b_scene.render().alpha_mode() == BL::RenderSettings::alpha_mode_TRANSPARENT; | background->transparent = b_scene.render().alpha_mode() == BL::RenderSettings::alpha_mode_TRANSPARENT; | ||||
| background->use_shader = render_layer.use_background_shader; | background->use_shader = view_layer.use_background_shader; | ||||
| background->use_ao = background->use_ao && render_layer.use_background_ao; | background->use_ao = background->use_ao && view_layer.use_background_ao; | ||||
| if(background->modified(prevbackground)) | if(background->modified(prevbackground)) | ||||
| background->tag_update(scene); | background->tag_update(scene); | ||||
| } | } | ||||
| /* Sync Lamps */ | /* Sync Lamps */ | ||||
| void BlenderSync::sync_lamps(bool update_all) | void BlenderSync::sync_lamps(bool update_all) | ||||
| Show All 16 Lines | if(shader_map.sync(&shader, *b_lamp) || update_all) { | ||||
| ShaderGraph *graph = new ShaderGraph(); | ShaderGraph *graph = new ShaderGraph(); | ||||
| /* create nodes */ | /* create nodes */ | ||||
| if(b_lamp->use_nodes() && b_lamp->node_tree()) { | if(b_lamp->use_nodes() && b_lamp->node_tree()) { | ||||
| shader->name = b_lamp->name().c_str(); | shader->name = b_lamp->name().c_str(); | ||||
| BL::ShaderNodeTree b_ntree(b_lamp->node_tree()); | BL::ShaderNodeTree b_ntree(b_lamp->node_tree()); | ||||
| add_nodes(scene, b_engine, b_data, b_scene, b_scene_layer, !preview, graph, b_ntree); | add_nodes(scene, b_engine, b_data, b_scene, b_view_layer, !preview, graph, b_ntree); | ||||
| } | } | ||||
| else { | else { | ||||
| float strength = 1.0f; | float strength = 1.0f; | ||||
| if(b_lamp->type() == BL::Lamp::type_POINT || | if(b_lamp->type() == BL::Lamp::type_POINT || | ||||
| b_lamp->type() == BL::Lamp::type_SPOT || | b_lamp->type() == BL::Lamp::type_SPOT || | ||||
| b_lamp->type() == BL::Lamp::type_AREA) | b_lamp->type() == BL::Lamp::type_AREA) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines | |||||