@@ -15,58 +15,80 @@ using namespace attr;
1515namespace hesiod
1616{
1717
18+ // -----------------------------------------------------------------------------
19+ // Ports & Attributes
20+ // -----------------------------------------------------------------------------
21+
22+ constexpr const char *P_INPUT = " input" ;
23+ constexpr const char *P_MASK = " mask" ;
24+ constexpr const char *P_OUTPUT = " output" ;
25+
26+ constexpr const char *A_RADIUS = " radius" ;
27+
28+ // -----------------------------------------------------------------------------
29+ // Setup
30+ // -----------------------------------------------------------------------------
31+
1832void setup_smooth_cpulse_node (BaseNode &node)
1933{
2034 Logger::log ()->trace (" setup node {}" , node.get_label ());
2135
2236 // port(s)
23- node.add_port <hmap::VirtualArray>(gnode::PortType::IN, " input " );
24- node.add_port <hmap::VirtualArray>(gnode::PortType::IN, " mask " );
25- node.add_port <hmap::VirtualArray>(gnode::PortType::OUT, " output " , CONFIG (node));
37+ node.add_port <hmap::VirtualArray>(gnode::PortType::IN, P_INPUT );
38+ node.add_port <hmap::VirtualArray>(gnode::PortType::IN, P_MASK );
39+ node.add_port <hmap::VirtualArray>(gnode::PortType::OUT, P_OUTPUT , CONFIG (node));
2640
2741 // attribute(s)
28- node.add_attr <FloatAttribute>(" radius " , " radius " , 0 .05f , 0 .f , 0 .2f );
42+ node.add_attr <FloatAttribute>(A_RADIUS , " Radius " , 0 .05f , 0 .f , 0 .2f );
2943
3044 // attribute(s) order
31- node.set_attr_ordered_key ({" radius " });
45+ node.set_attr_ordered_key ({A_RADIUS });
3246
3347 setup_pre_process_mask_attributes (node);
3448 setup_post_process_heightmap_attributes (node,
3549 {.add_mix = true , .remap_active_state = false });
3650}
3751
52+ // -----------------------------------------------------------------------------
53+ // Compute
54+ // -----------------------------------------------------------------------------
55+
3856void compute_smooth_cpulse_node (BaseNode &node)
3957{
4058 Logger::log ()->trace (" computing node [{}]/[{}]" , node.get_label (), node.get_id ());
4159
42- hmap::VirtualArray *p_in = node.get_value_ref <hmap::VirtualArray>(" input" );
60+ auto *p_in = node.get_value_ref <hmap::VirtualArray>(P_INPUT);
61+ auto *p_out = node.get_value_ref <hmap::VirtualArray>(P_OUTPUT);
62+
63+ if (!p_in || !p_out)
64+ return ;
4365
44- if (p_in)
45- {
46- hmap::VirtualArray *p_mask = node.get_value_ref <hmap::VirtualArray>(" mask" );
47- hmap::VirtualArray *p_out = node.get_value_ref <hmap::VirtualArray>(" output" );
66+ auto *p_mask = node.get_value_ref <hmap::VirtualArray>(P_MASK);
4867
49- // prepare mask
50- std::shared_ptr<hmap::VirtualArray> sp_mask = pre_process_mask (node, p_mask, *p_in);
68+ // prepare mask
69+ std::shared_ptr<hmap::VirtualArray> sp_mask = pre_process_mask (node, p_mask, *p_in);
5170
52- int ir = std::max (1 , (int )(node.get_attr <FloatAttribute>(" radius " ) * p_out->shape .x ));
71+ int ir = std::max (1 , (int )(node.get_attr <FloatAttribute>(A_RADIUS ) * p_out->shape .x ));
5372
54- hmap::for_each_tile (
55- {p_out, p_in, p_mask},
56- [&ir](std::vector<hmap::Array *> p_arrays, const hmap::TileRegion &)
57- {
58- auto [pa_out, pa_in, pa_mask] = unpack<3 >(p_arrays);
59- *pa_out = *pa_in;
73+ hmap::for_each_tile (
74+ {p_in, p_mask},
75+ {p_out},
76+ [&ir](std::vector<const hmap::Array *> p_arrays_in,
77+ std::vector<hmap::Array *> p_arrays_out,
78+ const hmap::TileRegion &)
79+ {
80+ const auto [pa_in, pa_mask] = unpack<2 >(p_arrays_in);
81+ auto [pa_out] = unpack<1 >(p_arrays_out);
82+ *pa_out = *pa_in;
6083
61- hmap::gpu::smooth_cpulse (*pa_out, ir, pa_mask);
62- },
63- node.cfg ().cm_gpu );
84+ hmap::gpu::smooth_cpulse (*pa_out, ir, pa_mask);
85+ },
86+ node.cfg ().cm_gpu );
6487
65- p_out->smooth_overlap_buffers ();
88+ p_out->smooth_overlap_buffers ();
6689
67- // post-process
68- post_process_heightmap (node, *p_out, p_in);
69- }
90+ // post-process
91+ post_process_heightmap (node, *p_out, p_in);
7092}
7193
7294} // namespace hesiod
0 commit comments