Blender  V3.3
node_shader_ambient_occlusion.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 
6 #include "UI_interface.h"
7 #include "UI_resources.h"
8 
10 
12 {
13  b.add_input<decl::Color>(N_("Color")).default_value({1.0f, 1.0f, 1.0f, 1.0f});
14  b.add_input<decl::Float>(N_("Distance")).default_value(1.0f).min(0.0f).max(1000.0f);
15  b.add_input<decl::Vector>(N_("Normal")).min(-1.0f).max(1.0f).hide_value();
16  b.add_output<decl::Color>(N_("Color"));
17  b.add_output<decl::Float>(N_("AO"));
18 }
19 
21  bContext *UNUSED(C),
22  PointerRNA *ptr)
23 {
24  uiItemR(layout, ptr, "samples", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
25  uiItemR(layout, ptr, "inside", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
26  uiItemR(layout, ptr, "only_local", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
27 }
28 
30  bNode *node,
31  bNodeExecData *UNUSED(execdata),
32  GPUNodeStack *in,
34 {
35  if (!in[2].link) {
36  GPU_link(mat, "world_normals_get", &in[2].link);
37  }
38 
40 
41  float inverted = (node->custom2 & SHD_AO_INSIDE) ? 1.0f : 0.0f;
42  float f_samples = divide_ceil_u(node->custom1, 4);
43 
44  return GPU_stack_link(mat,
45  node,
46  "node_ambient_occlusion",
47  in,
48  out,
49  GPU_constant(&inverted),
50  GPU_constant(&f_samples));
51 }
52 
54 {
55  node->custom1 = 16; /* samples */
56  node->custom2 = 0;
57 }
58 
59 } // namespace blender::nodes::node_shader_ambient_occlusion_cc
60 
61 /* node type definition */
63 {
65 
66  static bNodeType ntype;
67 
68  sh_node_type_base(&ntype, SH_NODE_AMBIENT_OCCLUSION, "Ambient Occlusion", NODE_CLASS_INPUT);
73 
74  nodeRegisterType(&ntype);
75 }
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 SH_NODE_AMBIENT_OCCLUSION
Definition: BKE_node.h:1143
#define NODE_CLASS_INPUT
Definition: BKE_node.h:345
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
MINLINE uint divide_ceil_u(uint a, uint b)
#define UNUSED(x)
#define SHD_AO_INSIDE
GPUNodeLink * GPU_constant(const float *num)
@ GPU_MATFLAG_AO
Definition: GPU_material.h:79
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
Definition: gpu_material.c:596
bool GPU_link(GPUMaterial *mat, const char *name,...)
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
@ 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
bNodeTree * ntree
static void node_shader_buts_ambient_occlusion(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static void node_shader_init_ambient_occlusion(bNodeTree *UNUSED(ntree), bNode *node)
static int node_shader_gpu_ambient_occlusion(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_ambient_occlusion()
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