Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/shader/nodes/node_shader_tex_noise.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_noise_cc { | namespace blender::nodes { | ||||
| static void sh_node_tex_noise_declare(NodeDeclarationBuilder &b) | static void sh_node_tex_noise_declare(NodeDeclarationBuilder &b) | ||||
| { | { | ||||
| b.is_function_node(); | b.is_function_node(); | ||||
| b.add_input<decl::Vector>(N_("Vector")).implicit_field(); | b.add_input<decl::Vector>(N_("Vector")).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_("Detail")).min(0.0f).max(15.0f).default_value(2.0f); | b.add_input<decl::Float>(N_("Detail")).min(0.0f).max(15.0f).default_value(2.0f); | ||||
| b.add_input<decl::Float>(N_("Roughness")) | b.add_input<decl::Float>(N_("Roughness")) | ||||
| .min(0.0f) | .min(0.0f) | ||||
| .max(1.0f) | .max(1.0f) | ||||
| .default_value(0.5f) | .default_value(0.5f) | ||||
| .subtype(PROP_FACTOR); | .subtype(PROP_FACTOR); | ||||
| b.add_input<decl::Float>(N_("Distortion")).min(-1000.0f).max(1000.0f).default_value(0.0f); | b.add_input<decl::Float>(N_("Distortion")).min(-1000.0f).max(1000.0f).default_value(0.0f); | ||||
| b.add_output<decl::Float>(N_("Fac")).no_muted_links(); | b.add_output<decl::Float>(N_("Fac")).no_muted_links(); | ||||
| b.add_output<decl::Color>(N_("Color")).no_muted_links(); | b.add_output<decl::Color>(N_("Color")).no_muted_links(); | ||||
| }; | }; | ||||
| } // namespace blender::nodes | |||||
| static void node_shader_init_tex_noise(bNodeTree *UNUSED(ntree), bNode *node) | static void node_shader_init_tex_noise(bNodeTree *UNUSED(ntree), bNode *node) | ||||
| { | { | ||||
| NodeTexNoise *tex = (NodeTexNoise *)MEM_callocN(sizeof(NodeTexNoise), "NodeTexNoise"); | NodeTexNoise *tex = (NodeTexNoise *)MEM_callocN(sizeof(NodeTexNoise), "NodeTexNoise"); | ||||
| 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; | ||||
| node->storage = tex; | node->storage = tex; | ||||
| Show All 28 Lines | static void node_shader_update_tex_noise(bNodeTree *ntree, bNode *node) | ||||
| bNodeSocket *sockVector = nodeFindSocket(node, SOCK_IN, "Vector"); | bNodeSocket *sockVector = nodeFindSocket(node, SOCK_IN, "Vector"); | ||||
| bNodeSocket *sockW = nodeFindSocket(node, SOCK_IN, "W"); | bNodeSocket *sockW = nodeFindSocket(node, SOCK_IN, "W"); | ||||
| NodeTexNoise *tex = (NodeTexNoise *)node->storage; | NodeTexNoise *tex = (NodeTexNoise *)node->storage; | ||||
| nodeSetSocketAvailability(ntree, sockVector, tex->dimensions != 1); | nodeSetSocketAvailability(ntree, sockVector, tex->dimensions != 1); | ||||
| nodeSetSocketAvailability(ntree, sockW, tex->dimensions == 1 || tex->dimensions == 4); | nodeSetSocketAvailability(ntree, sockW, tex->dimensions == 1 || tex->dimensions == 4); | ||||
| } | } | ||||
| namespace blender::nodes { | |||||
| class NoiseFunction : public fn::MultiFunction { | class NoiseFunction : public fn::MultiFunction { | ||||
| private: | private: | ||||
| int dimensions_; | int dimensions_; | ||||
| public: | public: | ||||
| NoiseFunction(int dimensions) : dimensions_(dimensions) | NoiseFunction(int dimensions) : dimensions_(dimensions) | ||||
| { | { | ||||
| BLI_assert(dimensions >= 1 && dimensions <= 4); | BLI_assert(dimensions >= 1 && dimensions <= 4); | ||||
| ▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | |||||
| static void sh_node_noise_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) | static void sh_node_noise_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder) | ||||
| { | { | ||||
| bNode &node = builder.node(); | bNode &node = builder.node(); | ||||
| NodeTexNoise *tex = (NodeTexNoise *)node.storage; | NodeTexNoise *tex = (NodeTexNoise *)node.storage; | ||||
| builder.construct_and_set_matching_fn<NoiseFunction>(tex->dimensions); | builder.construct_and_set_matching_fn<NoiseFunction>(tex->dimensions); | ||||
| } | } | ||||
| } // namespace blender::nodes::node_shader_tex_noise_cc | } // namespace blender::nodes | ||||
| /* node type definition */ | /* node type definition */ | ||||
| void register_node_type_sh_tex_noise() | void register_node_type_sh_tex_noise(void) | ||||
| { | { | ||||
| namespace file_ns = blender::nodes::node_shader_tex_noise_cc; | |||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| sh_fn_node_type_base(&ntype, SH_NODE_TEX_NOISE, "Noise Texture", NODE_CLASS_TEXTURE, 0); | sh_fn_node_type_base(&ntype, SH_NODE_TEX_NOISE, "Noise Texture", NODE_CLASS_TEXTURE, 0); | ||||
| ntype.declare = file_ns::sh_node_tex_noise_declare; | ntype.declare = blender::nodes::sh_node_tex_noise_declare; | ||||
| node_type_init(&ntype, file_ns::node_shader_init_tex_noise); | node_type_init(&ntype, node_shader_init_tex_noise); | ||||
| node_type_storage( | node_type_storage( | ||||
| &ntype, "NodeTexNoise", node_free_standard_storage, node_copy_standard_storage); | &ntype, "NodeTexNoise", node_free_standard_storage, node_copy_standard_storage); | ||||
| node_type_gpu(&ntype, file_ns::node_shader_gpu_tex_noise); | node_type_gpu(&ntype, node_shader_gpu_tex_noise); | ||||
| node_type_update(&ntype, file_ns::node_shader_update_tex_noise); | node_type_update(&ntype, node_shader_update_tex_noise); | ||||
| ntype.build_multi_function = file_ns::sh_node_noise_build_multi_function; | ntype.build_multi_function = blender::nodes::sh_node_noise_build_multi_function; | ||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||