Ejemplo n.º 1
0
    def Dtest_isect2(self):
        factory = renmas2.Factory()
        ren = renmas2.Renderer()
        runtime = Runtime()
        ply = renmas2.core.Ply()
        ply.load("I:/Ply_files/cube.ply")
        #ply.load("I:/Ply_files/dragon_vrip.ply")
        vb = ply._vertex_buffer
        tb = ply._triangle_buffer
        mesh = factory.create_mesh(vb, tb)
        triangles = self.create_triangle_list(vb, tb)

        mesh.isect_asm([runtime], "ray_flat_mesh_intersection", ren.assembler,
                       ren.structures)
        mc = ren.assembler.assemble(self.asm_code2(ren))
        ds = runtime.load("test", mc)

        for i in range(100):
            ray = self.random_ray()
            self.ray_ds(ds, ray, "ray1")
            self.flat_mesh_ds(ds, mesh, "mesh1")
            runtime.run("test")
            hp = mesh.isect(ray)
            if hp:
                print(hp.t)
                print(ds["hp1.t"])
            print(ds["ret"])
Ejemplo n.º 2
0
    def test_isect1(self):
        factory = renmas2.Factory()
        ren = renmas2.Renderer()
        runtime = Runtime()

        triangle = factory.create_triangle(v0=(2, 2, 2),
                                           v1=(5, 2, 2),
                                           v2=(3.5, 5, 2))
        triangle = factory.create_triangle(v0=(3.64479, 19.4901, 31.67),
                                           v1=(1.5157999, 0.6639999, 31.8798),
                                           v2=(1.4469, 0.663999, 31.415))
        ray = factory.create_ray(origin=(280.0, 110.0, 244.0),
                                 direction=(-0.759278, -0.2980911,
                                            -0.57847869))
        #hp = triangle.isect(ray)

        triangle.isect_asm([runtime], "ray_triangle_intersection",
                           ren.assembler, ren.structures)
        mc = ren.assembler.assemble(self.asm_code(ren))
        ds = runtime.load("test", mc)

        self.ray_ds(ds, ray, "ray1")
        self.triangle_ds(ds, triangle, "tri1")
        runtime.run("test")
        self.intersect(ray, triangle, runtime, ds)
        for i in range(1000):
            r = self.random_ray()
            t = self.random_triangle()
            self.intersect(r, t, runtime, ds)
Ejemplo n.º 3
0
    def test_addsample(self):
        ren = renmas2.Renderer()
        runtime = Runtime()

        #ren.spectrum_rendering = True
        ren.film.nsamples = 2 
        ren.prepare()
        ren.converter.to_rgb_asm("spectrum_to_rgb", [runtime])
        ren.film.add_sample_asm([runtime], "add_sample", "spectrum_to_rgb")
        mc = ren.assembler.assemble(self.asm_code(ren))
        ds = runtime.load("test", mc)

        ds["sp1.ix"] = 10
        ds["sp1.iy"] = 10
        ds["sp1.xyxy"] = (10.4, 10.4, 10.4, 10.4)
        sample = renmas2.samplers.Sample(10.4, 10.4, 10, 10, 0.5)
        spec = ren.converter.create_spectrum((0.70, 0.2, 0.3))
        ren.film.add_sample(sample, spec)
        ds["spec1.values"] = spec.to_ds()
        runtime.run("test")

        ds["sp1.ix"] = 15
        ds["sp1.iy"] = 19
        ds["sp1.xyxy"] = (15.7, 19.4, 15.7, 19.4)
        sample = renmas2.samplers.Sample(10.4, 10.4, 15, 19, 0.5)
        spec = ren.converter.create_spectrum((0.50, 0.4, 0.1))
        ren.film.add_sample(sample, spec)
        ds["spec1.values"] = spec.to_ds()
        runtime.run("test")

        print(ren.film._ds[0]["temp"])
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    def test_pow_ps(self):
        asm = Tdasm()
        mc = asm.assemble(POW_CODE_PS)
        runtime = Runtime()
        load_math_func("fast_pow_ps", runtime)
        ds = runtime.load("pow_ps", mc)

        for x in range(1000):
            num1 = random.random() * 3 
            num2 = random.random() * 3
            num3 = random.random() * 3
            num4 = random.random() * 3
            num5 = random.random() * 3 
            num6 = random.random() * 3
            num7 = random.random() * 3
            num8 = random.random() * 3
            ds["v1"] = (num1, num2, num3, num4) 
            ds["v2"] = (num5, num6, num7, num8)
            runtime.run("pow_ps")
            rez_asm = ds["v1"]
            rez_py1 = math.pow(num1, num5)
            rez_py2 = math.pow(num2, num6)
            rez_py3 = math.pow(num3, num7)
            rez_py4 = math.pow(num4, num8)

            self.assertAlmostEqual(rez_asm[0], rez_py1, 1)
            self.assertAlmostEqual(rez_asm[1], rez_py2, 1)
            self.assertAlmostEqual(rez_asm[2], rez_py3, 1)
            self.assertAlmostEqual(rez_asm[3], rez_py4, 1)
Ejemplo n.º 6
0
    def test_isect1(self):
        factory = renmas2.Factory()
        ren = renmas2.Renderer()
        runtime = Runtime()

        ply = renmas2.core.Ply()
        ply.load("I:/Ply_files/Horse97K.ply")
        vb = ply.vertex_buffer
        tb = ply.triangle_buffer
        mesh = factory.create_mesh(vb, tb)

        mesh.isect_asm([runtime], "ray_smooth_mesh_intersection",
                       ren.assembler, ren.structures)
        mc = ren.assembler.assemble(self.asm_code1(ren))
        ds = runtime.load("test", mc)

        for i in range(1000):
            ray = self.random_ray()
            self.ray_ds(ds, ray, "ray1")
            self.smooth_mesh_ds(ds, mesh, "mesh1")
            runtime.run("test")
            hp = mesh.isect(ray)
            if hp:
                #print(hp.t, ds["hp1.t"])
                n1 = hp.normal
                n2 = ds["hp1.normal"]

                self.assertAlmostEqual(n1.x, n2[0], 3)
                self.assertAlmostEqual(n1.y, n2[1], 3)
                self.assertAlmostEqual(n1.z, n2[2], 3)
Ejemplo n.º 7
0
    def Dtest_isect2(self):
        factory = renmas2.Factory()
        ren = renmas2.Renderer()
        runtime = Runtime()
        ply = renmas2.core.Ply()
        ply.load("I:/Ply_files/cube.ply")
        #ply.load("I:/Ply_files/dragon_vrip.ply")
        vb = ply._vertex_buffer
        tb = ply._triangle_buffer
        mesh = factory.create_mesh(vb, tb)
        triangles = self.create_triangle_list(vb, tb)

        mesh.isect_asm([runtime], "ray_flat_mesh_intersection", ren.assembler, ren.structures)
        mc = ren.assembler.assemble(self.asm_code2(ren))
        ds = runtime.load("test", mc)

        for i in range(100):
            ray = self.random_ray()
            self.ray_ds(ds, ray, "ray1")
            self.flat_mesh_ds(ds, mesh, "mesh1")
            runtime.run("test")
            hp = mesh.isect(ray)
            if hp:
                print(hp.t)
                print(ds["hp1.t"])
            print(ds["ret"])
Ejemplo n.º 8
0
    def test1(self):
        mgr = ColorManager()

        sampler = RegularSampler(2, 2, pixel=1.0)
        tile = Tile(5, 5, 20, 20)
        tile.split(1)
        runtime = Runtime()

        sampler.get_sample_asm([runtime], "get_sample", mgr.assembler)
        mc = mgr.assembler.assemble(self.asm_code())
        ds = runtime.load('test', mc)

        sampler.set_tile(tile)

        while True:
            sample = sampler.get_sample()
            if sample is None:
                break

            runtime.run('test')
            self.sample_test(sample, ds)

        runtime.run('test')
        ret = ds['kraj']
        self.assertFalse(ret)
Ejemplo n.º 9
0
    def test_light_sample(self):
        runtime = Runtime()
        ren = renmas2.Renderer()
        factory = renmas2.Factory()
        rectangle = factory.create_rectangle(point=(0, 0, 55.92),
                                             e1=(55.28, 0, 0),
                                             e2=(0, 54.88, 0.0),
                                             normal=(0.0, 0.0, -1.0))

        ren.macro_call.set_runtimes([runtime])
        mc = rectangle.light_sample_asm('light_rect', ren.assembler,
                                        ren.structures)
        ds_rect = runtime.load('light_sample_name', mc)
        rectangle.populate_ds(ds_rect)

        mc = ren.assembler.assemble(self.asm_code1(ren))
        ds = runtime.load("test", mc)

        runtime.run("test")

        print(ds['hp.light_sample'])
        print(ds['hp.light_normal'])
        print(ds['hp.light_pdf'])

        normal = factory.vector(2.9, 1.2, 4.5)
        normal.normalize()
        hit_point = factory.vector(2.2, 3.3, 4.4)
        hp = renmas2.shapes.HitPoint(1.0, hit_point, normal, 0)
        rectangle.light_sample(hp)
        print(hp.light_sample)
        print(hp.light_normal)
        print(hp.light_pdf)
Ejemplo n.º 10
0
    def test_hemisphere_cos(self):
        factory = renmas2.Factory()
        ren = renmas2.Renderer()
        runtime = Runtime()

        mat1 = ren.shader.material("default")
        sam = renmas2.materials.HemisphereCos(1.5)
        mat1.add(sam)

        normal = factory.vector(2, 4, 5) 
        normal.normalize()
        hit_point = factory.vector(3, 5, 6)
        hp = renmas2.shapes.HitPoint(1.5, hit_point, normal, 0)

        ren.macro_call.set_runtimes([runtime])
        mat1.next_direction_asm([runtime], ren.structures, ren.assembler)
        mc = ren.assembler.assemble(self.asm_code1(ren))
        ds = runtime.load("test", mc)
        ds["next_dir_ptr"] = runtime.address_module(mat1.nd_asm_name)
        ds["hp.normal"] = (normal.x, normal.y, normal.z, 0.0)
        ds["hp.t"] = 1.5
        ds["hp.hit"] = (hit_point.x, hit_point.y, hit_point.z)
        runtime.run("test")

        print(ds['hp.wi'])
        print(ds['hp.ndotwi'])
        print(ds['hp.pdf'])
        
        mat1.next_direction(hp)
        print(hp.ndotwi)
        print(hp.wi)
        print(hp.pdf)
Ejemplo n.º 11
0
def intersect_ray_spheres_bool(n):
    asm = util.get_asm()
    mc = asm.assemble(ASM1)
    runtime = Runtime()
    
    #Sphere.intersectbool_asm(runtime, "ray_sphere_intersect")
    Sphere.intersect_asm(runtime, "ray_sphere_intersect")
    ds = runtime.load("test", mc)

    for x in range(n):
        sphere = generate_sphere()
        ray = generate_ray()
        ds["sph.origin"] = v4(sphere.origin)
        ds["sph.radius"] = sphere.radius
        ds["sph.mat_index"] = sphere.material

        ds["r1.origin"] = v4(ray.origin)
        ds["r1.dir"] = v4(ray.dir)

        hp = sphere.intersect(ray, 999999.0)
        
        runtime.run("test")
        
        if hp is not False and ds["hit"] == 0:
            print(hp.t, ds["t"], ds["hit"])
        if hp is False and ds["hit"] == 1:
            print(ds["t"], ds["hit"])

        if hp is not False:
            print_hitpoint(ds, hp)
Ejemplo n.º 12
0
    def test1(self):
        mgr = ColorManager()
        
        sampler = RandomSampler(2, 2, pixel=1.0)
        tile = Tile(0, 0, 3, 3)
        tile.split(1)
        runtime = Runtime()
        mgr.macro_call.set_runtimes([runtime])

        sampler.get_sample_asm([runtime], "get_sample", mgr.assembler)
        mc = mgr.assembler.assemble(self.asm_code())
        ds = runtime.load('test', mc)

        sampler.set_tile(tile)

        while True:
            sample = sampler.get_sample()
            if sample is None:
                break

            runtime.run('test')
            self.show_samples(sample, ds)
        
        runtime.run('test')
        ret = ds['kraj']
        self.assertFalse(ret)
Ejemplo n.º 13
0
    def test_sincos_ps(self):
        asm = Tdasm()
        mc = asm.assemble(SINCOS_CODE_PS)
        runtime = Runtime()
        load_math_func("fast_sincos_ps", runtime)
        ds = runtime.load("sincos_ps", mc)

        for x in range(1000):
            num1 = random.random() * 2000
            num2 = random.random() * 2000
            num3 = random.random() * 2000
            num4 = random.random() * 2000
            ds["v1"] = (num1, num2, num3, num4)
            runtime.run("sincos_ps")
            rez_asm_sin = ds["v1"]
            rez_asm_cos = ds["v2"]
            rez_py1_sin = math.sin(num1)
            rez_py2_sin = math.sin(num2)
            rez_py3_sin = math.sin(num3)
            rez_py4_sin = math.sin(num4)
            rez_py1_cos = math.cos(num1)
            rez_py2_cos = math.cos(num2)
            rez_py3_cos = math.cos(num3)
            rez_py4_cos = math.cos(num4)

            self.assertAlmostEqual(rez_asm_sin[0], rez_py1_sin, 3)
            self.assertAlmostEqual(rez_asm_sin[1], rez_py2_sin, 3)
            self.assertAlmostEqual(rez_asm_sin[2], rez_py3_sin, 3)
            self.assertAlmostEqual(rez_asm_sin[3], rez_py4_sin, 3)
            self.assertAlmostEqual(rez_asm_cos[0], rez_py1_cos, 3)
            self.assertAlmostEqual(rez_asm_cos[1], rez_py2_cos, 3)
            self.assertAlmostEqual(rez_asm_cos[2], rez_py3_cos, 3)
            self.assertAlmostEqual(rez_asm_cos[3], rez_py4_cos, 3)
Ejemplo n.º 14
0
def intersect_ray_spheres_bool(n):
    asm = util.get_asm()
    mc = asm.assemble(ASM1)
    runtime = Runtime()

    #Sphere.intersectbool_asm(runtime, "ray_sphere_intersect")
    Sphere.intersect_asm(runtime, "ray_sphere_intersect")
    ds = runtime.load("test", mc)

    for x in range(n):
        sphere = generate_sphere()
        ray = generate_ray()
        ds["sph.origin"] = v4(sphere.origin)
        ds["sph.radius"] = sphere.radius
        ds["sph.mat_index"] = sphere.material

        ds["r1.origin"] = v4(ray.origin)
        ds["r1.dir"] = v4(ray.dir)

        hp = sphere.intersect(ray, 999999.0)

        runtime.run("test")

        if hp is not False and ds["hit"] == 0:
            print(hp.t, ds["t"], ds["hit"])
        if hp is False and ds["hit"] == 1:
            print(ds["t"], ds["hit"])

        if hp is not False:
            print_hitpoint(ds, hp)
Ejemplo n.º 15
0
    def test_isect1(self):
        factory = renmas2.Factory()
        ren = renmas2.Renderer()
        runtime = Runtime()

        ply = renmas2.core.Ply()
        ply.load("I:/Ply_files/Horse97K.ply")
        vb = ply.vertex_buffer
        tb = ply.triangle_buffer
        mesh = factory.create_mesh(vb, tb)

        mesh.isect_asm([runtime], "ray_smooth_mesh_intersection", ren.assembler, ren.structures)
        mc = ren.assembler.assemble(self.asm_code1(ren))
        ds = runtime.load("test", mc)

        for i in range(1000):
            ray = self.random_ray()
            self.ray_ds(ds, ray, "ray1")
            self.smooth_mesh_ds(ds, mesh, "mesh1")
            runtime.run("test")
            hp = mesh.isect(ray)
            if hp:
                # print(hp.t, ds["hp1.t"])
                n1 = hp.normal
                n2 = ds["hp1.normal"]

                self.assertAlmostEqual(n1.x, n2[0], 3)
                self.assertAlmostEqual(n1.y, n2[1], 3)
                self.assertAlmostEqual(n1.z, n2[2], 3)
Ejemplo n.º 16
0
def test_clamp():
    mgr = ColorManager()
    ASM = "\n #DATA \n " + mgr.spectrum_struct() + """
    spectrum sp1
    float low =0.25
    float high = 0.35

    #CODE
    macro mov ebx, sp1
    macro eq32 xmm0 = low
    macro eq32 xmm1 = high
    macro spectrum clamp ebx
    #END
    """
    mc = mgr.assembler.assemble(ASM) 
    #mc.print_machine_code()
    runtime = Runtime()
    ds = runtime.load("test", mc)
    col = mgr.create_spectrum((0.3, 0.2, 0.4))
    ds['sp1.values'] = col.to_ds() 
    runtime.run('test')
    print(ds['sp1.values'])
    col.clamp(low=0.25, high=0.35)
    if col.sampled:
        print(col)
    else:
        print(col.r, col.g, col.b)
    pass
Ejemplo n.º 17
0
    def test_sincos_ps(self):
        asm = Tdasm()
        mc = asm.assemble(SINCOS_CODE_PS)
        runtime = Runtime()
        load_math_func("fast_sincos_ps", runtime)
        ds = runtime.load("sincos_ps", mc)

        for x in range(1000):
            num1 = random.random() * 2000
            num2 = random.random() * 2000
            num3 = random.random() * 2000
            num4 = random.random() * 2000
            ds["v1"] = (num1, num2, num3, num4) 
            runtime.run("sincos_ps")
            rez_asm_sin = ds["v1"]
            rez_asm_cos = ds["v2"]
            rez_py1_sin = math.sin(num1)
            rez_py2_sin = math.sin(num2)
            rez_py3_sin = math.sin(num3)
            rez_py4_sin = math.sin(num4)
            rez_py1_cos = math.cos(num1)
            rez_py2_cos = math.cos(num2)
            rez_py3_cos = math.cos(num3)
            rez_py4_cos = math.cos(num4)

            self.assertAlmostEqual(rez_asm_sin[0], rez_py1_sin, 3)
            self.assertAlmostEqual(rez_asm_sin[1], rez_py2_sin, 3)
            self.assertAlmostEqual(rez_asm_sin[2], rez_py3_sin, 3)
            self.assertAlmostEqual(rez_asm_sin[3], rez_py4_sin, 3)
            self.assertAlmostEqual(rez_asm_cos[0], rez_py1_cos, 3)
            self.assertAlmostEqual(rez_asm_cos[1], rez_py2_cos, 3)
            self.assertAlmostEqual(rez_asm_cos[2], rez_py3_cos, 3)
            self.assertAlmostEqual(rez_asm_cos[3], rez_py4_cos, 3)
Ejemplo n.º 18
0
    def test_transmission_sampling(self):
        factory = renmas2.Factory()
        ren = renmas2.Renderer()
        runtime = Runtime()

        mat = renmas2.core.material.Material(ren.converter.zero_spectrum())
        eta_in = 1.3
        eta_out = 1.0
        sampling = renmas2.materials.PerfectTransmissionSampling(eta_in, eta_out)
        mat.add(sampling)

        eta_in = ren.converter.zero_spectrum().set(1.3)
        eta_out = ren.converter.zero_spectrum().set(1.0)
        fresnel = renmas2.materials.FresnelDielectric(eta_in, eta_out) 
        spec = ren.converter.create_spectrum((0.5, 0.5, 0.5))

        perf_spec = renmas2.materials.PerfectTransmission(spec, fresnel, 1.0)
        mat.add(perf_spec)

        ref_sam = renmas2.materials.PerfectSpecularSampling()
        mat.add(ref_sam)

        spec2 = ren.converter.create_spectrum((0.9, 0.9, 0.9))
        fresnel2 = renmas2.materials.FresnelDielectric(eta_in, eta_out) 
        perf_ref = renmas2.materials.PerfectSpecular(spec2, fresnel2, 1.0)
        mat.add(perf_ref)

        normal = factory.vector(2, 4.5, 5) 
        normal.normalize()
        hit_point = factory.vector(3, 5, 6)
        wo = factory.vector(-2, 1, 0)
        wo.normalize()
        hp = renmas2.shapes.HitPoint(1.5, hit_point, normal, 0)
        hp.wo = wo
        hp.fliped = False 

        ren.macro_call.set_runtimes([runtime])
        mat.next_direction_bsdf_asm([runtime], ren.structures, ren.assembler)
        mc = ren.assembler.assemble(self.asm_code1(ren))
        ds = runtime.load("test", mc)

        ds["next_dir_ptr"] = runtime.address_module(mat.nd_asm_name)
        ds["hp.normal"] = (normal.x, normal.y, normal.z, 0.0)
        ds["hp.t"] = 1.5
        ds["hp.hit"] = (hit_point.x, hit_point.y, hit_point.z, 0.0)
        ds["hp.wo"] = (wo.x, wo.y, wo.z, 0.0)
        ds["hp.fliped"] = 0
        runtime.run("test")

        mat.next_direction_bsdf(hp)
        print ("Python")
        print (hp.wi)
        print (hp.ndotwi)
        print (hp.specular)
        print (hp.f_spectrum)
        print ("ASM")
        print (ds["hp.wi"])
        print (ds["hp.ndotwi"])
        print (ds["hp.specular"])
        print (ds["hp.f_spectrum.values"])
Ejemplo n.º 19
0
    def test_hemisphere_cos(self):
        factory = renmas2.Factory()
        ren = renmas2.Renderer()
        runtime = Runtime()

        spec = ren.converter.create_spectrum((0.2, 0.3, 0.1))
        mat1 = renmas2.core.material.Material(ren.converter.zero_spectrum())
        phong = factory.create_phong(spec, 2.0)
        lam_sampling = renmas2.materials.LambertianSampling()
        mat1.add(phong)
        mat1.add(lam_sampling)

        normal = factory.vector(2, 4, 5)
        normal.normalize()
        hit_point = factory.vector(3, 5, 6)
        hp = renmas2.shapes.HitPoint(1.5, hit_point, normal, 0)

        ren.macro_call.set_runtimes([runtime])
        mat1.next_direction_asm([runtime], ren.structures, ren.assembler)
        mc = ren.assembler.assemble(self.asm_code1(ren))
        ds = runtime.load("test", mc)
        ds["next_dir_ptr"] = runtime.address_module(mat1.nd_asm_name)
        ds["hp.normal"] = (normal.x, normal.y, normal.z, 0.0)
        ds["hp.t"] = 1.5
        ds["hp.hit"] = (hit_point.x, hit_point.y, hit_point.z)
        runtime.run("test")

        print(ds['hp.wi'])
        print(ds['hp.ndotwi'])
        print(ds['hp.pdf'])

        mat1.next_direction(hp)
        print(hp.ndotwi)
        print(hp.wi)
        print(hp.pdf)
Ejemplo n.º 20
0
    def test1(self):
        mgr = ColorManager()
        
        sampler = RegularSampler(2, 2, pixel=1.0)
        tile = Tile(5, 5, 20, 20)
        tile.split(1)
        runtime = Runtime()

        sampler.get_sample_asm([runtime], "get_sample", mgr.assembler)
        mc = mgr.assembler.assemble(self.asm_code())
        ds = runtime.load('test', mc)

        sampler.set_tile(tile)

        while True:
            sample = sampler.get_sample()
            if sample is None:
                break

            runtime.run('test')
            self.sample_test(sample, ds)
        
        runtime.run('test')
        ret = ds['kraj']
        self.assertFalse(ret)
Ejemplo n.º 21
0
    def test_light_sample(self):
        runtime = Runtime()
        ren = renmas2.Renderer()
        factory = renmas2.Factory()
        rectangle = factory.create_rectangle(point=(0,0,55.92), e1=(55.28,0,0), e2=(0,54.88,0.0), normal=(0.0,0.0,-1.0))

        ren.macro_call.set_runtimes([runtime])
        mc = rectangle.light_sample_asm('light_rect', ren.assembler, ren.structures)
        ds_rect = runtime.load('light_sample_name', mc)
        rectangle.populate_ds(ds_rect)

        mc = ren.assembler.assemble(self.asm_code1(ren))
        ds = runtime.load("test", mc) 

        runtime.run("test")

        print(ds['hp.light_sample'])
        print(ds['hp.light_normal'])
        print(ds['hp.light_pdf'])

        normal = factory.vector(2.9, 1.2, 4.5)
        normal.normalize()
        hit_point = factory.vector(2.2, 3.3, 4.4)
        hp = renmas2.shapes.HitPoint(1.0, hit_point, normal, 0)
        rectangle.light_sample(hp)
        print(hp.light_sample)
        print(hp.light_normal)
        print(hp.light_pdf)
Ejemplo n.º 22
0
    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"])
Ejemplo n.º 23
0
    def test_addsample(self):
        ren = renmas2.Renderer()
        runtime = Runtime()

        #ren.spectrum_rendering = True
        ren.film.nsamples = 2
        ren.prepare()
        ren.converter.to_rgb_asm("spectrum_to_rgb", [runtime])
        ren.film.add_sample_asm([runtime], "add_sample", "spectrum_to_rgb")
        mc = ren.assembler.assemble(self.asm_code(ren))
        ds = runtime.load("test", mc)

        ds["sp1.ix"] = 10
        ds["sp1.iy"] = 10
        ds["sp1.xyxy"] = (10.4, 10.4, 10.4, 10.4)
        sample = renmas2.samplers.Sample(10.4, 10.4, 10, 10, 0.5)
        spec = ren.converter.create_spectrum((0.70, 0.2, 0.3))
        ren.film.add_sample(sample, spec)
        ds["spec1.values"] = spec.to_ds()
        runtime.run("test")

        ds["sp1.ix"] = 15
        ds["sp1.iy"] = 19
        ds["sp1.xyxy"] = (15.7, 19.4, 15.7, 19.4)
        sample = renmas2.samplers.Sample(10.4, 10.4, 15, 19, 0.5)
        spec = ren.converter.create_spectrum((0.50, 0.4, 0.1))
        ren.film.add_sample(sample, spec)
        ds["spec1.values"] = spec.to_ds()
        runtime.run("test")

        print(ren.film._ds[0]["temp"])
Ejemplo n.º 24
0
    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"])
Ejemplo n.º 25
0
    def test_isect_b(self):
        point = Vector3(0.0, 0.0, 55.92)
        e1 = Vector3(55.28, 0.0, 0.0)
        e2 = Vector3(0.0, 54.88, 0.0)
        normal = Vector3(0.0, 0.0, -1.0)
        rectangle = Rectangle(point, e1, e2, normal)

        origin = Vector3(3.0, 2.5, 0.0)
        direction = Vector3(0.0, 0.1, 0.88)
        direction.normalize()
        ray = Ray(origin, direction)

        runtime = Runtime()
        rectangle.isect_asm_b([runtime], "ray_rectangle_intersection")

        assembler = create_assembler()
        mc = assembler.assemble(self.asm_code_bool())
        ds = runtime.load("test", mc)

        Ray.populate_ds(ds, ray, 'ray1')
        Rectangle.populate_ds(ds, rectangle, 'rec1')

        runtime.run("test")
        hp = rectangle.isect(ray)

        if hp is False: self.assertFalse(ds["ret"] != 0)
        if ds["ret"] == 0: self.assertFalse(hp)
Ejemplo n.º 26
0
    def test_hemisphere_cos(self):
        factory = renmas2.Factory()
        ren = renmas2.Renderer()
        runtime = Runtime()

        mat1 = ren.shader.material("default")
        sam = renmas2.materials.HemisphereCos(1.5)
        mat1.add(sam)

        normal = factory.vector(2, 4, 5)
        normal.normalize()
        hit_point = factory.vector(3, 5, 6)
        hp = renmas2.shapes.HitPoint(1.5, hit_point, normal, 0)

        ren.macro_call.set_runtimes([runtime])
        mat1.next_direction_asm([runtime], ren.structures, ren.assembler)
        mc = ren.assembler.assemble(self.asm_code1(ren))
        ds = runtime.load("test", mc)
        ds["next_dir_ptr"] = runtime.address_module(mat1.nd_asm_name)
        ds["hp.normal"] = (normal.x, normal.y, normal.z, 0.0)
        ds["hp.t"] = 1.5
        ds["hp.hit"] = (hit_point.x, hit_point.y, hit_point.z)
        runtime.run("test")

        print(ds['hp.wi'])
        print(ds['hp.ndotwi'])
        print(ds['hp.pdf'])

        mat1.next_direction(hp)
        print(hp.ndotwi)
        print(hp.wi)
        print(hp.pdf)
Ejemplo n.º 27
0
    def test_isect_b(self):
        point = Vector3(0.0, 0.0, 55.92)
        e1 = Vector3(55.28, 0.0, 0.0)
        e2 = Vector3(0.0, 54.88, 0.0)
        normal = Vector3(0.0, 0.0, -1.0)
        rectangle = Rectangle(point, e1, e2, normal)

        origin = Vector3(3.0, 2.5, 0.0)
        direction = Vector3(0.0, 0.1, 0.88)
        direction.normalize()
        ray = Ray(origin, direction)

        runtime = Runtime()
        rectangle.isect_asm_b([runtime], "ray_rectangle_intersection")

        assembler = create_assembler()
        mc = assembler.assemble(self.asm_code_bool())
        ds = runtime.load("test", mc)

        Ray.populate_ds(ds, ray, 'ray1')
        Rectangle.populate_ds(ds, rectangle, 'rec1')

        runtime.run("test")
        hp = rectangle.isect(ray)

        if hp is False: self.assertFalse(ds["ret"]!=0)
        if ds["ret"] == 0: self.assertFalse(hp)
Ejemplo n.º 28
0
    def test_phong1(self):
        factory = renmas2.Factory()
        ren = renmas2.Renderer()
        runtime = Runtime()
        mat = renmas2.core.material.Material(ren.converter.zero_spectrum())
        spec = ren.converter.create_spectrum((0.2, 0.3, 0.1))
        ren.macro_call.set_runtimes([runtime])

        phong = factory.create_phong(spec, 2.0)
        mat.add(phong)
        t = 2.3
        hit_point = factory.vector(2.2, 3.1, 4.4)
        normal = factory.vector(2.9, 1.2, 4.5)
        normal.normalize()
        ray = factory.create_ray(origin=(4, 4, 4), direction=(6, 7, 8))

        hp = renmas2.shapes.HitPoint(t, hit_point, normal, 0, ray)
        wi = factory.vector(-6, 8, -3.8)
        wi.normalize()
        hp.wo = ray.dir * -1.0
        hp.wi = wi
        hp.ndotwi = normal.dot(wi)

        mat.f_asm([runtime], ren.assembler, ren.structures)
        mc = ren.assembler.assemble(self.asm_code1(ren))
        ds = runtime.load("test", mc)
        self.populate_ds(ds, hp)
        ds["brdf_ptr"] = runtime.address_module(mat.f_asm_name)
        runtime.run("test")

        spectrum = mat.f(hp)
        print(spectrum)
        print(ds["hp.f_spectrum.values"])
Ejemplo n.º 29
0
    def test_phong1(self):
        factory = renmas2.Factory()
        ren = renmas2.Renderer()
        runtime = Runtime()
        mat = renmas2.core.material.Material(ren.converter.zero_spectrum())
        spec = ren.converter.create_spectrum((0.2, 0.3, 0.1))
        ren.macro_call.set_runtimes([runtime])

        phong = factory.create_phong(spec, 2.0) 
        mat.add(phong)
        t = 2.3
        hit_point = factory.vector(2.2, 3.1, 4.4)
        normal = factory.vector(2.9, 1.2, 4.5)
        normal.normalize()
        ray = factory.create_ray(origin=(4,4,4), direction=(6,7,8))

        hp = renmas2.shapes.HitPoint(t, hit_point, normal, 0, ray)
        wi = factory.vector(-6,8,-3.8)
        wi.normalize()
        hp.wo = ray.dir * -1.0
        hp.wi = wi
        hp.ndotwi = normal.dot(wi)

        mat.f_asm([runtime], ren.assembler, ren.structures)
        mc = ren.assembler.assemble(self.asm_code1(ren))
        ds = runtime.load("test", mc)
        self.populate_ds(ds, hp)
        ds["brdf_ptr"] = runtime.address_module(mat.f_asm_name)
        runtime.run("test")

        spectrum = mat.f(hp)
        print(spectrum)
        print(ds["hp.f_spectrum.values"])
Ejemplo n.º 30
0
    def test_hemisphere_cos(self):
        factory = renmas2.Factory()
        ren = renmas2.Renderer()
        runtime = Runtime()

        spec = ren.converter.create_spectrum((0.2, 0.3, 0.1))
        mat1 = renmas2.core.material.Material(ren.converter.zero_spectrum())
        phong = factory.create_phong(spec, 2.0) 
        lam_sampling = renmas2.materials.LambertianSampling()
        mat1.add(phong)
        mat1.add(lam_sampling)

        normal = factory.vector(2, 4, 5) 
        normal.normalize()
        hit_point = factory.vector(3, 5, 6)
        hp = renmas2.shapes.HitPoint(1.5, hit_point, normal, 0)

        ren.macro_call.set_runtimes([runtime])
        mat1.next_direction_asm([runtime], ren.structures, ren.assembler)
        mc = ren.assembler.assemble(self.asm_code1(ren))
        ds = runtime.load("test", mc)
        ds["next_dir_ptr"] = runtime.address_module(mat1.nd_asm_name)
        ds["hp.normal"] = (normal.x, normal.y, normal.z, 0.0)
        ds["hp.t"] = 1.5
        ds["hp.hit"] = (hit_point.x, hit_point.y, hit_point.z)
        runtime.run("test")

        print(ds['hp.wi'])
        print(ds['hp.ndotwi'])
        print(ds['hp.pdf'])
        
        mat1.next_direction(hp)
        print(hp.ndotwi)
        print(hp.wi)
        print(hp.pdf)
Ejemplo n.º 31
0
    def test1(self):
        mgr = ColorManager()

        sampler = RandomSampler(2, 2, pixel=1.0)
        tile = Tile(0, 0, 3, 3)
        tile.split(1)
        runtime = Runtime()
        mgr.macro_call.set_runtimes([runtime])

        sampler.get_sample_asm([runtime], "get_sample", mgr.assembler)
        mc = mgr.assembler.assemble(self.asm_code())
        ds = runtime.load('test', mc)

        sampler.set_tile(tile)

        while True:
            sample = sampler.get_sample()
            if sample is None:
                break

            runtime.run('test')
            self.show_samples(sample, ds)

        runtime.run('test')
        ret = ds['kraj']
        self.assertFalse(ret)
Ejemplo n.º 32
0
    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)
Ejemplo n.º 33
0
    def test_pow_ps(self):
        asm = Tdasm()
        mc = asm.assemble(POW_CODE_PS)
        runtime = Runtime()
        load_math_func("fast_pow_ps", runtime)
        ds = runtime.load("pow_ps", mc)

        for x in range(1000):
            num1 = random.random() * 3
            num2 = random.random() * 3
            num3 = random.random() * 3
            num4 = random.random() * 3
            num5 = random.random() * 3
            num6 = random.random() * 3
            num7 = random.random() * 3
            num8 = random.random() * 3
            ds["v1"] = (num1, num2, num3, num4)
            ds["v2"] = (num5, num6, num7, num8)
            runtime.run("pow_ps")
            rez_asm = ds["v1"]
            rez_py1 = math.pow(num1, num5)
            rez_py2 = math.pow(num2, num6)
            rez_py3 = math.pow(num3, num7)
            rez_py4 = math.pow(num4, num8)

            self.assertAlmostEqual(rez_asm[0], rez_py1, 1)
            self.assertAlmostEqual(rez_asm[1], rez_py2, 1)
            self.assertAlmostEqual(rez_asm[2], rez_py3, 1)
            self.assertAlmostEqual(rez_asm[3], rez_py4, 1)
Ejemplo n.º 34
0
    def test_transmission_sampling(self):
        factory = renmas2.Factory()
        ren = renmas2.Renderer()
        runtime = Runtime()

        mat = renmas2.core.material.Material(ren.converter.zero_spectrum())
        eta_in = 1.3
        eta_out = 1.0
        sampling = renmas2.materials.PerfectTransmissionSampling(
            eta_in, eta_out)
        mat.add(sampling)

        eta_in = ren.converter.zero_spectrum().set(1.3)
        eta_out = ren.converter.zero_spectrum().set(1.0)
        fresnel = renmas2.materials.FresnelDielectric(eta_in, eta_out)
        spec = ren.converter.create_spectrum((0.5, 0.5, 0.5))

        perf_spec = renmas2.materials.PerfectTransmission(spec, fresnel, 1.0)
        mat.add(perf_spec)

        normal = factory.vector(2, 4.5, 5)
        normal.normalize()
        hit_point = factory.vector(3, 5, 6)
        wo = factory.vector(-2, 1, 0)
        wo.normalize()
        hp = renmas2.shapes.HitPoint(1.5, hit_point, normal, 0)
        hp.wo = wo
        hp.fliped = False

        ren.macro_call.set_runtimes([runtime])
        mat.next_direction_btdf_asm([runtime], ren.structures, ren.assembler)
        mc = ren.assembler.assemble(self.asm_code1(ren))
        ds = runtime.load("test", mc)

        ds["next_dir_ptr"] = runtime.address_module(mat.nd_asm_name)
        ds["hp.normal"] = (normal.x, normal.y, normal.z, 0.0)
        ds["hp.t"] = 1.5
        ds["hp.hit"] = (hit_point.x, hit_point.y, hit_point.z, 0.0)
        ds["hp.wo"] = (wo.x, wo.y, wo.z, 0.0)
        ds["hp.fliped"] = 0
        runtime.run("test")

        mat.next_direction_btdf(hp)
        print("Python")
        print(hp.wi)
        print(hp.ndotwi)
        print(hp.specular)
        print(hp.f_spectrum)
        print("ASM")
        print(ds["hp.wi"])
        print(ds["hp.ndotwi"])
        print(ds["hp.specular"])
        print(ds["hp.f_spectrum.values"])
Ejemplo n.º 35
0
    def test_Y_rgb(self):
        mgr = ColorManager(False)
        runtime = Runtime()

        mgr.Y_asm([runtime], 'luminance')
        spec1 = mgr.create_spectrum((0.66,0.88, 0.11))

        mc = create_assembler().assemble(self.asm_code1(mgr))
        ds = runtime.load("test", mc)
        ds["sp1.values"] = spec1.to_ds()
        runtime.run("test")
        
        self.assertAlmostEqual(mgr.Y(spec1), ds["Y"], 4)
Ejemplo n.º 36
0
    def test_Y_rgb(self):
        mgr = ColorManager(False)
        runtime = Runtime()

        mgr.Y_asm([runtime], 'luminance')
        spec1 = mgr.create_spectrum((0.66, 0.88, 0.11))

        mc = create_assembler().assemble(self.asm_code1(mgr))
        ds = runtime.load("test", mc)
        ds["sp1.values"] = spec1.to_ds()
        runtime.run("test")

        self.assertAlmostEqual(mgr.Y(spec1), ds["Y"], 4)
Ejemplo n.º 37
0
    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)
Ejemplo n.º 38
0
    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)
Ejemplo n.º 39
0
    def test_atan(self):
        asm = Tdasm()
        mc = asm.assemble(ATAN_CODE)
        runtime = Runtime()
        load_math_func("fast_atan_ss", runtime)
        ds = runtime.load("atan", mc)

        for x in range(1000):
            num = random.random() * 2000
            ds["x"] = num 
            runtime.run("atan")
            rez_asm = ds["x"]
            rez_py = math.atan(num)
            self.assertAlmostEqual(rez_asm, rez_py, 3)
Ejemplo n.º 40
0
    def test_exp(self):
        asm = Tdasm()
        mc = asm.assemble(EXP_CODE)
        runtime = Runtime()
        load_math_func("fast_exp_ss", runtime)
        ds = runtime.load("exp", mc)

        for x in range(1000):
            num = random.random() * 4 
            ds["x"] = num 
            runtime.run("exp")
            rez_asm = ds["x"]
            rez_py = math.exp(num)
            self.assertAlmostEqual(rez_asm, rez_py, 2)
Ejemplo n.º 41
0
    def test_exp(self):
        asm = Tdasm()
        mc = asm.assemble(EXP_CODE)
        runtime = Runtime()
        load_math_func("fast_exp_ss", runtime)
        ds = runtime.load("exp", mc)

        for x in range(1000):
            num = random.random() * 4
            ds["x"] = num
            runtime.run("exp")
            rez_asm = ds["x"]
            rez_py = math.exp(num)
            self.assertAlmostEqual(rez_asm, rez_py, 2)
Ejemplo n.º 42
0
    def test_log(self):
        asm = Tdasm()
        mc = asm.assemble(LOG_CODE)
        runtime = Runtime()
        load_math_func("fast_log_ss", runtime)
        ds = runtime.load("log", mc)

        for x in range(1000):
            num = random.random()
            ds["x"] = num
            runtime.run("log")
            rez_asm = ds["x"]
            rez_py = math.log(num)
            self.assertAlmostEqual(rez_asm, rez_py, 3)
Ejemplo n.º 43
0
    def test_atan(self):
        asm = Tdasm()
        mc = asm.assemble(ATAN_CODE)
        runtime = Runtime()
        load_math_func("fast_atan_ss", runtime)
        ds = runtime.load("atan", mc)

        for x in range(1000):
            num = random.random() * 2000
            ds["x"] = num
            runtime.run("atan")
            rez_asm = ds["x"]
            rez_py = math.atan(num)
            self.assertAlmostEqual(rez_asm, rez_py, 3)
Ejemplo n.º 44
0
    def test_log(self):
        asm = Tdasm()
        mc = asm.assemble(LOG_CODE)
        runtime = Runtime()
        load_math_func("fast_log_ss", runtime)
        ds = runtime.load("log", mc)

        for x in range(1000):
            num = random.random()  
            ds["x"] = num 
            runtime.run("log")
            rez_asm = ds["x"]
            rez_py = math.log(num)
            self.assertAlmostEqual(rez_asm, rez_py, 3)
Ejemplo n.º 45
0
    def Atest_isect1(self):
        factory = renmas2.Factory()
        ren = renmas2.Renderer()
        runtime = Runtime()

        ply = renmas2.core.Ply()
        ply.load("I:/Ply_files/cube.ply")
        #ply.load("I:/Ply_files/dragon_vrip.ply")
        #ply.load("I:/Ply_files/xyzrgb_dragon.ply")
        #ply.load("I:/Ply_files/lucy.ply")
        vb = ply._vertex_buffer
        tb = ply._triangle_buffer
        mesh = factory.create_mesh(vb, tb)
        triangles = self.create_triangle_list(vb, tb)

        #self.intersection_tests(10, triangles, mesh)

        mesh._isect_triangles_asm([runtime], "ray_triangles_idx",
                                  ren.assembler, ren.structures)
        mc = ren.assembler.assemble(self.asm_code1(ren))
        ds = runtime.load("test", mc)

        ray = self.random_ray()
        self.ray_ds(ds, ray, "ray1")
        self.flat_mesh_ds(ds, mesh, "mesh1")
        addr = mesh._grid._get_addr_in_array(0, 1, 2)
        print(addr)
        ds["ptr_triangles_arr"] = addr

        ntri = x86.GetUInt32(addr, 0, 0)
        triangles = x86.GetUInt32(addr + 4, 0, ntri)
        hp = mesh.isect_triangles(ray, triangles)
        print(hp)
        if hp:
            print("t=", hp.t)
            print("hit=", hp.hit_point)
            print("normala=", hp.normal)
        print(ntri)
        print(triangles)
        runtime.run("test")
        print("ret", ds["ret"])
        print("t= ", ds["t"])
        print("hit=", ds["hit"])
        print("normala", ds["normal"])

        start = time.clock()
        #self.speed_test(20, triangles, mesh)
        end = time.clock()
Ejemplo n.º 46
0
    def test_pow(self):
        asm = Tdasm()
        mc = asm.assemble(POW_CODE)
        runtime = Runtime()
        load_math_func("fast_pow_ss", runtime)
        ds = runtime.load("pow", mc)

        for x in range(1000):
            num = random.random() * 3 
            num1 = random.random() * 3 
            ds["x"] = num 
            ds["y"] = num1 
            runtime.run("pow")
            rez_asm = ds["x"]
            rez_py = math.pow(num, num1)
            self.assertAlmostEqual(rez_asm, rez_py, 1)
Ejemplo n.º 47
0
    def test_lamb1(self):
        factory = renmas2.Factory()
        ren = renmas2.Renderer()
        runtime = Runtime()
        mat = renmas2.core.material.Material(ren.converter.zero_spectrum())

        #mat.f_asm([runtime], ren.assembler, ren.structures)

        mat1 = ren.shader.material("default")
        mat1.f_asm([runtime], ren.assembler, ren.structures)

        mc = ren.assembler.assemble(self.asm_code1(ren))
        ds = runtime.load("test", mc)
        ds["brdf_ptr"] = runtime.address_module(mat1.f_asm_name)
        runtime.run("test")
        print(ds["hp.f_spectrum.values"])
Ejemplo n.º 48
0
    def test_Y(self):
        factory = renmas2.Factory()
        ren = renmas2.Renderer()
        runtime = Runtime()

        ren.spectral_rendering = True
        conv = ren.converter
        conv.Y_asm("lumminance", [runtime])
        spec1 = conv.create_spectrum((0.66, 0.88, 0.11))

        mc = ren.assembler.assemble(self.asm_code1(ren))
        ds = runtime.load("test", mc)
        ds["sp1.values"] = spec1.to_ds()
        runtime.run("test")

        self.assertAlmostEqual(conv.Y(spec1), ds["Y"], 4)
Ejemplo n.º 49
0
    def test_lamb1(self):
        factory = renmas2.Factory()
        ren = renmas2.Renderer()
        runtime = Runtime()
        mat = renmas2.core.material.Material(ren.converter.zero_spectrum())

        #mat.f_asm([runtime], ren.assembler, ren.structures)

        mat1 = ren.shader.material("default")
        mat1.f_asm([runtime], ren.assembler, ren.structures)

        mc = ren.assembler.assemble(self.asm_code1(ren))
        ds = runtime.load("test", mc)
        ds["brdf_ptr"] = runtime.address_module(mat1.f_asm_name)
        runtime.run("test")
        print(ds["hp.f_spectrum.values"])
Ejemplo n.º 50
0
    def test_chromacity_to_spectrum2(self):
        mgr = ColorManager(spectral=True)
        runtime = Runtime()

        mgr.chromacity_to_spectrum_asm([runtime], 'chromacity_to_spectrum')
        mc = create_assembler().assemble(self.asm_code1(mgr))
        ds = runtime.load("test", mc)
        ds['x'] = 0.45
        ds['y'] = 0.41

        spec = mgr.chromacity_to_spectrum(0.45, 0.41)
        runtime.run("test")

        vals = ds['sp1.values']
        for i in range(len(vals)):
            self.assertAlmostEqual(vals[i], spec.samples[i], 4)
Ejemplo n.º 51
0
    def test_Y(self):
        mgr = ColorManager(False)
        runtime = Runtime()

        mgr.XYZ_to_RGB_asm([runtime], 'XYZ_to_RGB')
        mc = create_assembler().assemble(self.asm_code1())
        ds = runtime.load("test", mc)

        ds["XYZ"] = (0.69, 0.78, 0.88, 0.00)
        runtime.run("test")
        ret1 = ds["RGB"]
        ret2 = mgr.XYZ_to_RGB(0.69, 0.78, 0.88)

        self.assertAlmostEqual(ret1[0], ret2[0], 4)
        self.assertAlmostEqual(ret1[1], ret2[1], 4)
        self.assertAlmostEqual(ret1[2], ret2[2], 4)
Ejemplo n.º 52
0
    def test_Y(self):
        factory = renmas2.Factory()
        ren = renmas2.Renderer()
        runtime = Runtime()

        ren.spectral_rendering = True
        conv = ren.converter
        conv.Y_asm("lumminance", [runtime])
        spec1 = conv.create_spectrum((0.66, 0.88, 0.11))

        mc = ren.assembler.assemble(self.asm_code1(ren))
        ds = runtime.load("test", mc)
        ds["sp1.values"] = spec1.to_ds()
        runtime.run("test")

        self.assertAlmostEqual(conv.Y(spec1), ds["Y"], 4)
Ejemplo n.º 53
0
    def test_Y(self):
        mgr = ColorManager(False)
        runtime = Runtime()

        mgr.XYZ_to_RGB_asm([runtime], 'XYZ_to_RGB')
        mc = create_assembler().assemble(self.asm_code1())
        ds = runtime.load("test", mc)

        ds["XYZ"] = (0.69, 0.78, 0.88, 0.00)
        runtime.run("test")
        ret1 = ds["RGB"]
        ret2 = mgr.XYZ_to_RGB(0.69, 0.78, 0.88)

        self.assertAlmostEqual(ret1[0], ret2[0], 4)
        self.assertAlmostEqual(ret1[1], ret2[1], 4)
        self.assertAlmostEqual(ret1[2], ret2[2], 4)
Ejemplo n.º 54
0
    def test_pow(self):
        asm = Tdasm()
        mc = asm.assemble(POW_CODE)
        runtime = Runtime()
        load_math_func("fast_pow_ss", runtime)
        ds = runtime.load("pow", mc)

        for x in range(1000):
            num = random.random() * 3
            num1 = random.random() * 3
            ds["x"] = num
            ds["y"] = num1
            runtime.run("pow")
            rez_asm = ds["x"]
            rez_py = math.pow(num, num1)
            self.assertAlmostEqual(rez_asm, rez_py, 1)
Ejemplo n.º 55
0
    def Atest_isect1(self):
        factory = renmas2.Factory()
        ren = renmas2.Renderer()
        runtime = Runtime()

        ply = renmas2.core.Ply()
        ply.load("I:/Ply_files/cube.ply")
        #ply.load("I:/Ply_files/dragon_vrip.ply")
        #ply.load("I:/Ply_files/xyzrgb_dragon.ply")
        #ply.load("I:/Ply_files/lucy.ply")
        vb = ply._vertex_buffer
        tb = ply._triangle_buffer
        mesh = factory.create_mesh(vb, tb)
        triangles = self.create_triangle_list(vb, tb)

        #self.intersection_tests(10, triangles, mesh)

        mesh._isect_triangles_asm([runtime], "ray_triangles_idx", ren.assembler, ren.structures)
        mc = ren.assembler.assemble(self.asm_code1(ren))
        ds = runtime.load("test", mc)

        ray = self.random_ray()
        self.ray_ds(ds, ray, "ray1")
        self.flat_mesh_ds(ds, mesh, "mesh1")
        addr = mesh._grid._get_addr_in_array(0, 1, 2)
        print(addr)
        ds["ptr_triangles_arr"] = addr

        ntri = x86.GetUInt32(addr, 0, 0)
        triangles = x86.GetUInt32(addr+4, 0, ntri)
        hp = mesh.isect_triangles(ray, triangles)
        print(hp)
        if hp:
            print ("t=",hp.t)
            print ("hit=", hp.hit_point)
            print ("normala=", hp.normal)
        print(ntri)
        print(triangles)
        runtime.run("test")
        print("ret", ds["ret"])
        print("t= ", ds["t"])
        print("hit=", ds["hit"])
        print("normala", ds["normal"])

        start = time.clock()
        #self.speed_test(20, triangles, mesh)
        end = time.clock()
Ejemplo n.º 56
0
    def test_sincos(self):
        asm = Tdasm()
        mc = asm.assemble(SINCOS_CODE)
        runtime = Runtime()
        load_math_func("fast_sincos_ss", runtime)
        ds = runtime.load("sincos", mc)

        for x in range(1000):
            num = random.random() * 2000
            ds["x"] = num 
            runtime.run("sincos")
            rez_asm1 = ds["x"]
            rez_asm2 = ds["y"]

            rez_py1, rez_py2 = math.sin(num), math.cos(num)
            self.assertAlmostEqual(rez_asm1, rez_py1, 3)
            self.assertAlmostEqual(rez_asm2, rez_py2, 3)
Ejemplo n.º 57
0
    def test_spectrum_to_rgb2(self):
        mgr = ColorManager(spectral=True)
        runtime = Runtime()

        mgr.rgb_to_sampled_asm([runtime], 'rgb_to_spectrum')
        spec1 = mgr.create_spectrum((0.66,0.88, 0.11))

        mc = create_assembler().assemble(self.asm_code1(mgr))
        ds = runtime.load("test", mc)

        ds["rgb"] = (0.66, 0.88, 0.11, 0.00)
        runtime.run("test")
        
        vals = ds['sp1.values']
        
        for i in range(len(vals)):
            self.assertAlmostEqual(vals[i], spec1.samples[i], 4)
Ejemplo n.º 58
0
    def test_sincos(self):
        asm = Tdasm()
        mc = asm.assemble(SINCOS_CODE)
        runtime = Runtime()
        load_math_func("fast_sincos_ss", runtime)
        ds = runtime.load("sincos", mc)

        for x in range(1000):
            num = random.random() * 2000
            ds["x"] = num
            runtime.run("sincos")
            rez_asm1 = ds["x"]
            rez_asm2 = ds["y"]

            rez_py1, rez_py2 = math.sin(num), math.cos(num)
            self.assertAlmostEqual(rez_asm1, rez_py1, 3)
            self.assertAlmostEqual(rez_asm2, rez_py2, 3)