Blender V4.3
node_shader_ambient_occlusion.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
7#include "UI_interface.hh"
8#include "UI_resources.hh"
9
11
13{
14 b.add_input<decl::Color>("Color").default_value({1.0f, 1.0f, 1.0f, 1.0f});
15 b.add_input<decl::Float>("Distance").default_value(1.0f).min(0.0f).max(1000.0f);
16 b.add_input<decl::Vector>("Normal").min(-1.0f).max(1.0f).hide_value();
17 b.add_output<decl::Color>("Color");
18 b.add_output<decl::Float>("AO");
19}
20
22{
23 uiItemR(layout, ptr, "samples", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
24 uiItemR(layout, ptr, "inside", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
25 uiItemR(layout, ptr, "only_local", UI_ITEM_R_SPLIT_EMPTY_NAME, nullptr, ICON_NONE);
26}
27
29 bNode *node,
30 bNodeExecData * /*execdata*/,
31 GPUNodeStack *in,
32 GPUNodeStack *out)
33{
34 if (!in[2].link) {
35 GPU_link(mat, "world_normals_get", &in[2].link);
36 }
37
39
40 float inverted = (node->custom2 & SHD_AO_INSIDE) ? 1.0f : 0.0f;
41 float f_samples = divide_ceil_u(node->custom1, 4);
42
43 return GPU_stack_link(mat,
44 node,
45 "node_ambient_occlusion",
46 in,
47 out,
48 GPU_constant(&inverted),
49 GPU_constant(&f_samples));
50}
51
52static void node_shader_init_ambient_occlusion(bNodeTree * /*ntree*/, bNode *node)
53{
54 node->custom1 = 16; /* samples */
55 node->custom2 = 0;
56}
57
59#ifdef WITH_MATERIALX
60{
61 /* TODO: observed crash while rendering MaterialX_v1_38_6::ExceptionShaderGenError */
70 return get_output_default(socket_out_->name, NodeItem::Type::Any);
71}
72#endif
74
75} // namespace blender::nodes::node_shader_ambient_occlusion_cc
76
77/* node type definition */
79{
81
82 static blender::bke::bNodeType ntype;
83
84 sh_node_type_base(&ntype, SH_NODE_AMBIENT_OCCLUSION, "Ambient Occlusion", NODE_CLASS_INPUT);
85 ntype.declare = file_ns::node_declare;
86 ntype.draw_buttons = file_ns::node_shader_buts_ambient_occlusion;
87 ntype.initfunc = file_ns::node_shader_init_ambient_occlusion;
88 ntype.gpu_fn = file_ns::node_shader_gpu_ambient_occlusion;
89 ntype.materialx_fn = file_ns::node_shader_materialx;
90
92}
#define NODE_CLASS_INPUT
Definition BKE_node.hh:404
MINLINE uint divide_ceil_u(uint a, uint b)
@ SHD_AO_INSIDE
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_constant(const float *num)
@ GPU_MATFLAG_AO
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
bool GPU_link(GPUMaterial *mat, const char *name,...)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
local_group_size(16, 16) .push_constant(Type b
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static void node_shader_init_ambient_occlusion(bNodeTree *, bNode *node)
static void node_shader_buts_ambient_occlusion(uiLayout *layout, bContext *, PointerRNA *ptr)
static int node_shader_gpu_ambient_occlusion(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void register_node_type_sh_ambient_occlusion()
void sh_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
#define min(a, b)
Definition sort.c:32
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
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
PointerRNA * ptr
Definition wm_files.cc:4126