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
|
2014-12-25 01:50:24 +00:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "device.h"
|
2011-09-12 13:13:56 +00:00
|
|
|
#include "light.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "mesh.h"
|
2012-12-28 14:21:30 +00:00
|
|
|
#include "curves.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "object.h"
|
2014-02-25 17:29:11 +00:00
|
|
|
#include "particles.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "scene.h"
|
|
|
|
|
|
|
|
#include "util_foreach.h"
|
2011-09-02 16:15:18 +00:00
|
|
|
#include "util_map.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "util_progress.h"
|
2012-06-08 16:17:57 +00:00
|
|
|
#include "util_vector.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
/* Object */
|
|
|
|
|
|
|
|
Object::Object()
|
|
|
|
{
|
|
|
|
name = "";
|
|
|
|
mesh = NULL;
|
|
|
|
tfm = transform_identity();
|
2011-09-01 15:53:36 +00:00
|
|
|
visibility = ~0;
|
2012-05-29 10:34:16 +00:00
|
|
|
random_id = 0;
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
pass_id = 0;
|
2014-02-25 17:29:11 +00:00
|
|
|
particle_system = NULL;
|
|
|
|
particle_index = 0;
|
Cycles: merging features from tomato branch.
=== BVH build time optimizations ===
* BVH building was multithreaded. Not all building is multithreaded, packing
and the initial bounding/splitting is still single threaded, but recursive
splitting is, which was the main bottleneck.
* Object splitting now uses binning rather than sorting of all elements, using
code from the Embree raytracer from Intel.
http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/
* Other small changes to avoid allocations, pack memory more tightly, avoid
some unnecessary operations, ...
These optimizations do not work yet when Spatial Splits are enabled, for that
more work is needed. There's also other optimizations still needed, in
particular for the case of many low poly objects, the packing step and node
memory allocation.
BVH raytracing time should remain about the same, but BVH build time should be
significantly reduced, test here show speedup of about 5x to 10x on a dual core
and 5x to 25x on an 8-core machine, depending on the scene.
=== Threads ===
Centralized task scheduler for multithreading, which is basically the
CPU device threading code wrapped into something reusable.
Basic idea is that there is a single TaskScheduler that keeps a pool of threads,
one for each core. Other places in the code can then create a TaskPool that they
can drop Tasks in to be executed by the scheduler, and wait for them to complete
or cancel them early.
=== Normal ====
Added a Normal output to the texture coordinate node. This currently
gives the object space normal, which is the same under object animation.
In the future this might become a "generated" normal so it's also stable for
deforming objects, but for now it's already useful for non-deforming objects.
=== Render Layers ===
Per render layer Samples control, leaving it to 0 will use the common scene
setting.
Environment pass will now render environment even if film is set to transparent.
Exclude Layers" added. Scene layers (all object that influence the render,
directly or indirectly) are shared between all render layers. However sometimes
it's useful to leave out some object influence for a particular render layer.
That's what this option allows you to do.
=== Filter Glossy ===
When using a value higher than 0.0, this will blur glossy reflections after
blurry bounces, to reduce noise at the cost of accuracy. 1.0 is a good
starting value to tweak.
Some light paths have a low probability of being found while contributing much
light to the pixel. As a result these light paths will be found in some pixels
and not in others, causing fireflies. An example of such a difficult path might
be a small light that is causing a small specular highlight on a sharp glossy
material, which we are seeing through a rough glossy material. With path tracing
it is difficult to find the specular highlight, but if we increase the roughness
on the material the highlight gets bigger and softer, and so easier to find.
Often this blurring will be hardly noticeable, because we are seeing it through
a blurry material anyway, but there are also cases where this will lead to a
loss of detail in lighting.
2012-04-28 08:53:59 +00:00
|
|
|
bounds = BoundBox::empty;
|
2012-04-30 12:49:26 +00:00
|
|
|
motion.pre = transform_identity();
|
2013-09-03 22:39:21 +00:00
|
|
|
motion.mid = transform_identity();
|
2012-04-30 12:49:26 +00:00
|
|
|
motion.post = transform_identity();
|
|
|
|
use_motion = false;
|
2012-05-02 09:33:45 +00:00
|
|
|
use_holdout = false;
|
2013-09-03 22:39:21 +00:00
|
|
|
dupli_generated = make_float3(0.0f, 0.0f, 0.0f);
|
|
|
|
dupli_uv = make_float2(0.0f, 0.0f);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Object::~Object()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-03-29 12:03:46 +00:00
|
|
|
void Object::compute_bounds(bool motion_blur)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-04-30 12:49:26 +00:00
|
|
|
BoundBox mbounds = mesh->bounds;
|
|
|
|
|
|
|
|
if(motion_blur && use_motion) {
|
2012-11-29 00:43:50 +00:00
|
|
|
DecompMotionTransform decomp;
|
2012-10-17 12:55:23 +00:00
|
|
|
transform_motion_decompose(&decomp, &motion, &tfm);
|
2012-04-30 12:49:26 +00:00
|
|
|
|
|
|
|
bounds = BoundBox::empty;
|
|
|
|
|
|
|
|
/* todo: this is really terrible. according to pbrt there is a better
|
|
|
|
* way to find this iteratively, but did not find implementation yet
|
|
|
|
* or try to implement myself */
|
2014-03-29 12:03:46 +00:00
|
|
|
for(float t = 0.0f; t < 1.0f; t += (1.0f/128.0f)) {
|
2012-04-30 12:49:26 +00:00
|
|
|
Transform ttfm;
|
|
|
|
|
|
|
|
transform_motion_interpolate(&ttfm, &decomp, t);
|
|
|
|
bounds.grow(mbounds.transformed(&ttfm));
|
|
|
|
}
|
|
|
|
}
|
2014-10-03 08:52:04 +00:00
|
|
|
else {
|
|
|
|
if(mesh->transform_applied) {
|
|
|
|
bounds = mbounds;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bounds = mbounds.transformed(&tfm);
|
|
|
|
}
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2014-05-09 15:02:08 +00:00
|
|
|
void Object::apply_transform(bool apply_to_motion)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
if(!mesh || tfm == transform_identity())
|
|
|
|
return;
|
2014-03-29 12:03:46 +00:00
|
|
|
|
2014-03-29 12:03:47 +00:00
|
|
|
/* triangles */
|
|
|
|
if(mesh->verts.size()) {
|
|
|
|
/* store matrix to transform later. when accessing these as attributes we
|
|
|
|
* do not want the transform to be applied for consistency between static
|
|
|
|
* and dynamic BVH, so we do it on packing. */
|
|
|
|
mesh->transform_normal = transform_transpose(transform_inverse(tfm));
|
|
|
|
|
|
|
|
/* apply to mesh vertices */
|
|
|
|
for(size_t i = 0; i < mesh->verts.size(); i++)
|
|
|
|
mesh->verts[i] = transform_point(&tfm, mesh->verts[i]);
|
2014-05-09 15:02:08 +00:00
|
|
|
|
|
|
|
if(apply_to_motion) {
|
|
|
|
Attribute *attr = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
|
2014-03-29 12:03:47 +00:00
|
|
|
|
2014-05-09 15:02:08 +00:00
|
|
|
if (attr) {
|
|
|
|
size_t steps_size = mesh->verts.size() * (mesh->motion_steps - 1);
|
|
|
|
float3 *vert_steps = attr->data_float3();
|
2014-03-29 12:03:47 +00:00
|
|
|
|
2014-05-09 15:02:08 +00:00
|
|
|
for (size_t i = 0; i < steps_size; i++)
|
|
|
|
vert_steps[i] = transform_point(&tfm, vert_steps[i]);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-05-09 15:02:08 +00:00
|
|
|
Attribute *attr_N = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_NORMAL);
|
2014-03-29 12:03:46 +00:00
|
|
|
|
2014-05-09 15:02:08 +00:00
|
|
|
if(attr_N) {
|
|
|
|
Transform ntfm = mesh->transform_normal;
|
|
|
|
size_t steps_size = mesh->verts.size() * (mesh->motion_steps - 1);
|
|
|
|
float3 *normal_steps = attr_N->data_float3();
|
2014-03-29 12:03:47 +00:00
|
|
|
|
2014-05-09 15:02:08 +00:00
|
|
|
for (size_t i = 0; i < steps_size; i++)
|
|
|
|
normal_steps[i] = normalize(transform_direction(&ntfm, normal_steps[i]));
|
|
|
|
}
|
2014-03-29 12:03:47 +00:00
|
|
|
}
|
2014-03-29 12:03:46 +00:00
|
|
|
}
|
|
|
|
|
2014-03-29 12:03:47 +00:00
|
|
|
/* curves */
|
|
|
|
if(mesh->curve_keys.size()) {
|
|
|
|
/* compute uniform scale */
|
|
|
|
float3 c0 = transform_get_column(&tfm, 0);
|
|
|
|
float3 c1 = transform_get_column(&tfm, 1);
|
|
|
|
float3 c2 = transform_get_column(&tfm, 2);
|
|
|
|
float scalar = pow(fabsf(dot(cross(c0, c1), c2)), 1.0f/3.0f);
|
|
|
|
|
|
|
|
/* apply transform to curve keys */
|
|
|
|
for(size_t i = 0; i < mesh->curve_keys.size(); i++) {
|
|
|
|
float3 co = transform_point(&tfm, float4_to_float3(mesh->curve_keys[i]));
|
|
|
|
float radius = mesh->curve_keys[i].w * scalar;
|
|
|
|
|
|
|
|
/* scale for curve radius is only correct for uniform scale */
|
|
|
|
mesh->curve_keys[i] = float3_to_float4(co);
|
|
|
|
mesh->curve_keys[i].w = radius;
|
|
|
|
}
|
2014-03-29 12:03:46 +00:00
|
|
|
|
2014-05-09 15:02:08 +00:00
|
|
|
if(apply_to_motion) {
|
|
|
|
Attribute *curve_attr = mesh->curve_attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
|
2012-12-28 14:21:30 +00:00
|
|
|
|
2014-05-09 15:02:08 +00:00
|
|
|
if (curve_attr) {
|
|
|
|
/* apply transform to motion curve keys */
|
|
|
|
size_t steps_size = mesh->curve_keys.size() * (mesh->motion_steps - 1);
|
|
|
|
float4 *key_steps = curve_attr->data_float4();
|
2014-03-29 12:03:46 +00:00
|
|
|
|
2014-05-09 15:02:08 +00:00
|
|
|
for (size_t i = 0; i < steps_size; i++) {
|
|
|
|
float3 co = transform_point(&tfm, float4_to_float3(key_steps[i]));
|
|
|
|
float radius = key_steps[i].w * scalar;
|
2014-03-29 12:03:47 +00:00
|
|
|
|
2014-05-09 15:02:08 +00:00
|
|
|
/* scale for curve radius is only correct for uniform scale */
|
|
|
|
key_steps[i] = float3_to_float4(co);
|
|
|
|
key_steps[i].w = radius;
|
|
|
|
}
|
2014-03-29 12:03:47 +00:00
|
|
|
}
|
|
|
|
}
|
2014-03-29 12:03:46 +00:00
|
|
|
}
|
|
|
|
|
2011-11-12 14:29:52 +00:00
|
|
|
/* we keep normals pointing in same direction on negative scale, notify
|
2012-06-09 17:22:52 +00:00
|
|
|
* mesh about this in it (re)calculates normals */
|
2011-11-12 14:29:52 +00:00
|
|
|
if(transform_negative_scale(tfm))
|
|
|
|
mesh->transform_negative_scaled = true;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if(bounds.valid()) {
|
|
|
|
mesh->compute_bounds();
|
2014-03-29 12:03:46 +00:00
|
|
|
compute_bounds(false);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2012-07-31 15:05:16 +00:00
|
|
|
|
|
|
|
/* tfm is not reset to identity, all code that uses it needs to check the
|
|
|
|
transform_applied boolean */
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Object::tag_update(Scene *scene)
|
|
|
|
{
|
2011-09-12 13:13:56 +00:00
|
|
|
if(mesh) {
|
|
|
|
if(mesh->transform_applied)
|
|
|
|
mesh->need_update = true;
|
|
|
|
|
2011-09-27 20:37:24 +00:00
|
|
|
foreach(uint sindex, mesh->used_shaders) {
|
|
|
|
Shader *shader = scene->shaders[sindex];
|
|
|
|
|
2013-06-18 09:36:00 +00:00
|
|
|
if(shader->use_mis && shader->has_surface_emission)
|
2011-09-12 13:13:56 +00:00
|
|
|
scene->light_manager->need_update = true;
|
2011-09-27 20:37:24 +00:00
|
|
|
}
|
2011-09-12 13:13:56 +00:00
|
|
|
}
|
|
|
|
|
2012-12-28 14:21:30 +00:00
|
|
|
scene->curve_system_manager->need_update = true;
|
2011-04-27 11:58:34 +00:00
|
|
|
scene->mesh_manager->need_update = true;
|
|
|
|
scene->object_manager->need_update = true;
|
|
|
|
}
|
|
|
|
|
2014-03-29 12:03:46 +00:00
|
|
|
vector<float> Object::motion_times()
|
|
|
|
{
|
|
|
|
/* compute times at which we sample motion for this object */
|
|
|
|
vector<float> times;
|
|
|
|
|
2014-05-06 18:18:58 +00:00
|
|
|
if(!mesh || mesh->motion_steps == 1)
|
2014-03-29 12:03:46 +00:00
|
|
|
return times;
|
|
|
|
|
2014-05-06 18:18:58 +00:00
|
|
|
int motion_steps = mesh->motion_steps;
|
|
|
|
|
2014-03-29 12:03:46 +00:00
|
|
|
for(int step = 0; step < motion_steps; step++) {
|
|
|
|
if(step != motion_steps / 2) {
|
|
|
|
float time = 2.0f * step / (motion_steps - 1) - 1.0f;
|
|
|
|
times.push_back(time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return times;
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Object Manager */
|
|
|
|
|
|
|
|
ObjectManager::ObjectManager()
|
|
|
|
{
|
|
|
|
need_update = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectManager::~ObjectManager()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-12-01 19:15:05 +00:00
|
|
|
void ObjectManager::device_update_transforms(Device *device, DeviceScene *dscene, Scene *scene, uint *object_flag, Progress& progress)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-12-20 19:26:57 +00:00
|
|
|
float4 *objects;
|
|
|
|
float4 *objects_vector = NULL;
|
2011-04-27 11:58:34 +00:00
|
|
|
int i = 0;
|
2011-09-02 16:15:18 +00:00
|
|
|
map<Mesh*, float> surface_area_map;
|
2014-02-25 17:29:11 +00:00
|
|
|
map<ParticleSystem*, int> particle_offset;
|
2012-10-15 21:12:58 +00:00
|
|
|
Scene::MotionType need_motion = scene->need_motion(device->info.advanced_shading);
|
|
|
|
bool have_motion = false;
|
2013-04-17 20:07:22 +00:00
|
|
|
bool have_curves = false;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-12-20 19:26:57 +00:00
|
|
|
objects = dscene->objects.resize(OBJECT_SIZE*scene->objects.size());
|
|
|
|
if(need_motion == Scene::MOTION_PASS)
|
|
|
|
objects_vector = dscene->objects_vector.resize(OBJECT_VECTOR_SIZE*scene->objects.size());
|
|
|
|
|
2014-02-25 17:29:11 +00:00
|
|
|
/* particle system device offsets
|
|
|
|
* 0 is dummy particle, index starts at 1
|
|
|
|
*/
|
|
|
|
int numparticles = 1;
|
|
|
|
foreach(ParticleSystem *psys, scene->particle_systems) {
|
|
|
|
particle_offset[psys] = numparticles;
|
|
|
|
numparticles += psys->particles.size();
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
foreach(Object *ob, scene->objects) {
|
|
|
|
Mesh *mesh = ob->mesh;
|
2012-05-02 09:33:45 +00:00
|
|
|
uint flag = 0;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* compute transformations */
|
|
|
|
Transform tfm = ob->tfm;
|
|
|
|
Transform itfm = transform_inverse(tfm);
|
|
|
|
|
2011-09-02 16:15:18 +00:00
|
|
|
/* compute surface area. for uniform scale we can do avoid the many
|
2012-06-09 17:22:52 +00:00
|
|
|
* transform calls and share computation for instances */
|
2011-04-27 11:58:34 +00:00
|
|
|
/* todo: correct for displacement, and move to a better place */
|
2011-09-02 16:15:18 +00:00
|
|
|
float uniform_scale;
|
|
|
|
float surface_area = 0.0f;
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
float pass_id = ob->pass_id;
|
2012-06-03 09:50:17 +00:00
|
|
|
float random_number = (float)ob->random_id * (1.0f/(float)0xFFFFFFFF);
|
2014-02-25 17:29:11 +00:00
|
|
|
int particle_index = (ob->particle_system)? ob->particle_index + particle_offset[ob->particle_system]: 0;
|
2013-04-17 20:07:22 +00:00
|
|
|
|
2011-09-02 16:15:18 +00:00
|
|
|
if(transform_uniform_scale(tfm, uniform_scale)) {
|
|
|
|
map<Mesh*, float>::iterator it = surface_area_map.find(mesh);
|
|
|
|
|
|
|
|
if(it == surface_area_map.end()) {
|
|
|
|
foreach(Mesh::Triangle& t, mesh->triangles) {
|
|
|
|
float3 p1 = mesh->verts[t.v[0]];
|
|
|
|
float3 p2 = mesh->verts[t.v[1]];
|
|
|
|
float3 p3 = mesh->verts[t.v[2]];
|
|
|
|
|
|
|
|
surface_area += triangle_area(p1, p2, p3);
|
|
|
|
}
|
|
|
|
|
|
|
|
surface_area_map[mesh] = surface_area;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
surface_area = it->second;
|
|
|
|
|
|
|
|
surface_area *= uniform_scale;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foreach(Mesh::Triangle& t, mesh->triangles) {
|
2012-04-16 08:35:21 +00:00
|
|
|
float3 p1 = transform_point(&tfm, mesh->verts[t.v[0]]);
|
|
|
|
float3 p2 = transform_point(&tfm, mesh->verts[t.v[1]]);
|
|
|
|
float3 p3 = transform_point(&tfm, mesh->verts[t.v[2]]);
|
2011-09-02 16:15:18 +00:00
|
|
|
|
|
|
|
surface_area += triangle_area(p1, p2, p3);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* pack in texture */
|
|
|
|
int offset = i*OBJECT_SIZE;
|
|
|
|
|
2014-05-04 15:30:02 +00:00
|
|
|
/* OBJECT_TRANSFORM */
|
2012-04-30 12:49:26 +00:00
|
|
|
memcpy(&objects[offset], &tfm, sizeof(float4)*3);
|
2014-05-04 15:30:02 +00:00
|
|
|
/* OBJECT_INVERSE_TRANSFORM */
|
2012-12-20 19:26:57 +00:00
|
|
|
memcpy(&objects[offset+4], &itfm, sizeof(float4)*3);
|
2014-05-04 15:30:02 +00:00
|
|
|
/* OBJECT_PROPERTIES */
|
2014-02-25 17:29:11 +00:00
|
|
|
objects[offset+8] = make_float4(surface_area, pass_id, random_number, __int_as_float(particle_index));
|
2012-04-30 12:49:26 +00:00
|
|
|
|
|
|
|
if(need_motion == Scene::MOTION_PASS) {
|
|
|
|
/* motion transformations, is world/object space depending if mesh
|
2012-06-09 17:22:52 +00:00
|
|
|
* comes with deformed position in object space, or if we transform
|
|
|
|
* the shading point in world space */
|
2012-04-30 12:49:26 +00:00
|
|
|
Transform mtfm_pre = ob->motion.pre;
|
|
|
|
Transform mtfm_post = ob->motion.post;
|
|
|
|
|
2014-03-29 12:03:46 +00:00
|
|
|
if(!mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION)) {
|
2012-04-30 12:49:26 +00:00
|
|
|
mtfm_pre = mtfm_pre * itfm;
|
|
|
|
mtfm_post = mtfm_post * itfm;
|
2014-03-29 12:03:46 +00:00
|
|
|
}
|
2014-11-18 21:42:22 +00:00
|
|
|
else {
|
|
|
|
flag |= SD_OBJECT_HAS_VERTEX_MOTION;
|
|
|
|
}
|
2012-04-30 12:49:26 +00:00
|
|
|
|
2012-12-20 19:26:57 +00:00
|
|
|
memcpy(&objects_vector[i*OBJECT_VECTOR_SIZE+0], &mtfm_pre, sizeof(float4)*3);
|
|
|
|
memcpy(&objects_vector[i*OBJECT_VECTOR_SIZE+3], &mtfm_post, sizeof(float4)*3);
|
2012-04-30 12:49:26 +00:00
|
|
|
}
|
2012-10-09 18:37:14 +00:00
|
|
|
#ifdef __OBJECT_MOTION__
|
2012-04-30 12:49:26 +00:00
|
|
|
else if(need_motion == Scene::MOTION_BLUR) {
|
|
|
|
if(ob->use_motion) {
|
|
|
|
/* decompose transformations for interpolation */
|
2012-11-29 00:43:50 +00:00
|
|
|
DecompMotionTransform decomp;
|
2012-04-30 12:49:26 +00:00
|
|
|
|
2012-10-17 12:55:23 +00:00
|
|
|
transform_motion_decompose(&decomp, &ob->motion, &ob->tfm);
|
2012-12-20 19:26:57 +00:00
|
|
|
memcpy(&objects[offset], &decomp, sizeof(float4)*8);
|
2012-05-02 09:33:45 +00:00
|
|
|
flag |= SD_OBJECT_MOTION;
|
2012-10-15 21:12:58 +00:00
|
|
|
have_motion = true;
|
2012-04-30 12:49:26 +00:00
|
|
|
}
|
|
|
|
}
|
2012-10-09 18:37:14 +00:00
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-04-26 12:25:20 +00:00
|
|
|
if(mesh->use_motion_blur)
|
|
|
|
have_motion = true;
|
|
|
|
|
2014-03-29 12:03:46 +00:00
|
|
|
/* dupli object coords and motion info */
|
|
|
|
int totalsteps = mesh->motion_steps;
|
|
|
|
int numsteps = (totalsteps - 1)/2;
|
|
|
|
int numverts = mesh->verts.size();
|
|
|
|
int numkeys = mesh->curve_keys.size();
|
|
|
|
|
|
|
|
objects[offset+9] = make_float4(ob->dupli_generated[0], ob->dupli_generated[1], ob->dupli_generated[2], __int_as_float(numkeys));
|
|
|
|
objects[offset+10] = make_float4(ob->dupli_uv[0], ob->dupli_uv[1], __int_as_float(numsteps), __int_as_float(numverts));
|
2012-10-04 21:40:39 +00:00
|
|
|
|
2012-05-02 09:33:45 +00:00
|
|
|
/* object flag */
|
|
|
|
if(ob->use_holdout)
|
|
|
|
flag |= SD_HOLDOUT_MASK;
|
|
|
|
object_flag[i] = flag;
|
|
|
|
|
2013-04-17 20:07:22 +00:00
|
|
|
/* have curves */
|
|
|
|
if(mesh->curves.size())
|
|
|
|
have_curves = true;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
i++;
|
|
|
|
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
device->tex_alloc("__objects", dscene->objects);
|
2012-12-20 19:26:57 +00:00
|
|
|
if(need_motion == Scene::MOTION_PASS)
|
|
|
|
device->tex_alloc("__objects_vector", dscene->objects_vector);
|
2012-10-15 21:12:58 +00:00
|
|
|
|
|
|
|
dscene->data.bvh.have_motion = have_motion;
|
2013-04-17 20:07:22 +00:00
|
|
|
dscene->data.bvh.have_curves = have_curves;
|
|
|
|
dscene->data.bvh.have_instancing = true;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
|
|
|
|
{
|
|
|
|
if(!need_update)
|
|
|
|
return;
|
|
|
|
|
|
|
|
device_free(device, dscene);
|
|
|
|
|
|
|
|
if(scene->objects.size() == 0)
|
|
|
|
return;
|
|
|
|
|
2012-12-01 19:15:05 +00:00
|
|
|
/* object info flag */
|
|
|
|
uint *object_flag = dscene->object_flag.resize(scene->objects.size());
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* set object transform matrices, before applying static transforms */
|
|
|
|
progress.set_status("Updating Objects", "Copying Transformations to device");
|
2012-12-01 19:15:05 +00:00
|
|
|
device_update_transforms(device, dscene, scene, object_flag, progress);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
|
|
|
/* prepare for static BVH building */
|
|
|
|
/* todo: do before to support getting object level coords? */
|
2014-05-19 10:49:36 +00:00
|
|
|
if(scene->params.bvh_type == SceneParams::BVH_STATIC) {
|
2011-04-27 11:58:34 +00:00
|
|
|
progress.set_status("Updating Objects", "Applying Static Transformations");
|
2013-04-17 20:07:22 +00:00
|
|
|
apply_static_transforms(dscene, scene, object_flag, progress);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-03 10:11:19 +00:00
|
|
|
void ObjectManager::device_update_flags(Device *device, DeviceScene *dscene,
|
|
|
|
Scene *scene, Progress& progress)
|
|
|
|
{
|
|
|
|
if(!need_update)
|
|
|
|
return;
|
|
|
|
|
|
|
|
need_update = false;
|
|
|
|
|
|
|
|
if(scene->objects.size() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* object info flag */
|
|
|
|
uint *object_flag = dscene->object_flag.get_data();
|
|
|
|
|
|
|
|
vector<Object *> volume_objects;
|
|
|
|
foreach(Object *object, scene->objects) {
|
|
|
|
if(object->mesh->has_volume) {
|
|
|
|
volume_objects.push_back(object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int object_index = 0;
|
|
|
|
foreach(Object *object, scene->objects) {
|
|
|
|
if(object->mesh->has_volume) {
|
|
|
|
object_flag[object_index] |= SD_OBJECT_HAS_VOLUME;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach(Object *volume_object, volume_objects) {
|
|
|
|
if(object == volume_object) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(object->bounds.intersects(volume_object->bounds)) {
|
|
|
|
object_flag[object_index] |= SD_OBJECT_INTERSECTS_VOLUME;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++object_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate object flag */
|
|
|
|
device->tex_alloc("__object_flag", dscene->object_flag);
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void ObjectManager::device_free(Device *device, DeviceScene *dscene)
|
|
|
|
{
|
|
|
|
device->tex_free(dscene->objects);
|
|
|
|
dscene->objects.clear();
|
2012-05-02 09:33:45 +00:00
|
|
|
|
2012-12-20 19:26:57 +00:00
|
|
|
device->tex_free(dscene->objects_vector);
|
|
|
|
dscene->objects_vector.clear();
|
|
|
|
|
2012-05-02 09:33:45 +00:00
|
|
|
device->tex_free(dscene->object_flag);
|
|
|
|
dscene->object_flag.clear();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2013-04-17 20:07:22 +00:00
|
|
|
void ObjectManager::apply_static_transforms(DeviceScene *dscene, Scene *scene, uint *object_flag, Progress& progress)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
/* todo: normals and displacement should be done before applying transform! */
|
|
|
|
/* todo: create objects/meshes in right order! */
|
|
|
|
|
|
|
|
/* counter mesh users */
|
|
|
|
map<Mesh*, int> mesh_users;
|
2012-10-09 18:37:14 +00:00
|
|
|
#ifdef __OBJECT_MOTION__
|
2012-10-15 21:12:58 +00:00
|
|
|
Scene::MotionType need_motion = scene->need_motion();
|
|
|
|
bool motion_blur = need_motion == Scene::MOTION_BLUR;
|
2014-05-09 15:02:08 +00:00
|
|
|
bool apply_to_motion = need_motion != Scene::MOTION_PASS;
|
2012-10-09 18:37:14 +00:00
|
|
|
#else
|
|
|
|
bool motion_blur = false;
|
|
|
|
#endif
|
2012-12-01 19:15:05 +00:00
|
|
|
int i = 0;
|
2013-04-17 20:07:22 +00:00
|
|
|
bool have_instancing = false;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
foreach(Object *object, scene->objects) {
|
|
|
|
map<Mesh*, int>::iterator it = mesh_users.find(object->mesh);
|
|
|
|
|
|
|
|
if(it == mesh_users.end())
|
|
|
|
mesh_users[object->mesh] = 1;
|
|
|
|
else
|
|
|
|
it->second++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
|
|
|
/* apply transforms for objects with single user meshes */
|
|
|
|
foreach(Object *object, scene->objects) {
|
|
|
|
if(mesh_users[object->mesh] == 1) {
|
2012-04-30 12:49:26 +00:00
|
|
|
if(!(motion_blur && object->use_motion)) {
|
|
|
|
if(!object->mesh->transform_applied) {
|
2014-05-09 15:02:08 +00:00
|
|
|
object->apply_transform(apply_to_motion);
|
2012-04-30 12:49:26 +00:00
|
|
|
object->mesh->transform_applied = true;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
}
|
2012-12-01 19:15:05 +00:00
|
|
|
|
|
|
|
object_flag[i] |= SD_TRANSFORM_APPLIED;
|
2014-08-13 10:19:12 +00:00
|
|
|
if(object->mesh->transform_negative_scaled)
|
|
|
|
object_flag[i] |= SD_NEGATIVE_SCALE_APPLIED;
|
2012-04-30 12:49:26 +00:00
|
|
|
}
|
2013-04-17 20:07:22 +00:00
|
|
|
else
|
|
|
|
have_instancing = true;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2013-04-17 20:07:22 +00:00
|
|
|
else
|
|
|
|
have_instancing = true;
|
2012-12-01 19:15:05 +00:00
|
|
|
|
|
|
|
i++;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2013-04-17 20:07:22 +00:00
|
|
|
|
|
|
|
dscene->data.bvh.have_instancing = have_instancing;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectManager::tag_update(Scene *scene)
|
|
|
|
{
|
|
|
|
need_update = true;
|
2012-12-28 14:21:30 +00:00
|
|
|
scene->curve_system_manager->need_update = true;
|
2011-04-27 11:58:34 +00:00
|
|
|
scene->mesh_manager->need_update = true;
|
2011-09-16 12:59:22 +00:00
|
|
|
scene->light_manager->need_update = true;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|