Skip to content

Commit

Permalink
Add RecastCracks node, fix angle scaling of GaborWave and Gavoronoise
Browse files Browse the repository at this point in the history
  • Loading branch information
otto-link committed Jan 5, 2025
1 parent be20e5e commit 46c1c16
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 6 deletions.
1 change: 1 addition & 0 deletions Hesiod/include/hesiod/model/nodes/node_factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ DECLARE_NODE(radial_displacement_to_xy)
DECLARE_NODE(recast_canyon)
DECLARE_NODE(recast_cliff)
DECLARE_NODE(recast_cliff_directional)
DECLARE_NODE(recast_cracks)
DECLARE_NODE(recast_sag)
DECLARE_NODE(recurve)
DECLARE_NODE(recurve_kura)
Expand Down
2 changes: 2 additions & 0 deletions Hesiod/src/model/nodes/node_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ std::map<std::string, std::string> get_node_inventory()
{"RecastCanyon", "Filter/Recast"},
{"RecastCliff", "Filter/Recast"},
{"RecastCliffDirectional", "Filter/Recast"},
{"RecastCracks", "Filter/Recast"},
{"RecastSag", "Filter/Recast"},
{"Recurve", "Filter/Recurve"},
{"RecurveKura", "Filter/Recurve"},
Expand Down Expand Up @@ -401,6 +402,7 @@ std::shared_ptr<gnode::Node> node_factory(const std::string &node_type
SETUP_NODE(RecastCanyon, recast_canyon);
SETUP_NODE(RecastCliff, recast_cliff);
SETUP_NODE(RecastCliffDirectional, recast_cliff_directional);
SETUP_NODE(RecastCracks, recast_cracks);
SETUP_NODE(RecastSag, recast_sag);
SETUP_NODE(Recurve, recurve);
SETUP_NODE(RecurveKura, recurve_kura);
Expand Down
7 changes: 4 additions & 3 deletions Hesiod/src/model/nodes/nodes_function/gabor_wave_fbm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ void compute_gabor_wave_fbm_node(BaseNode *p_node)

// manage angle (as a scalar parameter or as an input heightmap if
// provided)
hmap::Heightmap angle_map = !p_angle
? hmap::Heightmap(CONFIG, GET("angle", FloatAttribute))
: hmap::Heightmap();
hmap::Heightmap angle_map = !p_angle ? hmap::Heightmap(CONFIG,
M_PI / 180.f *
GET("angle", FloatAttribute))
: hmap::Heightmap();
p_angle = p_angle ? p_angle : &angle_map;

hmap::transform(
Expand Down
7 changes: 4 additions & 3 deletions Hesiod/src/model/nodes/nodes_function/gavoronoise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ void compute_gavoronoise_node(BaseNode *p_node)

// manage angle (as a scalar parameter or as an input heightmap if
// provided)
hmap::Heightmap angle_map = !p_angle
? hmap::Heightmap(CONFIG, GET("angle", FloatAttribute))
: hmap::Heightmap();
hmap::Heightmap angle_map = !p_angle ? hmap::Heightmap(CONFIG,
M_PI / 180.f *
GET("angle", FloatAttribute))
: hmap::Heightmap();
p_angle = p_angle ? p_angle : &angle_map;

hmap::transform(
Expand Down
72 changes: 72 additions & 0 deletions Hesiod/src/model/nodes/nodes_function/recast_cracks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* Copyright (c) 2023 Otto Link. Distributed under the terms of the GNU General
* Public License. The full license is in the file LICENSE, distributed with
* this software. */
#include "highmap/filters.hpp"

#include "attributes.hpp"

#include "hesiod/logger.hpp"
#include "hesiod/model/nodes/base_node.hpp"
#include "hesiod/model/utils.hpp"

using namespace attr;

namespace hesiod
{

void setup_recast_cracks_node(BaseNode *p_node)
{
LOG->trace("setup node {}", p_node->get_label());

// port(s)
p_node->add_port<hmap::Heightmap>(gnode::PortType::IN, "input");
p_node->add_port<hmap::Heightmap>(gnode::PortType::OUT, "output", CONFIG);

// attribute(s)
p_node->add_attr<FloatAttribute>("cut_min", 0.05f, 0.f, 1.f, "cut_min");
p_node->add_attr<FloatAttribute>("cut_max", 0.5f, 0.f, 1.f, "cut_max");
p_node->add_attr<FloatAttribute>("k_smoothing", 0.01f, 0.f, 1.f, "k_smoothing");
}

void compute_recast_cracks_node(BaseNode *p_node)
{
Q_EMIT p_node->compute_started(p_node->get_id());

LOG->trace("computing node {}", p_node->get_label());

hmap::Heightmap *p_in = p_node->get_value_ref<hmap::Heightmap>("input");

if (p_in)
{
hmap::Heightmap *p_out = p_node->get_value_ref<hmap::Heightmap>("output");

// copy the input heightmap
*p_out = *p_in;

float hmin = p_in->min();
float hmax = p_in->max();

hmap::transform(
{p_out},
[p_node, hmin, hmax](std::vector<hmap::Array *> p_arrays,
hmap::Vec2<int>,
hmap::Vec4<float>)
{
hmap::Array *pa_out = p_arrays[0];

hmap::recast_cracks(*pa_out,
GET("cut_min", FloatAttribute),
GET("cut_max", FloatAttribute),
GET("k_smoothing", FloatAttribute),
hmin,
hmax);
},
hmap::TransformMode::DISTRIBUTED);

p_out->smooth_overlap_buffers();
}

Q_EMIT p_node->compute_finished(p_node->get_id());
}

} // namespace hesiod

0 comments on commit 46c1c16

Please sign in to comment.