def test_cameras(self): eye = Vector3(0.0, 10.0, 5.0) lookat = Vector3(0.0, 0.0, 0.0) distance = 100.0 cam = Camera(eye, lookat, distance) cam.load('pinhole') cam.compile() runtimes = [Runtime()] cam.prepare(runtimes) code = """ ray = Ray() sample = Sample() sample.x = 2.2 sample.y = 2.5 generate_ray(ray, sample) origin = ray.origin direction = ray.direction """ origin = Vec3Arg('origin', Vector3(0.0, 0.0, 0.0)) direction = Vec3Arg('direction', Vector3(0.0, 0.0, 0.0)) args = [origin, direction] shader = Shader(code=code, args=args) shader.compile([cam.shader]) shader.prepare(runtimes) shader.execute() ray = Ray(Vector3(0.0, 0.0, 0.0), Vector3(0.0, 0.0, 0.0)) sample = Sample(2.2, 2.5, 2, 2, 1.0) cam.execute_py(ray, sample) v = shader.get_value('origin') o = ray.origin self.assertAlmostEqual(v.x, o.x) self.assertAlmostEqual(v.y, o.y) self.assertAlmostEqual(v.z, o.z) v = shader.get_value('direction') d = ray.direction self.assertAlmostEqual(v.x, d.x) self.assertAlmostEqual(v.y, d.y) self.assertAlmostEqual(v.z, d.z)
#intersection mgr = ShapeManager() sphere = Sphere(Vector3(0.0, 0.0, 0.0), 2.0, 0) mgr.add('sph1', sphere) isector = LinearIsect(mgr) isector.compile() isector.prepare(runtimes) ################### integrator = Integrator() integrator.load('isect_shader') sampler.compile() camera.compile() sampler.prepare(runtimes) camera.prepare(runtimes) integrator.compile([sampler.shader, camera.shader, isector.shader]) integrator.prepare(runtimes) img = ImagePRGBA(1024, 768) integrator.shader.set_value('image', img) start = time.clock() integrator.execute() end = time.clock() print("Rendering time:", end-start) img2 = ImageRGBA(1024, 768) blt_prgba_to_rgba(img, img2)