Files
goo-engine/source/blender/nodes/intern/node_register.cc
T
Jacques Lucke 6e5e01e630 Geometry Nodes: new For Each Geometry Element zone
This adds a new type of zone to Geometry Nodes that allows executing some nodes
for each element in a geometry.

## Features

* The `Selection` input allows iterating over a subset of elements on the set
  domain.
* Fields passed into the input node are available as single values inside of the
  zone.
* The input geometry can be split up into separate (completely independent)
  geometries for each element (on all domains except face corner).
* New attributes can be created on the input geometry by outputting a single
  value from each iteration.
* New geometries can be generated in each iteration.
    * All of these geometries are joined to form the final output.
    * Attributes from the input geometry are propagated to the output
      geometries.

## Evaluation

The evaluation strategy is similar to the one used for repeat zones. Namely, it
dynamically builds a `lazy_function::Graph` once it knows how many iterations
are necessary. It contains a separate node for each iteration. The inputs for
each iteration are hardcoded into the graph. The outputs of each iteration a
passed to a separate lazy-function that reduces all the values down to the final
outputs. This final output can have a huge number of inputs and that is not
ideal for multi-threading yet, but that can still be improved in the future.

## Performance

There is a non-neglilible amount of overhead for each iteration. The overhead is
way larger than the per-element overhead when just doing field evaluation.
Therefore, normal field evaluation should be preferred when possible. That can
partially still be optimized if there is only some number crunching going on in
the zone but that optimization is not implemented yet.

However, processing many small geometries (e.g. each hair of a character
separately) will likely **always be slower** than working on fewer larger
geoemtries. The additional flexibility you get by processing each element
separately comes at the cost that Blender can't optimize the operation as well.
For node groups that need to handle lots of geometry elements, we recommend
trying to design the node setup so that iteration over tiny sub-geometries is
not required.

An opposite point is true as well though. It can be faster to process more
medium sized geometries in parallel than fewer very large geometries because of
more multi-threading opportunities. The exact threshold between tiny, medium and
large geometries depends on a lot of factors though.

Overall, this initial version of the new zone does not implement all
optimization opportunities yet, but the points mentioned above will still hold
true later.

Pull Request: https://projects.blender.org/blender/blender/pulls/127331
2024-09-24 11:52:02 +02:00

137 lines
4.4 KiB
C++

/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "BLI_string.h"
#include "NOD_geometry.hh"
#include "NOD_register.hh"
#include "NOD_socket.hh"
#include "BKE_node.hh"
#include "BLT_translation.hh"
#include "UI_resources.hh"
static bool node_undefined_poll(const blender::bke::bNodeType * /*ntype*/,
const bNodeTree * /*nodetree*/,
const char ** /*r_disabled_hint*/)
{
/* this type can not be added deliberately, it's just a placeholder */
return false;
}
/* register fallback types used for undefined tree, nodes, sockets */
static void register_undefined_types()
{
/* NOTE: these types are not registered in the type hashes,
* they are just used as placeholders in case the actual types are not registered.
*/
blender::bke::NodeTreeTypeUndefined.type = NTREE_UNDEFINED;
STRNCPY(blender::bke::NodeTreeTypeUndefined.idname, "NodeTreeUndefined");
STRNCPY(blender::bke::NodeTreeTypeUndefined.ui_name, N_("Undefined"));
STRNCPY(blender::bke::NodeTreeTypeUndefined.ui_description, N_("Undefined Node Tree Type"));
blender::bke::node_type_base_custom(
&blender::bke::NodeTypeUndefined, "NodeUndefined", "Undefined", "UNDEFINED", 0);
blender::bke::NodeTypeUndefined.poll = node_undefined_poll;
STRNCPY(blender::bke::NodeSocketTypeUndefined.idname, "NodeSocketUndefined");
/* extra type info for standard socket types */
blender::bke::NodeSocketTypeUndefined.type = SOCK_CUSTOM;
blender::bke::NodeSocketTypeUndefined.subtype = PROP_NONE;
blender::bke::NodeSocketTypeUndefined.use_link_limits_of_type = true;
blender::bke::NodeSocketTypeUndefined.input_link_limit = 0xFFF;
blender::bke::NodeSocketTypeUndefined.output_link_limit = 0xFFF;
}
class SimulationZoneType : public blender::bke::bNodeZoneType {
public:
SimulationZoneType()
{
this->input_idname = "GeometryNodeSimulationInput";
this->output_idname = "GeometryNodeSimulationOutput";
this->input_type = GEO_NODE_SIMULATION_INPUT;
this->output_type = GEO_NODE_SIMULATION_OUTPUT;
this->theme_id = TH_NODE_ZONE_SIMULATION;
}
const int &get_corresponding_output_id(const bNode &input_bnode) const override
{
BLI_assert(input_bnode.type == this->input_type);
return static_cast<NodeGeometrySimulationInput *>(input_bnode.storage)->output_node_id;
}
};
class RepeatZoneType : public blender::bke::bNodeZoneType {
public:
RepeatZoneType()
{
this->input_idname = "GeometryNodeRepeatInput";
this->output_idname = "GeometryNodeRepeatOutput";
this->input_type = GEO_NODE_REPEAT_INPUT;
this->output_type = GEO_NODE_REPEAT_OUTPUT;
this->theme_id = TH_NODE_ZONE_REPEAT;
}
const int &get_corresponding_output_id(const bNode &input_bnode) const override
{
BLI_assert(input_bnode.type == this->input_type);
return static_cast<NodeGeometryRepeatInput *>(input_bnode.storage)->output_node_id;
}
};
class ForeachGeometryElementZoneType : public blender::bke::bNodeZoneType {
public:
ForeachGeometryElementZoneType()
{
this->input_idname = "GeometryNodeForeachGeometryElementInput";
this->output_idname = "GeometryNodeForeachGeometryElementOutput";
this->input_type = GEO_NODE_FOREACH_GEOMETRY_ELEMENT_INPUT;
this->output_type = GEO_NODE_FOREACH_GEOMETRY_ELEMENT_OUTPUT;
this->theme_id = TH_NODE_ZONE_FOREACH_GEOMETRY_ELEMENT;
}
const int &get_corresponding_output_id(const bNode &input_bnode) const override
{
BLI_assert(input_bnode.type == this->input_type);
return static_cast<NodeGeometryForeachGeometryElementInput *>(input_bnode.storage)
->output_node_id;
}
};
static void register_zone_types()
{
static SimulationZoneType simulation_zone_type;
static RepeatZoneType repeat_zone_type;
static ForeachGeometryElementZoneType foreach_geometry_element_zone_type;
blender::bke::register_node_zone_type(simulation_zone_type);
blender::bke::register_node_zone_type(repeat_zone_type);
blender::bke::register_node_zone_type(foreach_geometry_element_zone_type);
}
void register_nodes()
{
register_zone_types();
register_undefined_types();
register_standard_node_socket_types();
register_node_tree_type_geo();
register_node_type_frame();
register_node_type_reroute();
register_node_type_group_input();
register_node_type_group_output();
register_composite_nodes();
register_shader_nodes();
register_texture_nodes();
register_geometry_nodes();
register_function_nodes();
}