diff options
Diffstat (limited to 'intern/cycles/render')
-rw-r--r-- | intern/cycles/render/mesh.cpp | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp index 257e83171e9..b02b9b792b7 100644 --- a/intern/cycles/render/mesh.cpp +++ b/intern/cycles/render/mesh.cpp @@ -500,7 +500,7 @@ void Mesh::add_vertex_normals() size_t triangles_size = num_triangles(); /* static vertex normals */ - if(!attributes.find(ATTR_STD_VERTEX_NORMAL)) { + if(!attributes.find(ATTR_STD_VERTEX_NORMAL) && triangles_size) { /* get attributes */ Attribute *attr_fN = attributes.find(ATTR_STD_FACE_NORMAL); Attribute *attr_vN = attributes.add(ATTR_STD_VERTEX_NORMAL); @@ -529,7 +529,7 @@ void Mesh::add_vertex_normals() Attribute *attr_mP = attributes.find(ATTR_STD_MOTION_VERTEX_POSITION); Attribute *attr_mN = attributes.find(ATTR_STD_MOTION_VERTEX_NORMAL); - if(has_motion_blur() && attr_mP && !attr_mN) { + if(has_motion_blur() && attr_mP && !attr_mN && triangles_size) { /* create attribute */ attr_mN = attributes.add(ATTR_STD_MOTION_VERTEX_NORMAL); @@ -556,6 +556,32 @@ void Mesh::add_vertex_normals() } } } + + /* subd vertex normals */ + if(!subd_attributes.find(ATTR_STD_VERTEX_NORMAL) && subd_faces.size()) { + /* get attributes */ + Attribute *attr_vN = subd_attributes.add(ATTR_STD_VERTEX_NORMAL); + float3 *vN = attr_vN->data_float3(); + + /* compute vertex normals */ + memset(vN, 0, verts.size()*sizeof(float3)); + + for(size_t i = 0; i < subd_faces.size(); i++) { + SubdFace& face = subd_faces[i]; + + for(size_t j = 0; j < face.num_corners; j++) { + size_t corner = subd_face_corners[face.start_corner+j]; + vN[corner] += verts[corner]; + } + } + + for(size_t i = 0; i < verts_size; i++) { + vN[i] = normalize(vN[i]); + if(flip) { + vN[i] = -vN[i]; + } + } + } } void Mesh::pack_normals(Scene *scene, uint *tri_shader, float4 *vnormal) |