Blender  V3.3
node_shader_bump.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 
8 #include "node_shader_util.hh"
9 
10 #include "UI_interface.h"
11 #include "UI_resources.h"
12 
13 /* **************** BUMP ******************** */
14 
16 
18 {
19  b.add_input<decl::Float>(N_("Strength"))
20  .default_value(1.0f)
21  .min(0.0f)
22  .max(1.0f)
23  .subtype(PROP_FACTOR);
24  b.add_input<decl::Float>(N_("Distance")).default_value(1.0f).min(0.0f).max(1000.0f);
25  b.add_input<decl::Float>(N_("Height"))
26  .default_value(1.0f)
27  .min(-1000.0f)
28  .max(1000.0f)
29  .hide_value();
30  b.add_input<decl::Vector>(N_("Normal")).min(-1.0f).max(1.0f).hide_value();
31  b.add_output<decl::Vector>(N_("Normal"));
32 }
33 
35 {
36  uiItemR(layout, ptr, "invert", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, 0);
37 }
38 
39 static int gpu_shader_bump(GPUMaterial *mat,
40  bNode *node,
41  bNodeExecData *UNUSED(execdata),
42  GPUNodeStack *in,
44 {
45  /* If there is no Height input, the node becomes a no-op. */
46  if (!in[2].link) {
47  if (!in[3].link) {
48  return GPU_link(mat, "world_normals_get", &out[0].link);
49  }
50  else {
51  /* Actually running the bump code would normalize, but Cycles handles it as total no-op. */
52  return GPU_link(mat, "vector_copy", in[3].link, &out[0].link);
53  }
54  }
55 
56  if (!in[3].link) {
57  GPU_link(mat, "world_normals_get", &in[3].link);
58  }
59 
60  const char *height_function = GPU_material_split_sub_function(mat, GPU_FLOAT, &in[2].link);
61 
62  /* TODO (Miguel Pozo):
63  * Currently, this doesn't compute the actual differentials, just the height at dX and dY
64  * offsets. The actual differentials are computed inside the GLSL node_bump function by
65  * substracting the height input. This avoids redundant computations when the height input is
66  * also needed by regular nodes as part in the main function (See #103903 for context).
67  * A better option would be to add a "value" input socket (in this case the height) to the
68  * differentiate node, but currently this kind of intermediate nodes are pruned in the codegen
69  * process (see #104265), so we need to fix that first. */
70  GPUNodeLink *dheight = GPU_differentiate_float_function(height_function);
71 
72  float invert = (node->custom1) ? -1.0 : 1.0;
73 
74  return GPU_stack_link(mat, node, "node_bump", in, out, dheight, GPU_constant(&invert));
75 }
76 
77 } // namespace blender::nodes::node_shader_bump_cc
78 
79 /* node type definition */
81 {
82  namespace file_ns = blender::nodes::node_shader_bump_cc;
83 
84  static bNodeType ntype;
85 
90 
91  nodeRegisterType(&ntype);
92 }
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn)
Definition: node.cc:4465
#define SH_NODE_BUMP
Definition: BKE_node.h:1141
#define NODE_CLASS_OP_VECTOR
Definition: BKE_node.h:348
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
#define UNUSED(x)
GPUNodeLink * GPU_differentiate_float_function(const char *function_name)
char * GPU_material_split_sub_function(GPUMaterial *material, eGPUType return_type, GPUNodeLink **link)
Definition: gpu_material.c:541
GPUNodeLink * GPU_constant(const float *num)
@ GPU_FLOAT
Definition: GPU_material.h:49
bool GPU_link(GPUMaterial *mat, const char *name,...)
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
@ PROP_FACTOR
Definition: RNA_types.h:144
@ UI_ITEM_R_SPLIT_EMPTY_NAME
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
OperationNode * node
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
Definition: invert.h:8
static int gpu_shader_bump(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static void node_shader_buts_bump(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static void node_declare(NodeDeclarationBuilder &b)
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_sh_bump()
void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass)
#define min(a, b)
Definition: sort.c:35
Defines a node type.
Definition: BKE_node.h:226
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:244
NodeDeclareFunction declare
Definition: BKE_node.h:324
#define N_(msgid)
PointerRNA * ptr
Definition: wm_files.c:3480