fix for [#31890] Lens Distortion inside Node group don't work

This commit is contained in:
Jeroen Bakker 2012-06-22 14:43:25 +00:00
parent 65e9216cce
commit 590f5fdbdf
5 changed files with 69 additions and 28 deletions

View File

@ -39,7 +39,7 @@ void LensDistortionNode::convertToOperations(ExecutionSystem *graph, CompositorC
ProjectorLensDistortionOperation *operation = new ProjectorLensDistortionOperation();
this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph);
operation->setDispertion(this->getInputSocket(2)->getStaticValues()[0]);
this->getInputSocket(2)->relinkConnections(operation->getInputSocket(1), 2, graph);
this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0));
operation->setData(data);
@ -50,8 +50,8 @@ void LensDistortionNode::convertToOperations(ExecutionSystem *graph, CompositorC
ScreenLensDistortionOperation *operation = new ScreenLensDistortionOperation();
this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph);
operation->setDistortion(this->getInputSocket(1)->getStaticValues()[0]);
operation->setDispertion(this->getInputSocket(2)->getStaticValues()[0]);
this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), 1, graph);
this->getInputSocket(2)->relinkConnections(operation->getInputSocket(2), 2, graph);
this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0));
operation->setData(data);

View File

@ -27,19 +27,21 @@
ProjectorLensDistortionOperation::ProjectorLensDistortionOperation() : NodeOperation()
{
this->addInputSocket(COM_DT_COLOR);
this->addInputSocket(COM_DT_VALUE);
this->addOutputSocket(COM_DT_COLOR);
this->setComplex(true);
this->inputProgram = NULL;
this->dispersionAvailable = false;
this->dispersion = 0.0f;
}
void ProjectorLensDistortionOperation::initExecution()
{
this->inputProgram = this->getInputSocketReader(0);
kr = 0.25f * MAX2(MIN2(this->dispersion, 1.f), 0.f);
kr2 = kr * 20;
}
void *ProjectorLensDistortionOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers)
{
updateDispersion(memoryBuffers);
void *buffer = inputProgram->initializeTileData(NULL, memoryBuffers);
return buffer;
}
@ -69,9 +71,28 @@ void ProjectorLensDistortionOperation::deinitExecution()
bool ProjectorLensDistortionOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output)
{
rcti newInput;
newInput.ymax = input->ymax;
newInput.ymin = input->ymin;
newInput.xmin = input->xmin - kr2 - 2;
newInput.xmax = input->xmax + kr2 + 2;
if (dispersionAvailable) {
newInput.ymax = input->ymax;
newInput.ymin = input->ymin;
newInput.xmin = input->xmin - kr2 - 2;
newInput.xmax = input->xmax + kr2 + 2;
} else {
newInput.xmin = 0;
newInput.ymin = input->ymin;
newInput.ymax = input->ymax;
newInput.xmax = inputProgram->getWidth();
}
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
}
void ProjectorLensDistortionOperation::updateDispersion(MemoryBuffer **inputBuffers)
{
if (!dispersionAvailable) {
float result[4];
this->getInputSocketReader(1)->read(result, 0, 0, COM_PS_NEAREST, inputBuffers);
dispersion = result[0];
kr = 0.25f * MAX2(MIN2(this->dispersion, 1.f), 0.f);
kr2 = kr * 20;
dispersionAvailable = true;
}
}

View File

@ -35,6 +35,8 @@ private:
NodeLensDist *data;
float dispersion;
bool dispersionAvailable;
float kr, kr2;
public:
ProjectorLensDistortionOperation();
@ -56,9 +58,10 @@ public:
void deinitExecution();
void setData(NodeLensDist *data) { this->data = data; }
void setDispertion(float dispersion) { this->dispersion = dispersion; }
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
void updateDispersion(MemoryBuffer** inputBuffers);
};
#endif

View File

@ -30,34 +30,24 @@ extern "C" {
ScreenLensDistortionOperation::ScreenLensDistortionOperation() : NodeOperation()
{
this->addInputSocket(COM_DT_COLOR);
this->addInputSocket(COM_DT_VALUE);
this->addInputSocket(COM_DT_VALUE);
this->addOutputSocket(COM_DT_COLOR);
this->setComplex(true);
this->inputProgram = NULL;
this->valuesAvailable = false;
this->dispersion = 0.0f;
this->distortion = 0.0f;
}
void ScreenLensDistortionOperation::initExecution()
{
this->inputProgram = this->getInputSocketReader(0);
kg = MAX2(MIN2(this->distortion, 1.f), -0.999f);
// smaller dispersion range for somewhat more control
const float d = 0.25f * MAX2(MIN2(this->dispersion, 1.f), 0.f);
kr = MAX2(MIN2((kg + d), 1.f), -0.999f);
kb = MAX2(MIN2((kg - d), 1.f), -0.999f);
maxk = MAX3(kr, kg, kb);
sc = (this->data->fit && (maxk > 0.f)) ? (1.f / (1.f + 2.f * maxk)) : (1.f / (1.f + maxk));
drg = 4.f * (kg - kr);
dgb = 4.f * (kb - kg);
kr4 = kr * 4.f;
kg4 = kg * 4.f;
kb4 = kb * 4.f;
cx = 0.5f * (float)getWidth();
cy = 0.5f * (float)getHeight();
}
void *ScreenLensDistortionOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers)
{
void *buffer = inputProgram->initializeTileData(NULL, memoryBuffers);
updateDispersionAndDistortion(memoryBuffers);
return buffer;
}
@ -171,3 +161,30 @@ bool ScreenLensDistortionOperation::determineDependingAreaOfInterest(rcti *input
newInput.xmax = inputProgram->getWidth();
return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output);
}
void ScreenLensDistortionOperation::updateDispersionAndDistortion(MemoryBuffer **inputBuffers)
{
if (!valuesAvailable) {
float result[4];
this->getInputSocketReader(1)->read(result, 0, 0, COM_PS_NEAREST, inputBuffers);
this->distortion = result[0];
this->getInputSocketReader(2)->read(result, 0, 0, COM_PS_NEAREST, inputBuffers);
this->dispersion = result[0];
kg = MAX2(MIN2(this->distortion, 1.f), -0.999f);
// smaller dispersion range for somewhat more control
const float d = 0.25f * MAX2(MIN2(this->dispersion, 1.f), 0.f);
kr = MAX2(MIN2((kg + d), 1.f), -0.999f);
kb = MAX2(MIN2((kg - d), 1.f), -0.999f);
maxk = MAX3(kr, kg, kb);
sc = (this->data->fit && (maxk > 0.f)) ? (1.f / (1.f + 2.f * maxk)) : (1.f / (1.f + maxk));
drg = 4.f * (kg - kr);
dgb = 4.f * (kb - kg);
kr4 = kr * 4.f;
kg4 = kg * 4.f;
kb4 = kb * 4.f;
cx = 0.5f * (float)getWidth();
cy = 0.5f * (float)getHeight();
valuesAvailable = true;
}
}

View File

@ -36,6 +36,7 @@ private:
float dispersion;
float distortion;
bool valuesAvailable;
float kr, kg, kb;
float kr4, kg4, kb4;
float maxk;
@ -62,13 +63,12 @@ public:
void deinitExecution();
void setData(NodeLensDist *data) { this->data = data; }
void setDispertion(float dispersion) { this->dispersion = dispersion; }
void setDistortion(float distortion) { this->distortion = distortion; }
bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output);
private:
void determineUV(float *result, float x, float y) const;
void updateDispersionAndDistortion(MemoryBuffer** inputBuffers);
};
#endif