for s in objs: hit = s.intersect(ray, min_dist) if hit is False: continue if hit.t < min_dist: min_dist = hit.t hit_point = hit return hit_point if __name__ == "__main__": asm = util.get_asm() mc = asm.assemble(ASM) #mc.print_machine_code() runtime = Runtime() Plane.intersect_asm(runtime, "_plane_intersect") intersect_ray_shape_array("plane", runtime, "plane_array", "_plane_intersect") ds = runtime.load("test", mc) planes, dyn_planes = generate_planes(10000) ray = generate_ray() hp = ray_objects(ray, planes) adr = dyn_planes.get_addr() ds["ptr_planes"] = adr ds["nplanes"] = dyn_planes.size ds["r1.origin"] = v4(ray.origin) ds["r1.dir"] = v4(ray.dir) t = timeit.Timer(lambda: runtime.run("test"))
mc = asm.assemble(ASM3) #mc = asm.assemble(SSE2_ASM) #mc.print_machine_code() runtime = Runtime() ds = runtime.load("test", mc) ds["tri1.p0"] = v4(tr.v0) ds["tri1.p1"] = v4(tr.v1) ds["tri1.p2"] = v4(tr.v2) ds["tri1.normal"] = v4(tr.normal) ds["tri1.mat_index"] = tr.material ds["r1.origin"] = v4(ray.origin) ds["r1.dir"] = v4(ray.dir) intersect_ray_shape_array("triangle", runtime, "triangle_array", "ray_triangle") #runtime.run("test") dy_arr, lst_arr = create_triangle_array(100000) isect_ray(lst_arr[0], ray) hp = isect(ray, lst_arr) if hp is not False and hp is not None: print("Tocka presjeka", hp.t) mc2 = asm.assemble(ASM2) ds2 = runtime.load("test2", mc2) ds2["r1.origin"] = v4(ray.origin) ds2["r1.dir"] = v4(ray.dir)
print ("time", t.timeit(1)) hp = isect(ray, shape_db.shapes()) hp2 = isect_ray_scene(ray) asm = util.get_asm() dy_spheres = shape_db.asm_shapes[Sphere] dy_planes = shape_db.asm_shapes[Plane] #ds["r1.origin"] = v4(ray.origin) #ds["r1.dir"] = v4(ray.dir) runtime = Runtime() Sphere.intersect_asm(runtime, "_sphere_intersect") intersect_ray_shape_array("sphere", runtime, "sphere_array", "_sphere_intersect") Plane.intersect_asm(runtime, "_plane_intersect") intersect_ray_shape_array("plane", runtime, "plane_array", "_plane_intersect") mc = asm.assemble(ASM) ds = runtime.load("test", mc) ds["r1.origin"] = v4(ray.origin) ds["r1.dir"] = v4(ray.dir) ds["ptr_spheres"] = dy_spheres.get_addr() ds["nspheres"] = dy_spheres.size ds["ptr_planes"] = dy_planes.get_addr() ds["nplanes"] = dy_planes.size #runtime.run("test")
if __name__ == "__main__": asm = util.get_asm() mc = asm.assemble(ASM) #mc.print_machine_code() runtime = Runtime() #ds = runtime.load("test", mc) #intersect_sphere(runtime, ds) #intersect_ray_spheres(100000, runtime, ds) #intersect_ray_spheres_bool(10) Sphere.intersect_asm(runtime, "_sphere_intersect") intersect_ray_shape_array("sphere", runtime, "sphere_array", "_sphere_intersect") mc = asm.assemble(ASM2) ds = runtime.load("test2", mc) spheres, dyn_spheres = generate_spheres(1000) ray = generate_ray() hp = ray_objects(ray, spheres) adr = dyn_spheres.get_addr() ds["ptr_spheres"] = adr ds["nspheres"] = dyn_spheres.size ds["r1.origin"] = v4(ray.origin) ds["r1.dir"] = v4(ray.dir) runtime.run("test2")