summaryrefslogtreecommitdiff
path: root/src/intersect.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/intersect.h')
-rw-r--r--src/intersect.h16
1 files changed, 11 insertions, 5 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