@@ -14,32 +14,64 @@ using namespace attr;
1414namespace hesiod
1515{
1616
17+ // -----------------------------------------------------------------------------
18+ // Ports & Attributes
19+ // -----------------------------------------------------------------------------
20+
21+ constexpr const char *P_ALPHA = " alpha" ;
22+ constexpr const char *P_TEXTURE = " texture" ;
23+
24+ constexpr const char *A_COLOR = " color" ;
25+ constexpr const char *A_ALPHA = " alpha" ;
26+
27+ // -----------------------------------------------------------------------------
28+ // Setup
29+ // -----------------------------------------------------------------------------
30+
1731void setup_colorize_solid_node (BaseNode &node)
1832{
1933 Logger::log ()->trace (" setup node {}" , node.get_label ());
2034
2135 // port(s)
22- node.add_port <hmap::VirtualTexture>(gnode::PortType::OUT, " texture" , CONFIG_TEX (node));
36+ node.add_port <hmap::VirtualArray>(gnode::PortType::IN, P_ALPHA);
37+ node.add_port <hmap::VirtualTexture>(gnode::PortType::OUT, P_TEXTURE, CONFIG_TEX (node));
2338
2439 // attribute(s)
25- node.add_attr <ColorAttribute>(" color " , " color " , 0 .5f , 0 . 5f , 0 .5f , 1 .f );
26- node.add_attr <FloatAttribute>(" alpha " , " alpha " , 1 .f , 0 .f , 1 .f );
40+ node.add_attr <ColorAttribute>(A_COLOR , " Solid Color " , 0 .f , 1 . f , 0 .f , 1 .f );
41+ node.add_attr <FloatAttribute>(A_ALPHA , " Transparency " , 1 .f , 0 .f , 1 .f );
2742
2843 // attribute(s) order
29- node.set_attr_ordered_key ({" color " , " alpha " });
44+ node.set_attr_ordered_key ({A_COLOR, A_ALPHA });
3045}
3146
47+ // -----------------------------------------------------------------------------
48+ // Compute
49+ // -----------------------------------------------------------------------------
50+
3251void compute_colorize_solid_node (BaseNode &node)
3352{
3453 Logger::log ()->trace (" computing node [{}]/[{}]" , node.get_label (), node.get_id ());
3554
36- hmap::VirtualTexture *p_tex = node.get_value_ref <hmap::VirtualTexture>(" texture" );
37- std::vector<float > col3 = node.get_attr <ColorAttribute>(" color" );
55+ auto *p_alpha = node.get_value_ref <hmap::VirtualArray>(P_ALPHA);
56+ auto *p_texture = node.get_value_ref <hmap::VirtualTexture>(P_TEXTURE);
57+
58+ const std::vector<float > color = node.get_attr <ColorAttribute>(A_COLOR);
59+ const float alpha = node.get_attr <FloatAttribute>(A_ALPHA);
3860
3961 for (int nch = 0 ; nch < 4 ; ++nch)
4062 {
41- float v = nch < 3 ? col3[nch] : node.get_attr <FloatAttribute>(" alpha" );
42- p_tex->fill (nch, v, node.cfg ().cm_cpu );
63+ if (nch < 3 )
64+ {
65+ p_texture->fill (nch, color[nch], node.cfg ().cm_cpu );
66+ }
67+ else
68+ {
69+ // use alpha input port if available
70+ if (p_alpha)
71+ hmap::copy_data (*p_alpha, p_texture->channel (nch), node.cfg ().cm_cpu );
72+ else
73+ p_texture->fill (nch, alpha, node.cfg ().cm_cpu );
74+ }
4375 }
4476}
4577
0 commit comments