diff options
Diffstat (limited to 'source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp')
-rw-r--r-- | source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp | 144 |
1 files changed, 138 insertions, 6 deletions
diff --git a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp index 9eb004b3686..46101f6355d 100644 --- a/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp +++ b/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp @@ -33,6 +33,9 @@ VariableSizeBokehBlurOperation::VariableSizeBokehBlurOperation() : NodeOperation 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); @@ -42,6 +45,9 @@ VariableSizeBokehBlurOperation::VariableSizeBokehBlurOperation() : NodeOperation this->m_inputDepthProgram = NULL; this->m_maxBlur = 32.0f; this->m_threshold = 1.0f; +#ifdef COM_DEFOCUS_SEARCH + this->m_inputSearchProgram = NULL; +#endif } @@ -51,6 +57,9 @@ void VariableSizeBokehBlurOperation::initExecution() 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); } @@ -63,10 +72,19 @@ void VariableSizeBokehBlurOperation::executePixel(float *color, int x, int y, Me 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); @@ -80,9 +98,9 @@ void VariableSizeBokehBlurOperation::executePixel(float *color, int x, int y, Me 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) { + this->m_inputSizeProgram->read(tempSize, nx, ny, COM_PS_NEAREST, inputBuffers); + float size = tempSize[0]; if ((sizeCenter > this->m_threshold && size > this->m_threshold) || size <= this->m_threshold) { float dx = nx - x; float dy = ny - y; @@ -115,6 +133,10 @@ void VariableSizeBokehBlurOperation::deinitExecution() this->m_inputProgram = NULL; this->m_inputBokehProgram = NULL; this->m_inputSizeProgram = NULL; + this->m_inputDepthProgram = NULL; +#ifdef COM_DEFOCUS_SEARCH + this->m_inputSearchProgram = NULL; +#endif } bool VariableSizeBokehBlurOperation::determineDependingAreaOfInterest(rcti *input, ReadBufferOperation *readOperation, rcti *output) @@ -130,6 +152,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) ) { @@ -143,9 +166,118 @@ bool VariableSizeBokehBlurOperation::determineDependingAreaOfInterest(rcti *inpu if (operation->determineDependingAreaOfInterest(&newInput, readOperation, output) ) { return true; } +#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 |