[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48758] trunk/blender/source/blender/ compositor: removed depth aware defocus
Jeroen Bakker
j.bakker at atmind.nl
Mon Jul 9 17:21:43 CEST 2012
Revision: 48758
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48758
Author: jbakker
Date: 2012-07-09 15:21:43 +0000 (Mon, 09 Jul 2012)
Log Message:
-----------
removed depth aware defocus
add blur to radius buffer
Modified Paths:
--------------
trunk/blender/source/blender/compositor/nodes/COM_DefocusNode.cpp
trunk/blender/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.cpp
trunk/blender/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.h
trunk/blender/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp
trunk/blender/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h
trunk/blender/source/blender/compositor/operations/COM_OpenCLKernels.cl
trunk/blender/source/blender/compositor/operations/COM_OpenCLKernels.cl.h
trunk/blender/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.cpp
trunk/blender/source/blender/compositor/operations/COM_VariableSizeBokehBlurOperation.h
Modified: trunk/blender/source/blender/compositor/nodes/COM_DefocusNode.cpp
===================================================================
--- trunk/blender/source/blender/compositor/nodes/COM_DefocusNode.cpp 2012-07-09 14:25:35 UTC (rev 48757)
+++ trunk/blender/source/blender/compositor/nodes/COM_DefocusNode.cpp 2012-07-09 15:21:43 UTC (rev 48758)
@@ -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)
{
@@ -46,7 +47,6 @@
NodeDefocus *data = (NodeDefocus *)node->storage;
NodeOperation *radiusOperation;
- OutputSocket * depthOperation;
if (data->no_zbuf) {
MathMultiplyOperation *multiply = new MathMultiplyOperation();
SetValueOperation *multiplier = new SetValueOperation();
@@ -64,7 +64,6 @@
graph->addOperation(maxRadius);
graph->addOperation(minimize);
radiusOperation = minimize;
- depthOperation = minimize->getOutputSocket(0);
}
else {
ConvertDepthToRadiusOperation *converter = new ConvertDepthToRadiusOperation();
@@ -73,8 +72,12 @@
converter->setMaxRadius(data->maxblur);
this->getInputSocket(1)->relinkConnections(converter->getInputSocket(0), 1, graph);
graph->addOperation(converter);
- radiusOperation = converter;
- depthOperation = converter->getInputSocket(0)->getConnection()->getFromSocket();
+
+ FastGaussianBlurValueOperation * blur = new FastGaussianBlurValueOperation();
+ addLink(graph, converter->getOutputSocket(0), blur->getInputSocket(0));
+ graph->addOperation(blur);
+ radiusOperation = blur;
+ converter->setPostBlur(blur);
}
BokehImageOperation *bokeh = new BokehImageOperation();
@@ -112,7 +115,6 @@
operation->setThreshold(data->bthresh);
addLink(graph, bokeh->getOutputSocket(), operation->getInputSocket(1));
addLink(graph, radiusOperation->getOutputSocket(), operation->getInputSocket(2));
- addLink(graph, depthOperation, operation->getInputSocket(3));
#ifdef COM_DEFOCUS_SEARCH
addLink(graph, search->getOutputSocket(), operation->getInputSocket(4));
#endif
Modified: trunk/blender/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.cpp 2012-07-09 14:25:35 UTC (rev 48757)
+++ trunk/blender/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.cpp 2012-07-09 15:21:43 UTC (rev 48758)
@@ -32,6 +32,7 @@
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 @@
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 @@
#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;
}
Modified: trunk/blender/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.h
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.h 2012-07-09 14:25:35 UTC (rev 48757)
+++ trunk/blender/source/blender/compositor/operations/COM_ConvertDepthToRadiusOperation.h 2012-07-09 15:21:43 UTC (rev 48758)
@@ -24,7 +24,7 @@
#define _COM_ConvertDepthToRadiusOperation_h
#include "COM_NodeOperation.h"
#include "DNA_object_types.h"
-
+#include "COM_FastGaussianBlurOperation.h"
/**
* this program converts an input color to an output value.
* it assumes we are in sRGB color space.
@@ -43,6 +43,8 @@
float m_cam_lens;
float m_dof_sp;
Object *m_cameraObject;
+
+ FastGaussianBlurValueOperation *m_blurPostOperation;
public:
/**
* Default constructor
@@ -68,5 +70,7 @@
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
Modified: trunk/blender/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp 2012-07-09 14:25:35 UTC (rev 48757)
+++ trunk/blender/source/blender/compositor/operations/COM_FastGaussianBlurOperation.cpp 2012-07-09 15:21:43 UTC (rev 48758)
@@ -220,3 +220,66 @@
#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;
+}
+
Modified: trunk/blender/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h 2012-07-09 14:25:35 UTC (rev 48757)
+++ trunk/blender/source/blender/compositor/operations/COM_FastGaussianBlurOperation.h 2012-07-09 15:21:43 UTC (rev 48758)
@@ -40,7 +40,23 @@
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
Modified: trunk/blender/source/blender/compositor/operations/COM_OpenCLKernels.cl
===================================================================
--- trunk/blender/source/blender/compositor/operations/COM_OpenCLKernels.cl 2012-07-09 14:25:35 UTC (rev 48757)
+++ trunk/blender/source/blender/compositor/operations/COM_OpenCLKernels.cl 2012-07-09 15:21:43 UTC (rev 48758)
@@ -53,7 +53,7 @@
//KERNEL --- DEFOCUS /VARIABLESIZEBOKEHBLUR ---
__kernel void defocusKernel(__read_only image2d_t inputImage, __read_only image2d_t bokehImage,
- __read_only image2d_t inputDepth, __read_only image2d_t inputSize,
+ __read_only image2d_t inputSize,
__write_only image2d_t output, int2 offsetInput, int2 offsetOutput,
int step, int maxBlur, float threshold, int2 dimension, int2 offset)
{
@@ -65,7 +65,6 @@
float4 readColor;
float4 bokeh;
float tempSize;
- float tempDepth;
float4 multiplier_accum = {1.0f, 1.0f, 1.0f, 1.0f};
float4 color_accum;
@@ -77,7 +76,6 @@
{
int2 inputCoordinate = realCoordinate - offsetInput;
float size = read_imagef(inputSize, SAMPLER_NEAREST, inputCoordinate).s0;
- float depth = read_imagef(inputDepth, SAMPLER_NEAREST, inputCoordinate).s0 + threshold;
color_accum = read_imagef(inputImage, SAMPLER_NEAREST, inputCoordinate);
for (int ny = miny; ny < maxy; ny += step) {
@@ -85,21 +83,17 @@
if (nx >= 0 && nx < dimension.s0 && ny >= 0 && ny < dimension.s1) {
inputCoordinate.s0 = nx - offsetInput.s0;
inputCoordinate.s1 = ny - offsetInput.s1;
- tempDepth = read_imagef(inputDepth, SAMPLER_NEAREST, inputCoordinate).s0;
- if (tempDepth < depth) {
- tempSize = read_imagef(inputSize, SAMPLER_NEAREST, inputCoordinate).s0;
-
- if ((size > threshold && tempSize > 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;
- }
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list