Refactor: Move common code into small functions
This commit is contained in:
@@ -50,6 +50,11 @@ static void node_composit_buts_brightcontrast(uiLayout *layout, bContext * /*C*/
|
||||
|
||||
using namespace blender::realtime_compositor;
|
||||
|
||||
static bool get_use_premultiply(const bNode &node)
|
||||
{
|
||||
return node.custom1;
|
||||
}
|
||||
|
||||
class BrightContrastShaderNode : public ShaderNode {
|
||||
public:
|
||||
using ShaderNode::ShaderNode;
|
||||
@@ -59,7 +64,7 @@ class BrightContrastShaderNode : public ShaderNode {
|
||||
GPUNodeStack *inputs = get_inputs_array();
|
||||
GPUNodeStack *outputs = get_outputs_array();
|
||||
|
||||
const float use_premultiply = get_use_premultiply();
|
||||
const float use_premultiply = get_use_premultiply(bnode());
|
||||
|
||||
GPU_stack_link(material,
|
||||
&bnode(),
|
||||
@@ -68,11 +73,6 @@ class BrightContrastShaderNode : public ShaderNode {
|
||||
outputs,
|
||||
GPU_constant(&use_premultiply));
|
||||
}
|
||||
|
||||
bool get_use_premultiply()
|
||||
{
|
||||
return bnode().custom1;
|
||||
}
|
||||
};
|
||||
|
||||
static ShaderNode *get_compositor_shader_node(DNode node)
|
||||
@@ -131,7 +131,7 @@ static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &
|
||||
},
|
||||
mf::build::exec_presets::SomeSpanOrSingle<0>());
|
||||
|
||||
const bool use_premultiply = builder.node().custom1;
|
||||
const bool use_premultiply = get_use_premultiply(builder.node());
|
||||
if (use_premultiply) {
|
||||
builder.set_matching_fn(premultiply_used_function);
|
||||
}
|
||||
|
||||
@@ -65,6 +65,11 @@ static void node_composit_buts_map_range(uiLayout *layout, bContext * /*C*/, Poi
|
||||
|
||||
using namespace blender::realtime_compositor;
|
||||
|
||||
static bool get_should_clamp(const bNode &node)
|
||||
{
|
||||
return node.custom1;
|
||||
}
|
||||
|
||||
class MapRangeShaderNode : public ShaderNode {
|
||||
public:
|
||||
using ShaderNode::ShaderNode;
|
||||
@@ -74,7 +79,7 @@ class MapRangeShaderNode : public ShaderNode {
|
||||
GPUNodeStack *inputs = get_inputs_array();
|
||||
GPUNodeStack *outputs = get_outputs_array();
|
||||
|
||||
const float should_clamp = get_should_clamp();
|
||||
const float should_clamp = get_should_clamp(bnode());
|
||||
|
||||
GPU_stack_link(material,
|
||||
&bnode(),
|
||||
@@ -83,11 +88,6 @@ class MapRangeShaderNode : public ShaderNode {
|
||||
outputs,
|
||||
GPU_constant(&should_clamp));
|
||||
}
|
||||
|
||||
bool get_should_clamp()
|
||||
{
|
||||
return bnode().custom1;
|
||||
}
|
||||
};
|
||||
|
||||
static ShaderNode *get_compositor_shader_node(DNode node)
|
||||
@@ -158,7 +158,7 @@ static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &
|
||||
},
|
||||
mf::build::exec_presets::SomeSpanOrSingle<0>());
|
||||
|
||||
const bool should_clamp = builder.node().custom1;
|
||||
const bool should_clamp = get_should_clamp(builder.node());
|
||||
if (should_clamp) {
|
||||
builder.set_matching_fn(clamp_function);
|
||||
}
|
||||
|
||||
@@ -67,6 +67,16 @@ static void node_composit_buts_map_value(uiLayout *layout, bContext * /*C*/, Poi
|
||||
|
||||
using namespace blender::realtime_compositor;
|
||||
|
||||
static bool get_use_min(const bNode &node)
|
||||
{
|
||||
return node_storage(node).flag & TEXMAP_CLIP_MIN;
|
||||
}
|
||||
|
||||
static bool get_use_max(const bNode &node)
|
||||
{
|
||||
return node_storage(node).flag & TEXMAP_CLIP_MAX;
|
||||
}
|
||||
|
||||
class MapValueShaderNode : public ShaderNode {
|
||||
public:
|
||||
using ShaderNode::ShaderNode;
|
||||
@@ -78,8 +88,8 @@ class MapValueShaderNode : public ShaderNode {
|
||||
|
||||
const TexMapping &texture_mapping = node_storage(bnode());
|
||||
|
||||
const float use_min = get_use_min();
|
||||
const float use_max = get_use_max();
|
||||
const float use_min = get_use_min(bnode());
|
||||
const float use_max = get_use_max(bnode());
|
||||
|
||||
GPU_stack_link(material,
|
||||
&bnode(),
|
||||
@@ -93,16 +103,6 @@ class MapValueShaderNode : public ShaderNode {
|
||||
GPU_constant(&use_max),
|
||||
GPU_uniform(texture_mapping.max));
|
||||
}
|
||||
|
||||
bool get_use_min()
|
||||
{
|
||||
return node_storage(bnode()).flag & TEXMAP_CLIP_MIN;
|
||||
}
|
||||
|
||||
bool get_use_max()
|
||||
{
|
||||
return node_storage(bnode()).flag & TEXMAP_CLIP_MAX;
|
||||
}
|
||||
};
|
||||
|
||||
static ShaderNode *get_compositor_shader_node(DNode node)
|
||||
@@ -138,8 +138,8 @@ static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &
|
||||
const float size = texture_mapping.size[0];
|
||||
const float min = texture_mapping.min[0];
|
||||
const float max = texture_mapping.max[0];
|
||||
const bool use_min = texture_mapping.flag & TEXMAP_CLIP_MIN;
|
||||
const bool use_max = texture_mapping.flag & TEXMAP_CLIP_MAX;
|
||||
const bool use_min = get_use_min(builder.node());
|
||||
const bool use_max = get_use_max(builder.node());
|
||||
|
||||
if (use_min) {
|
||||
if (use_max) {
|
||||
|
||||
@@ -41,6 +41,14 @@ static void cmp_node_normal_declare(NodeDeclarationBuilder &b)
|
||||
|
||||
using namespace blender::realtime_compositor;
|
||||
|
||||
/* The vector value is stored in the default value of the output socket. */
|
||||
static float3 get_vector_value(const bNode &node)
|
||||
{
|
||||
const bNodeSocket &normal_output = node.output_by_identifier("Normal");
|
||||
const float3 node_normal = normal_output.default_value_typed<bNodeSocketValueVector>()->value;
|
||||
return math::normalize(node_normal);
|
||||
}
|
||||
|
||||
class NormalShaderNode : public ShaderNode {
|
||||
public:
|
||||
using ShaderNode::ShaderNode;
|
||||
@@ -55,16 +63,7 @@ class NormalShaderNode : public ShaderNode {
|
||||
"node_composite_normal",
|
||||
inputs,
|
||||
outputs,
|
||||
GPU_uniform(get_vector_value()));
|
||||
}
|
||||
|
||||
/* The vector value is stored in the default value of the output socket. */
|
||||
const float *get_vector_value()
|
||||
{
|
||||
return node()
|
||||
.output_by_identifier("Normal")
|
||||
->default_value_typed<bNodeSocketValueVector>()
|
||||
->value;
|
||||
GPU_uniform(get_vector_value(bnode())));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -75,9 +74,7 @@ static ShaderNode *get_compositor_shader_node(DNode node)
|
||||
|
||||
static void node_build_multi_function(blender::nodes::NodeMultiFunctionBuilder &builder)
|
||||
{
|
||||
const bNodeSocket &normal_output = builder.node().output_by_identifier("Normal");
|
||||
const float3 node_normal = normal_output.default_value_typed<bNodeSocketValueVector>()->value;
|
||||
const float3 normalized_node_normal = math::normalize(node_normal);
|
||||
const float3 normalized_node_normal = get_vector_value(builder.node());
|
||||
|
||||
builder.construct_and_set_matching_fn_cb([=]() {
|
||||
return mf::build::SI1_SO2<float4, float4, float>(
|
||||
|
||||
Reference in New Issue
Block a user