Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacques Lucke <jacques@blender.org>2020-08-02 23:04:24 +0300
committerJacques Lucke <jacques@blender.org>2020-08-02 23:10:47 +0300
commit396d0b5cd0bcd9dd3dfa8d9006ee9f6f91c7196d (patch)
tree863a92ba15bd2d949c4b0de07735f635ac08e177 /source/blender/nodes
parentd1063575b536ed9490c5002007b45704e7755385 (diff)
Particles: new Age Reached Event, Kill Particle and Random Float node
The hardcoded age limit is now gone. The behavior can be implemented with an Age Reached Event and Kill Particle node. Other utility nodes to handle age limits of particles can be added later. Adding an Age Limit attribute to particles on birth will be useful for some effects, e.g. when you want to control the color or size of a particle over its life time. The Random Float node takes a seed currently. Different nodes will produce different values even with the same seed. However, the same node will generate the same random number for the same seed every time. The "Hash" of a particle can be used as seed. Later, we'd want to have more modes in the node to make it more user friendly. Modes could be: Per Particle, Per Time, Per Particle Per Time, Per Node Instance, ... Also a Random Vector node will be useful, as it currently has to be build using three Random Float nodes.
Diffstat (limited to 'source/blender/nodes')
-rw-r--r--source/blender/nodes/CMakeLists.txt3
-rw-r--r--source/blender/nodes/NOD_function.h1
-rw-r--r--source/blender/nodes/NOD_simulation.h2
-rw-r--r--source/blender/nodes/NOD_static_types.h4
-rw-r--r--source/blender/nodes/function/nodes/node_fn_random_float.cc89
-rw-r--r--source/blender/nodes/simulation/nodes/node_sim_age_reached_event.cc38
-rw-r--r--source/blender/nodes/simulation/nodes/node_sim_kill_particle.cc36
-rw-r--r--source/blender/nodes/simulation/nodes/node_sim_particle_mesh_emitter.cc1
8 files changed, 173 insertions, 1 deletions
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index c53e01ac80f..33b95d50cc0 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -136,6 +136,7 @@ set(SRC
function/nodes/node_fn_float_compare.cc
function/nodes/node_fn_group_instance_id.cc
function/nodes/node_fn_object_transforms.cc
+ function/nodes/node_fn_random_float.cc
function/nodes/node_fn_switch.cc
function/node_function_util.cc
@@ -232,10 +233,12 @@ set(SRC
shader/node_shader_tree.c
shader/node_shader_util.c
+ simulation/nodes/node_sim_age_reached_event.cc
simulation/nodes/node_sim_common.cc
simulation/nodes/node_sim_emit_particles.cc
simulation/nodes/node_sim_execute_condition.cc
simulation/nodes/node_sim_force.cc
+ simulation/nodes/node_sim_kill_particle.cc
simulation/nodes/node_sim_multi_execute.cc
simulation/nodes/node_sim_particle_attribute.cc
simulation/nodes/node_sim_particle_birth_event.cc
diff --git a/source/blender/nodes/NOD_function.h b/source/blender/nodes/NOD_function.h
index 4c05da694f7..1d22e9c6811 100644
--- a/source/blender/nodes/NOD_function.h
+++ b/source/blender/nodes/NOD_function.h
@@ -27,6 +27,7 @@ void register_node_type_fn_switch(void);
void register_node_type_fn_group_instance_id(void);
void register_node_type_fn_combine_strings(void);
void register_node_type_fn_object_transforms(void);
+void register_node_type_fn_random_float(void);
#ifdef __cplusplus
}
diff --git a/source/blender/nodes/NOD_simulation.h b/source/blender/nodes/NOD_simulation.h
index 2947d38fe83..fe3f73517ec 100644
--- a/source/blender/nodes/NOD_simulation.h
+++ b/source/blender/nodes/NOD_simulation.h
@@ -39,6 +39,8 @@ void register_node_type_sim_particle_mesh_collision_event(void);
void register_node_type_sim_emit_particles(void);
void register_node_type_sim_time(void);
void register_node_type_sim_particle_attribute(void);
+void register_node_type_sim_age_reached_event(void);
+void register_node_type_sim_kill_particle(void);
#ifdef __cplusplus
}
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index 31ce3f81450..7922a73902c 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -270,6 +270,8 @@ DefNode(SimulationNode, SIM_NODE_PARTICLE_MESH_COLLISION_EVENT, 0, "PARTIC
DefNode(SimulationNode, SIM_NODE_EMIT_PARTICLES, 0, "EMIT_PARTICLES", EmitParticles, "Emit Particles", "")
DefNode(SimulationNode, SIM_NODE_TIME, def_sim_time, "TIME", Time, "Time", "")
DefNode(SimulationNode, SIM_NODE_PARTICLE_ATTRIBUTE, def_sim_particle_attribute, "PARTICLE_ATTRIBUTE", ParticleAttribute, "Particle Attribute", "")
+DefNode(SimulationNode, SIM_NODE_AGE_REACHED_EVENT, 0, "AGE_REACHED_EVENT", AgeReachedEvent, "Age Reached Event", "")
+DefNode(SimulationNode, SIM_NODE_KILL_PARTICLE, 0, "KILL_PARTICLE", KillParticle, "Kill Particle", "")
DefNode(FunctionNode, FN_NODE_BOOLEAN_MATH, def_boolean_math, "BOOLEAN_MATH", BooleanMath, "Boolean Math", "")
DefNode(FunctionNode, FN_NODE_FLOAT_COMPARE, def_float_compare, "FLOAT_COMPARE", FloatCompare, "Float Compare", "")
@@ -277,7 +279,7 @@ DefNode(FunctionNode, FN_NODE_SWITCH, def_fn_switch, "SWITCH",
DefNode(FunctionNode, FN_NODE_GROUP_INSTANCE_ID, 0, "GROUP_INSTANCE_ID", GroupInstanceID, "Group Instance ID", "")
DefNode(FunctionNode, FN_NODE_COMBINE_STRINGS, 0, "COMBINE_STRINGS", CombineStrings, "Combine Strings", "")
DefNode(FunctionNode, FN_NODE_OBJECT_TRANSFORMS, 0, "OBJECT_TRANSFORMS", ObjectTransforms, "Object Transforms", "")
-
+DefNode(FunctionNode, FN_NODE_RANDOM_FLOAT, 0, "RANDOM_FLOAT", RandomFloat, "Random Float", "")
/* undefine macros */
diff --git a/source/blender/nodes/function/nodes/node_fn_random_float.cc b/source/blender/nodes/function/nodes/node_fn_random_float.cc
new file mode 100644
index 00000000000..2ee0830637a
--- /dev/null
+++ b/source/blender/nodes/function/nodes/node_fn_random_float.cc
@@ -0,0 +1,89 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "node_function_util.hh"
+
+#include "BLI_hash.h"
+
+static bNodeSocketTemplate fn_node_random_float_in[] = {
+ {SOCK_FLOAT, N_("Min"), 0.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f, PROP_NONE},
+ {SOCK_FLOAT, N_("Max"), 1.0f, 0.0f, 0.0f, 0.0f, -10000.0f, 10000.0f, PROP_NONE},
+ {SOCK_INT, N_("Seed")},
+ {-1, ""},
+};
+
+static bNodeSocketTemplate fn_node_random_float_out[] = {
+ {SOCK_FLOAT, N_("Value")},
+ {-1, ""},
+};
+
+class RandomFloatFunction : public blender::fn::MultiFunction {
+ private:
+ uint32_t function_seed_;
+
+ public:
+ RandomFloatFunction(uint32_t function_seed) : function_seed_(function_seed)
+ {
+ blender::fn::MFSignatureBuilder signature = this->get_builder("Random float");
+ signature.single_input<float>("Min");
+ signature.single_input<float>("Max");
+ signature.single_input<int>("Seed");
+ signature.single_output<float>("Value");
+ }
+
+ void call(blender::IndexMask mask,
+ blender::fn::MFParams params,
+ blender::fn::MFContext UNUSED(context)) const override
+ {
+ blender::fn::VSpan<float> min_values = params.readonly_single_input<float>(0, "Min");
+ blender::fn::VSpan<float> max_values = params.readonly_single_input<float>(1, "Max");
+ blender::fn::VSpan<int> seeds = params.readonly_single_input<int>(2, "Seed");
+ blender::MutableSpan<float> values = params.uninitialized_single_output<float>(3, "Value");
+
+ for (int64_t i : mask) {
+ const float min_value = min_values[i];
+ const float max_value = max_values[i];
+ const int seed = seeds[i];
+ const float value = BLI_hash_int_01((uint32_t)seed ^ function_seed_);
+ values[i] = value * (max_value - min_value) + min_value;
+ }
+ }
+};
+
+static void fn_node_random_float_expand_in_mf_network(
+ blender::nodes::NodeMFNetworkBuilder &builder)
+{
+ uint32_t function_seed = 1746872341u;
+ const blender::nodes::DNode &node = builder.dnode();
+ const blender::DefaultHash<blender::StringRefNull> hasher;
+ function_seed = 33 * function_seed + hasher(node.name());
+ for (const blender::nodes::DParentNode *parent = node.parent(); parent != nullptr;
+ parent = parent->parent()) {
+ function_seed = 33 * function_seed + hasher(parent->node_ref().name());
+ }
+
+ builder.construct_and_set_matching_fn<RandomFloatFunction>(function_seed);
+}
+
+void register_node_type_fn_random_float()
+{
+ static bNodeType ntype;
+
+ fn_node_type_base(&ntype, FN_NODE_RANDOM_FLOAT, "Random Float", 0, 0);
+ node_type_socket_templates(&ntype, fn_node_random_float_in, fn_node_random_float_out);
+ ntype.expand_in_mf_network = fn_node_random_float_expand_in_mf_network;
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/simulation/nodes/node_sim_age_reached_event.cc b/source/blender/nodes/simulation/nodes/node_sim_age_reached_event.cc
new file mode 100644
index 00000000000..add8c4eba4d
--- /dev/null
+++ b/source/blender/nodes/simulation/nodes/node_sim_age_reached_event.cc
@@ -0,0 +1,38 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "node_simulation_util.h"
+
+static bNodeSocketTemplate sim_node_age_reached_event_in[] = {
+ {SOCK_FLOAT, N_("Age"), 3, 0, 0, 0, 0, 10000000},
+ {SOCK_CONTROL_FLOW, N_("Execute")},
+ {-1, ""},
+};
+
+static bNodeSocketTemplate sim_node_age_reached_event_out[] = {
+ {SOCK_EVENTS, N_("Event")},
+ {-1, ""},
+};
+
+void register_node_type_sim_age_reached_event()
+{
+ static bNodeType ntype;
+
+ sim_node_type_base(&ntype, SIM_NODE_AGE_REACHED_EVENT, "Age Reached Event", 0, 0);
+ node_type_socket_templates(
+ &ntype, sim_node_age_reached_event_in, sim_node_age_reached_event_out);
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/simulation/nodes/node_sim_kill_particle.cc b/source/blender/nodes/simulation/nodes/node_sim_kill_particle.cc
new file mode 100644
index 00000000000..793b40d9365
--- /dev/null
+++ b/source/blender/nodes/simulation/nodes/node_sim_kill_particle.cc
@@ -0,0 +1,36 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "node_simulation_util.h"
+
+static bNodeSocketTemplate sim_node_kill_particle_in[] = {
+ {SOCK_CONTROL_FLOW, N_("Execute")},
+ {-1, ""},
+};
+
+static bNodeSocketTemplate sim_node_kill_particle_out[] = {
+ {SOCK_CONTROL_FLOW, N_("Execute")},
+ {-1, ""},
+};
+
+void register_node_type_sim_kill_particle()
+{
+ static bNodeType ntype;
+
+ sim_node_type_base(&ntype, SIM_NODE_KILL_PARTICLE, "Kill Particle", 0, 0);
+ node_type_socket_templates(&ntype, sim_node_kill_particle_in, sim_node_kill_particle_out);
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/simulation/nodes/node_sim_particle_mesh_emitter.cc b/source/blender/nodes/simulation/nodes/node_sim_particle_mesh_emitter.cc
index 859ad81656b..5e1a6c35d52 100644
--- a/source/blender/nodes/simulation/nodes/node_sim_particle_mesh_emitter.cc
+++ b/source/blender/nodes/simulation/nodes/node_sim_particle_mesh_emitter.cc
@@ -21,6 +21,7 @@
static bNodeSocketTemplate sim_node_particle_mesh_emitter_in[] = {
{SOCK_OBJECT, N_("Object")},
{SOCK_FLOAT, N_("Rate"), 100.0f, 0.0f, 0.0f, 0.0f, 0.0f, FLT_MAX},
+ {SOCK_CONTROL_FLOW, N_("Execute")},
{-1, ""},
};