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

film.cpp « render « cycles « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 05874244605cb604e6e25de0d570b24c40cc08c1 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
 * 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.
 */

#include "camera.h"
#include "device.h"
#include "film.h"
#include "film_response.h"
#include "scene.h"

CCL_NAMESPACE_BEGIN

static FilmResponseType find_response_type(const string& name)
{
	if(name == "" || name == "None")
		return FILM_RESPONSE_NONE;

	for(size_t i = 0; i < FILM_RESPONSE_NUM; i++) {
		FilmResponse *curve = &FILM_RESPONSE[i];
		if(curve->name == name)
			return (FilmResponseType)i;
	}

	return FILM_RESPONSE_NONE;
}

Film::Film()
{
	exposure = 0.8f;
	response = "Advantix 400";
	last_response = "";
	need_update = true;
}

Film::~Film()
{
}

#if 0
static void generate_python_enum()
{
	for(size_t i = 0; i < FILM_RESPONSE_NUM; i++) {
		FilmResponse *curve = &FILM_RESPONSE[i];
		/*if(i == 0 || strcmp(curve->brand, FILM_RESPONSE[i-1].brand))
			printf("(\"\", \"%s\", \"\"),\n", curve->brand);*/
		printf("(\"%s\", \"%s %s\", \"\"),\n", curve->name, curve->brand, curve->name);
	}
}
#endif

void Film::device_update(Device *device, DeviceScene *dscene)
{
	if(!need_update)
		return;

	KernelFilm *kfilm = &dscene->data.film;

	/* update __data */
	kfilm->exposure = exposure;

	FilmResponseType response_type = find_response_type(response);

	/* update __response_curves */
	if(response != last_response)  {
		device_free(device, dscene);

		if(response_type != FILM_RESPONSE_NONE)  {
			FilmResponse *curve = &FILM_RESPONSE[response_type];
			size_t response_curve_size = FILM_RESPONSE_SIZE;

			dscene->response_curve_R.copy(curve->B_R, response_curve_size);

			if(curve->rgb) {
				dscene->response_curve_G.copy(curve->B_G, response_curve_size);
				dscene->response_curve_B.copy(curve->B_B, response_curve_size);
			}
			else {
				dscene->response_curve_G.copy(curve->B_R, response_curve_size);
				dscene->response_curve_B.copy(curve->B_R, response_curve_size);
			}

			device->tex_alloc("__response_curve_R", dscene->response_curve_R, true);
			device->tex_alloc("__response_curve_G", dscene->response_curve_G, true);
			device->tex_alloc("__response_curve_B", dscene->response_curve_B, true);
		}

		last_response = response;
	}

	kfilm->use_response_curve = (response_type != FILM_RESPONSE_NONE);

	need_update = false;
}

void Film::device_free(Device *device, DeviceScene *dscene)
{
	device->tex_free(dscene->response_curve_R);
	device->tex_free(dscene->response_curve_G);
	device->tex_free(dscene->response_curve_B);

	dscene->response_curve_R.clear();
	dscene->response_curve_G.clear();
	dscene->response_curve_B.clear();

	last_response = "";
}

bool Film::modified(const Film& film)
{
	return !(response == film.response &&
		exposure == film.exposure &&
		pass == film.pass);
}

void Film::tag_update(Scene *scene)
{
	need_update = true;
}

CCL_NAMESPACE_END