From 590f5fdbdfc2357c5b0490a406c9c39cf66de50a Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Fri, 22 Jun 2012 14:43:25 +0000 Subject: fix for [#31890] Lens Distortion inside Node group don't work --- .../compositor/nodes/COM_LensDistortionNode.cpp | 6 +-- .../COM_ProjectorLensDistortionOperation.cpp | 33 ++++++++++++--- .../COM_ProjectorLensDistortionOperation.h | 5 ++- .../COM_ScreenLensDistortionOperation.cpp | 49 +++++++++++++++------- .../operations/COM_ScreenLensDistortionOperation.h | 4 +- 5 files changed, 69 insertions(+), 28 deletions(-) (limited to 'source/blender') diff --git a/source/blender/compositor/nodes/COM_LensDistortionNode.cpp b/source/blender/compositor/nodes/COM_LensDistortionNode.cpp index 03034e34eb7..0319e66ee22 100644 --- a/source/blender/compositor/nodes/COM_LensDistortionNode.cpp +++ b/source/blender/compositor/nodes/COM_LensDistortionNode.cpp @@ -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); diff --git a/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cpp b/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cpp index 77f2a06b29b..b337e435df4 100644 --- a/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cpp +++ b/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cpp @@ -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; + } +} diff --git a/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.h b/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.h index 2e188617ab5..5023a5df507 100644 --- a/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.h +++ b/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.h @@ -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 diff --git a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp index 02cc62d4bdd..da3504de971 100644 --- a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp +++ b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp @@ -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; + } +} diff --git a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.h b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.h index 34656f38a09..21babd11295 100644 --- a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.h +++ b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.h @@ -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 -- cgit v1.2.3