diff options
Diffstat (limited to 'source/blender/compositor')
146 files changed, 1013 insertions, 376 deletions
diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt index 30cea825281..870e379b343 100644 --- a/source/blender/compositor/CMakeLists.txt +++ b/source/blender/compositor/CMakeLists.txt @@ -424,10 +424,10 @@ set(SRC operations/COM_PreviewOperation.cpp operations/COM_SplitViewerOperation.h operations/COM_SplitViewerOperation.cpp - operations/COM_ConvertValueToColourProg.h - operations/COM_ConvertValueToColourProg.cpp - operations/COM_ConvertColourToValueProg.h - operations/COM_ConvertColourToValueProg.cpp + operations/COM_ConvertValueToColorProg.h + operations/COM_ConvertValueToColorProg.cpp + operations/COM_ConvertColorToValueProg.h + operations/COM_ConvertColorToValueProg.cpp operations/COM_ConvertColorToBWOperation.h operations/COM_ConvertColorToBWOperation.cpp operations/COM_ConvertColorToVectorOperation.h diff --git a/source/blender/compositor/COM_compositor.h b/source/blender/compositor/COM_compositor.h index 86390e5650a..c65ea771477 100644 --- a/source/blender/compositor/COM_compositor.h +++ b/source/blender/compositor/COM_compositor.h @@ -299,6 +299,19 @@ extern "C" { */ void COM_execute(RenderData* rd, bNodeTree *editingtree, int rendering); +/** + * @brief Return a list of highlighted bnodes pointers. + * @return + */ +void COM_startReadHighlights(void); + +/** + * @brief check if a bnode is highlighted + * @param bnode + * @return + */ +int COM_isHighlightedbNode(bNode* bnode); + #ifdef __cplusplus } #endif diff --git a/source/blender/compositor/intern/COM_CompositorContext.cpp b/source/blender/compositor/intern/COM_CompositorContext.cpp index 56335630b80..fbdb4cd6b28 100644 --- a/source/blender/compositor/intern/COM_CompositorContext.cpp +++ b/source/blender/compositor/intern/COM_CompositorContext.cpp @@ -30,6 +30,7 @@ CompositorContext::CompositorContext() this->m_quality = COM_QUALITY_HIGH; this->m_hasActiveOpenCLDevices = false; this->m_activegNode = NULL; + this->m_fastCalculation = false; } const int CompositorContext::getFramenumber() const diff --git a/source/blender/compositor/intern/COM_CompositorContext.h b/source/blender/compositor/intern/COM_CompositorContext.h index 49acda811f1..2f6abf39985 100644 --- a/source/blender/compositor/intern/COM_CompositorContext.h +++ b/source/blender/compositor/intern/COM_CompositorContext.h @@ -73,6 +73,11 @@ private: * @brief does this system have active opencl devices? */ bool m_hasActiveOpenCLDevices; + + /** + * @brief Skip slow nodes + */ + bool m_fastCalculation; public: /** @@ -148,6 +153,9 @@ public: int getChunksize() { return this->getbNodeTree()->chunksize; } const int isColorManaged() const; + + void setFastCalculation(bool fastCalculation) {this->m_fastCalculation = fastCalculation;} + bool isFastCalculation() {return this->m_fastCalculation;} }; diff --git a/source/blender/compositor/intern/COM_Converter.cpp b/source/blender/compositor/intern/COM_Converter.cpp index c8b6503c9c5..37d38261ea5 100644 --- a/source/blender/compositor/intern/COM_Converter.cpp +++ b/source/blender/compositor/intern/COM_Converter.cpp @@ -48,8 +48,8 @@ #include "COM_CompositorNode.h" #include "COM_ConvertAlphaNode.h" #include "COM_ConvertColorToVectorOperation.h" -#include "COM_ConvertColourToValueProg.h" -#include "COM_ConvertValueToColourProg.h" +#include "COM_ConvertColorToValueProg.h" +#include "COM_ConvertValueToColorProg.h" #include "COM_ConvertValueToVectorOperation.h" #include "COM_ConvertVectorToColorOperation.h" #include "COM_ConvertVectorToValueOperation.h" @@ -118,7 +118,7 @@ #include "COM_ViewerNode.h" #include "COM_ZCombineNode.h" -Node *Converter::convert(bNode *b_node) +Node *Converter::convert(bNode *b_node, bool fast) { Node *node; @@ -126,6 +126,22 @@ Node *Converter::convert(bNode *b_node) node = new MuteNode(b_node); return node; } + if (fast) { + if (b_node->type == CMP_NODE_BLUR || + b_node->type == CMP_NODE_VECBLUR || + b_node->type == CMP_NODE_BILATERALBLUR || + b_node->type == CMP_NODE_DEFOCUS || + b_node->type == CMP_NODE_BOKEHBLUR || + b_node->type == CMP_NODE_GLARE || + b_node->type == CMP_NODE_DBLUR || + b_node->type == CMP_NODE_MOVIEDISTORTION || + b_node->type == CMP_NODE_LENSDIST || + b_node->type == CMP_NODE_DOUBLEEDGEMASK || + b_node->type == CMP_NODE_DILATEERODE) + { + return new MuteNode(b_node); + } + } switch (b_node->type) { case CMP_NODE_COMPOSITE: @@ -138,7 +154,7 @@ Node *Converter::convert(bNode *b_node) node = new TextureNode(b_node); break; case CMP_NODE_RGBTOBW: - node = new ColourToBWNode(b_node); + node = new ColorToBWNode(b_node); break; case CMP_NODE_MIX_RGB: node = new MixNode(b_node); @@ -380,13 +396,13 @@ void Converter::convertDataType(SocketConnection *connection, ExecutionSystem *s DataType toDatatype = inputSocket->getDataType(); NodeOperation *converter = NULL; if (fromDatatype == COM_DT_VALUE && toDatatype == COM_DT_COLOR) { - converter = new ConvertValueToColourProg(); + converter = new ConvertValueToColorProg(); } else if (fromDatatype == COM_DT_VALUE && toDatatype == COM_DT_VECTOR) { converter = new ConvertValueToVectorOperation(); } else if (fromDatatype == COM_DT_COLOR && toDatatype == COM_DT_VALUE) { - converter = new ConvertColourToValueProg(); + converter = new ConvertColorToValueProg(); } else if (fromDatatype == COM_DT_COLOR && toDatatype == COM_DT_VECTOR) { converter = new ConvertColorToVectorOperation(); diff --git a/source/blender/compositor/intern/COM_Converter.h b/source/blender/compositor/intern/COM_Converter.h index dbe98871c50..15bda0839fa 100644 --- a/source/blender/compositor/intern/COM_Converter.h +++ b/source/blender/compositor/intern/COM_Converter.h @@ -42,7 +42,7 @@ public: * @see Node * @see MuteNode */ - static Node *convert(bNode *b_node); + static Node *convert(bNode *b_node, bool fast); /** * @brief This method will add a datetype conversion rule when the to-socket does not support the from-socket actual data type. diff --git a/source/blender/compositor/intern/COM_ExecutionGroup.cpp b/source/blender/compositor/intern/COM_ExecutionGroup.cpp index 2d3d24b296f..90f4ba85c78 100644 --- a/source/blender/compositor/intern/COM_ExecutionGroup.cpp +++ b/source/blender/compositor/intern/COM_ExecutionGroup.cpp @@ -25,9 +25,6 @@ #include <sstream> #include <stdlib.h> -#include "BLI_math.h" -#include "PIL_time.h" - #include "COM_ExecutionGroup.h" #include "COM_InputSocket.h" #include "COM_SocketConnection.h" @@ -41,6 +38,11 @@ #include "COM_ChunkOrder.h" #include "COM_ExecutionSystemHelper.h" +#include "BLI_math.h" +#include "PIL_time.h" +#include "WM_api.h" +#include "WM_types.h" + ExecutionGroup::ExecutionGroup() { this->m_isOutput = false; @@ -347,6 +349,8 @@ void ExecutionGroup::execute(ExecutionSystem *graph) finished = false; startEvaluated = true; numberEvaluated++; + + WM_main_add_notifier(NC_WINDOW | ND_DRAW, NULL); } else if (state == COM_ES_SCHEDULED) { finished = false; diff --git a/source/blender/compositor/intern/COM_ExecutionSystem.cpp b/source/blender/compositor/intern/COM_ExecutionSystem.cpp index 23e243187d5..ff841092848 100644 --- a/source/blender/compositor/intern/COM_ExecutionSystem.cpp +++ b/source/blender/compositor/intern/COM_ExecutionSystem.cpp @@ -44,9 +44,10 @@ #include "MEM_guardedalloc.h" #endif -ExecutionSystem::ExecutionSystem(RenderData *rd, bNodeTree *editingtree, bool rendering) +ExecutionSystem::ExecutionSystem(RenderData *rd, bNodeTree *editingtree, bool rendering, bool fastcalculation) { this->m_context.setbNodeTree(editingtree); + this->m_context.setFastCalculation(fastcalculation); bNode *gnode; for (gnode = (bNode *)editingtree->nodes.first; gnode; gnode = (bNode *)gnode->next) { if (gnode->type == NODE_GROUP && gnode->typeinfo->group_edit_get(gnode)) { @@ -137,8 +138,10 @@ void ExecutionSystem::execute() WorkScheduler::start(this->m_context); executeGroups(COM_PRIORITY_HIGH); - executeGroups(COM_PRIORITY_MEDIUM); - executeGroups(COM_PRIORITY_LOW); + if (!this->getContext().isFastCalculation()) { + executeGroups(COM_PRIORITY_MEDIUM); + executeGroups(COM_PRIORITY_LOW); + } WorkScheduler::finish(); WorkScheduler::stop(); diff --git a/source/blender/compositor/intern/COM_ExecutionSystem.h b/source/blender/compositor/intern/COM_ExecutionSystem.h index e51bd7f3026..209358ec786 100644 --- a/source/blender/compositor/intern/COM_ExecutionSystem.h +++ b/source/blender/compositor/intern/COM_ExecutionSystem.h @@ -156,7 +156,7 @@ public: * @param editingtree [bNodeTree*] * @param rendering [true false] */ - ExecutionSystem(RenderData *rd, bNodeTree *editingtree, bool rendering); + ExecutionSystem(RenderData *rd, bNodeTree *editingtree, bool rendering, bool fastcalculation); /** * Destructor diff --git a/source/blender/compositor/intern/COM_ExecutionSystemHelper.cpp b/source/blender/compositor/intern/COM_ExecutionSystemHelper.cpp index 0f6ba1f4ac9..4627d20ab2f 100644 --- a/source/blender/compositor/intern/COM_ExecutionSystemHelper.cpp +++ b/source/blender/compositor/intern/COM_ExecutionSystemHelper.cpp @@ -49,7 +49,7 @@ void ExecutionSystemHelper::addbNodeTree(ExecutionSystem &system, int nodes_star /* add all nodes of the tree to the node list */ bNode *node = (bNode *)tree->nodes.first; while (node != NULL) { - addNode(nodes, node, isActiveGroup); + addNode(nodes, node, isActiveGroup, system.getContext().isFastCalculation()); node = (bNode *)node->next; } @@ -77,11 +77,10 @@ void ExecutionSystemHelper::addNode(vector<Node *>& nodes, Node *node) nodes.push_back(node); } -Node *ExecutionSystemHelper::addNode(vector<Node *>& nodes, bNode *b_node, bool inActiveGroup) +Node *ExecutionSystemHelper::addNode(vector<Node *>& nodes, bNode *b_node, bool inActiveGroup, bool fast) { - Converter converter; Node *node; - node = converter.convert(b_node); + node = Converter::convert(b_node, fast); node->setIsInActiveGroup(inActiveGroup); if (node != NULL) { addNode(nodes, node); diff --git a/source/blender/compositor/intern/COM_ExecutionSystemHelper.h b/source/blender/compositor/intern/COM_ExecutionSystemHelper.h index 4b65ed15577..bd34fe8ab02 100644 --- a/source/blender/compositor/intern/COM_ExecutionSystemHelper.h +++ b/source/blender/compositor/intern/COM_ExecutionSystemHelper.h @@ -58,7 +58,7 @@ public: * @param bNode node to add * @return Node that represents the bNode or null when not able to convert. */ - static Node *addNode(vector<Node *>& nodes, bNode *b_node, bool isInActiveGroup); + static Node *addNode(vector<Node *>& nodes, bNode *b_node, bool isInActiveGroup, bool fast); /** * @brief Add a Node to a list diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.cpp b/source/blender/compositor/intern/COM_MemoryBuffer.cpp index 8dd1e55274f..223c582d999 100644 --- a/source/blender/compositor/intern/COM_MemoryBuffer.cpp +++ b/source/blender/compositor/intern/COM_MemoryBuffer.cpp @@ -22,8 +22,7 @@ #include "COM_MemoryBuffer.h" #include "MEM_guardedalloc.h" -#include "BLI_math.h" -#include "BKE_global.h" +//#include "BKE_global.h" unsigned int MemoryBuffer::determineBufferSize() { @@ -117,20 +116,6 @@ void MemoryBuffer::copyContentFrom(MemoryBuffer *otherBuffer) } } -void MemoryBuffer::read(float result[4], int x, int y) -{ - if (x >= this->m_rect.xmin && x < this->m_rect.xmax && - y >= this->m_rect.ymin && y < this->m_rect.ymax) - { - const int dx = x - this->m_rect.xmin; - const int dy = y - this->m_rect.ymin; - const int offset = (this->m_chunkWidth * dy + dx) * COM_NUMBER_OF_CHANNELS; - copy_v4_v4(result, &this->m_buffer[offset]); - } - else { - zero_v4(result); - } -} void MemoryBuffer::writePixel(int x, int y, const float color[4]) { if (x >= this->m_rect.xmin && x < this->m_rect.xmax && @@ -151,44 +136,6 @@ void MemoryBuffer::addPixel(int x, int y, const float color[4]) } } -void MemoryBuffer::readCubic(float result[4], float x, float y) -{ - int x1 = floor(x); - int x2 = x1 + 1; - int y1 = floor(y); - int y2 = y1 + 1; - - float valuex = x - x1; - float valuey = y - y1; - float mvaluex = 1.0f - valuex; - float mvaluey = 1.0f - valuey; - - float color1[4]; - float color2[4]; - float color3[4]; - float color4[4]; - - read(color1, x1, y1); - read(color2, x1, y2); - read(color3, x2, y1); - read(color4, x2, y2); - - color1[0] = color1[0] * mvaluey + color2[0] * valuey; - color1[1] = color1[1] * mvaluey + color2[1] * valuey; - color1[2] = color1[2] * mvaluey + color2[2] * valuey; - color1[3] = color1[3] * mvaluey + color2[3] * valuey; - - color3[0] = color3[0] * mvaluey + color4[0] * valuey; - color3[1] = color3[1] * mvaluey + color4[1] * valuey; - color3[2] = color3[2] * mvaluey + color4[2] * valuey; - color3[3] = color3[3] * mvaluey + color4[3] * valuey; - - result[0] = color1[0] * mvaluex + color3[0] * valuex; - result[1] = color1[1] * mvaluex + color3[1] * valuex; - result[2] = color1[2] * mvaluex + color3[2] * valuex; - result[3] = color1[3] * mvaluex + color3[3] * valuex; -} - // table of (exp(ar) - exp(a)) / (1 - exp(a)) for r in range [0, 1] and a = -2 // used instead of actual gaussian, otherwise at high texture magnifications circular artifacts are visible diff --git a/source/blender/compositor/intern/COM_MemoryBuffer.h b/source/blender/compositor/intern/COM_MemoryBuffer.h index 63b41aeddde..51a45efc051 100644 --- a/source/blender/compositor/intern/COM_MemoryBuffer.h +++ b/source/blender/compositor/intern/COM_MemoryBuffer.h @@ -28,10 +28,12 @@ class MemoryBuffer; #include "COM_ExecutionGroup.h" #include "BLI_rect.h" #include "COM_MemoryProxy.h" + extern "C" { - #include "BLI_threads.h" + //#include "BLI_threads.h" + #include "BLI_math.h" } -#include <vector> +//#include <vector> /** * @brief state of a memory buffer @@ -124,10 +126,62 @@ public: this->m_state = COM_MB_AVAILABLE; } - void read(float result[4], int x, int y); + inline void read(float result[4], int x, int y) { + if (x >= this->m_rect.xmin && x < this->m_rect.xmax && + y >= this->m_rect.ymin && y < this->m_rect.ymax) + { + const int dx = x - this->m_rect.xmin; + const int dy = y - this->m_rect.ymin; + const int offset = (this->m_chunkWidth * dy + dx) * COM_NUMBER_OF_CHANNELS; + copy_v4_v4(result, &this->m_buffer[offset]); + } + else { + zero_v4(result); + } + } + void writePixel(int x, int y, const float color[4]); void addPixel(int x, int y, const float color[4]); - void readCubic(float result[4], float x, float y); + inline void readCubic(float result[4], float x, float y) + { + int x1 = floor(x); + int x2 = x1 + 1; + int y1 = floor(y); + int y2 = y1 + 1; + + float valuex = x - x1; + float valuey = y - y1; + float mvaluex = 1.0f - valuex; + float mvaluey = 1.0f - valuey; + + float color1[4]; + float color2[4]; + float color3[4]; + float color4[4]; + + read(color1, x1, y1); + read(color2, x1, y2); + read(color3, x2, y1); + read(color4, x2, y2); + + color1[0] = color1[0] * mvaluey + color2[0] * valuey; + color1[1] = color1[1] * mvaluey + color2[1] * valuey; + color1[2] = color1[2] * mvaluey + color2[2] * valuey; + color1[3] = color1[3] * mvaluey + color2[3] * valuey; + + color3[0] = color3[0] * mvaluey + color4[0] * valuey; + color3[1] = color3[1] * mvaluey + color4[1] * valuey; + color3[2] = color3[2] * mvaluey + color4[2] * valuey; + color3[3] = color3[3] * mvaluey + color4[3] * valuey; + + result[0] = color1[0] * mvaluex + color3[0] * valuex; + result[1] = color1[1] * mvaluex + color3[1] * valuex; + result[2] = color1[2] * mvaluex + color3[2] * valuex; + result[3] = color1[3] * mvaluex + color3[3] * valuex; + } + + + void readEWA(float result[4], float fx, float fy, float dx, float dy); /** diff --git a/source/blender/compositor/intern/COM_Node.cpp b/source/blender/compositor/intern/COM_Node.cpp index 15b8a3933a7..320baacb669 100644 --- a/source/blender/compositor/intern/COM_Node.cpp +++ b/source/blender/compositor/intern/COM_Node.cpp @@ -39,9 +39,9 @@ //#include <stdio.h> #include "COM_defines.h" -Node::Node(bNode *editorNode, bool create_sockets) +Node::Node(bNode *editorNode, bool create_sockets): NodeBase() { - this->m_editorNode = editorNode; + setbNode(editorNode); if (create_sockets) { bNodeSocket *input = (bNodeSocket *)editorNode->inputs.first; @@ -64,15 +64,6 @@ Node::Node(bNode *editorNode, bool create_sockets) } } } -Node::Node() -{ - this->m_editorNode = NULL; -} - -bNode *Node::getbNode() -{ - return this->m_editorNode; -} void Node::addSetValueOperation(ExecutionSystem *graph, InputSocket *inputsocket, int editorNodeInputSocketIndex) { diff --git a/source/blender/compositor/intern/COM_Node.h b/source/blender/compositor/intern/COM_Node.h index 5d6d232f37a..bc4a25db605 100644 --- a/source/blender/compositor/intern/COM_Node.h +++ b/source/blender/compositor/intern/COM_Node.h @@ -48,10 +48,6 @@ typedef pair<NodeIterator, NodeIterator> NodeRange; */ class Node : public NodeBase { private: - /** - * @brief stores the reference to the SDNA bNode struct - */ - bNode *m_editorNode; /** * @brief Is this node part of the active group @@ -60,12 +56,7 @@ private: public: Node(bNode *editorNode, bool create_sockets = true); - - /** - * @brief get the reference to the SDNA bNode struct - */ - bNode *getbNode(); - + /** * @brief Is this node in the active group (the group that is being edited) * @param isInActiveGroup @@ -137,9 +128,6 @@ public: */ OutputSocket *findOutputSocketBybNodeSocket(bNodeSocket *socket); protected: - - Node(); - void addPreviewOperation(ExecutionSystem *system, InputSocket *inputSocket); void addPreviewOperation(ExecutionSystem *system, OutputSocket *outputSocket); diff --git a/source/blender/compositor/intern/COM_NodeBase.cpp b/source/blender/compositor/intern/COM_NodeBase.cpp index 8dbda5f649c..5c2ce37bdea 100644 --- a/source/blender/compositor/intern/COM_NodeBase.cpp +++ b/source/blender/compositor/intern/COM_NodeBase.cpp @@ -33,7 +33,7 @@ NodeBase::NodeBase() { - /* pass */ + this->m_editorNode = NULL; } diff --git a/source/blender/compositor/intern/COM_NodeBase.h b/source/blender/compositor/intern/COM_NodeBase.h index 7095cda39e3..3c390f6bcdb 100644 --- a/source/blender/compositor/intern/COM_NodeBase.h +++ b/source/blender/compositor/intern/COM_NodeBase.h @@ -54,6 +54,11 @@ private: */ vector<OutputSocket *> m_outputsockets; + /** + * @brief stores the reference to the SDNA bNode struct + */ + bNode *m_editorNode; + protected: /** * @brief get access to the vector of input sockets @@ -74,6 +79,18 @@ public: virtual ~NodeBase(); /** + * @brief get the reference to the SDNA bNode struct + */ + bNode *getbNode() {return m_editorNode;} + + /** + * @brief set the reference to the bNode + * @note used in Node instances to receive the storage/settings and complex node for highlight during execution + * @param bNode + */ + void setbNode(bNode *bNode) {this->m_editorNode = bNode;} + + /** * @brief is this node an operation? * This is true when the instance is of the subclass NodeOperation. * @return [true:false] diff --git a/source/blender/compositor/intern/COM_NodeOperation.cpp b/source/blender/compositor/intern/COM_NodeOperation.cpp index 6ef8a5ff078..c3fa308971c 100644 --- a/source/blender/compositor/intern/COM_NodeOperation.cpp +++ b/source/blender/compositor/intern/COM_NodeOperation.cpp @@ -28,7 +28,7 @@ #include "COM_SocketConnection.h" #include "COM_defines.h" -NodeOperation::NodeOperation() +NodeOperation::NodeOperation() : NodeBase() { this->m_resolutionInputSocketIndex = 0; this->m_complex = false; diff --git a/source/blender/compositor/intern/COM_WorkScheduler.cpp b/source/blender/compositor/intern/COM_WorkScheduler.cpp index c49ac24e018..c7544be1bb4 100644 --- a/source/blender/compositor/intern/COM_WorkScheduler.cpp +++ b/source/blender/compositor/intern/COM_WorkScheduler.cpp @@ -30,6 +30,7 @@ #include "COM_OpenCLDevice.h" #include "COM_OpenCLKernels.cl.h" #include "OCL_opencl.h" +#include "COM_WriteBufferOperation.h" #include "PIL_time.h" #include "BLI_threads.h" @@ -65,6 +66,55 @@ static bool g_openclActive = false; #endif #endif +#define MAX_HIGHLIGHT 8 +extern "C" { +int g_highlightIndex; +void ** g_highlightedNodes; +void ** g_highlightedNodesRead; + +#define HIGHLIGHT(wp) \ +{ \ + ExecutionGroup* group = wp->getExecutionGroup(); \ + if (group->isComplex()) { \ + NodeOperation* operation = group->getOutputNodeOperation(); \ + if (operation->isWriteBufferOperation()) {\ + WriteBufferOperation *writeOperation = (WriteBufferOperation*)operation;\ + NodeOperation *complexOperation = writeOperation->getInput(); \ + bNode *node = complexOperation->getbNode(); \ + if (node) { \ + if (node->original) { \ + node = node->original;\ + }\ + if (g_highlightIndex < MAX_HIGHLIGHT) {\ + g_highlightedNodes[g_highlightIndex++] = node;\ + }\ + } \ + } \ + } \ +} +void COM_startReadHighlights() { + if (g_highlightedNodesRead) { + delete g_highlightedNodesRead; + } + + g_highlightedNodesRead = g_highlightedNodes; + g_highlightedNodes = new void*[MAX_HIGHLIGHT]; + g_highlightIndex = 0; + for (int i = 0 ; i < MAX_HIGHLIGHT; i++) { + g_highlightedNodes[i] = 0; + } +} + +int COM_isHighlightedbNode(bNode* bnode) { + if (!g_highlightedNodesRead) return false; + for (int i = 0 ; i < MAX_HIGHLIGHT; i++) { + void* p = g_highlightedNodesRead[i]; + if (!p) return false; + if (p == bnode) return true; + } + return false; +} +} // end extern "C" #if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE void *WorkScheduler::thread_execute_cpu(void *data) @@ -73,6 +123,7 @@ void *WorkScheduler::thread_execute_cpu(void *data) WorkPackage *work; while ((work = (WorkPackage *)BLI_thread_queue_pop(g_cpuqueue))) { + HIGHLIGHT(work); device->execute(work); delete work; } @@ -86,6 +137,7 @@ void *WorkScheduler::thread_execute_gpu(void *data) WorkPackage *work; while ((work = (WorkPackage *)BLI_thread_queue_pop(g_gpuqueue))) { + HIGHLIGHT(work); device->execute(work); delete work; } @@ -197,6 +249,9 @@ extern void clContextError(const char *errinfo, const void *private_info, size_t void WorkScheduler::initialize() { + g_highlightedNodesRead = 0; + g_highlightedNodes = 0; + COM_startReadHighlights(); #if COM_CURRENT_THREADING_MODEL == COM_TM_QUEUE int numberOfCPUThreads = BLI_system_thread_count(); @@ -291,3 +346,4 @@ void WorkScheduler::deinitialize() #endif #endif } + diff --git a/source/blender/compositor/intern/COM_compositor.cpp b/source/blender/compositor/intern/COM_compositor.cpp index 7282cf65bc3..ab64f8f7bf1 100644 --- a/source/blender/compositor/intern/COM_compositor.cpp +++ b/source/blender/compositor/intern/COM_compositor.cpp @@ -57,8 +57,23 @@ void COM_execute(RenderData *rd, bNodeTree *editingtree, int rendering) /* set progress bar to 0% and status to init compositing*/ editingtree->progress(editingtree->prh, 0.0); + bool twopass = (editingtree->flag&NTREE_TWO_PASS) > 0 && !rendering; /* initialize execution system */ - ExecutionSystem *system = new ExecutionSystem(rd, editingtree, rendering); + if (twopass) { + ExecutionSystem *system = new ExecutionSystem(rd, editingtree, rendering, twopass); + system->execute(); + delete system; + + if (editingtree->test_break(editingtree->tbh)) { + // during editing multiple calls to this method can be triggered. + // make sure one the last one will be doing the work. + BLI_mutex_unlock(&compositorMutex); + return; + } + } + + + ExecutionSystem *system = new ExecutionSystem(rd, editingtree, rendering, false); system->execute(); delete system; diff --git a/source/blender/compositor/nodes/COM_BilateralBlurNode.cpp b/source/blender/compositor/nodes/COM_BilateralBlurNode.cpp index f96a92068f4..683093302c1 100644 --- a/source/blender/compositor/nodes/COM_BilateralBlurNode.cpp +++ b/source/blender/compositor/nodes/COM_BilateralBlurNode.cpp @@ -35,6 +35,7 @@ void BilateralBlurNode::convertToOperations(ExecutionSystem *graph, CompositorCo { NodeBilateralBlurData *data = (NodeBilateralBlurData *)this->getbNode()->storage; BilateralBlurOperation *operation = new BilateralBlurOperation(); + operation->setbNode(this->getbNode()); operation->setQuality(context->getQuality()); operation->setData(data); this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); diff --git a/source/blender/compositor/nodes/COM_BlurNode.cpp b/source/blender/compositor/nodes/COM_BlurNode.cpp index 1b541d81c33..5447652c238 100644 --- a/source/blender/compositor/nodes/COM_BlurNode.cpp +++ b/source/blender/compositor/nodes/COM_BlurNode.cpp @@ -49,6 +49,7 @@ void BlurNode::convertToOperations(ExecutionSystem *graph, CompositorContext *co if (data->filtertype == R_FILTER_FAST_GAUSS) { FastGaussianBlurOperation *operationfgb = new FastGaussianBlurOperation(); operationfgb->setData(data); + operationfgb->setbNode(editorNode); this->getInputSocket(0)->relinkConnections(operationfgb->getInputSocket(0), 0, graph); this->getInputSocket(1)->relinkConnections(operationfgb->getInputSocket(1), 1, graph); this->getOutputSocket(0)->relinkConnections(operationfgb->getOutputSocket(0)); @@ -58,12 +59,14 @@ void BlurNode::convertToOperations(ExecutionSystem *graph, CompositorContext *co else if (!data->bokeh) { GaussianXBlurOperation *operationx = new GaussianXBlurOperation(); operationx->setData(data); + operationx->setbNode(editorNode); operationx->setQuality(quality); this->getInputSocket(0)->relinkConnections(operationx->getInputSocket(0), 0, graph); this->getInputSocket(1)->relinkConnections(operationx->getInputSocket(1), 1, graph); graph->addOperation(operationx); GaussianYBlurOperation *operationy = new GaussianYBlurOperation(); operationy->setData(data); + operationy->setbNode(editorNode); operationy->setQuality(quality); this->getOutputSocket(0)->relinkConnections(operationy->getOutputSocket()); graph->addOperation(operationy); @@ -79,6 +82,7 @@ void BlurNode::convertToOperations(ExecutionSystem *graph, CompositorContext *co else { GaussianBokehBlurOperation *operation = new GaussianBokehBlurOperation(); operation->setData(data); + operation->setbNode(editorNode); this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), 1, graph); operation->setQuality(quality); diff --git a/source/blender/compositor/nodes/COM_BokehBlurNode.cpp b/source/blender/compositor/nodes/COM_BokehBlurNode.cpp index 59ec9525fa6..0ea4b20c793 100644 --- a/source/blender/compositor/nodes/COM_BokehBlurNode.cpp +++ b/source/blender/compositor/nodes/COM_BokehBlurNode.cpp @@ -61,6 +61,7 @@ void BokehBlurNode::convertToOperations(ExecutionSystem *graph, CompositorContex 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()); // } diff --git a/source/blender/compositor/nodes/COM_ColorToBWNode.cpp b/source/blender/compositor/nodes/COM_ColorToBWNode.cpp index 430f317eae2..511fdf09f41 100644 --- a/source/blender/compositor/nodes/COM_ColorToBWNode.cpp +++ b/source/blender/compositor/nodes/COM_ColorToBWNode.cpp @@ -25,18 +25,18 @@ #include "COM_ConvertColorToBWOperation.h" #include "COM_ExecutionSystem.h" -ColourToBWNode::ColourToBWNode(bNode *editorNode) : Node(editorNode) +ColorToBWNode::ColorToBWNode(bNode *editorNode) : Node(editorNode) { /* pass */ } -void ColourToBWNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context) +void ColorToBWNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context) { - InputSocket *colourSocket = this->getInputSocket(0); + InputSocket *colorSocket = this->getInputSocket(0); OutputSocket *valueSocket = this->getOutputSocket(0); ConvertColorToBWOperation *convertProg = new ConvertColorToBWOperation(); - colourSocket->relinkConnections(convertProg->getInputSocket(0), 0, graph); + colorSocket->relinkConnections(convertProg->getInputSocket(0), 0, graph); valueSocket->relinkConnections(convertProg->getOutputSocket(0)); graph->addOperation(convertProg); } diff --git a/source/blender/compositor/nodes/COM_ColorToBWNode.h b/source/blender/compositor/nodes/COM_ColorToBWNode.h index 9262634edda..f21c6ecef52 100644 --- a/source/blender/compositor/nodes/COM_ColorToBWNode.h +++ b/source/blender/compositor/nodes/COM_ColorToBWNode.h @@ -20,18 +20,18 @@ * Monique Dewanchand */ -#ifndef _COM_ColourToBWNode_h_ -#define _COM_ColourToBWNode_h_ +#ifndef _COM_ColorToBWNode_h_ +#define _COM_ColorToBWNode_h_ #include "COM_Node.h" #include "DNA_node_types.h" /** - * @brief ColourToBWNode + * @brief ColorToBWNode * @ingroup Node */ -class ColourToBWNode : public Node { +class ColorToBWNode : public Node { public: - ColourToBWNode(bNode *editorNode); + ColorToBWNode(bNode *editorNode); void convertToOperations(ExecutionSystem *graph, CompositorContext *context); }; #endif diff --git a/source/blender/compositor/nodes/COM_CompositorNode.cpp b/source/blender/compositor/nodes/COM_CompositorNode.cpp index 6a6f2d1b4ff..28e466203c4 100644 --- a/source/blender/compositor/nodes/COM_CompositorNode.cpp +++ b/source/blender/compositor/nodes/COM_CompositorNode.cpp @@ -34,12 +34,12 @@ void CompositorNode::convertToOperations(ExecutionSystem *graph, CompositorConte InputSocket *imageSocket = this->getInputSocket(0); InputSocket *alphaSocket = this->getInputSocket(1); if (imageSocket->isConnected()) { - CompositorOperation *colourAlphaProg = new CompositorOperation(); - colourAlphaProg->setRenderData(context->getRenderData()); - colourAlphaProg->setbNodeTree(context->getbNodeTree()); - imageSocket->relinkConnections(colourAlphaProg->getInputSocket(0)); - alphaSocket->relinkConnections(colourAlphaProg->getInputSocket(1)); - graph->addOperation(colourAlphaProg); - addPreviewOperation(graph, colourAlphaProg->getInputSocket(0)); + CompositorOperation *colorAlphaProg = new CompositorOperation(); + colorAlphaProg->setRenderData(context->getRenderData()); + colorAlphaProg->setbNodeTree(context->getbNodeTree()); + imageSocket->relinkConnections(colorAlphaProg->getInputSocket(0)); + alphaSocket->relinkConnections(colorAlphaProg->getInputSocket(1)); + graph->addOperation(colorAlphaProg); + addPreviewOperation(graph, colorAlphaProg->getInputSocket(0)); } } diff --git a/source/blender/compositor/nodes/COM_DefocusNode.cpp b/source/blender/compositor/nodes/COM_DefocusNode.cpp index 461505871c6..05bf907af5a 100644 --- a/source/blender/compositor/nodes/COM_DefocusNode.cpp +++ b/source/blender/compositor/nodes/COM_DefocusNode.cpp @@ -32,6 +32,7 @@ #include "COM_MathBaseOperation.h" #include "COM_SetValueOperation.h" #include "COM_GammaCorrectOperation.h" +#include "COM_FastGaussianBlurOperation.h" DefocusNode::DefocusNode(bNode *editorNode) : Node(editorNode) { @@ -71,7 +72,12 @@ void DefocusNode::convertToOperations(ExecutionSystem *graph, CompositorContext converter->setMaxRadius(data->maxblur); this->getInputSocket(1)->relinkConnections(converter->getInputSocket(0), 1, graph); graph->addOperation(converter); - radiusOperation = converter; + + FastGaussianBlurValueOperation * blur = new FastGaussianBlurValueOperation(); + addLink(graph, converter->getOutputSocket(0), blur->getInputSocket(0)); + graph->addOperation(blur); + radiusOperation = blur; + converter->setPostBlur(blur); } BokehImageOperation *bokeh = new BokehImageOperation(); @@ -89,7 +95,15 @@ void DefocusNode::convertToOperations(ExecutionSystem *graph, CompositorContext bokeh->setData(bokehdata); bokeh->deleteDataOnFinish(); graph->addOperation(bokeh); - + +#ifdef COM_DEFOCUS_SEARCH + InverseSearchRadiusOperation *search = new InverseSearchRadiusOperation(); + addLink(graph, radiusOperation->getOutputSocket(0), search->getInputSocket(0)); + addLink(graph, depthOperation, search->getInputSocket(1)); + search->setMaxBlur(data->maxblur); + search->setThreshold(data->bthresh); + graph->addOperation(search); +#endif VariableSizeBokehBlurOperation *operation = new VariableSizeBokehBlurOperation(); if (data->preview) { operation->setQuality(COM_QUALITY_LOW); @@ -97,10 +111,13 @@ void DefocusNode::convertToOperations(ExecutionSystem *graph, CompositorContext operation->setQuality(context->getQuality()); } operation->setMaxBlur(data->maxblur); + operation->setbNode(node); operation->setThreshold(data->bthresh); addLink(graph, bokeh->getOutputSocket(), operation->getInputSocket(1)); addLink(graph, radiusOperation->getOutputSocket(), operation->getInputSocket(2)); - addLink(graph, radiusOperation->getInputSocket(0)->getConnection()->getFromSocket(), operation->getInputSocket(3)); +#ifdef COM_DEFOCUS_SEARCH + addLink(graph, search->getOutputSocket(), operation->getInputSocket(4)); +#endif if (data->gamco) { GammaCorrectOperation *correct = new GammaCorrectOperation(); GammaUncorrectOperation *inverse = new GammaUncorrectOperation(); @@ -115,6 +132,5 @@ void DefocusNode::convertToOperations(ExecutionSystem *graph, CompositorContext this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); this->getOutputSocket()->relinkConnections(operation->getOutputSocket()); } - graph->addOperation(operation); } diff --git a/source/blender/compositor/nodes/COM_DilateErodeNode.cpp b/source/blender/compositor/nodes/COM_DilateErodeNode.cpp index 3f4e3736bbe..043ae367fbb 100644 --- a/source/blender/compositor/nodes/COM_DilateErodeNode.cpp +++ b/source/blender/compositor/nodes/COM_DilateErodeNode.cpp @@ -40,6 +40,7 @@ void DilateErodeNode::convertToOperations(ExecutionSystem *graph, CompositorCont bNode *editorNode = this->getbNode(); if (editorNode->custom1 == CMP_NODE_DILATEERODE_DISTANCE_THRESH) { DilateErodeThresholdOperation *operation = new DilateErodeThresholdOperation(); + operation->setbNode(editorNode); operation->setDistance(editorNode->custom2); operation->setInset(editorNode->custom3); @@ -59,6 +60,7 @@ void DilateErodeNode::convertToOperations(ExecutionSystem *graph, CompositorCont else if (editorNode->custom1 == CMP_NODE_DILATEERODE_DISTANCE) { if (editorNode->custom2 > 0) { DilateDistanceOperation *operation = new DilateDistanceOperation(); + operation->setbNode(editorNode); operation->setDistance(editorNode->custom2); this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0)); @@ -66,6 +68,7 @@ void DilateErodeNode::convertToOperations(ExecutionSystem *graph, CompositorCont } else { ErodeDistanceOperation *operation = new ErodeDistanceOperation(); + operation->setbNode(editorNode); operation->setDistance(-editorNode->custom2); this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0)); @@ -90,12 +93,14 @@ void DilateErodeNode::convertToOperations(ExecutionSystem *graph, CompositorCont } GaussianAlphaXBlurOperation *operationx = new GaussianAlphaXBlurOperation(); + operationx->setbNode(editorNode); operationx->setData(data); operationx->setQuality(quality); this->getInputSocket(0)->relinkConnections(operationx->getInputSocket(0), 0, graph); // this->getInputSocket(1)->relinkConnections(operationx->getInputSocket(1), 1, graph); // no size input yet graph->addOperation(operationx); GaussianAlphaYBlurOperation *operationy = new GaussianAlphaYBlurOperation(); + operationy->setbNode(editorNode); operationy->setData(data); operationy->setQuality(quality); this->getOutputSocket(0)->relinkConnections(operationy->getOutputSocket()); @@ -127,6 +132,7 @@ void DilateErodeNode::convertToOperations(ExecutionSystem *graph, CompositorCont else { if (editorNode->custom2 > 0) { DilateStepOperation *operation = new DilateStepOperation(); + operation->setbNode(editorNode); operation->setIterations(editorNode->custom2); this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0)); @@ -134,6 +140,7 @@ void DilateErodeNode::convertToOperations(ExecutionSystem *graph, CompositorCont } else { ErodeStepOperation *operation = new ErodeStepOperation(); + operation->setbNode(editorNode); operation->setIterations(-editorNode->custom2); this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0)); diff --git a/source/blender/compositor/nodes/COM_DoubleEdgeMaskNode.cpp b/source/blender/compositor/nodes/COM_DoubleEdgeMaskNode.cpp index 57c319e7630..ab1d83385c7 100644 --- a/source/blender/compositor/nodes/COM_DoubleEdgeMaskNode.cpp +++ b/source/blender/compositor/nodes/COM_DoubleEdgeMaskNode.cpp @@ -36,6 +36,7 @@ void DoubleEdgeMaskNode::convertToOperations(ExecutionSystem *system, Compositor bNode *bnode = this->getbNode(); operation = new DoubleEdgeMaskOperation(); + operation->setbNode(bnode); operation->setAdjecentOnly(bnode->custom1); operation->setKeepInside(bnode->custom2); diff --git a/source/blender/compositor/nodes/COM_FilterNode.cpp b/source/blender/compositor/nodes/COM_FilterNode.cpp index 23f87805821..021ec6c2508 100644 --- a/source/blender/compositor/nodes/COM_FilterNode.cpp +++ b/source/blender/compositor/nodes/COM_FilterNode.cpp @@ -73,7 +73,7 @@ void FilterNode::convertToOperations(ExecutionSystem *graph, CompositorContext * operation->set3x3Filter(0, 0, 0, 0, 1, 0, 0, 0, 0); break; } - + operation->setbNode(this->getbNode()); inputImageSocket->relinkConnections(operation->getInputSocket(0), 1, graph); inputSocket->relinkConnections(operation->getInputSocket(1), 0, graph); outputSocket->relinkConnections(operation->getOutputSocket()); diff --git a/source/blender/compositor/nodes/COM_GlareNode.cpp b/source/blender/compositor/nodes/COM_GlareNode.cpp index 7b34fa4d286..8782e6bb6d9 100644 --- a/source/blender/compositor/nodes/COM_GlareNode.cpp +++ b/source/blender/compositor/nodes/COM_GlareNode.cpp @@ -63,6 +63,8 @@ void GlareNode::convertToOperations(ExecutionSystem *system, CompositorContext * SetValueOperation *mixvalueoperation = new SetValueOperation(); MixGlareOperation *mixoperation = new MixGlareOperation(); mixoperation->getInputSocket(2)->setResizeMode(COM_SC_FIT); + thresholdOperation->setbNode(node); + glareoperation->setbNode(node); this->getInputSocket(0)->relinkConnections(thresholdOperation->getInputSocket(0), 0, system); addLink(system, thresholdOperation->getOutputSocket(), glareoperation->getInputSocket(0)); diff --git a/source/blender/compositor/nodes/COM_HueSaturationValueCorrectNode.cpp b/source/blender/compositor/nodes/COM_HueSaturationValueCorrectNode.cpp index df125403f98..fd961030ebf 100644 --- a/source/blender/compositor/nodes/COM_HueSaturationValueCorrectNode.cpp +++ b/source/blender/compositor/nodes/COM_HueSaturationValueCorrectNode.cpp @@ -22,7 +22,7 @@ #include "COM_HueSaturationValueCorrectNode.h" -#include "COM_ConvertColourToValueProg.h" +#include "COM_ConvertColorToValueProg.h" #include "COM_ExecutionSystem.h" #include "COM_ConvertRGBToHSVOperation.h" #include "COM_ConvertHSVToRGBOperation.h" @@ -41,7 +41,7 @@ HueSaturationValueCorrectNode::HueSaturationValueCorrectNode(bNode *editorNode) void HueSaturationValueCorrectNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context) { InputSocket *valueSocket = this->getInputSocket(0); - InputSocket *colourSocket = this->getInputSocket(1); + InputSocket *colorSocket = this->getInputSocket(1); OutputSocket *outputSocket = this->getOutputSocket(0); bNode *editorsnode = getbNode(); CurveMapping *storage = (CurveMapping *)editorsnode->storage; @@ -51,7 +51,7 @@ void HueSaturationValueCorrectNode::convertToOperations(ExecutionSystem *graph, HueSaturationValueCorrectOperation *changeHSV = new HueSaturationValueCorrectOperation(); MixBlendOperation *blend = new MixBlendOperation(); - colourSocket->relinkConnections(rgbToHSV->getInputSocket(0), 1, graph); + colorSocket->relinkConnections(rgbToHSV->getInputSocket(0), 1, graph); addLink(graph, rgbToHSV->getOutputSocket(), changeHSV->getInputSocket(0)); addLink(graph, changeHSV->getOutputSocket(), hsvToRGB->getInputSocket(0)); addLink(graph, hsvToRGB->getOutputSocket(), blend->getInputSocket(2)); diff --git a/source/blender/compositor/nodes/COM_HueSaturationValueNode.cpp b/source/blender/compositor/nodes/COM_HueSaturationValueNode.cpp index ef501317e48..9b55b809212 100644 --- a/source/blender/compositor/nodes/COM_HueSaturationValueNode.cpp +++ b/source/blender/compositor/nodes/COM_HueSaturationValueNode.cpp @@ -22,7 +22,7 @@ #include "COM_HueSaturationValueNode.h" -#include "COM_ConvertColourToValueProg.h" +#include "COM_ConvertColorToValueProg.h" #include "COM_ExecutionSystem.h" #include "COM_ConvertRGBToHSVOperation.h" #include "COM_ConvertHSVToRGBOperation.h" @@ -40,7 +40,7 @@ HueSaturationValueNode::HueSaturationValueNode(bNode *editorNode) : Node(editorN void HueSaturationValueNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context) { InputSocket *valueSocket = this->getInputSocket(0); - InputSocket *colourSocket = this->getInputSocket(1); + InputSocket *colorSocket = this->getInputSocket(1); OutputSocket *outputSocket = this->getOutputSocket(0); bNode *editorsnode = getbNode(); NodeHueSat *storage = (NodeHueSat *)editorsnode->storage; @@ -50,7 +50,7 @@ void HueSaturationValueNode::convertToOperations(ExecutionSystem *graph, Composi ChangeHSVOperation *changeHSV = new ChangeHSVOperation(); MixBlendOperation *blend = new MixBlendOperation(); - colourSocket->relinkConnections(rgbToHSV->getInputSocket(0), 0, graph); + colorSocket->relinkConnections(rgbToHSV->getInputSocket(0), 0, graph); addLink(graph, rgbToHSV->getOutputSocket(), changeHSV->getInputSocket(0)); addLink(graph, changeHSV->getOutputSocket(), hsvToRGB->getInputSocket(0)); addLink(graph, hsvToRGB->getOutputSocket(), blend->getInputSocket(2)); diff --git a/source/blender/compositor/nodes/COM_KeyingNode.cpp b/source/blender/compositor/nodes/COM_KeyingNode.cpp index cc6fc6e1236..7c39765fbf1 100644 --- a/source/blender/compositor/nodes/COM_KeyingNode.cpp +++ b/source/blender/compositor/nodes/COM_KeyingNode.cpp @@ -74,9 +74,11 @@ OutputSocket *KeyingNode::setupPreBlur(ExecutionSystem *graph, InputSocket *inpu blurXOperation->setSize(size); blurXOperation->setAxis(KeyingBlurOperation::BLUR_AXIS_X); + blurXOperation->setbNode(this->getbNode()); blurYOperation->setSize(size); blurYOperation->setAxis(KeyingBlurOperation::BLUR_AXIS_Y); + blurYOperation->setbNode(this->getbNode()); addLink(graph, separateOperation->getOutputSocket(), blurXOperation->getInputSocket(0)); addLink(graph, blurXOperation->getOutputSocket(), blurYOperation->getInputSocket(0)); @@ -104,9 +106,11 @@ OutputSocket *KeyingNode::setupPostBlur(ExecutionSystem *graph, OutputSocket *po blurXOperation->setSize(size); blurXOperation->setAxis(KeyingBlurOperation::BLUR_AXIS_X); + blurXOperation->setbNode(this->getbNode()); blurYOperation->setSize(size); blurYOperation->setAxis(KeyingBlurOperation::BLUR_AXIS_Y); + blurYOperation->setbNode(this->getbNode()); addLink(graph, postBlurInput, blurXOperation->getInputSocket(0)); addLink(graph, blurXOperation->getOutputSocket(), blurYOperation->getInputSocket(0)); @@ -129,6 +133,7 @@ OutputSocket *KeyingNode::setupDilateErode(ExecutionSystem *graph, OutputSocket dilateErodeOperation = new ErodeDistanceOperation(); dilateErodeOperation->setDistance(-distance); } + dilateErodeOperation->setbNode(this->getbNode()); addLink(graph, dilateErodeInput, dilateErodeOperation->getInputSocket(0)); @@ -161,14 +166,16 @@ OutputSocket *KeyingNode::setupFeather(ExecutionSystem *graph, CompositorContext operationx->setSize(1.0f); operationx->setSubtract(distance < 0); operationx->setFalloff(falloff); + operationx->setbNode(this->getbNode()); graph->addOperation(operationx); - + GaussianAlphaYBlurOperation *operationy = new GaussianAlphaYBlurOperation(); operationy->setData(data); operationy->setQuality(quality); operationy->setSize(1.0f); operationy->setSubtract(distance < 0); operationy->setFalloff(falloff); + operationy->setbNode(this->getbNode()); graph->addOperation(operationy); addLink(graph, featherInput, operationx->getInputSocket(0)); diff --git a/source/blender/compositor/nodes/COM_KeyingScreenNode.cpp b/source/blender/compositor/nodes/COM_KeyingScreenNode.cpp index 0fb8d45d066..cd1f79235ea 100644 --- a/source/blender/compositor/nodes/COM_KeyingScreenNode.cpp +++ b/source/blender/compositor/nodes/COM_KeyingScreenNode.cpp @@ -45,6 +45,7 @@ void KeyingScreenNode::convertToOperations(ExecutionSystem *graph, CompositorCon // always connect the output image KeyingScreenOperation *operation = new KeyingScreenOperation(); + operation->setbNode(editorNode); if (outputScreen->isConnected()) { outputScreen->relinkConnections(operation->getOutputSocket()); diff --git a/source/blender/compositor/nodes/COM_LensDistortionNode.cpp b/source/blender/compositor/nodes/COM_LensDistortionNode.cpp index bb431f86897..3913b4ac2b6 100644 --- a/source/blender/compositor/nodes/COM_LensDistortionNode.cpp +++ b/source/blender/compositor/nodes/COM_LensDistortionNode.cpp @@ -37,7 +37,7 @@ void LensDistortionNode::convertToOperations(ExecutionSystem *graph, CompositorC NodeLensDist *data = (NodeLensDist *)editorNode->storage; if (data->proj) { ProjectorLensDistortionOperation *operation = new ProjectorLensDistortionOperation(); - + operation->setbNode(editorNode); this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); this->getInputSocket(2)->relinkConnections(operation->getInputSocket(1), 2, graph); this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0)); @@ -48,9 +48,9 @@ void LensDistortionNode::convertToOperations(ExecutionSystem *graph, CompositorC } else { ScreenLensDistortionOperation *operation = new ScreenLensDistortionOperation(); + operation->setbNode(editorNode); operation->setData(data); - if (!(this->getInputSocket(1)->isConnected() || this->getInputSocket(2)->isConnected())) - { + if (!(this->getInputSocket(1)->isConnected() || this->getInputSocket(2)->isConnected())) { // no nodes connected to the distortion and dispersion. We can precalculate some values float distortion = ((const bNodeSocketValueFloat *)this->getInputSocket(1)->getbNodeSocket()->default_value)->value; float dispersion = ((const bNodeSocketValueFloat *)this->getInputSocket(2)->getbNodeSocket()->default_value)->value; diff --git a/source/blender/compositor/nodes/COM_MapValueNode.cpp b/source/blender/compositor/nodes/COM_MapValueNode.cpp index ba2fc804f42..ac57ffed9da 100644 --- a/source/blender/compositor/nodes/COM_MapValueNode.cpp +++ b/source/blender/compositor/nodes/COM_MapValueNode.cpp @@ -32,12 +32,12 @@ MapValueNode::MapValueNode(bNode *editorNode) : Node(editorNode) void MapValueNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context) { - InputSocket *colourSocket = this->getInputSocket(0); + InputSocket *colorSocket = this->getInputSocket(0); OutputSocket *valueSocket = this->getOutputSocket(0); TexMapping *storage = (TexMapping *)this->getbNode()->storage; MapValueOperation *convertProg = new MapValueOperation(); convertProg->setSettings(storage); - colourSocket->relinkConnections(convertProg->getInputSocket(0), 0, graph); + colorSocket->relinkConnections(convertProg->getInputSocket(0), 0, graph); valueSocket->relinkConnections(convertProg->getOutputSocket(0)); graph->addOperation(convertProg); } diff --git a/source/blender/compositor/nodes/COM_MaskNode.cpp b/source/blender/compositor/nodes/COM_MaskNode.cpp index 13037b61a56..b6300300f6f 100644 --- a/source/blender/compositor/nodes/COM_MaskNode.cpp +++ b/source/blender/compositor/nodes/COM_MaskNode.cpp @@ -45,7 +45,7 @@ void MaskNode::convertToOperations(ExecutionSystem *graph, CompositorContext *co // always connect the output image MaskOperation *operation = new MaskOperation(); - + operation->setbNode(editorNode); operation->setMaskWidth(data->xsch * data->size / 100.0f); operation->setMaskHeight(data->ysch * data->size / 100.0f); diff --git a/source/blender/compositor/nodes/COM_MathNode.cpp b/source/blender/compositor/nodes/COM_MathNode.cpp index 300c9967cc4..307590b977b 100644 --- a/source/blender/compositor/nodes/COM_MathNode.cpp +++ b/source/blender/compositor/nodes/COM_MathNode.cpp @@ -83,10 +83,14 @@ void MathNode::convertToOperations(ExecutionSystem *graph, CompositorContext *co } if (operation != NULL) { + bool useClamp = this->getbNode()->custom2; + this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, graph); this->getInputSocket(1)->relinkConnections(operation->getInputSocket(1), 1, graph); this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket()); - + + operation->setUseClamp(useClamp); + graph->addOperation(operation); } } diff --git a/source/blender/compositor/nodes/COM_MixNode.cpp b/source/blender/compositor/nodes/COM_MixNode.cpp index eb62ebd2635..7aeaaf56c98 100644 --- a/source/blender/compositor/nodes/COM_MixNode.cpp +++ b/source/blender/compositor/nodes/COM_MixNode.cpp @@ -58,6 +58,8 @@ void MixNode::convertToOperations(ExecutionSystem *graph, CompositorContext *con InputSocket *color2Socket = this->getInputSocket(2); OutputSocket *outputSocket = this->getOutputSocket(0); bNode *editorNode = this->getbNode(); + bool useAlphaPremultiply = this->getbNode()->custom2 & 1; + bool useClamp = this->getbNode()->custom2 & 2; MixBaseOperation *convertProg; @@ -119,7 +121,8 @@ void MixNode::convertToOperations(ExecutionSystem *graph, CompositorContext *con convertProg = new MixBlendOperation(); break; } - convertProg->setUseValueAlphaMultiply(this->getbNode()->custom2); + convertProg->setUseValueAlphaMultiply(useAlphaPremultiply); + convertProg->setUseClamp(useClamp); valueSocket->relinkConnections(convertProg->getInputSocket(0), 0, graph); color1Socket->relinkConnections(convertProg->getInputSocket(1), 1, graph); diff --git a/source/blender/compositor/nodes/COM_RenderLayersNode.cpp b/source/blender/compositor/nodes/COM_RenderLayersNode.cpp index 95e759fde24..dfb46af841c 100644 --- a/source/blender/compositor/nodes/COM_RenderLayersNode.cpp +++ b/source/blender/compositor/nodes/COM_RenderLayersNode.cpp @@ -82,7 +82,7 @@ void RenderLayersNode::testSocketConnection(ExecutionSystem *system, int outputS void RenderLayersNode::convertToOperations(ExecutionSystem *graph, CompositorContext *context) { - testSocketConnection(graph, 0, new RenderLayersColourProg()); + testSocketConnection(graph, 0, new RenderLayersColorProg()); testSocketConnection(graph, 1, new RenderLayersAlphaProg()); testSocketConnection(graph, 2, new RenderLayersDepthProg()); testSocketConnection(graph, 3, new RenderLayersNormalOperation()); diff --git a/source/blender/compositor/nodes/COM_TonemapNode.cpp b/source/blender/compositor/nodes/COM_TonemapNode.cpp index a1f33ed464b..68e322e9dcf 100644 --- a/source/blender/compositor/nodes/COM_TonemapNode.cpp +++ b/source/blender/compositor/nodes/COM_TonemapNode.cpp @@ -34,7 +34,7 @@ void TonemapNode::convertToOperations(ExecutionSystem *system, CompositorContext { NodeTonemap *data = (NodeTonemap *)this->getbNode()->storage; TonemapOperation *operation = data->type == 1 ? new PhotoreceptorTonemapOperation() : new TonemapOperation(); - + operation->setbNode(this->getbNode()); operation->setData(data); this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, system); this->getOutputSocket(0)->relinkConnections(operation->getOutputSocket(0)); diff --git a/source/blender/compositor/nodes/COM_VectorBlurNode.cpp b/source/blender/compositor/nodes/COM_VectorBlurNode.cpp index 5ef384a9984..07c8120b1d2 100644 --- a/source/blender/compositor/nodes/COM_VectorBlurNode.cpp +++ b/source/blender/compositor/nodes/COM_VectorBlurNode.cpp @@ -34,6 +34,7 @@ void VectorBlurNode::convertToOperations(ExecutionSystem *system, CompositorCont bNode *node = this->getbNode(); NodeBlurData *vectorBlurSettings = (NodeBlurData *)node->storage; VectorBlurOperation *operation = new VectorBlurOperation(); + operation->setbNode(node); operation->setVectorBlurSettings(vectorBlurSettings); operation->setQuality(context->getQuality()); this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, system); diff --git a/source/blender/compositor/operations/COM_AlphaOverKeyOperation.h b/source/blender/compositor/operations/COM_AlphaOverKeyOperation.h index e5b1f56f06c..113ec245ee6 100644 --- a/source/blender/compositor/operations/COM_AlphaOverKeyOperation.h +++ b/source/blender/compositor/operations/COM_AlphaOverKeyOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class AlphaOverKeyOperation : public MixBaseOperation { public: diff --git a/source/blender/compositor/operations/COM_AlphaOverMixedOperation.h b/source/blender/compositor/operations/COM_AlphaOverMixedOperation.h index 24a991da17b..3c0b955e360 100644 --- a/source/blender/compositor/operations/COM_AlphaOverMixedOperation.h +++ b/source/blender/compositor/operations/COM_AlphaOverMixedOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class AlphaOverMixedOperation : public MixBaseOperation { private: diff --git a/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.h b/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.h index bba3b714f6b..7b7b9238794 100644 --- a/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.h +++ b/source/blender/compositor/operations/COM_AlphaOverPremultiplyOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class AlphaOverPremultiplyOperation : public MixBaseOperation { public: diff --git a/source/blender/compositor/operations/COM_BokehBlurOperation.cpp b/source/blender/compositor/operations/COM_BokehBlurOperation.cpp index fb06f6d3761..e83ad4824e4 100644 --- a/source/blender/compositor/operations/COM_BokehBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_BokehBlurOperation.cpp @@ -160,15 +160,13 @@ bool BokehBlurOperation::determineDependingAreaOfInterest(rcti *input, ReadBuffe return false; } -static cl_kernel kernel = 0; void BokehBlurOperation::executeOpenCL(OpenCLDevice* device, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, list<cl_kernel> *clKernelsToCleanUp) { - if (!kernel) { - kernel = device->COM_clCreateKernel("bokehBlurKernel", NULL); - } + cl_kernel kernel = device->COM_clCreateKernel("bokehBlurKernel", NULL); + cl_int radius = this->getWidth() * this->m_size / 100.0f; cl_int step = this->getStep(); diff --git a/source/blender/compositor/operations/COM_ChangeHSVOperation.h b/source/blender/compositor/operations/COM_ChangeHSVOperation.h index 9c343db9c3c..ee35fbe01d4 100644 --- a/source/blender/compositor/operations/COM_ChangeHSVOperation.h +++ b/source/blender/compositor/operations/COM_ChangeHSVOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ChangeHSVOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_ChannelMatteOperation.h b/source/blender/compositor/operations/COM_ChannelMatteOperation.h index 5bc13736dda..ee17036a78d 100644 --- a/source/blender/compositor/operations/COM_ChannelMatteOperation.h +++ b/source/blender/compositor/operations/COM_ChannelMatteOperation.h @@ -25,8 +25,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ChannelMatteOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_ChromaMatteOperation.h b/source/blender/compositor/operations/COM_ChromaMatteOperation.h index 472a797fa28..eaca05e66ca 100644 --- a/source/blender/compositor/operations/COM_ChromaMatteOperation.h +++ b/source/blender/compositor/operations/COM_ChromaMatteOperation.h @@ -25,8 +25,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ChromaMatteOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.h b/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.h index 479927d30d1..a9c0dff9ad4 100644 --- a/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.h +++ b/source/blender/compositor/operations/COM_ColorBalanceASCCDLOperation.h @@ -25,8 +25,8 @@ #include "COM_NodeOperation.h" /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ColorBalanceASCCDLOperation : public NodeOperation { protected: diff --git a/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.h b/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.h index ec3652da09e..ffc78fae6f1 100644 --- a/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.h +++ b/source/blender/compositor/operations/COM_ColorBalanceLGGOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ColorBalanceLGGOperation : public NodeOperation { protected: diff --git a/source/blender/compositor/operations/COM_ColorMatteOperation.h b/source/blender/compositor/operations/COM_ColorMatteOperation.h index ae904f8f938..d996ce34667 100644 --- a/source/blender/compositor/operations/COM_ColorMatteOperation.h +++ b/source/blender/compositor/operations/COM_ColorMatteOperation.h @@ -25,8 +25,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ColorMatteOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_ColorSpillOperation.h b/source/blender/compositor/operations/COM_ColorSpillOperation.h index 6e3156819b2..7aac612cb8c 100644 --- a/source/blender/compositor/operations/COM_ColorSpillOperation.h +++ b/source/blender/compositor/operations/COM_ColorSpillOperation.h @@ -25,8 +25,8 @@ #include "COM_NodeOperation.h" /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ColorSpillOperation : public NodeOperation { protected: diff --git a/source/blender/compositor/operations/COM_ConvertColorProfileOperation.h b/source/blender/compositor/operations/COM_ConvertColorProfileOperation.h index 0b9a07a57ca..b237448d16e 100644 --- a/source/blender/compositor/operations/COM_ConvertColorProfileOperation.h +++ b/source/blender/compositor/operations/COM_ConvertColorProfileOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ConvertColorProfileOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_ConvertColorToBWOperation.h b/source/blender/compositor/operations/COM_ConvertColorToBWOperation.h index 2a57c997196..9c62ad8dd39 100644 --- a/source/blender/compositor/operations/COM_ConvertColorToBWOperation.h +++ b/source/blender/compositor/operations/COM_ConvertColorToBWOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ConvertColorToBWOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_ConvertColourToValueProg.cpp b/source/blender/compositor/operations/COM_ConvertColorToValueProg.cpp index c872f3e85bb..c09842b1aa9 100644 --- a/source/blender/compositor/operations/COM_ConvertColourToValueProg.cpp +++ b/source/blender/compositor/operations/COM_ConvertColorToValueProg.cpp @@ -20,28 +20,28 @@ * Monique Dewanchand */ -#include "COM_ConvertColourToValueProg.h" +#include "COM_ConvertColorToValueProg.h" -ConvertColourToValueProg::ConvertColourToValueProg() : NodeOperation() +ConvertColorToValueProg::ConvertColorToValueProg() : NodeOperation() { this->addInputSocket(COM_DT_COLOR); this->addOutputSocket(COM_DT_VALUE); this->m_inputOperation = NULL; } -void ConvertColourToValueProg::initExecution() +void ConvertColorToValueProg::initExecution() { this->m_inputOperation = this->getInputSocketReader(0); } -void ConvertColourToValueProg::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) +void ConvertColorToValueProg::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) { float inputColor[4]; this->m_inputOperation->read(&inputColor[0], x, y, sampler, inputBuffers); outputValue[0] = (inputColor[0] + inputColor[1] + inputColor[2]) / 3.0f; } -void ConvertColourToValueProg::deinitExecution() +void ConvertColorToValueProg::deinitExecution() { this->m_inputOperation = NULL; } diff --git a/source/blender/compositor/operations/COM_ConvertColourToValueProg.h b/source/blender/compositor/operations/COM_ConvertColorToValueProg.h index ebd4bcbd59b..c1ac7ca69ce 100644 --- a/source/blender/compositor/operations/COM_ConvertColourToValueProg.h +++ b/source/blender/compositor/operations/COM_ConvertColorToValueProg.h @@ -20,16 +20,16 @@ * Monique Dewanchand */ -#ifndef _COM_ConvertColourToValueProg_h -#define _COM_ConvertColourToValueProg_h +#ifndef _COM_ConvertColorToValueProg_h +#define _COM_ConvertColorToValueProg_h #include "COM_NodeOperation.h" /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ -class ConvertColourToValueProg : public NodeOperation { +class ConvertColorToValueProg : public NodeOperation { private: /** * Cached reference to the inputProgram @@ -39,7 +39,7 @@ public: /** * Default constructor */ - ConvertColourToValueProg(); + ConvertColorToValueProg(); /** * the inner loop of this program diff --git a/source/blender/compositor/operations/COM_ConvertColorToVectorOperation.h b/source/blender/compositor/operations/COM_ConvertColorToVectorOperation.h index f9170dfc7aa..51fa3a677cd 100644 --- a/source/blender/compositor/operations/COM_ConvertColorToVectorOperation.h +++ b/source/blender/compositor/operations/COM_ConvertColorToVectorOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ConvertColorToVectorOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.cpp b/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.cpp index 91b68a90126..b4319d25d13 100644 --- a/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.cpp +++ b/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.cpp @@ -32,6 +32,7 @@ ConvertDepthToRadiusOperation::ConvertDepthToRadiusOperation() : NodeOperation() this->m_fStop = 128.0f; this->m_cameraObject = NULL; this->m_maxRadius = 32.0f; + this->m_blurPostOperation = NULL; } float ConvertDepthToRadiusOperation::determineFocalDistance() @@ -68,6 +69,10 @@ void ConvertDepthToRadiusOperation::initExecution() this->m_aperture = 0.5f * (this->m_cam_lens / (this->m_aspect * 32.0f)) / this->m_fStop; float minsz = MIN2(getWidth(), getHeight()); this->m_dof_sp = (float)minsz / (16.f / this->m_cam_lens); // <- == aspect * MIN2(img->x, img->y) / tan(0.5f * fov); + + if (this->m_blurPostOperation) { + m_blurPostOperation->setSigma(m_aperture*128.0f); + } } void ConvertDepthToRadiusOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) @@ -88,7 +93,7 @@ void ConvertDepthToRadiusOperation::executePixel(float *outputValue, float x, fl #endif radius = 0.5f * fabsf(this->m_aperture * (this->m_dof_sp * (this->m_inverseFocalDistance - iZ) - 1.f)); // 'bug' #6615, limit minimum radius to 1 pixel, not really a solution, but somewhat mitigates the problem - if (radius < 0.5f) radius = 0.5f; + if (radius < 0.0f) radius = 0.0f; if (radius > this->m_maxRadius) { radius = this->m_maxRadius; } diff --git a/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.h b/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.h index 966a74c04ad..f0e905db9c2 100644 --- a/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.h +++ b/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.h @@ -24,10 +24,10 @@ #define _COM_ConvertDepthToRadiusOperation_h #include "COM_NodeOperation.h" #include "DNA_object_types.h" - +#include "COM_FastGaussianBlurOperation.h" /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ConvertDepthToRadiusOperation : public NodeOperation { private: @@ -43,6 +43,8 @@ private: float m_cam_lens; float m_dof_sp; Object *m_cameraObject; + + FastGaussianBlurValueOperation *m_blurPostOperation; public: /** * Default constructor @@ -68,5 +70,7 @@ public: void setMaxRadius(float maxRadius) { this->m_maxRadius = maxRadius; } void setCameraObject(Object *camera) { this->m_cameraObject = camera; } float determineFocalDistance(); + void setPostBlur(FastGaussianBlurValueOperation *operation) {this->m_blurPostOperation = operation;} + }; #endif diff --git a/source/blender/compositor/operations/COM_ConvertHSVToRGBOperation.h b/source/blender/compositor/operations/COM_ConvertHSVToRGBOperation.h index f8b6a4c11fa..3babbfb7c1d 100644 --- a/source/blender/compositor/operations/COM_ConvertHSVToRGBOperation.h +++ b/source/blender/compositor/operations/COM_ConvertHSVToRGBOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ConvertHSVToRGBOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_ConvertKeyToPremulOperation.h b/source/blender/compositor/operations/COM_ConvertKeyToPremulOperation.h index 2b5e1871972..50b39928305 100644 --- a/source/blender/compositor/operations/COM_ConvertKeyToPremulOperation.h +++ b/source/blender/compositor/operations/COM_ConvertKeyToPremulOperation.h @@ -25,8 +25,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ConvertKeyToPremulOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_ConvertPremulToKeyOperation.h b/source/blender/compositor/operations/COM_ConvertPremulToKeyOperation.h index 05c6b26b171..173cbb4fc0a 100644 --- a/source/blender/compositor/operations/COM_ConvertPremulToKeyOperation.h +++ b/source/blender/compositor/operations/COM_ConvertPremulToKeyOperation.h @@ -25,8 +25,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ConvertPremulToKeyOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_ConvertRGBToHSVOperation.h b/source/blender/compositor/operations/COM_ConvertRGBToHSVOperation.h index af8a7f78a61..42bd439c8c2 100644 --- a/source/blender/compositor/operations/COM_ConvertRGBToHSVOperation.h +++ b/source/blender/compositor/operations/COM_ConvertRGBToHSVOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ConvertRGBToHSVOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_ConvertRGBToYCCOperation.h b/source/blender/compositor/operations/COM_ConvertRGBToYCCOperation.h index 97fbdb29874..744e0657dc6 100644 --- a/source/blender/compositor/operations/COM_ConvertRGBToYCCOperation.h +++ b/source/blender/compositor/operations/COM_ConvertRGBToYCCOperation.h @@ -25,8 +25,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ConvertRGBToYCCOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_ConvertRGBToYUVOperation.h b/source/blender/compositor/operations/COM_ConvertRGBToYUVOperation.h index 89998897782..b470378704e 100644 --- a/source/blender/compositor/operations/COM_ConvertRGBToYUVOperation.h +++ b/source/blender/compositor/operations/COM_ConvertRGBToYUVOperation.h @@ -25,8 +25,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ConvertRGBToYUVOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_ConvertValueToColourProg.cpp b/source/blender/compositor/operations/COM_ConvertValueToColorProg.cpp index a29a381938f..100a4931d69 100644 --- a/source/blender/compositor/operations/COM_ConvertValueToColourProg.cpp +++ b/source/blender/compositor/operations/COM_ConvertValueToColorProg.cpp @@ -20,20 +20,20 @@ * Monique Dewanchand */ -#include "COM_ConvertValueToColourProg.h" +#include "COM_ConvertValueToColorProg.h" -ConvertValueToColourProg::ConvertValueToColourProg() : NodeOperation() +ConvertValueToColorProg::ConvertValueToColorProg() : NodeOperation() { this->addInputSocket(COM_DT_VALUE); this->addOutputSocket(COM_DT_COLOR); this->m_inputProgram = NULL; } -void ConvertValueToColourProg::initExecution() +void ConvertValueToColorProg::initExecution() { this->m_inputProgram = this->getInputSocketReader(0); } -void ConvertValueToColourProg::executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) +void ConvertValueToColorProg::executePixel(float *color, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) { float inputValue[4]; this->m_inputProgram->read(inputValue, x, y, sampler, inputBuffers); @@ -43,7 +43,7 @@ void ConvertValueToColourProg::executePixel(float *color, float x, float y, Pixe color[3] = 1.0f; } -void ConvertValueToColourProg::deinitExecution() +void ConvertValueToColorProg::deinitExecution() { this->m_inputProgram = NULL; } diff --git a/source/blender/compositor/operations/COM_ConvertValueToColourProg.h b/source/blender/compositor/operations/COM_ConvertValueToColorProg.h index 69ce7e9afea..d59964dd400 100644 --- a/source/blender/compositor/operations/COM_ConvertValueToColourProg.h +++ b/source/blender/compositor/operations/COM_ConvertValueToColorProg.h @@ -20,19 +20,19 @@ * Monique Dewanchand */ -#ifndef _COM_ConvertValueToColourProg_h -#define _COM_ConvertValueToColourProg_h +#ifndef _COM_ConvertValueToColorProg_h +#define _COM_ConvertValueToColorProg_h #include "COM_NodeOperation.h" -class ConvertValueToColourProg : public NodeOperation { +class ConvertValueToColorProg : public NodeOperation { private: /** * Cached reference to the inputProgram */ SocketReader *m_inputProgram; public: - ConvertValueToColourProg(); + ConvertValueToColorProg(); /** * the inner loop of this program diff --git a/source/blender/compositor/operations/COM_ConvertValueToVectorOperation.h b/source/blender/compositor/operations/COM_ConvertValueToVectorOperation.h index 781b31f7fce..0e79c1ff3df 100644 --- a/source/blender/compositor/operations/COM_ConvertValueToVectorOperation.h +++ b/source/blender/compositor/operations/COM_ConvertValueToVectorOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ConvertValueToVectorOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_ConvertVectorToColorOperation.h b/source/blender/compositor/operations/COM_ConvertVectorToColorOperation.h index 2f1173ba4e8..8225d03d58e 100644 --- a/source/blender/compositor/operations/COM_ConvertVectorToColorOperation.h +++ b/source/blender/compositor/operations/COM_ConvertVectorToColorOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ConvertVectorToColorOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_ConvertVectorToValueOperation.h b/source/blender/compositor/operations/COM_ConvertVectorToValueOperation.h index 8770992c69c..a7981e8dc59 100644 --- a/source/blender/compositor/operations/COM_ConvertVectorToValueOperation.h +++ b/source/blender/compositor/operations/COM_ConvertVectorToValueOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ConvertVectorToValueOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_ConvertYCCToRGBOperation.h b/source/blender/compositor/operations/COM_ConvertYCCToRGBOperation.h index a595fc19bc7..e23dfd8a985 100644 --- a/source/blender/compositor/operations/COM_ConvertYCCToRGBOperation.h +++ b/source/blender/compositor/operations/COM_ConvertYCCToRGBOperation.h @@ -25,8 +25,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ConvertYCCToRGBOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_ConvertYUVToRGBOperation.h b/source/blender/compositor/operations/COM_ConvertYUVToRGBOperation.h index e89f1500d69..3368e0a24df 100644 --- a/source/blender/compositor/operations/COM_ConvertYUVToRGBOperation.h +++ b/source/blender/compositor/operations/COM_ConvertYUVToRGBOperation.h @@ -25,8 +25,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ConvertYUVToRGBOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_DifferenceMatteOperation.cpp b/source/blender/compositor/operations/COM_DifferenceMatteOperation.cpp index 75f909e2198..3c4bdfe8e5b 100644 --- a/source/blender/compositor/operations/COM_DifferenceMatteOperation.cpp +++ b/source/blender/compositor/operations/COM_DifferenceMatteOperation.cpp @@ -49,7 +49,7 @@ void DifferenceMatteOperation::executePixel(float *outputValue, float x, float y float inColor1[4]; float inColor2[4]; - const float tolerence = this->m_settings->t1; + const float tolerance = this->m_settings->t1; const float falloff = this->m_settings->t2; float difference; float alpha; @@ -65,12 +65,12 @@ void DifferenceMatteOperation::executePixel(float *outputValue, float x, float y difference = difference / 3.0f; /*make 100% transparent*/ - if (difference < tolerence) { + if (difference < tolerance) { outputValue[0] = 0.0f; } /*in the falloff region, make partially transparent */ - else if (difference < falloff + tolerence) { - difference = difference - tolerence; + else if (difference < falloff + tolerance) { + difference = difference - tolerance; alpha = difference / falloff; /*only change if more transparent than before */ if (alpha < inColor1[3]) { diff --git a/source/blender/compositor/operations/COM_DifferenceMatteOperation.h b/source/blender/compositor/operations/COM_DifferenceMatteOperation.h index 48eb2626f02..c35550560e1 100644 --- a/source/blender/compositor/operations/COM_DifferenceMatteOperation.h +++ b/source/blender/compositor/operations/COM_DifferenceMatteOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class DifferenceMatteOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_DilateErodeOperation.cpp b/source/blender/compositor/operations/COM_DilateErodeOperation.cpp index 338a3a0b59b..a9b40f8a6ac 100644 --- a/source/blender/compositor/operations/COM_DilateErodeOperation.cpp +++ b/source/blender/compositor/operations/COM_DilateErodeOperation.cpp @@ -234,15 +234,13 @@ bool DilateDistanceOperation::determineDependingAreaOfInterest(rcti *input, Read return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output); } -static cl_kernel dilateKernel = 0; void DilateDistanceOperation::executeOpenCL(OpenCLDevice* device, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, list<cl_kernel> *clKernelsToCleanUp) { - if (!dilateKernel) { - dilateKernel = device->COM_clCreateKernel("dilateKernel", NULL); - } + cl_kernel dilateKernel = device->COM_clCreateKernel("dilateKernel", NULL); + cl_int distanceSquared = this->m_distance * this->m_distance; cl_int scope = this->m_scope; @@ -293,15 +291,13 @@ void ErodeDistanceOperation::executePixel(float *color, int x, int y, MemoryBuff color[0] = value; } -static cl_kernel erodeKernel = 0; void ErodeDistanceOperation::executeOpenCL(OpenCLDevice* device, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, list<cl_kernel> *clKernelsToCleanUp) { - if (!erodeKernel) { - erodeKernel = device->COM_clCreateKernel("erodeKernel", NULL); - } + cl_kernel erodeKernel = device->COM_clCreateKernel("erodeKernel", NULL); + cl_int distanceSquared = this->m_distance * this->m_distance; cl_int scope = this->m_scope; diff --git a/source/blender/compositor/operations/COM_DistanceMatteOperation.cpp b/source/blender/compositor/operations/COM_DistanceMatteOperation.cpp index 19cca3d25bb..5bdc616fed7 100644 --- a/source/blender/compositor/operations/COM_DistanceMatteOperation.cpp +++ b/source/blender/compositor/operations/COM_DistanceMatteOperation.cpp @@ -49,7 +49,7 @@ void DistanceMatteOperation::executePixel(float *outputValue, float x, float y, float inKey[4]; float inImage[4]; - const float tolerence = this->m_settings->t1; + const float tolerance = this->m_settings->t1; const float falloff = this->m_settings->t2; float distance; @@ -67,12 +67,12 @@ void DistanceMatteOperation::executePixel(float *outputValue, float x, float y, */ /*make 100% transparent */ - if (distance < tolerence) { + if (distance < tolerance) { outputValue[0] = 0.f; } /*in the falloff region, make partially transparent */ - else if (distance < falloff + tolerence) { - distance = distance - tolerence; + else if (distance < falloff + tolerance) { + distance = distance - tolerance; alpha = distance / falloff; /*only change if more transparent than before */ if (alpha < inImage[3]) { diff --git a/source/blender/compositor/operations/COM_DistanceMatteOperation.h b/source/blender/compositor/operations/COM_DistanceMatteOperation.h index 51e139d179e..267aa1fca7a 100644 --- a/source/blender/compositor/operations/COM_DistanceMatteOperation.h +++ b/source/blender/compositor/operations/COM_DistanceMatteOperation.h @@ -25,8 +25,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class DistanceMatteOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp index 8f0ebd9b8d2..6d9c980ea58 100644 --- a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp @@ -220,3 +220,66 @@ void FastGaussianBlurOperation::IIR_gauss(MemoryBuffer *src, float sigma, unsign #undef YVV } + + +/// +FastGaussianBlurValueOperation::FastGaussianBlurValueOperation() : NodeOperation() +{ + this->addInputSocket(COM_DT_VALUE); + this->addOutputSocket(COM_DT_VALUE); + this->m_iirgaus = NULL; + this->m_inputprogram = NULL; + this->m_sigma = 1.0f; + setComplex(true); +} + +void FastGaussianBlurValueOperation::executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data) +{ + MemoryBuffer *newData = (MemoryBuffer *)data; + newData->read(color, x, y); +} + +bool FastGaussianBlurValueOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) +{ + rcti newInput; + + if (this->m_iirgaus) { + return false; + } + else { + newInput.xmin = 0; + newInput.ymin = 0; + newInput.xmax = this->getWidth(); + newInput.ymax = this->getHeight(); + } + return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output); +} + +void FastGaussianBlurValueOperation::initExecution() +{ + this->m_inputprogram = getInputSocketReader(0); + initMutex(); +} + +void FastGaussianBlurValueOperation::deinitExecution() +{ + if (this->m_iirgaus) { + delete this->m_iirgaus; + this->m_iirgaus = NULL; + } + deinitMutex(); +} + +void *FastGaussianBlurValueOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers) +{ + lockMutex(); + if (!this->m_iirgaus) { + MemoryBuffer *newBuf = (MemoryBuffer *)this->m_inputprogram->initializeTileData(rect, memoryBuffers); + MemoryBuffer *copy = newBuf->duplicate(); + FastGaussianBlurOperation::IIR_gauss(copy, this->m_sigma, 0, 3); + this->m_iirgaus = copy; + } + unlockMutex(); + return this->m_iirgaus; +} + diff --git a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h index 1e303b23869..5f76490473f 100644 --- a/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h +++ b/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h @@ -40,7 +40,23 @@ public: void *initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers); void deinitExecution(); void initExecution(); +}; + +class FastGaussianBlurValueOperation : public NodeOperation { +private: + float m_sigma; + MemoryBuffer *m_iirgaus; + SocketReader *m_inputprogram; +public: + FastGaussianBlurValueOperation(); + bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); + void executePixel(float *color, int x, int y, MemoryBuffer * inputBuffers[], void *data); + void *initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers); + void deinitExecution(); + void initExecution(); + void setSigma(float sigma) { this->m_sigma = sigma; } }; + #endif diff --git a/source/blender/compositor/operations/COM_LuminanceMatteOperation.h b/source/blender/compositor/operations/COM_LuminanceMatteOperation.h index 7da56465cd8..041fd0d7ee9 100644 --- a/source/blender/compositor/operations/COM_LuminanceMatteOperation.h +++ b/source/blender/compositor/operations/COM_LuminanceMatteOperation.h @@ -25,8 +25,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class LuminanceMatteOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_MapValueOperation.h b/source/blender/compositor/operations/COM_MapValueOperation.h index 53157c39938..fb50d0fbe4d 100644 --- a/source/blender/compositor/operations/COM_MapValueOperation.h +++ b/source/blender/compositor/operations/COM_MapValueOperation.h @@ -26,8 +26,8 @@ #include "DNA_texture_types.h" /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MapValueOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_MaskOperation.cpp b/source/blender/compositor/operations/COM_MaskOperation.cpp index aa16ecf5d09..2b45cd53fd5 100644 --- a/source/blender/compositor/operations/COM_MaskOperation.cpp +++ b/source/blender/compositor/operations/COM_MaskOperation.cpp @@ -49,11 +49,19 @@ MaskOperation::MaskOperation() : NodeOperation() void MaskOperation::initExecution() { initMutex(); + this->m_rasterizedMask = NULL; + this->m_maskLayers.first = this->m_maskLayers.last = NULL; + + if (this->m_mask) { + BKE_mask_layer_copy_list(&this->m_maskLayers, &this->m_mask->masklayers); + } } void MaskOperation::deinitExecution() { + BKE_mask_layer_free_list(&this->m_maskLayers); + if (this->m_rasterizedMask) { MEM_freeN(this->m_rasterizedMask); this->m_rasterizedMask = NULL; @@ -75,7 +83,10 @@ void *MaskOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers float *buffer; buffer = (float *)MEM_callocN(sizeof(float) * width * height, "rasterized mask"); - BKE_mask_rasterize(this->m_mask, width, height, buffer, TRUE, this->m_do_smooth, this->m_do_feather); + + BKE_mask_rasterize_layers(&this->m_maskLayers, width, height, buffer, TRUE, + this->m_do_smooth, this->m_do_feather); + if (this->m_do_smooth) { PLX_antialias_buffer(buffer, width, height); } diff --git a/source/blender/compositor/operations/COM_MaskOperation.h b/source/blender/compositor/operations/COM_MaskOperation.h index d50f5c619bb..74fd12277e8 100644 --- a/source/blender/compositor/operations/COM_MaskOperation.h +++ b/source/blender/compositor/operations/COM_MaskOperation.h @@ -31,6 +31,10 @@ #include "BLI_listbase.h" #include "IMB_imbuf_types.h" +#ifdef __PLX_RASKTER_MT__ +#include "../../../../intern/raskter/raskter.h" +#endif + /** * Class with implementation of mask rasterization */ @@ -43,6 +47,8 @@ protected: bool m_do_smooth; bool m_do_feather; float *m_rasterizedMask; + + ListBase m_maskLayers; /** * Determine the output resolution. The resolution is retrieved from the Renderer diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.cpp b/source/blender/compositor/operations/COM_MathBaseOperation.cpp index 1bf89be57b5..596895a963a 100644 --- a/source/blender/compositor/operations/COM_MathBaseOperation.cpp +++ b/source/blender/compositor/operations/COM_MathBaseOperation.cpp @@ -64,6 +64,13 @@ void MathBaseOperation::determineResolution(unsigned int resolution[], unsigned NodeOperation::determineResolution(resolution, preferredResolution); } +void MathBaseOperation::clampIfNeeded(float *color) +{ + if (this->m_useClamp) { + CLAMP(color[0], 0.0f, 1.0f); + } +} + void MathAddOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) { float inputValue1[4]; @@ -73,6 +80,8 @@ void MathAddOperation::executePixel(float *outputValue, float x, float y, PixelS this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers); outputValue[0] = inputValue1[0] + inputValue2[0]; + + clampIfNeeded(outputValue); } void MathSubtractOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) @@ -84,6 +93,8 @@ void MathSubtractOperation::executePixel(float *outputValue, float x, float y, P this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers); outputValue[0] = inputValue1[0] - inputValue2[0]; + + clampIfNeeded(outputValue); } void MathMultiplyOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) @@ -95,6 +106,8 @@ void MathMultiplyOperation::executePixel(float *outputValue, float x, float y, P this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers); outputValue[0] = inputValue1[0] * inputValue2[0]; + + clampIfNeeded(outputValue); } void MathDivideOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) @@ -109,6 +122,8 @@ void MathDivideOperation::executePixel(float *outputValue, float x, float y, Pix outputValue[0] = 0.0; else outputValue[0] = inputValue1[0] / inputValue2[0]; + + clampIfNeeded(outputValue); } void MathSineOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) @@ -120,6 +135,8 @@ void MathSineOperation::executePixel(float *outputValue, float x, float y, Pixel this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers); outputValue[0] = sin(inputValue1[0]); + + clampIfNeeded(outputValue); } void MathCosineOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) @@ -131,6 +148,8 @@ void MathCosineOperation::executePixel(float *outputValue, float x, float y, Pix this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers); outputValue[0] = cos(inputValue1[0]); + + clampIfNeeded(outputValue); } void MathTangentOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) @@ -142,6 +161,8 @@ void MathTangentOperation::executePixel(float *outputValue, float x, float y, Pi this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers); outputValue[0] = tan(inputValue1[0]); + + clampIfNeeded(outputValue); } void MathArcSineOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) @@ -156,6 +177,8 @@ void MathArcSineOperation::executePixel(float *outputValue, float x, float y, Pi outputValue[0] = asin(inputValue1[0]); else outputValue[0] = 0.0; + + clampIfNeeded(outputValue); } void MathArcCosineOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) @@ -170,6 +193,8 @@ void MathArcCosineOperation::executePixel(float *outputValue, float x, float y, outputValue[0] = acos(inputValue1[0]); else outputValue[0] = 0.0; + + clampIfNeeded(outputValue); } void MathArcTangentOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) @@ -181,6 +206,8 @@ void MathArcTangentOperation::executePixel(float *outputValue, float x, float y, this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers); outputValue[0] = atan(inputValue1[0]); + + clampIfNeeded(outputValue); } void MathPowerOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) @@ -204,6 +231,8 @@ void MathPowerOperation::executePixel(float *outputValue, float x, float y, Pixe outputValue[0] = 0.0; } } + + clampIfNeeded(outputValue); } void MathLogarithmOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) @@ -218,6 +247,8 @@ void MathLogarithmOperation::executePixel(float *outputValue, float x, float y, outputValue[0] = log(inputValue1[0]) / log(inputValue2[0]); else outputValue[0] = 0.0; + + clampIfNeeded(outputValue); } void MathMinimumOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) @@ -229,6 +260,8 @@ void MathMinimumOperation::executePixel(float *outputValue, float x, float y, Pi this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers); outputValue[0] = min(inputValue1[0], inputValue2[0]); + + clampIfNeeded(outputValue); } void MathMaximumOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) @@ -240,6 +273,8 @@ void MathMaximumOperation::executePixel(float *outputValue, float x, float y, Pi this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers); outputValue[0] = max(inputValue1[0], inputValue2[0]); + + clampIfNeeded(outputValue); } void MathRoundOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) @@ -251,6 +286,8 @@ void MathRoundOperation::executePixel(float *outputValue, float x, float y, Pixe this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers); outputValue[0] = round(inputValue1[0]); + + clampIfNeeded(outputValue); } void MathLessThanOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) @@ -262,6 +299,8 @@ void MathLessThanOperation::executePixel(float *outputValue, float x, float y, P this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers); outputValue[0] = inputValue1[0] < inputValue2[0] ? 1.0f : 0.0f; + + clampIfNeeded(outputValue); } void MathGreaterThanOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) @@ -273,6 +312,8 @@ void MathGreaterThanOperation::executePixel(float *outputValue, float x, float y this->m_inputValue2Operation->read(&inputValue2[0], x, y, sampler, inputBuffers); outputValue[0] = inputValue1[0] > inputValue2[0] ? 1.0f : 0.0f; + + clampIfNeeded(outputValue); } diff --git a/source/blender/compositor/operations/COM_MathBaseOperation.h b/source/blender/compositor/operations/COM_MathBaseOperation.h index bf77223e26f..e53176aea49 100644 --- a/source/blender/compositor/operations/COM_MathBaseOperation.h +++ b/source/blender/compositor/operations/COM_MathBaseOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MathBaseOperation : public NodeOperation { protected: @@ -37,11 +37,15 @@ protected: SocketReader *m_inputValue1Operation; SocketReader *m_inputValue2Operation; + bool m_useClamp; + protected: /** * Default constructor */ MathBaseOperation(); + + void clampIfNeeded(float *color); public: /** * the inner loop of this program @@ -62,6 +66,8 @@ public: * Determine resolution */ void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + + void setUseClamp(bool value) { this->m_useClamp = value; } }; class MathAddOperation : public MathBaseOperation { diff --git a/source/blender/compositor/operations/COM_MixAddOperation.cpp b/source/blender/compositor/operations/COM_MixAddOperation.cpp index 7f7315fb3ff..f8bd802928d 100644 --- a/source/blender/compositor/operations/COM_MixAddOperation.cpp +++ b/source/blender/compositor/operations/COM_MixAddOperation.cpp @@ -46,5 +46,7 @@ void MixAddOperation::executePixel(float *outputValue, float x, float y, PixelSa outputValue[1] = inputColor1[1] + value * inputColor2[1]; outputValue[2] = inputColor1[2] + value * inputColor2[2]; outputValue[3] = inputColor1[3]; + + clampIfNeeded(outputValue); } diff --git a/source/blender/compositor/operations/COM_MixAddOperation.h b/source/blender/compositor/operations/COM_MixAddOperation.h index 7b03802cf7e..c5eaf0a4d77 100644 --- a/source/blender/compositor/operations/COM_MixAddOperation.h +++ b/source/blender/compositor/operations/COM_MixAddOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MixAddOperation : public MixBaseOperation { public: diff --git a/source/blender/compositor/operations/COM_MixBaseOperation.cpp b/source/blender/compositor/operations/COM_MixBaseOperation.cpp index fbe92f54aa8..9e0ae0c6ee8 100644 --- a/source/blender/compositor/operations/COM_MixBaseOperation.cpp +++ b/source/blender/compositor/operations/COM_MixBaseOperation.cpp @@ -94,3 +94,12 @@ void MixBaseOperation::determineResolution(unsigned int resolution[], unsigned i NodeOperation::determineResolution(resolution, preferredResolution); } +void MixBaseOperation::clampIfNeeded(float *color) +{ + if (this->m_useClamp) { + CLAMP(color[0], 0.0f, 1.0f); + CLAMP(color[1], 0.0f, 1.0f); + CLAMP(color[2], 0.0f, 1.0f); + CLAMP(color[3], 0.0f, 1.0f); + } +} diff --git a/source/blender/compositor/operations/COM_MixBaseOperation.h b/source/blender/compositor/operations/COM_MixBaseOperation.h index 8e9bb283533..05301fd0378 100644 --- a/source/blender/compositor/operations/COM_MixBaseOperation.h +++ b/source/blender/compositor/operations/COM_MixBaseOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MixBaseOperation : public NodeOperation { protected: @@ -38,6 +38,9 @@ protected: SocketReader *m_inputColor1Operation; SocketReader *m_inputColor2Operation; bool m_valueAlphaMultiply; + bool m_useClamp; + + void clampIfNeeded(float *color); public: /** * Default constructor @@ -63,5 +66,6 @@ public: void setUseValueAlphaMultiply(const bool value) { this->m_valueAlphaMultiply = value; } bool useValueAlphaMultiply() { return this->m_valueAlphaMultiply; } + void setUseClamp(bool value) { this->m_useClamp = value; } }; #endif diff --git a/source/blender/compositor/operations/COM_MixBlendOperation.cpp b/source/blender/compositor/operations/COM_MixBlendOperation.cpp index 341aba0e7fc..0c6ede01797 100644 --- a/source/blender/compositor/operations/COM_MixBlendOperation.cpp +++ b/source/blender/compositor/operations/COM_MixBlendOperation.cpp @@ -47,4 +47,6 @@ void MixBlendOperation::executePixel(float *outputValue, float x, float y, Pixel outputValue[1] = valuem * (inputColor1[1]) + value * (inputColor2[1]); outputValue[2] = valuem * (inputColor1[2]) + value * (inputColor2[2]); outputValue[3] = inputColor1[3]; + + clampIfNeeded(outputValue); } diff --git a/source/blender/compositor/operations/COM_MixBlendOperation.h b/source/blender/compositor/operations/COM_MixBlendOperation.h index b906134f5cb..16ad635bebd 100644 --- a/source/blender/compositor/operations/COM_MixBlendOperation.h +++ b/source/blender/compositor/operations/COM_MixBlendOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MixBlendOperation : public MixBaseOperation { public: diff --git a/source/blender/compositor/operations/COM_MixBurnOperation.cpp b/source/blender/compositor/operations/COM_MixBurnOperation.cpp index 039915ab66a..0d736583c58 100644 --- a/source/blender/compositor/operations/COM_MixBurnOperation.cpp +++ b/source/blender/compositor/operations/COM_MixBurnOperation.cpp @@ -83,5 +83,7 @@ void MixBurnOperation::executePixel(float *outputValue, float x, float y, PixelS } outputValue[3] = inputColor1[3]; + + clampIfNeeded(outputValue); } diff --git a/source/blender/compositor/operations/COM_MixBurnOperation.h b/source/blender/compositor/operations/COM_MixBurnOperation.h index af09772edde..7412f651ab3 100644 --- a/source/blender/compositor/operations/COM_MixBurnOperation.h +++ b/source/blender/compositor/operations/COM_MixBurnOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MixBurnOperation : public MixBaseOperation { public: diff --git a/source/blender/compositor/operations/COM_MixColorOperation.cpp b/source/blender/compositor/operations/COM_MixColorOperation.cpp index cb5791c02bb..e7f7eb4d656 100644 --- a/source/blender/compositor/operations/COM_MixColorOperation.cpp +++ b/source/blender/compositor/operations/COM_MixColorOperation.cpp @@ -58,5 +58,7 @@ void MixColorOperation::executePixel(float *outputValue, float x, float y, Pixel outputValue[2] = valuem * (inputColor1[2]) + value * tmpb; } outputValue[3] = inputColor1[3]; + + clampIfNeeded(outputValue); } diff --git a/source/blender/compositor/operations/COM_MixColorOperation.h b/source/blender/compositor/operations/COM_MixColorOperation.h index 9b0d93f934d..028ff517132 100644 --- a/source/blender/compositor/operations/COM_MixColorOperation.h +++ b/source/blender/compositor/operations/COM_MixColorOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MixColorOperation : public MixBaseOperation { public: diff --git a/source/blender/compositor/operations/COM_MixDarkenOperation.cpp b/source/blender/compositor/operations/COM_MixDarkenOperation.cpp index db243cf4a87..f229a89fdab 100644 --- a/source/blender/compositor/operations/COM_MixDarkenOperation.cpp +++ b/source/blender/compositor/operations/COM_MixDarkenOperation.cpp @@ -53,5 +53,7 @@ void MixDarkenOperation::executePixel(float *outputValue, float x, float y, Pixe else outputValue[2] = inputColor1[2]; outputValue[3] = inputColor1[3]; + + clampIfNeeded(outputValue); } diff --git a/source/blender/compositor/operations/COM_MixDarkenOperation.h b/source/blender/compositor/operations/COM_MixDarkenOperation.h index 69fb4450458..337fa1a7024 100644 --- a/source/blender/compositor/operations/COM_MixDarkenOperation.h +++ b/source/blender/compositor/operations/COM_MixDarkenOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MixDarkenOperation : public MixBaseOperation { public: diff --git a/source/blender/compositor/operations/COM_MixDifferenceOperation.cpp b/source/blender/compositor/operations/COM_MixDifferenceOperation.cpp index 9fe1a3cb94b..70d62182278 100644 --- a/source/blender/compositor/operations/COM_MixDifferenceOperation.cpp +++ b/source/blender/compositor/operations/COM_MixDifferenceOperation.cpp @@ -46,5 +46,7 @@ void MixDifferenceOperation::executePixel(float *outputValue, float x, float y, outputValue[1] = valuem * inputColor1[1] + value *fabsf(inputColor1[1] - inputColor2[1]); outputValue[2] = valuem * inputColor1[2] + value *fabsf(inputColor1[2] - inputColor2[2]); outputValue[3] = inputColor1[3]; + + clampIfNeeded(outputValue); } diff --git a/source/blender/compositor/operations/COM_MixDifferenceOperation.h b/source/blender/compositor/operations/COM_MixDifferenceOperation.h index c71b22214cc..503fbb691d3 100644 --- a/source/blender/compositor/operations/COM_MixDifferenceOperation.h +++ b/source/blender/compositor/operations/COM_MixDifferenceOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MixDifferenceOperation : public MixBaseOperation { public: diff --git a/source/blender/compositor/operations/COM_MixDivideOperation.cpp b/source/blender/compositor/operations/COM_MixDivideOperation.cpp index 0e1bd408b89..7ca47c4f507 100644 --- a/source/blender/compositor/operations/COM_MixDivideOperation.cpp +++ b/source/blender/compositor/operations/COM_MixDivideOperation.cpp @@ -56,5 +56,7 @@ void MixDivideOperation::executePixel(float *outputValue, float x, float y, Pixe outputValue[2] = 0.0f; outputValue[3] = inputColor1[3]; + + clampIfNeeded(outputValue); } diff --git a/source/blender/compositor/operations/COM_MixDivideOperation.h b/source/blender/compositor/operations/COM_MixDivideOperation.h index 375e7129e8b..db60a39f93f 100644 --- a/source/blender/compositor/operations/COM_MixDivideOperation.h +++ b/source/blender/compositor/operations/COM_MixDivideOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MixDivideOperation : public MixBaseOperation { public: diff --git a/source/blender/compositor/operations/COM_MixDodgeOperation.cpp b/source/blender/compositor/operations/COM_MixDodgeOperation.cpp index ea01806267b..b8ed3e252a9 100644 --- a/source/blender/compositor/operations/COM_MixDodgeOperation.cpp +++ b/source/blender/compositor/operations/COM_MixDodgeOperation.cpp @@ -88,5 +88,7 @@ void MixDodgeOperation::executePixel(float *outputValue, float x, float y, Pixel outputValue[2] = 0.0f; outputValue[3] = inputColor1[3]; + + clampIfNeeded(outputValue); } diff --git a/source/blender/compositor/operations/COM_MixDodgeOperation.h b/source/blender/compositor/operations/COM_MixDodgeOperation.h index a4adf6fde47..32aa8593657 100644 --- a/source/blender/compositor/operations/COM_MixDodgeOperation.h +++ b/source/blender/compositor/operations/COM_MixDodgeOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MixDodgeOperation : public MixBaseOperation { public: diff --git a/source/blender/compositor/operations/COM_MixGlareOperation.cpp b/source/blender/compositor/operations/COM_MixGlareOperation.cpp index 7cd24b3bf06..f0729bec23d 100644 --- a/source/blender/compositor/operations/COM_MixGlareOperation.cpp +++ b/source/blender/compositor/operations/COM_MixGlareOperation.cpp @@ -44,4 +44,6 @@ void MixGlareOperation::executePixel(float *outputValue, float x, float y, Pixel outputValue[1] = mf * ((inputColor1[1]) + value * (inputColor2[1] - inputColor1[1])); outputValue[2] = mf * ((inputColor1[2]) + value * (inputColor2[2] - inputColor1[2])); outputValue[3] = inputColor1[3]; + + clampIfNeeded(outputValue); } diff --git a/source/blender/compositor/operations/COM_MixGlareOperation.h b/source/blender/compositor/operations/COM_MixGlareOperation.h index 1a025eb3edd..1c715d7414b 100644 --- a/source/blender/compositor/operations/COM_MixGlareOperation.h +++ b/source/blender/compositor/operations/COM_MixGlareOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MixGlareOperation : public MixBaseOperation { public: diff --git a/source/blender/compositor/operations/COM_MixHueOperation.cpp b/source/blender/compositor/operations/COM_MixHueOperation.cpp index e7b444616f4..5528597ab17 100644 --- a/source/blender/compositor/operations/COM_MixHueOperation.cpp +++ b/source/blender/compositor/operations/COM_MixHueOperation.cpp @@ -58,4 +58,6 @@ void MixHueOperation::executePixel(float *outputValue, float x, float y, PixelSa outputValue[2] = valuem * (inputColor1[2]) + value * tmpb; } outputValue[3] = inputColor1[3]; + + clampIfNeeded(outputValue); } diff --git a/source/blender/compositor/operations/COM_MixHueOperation.h b/source/blender/compositor/operations/COM_MixHueOperation.h index 56310e253c0..ff1ef369440 100644 --- a/source/blender/compositor/operations/COM_MixHueOperation.h +++ b/source/blender/compositor/operations/COM_MixHueOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MixHueOperation : public MixBaseOperation { public: diff --git a/source/blender/compositor/operations/COM_MixLightenOperation.cpp b/source/blender/compositor/operations/COM_MixLightenOperation.cpp index 89166637f9f..d742bc27b00 100644 --- a/source/blender/compositor/operations/COM_MixLightenOperation.cpp +++ b/source/blender/compositor/operations/COM_MixLightenOperation.cpp @@ -51,5 +51,7 @@ void MixLightenOperation::executePixel(float *outputValue, float x, float y, Pix if (tmp > inputColor1[2]) outputValue[2] = tmp; else outputValue[2] = inputColor1[2]; outputValue[3] = inputColor1[3]; + + clampIfNeeded(outputValue); } diff --git a/source/blender/compositor/operations/COM_MixLightenOperation.h b/source/blender/compositor/operations/COM_MixLightenOperation.h index bb251a44653..dd51215b26a 100644 --- a/source/blender/compositor/operations/COM_MixLightenOperation.h +++ b/source/blender/compositor/operations/COM_MixLightenOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MixLightenOperation : public MixBaseOperation { public: diff --git a/source/blender/compositor/operations/COM_MixLinearLightOperation.cpp b/source/blender/compositor/operations/COM_MixLinearLightOperation.cpp index 5406a3cbcc1..006faf3f18b 100644 --- a/source/blender/compositor/operations/COM_MixLinearLightOperation.cpp +++ b/source/blender/compositor/operations/COM_MixLinearLightOperation.cpp @@ -54,4 +54,6 @@ void MixLinearLightOperation::executePixel(float *outputValue, float x, float y, outputValue[2] = inputColor1[2] + value * (2.0f * (inputColor2[2]) - 1.0f); outputValue[3] = inputColor1[3]; + + clampIfNeeded(outputValue); } diff --git a/source/blender/compositor/operations/COM_MixLinearLightOperation.h b/source/blender/compositor/operations/COM_MixLinearLightOperation.h index 39d5b6495d1..e96e2b7eaf7 100644 --- a/source/blender/compositor/operations/COM_MixLinearLightOperation.h +++ b/source/blender/compositor/operations/COM_MixLinearLightOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MixLinearLightOperation : public MixBaseOperation { public: diff --git a/source/blender/compositor/operations/COM_MixMultiplyOperation.cpp b/source/blender/compositor/operations/COM_MixMultiplyOperation.cpp index 978e96eb2f6..a480182a785 100644 --- a/source/blender/compositor/operations/COM_MixMultiplyOperation.cpp +++ b/source/blender/compositor/operations/COM_MixMultiplyOperation.cpp @@ -46,5 +46,7 @@ void MixMultiplyOperation::executePixel(float *outputValue, float x, float y, Pi outputValue[1] = inputColor1[1] * (valuem + value * inputColor2[1]); outputValue[2] = inputColor1[2] * (valuem + value * inputColor2[2]); outputValue[3] = inputColor1[3]; + + clampIfNeeded(outputValue); } diff --git a/source/blender/compositor/operations/COM_MixMultiplyOperation.h b/source/blender/compositor/operations/COM_MixMultiplyOperation.h index 2c12854bfa6..4c89a8f2957 100644 --- a/source/blender/compositor/operations/COM_MixMultiplyOperation.h +++ b/source/blender/compositor/operations/COM_MixMultiplyOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MixMultiplyOperation : public MixBaseOperation { public: diff --git a/source/blender/compositor/operations/COM_MixOverlayOperation.cpp b/source/blender/compositor/operations/COM_MixOverlayOperation.cpp index f4f96747acd..7c39f70faaa 100644 --- a/source/blender/compositor/operations/COM_MixOverlayOperation.cpp +++ b/source/blender/compositor/operations/COM_MixOverlayOperation.cpp @@ -62,5 +62,7 @@ void MixOverlayOperation::executePixel(float *outputValue, float x, float y, Pix outputValue[2] = 1.0f - (valuem + 2.0f * value * (1.0f - inputColor2[2])) * (1.0f - inputColor1[2]); } outputValue[3] = inputColor1[3]; + + clampIfNeeded(outputValue); } diff --git a/source/blender/compositor/operations/COM_MixOverlayOperation.h b/source/blender/compositor/operations/COM_MixOverlayOperation.h index 48d1d10a697..7de955b9f4f 100644 --- a/source/blender/compositor/operations/COM_MixOverlayOperation.h +++ b/source/blender/compositor/operations/COM_MixOverlayOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MixOverlayOperation : public MixBaseOperation { public: diff --git a/source/blender/compositor/operations/COM_MixSaturationOperation.cpp b/source/blender/compositor/operations/COM_MixSaturationOperation.cpp index c9c6f691fdb..1ae856d2ba0 100644 --- a/source/blender/compositor/operations/COM_MixSaturationOperation.cpp +++ b/source/blender/compositor/operations/COM_MixSaturationOperation.cpp @@ -54,4 +54,6 @@ void MixSaturationOperation::executePixel(float *outputValue, float x, float y, hsv_to_rgb(rH, (valuem * rS + value * colS), rV, &outputValue[0], &outputValue[1], &outputValue[2]); } outputValue[3] = inputColor1[3]; + + clampIfNeeded(outputValue); } diff --git a/source/blender/compositor/operations/COM_MixSaturationOperation.h b/source/blender/compositor/operations/COM_MixSaturationOperation.h index ccb95e2f00f..241009e2645 100644 --- a/source/blender/compositor/operations/COM_MixSaturationOperation.h +++ b/source/blender/compositor/operations/COM_MixSaturationOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MixSaturationOperation : public MixBaseOperation { public: diff --git a/source/blender/compositor/operations/COM_MixScreenOperation.cpp b/source/blender/compositor/operations/COM_MixScreenOperation.cpp index 9bc9144f4ff..c4ec210eb1c 100644 --- a/source/blender/compositor/operations/COM_MixScreenOperation.cpp +++ b/source/blender/compositor/operations/COM_MixScreenOperation.cpp @@ -47,5 +47,7 @@ void MixScreenOperation::executePixel(float *outputValue, float x, float y, Pixe outputValue[1] = 1.0f - (valuem + value * (1.0f - inputColor2[1])) * (1.0f - inputColor1[1]); outputValue[2] = 1.0f - (valuem + value * (1.0f - inputColor2[2])) * (1.0f - inputColor1[2]); outputValue[3] = inputColor1[3]; + + clampIfNeeded(outputValue); } diff --git a/source/blender/compositor/operations/COM_MixScreenOperation.h b/source/blender/compositor/operations/COM_MixScreenOperation.h index 6b9fa302325..4d0c1fded3d 100644 --- a/source/blender/compositor/operations/COM_MixScreenOperation.h +++ b/source/blender/compositor/operations/COM_MixScreenOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MixScreenOperation : public MixBaseOperation { public: diff --git a/source/blender/compositor/operations/COM_MixSoftLightOperation.cpp b/source/blender/compositor/operations/COM_MixSoftLightOperation.cpp index 52c2e8829dc..9de56fde87d 100644 --- a/source/blender/compositor/operations/COM_MixSoftLightOperation.cpp +++ b/source/blender/compositor/operations/COM_MixSoftLightOperation.cpp @@ -28,7 +28,7 @@ MixSoftLightOperation::MixSoftLightOperation() : MixBaseOperation() } void MixSoftLightOperation::executePixel(float *outputValue, float x, float y, PixelSampler sampler, MemoryBuffer *inputBuffers[]) \ - { +{ float inputColor1[4]; float inputColor2[4]; float value; @@ -52,5 +52,7 @@ void MixSoftLightOperation::executePixel(float *outputValue, float x, float y, P outputValue[1] = valuem * (inputColor1[1]) + value * (((1.0f - inputColor1[1]) * inputColor2[1] * (inputColor1[1])) + (inputColor1[1] * scg)); outputValue[2] = valuem * (inputColor1[2]) + value * (((1.0f - inputColor1[2]) * inputColor2[2] * (inputColor1[2])) + (inputColor1[2] * scb)); outputValue[3] = inputColor1[3]; - } + + clampIfNeeded(outputValue); +} diff --git a/source/blender/compositor/operations/COM_MixSoftLightOperation.h b/source/blender/compositor/operations/COM_MixSoftLightOperation.h index 4189066de2c..bcb718027b2 100644 --- a/source/blender/compositor/operations/COM_MixSoftLightOperation.h +++ b/source/blender/compositor/operations/COM_MixSoftLightOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MixSoftLightOperation : public MixBaseOperation { public: diff --git a/source/blender/compositor/operations/COM_MixSubtractOperation.cpp b/source/blender/compositor/operations/COM_MixSubtractOperation.cpp index 60f54ab478d..4861346c9da 100644 --- a/source/blender/compositor/operations/COM_MixSubtractOperation.cpp +++ b/source/blender/compositor/operations/COM_MixSubtractOperation.cpp @@ -44,5 +44,7 @@ void MixSubtractOperation::executePixel(float *outputValue, float x, float y, Pi outputValue[1] = inputColor1[1] - value * (inputColor2[1]); outputValue[2] = inputColor1[2] - value * (inputColor2[2]); outputValue[3] = inputColor1[3]; + + clampIfNeeded(outputValue); } diff --git a/source/blender/compositor/operations/COM_MixSubtractOperation.h b/source/blender/compositor/operations/COM_MixSubtractOperation.h index b820fb1e5e1..3c8112b0e36 100644 --- a/source/blender/compositor/operations/COM_MixSubtractOperation.h +++ b/source/blender/compositor/operations/COM_MixSubtractOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MixSubtractOperation : public MixBaseOperation { public: diff --git a/source/blender/compositor/operations/COM_MixValueOperation.cpp b/source/blender/compositor/operations/COM_MixValueOperation.cpp index 2651b0d7dee..511bbdf85f4 100644 --- a/source/blender/compositor/operations/COM_MixValueOperation.cpp +++ b/source/blender/compositor/operations/COM_MixValueOperation.cpp @@ -52,4 +52,6 @@ void MixValueOperation::executePixel(float *outputValue, float x, float y, Pixel rgb_to_hsv(inputColor2[0], inputColor2[1], inputColor2[2], &colH, &colS, &colV); hsv_to_rgb(rH, rS, (valuem * rV + value * colV), &outputValue[0], &outputValue[1], &outputValue[2]); outputValue[3] = inputColor1[3]; + + clampIfNeeded(outputValue); } diff --git a/source/blender/compositor/operations/COM_MixValueOperation.h b/source/blender/compositor/operations/COM_MixValueOperation.h index d12a2d2b3d6..c0f3ce10f29 100644 --- a/source/blender/compositor/operations/COM_MixValueOperation.h +++ b/source/blender/compositor/operations/COM_MixValueOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MixValueOperation : public MixBaseOperation { public: diff --git a/source/blender/compositor/operations/COM_MovieClipAttributeOperation.h b/source/blender/compositor/operations/COM_MovieClipAttributeOperation.h index ba104d07572..c6422fbbfc2 100644 --- a/source/blender/compositor/operations/COM_MovieClipAttributeOperation.h +++ b/source/blender/compositor/operations/COM_MovieClipAttributeOperation.h @@ -32,8 +32,8 @@ typedef enum MovieClipAttribute { MCA_ANGLE } MovieClipAttribute; /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class MovieClipAttributeOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_OpenCLKernels.cl b/source/blender/compositor/operations/COM_OpenCLKernels.cl index 0f8e543de7f..1f3b28f15d3 100644 --- a/source/blender/compositor/operations/COM_OpenCLKernels.cl +++ b/source/blender/compositor/operations/COM_OpenCLKernels.cl @@ -51,6 +51,62 @@ __kernel void bokehBlurKernel(__read_only image2d_t boundingBox, __read_only ima write_imagef(output, coords, color); } +//KERNEL --- DEFOCUS /VARIABLESIZEBOKEHBLUR --- +__kernel void defocusKernel(__read_only image2d_t inputImage, __read_only image2d_t bokehImage, + __read_only image2d_t inputSize, + __write_only image2d_t output, int2 offsetInput, int2 offsetOutput, + int step, int maxBlur, float threshold, int2 dimension, int2 offset) +{ + float4 color = {1.0f, 0.0f, 0.0f, 1.0f}; + int2 coords = {get_global_id(0), get_global_id(1)}; + coords += offset; + const int2 realCoordinate = coords + offsetOutput; + + float4 readColor; + float4 bokeh; + float tempSize; + float4 multiplier_accum = {1.0f, 1.0f, 1.0f, 1.0f}; + float4 color_accum; + + int minx = max(realCoordinate.s0 - maxBlur, 0); + int miny = max(realCoordinate.s1 - maxBlur, 0); + int maxx = min(realCoordinate.s0 + maxBlur, dimension.s0); + int maxy = min(realCoordinate.s1 + maxBlur, dimension.s1); + + { + int2 inputCoordinate = realCoordinate - offsetInput; + float size = read_imagef(inputSize, SAMPLER_NEAREST, inputCoordinate).s0; + color_accum = read_imagef(inputImage, SAMPLER_NEAREST, inputCoordinate); + + for (int ny = miny; ny < maxy; ny += step) { + for (int nx = minx; nx < maxx; nx += step) { + if (nx >= 0 && nx < dimension.s0 && ny >= 0 && ny < dimension.s1) { + inputCoordinate.s0 = nx - offsetInput.s0; + inputCoordinate.s1 = ny - offsetInput.s1; + tempSize = read_imagef(inputSize, SAMPLER_NEAREST, inputCoordinate).s0; + if (size > threshold && tempSize > threshold) { + float dx = nx - realCoordinate.s0; + float dy = ny - realCoordinate.s1; + if (dx != 0 || dy != 0) { + if (tempSize >= fabs(dx) && tempSize >= fabs(dy)) { + float2 uv = { 256.0f + dx * 256.0f / tempSize, 256.0f + dy * 256.0f / tempSize}; + bokeh = read_imagef(bokehImage, SAMPLER_NEAREST, uv); + readColor = read_imagef(inputImage, SAMPLER_NEAREST, inputCoordinate); + color_accum += bokeh*readColor; + multiplier_accum += bokeh; + } + } + } + } + } + } + } + + color = color_accum * (1.0f / multiplier_accum); + write_imagef(output, coords, color); +} + + // KERNEL --- DILATE --- __kernel void dilateKernel(__read_only image2d_t inputImage, __write_only image2d_t output, int2 offsetInput, int2 offsetOutput, int scope, int distanceSquared, int2 dimension, diff --git a/source/blender/compositor/operations/COM_OpenCLKernels.cl.h b/source/blender/compositor/operations/COM_OpenCLKernels.cl.h index e064b7511cb..1c223a527ca 100644 --- a/source/blender/compositor/operations/COM_OpenCLKernels.cl.h +++ b/source/blender/compositor/operations/COM_OpenCLKernels.cl.h @@ -16,7 +16,7 @@ const char * clkernelstoh_COM_OpenCLKernels_cl = "/// This file contains all ope " coords += offset;\n" \ " float tempBoundingBox;\n" \ " float4 color = {0.0f,0.0f,0.0f,0.0f};\n" \ -" float4 multiplier = {0.0f,0.0f,0.0f,0.0f};\n" \ +" float4 multiplyer = {0.0f,0.0f,0.0f,0.0f};\n" \ " float4 bokeh;\n" \ " const float radius2 = radius*2.0f;\n" \ " const int2 realCoordinate = coords + offsetOutput;\n" \ @@ -40,10 +40,10 @@ const char * clkernelstoh_COM_OpenCLKernels_cl = "/// This file contains all ope " uv.x = ((realCoordinate.x-nx)/radius2)*bokehImageDim.x+bokehImageCenter.x;\n" \ " bokeh = read_imagef(bokehImage, SAMPLER_NEAREST, uv);\n" \ " color += bokeh * read_imagef(inputImage, SAMPLER_NEAREST, inputXy);\n" \ -" multiplier += bokeh;\n" \ +" multiplyer += bokeh;\n" \ " }\n" \ " }\n" \ -" color /= multiplier;\n" \ +" color /= multiplyer;\n" \ "\n" \ " } else {\n" \ " int2 imageCoordinates = realCoordinate - offsetInput;\n" \ @@ -53,6 +53,62 @@ const char * clkernelstoh_COM_OpenCLKernels_cl = "/// This file contains all ope " write_imagef(output, coords, color);\n" \ "}\n" \ "\n" \ +"//KERNEL --- DEFOCUS /VARIABLESIZEBOKEHBLUR ---\n" \ +"__kernel void defocusKernel(__read_only image2d_t inputImage, __read_only image2d_t bokehImage,\n" \ +" __read_only image2d_t inputSize,\n" \ +" __write_only image2d_t output, int2 offsetInput, int2 offsetOutput,\n" \ +" int step, int maxBlur, float threshold, int2 dimension, int2 offset)\n" \ +"{\n" \ +" float4 color = {1.0f, 0.0f, 0.0f, 1.0f};\n" \ +" int2 coords = {get_global_id(0), get_global_id(1)};\n" \ +" coords += offset;\n" \ +" const int2 realCoordinate = coords + offsetOutput;\n" \ +"\n" \ +" float4 readColor;\n" \ +" float4 bokeh;\n" \ +" float tempSize;\n" \ +" float4 multiplier_accum = {1.0f, 1.0f, 1.0f, 1.0f};\n" \ +" float4 color_accum;\n" \ +"\n" \ +" int minx = max(realCoordinate.s0 - maxBlur, 0);\n" \ +" int miny = max(realCoordinate.s1 - maxBlur, 0);\n" \ +" int maxx = min(realCoordinate.s0 + maxBlur, dimension.s0);\n" \ +" int maxy = min(realCoordinate.s1 + maxBlur, dimension.s1);\n" \ +"\n" \ +" {\n" \ +" int2 inputCoordinate = realCoordinate - offsetInput;\n" \ +" float size = read_imagef(inputSize, SAMPLER_NEAREST, inputCoordinate).s0;\n" \ +" color_accum = read_imagef(inputImage, SAMPLER_NEAREST, inputCoordinate);\n" \ +"\n" \ +" for (int ny = miny; ny < maxy; ny += step) {\n" \ +" for (int nx = minx; nx < maxx; nx += step) {\n" \ +" if (nx >= 0 && nx < dimension.s0 && ny >= 0 && ny < dimension.s1) {\n" \ +" inputCoordinate.s0 = nx - offsetInput.s0;\n" \ +" inputCoordinate.s1 = ny - offsetInput.s1;\n" \ +" tempSize = read_imagef(inputSize, SAMPLER_NEAREST, inputCoordinate).s0;\n" \ +" if (size > threshold && tempSize > threshold) {\n" \ +" float dx = nx - realCoordinate.s0;\n" \ +" float dy = ny - realCoordinate.s1;\n" \ +" if (dx != 0 || dy != 0) {\n" \ +" if (tempSize >= fabs(dx) && tempSize >= fabs(dy)) {\n" \ +" float2 uv = { 256.0f + dx * 256.0f / tempSize, 256.0f + dy * 256.0f / tempSize};\n" \ +" bokeh = read_imagef(bokehImage, SAMPLER_NEAREST, uv);\n" \ +" readColor = read_imagef(inputImage, SAMPLER_NEAREST, inputCoordinate);\n" \ +" color_accum += bokeh*readColor;\n" \ +" multiplier_accum += bokeh;\n" \ +" }\n" \ +" }\n" \ +" }\n" \ +" }\n" \ +" }\n" \ +" }\n" \ +" }\n" \ +"\n" \ +" color = color_accum * (1.0f / multiplier_accum);\n" \ +" write_imagef(output, coords, color);\n" \ +"}\n" \ +"\n" \ +"\n" \ "// KERNEL --- DILATE ---\n" \ "__kernel void dilateKernel(__read_only image2d_t inputImage, __write_only image2d_t output,\n" \ " int2 offsetInput, int2 offsetOutput, int scope, int distanceSquared, int2 dimension,\n" \ @@ -70,9 +126,9 @@ const char * clkernelstoh_COM_OpenCLKernels_cl = "/// This file contains all ope " int2 inputXy;\n" \ "\n" \ " for (ny = minXY.y, inputXy.y = ny - offsetInput.y ; ny < maxXY.y ; ny ++, inputXy.y++) {\n" \ +" const float deltaY = (realCoordinate.y - ny);\n" \ " for (nx = minXY.x, inputXy.x = nx - offsetInput.x; nx < maxXY.x ; nx ++, inputXy.x++) {\n" \ " const float deltaX = (realCoordinate.x - nx);\n" \ -" const float deltaY = (realCoordinate.y - ny);\n" \ " const float measuredDistance = deltaX*deltaX+deltaY*deltaY;\n" \ " if (measuredDistance <= distanceSquared) {\n" \ " value = max(value, read_imagef(inputImage, SAMPLER_NEAREST, inputXy).s0);\n" \ diff --git a/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cpp b/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cpp index 74145c52a5d..12674153bc8 100644 --- a/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cpp +++ b/source/blender/compositor/operations/COM_ProjectorLensDistortionOperation.cpp @@ -79,10 +79,10 @@ bool ProjectorLensDistortionOperation::determineDependingAreaOfInterest(rcti *in newInput.xmin = input->xmin - this->m_kr2 - 2; newInput.xmax = input->xmax + this->m_kr2 + 2; } else { - newInput.xmin = input->xmin-7; //(0.25f*20*1)+2 == worse case dispersion + newInput.xmin = input->xmin - 7; //(0.25f*20*1)+2 == worse case dispersion newInput.ymin = input->ymin; newInput.ymax = input->ymax; - newInput.xmax = input->xmax+7; //(0.25f*20*1)+2 == worse case dispersion + newInput.xmax = input->xmax + 7; //(0.25f*20*1)+2 == worse case dispersion } return NodeOperation::determineDependingAreaOfInterest(&newInput, readOperation, output); } diff --git a/source/blender/compositor/operations/COM_RenderLayersImageProg.cpp b/source/blender/compositor/operations/COM_RenderLayersImageProg.cpp index 14c3d652c42..f21585844ff 100644 --- a/source/blender/compositor/operations/COM_RenderLayersImageProg.cpp +++ b/source/blender/compositor/operations/COM_RenderLayersImageProg.cpp @@ -22,7 +22,7 @@ #include "COM_RenderLayersImageProg.h" -RenderLayersColourProg::RenderLayersColourProg() : RenderLayersBaseProg(SCE_PASS_COMBINED, 4) +RenderLayersColorProg::RenderLayersColorProg() : RenderLayersBaseProg(SCE_PASS_COMBINED, 4) { this->addOutputSocket(COM_DT_COLOR); } diff --git a/source/blender/compositor/operations/COM_RenderLayersImageProg.h b/source/blender/compositor/operations/COM_RenderLayersImageProg.h index b6ddac425cb..2d63bad235b 100644 --- a/source/blender/compositor/operations/COM_RenderLayersImageProg.h +++ b/source/blender/compositor/operations/COM_RenderLayersImageProg.h @@ -20,15 +20,15 @@ * Monique Dewanchand */ -#ifndef _COM_RenderLayersColourProg_h -#define _COM_RenderLayersColourProg_h +#ifndef _COM_RenderLayersColorProg_h +#define _COM_RenderLayersColorProg_h #include "COM_RenderLayersBaseProg.h" /// @TODO rename to image operation -class RenderLayersColourProg : public RenderLayersBaseProg { +class RenderLayersColorProg : public RenderLayersBaseProg { public: - RenderLayersColourProg(); + RenderLayersColorProg(); }; #endif diff --git a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp index ea8483734d3..e70185f8fba 100644 --- a/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp +++ b/source/blender/compositor/operations/COM_ScreenLensDistortionOperation.cpp @@ -232,7 +232,7 @@ bool ScreenLensDistortionOperation::determineDependingAreaOfInterest(rcti *input return true; } -#define MARGIN 64 +#define MARGIN 96 #define UPDATE_INPUT \ newInput.xmin = MIN3(newInput.xmin, coords[0], coords[2]); \ @@ -256,7 +256,7 @@ bool ScreenLensDistortionOperation::determineDependingAreaOfInterest(rcti *input UPDATE_INPUT; determineUV(coords, input->xmax, input->ymin); UPDATE_INPUT; - margin = (ABS(this->m_distortion)+this->m_dispersion)*MARGIN; + margin = (ABS(this->m_distortion) + this->m_dispersion) * MARGIN + 2.0f; } else { @@ -283,7 +283,7 @@ bool ScreenLensDistortionOperation::determineDependingAreaOfInterest(rcti *input UPDATE_INPUT; determineUV(coords, input->xmax, input->ymin, 1.0f, 1.0f); UPDATE_INPUT; - margin=MARGIN; + margin = MARGIN; } #undef UPDATE_INPUT diff --git a/source/blender/compositor/operations/COM_SetAlphaOperation.h b/source/blender/compositor/operations/COM_SetAlphaOperation.h index 857bd08bfbf..21968c930e7 100644 --- a/source/blender/compositor/operations/COM_SetAlphaOperation.h +++ b/source/blender/compositor/operations/COM_SetAlphaOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class SetAlphaOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_SetColorOperation.h b/source/blender/compositor/operations/COM_SetColorOperation.h index abfa2b9538a..a51311837ee 100644 --- a/source/blender/compositor/operations/COM_SetColorOperation.h +++ b/source/blender/compositor/operations/COM_SetColorOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class SetColorOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_SetSamplerOperation.h b/source/blender/compositor/operations/COM_SetSamplerOperation.h index 24e0c5e2ef5..273eac159bc 100644 --- a/source/blender/compositor/operations/COM_SetSamplerOperation.h +++ b/source/blender/compositor/operations/COM_SetSamplerOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output Sampler. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output Sampler. + * it assumes we are in sRGB color space. */ class SetSamplerOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_SetValueOperation.h b/source/blender/compositor/operations/COM_SetValueOperation.h index dce0c3299ac..642940e03cd 100644 --- a/source/blender/compositor/operations/COM_SetValueOperation.h +++ b/source/blender/compositor/operations/COM_SetValueOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class SetValueOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_SetVectorOperation.h b/source/blender/compositor/operations/COM_SetVectorOperation.h index dc2a05ceff4..d1b9fe25085 100644 --- a/source/blender/compositor/operations/COM_SetVectorOperation.h +++ b/source/blender/compositor/operations/COM_SetVectorOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class SetVectorOperation : public NodeOperation { private: diff --git a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp index 9eb004b3686..61538fde258 100644 --- a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp @@ -22,6 +22,7 @@ #include "COM_VariableSizeBokehBlurOperation.h" #include "BLI_math.h" +#include "COM_OpenCLDevice.h" extern "C" { #include "RE_pipeline.h" @@ -32,16 +33,21 @@ VariableSizeBokehBlurOperation::VariableSizeBokehBlurOperation() : NodeOperation this->addInputSocket(COM_DT_COLOR); this->addInputSocket(COM_DT_COLOR, COM_SC_NO_RESIZE); // do not resize the bokeh image. this->addInputSocket(COM_DT_VALUE); // radius - this->addInputSocket(COM_DT_VALUE); // depth +#ifdef COM_DEFOCUS_SEARCH + this->addInputSocket(COM_DT_COLOR, COM_SC_NO_RESIZE); // inverse search radius optimization structure. +#endif this->addOutputSocket(COM_DT_COLOR); this->setComplex(true); + this->setOpenCL(true); this->m_inputProgram = NULL; this->m_inputBokehProgram = NULL; this->m_inputSizeProgram = NULL; - this->m_inputDepthProgram = NULL; this->m_maxBlur = 32.0f; this->m_threshold = 1.0f; +#ifdef COM_DEFOCUS_SEARCH + this->m_inputSearchProgram = NULL; +#endif } @@ -50,7 +56,9 @@ void VariableSizeBokehBlurOperation::initExecution() this->m_inputProgram = getInputSocketReader(0); this->m_inputBokehProgram = getInputSocketReader(1); this->m_inputSizeProgram = getInputSocketReader(2); - this->m_inputDepthProgram = getInputSocketReader(3); +#ifdef COM_DEFOCUS_SEARCH + this->m_inputSearchProgram = getInputSocketReader(4); +#endif QualityStepHelper::initExecution(COM_QH_INCREASE); } @@ -59,62 +67,93 @@ void VariableSizeBokehBlurOperation::executePixel(float *color, int x, int y, Me float readColor[4]; float bokeh[4]; float tempSize[4]; - float tempDepth[4]; float multiplier_accum[4] = {0.0f, 0.0f, 0.0f, 0.0f}; float color_accum[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - int miny = y - this->m_maxBlur; - int maxy = y + this->m_maxBlur; - int minx = x - this->m_maxBlur; - int maxx = x + this->m_maxBlur; +#ifdef COM_DEFOCUS_SEARCH + float search[4]; + this->inputSearchProgram->read(search, x/InverseSearchRadiusOperation::DIVIDER, y / InverseSearchRadiusOperation::DIVIDER, inputBuffers, NULL); + int minx = search[0]; + int miny = search[1]; + int maxx = search[2]; + int maxy = search[3]; +#else + int minx = MAX2(x - this->m_maxBlur, 0.0f); + int miny = MAX2(y - this->m_maxBlur, 0.0f); + int maxx = MIN2(x + this->m_maxBlur, m_width); + int maxy = MIN2(y + this->m_maxBlur, m_height); +#endif { this->m_inputSizeProgram->read(tempSize, x, y, COM_PS_NEAREST, inputBuffers); - this->m_inputDepthProgram->read(tempDepth, x, y, COM_PS_NEAREST, inputBuffers); this->m_inputProgram->read(readColor, x, y, COM_PS_NEAREST, inputBuffers); add_v4_v4(color_accum, readColor); add_v4_fl(multiplier_accum, 1.0f); float sizeCenter = tempSize[0]; - float centerDepth = tempDepth[0] + this->m_threshold; for (int ny = miny; ny < maxy; ny += QualityStepHelper::getStep()) { for (int nx = minx; nx < maxx; nx += QualityStepHelper::getStep()) { if (nx >= 0 && nx < this->getWidth() && ny >= 0 && ny < getHeight()) { - this->m_inputDepthProgram->read(tempDepth, nx, ny, COM_PS_NEAREST, inputBuffers); this->m_inputSizeProgram->read(tempSize, nx, ny, COM_PS_NEAREST, inputBuffers); float size = tempSize[0]; - if (tempDepth[0] < centerDepth) { - if ((sizeCenter > this->m_threshold && size > this->m_threshold) || size <= this->m_threshold) { - float dx = nx - x; - float dy = ny - y; - if (nx == x && ny == y) { - } - else if (size >= fabsf(dx) && size >= fabsf(dy)) { - float u = 256 + dx * 256 / size; - float v = 256 + dy * 256 / size; - this->m_inputBokehProgram->read(bokeh, u, v, COM_PS_NEAREST, inputBuffers); - this->m_inputProgram->read(readColor, nx, ny, COM_PS_NEAREST, inputBuffers); - madd_v4_v4v4(color_accum, bokeh, readColor); - add_v4_v4(multiplier_accum, bokeh); - } + float fsize = fabsf(size); + if (sizeCenter > this->m_threshold && size > this->m_threshold) { + float dx = nx - x; + float dy = ny - y; + if (nx == x && ny == y) { + } + else if (fsize > fabsf(dx) && fsize > fabsf(dy)) { + float u = (256 + (dx/size) * 256); + float v = (256 + (dy/size) * 256); + this->m_inputBokehProgram->read(bokeh, u, v, COM_PS_NEAREST, inputBuffers); + this->m_inputProgram->read(readColor, nx, ny, COM_PS_NEAREST, inputBuffers); + madd_v4_v4v4(color_accum, bokeh, readColor); + add_v4_v4(multiplier_accum, bokeh); } } } } } - color[0] = color_accum[0] * (1.0f / multiplier_accum[0]); - color[1] = color_accum[1] * (1.0f / multiplier_accum[1]); - color[2] = color_accum[2] * (1.0f / multiplier_accum[2]); - color[3] = color_accum[3] * (1.0f / multiplier_accum[3]); + color[0] = color_accum[0] / multiplier_accum[0]; + color[1] = color_accum[1] / multiplier_accum[1]; + color[2] = color_accum[2] / multiplier_accum[2]; + color[3] = color_accum[3] / multiplier_accum[3]; } } +void VariableSizeBokehBlurOperation::executeOpenCL(OpenCLDevice* device, + MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, + MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, + list<cl_kernel> *clKernelsToCleanUp) +{ + cl_kernel defocusKernel = device->COM_clCreateKernel("defocusKernel", NULL); + + cl_int step = this->getStep(); + cl_int maxBlur = this->m_maxBlur; + cl_float threshold = this->m_threshold; + + device->COM_clAttachMemoryBufferToKernelParameter(defocusKernel, 0, -1, clMemToCleanUp, inputMemoryBuffers, this->m_inputProgram); + device->COM_clAttachMemoryBufferToKernelParameter(defocusKernel, 1, -1, clMemToCleanUp, inputMemoryBuffers, this->m_inputBokehProgram); + device->COM_clAttachMemoryBufferToKernelParameter(defocusKernel, 2, 4, clMemToCleanUp, inputMemoryBuffers, this->m_inputSizeProgram); + device->COM_clAttachOutputMemoryBufferToKernelParameter(defocusKernel, 3, clOutputBuffer); + device->COM_clAttachMemoryBufferOffsetToKernelParameter(defocusKernel, 5, outputMemoryBuffer); + clSetKernelArg(defocusKernel, 6, sizeof(cl_int), &step); + clSetKernelArg(defocusKernel, 7, sizeof(cl_int), &maxBlur); + clSetKernelArg(defocusKernel, 8, sizeof(cl_float), &threshold); + device->COM_clAttachSizeToKernelParameter(defocusKernel, 9, this); + + device->COM_clEnqueueRange(defocusKernel, outputMemoryBuffer, 10, this); +} + void VariableSizeBokehBlurOperation::deinitExecution() { this->m_inputProgram = NULL; this->m_inputBokehProgram = NULL; this->m_inputSizeProgram = NULL; +#ifdef COM_DEFOCUS_SEARCH + this->m_inputSearchProgram = NULL; +#endif } bool VariableSizeBokehBlurOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) @@ -130,6 +169,7 @@ bool VariableSizeBokehBlurOperation::determineDependingAreaOfInterest(rcti *inpu bokehInput.xmin = 0; bokehInput.ymax = 512; bokehInput.ymin = 0; + NodeOperation *operation = getInputOperation(2); if (operation->determineDependingAreaOfInterest(&newInput, readOperation, output) ) { @@ -139,13 +179,118 @@ bool VariableSizeBokehBlurOperation::determineDependingAreaOfInterest(rcti *inpu if (operation->determineDependingAreaOfInterest(&bokehInput, readOperation, output) ) { return true; } - operation = getInputOperation(3); - if (operation->determineDependingAreaOfInterest(&newInput, readOperation, output) ) { +#ifdef COM_DEFOCUS_SEARCH + rcti searchInput; + searchInput.xmax = (input->xmax / InverseSearchRadiusOperation::DIVIDER) + 1; + searchInput.xmin = (input->xmin / InverseSearchRadiusOperation::DIVIDER) - 1; + searchInput.ymax = (input->ymax / InverseSearchRadiusOperation::DIVIDER) + 1; + searchInput.ymin = (input->ymin / InverseSearchRadiusOperation::DIVIDER) - 1; + operation = getInputOperation(4); + if (operation->determineDependingAreaOfInterest(&searchInput, readOperation, output) ) { return true; } +#endif operation = getInputOperation(0); if (operation->determineDependingAreaOfInterest(&newInput, readOperation, output) ) { return true; } return false; } + +#ifdef COM_DEFOCUS_SEARCH +// InverseSearchRadiusOperation +InverseSearchRadiusOperation::InverseSearchRadiusOperation() : NodeOperation() +{ + this->addInputSocket(COM_DT_VALUE, COM_SC_NO_RESIZE); // radius + this->addInputSocket(COM_DT_VALUE, COM_SC_NO_RESIZE); // depth + this->addOutputSocket(COM_DT_COLOR); + this->setComplex(true); + this->inputRadius = NULL; + this->inputDepth = NULL; +} + +void InverseSearchRadiusOperation::initExecution() +{ + this->inputRadius = this->getInputSocketReader(0); + this->inputDepth = this->getInputSocketReader(1); +} + +void* InverseSearchRadiusOperation::initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers) +{ + MemoryBuffer * data = new MemoryBuffer(NULL, rect); + int x, y; + float width = this->inputRadius->getWidth(); + float height = this->inputRadius->getHeight(); + + for (x = rect->xmin; x < rect->xmax ; x++) { + for (y = rect->ymin; y < rect->ymax ; y++) { + float[4] temp; + int rx = x * DIVIDER; + int ry = y * DIVIDER; + this->inputRadius->read(temp, rx, ry, memoryBuffers, NULL); + float centerRadius = temp[0]; + this->inputDepth->read(temp, rx, ry, memoryBuffers, NULL); + float centerDepth = temp[0]; + t[0] = MAX2(rx - this->maxBlur, 0.0f); + t[1] = MAX2(ry - this->maxBlur, 0.0f); + t[2] = MIN2(rx + this->maxBlur, width); + t[3] = MIN2(ry + this->maxBlur, height); + int minx = t[0]; + int miny = t[1]; + int maxx = t[2]; + int maxy = t[3]; + int sminx = rx; + int smaxx = rx; + int sminy = ry; + int smaxy = ry; + for (int nx = minx ; nx < maxx ; nx ++) { + for (int ny = miny ; ny < maxy ; ny ++) { + this->inputRadius->read(temp, nx, ny, memoryBuffers, NULL); + if (nx < rx && temp[0]) + + } + } + float t[4]; + data->writePixel(x, y, t); + } + } + return data; +} + +void InverseSearchRadiusOperation::executePixel(float *color, int x, int y, MemoryBuffer *inputBuffers[], void *data) +{ + MemoryBuffer *buffer = (MemoryBuffer*)data; + buffer->read(color, x, y); +} + +void InverseSearchRadiusOperation::deinitializeTileData(rcti *rect, MemoryBuffer **memoryBuffers, void *data) +{ + if (data) { + MemoryBuffer* mb = (MemoryBuffer*)data; + delete mb; + } +} + +void InverseSearchRadiusOperation::deinitExecution() +{ + this->inputRadius = NULL; + this->inputDepth = NULL; +} + +void InverseSearchRadiusOperation::determineResolution(unsigned int resolution[], unsigned int preferredResolution[]) +{ + NodeOperation::determineResolution(resolution, preferredResolution); + resolution[0] = resolution[0] / DIVIDER; + resolution[1] = resolution[1] / DIVIDER; +} + +bool InverseSearchRadiusOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) +{ + rcti newRect; + newRect.ymin = input->ymin*DIVIDER; + newRect.ymax = input->ymax*DIVIDER; + newRect.xmin = input->xmin*DIVIDER; + newRect.xmax = input->xmax*DIVIDER; + return NodeOperation::determineDependingAreaOfInterest(&newRect, readOperation, output); +} +#endif diff --git a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.h b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.h index 8e59a43fcb1..6c9196c3eab 100644 --- a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.h +++ b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.h @@ -25,6 +25,7 @@ #include "COM_NodeOperation.h" #include "COM_QualityStepHelper.h" + class VariableSizeBokehBlurOperation : public NodeOperation, public QualityStepHelper { private: int m_maxBlur; @@ -32,7 +33,9 @@ private: SocketReader *m_inputProgram; SocketReader *m_inputBokehProgram; SocketReader *m_inputSizeProgram; - SocketReader *m_inputDepthProgram; +#ifdef COM_DEFOCUS_SEARCH + SocketReader *inputSearchProgram; +#endif public: VariableSizeBokehBlurOperation(); @@ -58,6 +61,44 @@ public: void setThreshold(float threshold) { this->m_threshold = threshold; } + void executeOpenCL(OpenCLDevice* device, MemoryBuffer *outputMemoryBuffer, cl_mem clOutputBuffer, MemoryBuffer **inputMemoryBuffers, list<cl_mem> *clMemToCleanUp, list<cl_kernel> *clKernelsToCleanUp); +}; + +#ifdef COM_DEFOCUS_SEARCH +class InverseSearchRadiusOperation : public NodeOperation { +private: + int maxBlur; + float threshold; + SocketReader *inputDepth; + SocketReader *inputRadius; +public: + static const int DIVIDER = 4; + + InverseSearchRadiusOperation(); + + /** + * the inner loop of this program + */ + void executePixel(float *color, int x, int y, MemoryBuffer * inputBuffers[], void *data); + + /** + * Initialize the execution + */ + void initExecution(); + void* initializeTileData(rcti *rect, MemoryBuffer **memoryBuffers); + void deinitializeTileData(rcti *rect, MemoryBuffer **memoryBuffers, void *data); + + /** + * Deinitialize the execution + */ + void deinitExecution(); + + bool determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output); + void determineResolution(unsigned int resolution[], unsigned int preferredResolution[]); + + void setMaxBlur(int maxRadius) { this->maxBlur = maxRadius; } + void setThreshold(float threshold) { this->threshold = threshold; } }; #endif +#endif diff --git a/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp b/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp index f229c6cf365..446b169763c 100644 --- a/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp +++ b/source/blender/compositor/operations/COM_ViewerBaseOperation.cpp @@ -35,7 +35,6 @@ extern "C" { #include "MEM_guardedalloc.h" #include "IMB_imbuf.h" #include "IMB_imbuf_types.h" - #include "IMB_colormanagement.h" } @@ -47,13 +46,10 @@ ViewerBaseOperation::ViewerBaseOperation() : NodeOperation() this->m_outputBufferDisplay = NULL; this->m_active = false; this->m_doColorManagement = true; - this->m_partialBufferUpdate = NULL; } void ViewerBaseOperation::initExecution() { - this->m_partialBufferUpdate = NULL; - if (isActiveViewerOutput()) { initImage(); } @@ -63,7 +59,7 @@ void ViewerBaseOperation::initImage() { Image *anImage = this->m_image; ImBuf *ibuf = BKE_image_acquire_ibuf(anImage, this->m_imageUser, &this->m_lock); - + if (!ibuf) return; if (ibuf->x != (int)getWidth() || ibuf->y != (int)getHeight()) { imb_freerectImBuf(ibuf); @@ -75,34 +71,20 @@ void ViewerBaseOperation::initImage() imb_addrectfloatImBuf(ibuf); anImage->ok = IMA_OK_LOADED; } - - this->m_partialBufferUpdate = IMB_partial_buffer_update_context_new(ibuf); - + /* now we combine the input with ibuf */ this->m_outputBuffer = ibuf->rect_float; this->m_outputBufferDisplay = (unsigned char *)ibuf->rect; - + BKE_image_release_ibuf(this->m_image, this->m_lock); } void ViewerBaseOperation:: updateImage(rcti *rect) { - IMB_partial_buffer_update_rect(this->m_partialBufferUpdate, this->m_outputBuffer, rect); - WM_main_add_notifier(NC_WINDOW | ND_DRAW, NULL); } void ViewerBaseOperation::deinitExecution() { - if (this->m_partialBufferUpdate) { - /* partial buffer context could be NULL if it's not active viewer node */ - - ImBuf *ibuf = BKE_image_acquire_ibuf(this->m_image, this->m_imageUser, &this->m_lock); - - IMB_partial_buffer_update_free(this->m_partialBufferUpdate, ibuf); - - BKE_image_release_ibuf(this->m_image, this->m_lock); - } - this->m_outputBuffer = NULL; } diff --git a/source/blender/compositor/operations/COM_ViewerBaseOperation.h b/source/blender/compositor/operations/COM_ViewerBaseOperation.h index 4052c49ebbc..f3fd1e9c9df 100644 --- a/source/blender/compositor/operations/COM_ViewerBaseOperation.h +++ b/source/blender/compositor/operations/COM_ViewerBaseOperation.h @@ -40,7 +40,6 @@ protected: bool m_doColorManagement; bool m_doColorPredivide; - struct PartialBufferUpdateContext *m_partialBufferUpdate; public: bool isOutputOperation(bool rendering) const { return isActiveViewerOutput(); } void initExecution(); diff --git a/source/blender/compositor/operations/COM_WriteBufferOperation.cpp b/source/blender/compositor/operations/COM_WriteBufferOperation.cpp index 7259db34134..8decb73615b 100644 --- a/source/blender/compositor/operations/COM_WriteBufferOperation.cpp +++ b/source/blender/compositor/operations/COM_WriteBufferOperation.cpp @@ -156,10 +156,8 @@ void WriteBufferOperation::executeOpenCLRegion(OpenCLDevice* device, rcti *rect, if (error != CL_SUCCESS) { printf("CLERROR[%d]: %s\n", error, clewErrorString(error)); } this->getMemoryProxy()->getBuffer()->copyContentFrom(outputBuffer); - - // STEP 4 - + // STEP 4 while (clMemToCleanUp->size() > 0) { cl_mem mem = clMemToCleanUp->front(); error = clReleaseMemObject(mem); diff --git a/source/blender/compositor/operations/COM_WriteBufferOperation.h b/source/blender/compositor/operations/COM_WriteBufferOperation.h index 24bfdecd124..d77814a9dc4 100644 --- a/source/blender/compositor/operations/COM_WriteBufferOperation.h +++ b/source/blender/compositor/operations/COM_WriteBufferOperation.h @@ -46,6 +46,9 @@ public: void deinitExecution(); void executeOpenCLRegion(OpenCLDevice* device, rcti *rect, unsigned int chunkNumber, MemoryBuffer **memoryBuffers, MemoryBuffer *outputBuffer); void readResolutionFromInputSocket(); + inline NodeOperation *getInput() { + return m_input; + } }; #endif diff --git a/source/blender/compositor/operations/COM_ZCombineOperation.h b/source/blender/compositor/operations/COM_ZCombineOperation.h index 2ade3f599ad..422a946b98f 100644 --- a/source/blender/compositor/operations/COM_ZCombineOperation.h +++ b/source/blender/compositor/operations/COM_ZCombineOperation.h @@ -26,8 +26,8 @@ /** - * this program converts an input colour to an output value. - * it assumes we are in sRGB colour space. + * this program converts an input color to an output value. + * it assumes we are in sRGB color space. */ class ZCombineOperation : public NodeOperation { protected: |