2
* Copyright 2011, Blender Foundation.
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23
#include "COM_BokehImageOperation.h"
26
BokehImageOperation::BokehImageOperation() : NodeOperation()
28
this->addOutputSocket(COM_DT_COLOR);
29
this->m_deleteData = false;
31
void BokehImageOperation::initExecution()
33
this->m_center[0] = getWidth() / 2;
34
this->m_center[1] = getHeight() / 2;
35
this->m_inverseRounding = 1.0f - this->m_data->rounding;
36
this->m_circularDistance = getWidth() / 2;
37
this->m_flapRad = (float)(M_PI * 2) / this->m_data->flaps;
38
this->m_flapRadAdd = (this->m_data->angle / 360.0f) * (float)(M_PI * 2.0);
39
while (this->m_flapRadAdd < 0.0f) {
40
this->m_flapRadAdd += (float)(M_PI * 2.0);
42
while (this->m_flapRadAdd > (float)M_PI) {
43
this->m_flapRadAdd -= (float)(M_PI * 2.0);
46
void BokehImageOperation::detemineStartPointOfFlap(float r[2], int flapNumber, float distance)
48
r[0] = sinf(this->m_flapRad * flapNumber + this->m_flapRadAdd) * distance + this->m_center[0];
49
r[1] = cosf(this->m_flapRad * flapNumber + this->m_flapRadAdd) * distance + this->m_center[1];
51
float BokehImageOperation::isInsideBokeh(float distance, float x, float y)
53
float insideBokeh = 0.0f;
54
const float deltaX = x - this->m_center[0];
55
const float deltaY = y - this->m_center[1];
56
float closestPoint[2];
63
const float distanceToCenter = len_v2v2(point, this->m_center);
64
const float bearing = (atan2f(deltaX, deltaY) + (float)(M_PI * 2.0));
65
int flapNumber = (int)((bearing - this->m_flapRadAdd) / this->m_flapRad);
67
detemineStartPointOfFlap(lineP1, flapNumber, distance);
68
detemineStartPointOfFlap(lineP2, flapNumber + 1, distance);
69
closest_to_line_v2(closestPoint, point, lineP1, lineP2);
71
const float distanceLineToCenter = len_v2v2(this->m_center, closestPoint);
72
const float distanceRoundingToCenter = this->m_inverseRounding * distanceLineToCenter + this->m_data->rounding * distance;
74
const float catadioptricDistanceToCenter = distanceRoundingToCenter * this->m_data->catadioptric;
75
if (distanceRoundingToCenter >= distanceToCenter && catadioptricDistanceToCenter <= distanceToCenter) {
76
if (distanceRoundingToCenter - distanceToCenter < 1.0f) {
77
insideBokeh = (distanceRoundingToCenter - distanceToCenter);
79
else if (this->m_data->catadioptric != 0.0f && distanceToCenter - catadioptricDistanceToCenter < 1.0f) {
80
insideBokeh = (distanceToCenter - catadioptricDistanceToCenter);
88
void BokehImageOperation::executePixel(float output[4], float x, float y, PixelSampler sampler)
90
float shift = this->m_data->lensshift;
91
float shift2 = shift / 2.0f;
92
float distance = this->m_circularDistance;
93
float insideBokehMax = isInsideBokeh(distance, x, y);
94
float insideBokehMed = isInsideBokeh(distance - fabsf(shift2 * distance), x, y);
95
float insideBokehMin = isInsideBokeh(distance - fabsf(shift * distance), x, y);
97
output[0] = insideBokehMax;
98
output[1] = insideBokehMed;
99
output[2] = insideBokehMin;
102
output[0] = insideBokehMin;
103
output[1] = insideBokehMed;
104
output[2] = insideBokehMax;
106
output[3] = (insideBokehMax + insideBokehMed + insideBokehMin) / 3.0f;
109
void BokehImageOperation::deinitExecution()
111
if (this->m_deleteData) {
119
void BokehImageOperation::determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2])
121
resolution[0] = COM_BLUR_BOKEH_PIXELS;
122
resolution[1] = COM_BLUR_BOKEH_PIXELS;