Blender V4.3
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
9#include "UI_interface.hh"
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);
20 b.add_input<decl::Vector>("Radius").default_value({1.0f, 0.2f, 0.1f}).min(0.0f).max(100.0f);
21 b.add_input<decl::Float>("IOR").default_value(1.4f).min(1.01f).max(3.8f).subtype(PROP_FACTOR);
22 b.add_input<decl::Float>("Roughness")
23 .default_value(1.0f)
24 .min(0.0f)
25 .max(1.0f)
27 b.add_input<decl::Float>("Anisotropy")
28 .default_value(0.0f)
29 .min(0.0f)
30 .max(1.0f)
32 b.add_input<decl::Vector>("Normal").hide_value();
33 b.add_input<decl::Float>("Weight").available(false);
34 b.add_output<decl::Shader>("BSSRDF");
35}
36
38{
39 uiItemR(layout, ptr, "falloff", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
40}
41
43{
45 node->custom2 = true;
46}
47
49 bNode *node,
50 bNodeExecData * /*execdata*/,
51 GPUNodeStack *in,
52 GPUNodeStack *out)
53{
54 if (!in[6].link) {
55 GPU_link(mat, "world_normals_get", &in[6].link);
56 }
57
58 bNodeSocket *socket = (bNodeSocket *)BLI_findlink(&node->runtime->original->inputs, 2);
60 /* For some reason it seems that the socket value is in ARGB format. */
61 bool use_subsurf = GPU_material_sss_profile_create(mat, &socket_data->value[1]);
62
63 float use_sss = (use_subsurf) ? 1.0f : 0.0f;
64
66
67 return GPU_stack_link(mat, node, "node_subsurface_scattering", in, out, GPU_constant(&use_sss));
68}
69
71{
72 const int sss_method = node->custom1;
73
74 LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
75 if (STR_ELEM(sock->name, "IOR", "Anisotropy")) {
77 }
78 if (STR_ELEM(sock->name, "Roughness")) {
80 }
81 }
82}
83
85#ifdef WITH_MATERIALX
86{
87 /* NOTE: IOR and Subsurface Method isn't supported for this node in MaterialX. */
88 if (to_type_ != NodeItem::Type::BSDF) {
89 return empty();
90 }
91
92 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
93 NodeItem scale = get_input_value("Scale", NodeItem::Type::Float);
94 NodeItem radius = get_input_value("Radius", NodeItem::Type::Vector3);
95 NodeItem anisotropy = get_input_value("Anisotropy", NodeItem::Type::Float);
96 NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
97
98 return create_node("subsurface_bsdf",
99 NodeItem::Type::BSDF,
100 {{"weight", val(1.0f)},
101 {"color", color},
102 {"radius", radius * scale},
103 {"anisotropy", anisotropy},
104 {"normal", normal}});
105}
106#endif
108
109} // namespace blender::nodes::node_shader_subsurface_scattering_cc
110
111/* node type definition */
113{
115
116 static blender::bke::bNodeType ntype;
117
119 &ntype, SH_NODE_SUBSURFACE_SCATTERING, "Subsurface Scattering", NODE_CLASS_SHADER);
120 ntype.declare = file_ns::node_declare;
122 ntype.draw_buttons = file_ns::node_shader_buts_subsurface;
124 ntype.initfunc = file_ns::node_shader_init_subsurface_scattering;
125 ntype.gpu_fn = file_ns::node_shader_gpu_subsurface_scattering;
126 ntype.updatefunc = file_ns::node_shader_update_subsurface_scattering;
127 ntype.materialx_fn = file_ns::node_shader_materialx;
128
130}
#define SH_NODE_SUBSURFACE_SCATTERING
Definition BKE_node.hh:960
#define NODE_CLASS_SHADER
Definition BKE_node.hh:417
#define LISTBASE_FOREACH(type, var, list)
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define STR_ELEM(...)
Definition BLI_string.h:653
@ SHD_SUBSURFACE_BURLEY
@ SHD_SUBSURFACE_RANDOM_WALK
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_constant(const float *num)
bool GPU_material_sss_profile_create(GPUMaterial *material, float radii[3])
@ GPU_MATFLAG_DIFFUSE
@ GPU_MATFLAG_SUBSURFACE
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
bool GPU_link(GPUMaterial *mat, const char *name,...)
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a color
@ PROP_FACTOR
Definition RNA_types.hh:154
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
@ UI_ITEM_R_SPLIT_EMPTY_NAME
local_group_size(16, 16) .push_constant(Type b
void node_type_size_preset(bNodeType *ntype, eNodeSizePreset size)
Definition node.cc:4614
void node_set_socket_availability(bNodeTree *ntree, bNodeSocket *sock, bool is_available)
Definition node.cc:3911
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
MatBase< T, NumCol, NumRow > scale(const MatBase< T, NumCol, NumRow > &mat, const VectorT &scale)
void normal(const bNode &, void *r_value)
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, int type, const char *name, short nclass)
bool object_shader_nodes_poll(const bContext *C)
#define min(a, b)
Definition sort.c:32
void * default_value
int16_t custom1
ListBase inputs
bNodeRuntimeHandle * runtime
int16_t custom2
Defines a node type.
Definition BKE_node.hh:218
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:320
bool(* add_ui_poll)(const bContext *C)
Definition BKE_node.hh:288
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:318
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeDeclareFunction declare
Definition BKE_node.hh:347
void(* updatefunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:257
PointerRNA * ptr
Definition wm_files.cc:4126