Blender V4.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
5#include "node_shader_util.hh"
6
8
10{
11 b.add_input<decl::Float>("Height").default_value(0.0f).min(0.0f).max(1000.0f).description(
12 "Distance to displace the surface along the normal");
13 b.add_input<decl::Float>("Midlevel")
14 .default_value(0.5f)
15 .min(0.0f)
16 .max(1000.0f)
18 "Neutral displacement value that causes no displacement.\n"
19 "Lower values cause the surface to move inwards, "
20 "higher values push the surface outwards");
21 b.add_input<decl::Float>("Scale").default_value(1.0f).min(0.0f).max(1000.0f).description(
22 "Increase or decrease the amount of displacement");
23 b.add_input<decl::Vector>("Normal").hide_value();
24 b.add_output<decl::Vector>("Displacement");
25}
26
27static void node_shader_init_displacement(bNodeTree * /*ntree*/, bNode *node)
28{
29 node->custom1 = SHD_SPACE_OBJECT; /* space */
30}
31
33 bNode *node,
34 bNodeExecData * /*execdata*/,
35 GPUNodeStack *in,
36 GPUNodeStack *out)
37{
38 if (!in[3].link) {
39 GPU_link(mat, "world_normals_get", &in[3].link);
40 }
41
42 if (node->custom1 == SHD_SPACE_OBJECT) {
43 return GPU_stack_link(mat, node, "node_displacement_object", in, out);
44 }
45
46 return GPU_stack_link(mat, node, "node_displacement_world", in, out);
47}
48
50#ifdef WITH_MATERIALX
51{
52 /* NOTE: Normal input and Space feature don't have an implementation in MaterialX. */
53 NodeItem midlevel = get_input_value("Midlevel", NodeItem::Type::Float);
54 NodeItem height = get_input_value("Height", NodeItem::Type::Float) - midlevel;
55 NodeItem scale = get_input_value("Scale", NodeItem::Type::Float);
56
57 return create_node("displacement",
58 NodeItem::Type::DisplacementShader,
59 {{"displacement", height}, {"scale", scale}});
60}
61#endif
63
64} // namespace blender::nodes::node_shader_displacement_cc
65
66/* node type definition */
68{
70
71 static blender::bke::bNodeType ntype;
72
74 ntype.declare = file_ns::node_declare;
75 ntype.initfunc = file_ns::node_shader_init_displacement;
76 ntype.gpu_fn = file_ns::gpu_shader_displacement;
77 ntype.materialx_fn = file_ns::node_shader_materialx;
78
80}
#define NODE_CLASS_OP_VECTOR
Definition BKE_node.hh:407
#define SH_NODE_DISPLACEMENT
Definition BKE_node.hh:980
@ SHD_SPACE_OBJECT
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
bool GPU_link(GPUMaterial *mat, const char *name,...)
local_group_size(16, 16) .push_constant(Type b
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
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)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void register_node_type_sh_displacement()
void sh_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
Defines a node type.
Definition BKE_node.hh:218
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:320
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:318
NodeDeclareFunction declare
Definition BKE_node.hh:347