Cycles: code refactoring, to do render layer visibility test a bit different,
[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 #include "util_hash.h"
25
26 CCL_NAMESPACE_BEGIN
27
28 Integrator::Integrator()
29 {
30         min_bounce = 2;
31         max_bounce = 7;
32
33         max_diffuse_bounce = max_bounce;
34         max_glossy_bounce = max_bounce;
35         max_transmission_bounce = max_bounce;
36         probalistic_termination = true;
37
38         transparent_min_bounce = min_bounce;
39         transparent_max_bounce = max_bounce;
40         transparent_probalistic = true;
41         transparent_shadows = false;
42
43         no_caustics = false;
44         seed = 0;
45         layer_flag = ~0;
46
47         need_update = true;
48 }
49
50 Integrator::~Integrator()
51 {
52 }
53
54 void Integrator::device_update(Device *device, DeviceScene *dscene)
55 {
56         if(!need_update)
57                 return;
58
59         device_free(device, dscene);
60
61         KernelIntegrator *kintegrator = &dscene->data.integrator;
62
63         /* integrator parameters */
64         kintegrator->max_bounce = max_bounce + 1;
65         if(probalistic_termination)
66                 kintegrator->min_bounce = min_bounce + 1;
67         else
68                 kintegrator->min_bounce = kintegrator->max_bounce;
69
70         kintegrator->max_diffuse_bounce = max_diffuse_bounce + 1;
71         kintegrator->max_glossy_bounce = max_glossy_bounce + 1;
72         kintegrator->max_transmission_bounce = max_transmission_bounce + 1;
73
74         kintegrator->transparent_max_bounce = transparent_max_bounce + 1;
75         if(transparent_probalistic)
76                 kintegrator->transparent_min_bounce = transparent_min_bounce + 1;
77         else
78                 kintegrator->transparent_min_bounce = kintegrator->transparent_max_bounce;
79
80         kintegrator->transparent_shadows = transparent_shadows;
81
82         kintegrator->no_caustics = no_caustics;
83         kintegrator->seed = hash_int(seed);
84         kintegrator->layer_flag = layer_flag << PATH_RAY_LAYER_SHIFT;
85
86         /* sobol directions table */
87         int dimensions = PRNG_BASE_NUM + (max_bounce + transparent_max_bounce + 2)*PRNG_BOUNCE_NUM;
88         uint *directions = dscene->sobol_directions.resize(SOBOL_BITS*dimensions);
89
90         sobol_generate_direction_vectors((uint(*)[SOBOL_BITS])directions, dimensions);
91
92         device->tex_alloc("__sobol_directions", dscene->sobol_directions);
93
94         need_update = false;
95 }
96
97 void Integrator::device_free(Device *device, DeviceScene *dscene)
98 {
99         device->tex_free(dscene->sobol_directions);
100         dscene->sobol_directions.clear();
101 }
102
103 bool Integrator::modified(const Integrator& integrator)
104 {
105         return !(min_bounce == integrator.min_bounce &&
106                 max_bounce == integrator.max_bounce &&
107                 max_diffuse_bounce == integrator.max_diffuse_bounce &&
108                 max_glossy_bounce == integrator.max_glossy_bounce &&
109                 max_transmission_bounce == integrator.max_transmission_bounce &&
110                 probalistic_termination == integrator.probalistic_termination &&
111                 transparent_min_bounce == integrator.transparent_min_bounce &&
112                 transparent_max_bounce == integrator.transparent_max_bounce &&
113                 transparent_probalistic == integrator.transparent_probalistic &&
114                 transparent_shadows == integrator.transparent_shadows &&
115                 no_caustics == integrator.no_caustics &&
116                 layer_flag == integrator.layer_flag &&
117                 seed == integrator.seed);
118 }
119
120 void Integrator::tag_update(Scene *scene)
121 {
122         need_update = true;
123 }
124
125 CCL_NAMESPACE_END
126