Fix for tiles bug:
authorMonique Dewanchand <m.dewanchand@atmind.nl>
Tue, 10 Jul 2012 20:21:13 +0000 (20:21 +0000)
committerMonique Dewanchand <m.dewanchand@atmind.nl>
Tue, 10 Jul 2012 20:21:13 +0000 (20:21 +0000)
[#31981] Bokeh Blur Node - Size input socket does not accept input from Value Input node, Values smaller than 0.1 will produce black output

source/blender/compositor/nodes/COM_BokehBlurNode.cpp
source/blender/compositor/operations/COM_BokehBlurOperation.cpp
source/blender/compositor/operations/COM_BokehBlurOperation.h

index 0ea4b20c79359f84e60367af038db625556faf27..300193da84260ed84d58a6394a998e5015af8232 100644 (file)
@@ -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);
+       }
 }
index e83ad4824e446a94fefff4b29ec989958729614c..a425e4068841d5eb2cb8f52f1795280fc9a1ab07 100644 (file)
@@ -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;
+       }
+}
index 0433a4156a82914b9de0e7a4bdf67c89e8a2bcce..407118b17a5658d946f17df42b57eb52b757bf8b 100644 (file)
@@ -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<cl_mem> *clMemToCleanUp, list<cl_kernel> *clKernelsToCleanUp);
 };