Blender V5.0
node_shader_volume_coefficients.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 "BLI_string.h"
6
7#include "node_shader_util.hh"
8
10#include "UI_resources.hh"
11
12#include "BKE_node_runtime.hh"
13
15
17{
18 b.use_custom_socket_order();
19
20 b.add_output<decl::Shader>("Volume").translation_context(BLT_I18NCONTEXT_ID_ID);
21
22 b.add_input<decl::Float>("Weight").available(false);
23#define SOCK_WEIGHT_ID 0
24
25 PanelDeclarationBuilder &abs = b.add_panel("Absorption").default_closed(false);
26 abs.add_input<decl::Vector>("Absorption Coefficients")
27 .default_value({1.0f, 1.0f, 1.0f})
28 .min(0.0f)
29 .max(1000.0f)
31 "Probability density per color channel that light is absorbed per unit distance "
32 "traveled in the medium");
33#define SOCK_ABSORPTION_COEFFICIENTS_ID 1
34 PanelDeclarationBuilder &sca = b.add_panel("Scatter").default_closed(false);
35 sca.add_layout([](uiLayout *layout, bContext * /*C*/, PointerRNA *ptr) {
36 layout->prop(ptr, "phase", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
37 });
38 sca.add_input<decl::Vector>("Scatter Coefficients")
39 .default_value({1.0f, 1.0f, 1.0f})
40 .min(0.0f)
41 .max(1000.0f)
43 "Probability density per color channel of an out-scattering event occurring per unit "
44 "distance");
45#define SOCK_SCATTER_COEFFICIENTS_ID 2
46 sca.add_input<decl::Float>("Anisotropy")
47 .default_value(0.0f)
48 .min(-1.0f)
49 .max(1.0f)
51 .description(
52 "Directionality of the scattering. Zero is isotropic, negative is backward, "
53 "positive is forward");
54#define SOCK_SCATTER_ANISOTROPY_ID 3
55 sca.add_input<decl::Float>("IOR")
56 .default_value(1.33f)
57 .min(1.0f)
58 .max(2.0f)
60 .description("Index Of Refraction of the scattering particles");
61#define SOCK_SCATTER_IOR_ID 4
62 sca.add_input<decl::Float>("Backscatter")
63 .default_value(0.1f)
64 .min(0.0f)
65 .max(0.5f)
67 .description("Fraction of light that is scattered backwards");
68#define SOCK_SCATTER_BACKSCATTER_ID 5
69 sca.add_input<decl::Float>("Alpha").default_value(0.5f).min(0.0f).max(500.0f);
70#define SOCK_SCATTER_ALPHA_ID 6
71 sca.add_input<decl::Float>("Diameter")
72 .default_value(20.0f)
73 .min(0.0f)
74 .max(50.0f)
75 .description("Diameter of the water droplets, in micrometers");
76#define SOCK_SCATTER_DIAMETER_ID 7
77 PanelDeclarationBuilder &emi = b.add_panel("Emission").default_closed(false);
78 emi.add_input<decl::Vector>("Emission Coefficients")
79 .default_value({0.0f, 0.0f, 0.0f})
80 .min(0.0f)
81 .max(1000.0f)
82 .description("Emitted radiance per color channel that is added to a ray per unit distance");
83#define SOCK_EMISSION_COEFFICIENTS_ID 8
84}
85
86static void node_shader_init_coefficients(bNodeTree * /*ntree*/, bNode *node)
87{
89}
90
92{
93 const int phase_function = node->custom1;
94
95 LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
96 if (STR_ELEM(sock->name, "IOR", "Backscatter")) {
98 *ntree, *sock, phase_function == SHD_PHASE_FOURNIER_FORAND);
99 }
100 else if (STR_ELEM(sock->name, "Anisotropy")) {
102 *ntree, *sock, ELEM(phase_function, SHD_PHASE_HENYEY_GREENSTEIN, SHD_PHASE_DRAINE));
103 }
104 else if (STR_ELEM(sock->name, "Alpha")) {
105 bke::node_set_socket_availability(*ntree, *sock, phase_function == SHD_PHASE_DRAINE);
106 }
107 else if (STR_ELEM(sock->name, "Diameter")) {
108 bke::node_set_socket_availability(*ntree, *sock, phase_function == SHD_PHASE_MIE);
109 }
110 }
111}
112
127
128#undef SOCK_WEIGHT_ID
129#undef SOCK_ABSORPTION_COEFFICIENTS_ID
130#undef SOCK_SCATTER_COEFFICIENTS_ID
131#undef SOCK_SCATTER_ANISOTROPY_ID
132#undef SOCK_SCATTER_IOR_ID
133#undef SOCK_SCATTER_BACKSCATTER_ID
134#undef SOCK_SCATTER_ALPHA_ID
135#undef SOCK_SCATTER_DIAMETER_ID
136#undef SOCK_EMISSION_COEFFICIENTS_ID
137
138} // namespace blender::nodes::node_shader_volume_coefficients_cc
139
140/* node type definition */
142{
144
145 static blender::bke::bNodeType ntype;
146
147 sh_node_type_base(&ntype, "ShaderNodeVolumeCoefficients", SH_NODE_VOLUME_COEFFICIENTS);
148 ntype.ui_name = "Volume Coefficients";
149 ntype.ui_description =
150 "Model all three physical processes in a volume, represented by their coefficients";
151 ntype.enum_name_legacy = "VOLUME_COEFFICIENTS";
153 ntype.declare = file_ns::node_declare;
156 ntype.initfunc = file_ns::node_shader_init_coefficients;
157 ntype.gpu_fn = file_ns::node_shader_gpu_volume_coefficients;
158 ntype.updatefunc = file_ns::node_shader_update_coefficients;
159
161}
#define NODE_CLASS_SHADER
Definition BKE_node.hh:460
#define SH_NODE_VOLUME_COEFFICIENTS
#define LISTBASE_FOREACH(type, var, list)
#define STR_ELEM(...)
Definition BLI_string.h:661
#define ELEM(...)
#define BLT_I18NCONTEXT_ID_ID
@ SHD_PHASE_DRAINE
@ SHD_PHASE_HENYEY_GREENSTEIN
@ SHD_PHASE_MIE
@ SHD_PHASE_FOURNIER_FORAND
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
@ GPU_MATFLAG_VOLUME_SCATTER
@ GPU_MATFLAG_VOLUME_ABSORPTION
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
@ PROP_FACTOR
Definition RNA_types.hh:251
@ UI_ITEM_R_SPLIT_EMPTY_NAME
void add_layout(std::function< void(uiLayout *, bContext *, PointerRNA *)> draw)
DeclType::Builder & add_input(StringRef name, StringRef identifier="")
#define in
#define out
#define abs
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
void node_set_socket_availability(bNodeTree &ntree, bNodeSocket &sock, bool is_available)
Definition node.cc:4739
void node_type_size_preset(bNodeType &ntype, eNodeSizePreset size)
Definition node.cc:5396
static int node_shader_gpu_volume_coefficients(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_shader_update_coefficients(bNodeTree *ntree, bNode *node)
void sh_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
bool object_shader_nodes_poll(const bContext *C)
bool node_socket_not_black(const GPUNodeStack &socket)
#define SOCK_ABSORPTION_COEFFICIENTS_ID
void register_node_type_sh_volume_coefficients()
#define SOCK_SCATTER_COEFFICIENTS_ID
#define min(a, b)
Definition sort.cc:36
int16_t custom1
ListBase inputs
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
bool(* add_ui_poll)(const bContext *C)
Definition BKE_node.hh:310
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
NodeDeclareFunction declare
Definition BKE_node.hh:362
void(* updatefunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:281
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