Blender V5.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
8
9#include "node_shader_util.hh"
10
11#include "BLI_math_base_c.hh"
12
14#include "UI_resources.hh"
15
16namespace blender {
17
19
21{
22 b.add_input<decl::Color>("Color"_ustr).default_value({1.0f, 1.0f, 1.0f, 1.0f});
23 b.add_input<decl::Float>("Distance"_ustr).default_value(1.0f).min(0.0f).max(1000.0f);
24 b.add_input<decl::Vector>("Normal"_ustr).min(-1.0f).max(1.0f).hide_value();
25 b.add_output<decl::Color>("Color"_ustr);
26 b.add_output<decl::Float>("AO"_ustr);
27}
28
30 bContext * /*C*/,
31 PointerRNA *ptr)
32{
33 layout.prop(ptr, "samples", ui::ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
34 layout.prop(ptr, "inside", ui::ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
35 layout.prop(ptr, "only_local", ui::ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
36}
37
39 bNode *node,
40 bNodeExecData * /*execdata*/,
43{
44 if (!in[2].link) {
45 GPU_link(mat, "world_normals_get", GPU_shading_data(), &in[2].link);
46 }
47
49
50 float inverted = (node->custom2 & SHD_AO_INSIDE) ? 1.0f : 0.0f;
51 float f_samples = divide_ceil_u(node->custom1, 4);
52
53 return GPU_stack_link(mat,
54 node,
55 "node_ambient_occlusion",
56 in,
57 out,
59 GPU_constant(&f_samples),
62}
63
65{
66 node->custom1 = 16; /* samples */
67 node->custom2 = 0;
68}
69
71#ifdef WITH_MATERIALX
72{
73 /* TODO: observed crash while rendering MaterialX_v1_38_6::ExceptionShaderGenError */
82 return get_output_default(socket_out_->identifier, NodeItem::Type::Any);
83}
84#endif
86
87} // namespace nodes::node_shader_ambient_occlusion_cc
88
89/* node type definition */
91{
93
94 static bke::bNodeType ntype;
95
96 sh_node_type_base(&ntype, "ShaderNodeAmbientOcclusion"_ustr, SH_NODE_AMBIENT_OCCLUSION);
97 ntype.ui_name = "Ambient Occlusion";
98 ntype.ui_description =
99 "Compute how much the hemisphere above the shading point is occluded, for example to add "
100 "weathering effects to corners.\nNote: For Cycles, this may slow down renders significantly";
101 ntype.enum_name_legacy = "AMBIENT_OCCLUSION";
102 ntype.nclass = NODE_CLASS_INPUT;
103 ntype.declare = file_ns::node_declare;
104 ntype.draw_buttons = file_ns::node_shader_buts_ambient_occlusion;
105 ntype.initfunc = file_ns::node_shader_init_ambient_occlusion;
106 ntype.gpu_fn = file_ns::node_shader_gpu_ambient_occlusion;
107 ntype.materialx_fn = file_ns::node_shader_materialx;
108
110}
111
112} // namespace blender
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define SH_NODE_AMBIENT_OCCLUSION
ccl_device_inline float3x3 inverted(const float3x3 m)
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static void node_shader_buts_ambient_occlusion(ui::Layout &layout, bContext *, PointerRNA *ptr)
static void node_shader_init_ambient_occlusion(bNodeTree *, bNode *node)
static int node_shader_gpu_ambient_occlusion(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
BMesh Iterators.
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
void sh_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
GPUNodeLink * GPU_constant(const float *num)
bool GPU_link(GPUMaterial *mat, const char *name,...)
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
GPUNodeLink * GPU_shading_data()
MINLINE uint divide_ceil_u(uint a, uint b)
GPUNodeLink * GPU_kernel_globals()
void register_node_type_sh_ambient_occlusion()
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
#define min(a, b)
Definition sort.cc:38
Defines a node type.
Definition BKE_node.hh:265
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:375
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:290
std::string ui_description
Definition BKE_node.hh:271
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:373
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)