Mango request: option to clamp result of Mix RGB and Color Math nodes

---
Merging r48792 from soc-2011-tomato into trunk
This commit is contained in:
Sergey Sharybin 2012-07-10 10:36:18 +00:00
commit 5b57f38fb5
27 changed files with 125 additions and 6 deletions

@ -83,10 +83,14 @@ void MathNode::convertToOperations(ExecutionSystem *graph, CompositorContext *co
}
if (operation != NULL) {
bool useClamp = this->getbNode()->custom2;
this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph);
this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), 1, graph);
this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket());
operation->setUseClamp(useClamp);
graph->addOperation(operation);
}
}

@ -58,6 +58,8 @@ void MixNode::convertToOperations(ExecutionSystem *graph, CompositorContext *con
InputSocket *color2Socket = this->getInputSocket(2);
OutputSocket *outputSocket = this->getOutputSocket(0);
bNode *editorNode = this->getbNode();
bool useAlphaPremultiply = this->getbNode()->custom2 & 1;
bool useClamp = this->getbNode()->custom2 & 2;
MixBaseOperation *convertProg;
@ -119,7 +121,8 @@ void MixNode::convertToOperations(ExecutionSystem *graph, CompositorContext *con
convertProg = new MixBlendOperation();
break;
}
convertProg->setUseValueAlphaMultiply(this->getbNode()->custom2);
convertProg->setUseValueAlphaMultiply(useAlphaPremultiply);
convertProg->setUseClamp(useClamp);
valueSocket->relinkConnections(convertProg->getInputSocket(0), 0, graph);
color1Socket->relinkConnections(convertProg->getInputSocket(1), 1, graph);

@ -64,6 +64,13 @@ void MathBaseOperation::determineResolution(unsigned int resolution[], unsigned
NodeOperation::determineResolution(resolution, preferredResolution);
}
void MathBaseOperation::clampIfNeeded(float *color)
{
if (this->m_useClamp) {
CLAMP(color[0], 0.0f, 1.0f);
}
}
void MathAddOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
{
float inputValue1[4];
@ -73,6 +80,8 @@ void MathAddOperation::executePixel(float *outputValue, float x, float y, PixelS
this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers);
outputValue[0] = inputValue1[0] + inputValue2[0];
clampIfNeeded(outputValue);
}
void MathSubtractOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
@ -84,6 +93,8 @@ void MathSubtractOperation::executePixel(float *outputValue, float x, float y, P
this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers);
outputValue[0] = inputValue1[0] - inputValue2[0];
clampIfNeeded(outputValue);
}
void MathMultiplyOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
@ -95,6 +106,8 @@ void MathMultiplyOperation::executePixel(float *outputValue, float x, float y, P
this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers);
outputValue[0] = inputValue1[0] * inputValue2[0];
clampIfNeeded(outputValue);
}
void MathDivideOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
@ -109,6 +122,8 @@ void MathDivideOperation::executePixel(float *outputValue, float x, float y, Pix
outputValue[0] = 0.0;
else
outputValue[0] = inputValue1[0] / inputValue2[0];
clampIfNeeded(outputValue);
}
void MathSineOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
@ -120,6 +135,8 @@ void MathSineOperation::executePixel(float *outputValue, float x, float y, Pixel
this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers);
outputValue[0] = sin(inputValue1[0]);
clampIfNeeded(outputValue);
}
void MathCosineOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
@ -131,6 +148,8 @@ void MathCosineOperation::executePixel(float *outputValue, float x, float y, Pix
this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers);
outputValue[0] = cos(inputValue1[0]);
clampIfNeeded(outputValue);
}
void MathTangentOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
@ -142,6 +161,8 @@ void MathTangentOperation::executePixel(float *outputValue, float x, float y, Pi
this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers);
outputValue[0] = tan(inputValue1[0]);
clampIfNeeded(outputValue);
}
void MathArcSineOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
@ -156,6 +177,8 @@ void MathArcSineOperation::executePixel(float *outputValue, float x, float y, Pi
outputValue[0] = asin(inputValue1[0]);
else
outputValue[0] = 0.0;
clampIfNeeded(outputValue);
}
void MathArcCosineOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
@ -170,6 +193,8 @@ void MathArcCosineOperation::executePixel(float *outputValue, float x, float y,
outputValue[0] = acos(inputValue1[0]);
else
outputValue[0] = 0.0;
clampIfNeeded(outputValue);
}
void MathArcTangentOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
@ -181,6 +206,8 @@ void MathArcTangentOperation::executePixel(float *outputValue, float x, float y,
this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers);
outputValue[0] = atan(inputValue1[0]);
clampIfNeeded(outputValue);
}
void MathPowerOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
@ -204,6 +231,8 @@ void MathPowerOperation::executePixel(float *outputValue, float x, float y, Pixe
outputValue[0] = 0.0;
}
}
clampIfNeeded(outputValue);
}
void MathLogarithmOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
@ -218,6 +247,8 @@ void MathLogarithmOperation::executePixel(float *outputValue, float x, float y,
outputValue[0] = log(inputValue1[0]) / log(inputValue2[0]);
else
outputValue[0] = 0.0;
clampIfNeeded(outputValue);
}
void MathMinimumOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
@ -229,6 +260,8 @@ void MathMinimumOperation::executePixel(float *outputValue, float x, float y, Pi
this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers);
outputValue[0] = min(inputValue1[0], inputValue2[0]);
clampIfNeeded(outputValue);
}
void MathMaximumOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
@ -240,6 +273,8 @@ void MathMaximumOperation::executePixel(float *outputValue, float x, float y, Pi
this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers);
outputValue[0] = max(inputValue1[0], inputValue2[0]);
clampIfNeeded(outputValue);
}
void MathRoundOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
@ -251,6 +286,8 @@ void MathRoundOperation::executePixel(float *outputValue, float x, float y, Pixe
this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers);
outputValue[0] = round(inputValue1[0]);
clampIfNeeded(outputValue);
}
void MathLessThanOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
@ -262,6 +299,8 @@ void MathLessThanOperation::executePixel(float *outputValue, float x, float y, P
this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers);
outputValue[0] = inputValue1[0] < inputValue2[0] ? 1.0f : 0.0f;
clampIfNeeded(outputValue);
}
void MathGreaterThanOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[])
@ -273,6 +312,8 @@ void MathGreaterThanOperation::executePixel(float *outputValue, float x, float y
this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers);
outputValue[0] = inputValue1[0] > inputValue2[0] ? 1.0f : 0.0f;
clampIfNeeded(outputValue);
}

@ -37,11 +37,15 @@ protected:
SocketReader *m_inputValue1Operation;
SocketReader *m_inputValue2Operation;
bool m_useClamp;
protected:
/**
* Default constructor
*/
MathBaseOperation();
void clampIfNeeded(float *color);
public:
/**
* the inner loop of this program
@ -62,6 +66,8 @@ public:
* Determine resolution
*/
void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]);
void setUseClamp(bool value) { this->m_useClamp = value; }
};
class MathAddOperation : public MathBaseOperation {

@ -46,5 +46,7 @@ void MixAddOperation::executePixel(float *outputValue, float x, float y, PixelSa
outputValue[1] = inputColor1[1] + value * inputColor2[1];
outputValue[2] = inputColor1[2] + value * inputColor2[2];
outputValue[3] = inputColor1[3];
clampIfNeeded(outputValue);
}

@ -94,3 +94,12 @@ void MixBaseOperation::determineResolution(unsigned int resolution[], unsigned i
NodeOperation::determineResolution(resolution, preferredResolution);
}
void MixBaseOperation::clampIfNeeded(float *color)
{
if (this->m_useClamp) {
CLAMP(color[0], 0.0f, 1.0f);
CLAMP(color[1], 0.0f, 1.0f);
CLAMP(color[2], 0.0f, 1.0f);
CLAMP(color[3], 0.0f, 1.0f);
}
}

@ -38,6 +38,9 @@ protected:
SocketReader *m_inputColor1Operation;
SocketReader *m_inputColor2Operation;
bool m_valueAlphaMultiply;
bool m_useClamp;
void clampIfNeeded(float *color);
public:
/**
* Default constructor
@ -63,5 +66,6 @@ public:
void setUseValueAlphaMultiply(const bool value) { this->m_valueAlphaMultiply = value; }
bool useValueAlphaMultiply() { return this->m_valueAlphaMultiply; }
void setUseClamp(bool value) { this->m_useClamp = value; }
};
#endif

@ -47,4 +47,6 @@ void MixBlendOperation::executePixel(float *outputValue, float x, float y, Pixel
outputValue[1] = valuem * (inputColor1[1]) + value * (inputColor2[1]);
outputValue[2] = valuem * (inputColor1[2]) + value * (inputColor2[2]);
outputValue[3] = inputColor1[3];
clampIfNeeded(outputValue);
}

@ -83,5 +83,7 @@ void MixBurnOperation::executePixel(float *outputValue, float x, float y, PixelS
}
outputValue[3] = inputColor1[3];
clampIfNeeded(outputValue);
}

@ -58,5 +58,7 @@ void MixColorOperation::executePixel(float *outputValue, float x, float y, Pixel
outputValue[2] = valuem * (inputColor1[2]) + value * tmpb;
}
outputValue[3] = inputColor1[3];
clampIfNeeded(outputValue);
}

@ -53,5 +53,7 @@ void MixDarkenOperation::executePixel(float *outputValue, float x, float y, Pixe
else outputValue[2] = inputColor1[2];
outputValue[3] = inputColor1[3];
clampIfNeeded(outputValue);
}

@ -46,5 +46,7 @@ void MixDifferenceOperation::executePixel(float *outputValue, float x, float y,
outputValue[1] = valuem * inputColor1[1] + value *fabsf(inputColor1[1] - inputColor2[1]);
outputValue[2] = valuem * inputColor1[2] + value *fabsf(inputColor1[2] - inputColor2[2]);
outputValue[3] = inputColor1[3];
clampIfNeeded(outputValue);
}

@ -56,5 +56,7 @@ void MixDivideOperation::executePixel(float *outputValue, float x, float y, Pixe
outputValue[2] = 0.0f;
outputValue[3] = inputColor1[3];
clampIfNeeded(outputValue);
}

@ -88,5 +88,7 @@ void MixDodgeOperation::executePixel(float *outputValue, float x, float y, Pixel
outputValue[2] = 0.0f;
outputValue[3] = inputColor1[3];
clampIfNeeded(outputValue);
}

@ -44,4 +44,6 @@ void MixGlareOperation::executePixel(float *outputValue, float x, float y, Pixel
outputValue[1] = mf * ((inputColor1[1]) + value * (inputColor2[1] - inputColor1[1]));
outputValue[2] = mf * ((inputColor1[2]) + value * (inputColor2[2] - inputColor1[2]));
outputValue[3] = inputColor1[3];
clampIfNeeded(outputValue);
}

@ -58,4 +58,6 @@ void MixHueOperation::executePixel(float *outputValue, float x, float y, PixelSa
outputValue[2] = valuem * (inputColor1[2]) + value * tmpb;
}
outputValue[3] = inputColor1[3];
clampIfNeeded(outputValue);
}

@ -51,5 +51,7 @@ void MixLightenOperation::executePixel(float *outputValue, float x, float y, Pix
if (tmp > inputColor1[2]) outputValue[2] = tmp;
else outputValue[2] = inputColor1[2];
outputValue[3] = inputColor1[3];
clampIfNeeded(outputValue);
}

@ -54,4 +54,6 @@ void MixLinearLightOperation::executePixel(float *outputValue, float x, float y,
outputValue[2] = inputColor1[2] + value * (2.0f * (inputColor2[2]) - 1.0f);
outputValue[3] = inputColor1[3];
clampIfNeeded(outputValue);
}

@ -46,5 +46,7 @@ void MixMultiplyOperation::executePixel(float *outputValue, float x, float y, Pi
outputValue[1] = inputColor1[1] * (valuem + value * inputColor2[1]);
outputValue[2] = inputColor1[2] * (valuem + value * inputColor2[2]);
outputValue[3] = inputColor1[3];
clampIfNeeded(outputValue);
}

@ -62,5 +62,7 @@ void MixOverlayOperation::executePixel(float *outputValue, float x, float y, Pix
outputValue[2] = 1.0f - (valuem + 2.0f * value * (1.0f - inputColor2[2])) * (1.0f - inputColor1[2]);
}
outputValue[3] = inputColor1[3];
clampIfNeeded(outputValue);
}

@ -54,4 +54,6 @@ void MixSaturationOperation::executePixel(float *outputValue, float x, float y,
hsv_to_rgb(rH, (valuem * rS + value * colS), rV, &outputValue[0], &outputValue[1], &outputValue[2]);
}
outputValue[3] = inputColor1[3];
clampIfNeeded(outputValue);
}

@ -47,5 +47,7 @@ void MixScreenOperation::executePixel(float *outputValue, float x, float y, Pixe
outputValue[1] = 1.0f - (valuem + value * (1.0f - inputColor2[1])) * (1.0f - inputColor1[1]);
outputValue[2] = 1.0f - (valuem + value * (1.0f - inputColor2[2])) * (1.0f - inputColor1[2]);
outputValue[3] = inputColor1[3];
clampIfNeeded(outputValue);
}

@ -28,7 +28,7 @@ MixSoftLightOperation::MixSoftLightOperation() : MixBaseOperation()
}
void MixSoftLightOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) \
{
{
float inputColor1[4];
float inputColor2[4];
float value;
@ -52,5 +52,7 @@ void MixSoftLightOperation::executePixel(float *outputValue, float x, float y, P
outputValue[1] = valuem * (inputColor1[1]) + value * (((1.0f - inputColor1[1]) * inputColor2[1] * (inputColor1[1])) + (inputColor1[1] * scg));
outputValue[2] = valuem * (inputColor1[2]) + value * (((1.0f - inputColor1[2]) * inputColor2[2] * (inputColor1[2])) + (inputColor1[2] * scb));
outputValue[3] = inputColor1[3];
}
clampIfNeeded(outputValue);
}

@ -44,5 +44,7 @@ void MixSubtractOperation::executePixel(float *outputValue, float x, float y, Pi
outputValue[1] = inputColor1[1] - value * (inputColor2[1]);
outputValue[2] = inputColor1[2] - value * (inputColor2[2]);
outputValue[3] = inputColor1[3];
clampIfNeeded(outputValue);
}

@ -52,4 +52,6 @@ void MixValueOperation::executePixel(float *outputValue, float x, float y, Pixel
rgb_to_hsv(inputColor2[0], inputColor2[1], inputColor2[2], &colH, &colS, &colV);
hsv_to_rgb(rH, rS, (valuem * rV + value * colV), &outputValue[0], &outputValue[1], &outputValue[2]);
outputValue[3] = inputColor1[3];
clampIfNeeded(outputValue);
}

@ -303,14 +303,17 @@ static void node_buts_rgb(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr
static void node_buts_mix_rgb(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
uiLayout *row;
uiLayout *row, *col;
bNodeTree *ntree = (bNodeTree *)ptr->id.data;
row = uiLayoutRow(layout, TRUE);
col = uiLayoutColumn(layout, FALSE);
row = uiLayoutRow(col, TRUE);
uiItemR(row, ptr, "blend_type", 0, "", ICON_NONE);
if (ntree->type == NTREE_COMPOSIT)
uiItemR(row, ptr, "use_alpha", 0, "", ICON_IMAGE_RGB_ALPHA);
uiItemR(col, ptr, "use_clamp", 0, NULL, ICON_NONE);
}
static void node_buts_time(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
@ -452,6 +455,7 @@ static void node_buts_texture(uiLayout *layout, bContext *UNUSED(C), PointerRNA
static void node_buts_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
uiItemR(layout, ptr, "operation", 0, "", ICON_NONE);
uiItemR(layout, ptr, "use_clamp", 0, NULL, ICON_NONE);
}
static int node_resize_area_default(bNode *node, int x, int y)

@ -1191,6 +1191,11 @@ static void def_math(StructRNA *srna)
RNA_def_property_enum_items(prop, node_math_items);
RNA_def_property_ui_text(prop, "Operation", "");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
prop = RNA_def_property(srna, "use_clamp", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "custom2", 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_vector_math(StructRNA *srna)
@ -1272,6 +1277,11 @@ static void def_mix_rgb(StructRNA *srna)
RNA_def_property_boolean_sdna(prop, NULL, "custom2", 1);
RNA_def_property_ui_text(prop, "Alpha", "Include alpha of second input in this operation");
RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
prop = RNA_def_property(srna, "use_clamp", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "custom2", 2);
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_texture(StructRNA *srna)