Cycles: svn merge -r41225:41232 ^/trunk/blender
[blender.git] / intern / cycles / render / integrator.cpp
1 /*
2  * Copyright 2011, Blender Foundation.
3  *
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.
8  *
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.
13  *
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.
17  */
18
19 #include "device.h"
20 #include "integrator.h"
21 #include "scene.h"
22 #include "sobol.h"
23
24 CCL_NAMESPACE_BEGIN
25
26 Integrator::Integrator()
27 {
28         min_bounce = 2;
29         max_bounce = 7;
30
31         max_diffuse_bounce = max_bounce;
32         max_glossy_bounce = max_bounce;
33         max_transmission_bounce = max_bounce;
34         probalistic_termination = true;
35
36         transparent_min_bounce = min_bounce;
37         transparent_max_bounce = max_bounce;
38         transparent_probalistic = true;
39         transparent_shadows = false;
40
41         no_caustics = false;
42         blur_caustics = 0.0f;
43
44         need_update = true;
45 }
46
47 Integrator::~Integrator()
48 {
49 }
50
51 void Integrator::device_update(Device *device, DeviceScene *dscene)
52 {
53         if(!need_update)
54                 return;
55
56         device_free(device, dscene);
57
58         KernelIntegrator *kintegrator = &dscene->data.integrator;
59
60         /* integrator parameters */
61         kintegrator->max_bounce = max_bounce + 1;
62         if(probalistic_termination)
63                 kintegrator->min_bounce = min_bounce + 1;
64         else
65                 kintegrator->min_bounce = kintegrator->max_bounce;
66
67         kintegrator->max_diffuse_bounce = max_diffuse_bounce + 1;
68         kintegrator->max_glossy_bounce = max_glossy_bounce + 1;
69         kintegrator->max_transmission_bounce = max_transmission_bounce + 1;
70
71         kintegrator->transparent_max_bounce = transparent_max_bounce + 1;
72         if(transparent_probalistic)
73                 kintegrator->transparent_min_bounce = transparent_min_bounce + 1;
74         else
75                 kintegrator->transparent_min_bounce = kintegrator->transparent_max_bounce;
76
77         kintegrator->transparent_shadows = transparent_shadows;
78
79         kintegrator->no_caustics = no_caustics;
80         kintegrator->blur_caustics = blur_caustics;
81
82         /* sobol directions table */
83         int dimensions = PRNG_BASE_NUM + (max_bounce + transparent_max_bounce + 2)*PRNG_BOUNCE_NUM;
84         uint *directions = dscene->sobol_directions.resize(SOBOL_BITS*dimensions);
85
86         sobol_generate_direction_vectors((uint(*)[SOBOL_BITS])directions, dimensions);
87
88         device->tex_alloc("__sobol_directions", dscene->sobol_directions);
89
90         need_update = false;
91 }
92
93 void Integrator::device_free(Device *device, DeviceScene *dscene)
94 {
95         device->tex_free(dscene->sobol_directions);
96         dscene->sobol_directions.clear();
97 }
98
99 bool Integrator::modified(const Integrator& integrator)
100 {
101         return !(min_bounce == integrator.min_bounce &&
102                 max_bounce == integrator.max_bounce &&
103                 max_diffuse_bounce == integrator.max_diffuse_bounce &&
104                 max_glossy_bounce == integrator.max_glossy_bounce &&
105                 max_transmission_bounce == integrator.max_transmission_bounce &&
106                 probalistic_termination == integrator.probalistic_termination &&
107                 transparent_min_bounce == integrator.transparent_min_bounce &&
108                 transparent_max_bounce == integrator.transparent_max_bounce &&
109                 transparent_probalistic == integrator.transparent_probalistic &&
110                 transparent_shadows == integrator.transparent_shadows &&
111                 no_caustics == integrator.no_caustics &&
112                 blur_caustics == integrator.blur_caustics);
113 }
114
115 void Integrator::tag_update(Scene *scene)
116 {
117         need_update = true;
118 }
119
120 CCL_NAMESPACE_END
121