Blender V5.3
node_shader_light_evaluation.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "node_shader_util.hh"
10
12#include "UI_resources.hh"
13
14namespace blender {
15
17
19{
20 const bNodeTree *ntree = b.tree_or_null();
21 const bool is_gpu_internal = ntree && (ntree->flag & NTREE_IS_GPU_SHADER_INTERNAL);
22
23 b.add_input<decl::Int>("LightIndex"_ustr).available(is_gpu_internal);
24 b.add_input<decl::Vector>("Position"_ustr)
25 .hide_value()
26 .description("Evaluation position. Surface position by default");
27 b.add_input<decl::Vector>("Normal"_ustr)
28 .hide_value()
29 .description("Evaluation normal. Surface normal by default");
30 b.add_input<decl::Float>("Roughness"_ustr)
31 .default_value(0.5f)
32 .min(0.0f)
33 .max(1.0f)
35 .description("Evaluation roughness. Used for reflection factor")
36 .make_available([](bNode &node) { node.custom1 = SHD_LIGHT_EVAL_GLOSSY; });
37
38 b.add_output<decl::Float>("Factor"_ustr).description("Shading reflection factor, scaled by PI");
39 b.add_output<decl::Float>("Mask"_ustr)
40 .description(
41 "All local lights: Mask to smooth the light cutoff.\n"
42 "Spot lights: Cutoff mask and spot attenuation.\n"
43 "Sun lights: 1.0");
44 b.add_output<decl::Vector>("Direction"_ustr)
45 .description(
46 "Local lights: Normalized direction from evaluation position to light position.\n"
47 "Sun lights: Sun direction * -1.0");
48 b.add_output<decl::Float>("Distance"_ustr)
49 .description(
50 "Local lights: Distance from evaluation position to light position.\n"
51 "Sun lights: 1.0");
52}
53
55 bContext * /*C*/,
56 PointerRNA *ptr)
57{
58 layout.prop(ptr, "mode", ui::ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
59}
60
62{
63 const int mode = node->custom1;
64
66 *bke::node_find_socket(*node, SOCK_IN, "Roughness"_ustr),
67 mode == SHD_LIGHT_EVAL_GLOSSY);
68}
69
71 bNode *node,
72 bNodeExecData * /*execdata*/,
75{
76 const int mode = node->custom1;
77
78 if (!in[0].link) {
79 /* Error: not linked to a light accumulation zone. */
81 return false;
82 }
83
84 if (!in[1].link) {
85 GPU_link(mat, "world_position_get", GPU_shading_data(), &in[1].link);
86 }
87 if (!in[2].link) {
88 GPU_link(mat, "world_normals_get", GPU_shading_data(), &in[2].link);
89 }
90
91 if (out[0].hasoutput) {
92 if (mode == SHD_LIGHT_EVAL_GLOSSY) {
94 node,
95 "node_light_evaluation_glossy",
96 in,
97 out,
100 }
101 else {
102 GPU_stack_link(mat,
103 node,
104 "node_light_evaluation_diffuse",
105 in,
106 out,
109 }
110 }
111 else {
112 /* Simple path that doesn't compute LTC. */
113 GPU_link(mat,
114 "node_light_evaluation_common",
115 in[0].link,
116 in[1].link,
118 &out[1].link,
119 &out[2].link,
120 &out[3].link);
121 }
122
123 return true;
124}
125
126} // namespace nodes::node_shader_light_evaluation_cc
127
128/* node type definition */
130{
131 namespace file_ns = nodes::node_shader_light_evaluation_cc;
132
133 static bke::bNodeType ntype;
134
135 sh_node_type_base(&ntype, "ShaderNodeLightEvaluation"_ustr, SH_NODE_LIGHT_EVALUATION);
136 ntype.ui_name = "Light Evaluation";
137 ntype.ui_description = "Light Evaluation";
138 ntype.enum_name_legacy = "LIGHT_EVALUATION";
139 ntype.nclass = NODE_CLASS_INPUT;
140 ntype.declare = file_ns::node_declare;
141 ntype.draw_buttons = file_ns::node_shader_buts_light_evaluation;
143 ntype.gpu_fn = file_ns::node_shader_gpu_light_evaluation;
144 ntype.updatefunc = file_ns::node_shader_update_light_evaluation;
145 // ntype.materialx_fn = file_ns::node_shader_materialx;
146
148}
149
150} // namespace blender
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define SH_NODE_LIGHT_EVALUATION
#define BLI_assert_unreachable()
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void node_set_socket_availability(bNodeTree &ntree, bNodeSocket &sock, bool is_available)
Definition node.cc:5499
bNodeSocket * node_find_socket(bNode &node, eNodeSocketInOut in_out, UString identifier)
Definition node.cc:3036
static void node_shader_buts_light_evaluation(ui::Layout &layout, bContext *, PointerRNA *ptr)
static void node_shader_update_light_evaluation(bNodeTree *ntree, bNode *node)
static int node_shader_gpu_light_evaluation(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)
bool GPU_link(GPUMaterial *mat, const char *name,...)
GPUNodeLink * GPU_shading_data()
@ NTREE_IS_GPU_SHADER_INTERNAL
GPUNodeLink * GPU_kernel_globals()
void search_link_ops_for_shader_material_lighting_node(nodes::GatherLinkSearchOpParams &params)
@ PROP_FACTOR
Definition RNA_types.hh:308
@ SHD_LIGHT_EVAL_GLOSSY
void register_node_type_sh_light_evaluation()
eNodeTree_Flag flag
Defines a node type.
Definition BKE_node.hh:265
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:290
std::string ui_description
Definition BKE_node.hh:271
void(*) updatefunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:312
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:373
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:409
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)