Revision: 48816
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48816
Author:   mdewanchand
Date:     2012-07-10 20:21:13 +0000 (Tue, 10 Jul 2012)
Log Message:
-----------
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

Modified Paths:
--------------
    trunk/blender/source/blender/compositor/nodes/COM_BokehBlurNode.cpp
    
trunk/blender/source/blender/compositor/operations/COM_BokehBlurOperation.cpp
    trunk/blender/source/blender/compositor/operations/COM_BokehBlurOperation.h

Modified: trunk/blender/source/blender/compositor/nodes/COM_BokehBlurNode.cpp
===================================================================
--- trunk/blender/source/blender/compositor/nodes/COM_BokehBlurNode.cpp 
2012-07-10 19:23:57 UTC (rev 48815)
+++ trunk/blender/source/blender/compositor/nodes/COM_BokehBlurNode.cpp 
2012-07-10 20:21:13 UTC (rev 48816)
@@ -37,32 +37,24 @@
 
 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);
+       }
 }

Modified: 
trunk/blender/source/blender/compositor/operations/COM_BokehBlurOperation.cpp
===================================================================
--- 
trunk/blender/source/blender/compositor/operations/COM_BokehBlurOperation.cpp   
    2012-07-10 19:23:57 UTC (rev 48815)
+++ 
trunk/blender/source/blender/compositor/operations/COM_BokehBlurOperation.cpp   
    2012-07-10 20:21:13 UTC (rev 48816)
@@ -33,12 +33,13 @@
        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 @@
 
 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 @@
                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::deinitExecution()
 {
+       deinitMutex();
        this->m_inputProgram = NULL;
        this->m_inputBokehProgram = NULL;
        this->m_inputBoundingBoxReader = NULL;
@@ -136,10 +149,17 @@
        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 @@
        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 @@
        
        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;
+       }
+}

Modified: 
trunk/blender/source/blender/compositor/operations/COM_BokehBlurOperation.h
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_BokehBlurOperation.h 
2012-07-10 19:23:57 UTC (rev 48815)
+++ trunk/blender/source/blender/compositor/operations/COM_BokehBlurOperation.h 
2012-07-10 20:21:13 UTC (rev 48816)
@@ -30,7 +30,9 @@
        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 @@
        
        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);
 };

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to