Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc
| Show All 11 Lines | |||||
| * You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
| * along with this program; if not, write to the Free Software Foundation, | * along with this program; if not, write to the Free Software Foundation, | ||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
| * | * | ||||
| * The Original Code is Copyright (C) 2005 Blender Foundation. | * The Original Code is Copyright (C) 2005 Blender Foundation. | ||||
| * All rights reserved. | * All rights reserved. | ||||
| */ | */ | ||||
| #include "node_shader_util.hh" | #include "../node_shader_util.h" | ||||
| #include "BLI_noise.hh" | #include "BLI_noise.hh" | ||||
| namespace blender::nodes::node_shader_tex_voronoi_cc { | namespace blender::nodes { | ||||
| static void sh_node_tex_voronoi_declare(NodeDeclarationBuilder &b) | static void sh_node_tex_voronoi_declare(NodeDeclarationBuilder &b) | ||||
| { | { | ||||
| b.is_function_node(); | b.is_function_node(); | ||||
| b.add_input<decl::Vector>(N_("Vector")).hide_value().implicit_field(); | b.add_input<decl::Vector>(N_("Vector")).hide_value().implicit_field(); | ||||
| b.add_input<decl::Float>(N_("W")).min(-1000.0f).max(1000.0f); | b.add_input<decl::Float>(N_("W")).min(-1000.0f).max(1000.0f); | ||||
| b.add_input<decl::Float>(N_("Scale")).min(-1000.0f).max(1000.0f).default_value(5.0f); | b.add_input<decl::Float>(N_("Scale")).min(-1000.0f).max(1000.0f).default_value(5.0f); | ||||
| b.add_input<decl::Float>(N_("Smoothness")) | b.add_input<decl::Float>(N_("Smoothness")) | ||||
| Show All 9 Lines | b.add_input<decl::Float>(N_("Randomness")) | ||||
| .subtype(PROP_FACTOR); | .subtype(PROP_FACTOR); | ||||
| b.add_output<decl::Float>(N_("Distance")).no_muted_links(); | b.add_output<decl::Float>(N_("Distance")).no_muted_links(); | ||||
| b.add_output<decl::Color>(N_("Color")).no_muted_links(); | b.add_output<decl::Color>(N_("Color")).no_muted_links(); | ||||
| b.add_output<decl::Vector>(N_("Position")).no_muted_links(); | b.add_output<decl::Vector>(N_("Position")).no_muted_links(); | ||||
| b.add_output<decl::Float>(N_("W")).no_muted_links(); | b.add_output<decl::Float>(N_("W")).no_muted_links(); | ||||
| b.add_output<decl::Float>(N_("Radius")).no_muted_links(); | b.add_output<decl::Float>(N_("Radius")).no_muted_links(); | ||||
| }; | }; | ||||
| } // namespace blender::nodes | |||||
| static void node_shader_init_tex_voronoi(bNodeTree *UNUSED(ntree), bNode *node) | static void node_shader_init_tex_voronoi(bNodeTree *UNUSED(ntree), bNode *node) | ||||
| { | { | ||||
| NodeTexVoronoi *tex = (NodeTexVoronoi *)MEM_callocN(sizeof(NodeTexVoronoi), "NodeTexVoronoi"); | NodeTexVoronoi *tex = (NodeTexVoronoi *)MEM_callocN(sizeof(NodeTexVoronoi), "NodeTexVoronoi"); | ||||
| BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); | BKE_texture_mapping_default(&tex->base.tex_mapping, TEXMAP_TYPE_POINT); | ||||
| BKE_texture_colormapping_default(&tex->base.color_mapping); | BKE_texture_colormapping_default(&tex->base.color_mapping); | ||||
| tex->dimensions = 3; | tex->dimensions = 3; | ||||
| tex->distance = SHD_VORONOI_EUCLIDEAN; | tex->distance = SHD_VORONOI_EUCLIDEAN; | ||||
| tex->feature = SHD_VORONOI_F1; | tex->feature = SHD_VORONOI_F1; | ||||
| ▲ Show 20 Lines • Show All 100 Lines • ▼ Show 20 Lines | static void node_shader_update_tex_voronoi(bNodeTree *ntree, bNode *node) | ||||
| nodeSetSocketAvailability(ntree, | nodeSetSocketAvailability(ntree, | ||||
| outWSock, | outWSock, | ||||
| tex->feature != SHD_VORONOI_DISTANCE_TO_EDGE && | tex->feature != SHD_VORONOI_DISTANCE_TO_EDGE && | ||||
| tex->feature != SHD_VORONOI_N_SPHERE_RADIUS && | tex->feature != SHD_VORONOI_N_SPHERE_RADIUS && | ||||
| (ELEM(tex->dimensions, 1, 4))); | (ELEM(tex->dimensions, 1, 4))); | ||||
| nodeSetSocketAvailability(ntree, outRadiusSock, tex->feature == SHD_VORONOI_N_SPHERE_RADIUS); | nodeSetSocketAvailability(ntree, outRadiusSock, tex->feature == SHD_VORONOI_N_SPHERE_RADIUS); | ||||
| } | } | ||||
| namespace blender::nodes { | |||||
| static MultiFunction::ExecutionHints voronoi_execution_hints{50, false}; | static MultiFunction::ExecutionHints voronoi_execution_hints{50, false}; | ||||
| class VoronoiMinowskiFunction : public fn::MultiFunction { | class VoronoiMinowskiFunction : public fn::MultiFunction { | ||||
| private: | private: | ||||
| int dimensions_; | int dimensions_; | ||||
| int feature_; | int feature_; | ||||
| public: | public: | ||||
| ▲ Show 20 Lines • Show All 1,138 Lines • ▼ Show 20 Lines | else if (minowski) { | ||||
| builder.construct_and_set_matching_fn<VoronoiMinowskiFunction>(tex->dimensions, tex->feature); | builder.construct_and_set_matching_fn<VoronoiMinowskiFunction>(tex->dimensions, tex->feature); | ||||
| } | } | ||||
| else { | else { | ||||
| builder.construct_and_set_matching_fn<VoronoiMetricFunction>( | builder.construct_and_set_matching_fn<VoronoiMetricFunction>( | ||||
| tex->dimensions, tex->feature, tex->distance); | tex->dimensions, tex->feature, tex->distance); | ||||
| } | } | ||||
| } | } | ||||
| } // namespace blender::nodes::node_shader_tex_voronoi_cc | } // namespace blender::nodes | ||||
| void register_node_type_sh_tex_voronoi() | void register_node_type_sh_tex_voronoi(void) | ||||
| { | { | ||||
| namespace file_ns = blender::nodes::node_shader_tex_voronoi_cc; | |||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| sh_fn_node_type_base(&ntype, SH_NODE_TEX_VORONOI, "Voronoi Texture", NODE_CLASS_TEXTURE, 0); | sh_fn_node_type_base(&ntype, SH_NODE_TEX_VORONOI, "Voronoi Texture", NODE_CLASS_TEXTURE, 0); | ||||
| ntype.declare = file_ns::sh_node_tex_voronoi_declare; | ntype.declare = blender::nodes::sh_node_tex_voronoi_declare; | ||||
| node_type_init(&ntype, file_ns::node_shader_init_tex_voronoi); | node_type_init(&ntype, node_shader_init_tex_voronoi); | ||||
| node_type_storage( | node_type_storage( | ||||
| &ntype, "NodeTexVoronoi", node_free_standard_storage, node_copy_standard_storage); | &ntype, "NodeTexVoronoi", node_free_standard_storage, node_copy_standard_storage); | ||||
| node_type_gpu(&ntype, file_ns::node_shader_gpu_tex_voronoi); | node_type_gpu(&ntype, node_shader_gpu_tex_voronoi); | ||||
| node_type_update(&ntype, file_ns::node_shader_update_tex_voronoi); | node_type_update(&ntype, node_shader_update_tex_voronoi); | ||||
| ntype.build_multi_function = file_ns::sh_node_voronoi_build_multi_function; | ntype.build_multi_function = blender::nodes::sh_node_voronoi_build_multi_function; | ||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||