diff --git a/source/blender/compositor/nodes/COM_AntiAliasingNode.cc b/source/blender/compositor/nodes/COM_AntiAliasingNode.cc index 554579306ff..1574804208f 100644 --- a/source/blender/compositor/nodes/COM_AntiAliasingNode.cc +++ b/source/blender/compositor/nodes/COM_AntiAliasingNode.cc @@ -29,9 +29,7 @@ void AntiAliasingNode::convertToOperations(NodeConverter &converter, NodeAntiAliasingData *data = (NodeAntiAliasingData *)node->storage; /* Edge Detection (First Pass) */ - SMAAEdgeDetectionOperation *operation1 = nullptr; - - operation1 = new SMAALumaEdgeDetectionOperation(); + SMAALumaEdgeDetectionOperation *operation1 = new SMAALumaEdgeDetectionOperation(); operation1->setThreshold(data->threshold); operation1->setLocalContrastAdaptationFactor(data->contrast_limit); converter.addOperation(operation1); diff --git a/source/blender/compositor/operations/COM_SMAAOperation.cc b/source/blender/compositor/operations/COM_SMAAOperation.cc index 887f7a760f3..e73c2fbb51c 100644 --- a/source/blender/compositor/operations/COM_SMAAOperation.cc +++ b/source/blender/compositor/operations/COM_SMAAOperation.cc @@ -156,7 +156,7 @@ static void area_diag(int d1, int d2, int e1, int e2, float weights[2]) /* Edge Detection (First Pass) */ /*-----------------------------------------------------------------------------*/ -SMAAEdgeDetectionOperation::SMAAEdgeDetectionOperation() : NodeOperation() +SMAALumaEdgeDetectionOperation::SMAALumaEdgeDetectionOperation() { this->addInputSocket(DataType::Color); /* image */ this->addInputSocket(DataType::Value); /* depth, material ID, etc. */ @@ -168,31 +168,31 @@ SMAAEdgeDetectionOperation::SMAAEdgeDetectionOperation() : NodeOperation() this->m_contrast_limit = 2.0f; } -void SMAAEdgeDetectionOperation::initExecution() +void SMAALumaEdgeDetectionOperation::initExecution() { this->m_imageReader = this->getInputSocketReader(0); this->m_valueReader = this->getInputSocketReader(1); } -void SMAAEdgeDetectionOperation::deinitExecution() +void SMAALumaEdgeDetectionOperation::deinitExecution() { this->m_imageReader = nullptr; this->m_valueReader = nullptr; } -void SMAAEdgeDetectionOperation::setThreshold(float threshold) +void SMAALumaEdgeDetectionOperation::setThreshold(float threshold) { /* UI values are between 0 and 1 for simplicity but algorithm expects values between 0 and 0.5 */ m_threshold = scalenorm(0, 0.5, threshold); } -void SMAAEdgeDetectionOperation::setLocalContrastAdaptationFactor(float factor) +void SMAALumaEdgeDetectionOperation::setLocalContrastAdaptationFactor(float factor) { /* UI values are between 0 and 1 for simplicity but algorithm expects values between 1 and 10 */ m_contrast_limit = scalenorm(1, 10, factor); } -bool SMAAEdgeDetectionOperation::determineDependingAreaOfInterest( +bool SMAALumaEdgeDetectionOperation::determineDependingAreaOfInterest( rcti *input, ReadBufferOperation *readOperation, rcti *output) { rcti newInput; @@ -287,122 +287,11 @@ void SMAALumaEdgeDetectionOperation::executePixel(float output[4], int x, int y, } } -/* Color Edge Detection */ - -static float color_delta(const float color1[4], const float color2[4]) -{ - return fmaxf(fmaxf(fabsf(color1[0] - color2[0]), fabsf(color1[1] - color2[1])), - fabsf(color1[2] - color2[2])); -} - -void SMAAColorEdgeDetectionOperation::executePixel(float output[4], int x, int y, void * /*data*/) -{ - /* Calculate color deltas: */ - float C[4], Cleft[4], Ctop[4]; - sample(m_imageReader, x, y, C); - sample(m_imageReader, x - 1, y, Cleft); - sample(m_imageReader, x, y - 1, Ctop); - float Dleft = color_delta(C, Cleft); - float Dtop = color_delta(C, Ctop); - - /* We do the usual threshold: */ - output[0] = (x > 0 && Dleft >= m_threshold) ? 1.0f : 0.0f; - output[1] = (y > 0 && Dtop >= m_threshold) ? 1.0f : 0.0f; - output[2] = 0.0f; - output[3] = 1.0f; - - /* Then discard if there is no edge: */ - if (is_zero_v2(output)) { - return; - } - - /* Calculate right and bottom deltas: */ - float Cright[4], Cbottom[4]; - sample(m_imageReader, x + 1, y, Cright); - sample(m_imageReader, x, y + 1, Cbottom); - float Dright = color_delta(C, Cright); - float Dbottom = color_delta(C, Cbottom); - - /* Calculate the maximum delta in the direct neighborhood: */ - float maxDelta = fmaxf(fmaxf(Dleft, Dright), fmaxf(Dtop, Dbottom)); - - /* Get color used for both left and top edges: */ - float Clefttop[4]; - sample(m_imageReader, x - 1, y - 1, Clefttop); - - /* Left edge */ - if (output[0] != 0.0f) { - /* Calculate deltas around the left pixel: */ - float Cleftleft[4], Cleftbottom[4]; - sample(m_imageReader, x - 2, y, Cleftleft); - sample(m_imageReader, x - 1, y + 1, Cleftbottom); - float Dleftleft = color_delta(Cleft, Cleftleft); - float Dlefttop = color_delta(Cleft, Clefttop); - float Dleftbottom = color_delta(Cleft, Cleftbottom); - - /* Calculate the final maximum delta: */ - maxDelta = fmaxf(maxDelta, fmaxf(Dleftleft, fmaxf(Dlefttop, Dleftbottom))); - - /* Local contrast adaptation: */ - if (maxDelta > m_contrast_limit * Dleft) { - output[0] = 0.0f; - } - } - - /* Top edge */ - if (output[1] != 0.0f) { - /* Calculate deltas around the top pixel: */ - float Ctoptop[4], Ctopright[4]; - sample(m_imageReader, x, y - 2, Ctoptop); - sample(m_imageReader, x + 1, y - 1, Ctopright); - float Dtoptop = color_delta(Ctop, Ctoptop); - float Dtopleft = color_delta(Ctop, Clefttop); - float Dtopright = color_delta(Ctop, Ctopright); - - /* Calculate the final maximum delta: */ - maxDelta = fmaxf(maxDelta, fmaxf(Dtoptop, fmaxf(Dtopleft, Dtopright))); - - /* Local contrast adaptation: */ - if (maxDelta > m_contrast_limit * Dtop) { - output[1] = 0.0f; - } - } -} - -/* Depth Edge Detection */ - -void SMAADepthEdgeDetectionOperation::executePixel(float output[4], int x, int y, void * /*data*/) -{ - float here[4], left[4], top[4]; - - sample(m_valueReader, x, y, here); - sample(m_valueReader, x - 1, y, left); - sample(m_valueReader, x, y - 1, top); - - output[0] = (x > 0 && fabsf(here[0] - left[0]) >= m_threshold) ? 1.0f : 0.0f; - output[1] = (y > 0 && fabsf(here[0] - top[0]) >= m_threshold) ? 1.0f : 0.0f; - output[2] = 0.0f; - output[3] = 1.0f; -} - -bool SMAADepthEdgeDetectionOperation::determineDependingAreaOfInterest( - rcti *input, ReadBufferOperation *readOperation, rcti *output) -{ - rcti newInput; - - newInput.xmax = input->xmax; - newInput.xmin = input->xmin - 1; - newInput.ymax = input->ymax; - newInput.ymin = input->ymin - 1; - - return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output); -} - /*-----------------------------------------------------------------------------*/ /* Blending Weight Calculation (Second Pass) */ /*-----------------------------------------------------------------------------*/ -SMAABlendingWeightCalculationOperation::SMAABlendingWeightCalculationOperation() : NodeOperation() +SMAABlendingWeightCalculationOperation::SMAABlendingWeightCalculationOperation() { this->addInputSocket(DataType::Color); /* edges */ this->addOutputSocket(DataType::Color); @@ -888,7 +777,7 @@ void SMAABlendingWeightCalculationOperation::detectVerticalCornerPattern( /* Neighborhood Blending (Third Pass) */ /*-----------------------------------------------------------------------------*/ -SMAANeighborhoodBlendingOperation::SMAANeighborhoodBlendingOperation() : NodeOperation() +SMAANeighborhoodBlendingOperation::SMAANeighborhoodBlendingOperation() { this->addInputSocket(DataType::Color); /* image */ this->addInputSocket(DataType::Color); /* blend */ diff --git a/source/blender/compositor/operations/COM_SMAAOperation.h b/source/blender/compositor/operations/COM_SMAAOperation.h index c2fdd9fef72..94e67c8402f 100644 --- a/source/blender/compositor/operations/COM_SMAAOperation.h +++ b/source/blender/compositor/operations/COM_SMAAOperation.h @@ -25,7 +25,7 @@ /*-----------------------------------------------------------------------------*/ /* Edge Detection (First Pass) */ -class SMAAEdgeDetectionOperation : public NodeOperation { +class SMAALumaEdgeDetectionOperation : public NodeOperation { protected: SocketReader *m_imageReader; SocketReader *m_valueReader; @@ -34,12 +34,12 @@ class SMAAEdgeDetectionOperation : public NodeOperation { float m_contrast_limit; public: - SMAAEdgeDetectionOperation(); + SMAALumaEdgeDetectionOperation(); /** * the inner loop of this program */ - virtual void executePixel(float output[4], int x, int y, void *data) = 0; + void executePixel(float output[4], int x, int y, void *data); /** * Initialize the execution @@ -60,24 +60,6 @@ class SMAAEdgeDetectionOperation : public NodeOperation { rcti *output); }; -class SMAALumaEdgeDetectionOperation : public SMAAEdgeDetectionOperation { - public: - void executePixel(float output[4], int x, int y, void *data); -}; - -class SMAAColorEdgeDetectionOperation : public SMAAEdgeDetectionOperation { - public: - void executePixel(float output[4], int x, int y, void *data); -}; - -class SMAADepthEdgeDetectionOperation : public SMAAEdgeDetectionOperation { - public: - void executePixel(float output[4], int x, int y, void *data); - bool determineDependingAreaOfInterest(rcti *input, - ReadBufferOperation *readOperation, - rcti *output); -}; - /*-----------------------------------------------------------------------------*/ /* Blending Weight Calculation (Second Pass) */