diff options
Diffstat (limited to 'intern/cycles/render/object.cpp')
-rw-r--r-- | intern/cycles/render/object.cpp | 97 |
1 files changed, 86 insertions, 11 deletions
diff --git a/intern/cycles/render/object.cpp b/intern/cycles/render/object.cpp index 1f148d34ea6..ec85aa8f80b 100644 --- a/intern/cycles/render/object.cpp +++ b/intern/cycles/render/object.cpp @@ -11,9 +11,10 @@ * 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 + * limitations under the License. */ +#include "camera.h" #include "device.h" #include "light.h" #include "mesh.h" @@ -23,6 +24,7 @@ #include "scene.h" #include "util_foreach.h" +#include "util_logging.h" #include "util_map.h" #include "util_progress.h" #include "util_vector.h" @@ -75,8 +77,14 @@ void Object::compute_bounds(bool motion_blur) bounds.grow(mbounds.transformed(&ttfm)); } } - else - bounds = mbounds.transformed(&tfm); + else { + if(mesh->transform_applied) { + bounds = mbounds; + } + else { + bounds = mbounds.transformed(&tfm); + } + } } void Object::apply_transform(bool apply_to_motion) @@ -98,11 +106,11 @@ void Object::apply_transform(bool apply_to_motion) if(apply_to_motion) { Attribute *attr = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); - if (attr) { + if(attr) { size_t steps_size = mesh->verts.size() * (mesh->motion_steps - 1); float3 *vert_steps = attr->data_float3(); - for (size_t i = 0; i < steps_size; i++) + for(size_t i = 0; i < steps_size; i++) vert_steps[i] = transform_point(&tfm, vert_steps[i]); } @@ -113,7 +121,7 @@ void Object::apply_transform(bool apply_to_motion) size_t steps_size = mesh->verts.size() * (mesh->motion_steps - 1); float3 *normal_steps = attr_N->data_float3(); - for (size_t i = 0; i < steps_size; i++) + for(size_t i = 0; i < steps_size; i++) normal_steps[i] = normalize(transform_direction(&ntfm, normal_steps[i])); } } @@ -140,12 +148,12 @@ void Object::apply_transform(bool apply_to_motion) if(apply_to_motion) { Attribute *curve_attr = mesh->curve_attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); - if (curve_attr) { + 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(); - for (size_t i = 0; i < steps_size; i++) { + 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; @@ -185,6 +193,7 @@ void Object::tag_update(Scene *scene) } } + scene->camera->need_flags_update = true; scene->curve_system_manager->need_update = true; scene->mesh_manager->need_update = true; scene->object_manager->need_update = true; @@ -215,6 +224,7 @@ vector<float> Object::motion_times() ObjectManager::ObjectManager() { need_update = true; + need_flags_update = true; } ObjectManager::~ObjectManager() @@ -312,6 +322,9 @@ void ObjectManager::device_update_transforms(Device *device, DeviceScene *dscene mtfm_pre = mtfm_pre * itfm; mtfm_post = mtfm_post * itfm; } + else { + flag |= SD_OBJECT_HAS_VERTEX_MOTION; + } 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); @@ -367,13 +380,13 @@ void ObjectManager::device_update_transforms(Device *device, DeviceScene *dscene void ObjectManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress) { + VLOG(1) << "Total " << scene->objects.size() << " objects."; + if(!need_update) return; device_free(device, dscene); - need_update = false; - if(scene->objects.size() == 0) return; @@ -392,6 +405,65 @@ void ObjectManager::device_update(Device *device, DeviceScene *dscene, Scene *sc progress.set_status("Updating Objects", "Applying Static Transformations"); apply_static_transforms(dscene, scene, object_flag, progress); } +} + +void ObjectManager::device_update_flags(Device *device, + DeviceScene *dscene, + Scene *scene, + Progress& /*progress*/, + bool bounds_valid) +{ + if(!need_update && !need_flags_update) + return; + + need_update = false; + need_flags_update = false; + + if(scene->objects.size() == 0) + return; + + /* object info flag */ + uint *object_flag = dscene->object_flag.get_data(); + + vector<Object *> volume_objects; + bool has_volume_objects = false; + foreach(Object *object, scene->objects) { + if(object->mesh->has_volume) { + if(bounds_valid) { + volume_objects.push_back(object); + } + has_volume_objects = true; + } + } + + int object_index = 0; + foreach(Object *object, scene->objects) { + if(object->mesh->has_volume) { + object_flag[object_index] |= SD_OBJECT_HAS_VOLUME; + } + else { + object_flag[object_index] &= ~SD_OBJECT_HAS_VOLUME; + } + + if(bounds_valid) { + 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; + } + } + } + else if(has_volume_objects) { + /* Not really valid, but can't make more reliable in the case + * of bounds not being up to date. + */ + object_flag[object_index] |= SD_OBJECT_INTERSECTS_VOLUME; + } + ++object_index; + } /* allocate object flag */ device->tex_alloc("__object_flag", dscene->object_flag); @@ -422,6 +494,7 @@ void ObjectManager::apply_static_transforms(DeviceScene *dscene, Scene *scene, u bool apply_to_motion = need_motion != Scene::MOTION_PASS; #else bool motion_blur = false; + bool apply_to_motion = false; #endif int i = 0; bool have_instancing = false; @@ -439,7 +512,9 @@ void ObjectManager::apply_static_transforms(DeviceScene *dscene, Scene *scene, u /* apply transforms for objects with single user meshes */ foreach(Object *object, scene->objects) { - if(mesh_users[object->mesh] == 1) { + if(mesh_users[object->mesh] == 1 && + object->mesh->displacement_method == Mesh::DISPLACE_BUMP) + { if(!(motion_blur && object->use_motion)) { if(!object->mesh->transform_applied) { object->apply_transform(apply_to_motion); |