2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "background.h"
|
2014-01-02 21:05:07 +00:00
|
|
|
#include "bake.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "camera.h"
|
2013-04-01 20:26:43 +00:00
|
|
|
#include "curves.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "device.h"
|
|
|
|
#include "film.h"
|
|
|
|
#include "integrator.h"
|
|
|
|
#include "light.h"
|
|
|
|
#include "mesh.h"
|
|
|
|
#include "object.h"
|
2013-04-01 20:26:43 +00:00
|
|
|
#include "osl.h"
|
2012-08-31 17:27:08 +00:00
|
|
|
#include "particles.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "scene.h"
|
2013-04-01 20:26:43 +00:00
|
|
|
#include "shader.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "svm.h"
|
2013-04-01 20:26:43 +00:00
|
|
|
#include "tables.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
#include "util_foreach.h"
|
|
|
|
#include "util_progress.h"
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
Scene::Scene(const SceneParams& params_, const DeviceInfo& device_info_)
|
2011-04-27 11:58:34 +00:00
|
|
|
: params(params_)
|
|
|
|
{
|
|
|
|
device = NULL;
|
|
|
|
memset(&dscene.data, 0, sizeof(dscene.data));
|
|
|
|
|
|
|
|
camera = new Camera();
|
2013-04-01 20:26:43 +00:00
|
|
|
lookup_tables = new LookupTables();
|
2011-04-27 11:58:34 +00:00
|
|
|
film = new Film();
|
|
|
|
background = new Background();
|
|
|
|
light_manager = new LightManager();
|
|
|
|
mesh_manager = new MeshManager();
|
|
|
|
object_manager = new ObjectManager();
|
|
|
|
integrator = new Integrator();
|
|
|
|
image_manager = new ImageManager();
|
2012-08-31 17:27:08 +00:00
|
|
|
particle_system_manager = new ParticleSystemManager();
|
2012-12-28 14:21:30 +00:00
|
|
|
curve_system_manager = new CurveSystemManager();
|
2014-01-02 21:05:07 +00:00
|
|
|
bake_manager = new BakeManager();
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2012-12-04 07:48:09 +00:00
|
|
|
/* OSL only works on the CPU */
|
|
|
|
if(device_info_.type == DEVICE_CPU)
|
|
|
|
shader_manager = ShaderManager::create(this, params.shadingsystem);
|
|
|
|
else
|
|
|
|
shader_manager = ShaderManager::create(this, SceneParams::SVM);
|
|
|
|
|
2014-05-11 01:38:39 +00:00
|
|
|
/* Extended image limits for CPU and GPUs */
|
|
|
|
image_manager->set_extended_image_limits(device_info_);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Scene::~Scene()
|
|
|
|
{
|
2012-11-09 08:46:53 +00:00
|
|
|
free_memory(true);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-11-09 08:46:53 +00:00
|
|
|
void Scene::free_memory(bool final)
|
|
|
|
{
|
2011-04-27 11:58:34 +00:00
|
|
|
foreach(Shader *s, shaders)
|
|
|
|
delete s;
|
|
|
|
foreach(Mesh *m, meshes)
|
|
|
|
delete m;
|
|
|
|
foreach(Object *o, objects)
|
|
|
|
delete o;
|
|
|
|
foreach(Light *l, lights)
|
|
|
|
delete l;
|
2012-08-31 17:27:08 +00:00
|
|
|
foreach(ParticleSystem *p, particle_systems)
|
|
|
|
delete p;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-02-14 16:11:47 +00:00
|
|
|
shaders.clear();
|
|
|
|
meshes.clear();
|
|
|
|
objects.clear();
|
|
|
|
lights.clear();
|
|
|
|
particle_systems.clear();
|
|
|
|
|
2012-11-09 08:46:53 +00:00
|
|
|
if(device) {
|
|
|
|
camera->device_free(device, &dscene);
|
2013-04-01 20:26:43 +00:00
|
|
|
film->device_free(device, &dscene, this);
|
2012-11-09 08:46:53 +00:00
|
|
|
background->device_free(device, &dscene);
|
|
|
|
integrator->device_free(device, &dscene);
|
|
|
|
|
|
|
|
object_manager->device_free(device, &dscene);
|
|
|
|
mesh_manager->device_free(device, &dscene);
|
2013-04-01 20:26:52 +00:00
|
|
|
shader_manager->device_free(device, &dscene, this);
|
2012-11-09 08:46:53 +00:00
|
|
|
light_manager->device_free(device, &dscene);
|
|
|
|
|
|
|
|
particle_system_manager->device_free(device, &dscene);
|
2012-12-28 14:21:30 +00:00
|
|
|
curve_system_manager->device_free(device, &dscene);
|
2012-11-09 08:46:53 +00:00
|
|
|
|
2014-01-02 21:05:07 +00:00
|
|
|
bake_manager->device_free(device, &dscene);
|
|
|
|
|
2013-02-14 16:48:43 +00:00
|
|
|
if(!params.persistent_data || final)
|
2012-11-09 08:46:53 +00:00
|
|
|
image_manager->device_free(device, &dscene);
|
2013-04-01 20:26:43 +00:00
|
|
|
|
|
|
|
lookup_tables->device_free(device, &dscene);
|
2012-11-09 08:46:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(final) {
|
2013-04-01 20:26:43 +00:00
|
|
|
delete lookup_tables;
|
2012-11-09 08:46:53 +00:00
|
|
|
delete camera;
|
|
|
|
delete film;
|
|
|
|
delete background;
|
|
|
|
delete integrator;
|
|
|
|
delete object_manager;
|
|
|
|
delete mesh_manager;
|
|
|
|
delete shader_manager;
|
|
|
|
delete light_manager;
|
|
|
|
delete particle_system_manager;
|
2012-12-28 14:21:30 +00:00
|
|
|
delete curve_system_manager;
|
2012-11-09 08:46:53 +00:00
|
|
|
delete image_manager;
|
2014-01-02 21:05:07 +00:00
|
|
|
delete bake_manager;
|
2012-11-09 08:46:53 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::device_update(Device *device_, Progress& progress)
|
|
|
|
{
|
|
|
|
if(!device)
|
|
|
|
device = device_;
|
|
|
|
|
|
|
|
/* The order of updates is important, because there's dependencies between
|
|
|
|
* the different managers, using data computed by previous managers.
|
|
|
|
*
|
|
|
|
* - Image manager uploads images used by shaders.
|
|
|
|
* - Camera may be used for adapative subdivison.
|
|
|
|
* - Displacement shader must have all shader data available.
|
2014-02-06 20:09:46 +00:00
|
|
|
* - Light manager needs lookup tables and final mesh data to compute emission CDF.
|
2014-03-12 17:20:42 +00:00
|
|
|
* - Film needs light manager to run for use_light_visibility
|
|
|
|
* - Lookup tables are done a second time to handle film tables
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
2012-05-13 12:32:44 +00:00
|
|
|
|
|
|
|
image_manager->set_pack_images(device->info.pack_images);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
progress.set_status("Updating Shaders");
|
|
|
|
shader_manager->device_update(device, &dscene, this, progress);
|
|
|
|
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
|
|
|
progress.set_status("Updating Images");
|
|
|
|
image_manager->device_update(device, &dscene, progress);
|
|
|
|
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
2013-12-28 15:56:19 +00:00
|
|
|
progress.set_status("Updating Background");
|
|
|
|
background->device_update(device, &dscene, this);
|
|
|
|
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
progress.set_status("Updating Camera");
|
2012-04-30 12:49:26 +00:00
|
|
|
camera->device_update(device, &dscene, this);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
|
|
|
progress.set_status("Updating Objects");
|
|
|
|
object_manager->device_update(device, &dscene, this, progress);
|
|
|
|
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
2012-12-28 14:21:30 +00:00
|
|
|
progress.set_status("Updating Hair Systems");
|
|
|
|
curve_system_manager->device_update(device, &dscene, this, progress);
|
|
|
|
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
2014-02-06 20:09:46 +00:00
|
|
|
progress.set_status("Updating Lookup Tables");
|
|
|
|
lookup_tables->device_update(device, &dscene);
|
|
|
|
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
progress.set_status("Updating Meshes");
|
|
|
|
mesh_manager->device_update(device, &dscene, this, progress);
|
|
|
|
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
|
|
|
progress.set_status("Updating Lights");
|
|
|
|
light_manager->device_update(device, &dscene, this, progress);
|
|
|
|
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
2012-08-31 17:27:08 +00:00
|
|
|
progress.set_status("Updating Particle Systems");
|
|
|
|
particle_system_manager->device_update(device, &dscene, this, progress);
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
2014-03-12 17:20:42 +00:00
|
|
|
progress.set_status("Updating Film");
|
|
|
|
film->device_update(device, &dscene, this);
|
|
|
|
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
2012-02-28 19:43:33 +00:00
|
|
|
progress.set_status("Updating Integrator");
|
2012-06-13 11:44:48 +00:00
|
|
|
integrator->device_update(device, &dscene, this);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
2014-03-12 17:20:42 +00:00
|
|
|
progress.set_status("Updating Lookup Tables");
|
|
|
|
lookup_tables->device_update(device, &dscene);
|
|
|
|
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
2014-01-02 21:05:07 +00:00
|
|
|
progress.set_status("Updating Baking");
|
|
|
|
bake_manager->device_update(device, &dscene, this, progress);
|
|
|
|
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
progress.set_status("Updating Device", "Writing constant memory");
|
|
|
|
device->const_copy_to("__data", &dscene.data, sizeof(dscene.data));
|
|
|
|
}
|
|
|
|
|
2012-10-15 21:12:58 +00:00
|
|
|
Scene::MotionType Scene::need_motion(bool advanced_shading)
|
2012-04-30 12:49:26 +00:00
|
|
|
{
|
|
|
|
if(integrator->motion_blur)
|
2012-10-15 21:12:58 +00:00
|
|
|
return (advanced_shading)? MOTION_BLUR: MOTION_NONE;
|
2012-04-30 12:49:26 +00:00
|
|
|
else if(Pass::contains(film->passes, PASS_MOTION))
|
|
|
|
return MOTION_PASS;
|
|
|
|
else
|
|
|
|
return MOTION_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Scene::need_global_attribute(AttributeStandard std)
|
|
|
|
{
|
|
|
|
if(std == ATTR_STD_UV)
|
|
|
|
return Pass::contains(film->passes, PASS_UV);
|
2014-05-12 08:20:20 +00:00
|
|
|
else if(std == ATTR_STD_MOTION_VERTEX_POSITION)
|
2014-03-29 12:03:46 +00:00
|
|
|
return need_motion() != MOTION_NONE;
|
2014-05-12 08:20:20 +00:00
|
|
|
else if(std == ATTR_STD_MOTION_VERTEX_NORMAL)
|
2014-03-29 12:03:46 +00:00
|
|
|
return need_motion() == MOTION_BLUR;
|
2012-04-30 12:49:26 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::need_global_attributes(AttributeRequestSet& attributes)
|
|
|
|
{
|
|
|
|
for(int std = ATTR_STD_NONE; std < ATTR_STD_NUM; std++)
|
|
|
|
if(need_global_attribute((AttributeStandard)std))
|
|
|
|
attributes.add((AttributeStandard)std);
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
bool Scene::need_update()
|
|
|
|
{
|
|
|
|
return (need_reset() || film->need_update);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Scene::need_reset()
|
|
|
|
{
|
|
|
|
return (background->need_update
|
|
|
|
|| image_manager->need_update
|
|
|
|
|| camera->need_update
|
|
|
|
|| object_manager->need_update
|
|
|
|
|| mesh_manager->need_update
|
|
|
|
|| light_manager->need_update
|
2013-04-01 20:26:43 +00:00
|
|
|
|| lookup_tables->need_update
|
2011-04-27 11:58:34 +00:00
|
|
|
|| integrator->need_update
|
2012-08-31 17:27:08 +00:00
|
|
|
|| shader_manager->need_update
|
2012-12-28 14:21:30 +00:00
|
|
|
|| particle_system_manager->need_update
|
2014-01-02 21:05:07 +00:00
|
|
|
|| curve_system_manager->need_update
|
|
|
|
|| bake_manager->need_update);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2012-11-09 08:46:53 +00:00
|
|
|
void Scene::reset()
|
|
|
|
{
|
2013-02-14 16:11:47 +00:00
|
|
|
shader_manager->reset(this);
|
2012-11-09 08:46:53 +00:00
|
|
|
shader_manager->add_default(this);
|
|
|
|
|
|
|
|
/* ensure all objects are updated */
|
|
|
|
camera->tag_update();
|
|
|
|
film->tag_update(this);
|
|
|
|
background->tag_update(this);
|
|
|
|
integrator->tag_update(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Scene::device_free()
|
|
|
|
{
|
|
|
|
free_memory(false);
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|