Skip to content

Commit d1ffb0e

Browse files
committed
Add alpha input for ColorizeSolid (#524)
1 parent 60eb40e commit d1ffb0e

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

Hesiod/src/model/nodes/nodes_function/colorize_solid.cpp

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,64 @@ using namespace attr;
1414
namespace 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+
1731
void 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+
3251
void 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

Hesiod/src/model/nodes/nodes_function/snow_melting_map.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
* Public License. The full license is in the file LICENSE, distributed with
33
* this software. */
44
#include "highmap/hydrology.hpp"
5-
#include "highmap/primitives.hpp"
6-
#include "highmap/range.hpp"
75

86
#include "attributes.hpp"
97

108
#include "hesiod/logger.hpp"
119
#include "hesiod/model/nodes/base_node.hpp"
12-
#include "hesiod/model/nodes/post_process.hpp"
1310

1411
using namespace attr;
1512

Hesiod/src/model/nodes/nodes_function/snow_simulation.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
* Public License. The full license is in the file LICENSE, distributed with
33
* this software. */
44
#include "highmap/hydrology.hpp"
5-
#include "highmap/primitives.hpp"
65
#include "highmap/range.hpp"
76

87
#include "attributes.hpp"
98

109
#include "hesiod/logger.hpp"
1110
#include "hesiod/model/nodes/base_node.hpp"
12-
#include "hesiod/model/nodes/post_process.hpp"
1311

1412
using namespace attr;
1513

0 commit comments

Comments
 (0)