Welcome to mirror list, hosted at ThFree Co, Russian Federation.

COM_DefocusNode.cpp « nodes « compositor « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 77f7baaef98408ed3101438681fe1cf544fd3328 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
 * Copyright 2011, Blender Foundation.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Contributor: 
 *		Jeroen Bakker 
 *		Monique Dewanchand
 */

#include "COM_DefocusNode.h"
#include "DNA_scene_types.h"
#include "DNA_camera_types.h"
#include "DNA_object_types.h"
#include "DNA_node_types.h"
#include "COM_ExecutionSystem.h"
#include "COM_ConvertDepthToRadiusOperation.h"
#include "COM_VariableSizeBokehBlurOperation.h"
#include "COM_BokehImageOperation.h"
#include "COM_MathBaseOperation.h"
#include "COM_SetValueOperation.h"
#include "COM_GammaCorrectOperation.h"

DefocusNode::DefocusNode(bNode *editorNode): Node(editorNode)
{
}

void DefocusNode::convertToOperations(ExecutionSystem *graph, CompositorContext * context)
{
	bNode *node = this->getbNode();
	Scene *scene = (Scene*)node->id;
	Object *camob = (scene)? scene->camera: NULL;
	NodeDefocus *data = (NodeDefocus*)node->storage;

	NodeOperation *radiusOperation;
	if (data->no_zbuf) {
		MathMultiplyOperation *multiply = new MathMultiplyOperation();
		SetValueOperation *multiplier = new SetValueOperation();
		multiplier->setValue(data->scale);
		SetValueOperation *maxRadius = new SetValueOperation();
		maxRadius->setValue(data->maxblur);
		MathMinimumOperation *minimize = new MathMinimumOperation();
		this->getInputSocket(1)->relinkConnections(multiply->getInputSocket(0), true, 1, graph);
		addLink(graph, multiplier->getOutputSocket(), multiply->getInputSocket(1));
		addLink(graph, maxRadius->getOutputSocket(), minimize->getInputSocket(1));
		addLink(graph, multiply->getOutputSocket(), minimize->getInputSocket(0));
		
		graph->addOperation(multiply);
		graph->addOperation(multiplier);
		graph->addOperation(maxRadius);
		graph->addOperation(minimize);
		radiusOperation = minimize;
	}
	else {
		ConvertDepthToRadiusOperation *converter = new ConvertDepthToRadiusOperation();
		converter->setCameraObject(camob);
		converter->setfStop(data->fstop);
		converter->setMaxRadius(data->maxblur);
		this->getInputSocket(1)->relinkConnections(converter->getInputSocket(0), true, 1, graph);
		graph->addOperation(converter);
		radiusOperation = converter;
	}
	
	BokehImageOperation *bokeh = new BokehImageOperation();
	NodeBokehImage * bokehdata = new NodeBokehImage();
	bokehdata->angle = data->rotation;
	bokehdata->rounding = 0.0f;
	bokehdata->flaps = data->bktype;
	if (data->bktype<3) {
		bokehdata->flaps = 5;
		bokehdata->rounding = 1.0f;
	}
	bokehdata->catadioptric = 0.0f;
	bokehdata->lensshift = 0.0f;
	
	bokeh->setData(bokehdata);
	bokeh->deleteDataOnFinish();
	graph->addOperation(bokeh);
	
	VariableSizeBokehBlurOperation *operation = new VariableSizeBokehBlurOperation();
	operation->setQuality(context->getQuality());
	operation->setMaxBlur(data->maxblur);
	operation->setThreshold(data->bthresh);
	addLink(graph, bokeh->getOutputSocket(), operation->getInputSocket(1));
	addLink(graph, radiusOperation->getOutputSocket(), operation->getInputSocket(2));
	if (data->gamco) {
		GammaCorrectOperation * correct = new GammaCorrectOperation();
		GammaUncorrectOperation * inverse = new GammaUncorrectOperation();
		this->getInputSocket(0)->relinkConnections(correct->getInputSocket(0), 0, true, graph);
		addLink(graph, correct->getOutputSocket(), operation->getInputSocket(0));
		addLink(graph, operation->getOutputSocket(), inverse->getInputSocket(0));
		this->getOutputSocket()->relinkConnections(inverse->getOutputSocket());
		graph->addOperation(correct);
		graph->addOperation(inverse);
	}
	else {
		this->getInputSocket(0)->relinkConnections(operation->getInputSocket(0), 0, true, graph);
		this->getOutputSocket()->relinkConnections(operation->getOutputSocket());
	}
	
	graph->addOperation(operation);
}