40 const size_t object_index,
46 const array<int> &mesh_shaders = mesh->get_shader();
47 const array<Node *> &mesh_used_shaders = mesh->get_used_shaders();
50 const int num_verts = mesh_verts.
size();
53 int num_triangles = mesh->num_triangles();
54 for (
int i = 0; i < num_triangles; i++) {
56 int shader_index = mesh_shaders[i];
57 Shader *shader = (shader_index < mesh_used_shaders.
size()) ?
58 static_cast<Shader *
>(mesh_used_shaders[shader_index]) :
59 scene->default_surface;
61 if (!shader->has_displacement || shader->get_displacement_method() ==
DISPLACE_BUMP) {
65 for (
int j = 0; j < 3; j++) {
73 int object = object_index;
74 int prim = mesh->prim_offset + i;
98 d_input_data[d_input_size++] = in;
110 const array<int> &mesh_shaders = mesh->get_shader();
111 const array<Node *> &mesh_used_shaders = mesh->get_used_shaders();
114 const int num_verts = mesh_verts.
size();
115 const int num_motion_steps = mesh->get_motion_steps();
118 const float *d_output_data = d_output.
data();
119 int d_output_index = 0;
122 int num_triangles = mesh->num_triangles();
123 for (
int i = 0; i < num_triangles; i++) {
125 int shader_index = mesh_shaders[i];
126 Shader *shader = (shader_index < mesh_used_shaders.
size()) ?
127 static_cast<Shader *
>(mesh_used_shaders[shader_index]) :
128 scene->default_surface;
130 if (!shader->has_displacement || shader->get_displacement_method() ==
DISPLACE_BUMP) {
134 for (
int j = 0; j < 3; j++) {
138 d_output_data[d_output_index + 1],
139 d_output_data[d_output_index + 2]);
144 mesh_verts[t.
v[j]] += off;
145 if (attr_mP !=
NULL) {
146 for (
int step = 0; step < num_motion_steps - 1; step++) {
159 if (!mesh->has_true_displacement()) {
163 const size_t num_verts = mesh->verts.size();
164 const size_t num_triangles = mesh->num_triangles();
166 if (num_triangles == 0) {
170 string msg =
string_printf(
"Computing Displacement %s", mesh->name.c_str());
176 for (
size_t i = 0; i < scene->objects.size(); i++) {
177 if (scene->objects[i]->get_geometry() == mesh) {
195 unordered_set<int> stitch_keys;
196 for (pair<int, int> i : mesh->vert_to_stitching_key_map) {
197 stitch_keys.insert(i.second);
200 typedef unordered_multimap<int, int>::iterator map_it_t;
202 for (
int key : stitch_keys) {
203 pair<map_it_t, map_it_t>
verts = mesh->vert_stitching_map.equal_range(key);
209 int vert =
v->second;
211 pos += mesh->verts[vert];
222 mesh->verts[
v->second] =
pos;
231 mesh->add_face_normals();
233 bool need_recompute_vertex_normals =
false;
235 foreach (
Node *node, mesh->get_used_shaders()) {
237 if (shader->has_displacement && shader->get_displacement_method() ==
DISPLACE_TRUE) {
238 need_recompute_vertex_normals =
true;
243 if (need_recompute_vertex_normals) {
244 bool flip = mesh->transform_negative_scaled;
247 for (
size_t i = 0; i < num_triangles; i++) {
248 int shader_index = mesh->shader[i];
249 Shader *shader = (shader_index < mesh->used_shaders.size()) ?
250 static_cast<Shader *
>(mesh->used_shaders[shader_index]) :
251 scene->default_surface;
253 tri_has_true_disp[i] = shader->has_displacement &&
269 for (
size_t i = 0; i < num_triangles; i++) {
270 if (tri_has_true_disp[i]) {
271 for (
size_t j = 0; j < 3; j++) {
278 for (
size_t i = 0; i < num_triangles; i++) {
279 if (tri_has_true_disp[i]) {
280 for (
size_t j = 0; j < 3; j++) {
281 int vert = mesh->get_triangle(i).v[j];
285 if (stitch_keys.size()) {
286 map_it_t key = mesh->vert_to_stitching_key_map.find(vert);
288 if (key != mesh->vert_to_stitching_key_map.end()) {
289 pair<map_it_t, map_it_t>
verts = mesh->vert_stitching_map.equal_range(key->second);
292 if (
v->second == vert) {
296 vN[
v->second] += fN[i];
307 for (
size_t i = 0; i < num_triangles; i++) {
308 if (tri_has_true_disp[i]) {
309 for (
size_t j = 0; j < 3; j++) {
310 int vert = mesh->get_triangle(i).v[j];
318 vN[vert] = -vN[vert];
330 if (mesh->has_motion_blur() && attr_mP && attr_mN) {
331 for (
int step = 0; step < mesh->motion_steps - 1; step++) {
338 for (
size_t i = 0; i < num_triangles; i++) {
339 if (tri_has_true_disp[i]) {
340 for (
size_t j = 0; j < 3; j++) {
347 for (
size_t i = 0; i < num_triangles; i++) {
348 if (tri_has_true_disp[i]) {
349 for (
size_t j = 0; j < 3; j++) {
350 int vert = mesh->get_triangle(i).v[j];
355 if (stitch_keys.size()) {
356 map_it_t key = mesh->vert_to_stitching_key_map.find(vert);
358 if (key != mesh->vert_to_stitching_key_map.end()) {
359 pair<map_it_t, map_it_t>
verts = mesh->vert_stitching_map.equal_range(
363 if (
v->second == vert) {
378 for (
size_t i = 0; i < num_triangles; i++) {
379 if (tri_has_true_disp[i]) {
380 for (
size_t j = 0; j < 3; j++) {
381 int vert = mesh->get_triangle(i).v[j];
389 mN[vert] = -mN[vert];