diff options
author | Anthony LaTorre <tlatorre9@gmail.com> | 2011-08-26 01:27:43 -0400 |
---|---|---|
committer | Anthony LaTorre <tlatorre9@gmail.com> | 2011-08-26 01:27:43 -0400 |
commit | 46f7f58dd6cf3c008e3ef0496f0ee60b52db6941 (patch) | |
tree | a1039414283669a2783f001e0c77ac09e5ba7baa /src | |
parent | e75eda8a637c01c34c71063b91a86845cc1c5beb (diff) | |
download | chroma-46f7f58dd6cf3c008e3ef0496f0ee60b52db6941.tar.gz chroma-46f7f58dd6cf3c008e3ef0496f0ee60b52db6941.tar.bz2 chroma-46f7f58dd6cf3c008e3ef0496f0ee60b52db6941.zip |
no more 3d headache! 3d viewing angle changes depending on the distance to the object in the center of the screen.
Diffstat (limited to 'src')
-rw-r--r-- | src/alpha.h | 10 | ||||
-rw-r--r-- | src/kernel.cu | 35 |
2 files changed, 28 insertions, 17 deletions
diff --git a/src/alpha.h b/src/alpha.h index 263fa1e..ac75834 100644 --- a/src/alpha.h +++ b/src/alpha.h @@ -10,8 +10,10 @@ #define ALPHA_DEPTH 10 -__device__ int get_color_alpha(const float3 &origin, const float3& direction, bool &hit, float &distance) +__device__ int get_color_alpha(const float3 &origin, const float3& direction) { + float distance; + if (!intersect_node(origin, direction, g_start_node, -1.0f)) return 0; @@ -95,13 +97,7 @@ __device__ int get_color_alpha(const float3 &origin, const float3& direction, bo while (node != head); if (n < 1) - { - hit = false; return 0; - } - - hit = true; - distance = distances[0]; float scale = 1.0f; float fr = 0.0f; diff --git a/src/kernel.cu b/src/kernel.cu index 71b4153..d36d260 100644 --- a/src/kernel.cu +++ b/src/kernel.cu @@ -239,7 +239,29 @@ __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, float *distances) +__global__ void distance_to_mesh(int nthreads, float3 *positions, float3 *directions, float *distances) +{ + int id = blockIdx.x*blockDim.x + threadIdx.x; + + if (id >= nthreads) + return; + + float3 position = positions[id]; + float3 direction = directions[id]; + direction /= norm(direction); + + float distance; + + int triangle_index = intersect_mesh(position, direction, distance); + + if (triangle_index == -1) + distances[id] = 1e9; + else + distances[id] = distance; + +} // distance_to_mesh + +__global__ void ray_trace(int nthreads, float3 *positions, float3 *directions, int *pixels) { int id = blockIdx.x*blockDim.x + threadIdx.x; @@ -257,7 +279,6 @@ __global__ void ray_trace(int nthreads, float3 *positions, float3 *directions, i if (triangle_index == -1) { pixels[id] = 0; - distances[id] = 1e9f; } else { @@ -268,7 +289,6 @@ __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 @@ -279,7 +299,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, float *distances) +__global__ void ray_trace_alpha(int nthreads, float3 *positions, float3 *directions, int *pixels) { int id = blockIdx.x*blockDim.x + threadIdx.x; @@ -293,12 +313,7 @@ __global__ void ray_trace_alpha(int nthreads, float3 *positions, float3 *directi bool hit; float distance; - pixels[id] = get_color_alpha(position, direction, hit, distance); - - if (hit) - distances[id] = distance; - else - distances[id] = 1e9; + pixels[id] = get_color_alpha(position, direction); } // ray_trace |