Blender  V3.3
node_shader_displacement.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2005 Blender Foundation. All rights reserved. */
3 
4 #include "node_shader_util.hh"
5 
7 
9 {
10  b.add_input<decl::Float>(N_("Height")).default_value(0.0f).min(0.0f).max(1000.0f);
11  b.add_input<decl::Float>(N_("Midlevel")).default_value(0.0f).min(0.0f).max(1000.0f);
12  b.add_input<decl::Float>(N_("Scale")).default_value(1.0f).min(0.0f).max(1000.0f);
13  b.add_input<decl::Vector>(N_("Normal")).hide_value();
14  b.add_output<decl::Vector>(N_("Displacement"));
15 }
16 
18 {
19  node->custom1 = SHD_SPACE_OBJECT; /* space */
20 
21  /* Set default value here for backwards compatibility. */
22  LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
23  if (STREQ(sock->name, "Midlevel")) {
24  ((bNodeSocketValueFloat *)sock->default_value)->value = 0.5f;
25  }
26  }
27 }
28 
30  bNode *node,
31  bNodeExecData *UNUSED(execdata),
32  GPUNodeStack *in,
34 {
35  if (!in[3].link) {
36  GPU_link(mat, "world_normals_get", &in[3].link);
37  }
38 
39  if (node->custom1 == SHD_SPACE_OBJECT) {
40  return GPU_stack_link(mat, node, "node_displacement_object", in, out);
41  }
42 
43  return GPU_stack_link(mat, node, "node_displacement_world", in, out);
44 }
45 
46 } // namespace blender::nodes::node_shader_displacement_cc
47 
48 /* node type definition */
50 {
52 
53  static bNodeType ntype;
54 
59 
60  nodeRegisterType(&ntype);
61 }
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn)
Definition: node.cc:4465
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4390
#define NODE_CLASS_OP_VECTOR
Definition: BKE_node.h:348
#define SH_NODE_DISPLACEMENT
Definition: BKE_node.h:1168
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
#define UNUSED(x)
#define STREQ(a, b)
#define SHD_SPACE_OBJECT
bool GPU_link(GPUMaterial *mat, const char *name,...)
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
OperationNode * node
bNodeTree * ntree
static void node_declare(NodeDeclarationBuilder &b)
static void node_shader_init_displacement(bNodeTree *UNUSED(ntree), bNode *node)
static int gpu_shader_displacement(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_sh_displacement()
void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass)
Defines a node type.
Definition: BKE_node.h:226
NodeDeclareFunction declare
Definition: BKE_node.h:324
#define N_(msgid)