Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/shader/nodes/node_shader_valToRgb.cc
| Show All 23 Lines | |||||
| #include "IMB_colormanagement.h" | #include "IMB_colormanagement.h" | ||||
| #include "DNA_texture_types.h" | #include "DNA_texture_types.h" | ||||
| #include "BLI_color.hh" | #include "BLI_color.hh" | ||||
| #include "node_shader_util.hh" | #include "node_shader_util.hh" | ||||
| namespace blender::nodes { | namespace blender::nodes::node_shader_valToRgb_cc { | ||||
| static void sh_node_valtorgb_declare(NodeDeclarationBuilder &b) | static void sh_node_valtorgb_declare(NodeDeclarationBuilder &b) | ||||
| { | { | ||||
| b.is_function_node(); | b.is_function_node(); | ||||
| b.add_input<decl::Float>(N_("Fac")).default_value(0.5f).min(0.0f).max(1.0f).subtype(PROP_FACTOR); | b.add_input<decl::Float>(N_("Fac")).default_value(0.5f).min(0.0f).max(1.0f).subtype(PROP_FACTOR); | ||||
| b.add_output<decl::Color>(N_("Color")); | b.add_output<decl::Color>(N_("Color")); | ||||
| b.add_output<decl::Float>(N_("Alpha")); | b.add_output<decl::Float>(N_("Alpha")); | ||||
| }; | }; | ||||
| } // namespace blender::nodes | |||||
| static void node_shader_exec_valtorgb(void *UNUSED(data), | static void node_shader_exec_valtorgb(void *UNUSED(data), | ||||
| int UNUSED(thread), | int UNUSED(thread), | ||||
| bNode *node, | bNode *node, | ||||
| bNodeExecData *UNUSED(execdata), | bNodeExecData *UNUSED(execdata), | ||||
| bNodeStack **in, | bNodeStack **in, | ||||
| bNodeStack **out) | bNodeStack **out) | ||||
| { | { | ||||
| /* stack order in: fac */ | /* stack order in: fac */ | ||||
| ▲ Show 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | |||||
| static void sh_node_valtorgb_build_multi_function( | static void sh_node_valtorgb_build_multi_function( | ||||
| blender::nodes::NodeMultiFunctionBuilder &builder) | blender::nodes::NodeMultiFunctionBuilder &builder) | ||||
| { | { | ||||
| bNode &bnode = builder.node(); | bNode &bnode = builder.node(); | ||||
| const ColorBand *color_band = (const ColorBand *)bnode.storage; | const ColorBand *color_band = (const ColorBand *)bnode.storage; | ||||
| builder.construct_and_set_matching_fn<ColorBandFunction>(*color_band); | builder.construct_and_set_matching_fn<ColorBandFunction>(*color_band); | ||||
| } | } | ||||
| void register_node_type_sh_valtorgb() | |||||
| { | |||||
| static bNodeType ntype; | |||||
| sh_fn_node_type_base(&ntype, SH_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTER, 0); | |||||
| ntype.declare = blender::nodes::sh_node_valtorgb_declare; | |||||
| node_type_init(&ntype, node_shader_init_valtorgb); | |||||
| node_type_size_preset(&ntype, NODE_SIZE_LARGE); | |||||
| node_type_storage(&ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage); | |||||
| node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_valtorgb); | |||||
| node_type_gpu(&ntype, gpu_shader_valtorgb); | |||||
| ntype.build_multi_function = sh_node_valtorgb_build_multi_function; | |||||
| nodeRegisterType(&ntype); | |||||
| } | |||||
| namespace blender::nodes { | |||||
| static void sh_node_rgbtobw_declare(NodeDeclarationBuilder &b) | 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_input<decl::Color>(N_("Color")).default_value({0.5f, 0.5f, 0.5f, 1.0f}); | ||||
| b.add_output<decl::Float>(N_("Val")); | b.add_output<decl::Float>(N_("Val")); | ||||
| }; | }; | ||||
| } // namespace blender::nodes | |||||
| static void node_shader_exec_rgbtobw(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) | ||||
| { | { | ||||
| /* Stack order out: BW. */ | /* Stack order out: BW. */ | ||||
| /* Stack order in: COL. */ | /* Stack order in: COL. */ | ||||
| float col[3]; | float col[3]; | ||||
| nodestack_get_vec(col, SOCK_VECTOR, in[0]); | nodestack_get_vec(col, SOCK_VECTOR, in[0]); | ||||
| out[0]->vec[0] = IMB_colormanagement_get_luminance(col); | out[0]->vec[0] = IMB_colormanagement_get_luminance(col); | ||||
| } | } | ||||
| static int gpu_shader_rgbtobw(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, "rgbtobw", in, out); | return GPU_stack_link(mat, node, "rgbtobw", in, out); | ||||
| } | } | ||||
| } // namespace blender::nodes::node_shader_rgbtobw_cc | |||||
| void register_node_type_sh_valtorgb() | |||||
| { | |||||
| namespace file_ns = blender::nodes::node_shader_valToRgb_cc; | |||||
| static bNodeType ntype; | |||||
| sh_fn_node_type_base(&ntype, SH_NODE_VALTORGB, "ColorRamp", NODE_CLASS_CONVERTER, 0); | |||||
| ntype.declare = file_ns::sh_node_valtorgb_declare; | |||||
| node_type_init(&ntype, file_ns::node_shader_init_valtorgb); | |||||
| node_type_size_preset(&ntype, NODE_SIZE_LARGE); | |||||
| node_type_storage(&ntype, "ColorBand", node_free_standard_storage, node_copy_standard_storage); | |||||
| node_type_exec(&ntype, nullptr, nullptr, file_ns::node_shader_exec_valtorgb); | |||||
| node_type_gpu(&ntype, file_ns::gpu_shader_valtorgb); | |||||
| ntype.build_multi_function = file_ns::sh_node_valtorgb_build_multi_function; | |||||
| nodeRegisterType(&ntype); | |||||
| } | |||||
| void register_node_type_sh_rgbtobw() | void register_node_type_sh_rgbtobw() | ||||
| { | { | ||||
| namespace file_ns = blender::nodes::node_shader_valToRgb_cc; | |||||
| static bNodeType ntype; | static bNodeType ntype; | ||||
| sh_node_type_base(&ntype, SH_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTER, 0); | sh_node_type_base(&ntype, SH_NODE_RGBTOBW, "RGB to BW", NODE_CLASS_CONVERTER, 0); | ||||
| ntype.declare = blender::nodes::sh_node_rgbtobw_declare; | ntype.declare = file_ns::sh_node_rgbtobw_declare; | ||||
| node_type_exec(&ntype, nullptr, nullptr, node_shader_exec_rgbtobw); | node_type_exec(&ntype, nullptr, nullptr, file_ns::node_shader_exec_rgbtobw); | ||||
| node_type_gpu(&ntype, gpu_shader_rgbtobw); | node_type_gpu(&ntype, file_ns::gpu_shader_rgbtobw); | ||||
| nodeRegisterType(&ntype); | nodeRegisterType(&ntype); | ||||
| } | } | ||||