summaryrefslogtreecommitdiff
path: root/src/kernel.cu
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel.cu')
-rw-r--r--src/kernel.cu16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/kernel.cu b/src/kernel.cu
index 307412e..71b4153 100644
--- a/src/kernel.cu
+++ b/src/kernel.cu
@@ -239,7 +239,7 @@ __global__ void process_image(int nthreads, float3 *image, int *pixels, int nima
} // process_image
-__global__ void ray_trace(int nthreads, float3 *positions, float3 *directions, int *pixels)
+__global__ void ray_trace(int nthreads, float3 *positions, float3 *directions, int *pixels, float *distances)
{
int id = blockIdx.x*blockDim.x + threadIdx.x;
@@ -257,6 +257,7 @@ __global__ void ray_trace(int nthreads, float3 *positions, float3 *directions, i
if (triangle_index == -1)
{
pixels[id] = 0;
+ distances[id] = 1e9f;
}
else
{
@@ -267,6 +268,7 @@ __global__ void ray_trace(int nthreads, float3 *positions, float3 *directions, i
float3 v2 = g_vertices[triangle_data.z];
pixels[id] = get_color(direction, v0, v1, v2, g_colors[triangle_index]);
+ distances[id] = distance;
}
} // ray_trace
@@ -277,7 +279,7 @@ __global__ void ray_trace(int nthreads, float3 *positions, float3 *directions, i
color whose brightness is determined by the cosine of the angle between
the ray and the normal of the triangle it intersected, else set the pixel
to 0. */
-__global__ void ray_trace_alpha(int nthreads, float3 *positions, float3 *directions, int *pixels)
+__global__ void ray_trace_alpha(int nthreads, float3 *positions, float3 *directions, int *pixels, float *distances)
{
int id = blockIdx.x*blockDim.x + threadIdx.x;
@@ -288,7 +290,15 @@ __global__ void ray_trace_alpha(int nthreads, float3 *positions, float3 *directi
float3 direction = directions[id];
direction /= norm(direction);
- pixels[id] = get_color_alpha(position, direction);
+ bool hit;
+ float distance;
+
+ pixels[id] = get_color_alpha(position, direction, hit, distance);
+
+ if (hit)
+ distances[id] = distance;
+ else
+ distances[id] = 1e9;
} // ray_trace