Blender  V3.3
node_shader_subsurface_scattering.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2005 Blender Foundation. All rights reserved. */
3 
4 #include "node_shader_util.hh"
5 
6 #include "UI_interface.h"
7 #include "UI_resources.h"
8 
10 
12 {
13  b.add_input<decl::Color>(N_("Color")).default_value({0.8f, 0.8f, 0.8f, 1.0f});
14  b.add_input<decl::Float>(N_("Scale")).default_value(1.0f).min(0.0f).max(1000.0f);
15  b.add_input<decl::Vector>(N_("Radius"))
16  .default_value({1.0f, 0.2f, 0.1f})
17  .min(0.0f)
18  .max(100.0f)
19  .compact();
20  b.add_input<decl::Float>(N_("IOR")).default_value(1.4f).min(1.01f).max(3.8f).subtype(
21  PROP_FACTOR);
22  b.add_input<decl::Float>(N_("Anisotropy"))
23  .default_value(0.0f)
24  .min(0.0f)
25  .max(1.0f)
26  .subtype(PROP_FACTOR);
27  b.add_input<decl::Vector>(N_("Normal")).hide_value();
28  b.add_input<decl::Float>(N_("Weight")).unavailable();
29  b.add_output<decl::Shader>(N_("BSSRDF"));
30 }
31 
33 {
34  uiItemR(layout, ptr, "falloff", UI_ITEM_R_SPLIT_EMPTY_NAME, "", ICON_NONE);
35 }
36 
38 {
40  node->custom2 = true;
41 }
42 
44  bNode *node,
45  bNodeExecData *UNUSED(execdata),
46  GPUNodeStack *in,
48 {
49  if (!in[5].link) {
50  GPU_link(mat, "world_normals_get", &in[5].link);
51  }
52 
53  bNodeSocket *socket = (bNodeSocket *)BLI_findlink(&node->original->inputs, 2);
55  /* For some reason it seems that the socket value is in ARGB format. */
56  bool use_subsurf = GPU_material_sss_profile_create(mat, &socket_data->value[1]);
57 
58  float use_sss = (use_subsurf) ? 1.0f : 0.0f;
59 
61 
62  return GPU_stack_link(mat, node, "node_subsurface_scattering", in, out, GPU_uniform(&use_sss));
63 }
64 
66 {
67  const int sss_method = node->custom1;
68 
69  LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
70  if (STR_ELEM(sock->name, "IOR", "Anisotropy")) {
72  }
73  }
74 }
75 
76 } // namespace blender::nodes::node_shader_subsurface_scattering_cc
77 
78 /* node type definition */
80 {
82 
83  static bNodeType ntype;
84 
86  &ntype, SH_NODE_SUBSURFACE_SCATTERING, "Subsurface Scattering", NODE_CLASS_SHADER);
93 
94  nodeRegisterType(&ntype);
95 }
void node_type_gpu(struct bNodeType *ntype, NodeGPUExecFunction gpu_fn)
Definition: node.cc:4465
void node_type_update(struct bNodeType *ntype, void(*updatefunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4443
#define SH_NODE_SUBSURFACE_SCATTERING
Definition: BKE_node.h:1148
void nodeSetSocketAvailability(struct bNodeTree *ntree, struct bNodeSocket *sock, bool is_available)
Definition: node.cc:3664
void node_type_init(struct bNodeType *ntype, void(*initfunc)(struct bNodeTree *ntree, struct bNode *node))
Definition: node.cc:4390
void node_type_size_preset(struct bNodeType *ntype, eNodeSizePreset size)
Definition: node.cc:4408
#define NODE_CLASS_SHADER
Definition: BKE_node.h:358
void nodeRegisterType(struct bNodeType *ntype)
Definition: node.cc:1357
@ NODE_SIZE_MIDDLE
Definition: BKE_node.h:366
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:336
void * BLI_findlink(const struct ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
#define STR_ELEM(...)
Definition: BLI_string.h:539
#define UNUSED(x)
@ SHD_SUBSURFACE_BURLEY
@ SHD_SUBSURFACE_RANDOM_WALK
bool GPU_material_sss_profile_create(GPUMaterial *material, float radii[3])
Definition: gpu_material.c:438
@ GPU_MATFLAG_DIFFUSE
Definition: GPU_material.h:71
@ GPU_MATFLAG_SUBSURFACE
Definition: GPU_material.h:72
void GPU_material_flag_set(GPUMaterial *mat, eGPUMaterialFlag flag)
Definition: gpu_material.c:596
GPUNodeLink * GPU_uniform(const float *num)
bool GPU_link(GPUMaterial *mat, const char *name,...)
bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
@ PROP_FACTOR
Definition: RNA_types.h:144
@ UI_ITEM_R_SPLIT_EMPTY_NAME
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
OperationNode * node
bNodeTree * ntree
static int node_shader_gpu_subsurface_scattering(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
static void node_shader_update_subsurface_scattering(bNodeTree *ntree, bNode *node)
static void node_shader_buts_subsurface(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
static void node_shader_init_subsurface_scattering(bNodeTree *UNUSED(ntree), bNode *node)
static const pxr::TfToken out("out", pxr::TfToken::Immortal)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void register_node_type_sh_subsurface_scattering()
void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass)
#define min(a, b)
Definition: sort.c:35
void * default_value
Defines a node type.
Definition: BKE_node.h:226
void(* draw_buttons)(struct uiLayout *, struct bContext *C, struct PointerRNA *ptr)
Definition: BKE_node.h:244
NodeDeclareFunction declare
Definition: BKE_node.h:324
#define N_(msgid)
PointerRNA * ptr
Definition: wm_files.c:3480