Fix #36113, Translate's wrapping has 1 pixel gap in X and Y after scale node.
The issue with wrapping is that it requires correct interpolation of the border pixels. Since interpolation is done at the far left end of the node tree in buffer/image/etc read operations, the wrapping setting can not be used directly in those operations (otherwise in-line translate operations would cause conflicts). To make wrapping work correctly we need to add a buffer in front of the translate operation, which can then be interpolated correctly based on wrapping. The WrapOperation becomes a variant of ReadBufferOperation, which uses its wrapping setting to determine the correct "extend" mode for interpolation of the buffer.
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
|
||||
#include "COM_TranslateOperation.h"
|
||||
#include "COM_WrapOperation.h"
|
||||
#include "COM_WriteBufferOperation.h"
|
||||
#include "COM_ExecutionSystem.h"
|
||||
|
||||
TranslateNode::TranslateNode(bNode *editorNode) : Node(editorNode)
|
||||
@@ -43,10 +44,15 @@ void TranslateNode::convertToOperations(ExecutionSystem *graph, CompositorContex
|
||||
NodeTranslateData *data = (NodeTranslateData *)bnode->storage;
|
||||
|
||||
if (data->wrap_axis) {
|
||||
WriteBufferOperation *writeOperation = new WriteBufferOperation();
|
||||
WrapOperation *wrapOperation = new WrapOperation();
|
||||
wrapOperation->setMemoryProxy(writeOperation->getMemoryProxy());
|
||||
wrapOperation->setWrapping(data->wrap_axis);
|
||||
inputSocket->relinkConnections(wrapOperation->getInputSocket(0), 0, graph);
|
||||
|
||||
inputSocket->relinkConnections(writeOperation->getInputSocket(0), 0, graph);
|
||||
addLink(graph, wrapOperation->getOutputSocket(), operation->getInputSocket(0));
|
||||
|
||||
graph->addOperation(writeOperation);
|
||||
graph->addOperation(wrapOperation);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -66,6 +66,21 @@ void ReadBufferOperation::executePixel(float output[4], float x, float y, PixelS
|
||||
}
|
||||
}
|
||||
|
||||
void ReadBufferOperation::executePixelExtend(float output[4], float x, float y, PixelSampler sampler,
|
||||
MemoryBufferExtend extend_x, MemoryBufferExtend extend_y)
|
||||
{
|
||||
if (m_single_value) {
|
||||
/* write buffer has a single value stored at (0,0) */
|
||||
m_buffer->read(output, 0, 0);
|
||||
}
|
||||
else if (sampler == COM_PS_NEAREST) {
|
||||
m_buffer->read(output, x, y, extend_x, extend_y);
|
||||
}
|
||||
else {
|
||||
m_buffer->readBilinear(output, x, y, extend_x, extend_y);
|
||||
}
|
||||
}
|
||||
|
||||
void ReadBufferOperation::executePixel(float output[4], float x, float y, float dx, float dy, PixelSampler sampler)
|
||||
{
|
||||
if (m_single_value) {
|
||||
|
||||
@@ -41,6 +41,8 @@ public:
|
||||
|
||||
void *initializeTileData(rcti *rect);
|
||||
void executePixel(float output[4], float x, float y, PixelSampler sampler);
|
||||
void executePixelExtend(float output[4], float x, float y, PixelSampler sampler,
|
||||
MemoryBufferExtend extend_x, MemoryBufferExtend extend_y);
|
||||
void executePixel(float output[4], float x, float y, float dx, float dy, PixelSampler sampler);
|
||||
const bool isReadBufferOperation() const { return true; }
|
||||
void setOffset(unsigned int offset) { this->m_offset = offset; }
|
||||
|
||||
@@ -23,21 +23,9 @@
|
||||
|
||||
#include "COM_WrapOperation.h"
|
||||
|
||||
WrapOperation::WrapOperation() : NodeOperation()
|
||||
WrapOperation::WrapOperation() : ReadBufferOperation()
|
||||
{
|
||||
this->addInputSocket(COM_DT_COLOR);
|
||||
this->addOutputSocket(COM_DT_COLOR);
|
||||
this->setResolutionInputSocketIndex(0);
|
||||
this->m_inputOperation = NULL;
|
||||
}
|
||||
void WrapOperation::initExecution()
|
||||
{
|
||||
this->m_inputOperation = this->getInputSocketReader(0);
|
||||
}
|
||||
|
||||
void WrapOperation::deinitExecution()
|
||||
{
|
||||
this->m_inputOperation = NULL;
|
||||
this->m_wrappingType = CMP_NODE_WRAP_NONE;
|
||||
}
|
||||
|
||||
inline float WrapOperation::getWrappedOriginalXPos(float x)
|
||||
@@ -59,6 +47,7 @@ void WrapOperation::executePixel(float output[4], float x, float y, PixelSampler
|
||||
float nx, ny;
|
||||
nx = x;
|
||||
ny = y;
|
||||
MemoryBufferExtend extend_x = COM_MB_CLIP, extend_y = COM_MB_CLIP;
|
||||
switch (m_wrappingType) {
|
||||
case CMP_NODE_WRAP_NONE:
|
||||
//Intentionally empty, originalXPos and originalYPos have been set before
|
||||
@@ -66,20 +55,23 @@ void WrapOperation::executePixel(float output[4], float x, float y, PixelSampler
|
||||
case CMP_NODE_WRAP_X:
|
||||
// wrap only on the x-axis
|
||||
nx = this->getWrappedOriginalXPos(x);
|
||||
extend_x = COM_MB_REPEAT;
|
||||
break;
|
||||
case CMP_NODE_WRAP_Y:
|
||||
// wrap only on the y-axis
|
||||
ny = this->getWrappedOriginalYPos(y);
|
||||
extend_y = COM_MB_REPEAT;
|
||||
break;
|
||||
case CMP_NODE_WRAP_XY:
|
||||
// wrap on both
|
||||
nx = this->getWrappedOriginalXPos(x);
|
||||
ny = this->getWrappedOriginalYPos(y);
|
||||
extend_x = COM_MB_REPEAT;
|
||||
extend_y = COM_MB_REPEAT;
|
||||
break;
|
||||
}
|
||||
|
||||
this->m_inputOperation->read(output, nx, ny, sampler);
|
||||
|
||||
executePixelExtend(output, nx, ny, sampler, extend_x, extend_y);
|
||||
}
|
||||
|
||||
bool WrapOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
|
||||
@@ -110,7 +102,7 @@ bool WrapOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOper
|
||||
}
|
||||
}
|
||||
|
||||
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
|
||||
return ReadBufferOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
|
||||
}
|
||||
|
||||
void WrapOperation::setWrapping(int wrapping_type)
|
||||
|
||||
@@ -23,20 +23,16 @@
|
||||
#ifndef _COM_WrapOperation_h_
|
||||
#define _COM_WrapOperation_h_
|
||||
|
||||
#include "COM_NodeOperation.h"
|
||||
#include "COM_ReadBufferOperation.h"
|
||||
|
||||
class WrapOperation : public NodeOperation {
|
||||
class WrapOperation : public ReadBufferOperation {
|
||||
private:
|
||||
SocketReader *m_inputOperation;
|
||||
int m_wrappingType;
|
||||
public:
|
||||
WrapOperation();
|
||||
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
|
||||
void executePixel(float output[4], float x, float y, PixelSampler sampler);
|
||||
|
||||
void initExecution();
|
||||
void deinitExecution();
|
||||
|
||||
void setWrapping(int wrapping_type);
|
||||
float getWrappedOriginalXPos(float x);
|
||||
float getWrappedOriginalYPos(float y);
|
||||
|
||||
Reference in New Issue
Block a user