Blender V5.0
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 "BLI_math_base.h"
8
10#include "UI_resources.hh"
11
13
15{
16 b.add_input<decl::Color>("Color").default_value({1.0f, 1.0f, 1.0f, 1.0f});
17 b.add_input<decl::Float>("Distance").default_value(1.0f).min(0.0f).max(1000.0f);
18 b.add_input<decl::Vector>("Normal").min(-1.0f).max(1.0f).hide_value();
19 b.add_output<decl::Color>("Color");
20 b.add_output<decl::Float>("AO");
21}
22
24{
25 layout->prop(ptr, "samples", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
26 layout->prop(ptr, "inside", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
27 layout->prop(ptr, "only_local", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
28}
29
31 bNode *node,
32 bNodeExecData * /*execdata*/,
35{
36 if (!in[2].link) {
37 GPU_link(mat, "world_normals_get", &in[2].link);
38 }
39
41
42 float inverted = (node->custom2 & SHD_AO_INSIDE) ? 1.0f : 0.0f;
43 float f_samples = divide_ceil_u(node->custom1, 4);
44
45 return GPU_stack_link(mat,
46 node,
47 "node_ambient_occlusion",
48 in,
49 out,
50 GPU_constant(&inverted),
51 GPU_constant(&f_samples));
52}
53
54static void node_shader_init_ambient_occlusion(bNodeTree * /*ntree*/, bNode *node)
55{
56 node->custom1 = 16; /* samples */
57 node->custom2 = 0;
58}
59
61#ifdef WITH_MATERIALX
62{
63 /* TODO: observed crash while rendering MaterialX_v1_38_6::ExceptionShaderGenError */
72 return get_output_default(socket_out_->identifier, NodeItem::Type::Any);
73}
74#endif
76
77} // namespace blender::nodes::node_shader_ambient_occlusion_cc
78
79/* node type definition */
81{
83
84 static blender::bke::bNodeType ntype;
85
86 sh_node_type_base(&ntype, "ShaderNodeAmbientOcclusion", SH_NODE_AMBIENT_OCCLUSION);
87 ntype.ui_name = "Ambient Occlusion";
88 ntype.ui_description =
89 "Compute how much the hemisphere above the shading point is occluded, for example to add "
90 "weathering effects to corners.\nNote: For Cycles, this may slow down renders significantly";
91 ntype.enum_name_legacy = "AMBIENT_OCCLUSION";
93 ntype.declare = file_ns::node_declare;
94 ntype.draw_buttons = file_ns::node_shader_buts_ambient_occlusion;
95 ntype.initfunc = file_ns::node_shader_init_ambient_occlusion;
96 ntype.gpu_fn = file_ns::node_shader_gpu_ambient_occlusion;
97 ntype.materialx_fn = file_ns::node_shader_materialx;
98
100}
#define NODE_CLASS_INPUT
Definition BKE_node.hh:447
#define SH_NODE_AMBIENT_OCCLUSION
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,...)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
#define in
#define out
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
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, std::string idname, const std::optional< int16_t > legacy_type)
#define min(a, b)
Definition sort.cc:36
int16_t custom1
int16_t custom2
Defines a node type.
Definition BKE_node.hh:238
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:344
std::string ui_description
Definition BKE_node.hh:244
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:289
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:342
const char * enum_name_legacy
Definition BKE_node.hh:247
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:259
NodeDeclareFunction declare
Definition BKE_node.hh:362
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
PointerRNA * ptr
Definition wm_files.cc:4238