diff options
author | Anthony LaTorre <telatorre@gmail.com> | 2011-06-02 15:45:05 -0400 |
---|---|---|
committer | Anthony LaTorre <telatorre@gmail.com> | 2011-06-02 15:45:05 -0400 |
commit | a0505450d281841a3e6d25a7510c98b58ef92281 (patch) | |
tree | 544e4772525f655f0b064fecd51cd7166b97a8c9 /src | |
parent | 8bbdf7f53b918857a09a9bee4a158f13834bfce6 (diff) | |
download | chroma-a0505450d281841a3e6d25a7510c98b58ef92281.tar.gz chroma-a0505450d281841a3e6d25a7510c98b58ef92281.tar.bz2 chroma-a0505450d281841a3e6d25a7510c98b58ef92281.zip |
material/surface codes or color are packed into the fourth byte of the triangle data texture depending on the color keyword passed to Geometry.build()
Diffstat (limited to 'src')
-rw-r--r-- | src/intersect.h | 16 | ||||
-rw-r--r-- | src/kernel.cu | 2 |
2 files changed, 12 insertions, 6 deletions
diff --git a/src/intersect.h b/src/intersect.h index a968f09..92bcf0c 100644 --- a/src/intersect.h +++ b/src/intersect.h @@ -54,16 +54,22 @@ __device__ bool intersect_triangle(const float3 &origin, const float3 &direction angle between the ray and the plane normal to determine the brightness. `direction` must be normalized. */ -__device__ int get_color(const float3 &direction, const float3 &v0, const float3& v1, const float3 &v2) +__device__ int get_color(const float3 &direction, const float3 &v0, const float3& v1, const float3 &v2, const int base_color=0xFFFFFFFF) { - float scale = 255*dot(normalize(cross(v1-v0,v2-v0)),-direction); + float scale = dot(normalize(cross(v1-v0,v2-v0)),-direction); + + unsigned int r = 0xFF & (base_color >> 16); + unsigned int g = 0xFF & (base_color >> 8); + unsigned int b = 0xFF & base_color; if (scale < 0.0f) - scale = 255*dot(-normalize(cross(v1-v0,v2-v0)),-direction); + scale = dot(-normalize(cross(v1-v0,v2-v0)),-direction); - int rgb = floorf(scale); + r = floorf(r*scale); + g = floorf(g*scale); + b = floorf(b*scale); - return rgb << 16 | rgb << 8 | rgb; + return r << 16 | g << 8 | b; } /* Test the intersection between a ray starting from `origin` traveling in the diff --git a/src/kernel.cu b/src/kernel.cu index a020180..ead08da 100644 --- a/src/kernel.cu +++ b/src/kernel.cu @@ -190,7 +190,7 @@ __global__ void ray_trace(int nthreads, float3 *origins, float3 *directions, int float3 v1 = make_float3(tex1Dfetch(vertices, triangle_data.y)); float3 v2 = make_float3(tex1Dfetch(vertices, triangle_data.z)); - *(pixels+idx) = get_color(direction, v0, v1, v2); + *(pixels+idx) = get_color(direction, v0, v1, v2, triangle_data.w); } } // ray_trace |