Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/blender/blender_shader.cpp
| Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | for(size_t i = 0; i < scene->shaders.size(); i++) { | ||||
| if(scene->shaders[i] == shader) { | if(scene->shaders[i] == shader) { | ||||
| used_shaders.push_back(i); | used_shaders.push_back(i); | ||||
| scene->shaders[i]->tag_used(scene); | scene->shaders[i]->tag_used(scene); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* RNA translation utilities */ | |||||
| static VolumeSampling get_volume_sampling(PointerRNA& ptr) | |||||
| { | |||||
| return (VolumeSampling)get_enum(ptr, | |||||
| "volume_sampling", | |||||
| VOLUME_NUM_SAMPLING, | |||||
| VOLUME_SAMPLING_DISTANCE); | |||||
| } | |||||
| static VolumeInterpolation get_volume_interpolation(PointerRNA& ptr) | |||||
| { | |||||
| return (VolumeInterpolation)get_enum(ptr, | |||||
| "volume_interpolation", | |||||
| VOLUME_NUM_INTERPOLATION, | |||||
| VOLUME_INTERPOLATION_LINEAR); | |||||
| } | |||||
| static int validate_enum_value(int value, int num_values, int default_value) | |||||
| { | |||||
| if(value >= num_values) { | |||||
| return default_value; | |||||
| } | |||||
| return value; | |||||
| } | |||||
| template<typename NodeType> | |||||
| static InterpolationType get_image_interpolation(NodeType b_node) | |||||
| { | |||||
| int value = b_node.interpolation(); | |||||
| return (InterpolationType)validate_enum_value(value, | |||||
| INTERPOLATION_NUM_TYPES, | |||||
| INTERPOLATION_LINEAR); | |||||
| } | |||||
| template<typename NodeType> | |||||
| static ExtensionType get_image_extension(NodeType b_node) | |||||
| { | |||||
| int value = b_node.extension(); | |||||
| return (ExtensionType)validate_enum_value(value, | |||||
| EXTENSION_NUM_TYPES, | |||||
| EXTENSION_REPEAT); | |||||
| } | |||||
| /* Graph */ | /* Graph */ | ||||
| static BL::NodeSocket get_node_output(BL::Node& b_node, const string& name) | static BL::NodeSocket get_node_output(BL::Node& b_node, const string& name) | ||||
| { | { | ||||
| BL::Node::outputs_iterator b_out; | BL::Node::outputs_iterator b_out; | ||||
| for(b_node.outputs.begin(b_out); b_out != b_node.outputs.end(); ++b_out) | for(b_node.outputs.begin(b_out); b_out != b_node.outputs.end(); ++b_out) | ||||
| if(b_out->name() == name) | if(b_out->name() == name) | ||||
| ▲ Show 20 Lines • Show All 586 Lines • ▼ Show 20 Lines | if(b_image) { | ||||
| image->animated = b_image_node.image_user().use_auto_refresh(); | image->animated = b_image_node.image_user().use_auto_refresh(); | ||||
| image->use_alpha = b_image.use_alpha(); | image->use_alpha = b_image.use_alpha(); | ||||
| /* TODO(sergey): Does not work properly when we change builtin type. */ | /* TODO(sergey): Does not work properly when we change builtin type. */ | ||||
| if(b_image.is_updated()) { | if(b_image.is_updated()) { | ||||
| scene->image_manager->tag_reload_image( | scene->image_manager->tag_reload_image( | ||||
| image->filename, | image->filename, | ||||
| image->builtin_data, | image->builtin_data, | ||||
| (InterpolationType)b_image_node.interpolation(), | get_image_interpolation(b_image_node), | ||||
| (ExtensionType)b_image_node.extension()); | get_image_extension(b_image_node)); | ||||
| } | } | ||||
| } | } | ||||
| image->color_space = ImageTextureNode::color_space_enum[(int)b_image_node.color_space()]; | 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 = ImageTextureNode::projection_enum[(int)b_image_node.projection()]; | ||||
| image->interpolation = (InterpolationType)b_image_node.interpolation(); | image->interpolation = get_image_interpolation(b_image_node); | ||||
| image->extension = (ExtensionType)b_image_node.extension(); | image->extension = get_image_extension(b_image_node); | ||||
| image->projection_blend = b_image_node.projection_blend(); | image->projection_blend = b_image_node.projection_blend(); | ||||
| BL::TexMapping b_texture_mapping(b_image_node.texture_mapping()); | BL::TexMapping b_texture_mapping(b_image_node.texture_mapping()); | ||||
| get_tex_mapping(&image->tex_mapping, b_texture_mapping); | get_tex_mapping(&image->tex_mapping, b_texture_mapping); | ||||
| node = image; | node = image; | ||||
| } | } | ||||
| else if(b_node.is_a(&RNA_ShaderNodeTexEnvironment)) { | else if(b_node.is_a(&RNA_ShaderNodeTexEnvironment)) { | ||||
| BL::ShaderNodeTexEnvironment b_env_node(b_node); | BL::ShaderNodeTexEnvironment b_env_node(b_node); | ||||
| BL::Image b_image(b_env_node.image()); | BL::Image b_image(b_env_node.image()); | ||||
| Show All 19 Lines | if(b_image) { | ||||
| env->animated = b_env_node.image_user().use_auto_refresh(); | env->animated = b_env_node.image_user().use_auto_refresh(); | ||||
| env->builtin_data = NULL; | env->builtin_data = NULL; | ||||
| } | } | ||||
| env->use_alpha = b_image.use_alpha(); | env->use_alpha = b_image.use_alpha(); | ||||
| /* TODO(sergey): Does not work properly when we change builtin type. */ | /* TODO(sergey): Does not work properly when we change builtin type. */ | ||||
| if(b_image.is_updated()) { | if(b_image.is_updated()) { | ||||
| scene->image_manager->tag_reload_image(env->filename, | scene->image_manager->tag_reload_image( | ||||
| env->filename, | |||||
| env->builtin_data, | env->builtin_data, | ||||
| (InterpolationType)b_env_node.interpolation(), | get_image_interpolation(b_env_node), | ||||
| EXTENSION_REPEAT); | EXTENSION_REPEAT); | ||||
| } | } | ||||
| } | } | ||||
| env->color_space = EnvironmentTextureNode::color_space_enum[(int)b_env_node.color_space()]; | env->color_space = EnvironmentTextureNode::color_space_enum[(int)b_env_node.color_space()]; | ||||
| env->interpolation = (InterpolationType)b_env_node.interpolation(); | env->interpolation = get_image_interpolation(b_env_node); | ||||
| env->projection = EnvironmentTextureNode::projection_enum[(int)b_env_node.projection()]; | env->projection = EnvironmentTextureNode::projection_enum[(int)b_env_node.projection()]; | ||||
| BL::TexMapping b_texture_mapping(b_env_node.texture_mapping()); | BL::TexMapping b_texture_mapping(b_env_node.texture_mapping()); | ||||
| get_tex_mapping(&env->tex_mapping, b_texture_mapping); | get_tex_mapping(&env->tex_mapping, b_texture_mapping); | ||||
| node = env; | node = env; | ||||
| } | } | ||||
| else if(b_node.is_a(&RNA_ShaderNodeTexGradient)) { | else if(b_node.is_a(&RNA_ShaderNodeTexGradient)) { | ||||
| BL::ShaderNodeTexGradient b_gradient_node(b_node); | BL::ShaderNodeTexGradient b_gradient_node(b_node); | ||||
| GradientTextureNode *gradient = new GradientTextureNode(); | GradientTextureNode *gradient = new GradientTextureNode(); | ||||
| ▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | else if(b_node.is_a(&RNA_ShaderNodeUVMap)) { | ||||
| node = uvm; | node = uvm; | ||||
| } | } | ||||
| else if(b_node.is_a(&RNA_ShaderNodeTexPointDensity)) { | else if(b_node.is_a(&RNA_ShaderNodeTexPointDensity)) { | ||||
| BL::ShaderNodeTexPointDensity b_point_density_node(b_node); | BL::ShaderNodeTexPointDensity b_point_density_node(b_node); | ||||
| PointDensityTextureNode *point_density = new PointDensityTextureNode(); | PointDensityTextureNode *point_density = new PointDensityTextureNode(); | ||||
| point_density->filename = b_point_density_node.name(); | point_density->filename = b_point_density_node.name(); | ||||
| point_density->space = | point_density->space = | ||||
| PointDensityTextureNode::space_enum[(int)b_point_density_node.space()]; | PointDensityTextureNode::space_enum[(int)b_point_density_node.space()]; | ||||
| point_density->interpolation = | point_density->interpolation = get_image_interpolation(b_point_density_node); | ||||
| (InterpolationType)b_point_density_node.interpolation(); | |||||
| 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, settings); | b_point_density_node.cache_point_density(b_scene, settings); | ||||
| ▲ Show 20 Lines • Show All 358 Lines • ▼ Show 20 Lines | if(shader_map.sync(&shader, *b_mat) || update_all) { | ||||
| graph->connect(closure->output("BSDF"), out->input("Surface")); | graph->connect(closure->output("BSDF"), out->input("Surface")); | ||||
| } | } | ||||
| /* settings */ | /* settings */ | ||||
| PointerRNA cmat = RNA_pointer_get(&b_mat->ptr, "cycles"); | PointerRNA cmat = RNA_pointer_get(&b_mat->ptr, "cycles"); | ||||
| shader->use_mis = get_boolean(cmat, "sample_as_light"); | shader->use_mis = get_boolean(cmat, "sample_as_light"); | ||||
| shader->use_transparent_shadow = get_boolean(cmat, "use_transparent_shadow"); | shader->use_transparent_shadow = get_boolean(cmat, "use_transparent_shadow"); | ||||
| shader->heterogeneous_volume = !get_boolean(cmat, "homogeneous_volume"); | shader->heterogeneous_volume = !get_boolean(cmat, "homogeneous_volume"); | ||||
| shader->volume_sampling_method = (VolumeSampling)get_enum(cmat, "volume_sampling"); | shader->volume_sampling_method = get_volume_sampling(cmat); | ||||
| shader->volume_interpolation_method = (VolumeInterpolation)get_enum(cmat, "volume_interpolation"); | shader->volume_interpolation_method = get_volume_interpolation(cmat); | ||||
| shader->set_graph(graph); | shader->set_graph(graph); | ||||
| shader->tag_update(scene); | shader->tag_update(scene); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Sync World */ | /* Sync World */ | ||||
| Show All 13 Lines | if(world_recalc || update_all || b_world.ptr.data != world_map) { | ||||
| 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, !preview, graph, b_ntree); | add_nodes(scene, b_engine, b_data, b_scene, !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 = (VolumeSampling)get_enum(cworld, "volume_sampling"); | shader->volume_sampling_method = get_volume_sampling(cworld); | ||||
| shader->volume_interpolation_method = (VolumeInterpolation)get_enum(cworld, "volume_interpolation"); | shader->volume_interpolation_method = get_volume_interpolation(cworld); | ||||
| } | } | ||||
| else if(b_world) { | else if(b_world) { | ||||
| ShaderNode *closure, *out; | ShaderNode *closure, *out; | ||||
| closure = graph->add(new BackgroundNode()); | closure = graph->add(new BackgroundNode()); | ||||
| closure->input("Color")->value = get_float3(b_world.horizon_color()); | closure->input("Color")->value = get_float3(b_world.horizon_color()); | ||||
| out = graph->output(); | out = graph->output(); | ||||
| ▲ Show 20 Lines • Show All 126 Lines • Show Last 20 Lines | |||||