[Bf-blender-cvs] [99e5f16d4a5] functions: new Separate Color node
Jacques Lucke
noreply at git.blender.org
Tue Jul 30 13:27:54 CEST 2019
Commit: 99e5f16d4a57220c557cbcbb38cf9190ddfa84e9
Author: Jacques Lucke
Date: Tue Jul 30 12:01:33 2019 +0200
Branches: functions
https://developer.blender.org/rB99e5f16d4a57220c557cbcbb38cf9190ddfa84e9
new Separate Color node
===================================================================
A release/scripts/startup/nodes/function_nodes/separate_color.py
M source/blender/functions/CMakeLists.txt
M source/blender/functions/FN_functions.hpp
M source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
A source/blender/functions/functions/color.cpp
A source/blender/functions/functions/color.hpp
A source/blender/functions/functions/constants.cpp
A source/blender/functions/functions/constants.hpp
M source/blender/functions/functions/scalar_math.cpp
M source/blender/functions/functions/scalar_math.hpp
M source/blender/functions/functions/vectors.cpp
M source/blender/functions/functions/vectors.hpp
===================================================================
diff --git a/release/scripts/startup/nodes/function_nodes/separate_color.py b/release/scripts/startup/nodes/function_nodes/separate_color.py
new file mode 100644
index 00000000000..4fa675eaf99
--- /dev/null
+++ b/release/scripts/startup/nodes/function_nodes/separate_color.py
@@ -0,0 +1,27 @@
+import bpy
+from .. base import FunctionNode
+from .. node_builder import NodeBuilder
+
+class SeparateColorNode(bpy.types.Node, FunctionNode):
+ bl_idname = "fn_SeparateColorNode"
+ bl_label = "Separate Color"
+
+ use_list__color: NodeBuilder.VectorizedProperty()
+
+ def declaration(self, builder: NodeBuilder):
+ builder.vectorized_input(
+ "color", "use_list__color",
+ "Color", "Colors", "Color")
+
+ builder.vectorized_output(
+ "red", ["use_list__color"],
+ "Red", "Red", "Float")
+ builder.vectorized_output(
+ "green", ["use_list__color"],
+ "Green", "Green", "Float")
+ builder.vectorized_output(
+ "blue", ["use_list__color"],
+ "Blue", "Blue", "Float")
+ builder.vectorized_output(
+ "alpha", ["use_list__color"],
+ "Alpha", "Alpha", "Float")
diff --git a/source/blender/functions/CMakeLists.txt b/source/blender/functions/CMakeLists.txt
index b97a6677060..2378765dfc1 100644
--- a/source/blender/functions/CMakeLists.txt
+++ b/source/blender/functions/CMakeLists.txt
@@ -132,6 +132,10 @@ set(SRC
functions/ranges.cpp
functions/comparisons.hpp
functions/comparisons.cpp
+ functions/constants.hpp
+ functions/constants.cpp
+ functions/color.hpp
+ functions/color.cpp
frontends/data_flow_nodes/builder.hpp
frontends/data_flow_nodes/builder.cpp
diff --git a/source/blender/functions/FN_functions.hpp b/source/blender/functions/FN_functions.hpp
index 6efb2675d94..35c5cce64e8 100644
--- a/source/blender/functions/FN_functions.hpp
+++ b/source/blender/functions/FN_functions.hpp
@@ -10,3 +10,5 @@
#include "functions/auto_vectorization.hpp"
#include "functions/ranges.hpp"
#include "functions/comparisons.hpp"
+#include "functions/constants.hpp"
+#include "functions/color.hpp"
diff --git a/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp b/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
index a62d0950049..3a3d7ea1904 100644
--- a/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
+++ b/source/blender/functions/frontends/data_flow_nodes/inserters/nodes.cpp
@@ -260,6 +260,16 @@ static void INSERT_separate_vector(BTreeGraphBuilder &builder, VirtualNode *vnod
builder.insert_matching_function(fn, vnode);
}
+static void INSERT_separate_color(BTreeGraphBuilder &builder, VirtualNode *vnode)
+{
+ PointerRNA rna = vnode->rna();
+ SharedFunction fn = get_vectorized_function(
+ Functions::GET_FN_separate_color(),
+ rna,
+ {{"use_list__color", Functions::GET_FN_output_magenta()}});
+ builder.insert_matching_function(fn, vnode);
+}
+
static SharedFunction &get_compare_function(int operation)
{
switch (operation) {
@@ -303,6 +313,7 @@ void register_node_inserters(GraphInserters &inserters)
inserters.reg_node_inserter("fn_SwitchNode", INSERT_switch);
inserters.reg_node_inserter("fn_ListLengthNode", INSERT_list_length);
inserters.reg_node_inserter("fn_CompareNode", INSERT_compare);
+ inserters.reg_node_inserter("fn_SeparateColorNode", INSERT_separate_color);
}
} // namespace DataFlowNodes
diff --git a/source/blender/functions/functions/color.cpp b/source/blender/functions/functions/color.cpp
new file mode 100644
index 00000000000..4ab223fd5a6
--- /dev/null
+++ b/source/blender/functions/functions/color.cpp
@@ -0,0 +1,38 @@
+#include "FN_tuple_call.hpp"
+#include "FN_types.hpp"
+#include "BLI_lazy_init.hpp"
+
+#include "color.hpp"
+
+namespace FN {
+namespace Functions {
+
+using namespace Types;
+
+class SeparateColor : public TupleCallBody {
+ void call(Tuple &fn_in, Tuple &fn_out, ExecutionContext &UNUSED(ctx)) const override
+ {
+ rgba_f color = this->get_input<rgba_f>(fn_in, 0, "Color");
+ this->set_output<float>(fn_out, 0, "Red", color.r);
+ this->set_output<float>(fn_out, 1, "Green", color.g);
+ this->set_output<float>(fn_out, 2, "Blue", color.b);
+ this->set_output<float>(fn_out, 3, "Alpha", color.a);
+ }
+};
+
+BLI_LAZY_INIT(SharedFunction, GET_FN_separate_color)
+{
+ FunctionBuilder fn_builder;
+ fn_builder.add_input("Color", GET_TYPE_rgba_f());
+ fn_builder.add_output("Red", GET_TYPE_float());
+ fn_builder.add_output("Green", GET_TYPE_float());
+ fn_builder.add_output("Blue", GET_TYPE_float());
+ fn_builder.add_output("Alpha", GET_TYPE_float());
+
+ auto fn = fn_builder.build("Separate Color");
+ fn->add_body<SeparateColor>();
+ return fn;
+}
+
+} // namespace Functions
+} // namespace FN
diff --git a/source/blender/functions/functions/color.hpp b/source/blender/functions/functions/color.hpp
new file mode 100644
index 00000000000..23041e064c8
--- /dev/null
+++ b/source/blender/functions/functions/color.hpp
@@ -0,0 +1,11 @@
+#pragma once
+
+#include "FN_core.hpp"
+
+namespace FN {
+namespace Functions {
+
+SharedFunction &GET_FN_separate_color();
+
+} // namespace Functions
+}; // namespace FN
diff --git a/source/blender/functions/functions/constants.cpp b/source/blender/functions/functions/constants.cpp
new file mode 100644
index 00000000000..0a7dc84851b
--- /dev/null
+++ b/source/blender/functions/functions/constants.cpp
@@ -0,0 +1,203 @@
+#include "FN_tuple_call.hpp"
+#include "FN_llvm.hpp"
+#include "FN_types.hpp"
+#include "BLI_lazy_init.hpp"
+
+#include "constants.hpp"
+
+namespace FN {
+namespace Functions {
+
+using namespace Types;
+
+template<typename T> class ConstValue : public TupleCallBody {
+ private:
+ T m_value;
+
+ public:
+ ConstValue(T value) : m_value(value)
+ {
+ }
+
+ void call(Tuple &UNUSED(fn_in), Tuple &fn_out, ExecutionContext &UNUSED(ctx)) const override
+ {
+ fn_out.set<T>(0, m_value);
+ }
+};
+
+class ConstInt32Gen : public LLVMBuildIRBody {
+ private:
+ int32_t m_value;
+
+ public:
+ ConstInt32Gen(int32_t value) : m_value(value)
+ {
+ }
+
+ void build_ir(CodeBuilder &builder,
+ CodeInterface &interface,
+ const BuildIRSettings &UNUSED(settings)) const override
+ {
+ llvm::Value *constant = builder.getInt32(m_value);
+ interface.set_output(0, constant);
+ }
+};
+
+class ConstFloatGen : public LLVMBuildIRBody {
+ private:
+ float m_value;
+
+ public:
+ ConstFloatGen(float value) : m_value(value)
+ {
+ }
+
+ void build_ir(CodeBuilder &builder,
+ CodeInterface &interface,
+ const BuildIRSettings &UNUSED(settings)) const override
+ {
+ llvm::Value *constant = builder.getFloat(m_value);
+ interface.set_output(0, constant);
+ }
+};
+
+class ConstBoolGen : public LLVMBuildIRBody {
+ private:
+ bool m_value;
+
+ public:
+ ConstBoolGen(bool value) : m_value(value)
+ {
+ }
+
+ void build_ir(CodeBuilder &builder,
+ CodeInterface &interface,
+ const BuildIRSettings &UNUSED(settings)) const override
+ {
+ llvm::Value *constant = builder.getInt1(m_value);
+ interface.set_output(0, constant);
+ }
+};
+
+static SharedFunction get_output_int32_function(int32_t value)
+{
+ FunctionBuilder builder;
+ builder.add_output("Value", GET_TYPE_int32());
+ auto fn = builder.build("Build Value: " + std::to_string(value));
+ fn->add_body<ConstValue<int32_t>>(value);
+ fn->add_body<ConstInt32Gen>(value);
+ return fn;
+}
+
+BLI_LAZY_INIT(SharedFunction, GET_FN_output_int32_0)
+{
+ return get_output_int32_function(0);
+}
+
+BLI_LAZY_INIT(SharedFunction, GET_FN_output_int32_1)
+{
+ return get_output_int32_function(1);
+}
+
+static SharedFunction get_output_float_function(float value)
+{
+ FunctionBuilder builder;
+ builder.add_output("Value", GET_TYPE_float());
+ auto fn = builder.build("Build Value: " + std::to_string(value));
+ fn->add_body<ConstValue<float>>(value);
+ fn->add_body<ConstFloatGen>(value);
+ return fn;
+}
+
+BLI_LAZY_INIT(SharedFunction, GET_FN_output_float_0)
+{
+ return get_output_float_function(0.0f);
+}
+
+BLI_LAZY_INIT(SharedFunction, GET_FN_output_float_1)
+{
+ return get_output_float_function(1.0f);
+}
+
+static SharedFunction get_output_bool_function(bool value)
+{
+ FunctionBuilder builder;
+ builder.add_output("Value", GET_TYPE_bool());
+ auto fn = builder.build("Build Value");
+ fn->add_body<ConstValue<bool>>(value);
+ fn->add_body<ConstBoolGen>(value);
+ return fn;
+}
+
+BLI_LAZY_INIT(SharedFunction, GET_FN_output_false)
+{
+ return get_output_bool_function(false);
+}
+
+BLI_LAZY_INIT(SharedFunction, GET_FN_output_true)
+{
+ return get_output_bool_function(true);
+}
+
+template<uint N> class ConstFloatArrayGen : public LLVMBuildIRBody {
+ private:
+ std::array<float, N> m_array;
+ LLVMTypeInfo &m_type_info;
+
+ public:
+ ConstFloatArrayGen(std::array<float, N> array, LLVMTypeInfo &type_info)
+ : m_array(array), m_type_info(type_info)
+ {
+ }
+
+ void build_ir(CodeBuilder &builder,
+ CodeInterface &interface,
+ const BuildIRSettings &UNUSED(settings)) const override
+ {
+ llvm::Value *output = builder.getUndef(m_type_info.get_type(builder.getContext()));
+ for (uint i = 0; i < N; i++) {
+ output = builder.CreateInsertElement(output, builder.getFloat(m_array[i]), i);
+ }
+ interface.set_output(0, output);
+ }
+};
+
+static SharedFunction get_output_float3_function(float3 vector)
+{
+ FunctionBuilder builder;
+ auto &float3_type = GET_TYPE_float3();
+ builder.add_output("Vector", float3_type);
+ auto fn = builder.build("Build Vector");
+ fn->add_body<ConstValue<float3>>(vector);
+ fn->add_body<ConstFloatArrayGen<3>>(vector, float3_type->extension<LLVMTypeInfo>());
+ return fn;
+}
+
+BLI_LAZY_INIT(SharedFunction, GET_FN_output_float3_0)
+{
+ return get_output_float3_function(float3(0, 0, 0));
+}
+
+BLI_LAZY_INIT(SharedFunction, GET_FN_output_float3_1)
+{
+ return get_output_float3_function(float3(1, 1, 1));
+}
+
+static SharedFunction get_output_rgba_f_function(rgba_f color)
+{
+ FunctionBuilder builder;
+ auto &rgba_
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list