예제 #1
0
    def render_intersection(self, intersection, ray, world, bouncenum):
        """Returns the value to render, possibly by recusively rendering reflections"""
        global bounces
        bounces.append(self)

        # getting color
        r1mod = (vectormath.get_projection_of_ray_onto_ray(
                [self.ray1[0], intersection],
                self.ray1
                ) % vectormath.get_distance(*self.ray1))
        r2mod = (vectormath.get_projection_of_ray_onto_ray(
                [self.ray2[0], intersection],
                self.ray2
                ) % vectormath.get_distance(*self.ray2))
        if (numpy.floor(r1mod) + numpy.floor(r2mod)) % 2 == 0:
            color = 0
        else:
            color = 1
        if bouncenum > BOUNCELIMIT:
            print 'bouncelimit acheived, ignoring further reflections for this ray'
            print bounces
            bounces = []
            return self.color * .5 + self.color * .5 * world.render_light(intersection, ray)
        else:
            bounce_ray = self.get_bounced_ray(ray, intersection)

        v = (
                color * .5 +
                self.reflectivity/2 * world.render_ray(bounce_ray, bouncenum+1) +
                color * (1 - self.reflectivity/2) * world.render_light(intersection, ray)
                )
        return v
예제 #2
0
 def get_first_intersection(self, ray):
     line_intersections = self.get_intersections(ray)
     if len(line_intersections) == 1:
         return line_intersections[0]
     elif len(line_intersections) == 0:
         return None
     else:
         line_intersections.sort(key=lambda x: vectormath.get_distance(ray[0], x))
         return line_intersections[0]
예제 #3
0
 def get_light_contribution(self, requested_intersection, ray, world):
     result = world.get_first_ray_intersection(ray)
     if result:
         obj, intersection = result
     else:
         return 0
         print 'got no intersection result'
     SAME_INTERSECTION_TOLERANCE = .00001
     if vectormath.get_distance(intersection, requested_intersection) < SAME_INTERSECTION_TOLERANCE:
         normal_ray = obj.get_normal_ray(intersection)
         theta = self.get_light_theta(normal_ray)
         return max(0.0, numpy.cos(theta))
     else:
         print 'different intersection found - this point is in shadow!'
         return 0