Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/mesh_displace.cpp
| Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | bool GeometryManager::displace( | ||||
| } | } | ||||
| string msg = string_printf("Computing Displacement %s", mesh->name.c_str()); | string msg = string_printf("Computing Displacement %s", mesh->name.c_str()); | ||||
| progress.set_status("Updating Mesh", msg); | progress.set_status("Updating Mesh", msg); | ||||
| /* find object index. todo: is arbitrary */ | /* find object index. todo: is arbitrary */ | ||||
| size_t object_index = OBJECT_NONE; | size_t object_index = OBJECT_NONE; | ||||
| for (size_t i = 0; i < scene->objects.size(); i++) { | for (size_t i = 0; i < scene->get_objects().size(); i++) { | ||||
| if (scene->objects[i]->get_geometry() == mesh) { | if (scene->get_objects()[i]->get_geometry() == mesh) { | ||||
| object_index = i; | object_index = i; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| /* setup input for device task */ | /* setup input for device task */ | ||||
| const size_t num_verts = mesh->verts.size(); | const size_t num_verts = mesh->verts.size(); | ||||
| vector<bool> done(num_verts, false); | vector<bool> done(num_verts, false); | ||||
| device_vector<uint4> d_input(device, "displace_input", MEM_READ_ONLY); | device_vector<uint4> d_input(device, "displace_input", MEM_READ_ONLY); | ||||
| uint4 *d_input_data = d_input.alloc(num_verts); | uint4 *d_input_data = d_input.alloc(num_verts); | ||||
| size_t d_input_size = 0; | size_t d_input_size = 0; | ||||
| size_t num_triangles = mesh->num_triangles(); | size_t num_triangles = mesh->num_triangles(); | ||||
| for (size_t i = 0; i < num_triangles; i++) { | for (size_t i = 0; i < num_triangles; i++) { | ||||
| Mesh::Triangle t = mesh->get_triangle(i); | Mesh::Triangle t = mesh->get_triangle(i); | ||||
| int shader_index = mesh->shader[i]; | int shader_index = mesh->shader[i]; | ||||
| Shader *shader = (shader_index < mesh->used_shaders.size()) ? | Shader *shader = (shader_index < mesh->used_shaders.size()) ? | ||||
| static_cast<Shader *>(mesh->used_shaders[shader_index]) : | static_cast<Shader *>(mesh->used_shaders[shader_index]) : | ||||
| scene->default_surface; | scene->get_default_surface(); | ||||
| if (!shader->has_displacement || shader->get_displacement_method() == DISPLACE_BUMP) { | if (!shader->get_has_displacement() || shader->get_displacement_method() == DISPLACE_BUMP) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| for (int j = 0; j < 3; j++) { | for (int j = 0; j < 3; j++) { | ||||
| if (done[t.v[j]]) | if (done[t.v[j]]) | ||||
| continue; | continue; | ||||
| done[t.v[j]] = true; | done[t.v[j]] = true; | ||||
| ▲ Show 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | bool GeometryManager::displace( | ||||
| float4 *offset = d_output.data(); | float4 *offset = d_output.data(); | ||||
| Attribute *attr_mP = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); | Attribute *attr_mP = mesh->attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); | ||||
| for (size_t i = 0; i < num_triangles; i++) { | for (size_t i = 0; i < num_triangles; i++) { | ||||
| Mesh::Triangle t = mesh->get_triangle(i); | Mesh::Triangle t = mesh->get_triangle(i); | ||||
| int shader_index = mesh->shader[i]; | int shader_index = mesh->shader[i]; | ||||
| Shader *shader = (shader_index < mesh->used_shaders.size()) ? | Shader *shader = (shader_index < mesh->used_shaders.size()) ? | ||||
| static_cast<Shader *>(mesh->used_shaders[shader_index]) : | static_cast<Shader *>(mesh->used_shaders[shader_index]) : | ||||
| scene->default_surface; | scene->get_default_surface(); | ||||
| if (!shader->has_displacement || shader->get_displacement_method() == DISPLACE_BUMP) { | if (!shader->get_has_displacement() || shader->get_displacement_method() == DISPLACE_BUMP) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| for (int j = 0; j < 3; j++) { | for (int j = 0; j < 3; j++) { | ||||
| if (!done[t.v[j]]) { | if (!done[t.v[j]]) { | ||||
| done[t.v[j]] = true; | done[t.v[j]] = true; | ||||
| float3 off = float4_to_float3(offset[k++]); | float3 off = float4_to_float3(offset[k++]); | ||||
| /* Avoid illegal vertex coordinates. */ | /* Avoid illegal vertex coordinates. */ | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | bool GeometryManager::displace( | ||||
| * to avoid applying the perturbation twice. */ | * to avoid applying the perturbation twice. */ | ||||
| mesh->attributes.remove(ATTR_STD_FACE_NORMAL); | mesh->attributes.remove(ATTR_STD_FACE_NORMAL); | ||||
| mesh->add_face_normals(); | mesh->add_face_normals(); | ||||
| bool need_recompute_vertex_normals = false; | bool need_recompute_vertex_normals = false; | ||||
| foreach (Node *node, mesh->get_used_shaders()) { | foreach (Node *node, mesh->get_used_shaders()) { | ||||
| Shader *shader = static_cast<Shader *>(node); | Shader *shader = static_cast<Shader *>(node); | ||||
| if (shader->has_displacement && shader->get_displacement_method() == DISPLACE_TRUE) { | if (shader->get_has_displacement() && shader->get_displacement_method() == DISPLACE_TRUE) { | ||||
| need_recompute_vertex_normals = true; | need_recompute_vertex_normals = true; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| if (need_recompute_vertex_normals) { | if (need_recompute_vertex_normals) { | ||||
| bool flip = mesh->transform_negative_scaled; | bool flip = mesh->transform_negative_scaled; | ||||
| vector<bool> tri_has_true_disp(num_triangles, false); | vector<bool> tri_has_true_disp(num_triangles, false); | ||||
| for (size_t i = 0; i < num_triangles; i++) { | for (size_t i = 0; i < num_triangles; i++) { | ||||
| int shader_index = mesh->shader[i]; | int shader_index = mesh->shader[i]; | ||||
| Shader *shader = (shader_index < mesh->used_shaders.size()) ? | Shader *shader = (shader_index < mesh->used_shaders.size()) ? | ||||
| static_cast<Shader *>(mesh->used_shaders[shader_index]) : | static_cast<Shader *>(mesh->used_shaders[shader_index]) : | ||||
| scene->default_surface; | scene->get_default_surface(); | ||||
| tri_has_true_disp[i] = shader->has_displacement && | tri_has_true_disp[i] = shader->get_has_displacement() && | ||||
| shader->get_displacement_method() == DISPLACE_TRUE; | shader->get_displacement_method() == DISPLACE_TRUE; | ||||
| } | } | ||||
| /* static vertex normals */ | /* static vertex normals */ | ||||
| /* get attributes */ | /* get attributes */ | ||||
| Attribute *attr_fN = mesh->attributes.find(ATTR_STD_FACE_NORMAL); | Attribute *attr_fN = mesh->attributes.find(ATTR_STD_FACE_NORMAL); | ||||
| Attribute *attr_vN = mesh->attributes.find(ATTR_STD_VERTEX_NORMAL); | Attribute *attr_vN = mesh->attributes.find(ATTR_STD_VERTEX_NORMAL); | ||||
| ▲ Show 20 Lines • Show All 142 Lines • Show Last 20 Lines | |||||