Blender V5.3
node_shader_displacement.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "node_shader_util.hh"
10
11namespace blender {
12
14
16{
17 b.add_input<decl::Float>("Height"_ustr)
18 .default_value(0.0f)
19 .min(0.0f)
20 .max(1000.0f)
21 .description("Distance to displace the surface along the normal");
22 b.add_input<decl::Float>("Midlevel"_ustr)
23 .default_value(0.5f)
24 .min(0.0f)
25 .max(1000.0f)
27 "Neutral displacement value that causes no displacement.\n"
28 "Lower values cause the surface to move inwards, "
29 "higher values push the surface outwards");
30 b.add_input<decl::Float>("Scale"_ustr)
31 .default_value(0.01f)
32 .min(0.0f)
33 .max(1000.0f)
34 .description("Increase or decrease the amount of displacement");
35 b.add_input<decl::Vector>("Normal"_ustr).hide_value();
36 b.add_output<decl::Vector>("Displacement"_ustr);
37}
38
40{
41 node->custom1 = SHD_SPACE_OBJECT; /* space */
42}
43
45 bNode *node,
46 bNodeExecData * /*execdata*/,
49{
50 if (!in[3].link) {
51 GPU_link(mat, "world_normals_get", GPU_shading_data(), &in[3].link);
52 }
53
54 if (node->custom1 == SHD_SPACE_OBJECT) {
55 return GPU_stack_link(
56 mat, node, "node_displacement_object", in, out, GPU_kernel_globals(), GPU_shading_data());
57 }
58
59 return GPU_stack_link(mat, node, "node_displacement_world", in, out);
60}
61
63#ifdef WITH_MATERIALX
64{
65 if (to_type_ != NodeItem::Type::DisplacementShader) {
66 return empty();
67 }
68
69 /* NOTE: Normal input and Space feature don't have an implementation in MaterialX. */
70 NodeItem midlevel = get_input_value("Midlevel", NodeItem::Type::Float);
71 NodeItem height = get_input_value("Height", NodeItem::Type::Float) - midlevel;
72 NodeItem scale = get_input_value("Scale", NodeItem::Type::Float);
73
74 return create_node("displacement",
75 NodeItem::Type::DisplacementShader,
76 {{"displacement", height}, {"scale", scale}});
77}
78#endif
80
81} // namespace nodes::node_shader_displacement_cc
82
83/* node type definition */
85{
86 namespace file_ns = nodes::node_shader_displacement_cc;
87
88 static bke::bNodeType ntype;
89
90 sh_node_type_base(&ntype, "ShaderNodeDisplacement"_ustr, SH_NODE_DISPLACEMENT);
91 ntype.ui_name = "Displacement";
92 ntype.ui_description = "Displace the surface along the surface normal";
93 ntype.enum_name_legacy = "DISPLACEMENT";
95 ntype.declare = file_ns::node_declare;
96 ntype.initfunc = file_ns::node_shader_init_displacement;
97 ntype.gpu_fn = file_ns::gpu_shader_displacement;
98 ntype.materialx_fn = file_ns::node_shader_materialx;
99
101}
102
103} // namespace blender
#define NODE_CLASS_OP_VECTOR
Definition BKE_node.hh:481
#define SH_NODE_DISPLACEMENT
float3x3 scale(float3x3 mat, float2 scale)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static void node_declare(NodeDeclarationBuilder &b)
static int gpu_shader_displacement(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_shader_init_displacement(bNodeTree *, bNode *node)
BMesh Iterators.
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
void sh_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
void register_node_type_sh_displacement()
bool GPU_link(GPUMaterial *mat, const char *name,...)
GPUNodeLink * GPU_shading_data()
GPUNodeLink * GPU_kernel_globals()
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
Defines a node type.
Definition BKE_node.hh:265
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:375
std::string ui_description
Definition BKE_node.hh:271
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:373
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393