def test_shader1(self): factory = renmas2.Factory() ren = renmas2.Renderer() irender = renmas2.IRender(ren) #ren.spectral_rendering = True runtime = Runtime() irender.add_light(type="pointlight", name="light1", source=(4.0, 4.0, 4.0), position=(10.1, 10, 10)) irender.add_shape(type="sphere", name="Sphere00", radius=3.0, position=(0.0, 0.0, 0.0)) ren.prepare() ren.intersector.visibility_asm([runtime], "ray_scene_visibility") ren.shader.shade_asm([runtime], "shade", "ray_scene_visibility") mc = ren.assembler.assemble(self.asm_code1(ren)) ds = runtime.load("test", mc) ds["hp.hit"] = (4.4, 2.2, 1.0, 0.0) ds["hp.t"] = 2.2 ds["hp.normal"] = (0.0, 1.0, 0.0, 0.0) ds["hp.mat_index"] = 0 runtime.run("test") hit = renmas2.Vector3(4.4, 2.2, 1.0) normal = renmas2.Vector3(0.0, 1.0, 0.0) hp = renmas2.shapes.HitPoint(2.2, hit, normal, 0) ret = ren.shader.shade(hp) print(ret) print(ds["hp.l_spectrum.values"])
def test_isect1(self): factory = renmas2.Factory() ren = renmas2.Renderer() runtime = Runtime() irender = renmas2.IRender(ren) #irender.add_shape(type="mesh", name="cube1", filename="I:/Ply_files/Horse97K.ply") #irender.add_shape(type="mesh", name="cube1", filename="I:/Obj_files/auto1.obj") triangle = factory.create_triangle(v0=(2, 2, 2), v1=(5, 2, 2), v2=(3.5, 5, 2)) ray = factory.create_ray(origin=(3, 2.5, 0), direction=(0, 0.1, 0.88)) ren.add("triangle1", triangle) ray = factory.create_ray(origin=(10, 10, 10), direction=(-1, -1, -1)) ren.intersector.prepare() ren.intersector.isect_asm([runtime], "ray_scene_intersection") mc = ren.assembler.assemble(self.asm_code(ren)) ds = runtime.load("test", mc) ren.intersector.visibility_asm([runtime], "ray_scene_intersection_bool") self.ray_ds(ds, ray, "ray1") runtime.run("test") print(ds["hp1.t"]) hp = ren.intersector.isect(ray) print(hp.t)
def test_isect(self): factory = renmas2.Factory() ren = renmas2.Renderer() runtime = Runtime() irender = renmas2.IRender(ren) filename = 'C:\\Users\\Mario\\Desktop\\glass\\glass.py' exec(compile(open(filename).read(), filename, 'exec'), dict(locals()), dict(globals())) ren.prepare() ren.macro_call.set_runtimes([runtime]) ren.intersector.isect_asm([runtime], 'ray_scene_intersection') mc = ren.assembler.assemble(self.asm_code(ren)) ds = runtime.load("test", mc) camera = ren.camera sampler = ren.sampler for tile in ren._tiles3: sampler.set_tile(tile) while True: sam = sampler.get_sample() if sam is None: break ray = camera.ray(sam) self.ray_ds(ds, ray, "ray1") runtime.run("test") t = ds["hp1.t"] hp = ren.intersector.isect(ray) if hp is False: self.assertFalse(ds["ret"] != 0) if ds["ret"] == 0: self.assertFalse(hp) if hp is not False: n1 = hp.normal n2 = ds["hp1.normal"] #print("Normal") #print(n1) #print(n2) #print("Hit point") #print(hp.hit_point) #print(ds['hp1.hit']) self.assertAlmostEqual(hp.t, t, 1) print(t, hp.t) print(n1) print(n2) self.assertAlmostEqual(n1.x, n2[0], 1) self.assertAlmostEqual(n1.y, n2[1], 1) self.assertAlmostEqual(n1.z, n2[2], 1)
def test_grid_performance(self): factory = renmas2.Factory() ren = renmas2.Renderer() runtime = Runtime() irender = renmas2.IRender(ren) filename = 'I:\\GitRENMAS\\scenes\\mini_moris.py' exec(compile(open(filename).read(), filename, 'exec'), dict(locals()), dict(globals())) ren.prepare() ren.macro_call.set_runtimes([runtime]) ren.intersector.isect_asm([runtime], 'ray_scene_intersection') mc = ren.assembler.assemble(self.asm_code(ren)) ds = runtime.load("test", mc) ren.sampler.set_tile(ren._tiles3[0]) while True: sam = ren.sampler.get_sample() if sam is None: break if sam.iy == 105: if sam.ix == 188: ray = ren.camera.ray(sam) self.ray_ds(ds, ray, "ray1") start = time.clock() runtime.run("test") end = time.clock() - start print("Time:", end) print("Counter1", ds["counter1"]) print("Counter2", ds["counter2"]) print("Counter3", ds["counter3"]) print("tx_next", ds["tx_next"]) print("ty_next", ds["ty_next"]) print("tz_next", ds["tz_next"]) print("temp", ds["temp"]) break hp = ren.intersector.isect(ray) if hp: print("intersection ocur") else: print("no intersection ocur")
import time import random import winlib import renmas2 import renmas2.core import renmas2.shapes renderer = renmas2.Renderer() irender = renmas2.IRender(renderer) factory = renmas2.core.Factory() m1 = {"lambertian":{"spectrum":(0.0, 0.9, 0.0)}} m = factory.create_material(brdfs=(m1,)) renderer.add("m1", m) l = factory.create_light(type="point", spectrum=(3.0,3.0,3.0), position=(10,10,10)) renderer.add("l1", l) blitter = renmas2.core.Blitter() def blt_float_img_to_window(x, y, img, win): da, dpitch = win.get_addr() dw, dh = win.get_size() sa, spitch = img.get_addr() sw, sh = img.get_size() blitter.blt_floatTorgba(da, x, y, dw, dh, dpitch, sa, 0, 0, sw, sh, spitch) renderer.threads(1) filename = 'G:\\GitRENMAS\\renmas\\scenes\\sphere1.py' exec(compile(open(filename).read(), filename, 'exec'), dict(locals()), dict(globals())) renderer.assign_material("Sphere00", 'm1')