Blender V5.0
node_shader_subsurface_scattering.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_string.h"
8
10#include "UI_resources.hh"
11
12#include "BKE_node_runtime.hh"
13
15
17{
18 b.add_input<decl::Color>("Color").default_value({0.8f, 0.8f, 0.8f, 1.0f});
19 b.add_input<decl::Float>("Scale").default_value(0.05f).min(0.0f).max(1000.0f).description(
20 "Scale factor of the subsurface scattering radius");
21 b.add_input<decl::Vector>("Radius")
22 .default_value({1.0f, 0.2f, 0.1f})
23 .min(0.0f)
24 .max(100.0f)
25 .description("Scattering radius per color channel (RGB), multiplied with Scale");
26 b.add_input<decl::Float>("IOR").default_value(1.4f).min(1.01f).max(3.8f).subtype(PROP_FACTOR);
27 b.add_input<decl::Float>("Roughness")
28 .default_value(1.0f)
29 .min(0.0f)
30 .max(1.0f)
32 b.add_input<decl::Float>("Anisotropy")
33 .default_value(0.0f)
34 .min(0.0f)
35 .max(1.0f)
37 b.add_input<decl::Vector>("Normal").hide_value();
38 b.add_input<decl::Float>("Weight").available(false);
39 b.add_output<decl::Shader>("BSSRDF");
40}
41
43{
44 layout->prop(ptr, "falloff", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
45}
46
48{
50 node->custom2 = true;
51}
52
54 bNode *node,
55 bNodeExecData * /*execdata*/,
58{
59 if (!in[6].link) {
60 GPU_link(mat, "world_normals_get", &in[6].link);
61 }
62
64
65 return GPU_stack_link(mat, node, "node_subsurface_scattering", in, out);
66}
67
69{
70 const int sss_method = node->custom1;
71
72 LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
73 if (STR_ELEM(sock->name, "IOR", "Anisotropy")) {
74 bke::node_set_socket_availability(*ntree, *sock, sss_method != SHD_SUBSURFACE_BURLEY);
75 }
76 if (STR_ELEM(sock->name, "Roughness")) {
78 }
79 }
80}
81
83#ifdef WITH_MATERIALX
84{
85 /* NOTE: IOR and Subsurface Method isn't supported for this node in MaterialX. */
86 if (to_type_ != NodeItem::Type::BSDF) {
87 return empty();
88 }
89
90 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
91 NodeItem scale = get_input_value("Scale", NodeItem::Type::Float);
92# if MATERIALX_MAJOR_VERSION <= 1 && MATERIALX_MINOR_VERSION <= 38
93 NodeItem radius = get_input_value("Radius", NodeItem::Type::Vector3);
94# else
95 NodeItem radius = get_input_value("Radius", NodeItem::Type::Color3);
96# endif
97 NodeItem anisotropy = get_input_value("Anisotropy", NodeItem::Type::Float);
98 NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
99
100 return create_node("subsurface_bsdf",
101 NodeItem::Type::BSDF,
102 {{"weight", val(1.0f)},
103 {"color", color},
104 {"radius", radius * scale},
105 {"anisotropy", anisotropy},
106 {"normal", normal}});
107}
108#endif
110
111} // namespace blender::nodes::node_shader_subsurface_scattering_cc
112
113/* node type definition */
115{
117
118 static blender::bke::bNodeType ntype;
119
120 sh_node_type_base(&ntype, "ShaderNodeSubsurfaceScattering", SH_NODE_SUBSURFACE_SCATTERING);
121 ntype.ui_name = "Subsurface Scattering";
122 ntype.ui_description =
123 "Subsurface multiple scattering shader to simulate light entering the surface and bouncing "
124 "internally.\nTypically used for materials such as skin, wax, marble or milk";
125 ntype.enum_name_legacy = "SUBSURFACE_SCATTERING";
127 ntype.declare = file_ns::node_declare;
129 ntype.draw_buttons = file_ns::node_shader_buts_subsurface;
131 ntype.initfunc = file_ns::node_shader_init_subsurface_scattering;
132 ntype.gpu_fn = file_ns::node_shader_gpu_subsurface_scattering;
133 ntype.updatefunc = file_ns::node_shader_update_subsurface_scattering;
134 ntype.materialx_fn = file_ns::node_shader_materialx;
135
137}
#define NODE_CLASS_SHADER
Definition BKE_node.hh:460
#define SH_NODE_SUBSURFACE_SCATTERING
#define LISTBASE_FOREACH(type, var, list)
#define STR_ELEM(...)
Definition BLI_string.h:661
@ SHD_SUBSURFACE_BURLEY
@ SHD_SUBSURFACE_RANDOM_WALK
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
@ GPU_MATFLAG_DIFFUSE
@ GPU_MATFLAG_SUBSURFACE
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
bool GPU_link(GPUMaterial *mat, const char *name,...)
@ PROP_FACTOR
Definition RNA_types.hh:251
@ UI_ITEM_R_SPLIT_EMPTY_NAME
#define in
#define out
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
MatBase< T, NumCol, NumRow > scale(const MatBase< T, NumCol, NumRow > &mat, const VectorT &scale)
static void node_shader_update_subsurface_scattering(bNodeTree *ntree, bNode *node)
static void node_shader_buts_subsurface(uiLayout *layout, bContext *, PointerRNA *ptr)
static int node_shader_gpu_subsurface_scattering(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void register_node_type_sh_subsurface_scattering()
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)
#define min(a, b)
Definition sort.cc:36
int16_t custom1
ListBase inputs
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
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
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:259
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