Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMai Lavelle <mai.lavelle@gmail.com>2016-08-23 20:57:45 +0300
committerMai Lavelle <mai.lavelle@gmail.com>2016-08-24 17:39:00 +0300
commit74bd80996287b3d7bb99fa9e980bb545f59155f7 (patch)
treec2a33252d26dca3c93d75bc3d14c380b106649d4 /intern/cycles/render
parent0ca4e3942427ad294428ba1b8db2cafe3bbdf5d6 (diff)
Cycles Standalone: Fix support for subdivision meshes
Changes from microdisplacement work broke previous support for subdivision meshes, sometimes leading to crashes; this makes things work again. Files that contain "patch" nodes will need to be updated to use meshes instead, as specifying patches was both inefficient and completely unsupported by the new subdivision code.
Diffstat (limited to 'intern/cycles/render')
-rw-r--r--intern/cycles/render/mesh.cpp30
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)