diff options
Diffstat (limited to 'src/mesh.h')
-rw-r--r-- | src/mesh.h | 29 |
1 files changed, 23 insertions, 6 deletions
@@ -36,13 +36,29 @@ __device__ int convert(int c) /* Test the intersection between a ray starting at `origin` traveling in the direction `direction` and the bounding box around node `i`. If the ray intersects the bounding box return true, else return false. */ -__device__ bool intersect_node(const float3 &origin, const float3 &direction, const int &i) +__device__ bool intersect_node(const float3 &origin, const float3 &direction, const int &i, const float &min_distance) { float3 lower_bound = g_lower_bounds[i]; float3 upper_bound = g_upper_bounds[i]; - return intersect_box(origin, direction, lower_bound, upper_bound); -} + float distance_to_box; + + if (intersect_box(origin, direction, lower_bound, upper_bound, distance_to_box)) + { + if (min_distance < 0.0f) + return true; + + if (distance_to_box > min_distance) + return false; + + return true; + } + else + { + return false; + } + +} // intersect_node /* Find the intersection between a ray starting at `origin` traveling in the direction `direction` and the global mesh texture. If the ray intersects @@ -53,8 +69,9 @@ __device__ int intersect_mesh(const float3 &origin, const float3& direction, flo int triangle_index = -1; float distance; + min_distance = -1.0f; - if (!intersect_node(origin, direction, g_start_node)) + if (!intersect_node(origin, direction, g_start_node, min_distance)) return -1; unsigned int stack[STACK_SIZE]; @@ -82,7 +99,7 @@ __device__ int intersect_mesh(const float3 &origin, const float3& direction, flo { for (i=first_child; i < stop; i++) { - if (intersect_node(origin, direction, i)) + if (intersect_node(origin, direction, i, min_distance)) { *node = i; node++; @@ -134,7 +151,7 @@ __device__ int intersect_mesh(const float3 &origin, const float3& direction, flo extern "C" { - __global__ void set_global_mesh_variables(uint4 *triangles, float3 *vertices, unsigned int *colors, unsigned int start_node, unsigned int first_node, float3 *lower_bounds, float3 *upper_bounds) +__global__ void set_global_mesh_variables(uint4 *triangles, float3 *vertices, unsigned int *colors, unsigned int start_node, unsigned int first_node, float3 *lower_bounds, float3 *upper_bounds) { g_triangles = triangles; g_vertices = vertices; |