[Bf-blender-cvs] [075950ad66b] blender-v2.79a-release: Cycles: Fix wrong shading when some mesh triangle has non-finite coordinate

Sergey Sharybin noreply at git.blender.org
Mon Jan 8 15:16:06 CET 2018


Commit: 075950ad66b02cea5aa436e04221d94571f55409
Author: Sergey Sharybin
Date:   Wed Oct 18 12:19:53 2017 +0200
Branches: blender-v2.79a-release
https://developer.blender.org/rB075950ad66b02cea5aa436e04221d94571f55409

Cycles: Fix wrong shading when some mesh triangle has non-finite coordinate

This is fully unpredictable for artists when one damaged object makes the whole
scene to render incorrectly. This involves two main changes:

- It is not enough to check triangle bounds to be valid when building BVH.
  This is because triangle might have some finite vertices and some non-finite.

- We shouldn't add non-finite triangle area to the overall area for MIS.

===================================================================

M	intern/cycles/bvh/bvh_build.cpp
M	intern/cycles/render/light.cpp
M	intern/cycles/render/mesh.cpp
M	intern/cycles/render/mesh.h

===================================================================

diff --git a/intern/cycles/bvh/bvh_build.cpp b/intern/cycles/bvh/bvh_build.cpp
index 224dcbaf3fc..ab0e2ddd7cf 100644
--- a/intern/cycles/bvh/bvh_build.cpp
+++ b/intern/cycles/bvh/bvh_build.cpp
@@ -129,7 +129,7 @@ void BVHBuild::add_reference_triangles(BoundBox& root, BoundBox& center, Mesh *m
 		if(attr_mP == NULL) {
 			BoundBox bounds = BoundBox::empty;
 			t.bounds_grow(verts, bounds);
-			if(bounds.valid()) {
+			if(bounds.valid() && t.valid(verts)) {
 				references.push_back(BVHReference(bounds,
 				                                  j,
 				                                  i,
diff --git a/intern/cycles/render/light.cpp b/intern/cycles/render/light.cpp
index 93d88c5642c..aeaf303bce2 100644
--- a/intern/cycles/render/light.cpp
+++ b/intern/cycles/render/light.cpp
@@ -348,6 +348,9 @@ void LightManager::device_update_distribution(Device *device, DeviceScene *dscen
 				offset++;
 
 				Mesh::Triangle t = mesh->get_triangle(i);
+				if(!t.valid(&mesh->verts[0])) {
+					continue;
+				}
 				float3 p1 = mesh->verts[t.v[0]];
 				float3 p2 = mesh->verts[t.v[1]];
 				float3 p3 = mesh->verts[t.v[2]];
diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp
index 03825f780e0..d160b4d4139 100644
--- a/intern/cycles/render/mesh.cpp
+++ b/intern/cycles/render/mesh.cpp
@@ -107,6 +107,13 @@ void Mesh::Triangle::verts_for_step(const float3 *verts,
 	}
 }
 
+bool Mesh::Triangle::valid(const float3 *verts) const
+{
+	return isfinite3_safe(verts[v[0]]) &&
+	       isfinite3_safe(verts[v[1]]) &&
+	       isfinite3_safe(verts[v[2]]);
+}
+
 /* Curve */
 
 void Mesh::Curve::bounds_grow(const int k, const float3 *curve_keys, const float *curve_radius, BoundBox& bounds) const
diff --git a/intern/cycles/render/mesh.h b/intern/cycles/render/mesh.h
index 043ce9d0ffc..f079021c915 100644
--- a/intern/cycles/render/mesh.h
+++ b/intern/cycles/render/mesh.h
@@ -70,6 +70,8 @@ public:
 		                    size_t num_steps,
 		                    size_t step,
 		                    float3 r_verts[3]) const;
+
+		bool valid(const float3 *verts) const;
 	};
 
 	Triangle get_triangle(size_t i) const



More information about the Bf-blender-cvs mailing list