def raycast_asm(): sampler = ren.get_sampler() camera = ren.get_camera() film = ren.get_film() lst_lights = ren.lst_lights() shapes = ren.lst_shapes() isect = renmas.shapes.isect #intersection rutine shade = renmas.core.shade background = renmas.core.Spectrum(0.05, 0.05, 0.05) hp2 = renmas.shapes.HitPoint() hp2.spectrum = background tile = next_tile() if tile is None: global image_saved if not image_saved: save_image(film, "Image5.png") image_saved = True return None sample = renmas.samplers.Sample() x, y, width, height = tile sampler.tile(x, y, width, height) start = time.clock() runtime.run("raycast") #100% rendering in assembly language blt_float_img_to_window(0, 0, film.image, win) end = time.clock() global duration duration = duration + (end - start) print("Renderiranje jednog tile je trajalo", end - start, duration) return True
def test_linear(): runtime, ds = isect_ray_sphere_array() random_spheres(1000) shapes = ren.lst_shapes() ray = ren.random_ray() ray_ds(ds, ray, "r1") dyn_arrays = ren.dyn_arrays() ds["nspheres"] = dyn_arrays[renmas.shapes.Sphere].size ds["ptr_spheres"] = dyn_arrays[renmas.shapes.Sphere].get_addr() runtime.run("isect") hp = renmas.shapes.isect(ray, shapes, 999999.0) if hp is not None: print(hp.t, ds["hp.t"])
def build_scene(): idx = ren.get_mat_idx("m1") ren.create_sphere(0, 0, 0, 5, idx) idx3 = ren.get_mat_idx("m4") ren.create_sphere(0, 10, 0, 5, idx3) idx3 = ren.get_mat_idx("m6") ren.create_sphere(0, 0, -10, 4, idx3) idx4 = ren.get_mat_idx("m5") ren.create_sphere(0, 0, 10, 4, idx4) idx5 = ren.get_mat_idx("m5") ren.create_triangle((8, 5, 5), (4, 9, 8), (5, -2, 3), idx5) shapes = ren.lst_shapes() return shapes
def build_scene(): idx = ren.get_mat_idx("m1") ren.create_sphere(0, 0, 0, 5, idx) idx3 = ren.get_mat_idx("m4") ren.create_sphere(0, 10, 0, 5, idx3) idx3 = ren.get_mat_idx("m6") ren.create_sphere(0, 0, -10, 4, idx3) idx4 = ren.get_mat_idx("m5") ren.create_sphere(0, 0, 10, 4, idx4) idx5 = ren.get_mat_idx("m5") ren.create_triangle((8,5,5), (4, 9, 8), (5, -2, 3), idx5) shapes = ren.lst_shapes() return shapes
def raycast(): sampler = ren.get_sampler() camera = ren.get_camera() film = ren.get_film() lst_lights = ren.lst_lights() shapes = ren.lst_shapes() #isect = renmas.shapes.isect #intersection rutine isect = grid.isect shade = renmas.core.shade background = renmas.core.Spectrum(0.00, 0.00, 0.00) hp2 = renmas.shapes.HitPoint() hp2.spectrum = background tile = next_tile() if tile is None: global image_saved if not image_saved: save_image(film, "Image5.png") print("Slika je spremljena") image_saved = True return None sample = renmas.samplers.Sample() x, y, width, height = tile sampler.tile(x, y, width, height) start = time.clock() while True: sam = sampler.get_sample(sample) if sam is None: break ray = camera.ray(sample) #hp = isect(ray, shapes, 999999.0) hp = isect(ray) if hp is None: film.add_sample(sample, hp2) #background else: hp.wo = ray.dir * -1.0 shade(hp) film.add_sample(sample, hp) #background blt_float_img_to_window(0, 0, film.image, win) end = time.clock() global duration duration = duration + (end - start) print("Renderiranje jednog tile je trajalo", end - start, duration) return True
cornell_scene() sh_props = {"type":"sphere", "position":(0,0,0), "radius":9, "material":"m1"} s = ren.create_shape(sh_props) sh_props = {"type":"triangle", "p0":(0.556,0.0,0.0), "p1":(0.006, 0.0, 0.559), "p2":(0.556, 0.0, 0.959) ,"material":"m1"} s = ren.create_shape(sh_props) sh_props = {"type":"triangle", "p0":(0.406,0.0,0.559), "p1":(0.556, 0.0, 0.0), "p2":(0.003, 0.0, 0.1) ,"material":"m1"} s = ren.create_shape(sh_props) ## BACK WALL sh_props = {"type":"triangle", "p0":(0.556,0.0,0.559), "p1":(0.0, 0.599, 0.559), "p2":(0.556, 0.549, 0.359) ,"material":"m2"} s = ren.create_shape(sh_props) sh_props = {"type":"triangle", "p0":(0.2,0.549,0.559), "p1":(0.756, 0.0, 0.559), "p2":(0.006, 0.0, 0.259) ,"material":"m2"} s = ren.create_shape(sh_props) runtime = Runtime() lst_shapes = ren.lst_shapes() adrese = ren.objfunc_array(lst_shapes, runtime) asm_structs = renmas.utils.structs("sample", "ray", "hitpoint") ASM = """ #DATA """ ASM += asm_structs + """ uint32 num uint32 addrs[256] hitpoint hp ray ray1 float min_dist = 999999.3
def build_scene(): ren.create_sphere(0, 0, 0, 2) shapes = ren.lst_shapes() return shapes
ray r1 hitpoint hp uint32 hit #CODE ; eax = pointer_to_ray, ebx = pointer_to_hitpoint mov eax, r1 mov ebx, hp call scene_isect mov dword [hit], eax #END """ gen_random_shapes(10) shapes = ren.lst_shapes() dyn_arrays = ren.dyn_arrays() runtime = Runtime() renmas.shapes.linear_isect_asm(runtime, "scene_isect", dyn_arrays) asm = renmas.utils.get_asm() mc = asm.assemble(ASM) ds = runtime.load("isect", mc) ray = ren.random_ray() ray_ds(ds, ray, "r1") runtime.run("isect") hp = renmas.shapes.isect(ray, shapes, 999999.0)
m_props = {"name": "m1", "sampling":"hemisphere_cos"} m = mdl.create_material(m_props) sh_props = {"type":"sphere", "position":(0,0,0), "radius":3, "material":"m1"} sphere = mdl.create_shape(sh_props) sh_props = {"type":"sphere", "position":(0,1,0), "radius":3, "material":"m1"} sphere2 = mdl.create_shape(sh_props) for x in range(1000): sh_props = {"type":"sphere", "position":(random.random(),random.random(),random.random()), "radius":random.random()*0.25, "material":"m1"} sphere3 = mdl.create_shape(sh_props) ray = generate_ray() #sphere = random_sphere() hp = sphere.isect(ray) hp = renmas.shapes.isect(ray, mdl.lst_shapes()) #print(hp.t) grid = Grid() grid.setup(mdl.lst_shapes()) hp3 = grid.isect(ray) #print(hp3.t) runtime = Runtime() grid.isect_asm(runtime, "grid_intersect") asm_structs = util.structs("ray", "grid", "hitpoint") ASM = """ #DATA """
} sphere2 = mdl.create_shape(sh_props) for x in range(1000): sh_props = { "type": "sphere", "position": (random.random(), random.random(), random.random()), "radius": random.random() * 0.25, "material": "m1" } sphere3 = mdl.create_shape(sh_props) ray = generate_ray() #sphere = random_sphere() hp = sphere.isect(ray) hp = renmas.shapes.isect(ray, mdl.lst_shapes()) #print(hp.t) grid = Grid() grid.setup(mdl.lst_shapes()) hp3 = grid.isect(ray) #print(hp3.t) runtime = Runtime() grid.isect_asm(runtime, "grid_intersect") asm_structs = util.structs("ray", "grid", "hitpoint") ASM = """ #DATA """