def render(): print "Ray Tracing Started" HRES = IMAGE_SIZE[0] VRES = IMAGE_SIZE[1] aspect_ratio = float(HRES) / VRES #Camera parameters to be abstracted away later fovy = 45.0 * (pi / 180.0) #UNIT_Y is up eye = Vector3(0, 0, 0) look_at = Vector3(0, 0, -10) d = 1 / tan(fovy/2) #End camera parameters #Calculate orthonormal basis l = look_at - eye l.normalise() v = cross_product(l, UNIT_Y) v.normalise() #Note that u is a unit vector! u = cross_product(v, l) #Note: v is right and u is up on the image plane #Find the lower left corner #look_at is the center of the image plane... ll = eye + l * d - v * aspect_ratio - u #End calculations rays = [] v_step = 2.0 / VRES h_step = 2.0 * aspect_ratio / HRES height = IMAGE_SIZE[1] width = IMAGE_SIZE[0] image_buf = [] for x in xrange(width): if x == (width * 0.25): print "25% complete..." if x == (width * 0.5): print "50% complete..." if x == (width * 0.75): print "75% complete..." if x == (width - 1): print "100% complete..." for y in xrange(height): p = ll + v * h_step * float(x) + u * v_step * float(y) d = p - eye d.normalise() primary_ray = Ray(eye, d) color = ray_trace(primary_ray) image_buf.append(clamp(color)) return image_buf
def render(ray_buffer = []): print "Ray Tracing Started" height = IMAGE_SIZE[1] width = IMAGE_SIZE[0] image_buf = [] for x in range(width): if x == (width * 0.25): print "25% complete..." if x == (width * 0.5): print "50% complete..." if x == (width * 0.75): print "75% complete..." if x == (width - 1): print "100% complete..." for y in range(height): primary_ray = ray_buffer[x * height + y] color = ray_trace(primary_ray) image_buf.append(clamp(color)) return image_buf