diff options
author | Mai Lavelle <mai.lavelle@gmail.com> | 2016-08-13 19:27:17 +0300 |
---|---|---|
committer | Mai Lavelle <mai.lavelle@gmail.com> | 2016-09-02 05:45:29 +0300 |
commit | 62aecbdac19aca49270a11cd0d835f22d31cad72 (patch) | |
tree | b69a4eb1f3f7677ff03d441f24912a303dc2daca /intern/cycles/render/mesh.cpp | |
parent | 9f1c42392e4ae8dfaa91ef8cc32119199ca7d723 (diff) |
Cycles: Store undisplaced coordinates for meshes when needed
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D2156
Diffstat (limited to 'intern/cycles/render/mesh.cpp')
-rw-r--r-- | intern/cycles/render/mesh.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp index f99454ee1bb..5445fd3c29c 100644 --- a/intern/cycles/render/mesh.cpp +++ b/intern/cycles/render/mesh.cpp @@ -584,6 +584,28 @@ void Mesh::add_vertex_normals() } } +void Mesh::add_undisplaced() +{ + AttributeSet& attrs = (subdivision_type == SUBDIVISION_NONE) ? attributes : subd_attributes; + + /* don't compute if already there */ + if(attrs.find(ATTR_STD_POSITION_UNDISPLACED)) { + return; + } + + /* get attribute */ + Attribute *attr = attrs.add(ATTR_STD_POSITION_UNDISPLACED); + attr->flags |= ATTR_SUBDIVIDED; + + float3 *data = attr->data_float3(); + + /* copy verts */ + size_t size = attr->buffer_size(this, (subdivision_type == SUBDIVISION_NONE) ? ATTR_PRIM_TRIANGLE : ATTR_PRIM_SUBD); + if(size) { + memcpy(data, verts.data(), size); + } +} + void Mesh::pack_normals(Scene *scene, uint *tri_shader, float4 *vnormal) { Attribute *attr_vN = attributes.find(ATTR_STD_VERTEX_NORMAL); @@ -1682,6 +1704,10 @@ void MeshManager::device_update(Device *device, DeviceScene *dscene, Scene *scen mesh->add_face_normals(); mesh->add_vertex_normals(); + if(mesh->need_attribute(scene, ATTR_STD_POSITION_UNDISPLACED)) { + mesh->add_undisplaced(); + } + if(progress.get_cancel()) return; } } |