Blender V5.3
node_shader_bsdf_sheen.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
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::Color>("Color"_ustr).default_value({0.8f, 0.8f, 0.8f, 1.0f});
24 b.add_input<decl::Float>("Roughness"_ustr)
25 .default_value(0.5f)
26 .min(0.0f)
27 .max(1.0f)
29 b.add_input<decl::Vector>("Normal"_ustr).hide_value();
30 b.add_input<decl::Float>("Weight"_ustr).available(is_gpu_internal);
31 b.add_output<decl::Shader>("BSDF"_ustr);
32}
33
34static void node_shader_buts_sheen(ui::Layout &layout, bContext * /*C*/, PointerRNA *ptr)
35{
36 layout.prop(ptr, "distribution", ui::ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
37}
38
39static void node_shader_init_sheen(bNodeTree * /*ntree*/, bNode *node)
40{
41 node->custom1 = SHD_SHEEN_MICROFIBER;
42}
43
45 bNode *node,
46 bNodeExecData * /*execdata*/,
49{
50 if (!in[2].link) {
51 GPU_link(mat, "world_normals_get", GPU_shading_data(), &in[2].link);
52 }
53
55
56 return GPU_stack_link(
57 mat, node, "node_bsdf_sheen", in, out, GPU_kernel_globals(), GPU_shading_data());
58}
59
61#ifdef WITH_MATERIALX
62{
63 if (to_type_ != NodeItem::Type::BSDF) {
64 return empty();
65 }
66
67 NodeItem color = get_input_value("Color", NodeItem::Type::Color3);
68 NodeItem roughness = get_input_value("Roughness", NodeItem::Type::Float);
69 NodeItem normal = get_input_link("Normal", NodeItem::Type::Vector3);
70# if !(MATERIALX_MAJOR_VERSION <= 1 && MATERIALX_MINOR_VERSION <= 38)
71 NodeItem mode = node_->custom1 == SHD_SHEEN_MICROFIBER ? val(std::string("zeltner")) :
72 val(std::string("conty_kulla"));
73# endif
74
75 return create_node("sheen_bsdf",
76 NodeItem::Type::BSDF,
77 {{"color", color},
78 {"roughness", roughness},
79 {"normal", normal}
80# if !(MATERIALX_MAJOR_VERSION <= 1 && MATERIALX_MINOR_VERSION <= 38)
81 ,
82 {"mode", mode}});
83# else
84 });
85# endif
86}
87#endif
89
90} // namespace nodes::node_shader_bsdf_sheen_cc
91
92/* node type definition */
94{
95 namespace file_ns = nodes::node_shader_bsdf_sheen_cc;
96
97 static bke::bNodeType ntype;
98
99 sh_node_type_base(&ntype, "ShaderNodeBsdfSheen"_ustr, SH_NODE_BSDF_SHEEN);
100 ntype.ui_name = "Sheen BSDF";
101 ntype.ui_description =
102 "Reflection for materials such as cloth.\nTypically mixed with other shaders (such as a "
103 "Diffuse Shader) and is not particularly useful on its own";
104 ntype.enum_name_legacy = "BSDF_SHEEN";
107 ntype.declare = file_ns::node_declare;
109 ntype.initfunc = file_ns::node_shader_init_sheen;
110 ntype.gpu_fn = file_ns::node_shader_gpu_bsdf_sheen;
111 ntype.draw_buttons = file_ns::node_shader_buts_sheen;
112 ntype.materialx_fn = file_ns::node_shader_materialx;
113
115}
116
117} // namespace blender
#define NODE_CLASS_SHADER
Definition BKE_node.hh:491
#define SH_NODE_BSDF_SHEEN
#define SHD_SHEEN_MICROFIBER
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
static void node_declare(NodeDeclarationBuilder &b)
static int node_shader_gpu_bsdf_sheen(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_shader_buts_sheen(ui::Layout &layout, bContext *, PointerRNA *ptr)
static void node_shader_init_sheen(bNodeTree *, bNode *node)
BMesh Iterators.
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
bool object_cycles_shader_nodes_poll(const bContext *C)
@ GPU_MATFLAG_DIFFUSE
void sh_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
void register_node_type_sh_bsdf_sheen()
bool GPU_link(GPUMaterial *mat, const char *name,...)
void search_link_ops_for_shader_bsdf_node(nodes::GatherLinkSearchOpParams &params)
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
GPUNodeLink * GPU_shading_data()
@ NTREE_IS_GPU_SHADER_INTERNAL
GPUNodeLink * GPU_kernel_globals()
@ PROP_FACTOR
Definition RNA_types.hh:308
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
eNodeTree_Flag flag
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
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:409
NodeDeclareFunction declare
Definition BKE_node.hh:393
bool(*) add_ui_poll(const bContext *C)
Definition BKE_node.hh:341
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)