Blender V4.5
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 layout->prop(ptr, "samples", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
24 layout->prop(ptr, "inside", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
25 layout->prop(ptr, "only_local", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
26}
27
29 bNode *node,
30 bNodeExecData * /*execdata*/,
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, "ShaderNodeAmbientOcclusion", SH_NODE_AMBIENT_OCCLUSION);
85 ntype.ui_name = "Ambient Occlusion";
86 ntype.ui_description =
87 "Compute how much the hemisphere above the shading point is occluded, for example to add "
88 "weathering effects to corners.\nNote: For Cycles, this may slow down renders significantly";
89 ntype.enum_name_legacy = "AMBIENT_OCCLUSION";
91 ntype.declare = file_ns::node_declare;
92 ntype.draw_buttons = file_ns::node_shader_buts_ambient_occlusion;
93 ntype.initfunc = file_ns::node_shader_init_ambient_occlusion;
94 ntype.gpu_fn = file_ns::node_shader_gpu_ambient_occlusion;
95 ntype.materialx_fn = file_ns::node_shader_materialx;
96
98}
#define NODE_CLASS_INPUT
Definition BKE_node.hh:433
#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:2748
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:226
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:332
std::string ui_description
Definition BKE_node.hh:232
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:277
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:330
const char * enum_name_legacy
Definition BKE_node.hh:235
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:355
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:4227