Blender V2.61 - r43446

integrator.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 2011, Blender Foundation.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 #include "device.h"
00020 #include "integrator.h"
00021 #include "scene.h"
00022 #include "sobol.h"
00023 
00024 #include "util_hash.h"
00025 
00026 CCL_NAMESPACE_BEGIN
00027 
00028 Integrator::Integrator()
00029 {
00030     min_bounce = 2;
00031     max_bounce = 7;
00032 
00033     max_diffuse_bounce = max_bounce;
00034     max_glossy_bounce = max_bounce;
00035     max_transmission_bounce = max_bounce;
00036     probalistic_termination = true;
00037 
00038     transparent_min_bounce = min_bounce;
00039     transparent_max_bounce = max_bounce;
00040     transparent_probalistic = true;
00041     transparent_shadows = false;
00042 
00043     no_caustics = false;
00044     seed = 0;
00045     layer_flag = ~0;
00046 
00047     need_update = true;
00048 }
00049 
00050 Integrator::~Integrator()
00051 {
00052 }
00053 
00054 void Integrator::device_update(Device *device, DeviceScene *dscene)
00055 {
00056     if(!need_update)
00057         return;
00058 
00059     device_free(device, dscene);
00060 
00061     KernelIntegrator *kintegrator = &dscene->data.integrator;
00062 
00063     /* integrator parameters */
00064     kintegrator->max_bounce = max_bounce + 1;
00065     if(probalistic_termination)
00066         kintegrator->min_bounce = min_bounce + 1;
00067     else
00068         kintegrator->min_bounce = kintegrator->max_bounce;
00069 
00070     kintegrator->max_diffuse_bounce = max_diffuse_bounce + 1;
00071     kintegrator->max_glossy_bounce = max_glossy_bounce + 1;
00072     kintegrator->max_transmission_bounce = max_transmission_bounce + 1;
00073 
00074     kintegrator->transparent_max_bounce = transparent_max_bounce + 1;
00075     if(transparent_probalistic)
00076         kintegrator->transparent_min_bounce = transparent_min_bounce + 1;
00077     else
00078         kintegrator->transparent_min_bounce = kintegrator->transparent_max_bounce;
00079 
00080     kintegrator->transparent_shadows = transparent_shadows;
00081 
00082     kintegrator->no_caustics = no_caustics;
00083     kintegrator->seed = hash_int(seed);
00084     kintegrator->layer_flag = layer_flag << PATH_RAY_LAYER_SHIFT;
00085 
00086     /* sobol directions table */
00087     int dimensions = PRNG_BASE_NUM + (max_bounce + transparent_max_bounce + 2)*PRNG_BOUNCE_NUM;
00088     uint *directions = dscene->sobol_directions.resize(SOBOL_BITS*dimensions);
00089 
00090     sobol_generate_direction_vectors((uint(*)[SOBOL_BITS])directions, dimensions);
00091 
00092     device->tex_alloc("__sobol_directions", dscene->sobol_directions);
00093 
00094     need_update = false;
00095 }
00096 
00097 void Integrator::device_free(Device *device, DeviceScene *dscene)
00098 {
00099     device->tex_free(dscene->sobol_directions);
00100     dscene->sobol_directions.clear();
00101 }
00102 
00103 bool Integrator::modified(const Integrator& integrator)
00104 {
00105     return !(min_bounce == integrator.min_bounce &&
00106         max_bounce == integrator.max_bounce &&
00107         max_diffuse_bounce == integrator.max_diffuse_bounce &&
00108         max_glossy_bounce == integrator.max_glossy_bounce &&
00109         max_transmission_bounce == integrator.max_transmission_bounce &&
00110         probalistic_termination == integrator.probalistic_termination &&
00111         transparent_min_bounce == integrator.transparent_min_bounce &&
00112         transparent_max_bounce == integrator.transparent_max_bounce &&
00113         transparent_probalistic == integrator.transparent_probalistic &&
00114         transparent_shadows == integrator.transparent_shadows &&
00115         no_caustics == integrator.no_caustics &&
00116         layer_flag == integrator.layer_flag &&
00117         seed == integrator.seed);
00118 }
00119 
00120 void Integrator::tag_update(Scene *scene)
00121 {
00122     need_update = true;
00123 }
00124 
00125 CCL_NAMESPACE_END
00126