Differential D13498 Diff 45751 source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.c
Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.c
- This file was moved from source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.cc.
| Show All 11 Lines | |||||
| * You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | ||||
| * along with this program; if not, write to the Free Software Foundation, | * along with this program; if not, write to the Free Software Foundation, | ||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
| * | * | ||||
| * The Original Code is Copyright (C) 2005 Blender Foundation. | * The Original Code is Copyright (C) 2005 Blender Foundation. | ||||
| * All rights reserved. | * All rights reserved. | ||||
| */ | */ | ||||
| #include "node_shader_util.hh" | #include "../node_shader_util.h" | ||||
| /* **************** OUTPUT ******************** */ | /* **************** OUTPUT ******************** */ | ||||
| namespace blender::nodes::node_shader_subsurface_scattering_cc { | static bNodeSocketTemplate sh_node_subsurface_scattering_in[] = { | ||||
| {SOCK_RGBA, N_("Color"), 0.8f, 0.8f, 0.8f, 1.0f, 0.0f, 1.0f}, | |||||
| static void node_declare(NodeDeclarationBuilder &b) | {SOCK_FLOAT, N_("Scale"), 1.0, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, | ||||
| { | {SOCK_VECTOR, N_("Radius"), 1.0f, 0.2f, 0.1f, 0.0f, 0.0f, 100.0f, PROP_NONE, SOCK_COMPACT}, | ||||
| b.add_input<decl::Color>(N_("Color")).default_value({0.8f, 0.8f, 0.8f, 1.0f}); | {SOCK_FLOAT, N_("IOR"), 1.4f, 0.0f, 0.0f, 0.0f, 1.01f, 3.8f, PROP_FACTOR}, | ||||
| b.add_input<decl::Float>(N_("Scale")).default_value(1.0f).min(0.0f).max(1000.0f); | {SOCK_FLOAT, N_("Anisotropy"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR}, | ||||
| b.add_input<decl::Vector>(N_("Radius")) | {SOCK_VECTOR, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, | ||||
| .default_value({1.0f, 0.2f, 0.1f}) | {-1, ""}, | ||||
| .min(0.0f) | }; | ||||
| .max(100.0f) | |||||
| .compact(); | static bNodeSocketTemplate sh_node_subsurface_scattering_out[] = { | ||||
| b.add_input<decl::Float>(N_("IOR")).default_value(1.4f).min(0.0f).max(3.8f).subtype(PROP_FACTOR); | {SOCK_SHADER, N_("BSSRDF")}, | ||||
| b.add_input<decl::Float>(N_("Anisotropy")).min(0.0f).max(1.0f).subtype(PROP_FACTOR); | {-1, ""}, | ||||
| b.add_input<decl::Vector>(N_("Normal")).min(-1.0f).max(1.0f).hide_value(); | }; | ||||
| b.add_output<decl::Shader>(N_("BSSRDF")); | |||||
| } | |||||
| static void node_shader_init_subsurface_scattering(bNodeTree *UNUSED(ntree), bNode *node) | static void node_shader_init_subsurface_scattering(bNodeTree *UNUSED(ntree), bNode *node) | ||||
| { | { | ||||
| node->custom1 = SHD_SUBSURFACE_RANDOM_WALK; | node->custom1 = SHD_SUBSURFACE_RANDOM_WALK; | ||||
| node->custom2 = true; | node->custom2 = true; | ||||
| } | } | ||||
| static int node_shader_gpu_subsurface_scattering(GPUMaterial *mat, | static int node_shader_gpu_subsurface_scattering(GPUMaterial *mat, | ||||
| bNode *node, | bNode *node, | ||||
| bNodeExecData *UNUSED(execdata), | bNodeExecData *UNUSED(execdata), | ||||
| GPUNodeStack *in, | GPUNodeStack *in, | ||||
| GPUNodeStack *out) | GPUNodeStack *out) | ||||
| { | { | ||||
| if (!in[5].link) { | if (!in[5].link) { | ||||
| GPU_link(mat, "world_normals_get", &in[5].link); | GPU_link(mat, "world_normals_get", &in[5].link); | ||||
| } | } | ||||
| if (node->sss_id > 0) { | if (node->sss_id > 0) { | ||||
| bNodeSocket *socket = (bNodeSocket *)BLI_findlink(&node->original->inputs, 2); | bNodeSocket *socket = BLI_findlink(&node->original->inputs, 2); | ||||
| bNodeSocketValueRGBA *socket_data = (bNodeSocketValueRGBA *)socket->default_value; | bNodeSocketValueRGBA *socket_data = socket->default_value; | ||||
| /* For some reason it seems that the socket value is in ARGB format. */ | /* For some reason it seems that the socket value is in ARGB format. */ | ||||
| GPU_material_sss_profile_create(mat, &socket_data->value[1]); | GPU_material_sss_profile_create(mat, &socket_data->value[1]); | ||||
| /* sss_id is 0 only the node is not connected to any output. | /* sss_id is 0 only the node is not connected to any output. | ||||
| * In this case flagging the material would trigger a bug (see T68736). */ | * In this case flagging the material would trigger a bug (see T68736). */ | ||||
| GPU_material_flag_set(mat, (eGPUMatFlag)(GPU_MATFLAG_DIFFUSE | GPU_MATFLAG_SSS)); | GPU_material_flag_set(mat, GPU_MATFLAG_DIFFUSE | GPU_MATFLAG_SSS); | ||||
| } | } | ||||
| return GPU_stack_link( | return GPU_stack_link( | ||||
| mat, node, "node_subsurface_scattering", in, out, GPU_constant(&node->sss_id)); | mat, node, "node_subsurface_scattering", in, out, GPU_constant(&node->sss_id)); | ||||
| } | } | ||||
| static void node_shader_update_subsurface_scattering(bNodeTree *ntree, bNode *node) | static void node_shader_update_subsurface_scattering(bNodeTree *ntree, bNode *node) | ||||
| { | { | ||||
| const int sss_method = node->custom1; | const int sss_method = node->custom1; | ||||
| LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { | for (bNodeSocket *sock = node->inputs.first; sock; sock = sock->next) { | ||||
| if (STR_ELEM(sock->name, "IOR", "Anisotropy")) { | if (STR_ELEM(sock->name, "IOR", "Anisotropy")) { | ||||
| nodeSetSocketAvailability(ntree, sock, sss_method != SHD_SUBSURFACE_BURLEY); | nodeSetSocketAvailability(ntree, sock, sss_method != SHD_SUBSURFACE_BURLEY); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } // namespace blender::nodes::node_shader_subsurface_scattering_cc | |||||
| /* node type definition */ | /* node type definition */ | ||||
| void register_node_type_sh_subsurface_scattering() | void register_node_type_sh_subsurface_scattering(void) | ||||
| { | { | ||||
| namespace file_ns = blender::nodes::node_shader_subsurface_scattering_cc; | |||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| sh_node_type_base( | sh_node_type_base( | ||||
| &ntype, SH_NODE_SUBSURFACE_SCATTERING, "Subsurface Scattering", NODE_CLASS_SHADER, 0); | &ntype, SH_NODE_SUBSURFACE_SCATTERING, "Subsurface Scattering", NODE_CLASS_SHADER, 0); | ||||
| ntype.declare = file_ns::node_declare; | node_type_socket_templates( | ||||
| &ntype, sh_node_subsurface_scattering_in, sh_node_subsurface_scattering_out); | |||||
| node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); | node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); | ||||
| node_type_init(&ntype, file_ns::node_shader_init_subsurface_scattering); | node_type_init(&ntype, node_shader_init_subsurface_scattering); | ||||
| node_type_storage(&ntype, "", nullptr, nullptr); | node_type_storage(&ntype, "", NULL, NULL); | ||||
| node_type_gpu(&ntype, file_ns::node_shader_gpu_subsurface_scattering); | node_type_gpu(&ntype, node_shader_gpu_subsurface_scattering); | ||||
| node_type_update(&ntype, file_ns::node_shader_update_subsurface_scattering); | node_type_update(&ntype, node_shader_update_subsurface_scattering); | ||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||