diff options
Diffstat (limited to 'intern/cycles/render/mesh_displace.cpp')
-rw-r--r-- | intern/cycles/render/mesh_displace.cpp | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/intern/cycles/render/mesh_displace.cpp b/intern/cycles/render/mesh_displace.cpp index adc5b820298..ad2a5713bcb 100644 --- a/intern/cycles/render/mesh_displace.cpp +++ b/intern/cycles/render/mesh_displace.cpp @@ -14,15 +14,15 @@ * limitations under the License. */ -#include "device.h" +#include "device/device.h" -#include "mesh.h" -#include "object.h" -#include "scene.h" -#include "shader.h" +#include "render/mesh.h" +#include "render/object.h" +#include "render/scene.h" +#include "render/shader.h" -#include "util_foreach.h" -#include "util_progress.h" +#include "util/util_foreach.h" +#include "util/util_progress.h" CCL_NAMESPACE_BEGIN @@ -64,8 +64,8 @@ bool MeshManager::displace(Device *device, DeviceScene *dscene, Scene *scene, Me /* setup input for device task */ const size_t num_verts = mesh->verts.size(); vector<bool> done(num_verts, false); - device_vector<uint4> d_input; - uint4 *d_input_data = d_input.resize(num_verts); + device_vector<uint4> d_input(device, "displace_input", MEM_READ_ONLY); + uint4 *d_input_data = d_input.alloc(num_verts); size_t d_input_size = 0; size_t num_triangles = mesh->num_triangles(); @@ -115,16 +115,14 @@ bool MeshManager::displace(Device *device, DeviceScene *dscene, Scene *scene, Me return false; /* run device task */ - device_vector<float4> d_output; - d_output.resize(d_input_size); + device_vector<float4> d_output(device, "displace_output", MEM_READ_WRITE); + d_output.alloc(d_input_size); + d_output.zero_to_device(); + d_input.copy_to_device(); /* needs to be up to data for attribute access */ device->const_copy_to("__data", &dscene->data, sizeof(dscene->data)); - device->mem_alloc(d_input, MEM_READ_ONLY); - device->mem_copy_to(d_input); - device->mem_alloc(d_output, MEM_WRITE_ONLY); - DeviceTask task(DeviceTask::SHADER); task.shader_input = d_input.device_pointer; task.shader_output = d_output.device_pointer; @@ -138,21 +136,20 @@ bool MeshManager::displace(Device *device, DeviceScene *dscene, Scene *scene, Me device->task_wait(); if(progress.get_cancel()) { - device->mem_free(d_input); - device->mem_free(d_output); + d_input.free(); + d_output.free(); return false; } - device->mem_copy_from(d_output, 0, 1, d_output.size(), sizeof(float4)); - device->mem_free(d_input); - device->mem_free(d_output); + d_output.copy_from_device(0, 1, d_output.size()); + d_input.free(); /* read result */ done.clear(); done.resize(num_verts, false); int k = 0; - float4 *offset = (float4*)d_output.data_pointer; + float4 *offset = d_output.data(); Attribute *attr_mP = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); for(size_t i = 0; i < num_triangles; i++) { @@ -169,6 +166,8 @@ bool MeshManager::displace(Device *device, DeviceScene *dscene, Scene *scene, Me if(!done[t.v[j]]) { done[t.v[j]] = true; float3 off = float4_to_float3(offset[k++]); + /* Avoid illegal vertex coordinates. */ + off = ensure_finite3(off); mesh->verts[t.v[j]] += off; if(attr_mP != NULL) { for(int step = 0; step < mesh->motion_steps - 1; step++) { @@ -180,6 +179,8 @@ bool MeshManager::displace(Device *device, DeviceScene *dscene, Scene *scene, Me } } + d_output.free(); + /* for displacement method both, we only need to recompute the face * normals, as bump mapping in the shader will already alter the * vertex normal, so we start from the non-displaced vertex normals |