Map Range Node (tiles)

this node allows for more control for normalization of the mapped input range.

Made during BlenderPRO 2012 - Brasilia, Brazil :)
Idea and testing: Daniel Salazar
Implementation: yours truly
Reviewed by Lukas Toenne and Sergey Sharybin
This commit is contained in:
Dalai Felinto 2012-11-14 19:53:46 +00:00
parent 71389d4d74
commit 7cfb79256e
15 changed files with 338 additions and 0 deletions

@ -706,6 +706,8 @@ void ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct GPUMateria
#define CMP_NODE_SWITCH 317
#define CMP_NODE_PIXELATE 318
#define CMP_NODE_MAP_RANGE 319
/* channel toggles */
#define CMP_CHAN_RGB 1
#define CMP_CHAN_A 2

@ -2184,6 +2184,7 @@ static void registerCompositNodes(bNodeTreeType *ttype)
register_node_type_cmp_normal(ttype);
register_node_type_cmp_curve_vec(ttype);
register_node_type_cmp_map_value(ttype);
register_node_type_cmp_map_range(ttype);
register_node_type_cmp_normalize(ttype);
register_node_type_cmp_filter(ttype);

@ -267,6 +267,8 @@ set(SRC
nodes/COM_MathNode.h
nodes/COM_MapValueNode.cpp
nodes/COM_MapValueNode.h
nodes/COM_MapRangeNode.cpp
nodes/COM_MapRangeNode.h
operations/COM_NormalizeOperation.cpp
operations/COM_NormalizeOperation.h
@ -572,6 +574,8 @@ set(SRC
operations/COM_SetAlphaOperation.h
operations/COM_MapValueOperation.cpp
operations/COM_MapValueOperation.h
operations/COM_MapRangeOperation.cpp
operations/COM_MapRangeOperation.h
# Distort operation
operations/COM_TranslateOperation.h

@ -83,6 +83,7 @@
#include "COM_LuminanceMatteNode.h"
#include "COM_MapUVNode.h"
#include "COM_MapValueNode.h"
#include "COM_MapRangeNode.h"
#include "COM_MaskNode.h"
#include "COM_MathNode.h"
#include "COM_MixNode.h"
@ -351,6 +352,9 @@ Node *Converter::convert(bNode *b_node, bool fast)
case CMP_NODE_MAP_VALUE:
node = new MapValueNode(b_node);
break;
case CMP_NODE_MAP_RANGE:
node = new MapRangeNode(b_node);
break;
case CMP_NODE_TRANSFORM:
node = new TransformNode(b_node);
break;

@ -0,0 +1,54 @@
/*
* Copyright 2012, Blender Foundation.
*
* 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.
*
* Contributor:
* Dalai Felinto
* Daniel Salazar
*/
#include "COM_MapRangeNode.h"
#include "COM_MapRangeOperation.h"
#include "COM_ExecutionSystem.h"
MapRangeNode::MapRangeNode(bNode *editorNode) : Node(editorNode)
{
/* pass */
}
void MapRangeNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context)
{
InputSocket *valueSocket = this->getInputSocket(0);
InputSocket *sourceMinSocket = this->getInputSocket(1);
InputSocket *sourceMaxSocket = this->getInputSocket(2);
InputSocket *destMinSocket = this->getInputSocket(3);
InputSocket *destMaxSocket = this->getInputSocket(4);
OutputSocket *outputSocket = this->getOutputSocket(0);
MapRangeOperation *operation = new MapRangeOperation();
valueSocket->relinkConnections(operation->getInputSocket(0), 0, graph);
sourceMinSocket->relinkConnections(operation->getInputSocket(1), 1, graph);
sourceMaxSocket->relinkConnections(operation->getInputSocket(2), 2, graph);
destMinSocket->relinkConnections(operation->getInputSocket(3), 3, graph);
destMaxSocket->relinkConnections(operation->getInputSocket(4), 4, graph);
outputSocket->relinkConnections(operation->getOutputSocket(0));
operation->setUseClamp(this->getbNode()->custom1);
graph->addOperation(operation);
}

@ -0,0 +1,38 @@
/*
* Copyright 2012, Blender Foundation.
*
* 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.
*
* Contributor:
* Dalai Felinto
* Daniel Salazar
*/
#ifndef __COM_MAPRANGENODE_H__
#define __COM_MAPRANGENODE_H__
#include "COM_Node.h"
#include "DNA_node_types.h"
/**
* @brief MapRangeNode
* @ingroup Node
*/
class MapRangeNode : public Node {
public:
MapRangeNode(bNode *editorNode);
void convertToOperations(ExecutionSystem *graph, CompositorContext *context);
};
#endif /* __COM_MAPRANGENODE_H__ */

@ -0,0 +1,81 @@
/*
* Copyright 2012, Blender Foundation.
*
* 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.
*
* Contributor:
* Dalai Felinto
* Daniel Salazar
*/
#include "COM_MapRangeOperation.h"
MapRangeOperation::MapRangeOperation() : NodeOperation()
{
this->addInputSocket(COM_DT_VALUE);
this->addInputSocket(COM_DT_VALUE);
this->addInputSocket(COM_DT_VALUE);
this->addInputSocket(COM_DT_VALUE);
this->addInputSocket(COM_DT_VALUE);
this->addOutputSocket(COM_DT_VALUE);
this->m_inputOperation = NULL;
this->m_useClamp = FALSE;
}
void MapRangeOperation::initExecution()
{
this->m_inputOperation = this->getInputSocketReader(0);
this->m_sourceMinOperation = this->getInputSocketReader(1);
this->m_sourceMaxOperation = this->getInputSocketReader(2);
this->m_destMinOperation = this->getInputSocketReader(3);
this->m_destMaxOperation = this->getInputSocketReader(4);
}
void MapRangeOperation::executePixel(float output[4], float x, float y, PixelSampler sampler)
{
float inputs[8]; /* includes the 5 inputs + 3 pads */
float value;
float source_min, source_max;
float dest_min, dest_max;
this->m_inputOperation->read(inputs, x, y, sampler);
this->m_sourceMinOperation->read(inputs+1, x, y, sampler);
this->m_sourceMaxOperation->read(inputs+2, x, y, sampler);
this->m_destMinOperation->read(inputs+3, x, y, sampler);
this->m_destMaxOperation->read(inputs+4, x, y, sampler);
value = inputs[0];
source_min = inputs[1];
source_max = inputs[2];
dest_min = inputs[3];
dest_max = inputs[4];
value = (value - source_min) / (source_max - source_min);
value = dest_min + value * (dest_max - dest_min);
if (this->m_useClamp)
CLAMP(value, dest_min, dest_max);
output[0] = value;
}
void MapRangeOperation::deinitExecution()
{
this->m_inputOperation = NULL;
this->m_sourceMinOperation = NULL;
this->m_sourceMaxOperation = NULL;
this->m_destMinOperation = NULL;
this->m_destMaxOperation = NULL;
}

@ -0,0 +1,71 @@
/*
* Copyright 2012, Blender Foundation.
*
* 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.
*
* Contributor:
* Dalai Felinto
* Daniel Salazar
*/
#ifndef _COM_MapRangeOperation_h
#define _COM_MapRangeOperation_h
#include "COM_NodeOperation.h"
#include "DNA_texture_types.h"
/**
* this program converts an input color to an output value.
* it assumes we are in sRGB color space.
*/
class MapRangeOperation : public NodeOperation {
private:
/**
* Cached reference to the inputProgram
*/
SocketReader *m_inputOperation;
SocketReader *m_sourceMinOperation;
SocketReader *m_sourceMaxOperation;
SocketReader *m_destMinOperation;
SocketReader *m_destMaxOperation;
bool m_useClamp;
public:
/**
* Default constructor
*/
MapRangeOperation();
/**
* the inner loop of this program
*/
void executePixel(float output[4], float x, float y, PixelSampler sampler);
/**
* Initialize the execution
*/
void initExecution();
/**
* Deinitialize the execution
*/
void deinitExecution();
/**
* Clamp the output
*/
void setUseClamp(bool value) { this->m_useClamp = value; }
};
#endif

@ -1887,6 +1887,14 @@ static void node_composit_buts_double_edge_mask(uiLayout *layout, bContext *UNUS
uiItemR(col, ptr, "edge_mode", 0, "", ICON_NONE);
}
static void node_composit_buts_map_range(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
uiLayout *col;
col = uiLayoutColumn(layout, TRUE);
uiItemR(col, ptr, "use_clamp", 0, NULL, ICON_NONE);
}
static void node_composit_buts_map_value(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
uiLayout *sub, *col;
@ -2825,6 +2833,9 @@ static void node_composit_set_butfunc(bNodeType *ntype)
case CMP_NODE_MAP_VALUE:
ntype->uifunc = node_composit_buts_map_value;
break;
case CMP_NODE_MAP_RANGE:
ntype->uifunc = node_composit_buts_map_range;
break;
case CMP_NODE_TIME:
ntype->uifunc = node_buts_time;
break;

@ -148,6 +148,7 @@ extern StructRNA RNA_CompositorNodeLevels;
extern StructRNA RNA_CompositorNodeLumaMatte;
extern StructRNA RNA_CompositorNodeMapUV;
extern StructRNA RNA_CompositorNodeMapValue;
extern StructRNA RNA_CompositorNodeMapRange;
extern StructRNA RNA_CompositorNodeMath;
extern StructRNA RNA_CompositorNodeMask;
extern StructRNA RNA_CompositorNodeMixRGB;

@ -2199,6 +2199,16 @@ static void def_cmp_map_value(StructRNA *srna)
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
}
static void def_cmp_map_range(StructRNA *srna)
{
PropertyRNA *prop;
prop = RNA_def_property(srna, "use_clamp", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "custom1", 1);
RNA_def_property_ui_text(prop, "Clamp", "Clamp result of the node to 0..1 range");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
}
static void def_cmp_vector_blur(StructRNA *srna)
{
PropertyRNA *prop;

@ -114,6 +114,7 @@ DefNode( CompositorNode, CMP_NODE_ALPHAOVER, def_cmp_alpha_over, "ALPHA
DefNode( CompositorNode, CMP_NODE_BLUR, def_cmp_blur, "BLUR", Blur, "Blur", "" )
DefNode( CompositorNode, CMP_NODE_FILTER, def_cmp_filter, "FILTER", Filter, "Filter", "" )
DefNode( CompositorNode, CMP_NODE_MAP_VALUE, def_cmp_map_value, "MAP_VALUE", MapValue, "Map Value", "" )
DefNode( CompositorNode, CMP_NODE_MAP_RANGE, def_cmp_map_range, "MAP_RANGE", MapRange, "Map Range", "" )
DefNode( CompositorNode, CMP_NODE_TIME, def_time, "TIME", Time, "Time", "" )
DefNode( CompositorNode, CMP_NODE_VECBLUR, def_cmp_vector_blur, "VECBLUR", VecBlur, "Vector Blur", "" )
DefNode( CompositorNode, CMP_NODE_SEPRGBA, 0, "SEPRGBA", SepRGBA, "Separate RGBA", "" )

@ -84,6 +84,7 @@ set(SRC
composite/nodes/node_composite_lummaMatte.c
composite/nodes/node_composite_mapUV.c
composite/nodes/node_composite_mapValue.c
composite/nodes/node_composite_mapRange.c
composite/nodes/node_composite_math.c
composite/nodes/node_composite_mask.c
composite/nodes/node_composite_mixrgb.c

@ -72,6 +72,7 @@ void register_node_type_cmp_huecorrect(struct bNodeTreeType *ttype);
void register_node_type_cmp_normal(struct bNodeTreeType *ttype);
void register_node_type_cmp_curve_vec(struct bNodeTreeType *ttype);
void register_node_type_cmp_map_value(struct bNodeTreeType *ttype);
void register_node_type_cmp_map_range(struct bNodeTreeType *ttype);
void register_node_type_cmp_normalize(struct bNodeTreeType *ttype);
void register_node_type_cmp_filter(struct bNodeTreeType *ttype);

@ -0,0 +1,58 @@
/*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* 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.
*
* The Original Code is Copyright (C) 2006 Blender Foundation.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/
/** \file blender/nodes/composite/nodes/node_composite_mapRange.c
* \ingroup cmpnodes
*/
#include "node_composite_util.h"
/* **************** MAP VALUE ******************** */
static bNodeSocketTemplate cmp_node_map_range_in[] = {
{ SOCK_FLOAT, 1, N_("Value"), 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, PROP_NONE},
{ SOCK_FLOAT, 1, N_("From Min"), 0.0f, 1.0f, 1.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE},
{ SOCK_FLOAT, 1, N_("From Max"), 1.0f, 1.0f, 1.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE},
{ SOCK_FLOAT, 1, N_("To Min"), 0.0f, 1.0f, 1.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE},
{ SOCK_FLOAT, 1, N_("To Max"), 1.0f, 1.0f, 1.0f, 1.0f, -10000.0f, 10000.0f, PROP_NONE},
{ -1, 0, "" }
};
static bNodeSocketTemplate cmp_node_map_range_out[] = {
{ SOCK_FLOAT, 0, N_("Value")},
{ -1, 0, "" }
};
void register_node_type_cmp_map_range(bNodeTreeType *ttype)
{
static bNodeType ntype;
node_type_base(ttype, &ntype, CMP_NODE_MAP_RANGE, "Map Range", NODE_CLASS_OP_VECTOR, NODE_OPTIONS);
node_type_socket_templates(&ntype, cmp_node_map_range_in, cmp_node_map_range_out);
node_type_size(&ntype, 120, 60, 150);
nodeRegisterType(ttype, &ntype);
}