Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/shader/nodes/node_shader_rgb_to_bw.cc
- This file was copied from source/blender/nodes/shader/nodes/node_shader_squeeze.cc.
| Show All 15 Lines | |||||
| * The Original Code is Copyright (C) 2005 Blender Foundation. | * The Original Code is Copyright (C) 2005 Blender Foundation. | ||||
| * All rights reserved. | * All rights reserved. | ||||
| */ | */ | ||||
| /** \file | /** \file | ||||
| * \ingroup shdnodes | * \ingroup shdnodes | ||||
| */ | */ | ||||
| #include "IMB_colormanagement.h" | |||||
| #include "node_shader_util.hh" | #include "node_shader_util.hh" | ||||
| /* **************** VALUE SQUEEZE ******************** */ | namespace blender::nodes::node_shader_rgb_to_bw_cc { | ||||
| static bNodeSocketTemplate sh_node_squeeze_in[] = { | |||||
| {SOCK_FLOAT, N_("Value"), 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE}, | |||||
| {SOCK_FLOAT, N_("Width"), 1.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE}, | |||||
| {SOCK_FLOAT, N_("Center"), 0.0f, 0.0f, 0.0f, 0.0f, -100.0f, 100.0f, PROP_NONE}, | |||||
| {-1, ""}}; | |||||
| static bNodeSocketTemplate sh_node_squeeze_out[] = {{SOCK_FLOAT, N_("Value")}, {-1, ""}}; | static void sh_node_rgbtobw_declare(NodeDeclarationBuilder &b) | ||||
| { | |||||
| b.add_input<decl::Color>(N_("Color")).default_value({0.5f, 0.5f, 0.5f, 1.0f}); | |||||
| b.add_output<decl::Float>(N_("Val")); | |||||
| }; | |||||
| static void node_shader_exec_squeeze(void *UNUSED(data), | static void node_shader_exec_rgbtobw(void *UNUSED(data), | ||||
| int UNUSED(thread), | int UNUSED(thread), | ||||
| bNode *UNUSED(node), | bNode *UNUSED(node), | ||||
| bNodeExecData *UNUSED(execdata), | bNodeExecData *UNUSED(execdata), | ||||
| bNodeStack **in, | bNodeStack **in, | ||||
| bNodeStack **out) | bNodeStack **out) | ||||
| { | { | ||||
| float vec[3]; | /* Stack order out: BW. */ | ||||
| /* Stack order in: COL. */ | |||||
| nodestack_get_vec(vec, SOCK_FLOAT, in[0]); | float col[3]; | ||||
| nodestack_get_vec(vec + 1, SOCK_FLOAT, in[1]); | nodestack_get_vec(col, SOCK_VECTOR, in[0]); | ||||
| nodestack_get_vec(vec + 2, SOCK_FLOAT, in[2]); | |||||
| out[0]->vec[0] = 1.0f / (1.0f + powf(M_E, -((vec[0] - vec[2]) * vec[1]))); | out[0]->vec[0] = IMB_colormanagement_get_luminance(col); | ||||
| } | } | ||||
| static int gpu_shader_squeeze(GPUMaterial *mat, | static int gpu_shader_rgbtobw(GPUMaterial *mat, | ||||
| bNode *node, | bNode *node, | ||||
| bNodeExecData *UNUSED(execdata), | bNodeExecData *UNUSED(execdata), | ||||
| GPUNodeStack *in, | GPUNodeStack *in, | ||||
| GPUNodeStack *out) | GPUNodeStack *out) | ||||
| { | { | ||||
| return GPU_stack_link(mat, node, "squeeze", in, out); | return GPU_stack_link(mat, node, "rgbtobw", in, out); | ||||
| } | } | ||||
| void register_node_type_sh_squeeze() | } // namespace blender::nodes::node_shader_valToRgb_cc | ||||
| void register_node_type_sh_rgbtobw() | |||||
| { | { | ||||
| namespace file_ns = blender::nodes::node_shader_rgb_to_bw_cc; | |||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| sh_node_type_base(&ntype, SH_NODE_SQUEEZE, "Squeeze Value", NODE_CLASS_CONVERTER, 0); | sh_node_type_base(&ntype, SH_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTER, 0); | ||||
| node_type_socket_templates(&ntype, sh_node_squeeze_in, sh_node_squeeze_out); | ntype.declare = file_ns::sh_node_rgbtobw_declare; | ||||
| node_type_storage(&ntype, "", nullptr, nullptr); | node_type_exec(&ntype, nullptr, nullptr, file_ns::node_shader_exec_rgbtobw); | ||||
| node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_squeeze); | node_type_gpu(&ntype, file_ns::gpu_shader_rgbtobw); | ||||
| node_type_gpu(&ntype, gpu_shader_squeeze); | |||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||