Welcome to mirror list, hosted at ThFree Co, Russian Federation.

node_texture_separate_color.c « nodes « texture « nodes « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a482a3f3421598f7d97bea077486d4acb4155cf4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* SPDX-License-Identifier: GPL-2.0-or-later
 * Copyright 2022 Blender Foundation. All rights reserved. */

/** \file
 * \ingroup texnodes
 */

#include "BLI_listbase.h"
#include "NOD_texture.h"
#include "node_texture_util.h"
#include <math.h>

static bNodeSocketTemplate inputs[] = {
    {SOCK_RGBA, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f},
    {-1, ""},
};
static bNodeSocketTemplate outputs[] = {
    {SOCK_FLOAT, N_("Red")},
    {SOCK_FLOAT, N_("Green")},
    {SOCK_FLOAT, N_("Blue")},
    {SOCK_FLOAT, N_("Alpha")},
    {-1, ""},
};

static void apply_color_space(float *out, NodeCombSepColorMode type)
{
  switch (type) {
    case NODE_COMBSEP_COLOR_RGB: {
      /* Pass */
      break;
    }
    case NODE_COMBSEP_COLOR_HSV: {
      rgb_to_hsv_v(out, out);
      break;
    }
    case NODE_COMBSEP_COLOR_HSL: {
      rgb_to_hsl_v(out, out);
      break;
    }
    default: {
      BLI_assert_unreachable();
      break;
    }
  }
}

static void valuefn_r(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
{
  tex_input_rgba(out, in[0], p, thread);
  apply_color_space(out, (NodeCombSepColorMode)node->custom1);
  *out = out[0];
}

static void valuefn_g(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
{
  tex_input_rgba(out, in[0], p, thread);
  apply_color_space(out, (NodeCombSepColorMode)node->custom1);
  *out = out[1];
}

static void valuefn_b(float *out, TexParams *p, bNode *node, bNodeStack **in, short thread)
{
  tex_input_rgba(out, in[0], p, thread);
  apply_color_space(out, (NodeCombSepColorMode)node->custom1);
  *out = out[2];
}

static void valuefn_a(float *out, TexParams *p, bNode *UNUSED(node), bNodeStack **in, short thread)
{
  tex_input_rgba(out, in[0], p, thread);
  *out = out[3];
}

static void update(bNodeTree *UNUSED(ntree), bNode *node)
{
  node_combsep_color_label(&node->outputs, (NodeCombSepColorMode)node->custom1);
}

static void exec(void *data,
                 int UNUSED(thread),
                 bNode *node,
                 bNodeExecData *execdata,
                 bNodeStack **in,
                 bNodeStack **out)
{
  tex_output(node, execdata, in, out[0], &valuefn_r, data);
  tex_output(node, execdata, in, out[1], &valuefn_g, data);
  tex_output(node, execdata, in, out[2], &valuefn_b, data);
  tex_output(node, execdata, in, out[3], &valuefn_a, data);
}

void register_node_type_tex_separate_color(void)
{
  static bNodeType ntype;

  tex_node_type_base(&ntype, TEX_NODE_SEPARATE_COLOR, "Separate Color", NODE_CLASS_OP_COLOR);
  node_type_socket_templates(&ntype, inputs, outputs);
  node_type_exec(&ntype, NULL, NULL, exec);
  node_type_update(&ntype, update);

  nodeRegisterType(&ntype);
}