From ea861ed3e131c54940bd3f8a6619c06812027efd Mon Sep 17 00:00:00 2001 From: James Fulop Date: Sun, 18 Sep 2016 23:39:34 -0400 Subject: [PATCH] fixed bug were it would pick vertices behind the camera --- renderdoc/data/glsl/mesh.comp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/renderdoc/data/glsl/mesh.comp b/renderdoc/data/glsl/mesh.comp index e1d4c17e6..1881cb31d 100644 --- a/renderdoc/data/glsl/mesh.comp +++ b/renderdoc/data/glsl/mesh.comp @@ -52,7 +52,7 @@ bool TriangleRayIntersect(vec3 A, vec3 B, vec3 C, // if the determinant is negative the triangle is backfacing, but we still take those! // if the determinant is close to 0, the ray misses the triangle - if (abs(det) > 0.000001f) + if (abs(det) > 0.00001) { float invDet = 1 / det; @@ -61,13 +61,16 @@ bool TriangleRayIntersect(vec3 A, vec3 B, vec3 C, float u = dot(tvec, pvec) * invDet; float v = dot(RayDirection, qvec) * invDet; - if (u > 0 && u < 1 && - v > 0 && u + v < 1) + if (u >= 0 && u <= 1 && + v >= 0 && u + v <= 1) { float t = dot(v0v2, qvec) * invDet; - HitPosition = RayPosition + (RayDirection * t); - //Info->Position = HitPosition; - Result = true; + if (t > 0.00001) + { + HitPosition = RayPosition + (RayDirection * t); + Result = true; + } + } }