From 8a4584d04daae39c76d1f46200a57d8f4f3c9d40 Mon Sep 17 00:00:00 2001 From: Monique Dewanchand Date: Tue, 10 Jul 2012 20:21:13 +0000 Subject: Fix for tiles bug: [#31981] Bokeh Blur Node - Size input socket does not accept input from Value Input node, Values smaller than 0.1 will produce black output --- .../blender/compositor/nodes/COM_BokehBlurNode.cpp | 46 ++++++++---------- .../operations/COM_BokehBlurOperation.cpp | 54 +++++++++++++++++++--- .../compositor/operations/COM_BokehBlurOperation.h | 4 +- 3 files changed, 70 insertions(+), 34 deletions(-) (limited to 'source/blender/compositor') diff --git a/source/blender/compositor/nodes/COM_BokehBlurNode.cpp b/source/blender/compositor/nodes/COM_BokehBlurNode.cpp index 0ea4b20c793..300193da842 100644 --- a/source/blender/compositor/nodes/COM_BokehBlurNode.cpp +++ b/source/blender/compositor/nodes/COM_BokehBlurNode.cpp @@ -37,32 +37,24 @@ BokehBlurNode::BokehBlurNode(bNode *editorNode) : Node(editorNode) void BokehBlurNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context) { -// Object *camob = context->getScene()->camera; + BokehBlurOperation *operation = new BokehBlurOperation(); + InputSocket *inputSizeSocket = this->getInputSocket(2); + bool connectedSizeSocket = inputSizeSocket->isConnected(); -// if (this->getInputSocket(2)->isConnected()) { -// VariableSizeBokehBlurOperation *operation = new VariableSizeBokehBlurOperation(); -// ConvertDepthToRadiusOperation *converter = new ConvertDepthToRadiusOperation(); -// converter->setfStop(this->getbNode()->custom3); -// converter->setCameraObject(camob); -// operation->setMaxBlur((int)this->getbNode()->custom4); -// operation->setQuality(context->getQuality()); -// this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); -// this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), 1, graph); -// this->getInputSocket(2)->relinkConnections(converter->getInputSocket(0), 2, graph); -// addLink(graph, converter->getOutputSocket(), operation->getInputSocket(2)); -// graph->addOperation(operation); -// graph->addOperation(converter); -// this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket()); -// } -// else { - BokehBlurOperation *operation = new BokehBlurOperation(); - this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); - this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), 1, graph); - this->getInputSocket(3)->relinkConnections(operation->getInputSocket(2), 3, graph); - operation->setSize(((bNodeSocketValueFloat *)this->getInputSocket(2)->getbNodeSocket()->default_value)->value); - operation->setQuality(context->getQuality()); - operation->setbNode(this->getbNode()); - graph->addOperation(operation); - this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket()); -// } + const bNodeSocket *sock = this->getInputSocket(2)->getbNodeSocket(); + const float size = ((const bNodeSocketValueFloat *)sock->default_value)->value; + + this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); + this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), 1, graph); + this->getInputSocket(2)->relinkConnections(operation->getInputSocket(3), 2, graph); + this->getInputSocket(3)->relinkConnections(operation->getInputSocket(2), 3, graph); + //operation->setSize(((bNodeSocketValueFloat *)this->getInputSocket(2)->getbNodeSocket()->default_value)->value); + operation->setQuality(context->getQuality()); + operation->setbNode(this->getbNode()); + graph->addOperation(operation); + this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket()); + + if (!connectedSizeSocket) { + operation->setSize(size); + } } diff --git a/source/blender/compositor/operations/COM_BokehBlurOperation.cpp b/source/blender/compositor/operations/COM_BokehBlurOperation.cpp index e83ad4824e4..a425e406884 100644 --- a/source/blender/compositor/operations/COM_BokehBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_BokehBlurOperation.cpp @@ -33,12 +33,13 @@ BokehBlurOperation::BokehBlurOperation() : NodeOperation() this->addInputSocket(COM_DT_COLOR); this->addInputSocket(COM_DT_COLOR, COM_SC_NO_RESIZE); this->addInputSocket(COM_DT_VALUE); + this->addInputSocket(COM_DT_VALUE); this->addOutputSocket(COM_DT_COLOR); this->setComplex(true); this->setOpenCL(true); this->m_size = 1.0f; - + this->m_sizeavailable = false; this->m_inputProgram = NULL; this->m_inputBokehProgram = NULL; this->m_inputBoundingBoxReader = NULL; @@ -46,12 +47,20 @@ BokehBlurOperation::BokehBlurOperation() : NodeOperation() void *BokehBlurOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers) { + //void *buffer = getInputOperation(0)->initializeTileData(NULL, memoryBuffers); + lockMutex(); + if (!this->m_sizeavailable) { + //updateGauss(memoryBuffers); + updateSize(memoryBuffers); + } void *buffer = getInputOperation(0)->initializeTileData(NULL, memoryBuffers); + unlockMutex(); return buffer; } void BokehBlurOperation::initExecution() { + initMutex(); this->m_inputProgram = getInputSocketReader(0); this->m_inputBokehProgram = getInputSocketReader(1); this->m_inputBoundingBoxReader = getInputSocketReader(2); @@ -87,7 +96,10 @@ void BokehBlurOperation::executePixel(float *color, int x, int y, MemoryBuffer * int bufferstartx = inputBuffer->getRect()->xmin; int bufferstarty = inputBuffer->getRect()->ymin; int pixelSize = this->m_size * this->getWidth() / 100.0f; - + if (pixelSize==0){ + this->m_inputProgram->read(color, x, y, COM_PS_NEAREST, inputBuffers); + return; + } int miny = y - pixelSize; int maxy = y + pixelSize; int minx = x - pixelSize; @@ -126,6 +138,7 @@ void BokehBlurOperation::executePixel(float *color, int x, int y, MemoryBuffer * void BokehBlurOperation::deinitExecution() { + deinitMutex(); this->m_inputProgram = NULL; this->m_inputBokehProgram = NULL; this->m_inputBoundingBoxReader = NULL; @@ -136,10 +149,17 @@ bool BokehBlurOperation::determineDependingAreaOfInterest(rcti *input, ReadBuffe rcti newInput; rcti bokehInput; - newInput.xmax = input->xmax + (this->m_size * this->getWidth() / 100.0f); - newInput.xmin = input->xmin - (this->m_size * this->getWidth() / 100.0f); - newInput.ymax = input->ymax + (this->m_size * this->getWidth() / 100.0f); - newInput.ymin = input->ymin - (this->m_size * this->getWidth() / 100.0f); + if (this->m_sizeavailable) { + newInput.xmax = input->xmax + (this->m_size * this->getWidth() / 100.0f); + newInput.xmin = input->xmin - (this->m_size * this->getWidth() / 100.0f); + newInput.ymax = input->ymax + (this->m_size * this->getWidth() / 100.0f); + newInput.ymin = input->ymin - (this->m_size * this->getWidth() / 100.0f); + } else { + newInput.xmax = input->xmax + (10.0f * this->getWidth() / 100.0f); + newInput.xmin = input->xmin - (10.0f * this->getWidth() / 100.0f); + newInput.ymax = input->ymax + (10.0f * this->getWidth() / 100.0f); + newInput.ymin = input->ymin - (10.0f * this->getWidth() / 100.0f); + } NodeOperation *operation = getInputOperation(1); bokehInput.xmax = operation->getWidth(); @@ -157,6 +177,17 @@ bool BokehBlurOperation::determineDependingAreaOfInterest(rcti *input, ReadBuffe if (operation->determineDependingAreaOfInterest(input, readOperation, output) ) { return true; } + if (!this->m_sizeavailable) { + rcti sizeInput; + sizeInput.xmin = 0; + sizeInput.ymin = 0; + sizeInput.xmax = 5; + sizeInput.ymax = 5; + operation = getInputOperation(3); + if (operation->determineDependingAreaOfInterest(&sizeInput, readOperation, output) ) { + return true; + } + } return false; } @@ -181,3 +212,14 @@ void BokehBlurOperation::executeOpenCL(OpenCLDevice* device, device->COM_clEnqueueRange(kernel, outputMemoryBuffer, 9, this); } + +void BokehBlurOperation::updateSize(MemoryBuffer **memoryBuffers) +{ + if (!this->m_sizeavailable) { + float result[4]; + this->getInputSocketReader(3)->read(result, 0, 0, COM_PS_NEAREST, memoryBuffers); + this->m_size = result[0]; + CLAMP(this->m_size, 0.0f, 10.0f); + this->m_sizeavailable = true; + } +} diff --git a/source/blender/compositor/operations/COM_BokehBlurOperation.h b/source/blender/compositor/operations/COM_BokehBlurOperation.h index 0433a4156a8..407118b17a5 100644 --- a/source/blender/compositor/operations/COM_BokehBlurOperation.h +++ b/source/blender/compositor/operations/COM_BokehBlurOperation.h @@ -30,7 +30,9 @@ private: SocketReader *m_inputProgram; SocketReader *m_inputBokehProgram; SocketReader *m_inputBoundingBoxReader; + void updateSize(MemoryBuffer **memoryBuffers); float m_size; + bool m_sizeavailable; float m_bokehMidX; float m_bokehMidY; float m_bokehDimension; @@ -55,7 +57,7 @@ public: bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); - void setSize(float size) { this->m_size = size; } + void setSize(float size) { this->m_size = size; this->m_sizeavailable = true; } void executeOpenCL(OpenCLDevice* device, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, list *clMemToCleanUp, list *clKernelsToCleanUp); }; -- cgit v1.2.3