コード例 #1
0
    def test_isect_b_rect(self):
        rect_shader = Rectangle.isect_b_shader('isect_b_rectangle')
        rect_shader.compile()
        runtimes = [Runtime()]
        rect_shader.prepare(runtimes)

        code = """
min_dist = 99999.0
p1 = isect_b_rectangle(ray, rectangle, min_dist)
        """

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

        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)

        r_arg = StructArg('ray', ray)
        sph_arg = StructArg('rectangle', rectangle)
        p1 = IntArg('p1', 6)

        args = [r_arg, sph_arg, p1]
        shader = Shader(code=code, args=args)
        shader.compile([rect_shader.shader])

        shader.prepare(runtimes)
        shader.execute()

        result = shader.get_value('p1')
        self.assertEqual(result, 1)
コード例 #2
0
    def test_isect_rect(self):
        rect_shader = Rectangle.isect_shader('isect_rectangle')
        rect_shader.compile()
        runtimes = [Runtime()]
        rect_shader.prepare(runtimes)

        code = """
min_dist = 99999.0
p1 = isect_rectangle(ray, rectangle, hitpoint, min_dist)
        """

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

        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)

        hitpoint = HitPoint.factory()
        hitpoint.mat_idx = 5

        r_arg = StructArg('ray', ray)
        sph_arg = StructArg('rectangle', rectangle)
        harg = StructArg('hitpoint', hitpoint)
        p1 = IntArg('p1', 6)

        args = [r_arg, sph_arg, harg, p1]
        shader = Shader(code=code, args=args)
        shader.compile([rect_shader.shader])
        shader.prepare(runtimes)

        shader.execute()
        hp2 = rectangle.isect(ray)

        hitpoint = shader.get_value('hitpoint')
        self.assertAlmostEqual(hp2.t, hitpoint.t, places=5)
        self.assertEqual(hp2.mat_idx, hitpoint.mat_idx)
        n1 = hp2.normal
        n2 = hitpoint.normal
        self.assertAlmostEqual(n1.x, n2.x)
        self.assertAlmostEqual(n1.y, n2.y)
        self.assertAlmostEqual(n1.z, n2.z)
        self.assertAlmostEqual(hitpoint.hit.x, hp2.hit.x, places=5)
        self.assertAlmostEqual(hitpoint.hit.y, hp2.hit.y, places=5)
        self.assertAlmostEqual(hitpoint.hit.z, hp2.hit.z, places=5)

        result = shader.get_value('p1')
        self.assertEqual(result, 1)
コード例 #3
0
ファイル: test_rectangle.py プロジェクト: mario007/renmas
    def test_isect_rect(self):
        rect_shader = Rectangle.isect_shader('isect_rectangle')
        rect_shader.compile()
        runtimes = [Runtime()]
        rect_shader.prepare(runtimes)

        code = """
min_dist = 99999.0
p1 = isect_rectangle(ray, rectangle, hitpoint, min_dist)
        """

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

        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)

        hitpoint = HitPoint.factory()
        hitpoint.mat_idx = 5

        r_arg = StructArg('ray', ray)
        sph_arg = StructArg('rectangle', rectangle)
        harg = StructArg('hitpoint', hitpoint)
        p1 = IntArg('p1', 6)

        args = [r_arg, sph_arg, harg, p1]
        shader = Shader(code=code, args=args)
        shader.compile([rect_shader.shader])
        shader.prepare(runtimes)

        shader.execute()
        hp2 = rectangle.isect(ray)

        hitpoint = shader.get_value('hitpoint')
        self.assertAlmostEqual(hp2.t, hitpoint.t, places=5)
        self.assertEqual(hp2.mat_idx, hitpoint.mat_idx)
        n1 = hp2.normal
        n2 = hitpoint.normal
        self.assertAlmostEqual(n1.x, n2.x)
        self.assertAlmostEqual(n1.y, n2.y)
        self.assertAlmostEqual(n1.z, n2.z)
        self.assertAlmostEqual(hitpoint.hit.x, hp2.hit.x, places=5)
        self.assertAlmostEqual(hitpoint.hit.y, hp2.hit.y, places=5)
        self.assertAlmostEqual(hitpoint.hit.z, hp2.hit.z, places=5)

        result = shader.get_value('p1')
        self.assertEqual(result, 1)
コード例 #4
0
ファイル: test_rectangle.py プロジェクト: mario007/renmas
    def test_isect_b_rect(self):
        rect_shader = Rectangle.isect_b_shader('isect_b_rectangle')
        rect_shader.compile()
        runtimes = [Runtime()]
        rect_shader.prepare(runtimes)

        code = """
min_dist = 99999.0
p1 = isect_b_rectangle(ray, rectangle, min_dist)
        """

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

        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)

        r_arg = StructArg('ray', ray)
        sph_arg = StructArg('rectangle', rectangle)
        p1 = IntArg('p1', 6)

        args = [r_arg, sph_arg, p1]
        shader = Shader(code=code, args=args)
        shader.compile([rect_shader.shader])

        shader.prepare(runtimes)
        shader.execute()

        result = shader.get_value('p1')
        self.assertEqual(result, 1)
コード例 #5
0
    def test_rgb_area_light(self):
        sam_mgr = SampledManager()
        register_rgb_shadepoint()

        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)

        material = Material()
        material.load('lambertian_emiter', sam_mgr)
        e = RGBSpectrum(0.5, 0.5, 0.5)
        material.set_value('emission', e)

        runtimes = [Runtime()]
        lgt = AreaLight(shape=rectangle, material=material)
        lgt.load('general', sam_mgr, spectral=False)
        lgt.compile()
        lgt.prepare(runtimes)
        ptrs = lgt.shader.get_ptrs()

        ptr_func = PointerArg('ptr_func', ptrs[0])
        spec = RGBArg('spec', RGBSpectrum(0.5, 0.5, 0.5))
        wi = Vec3Arg('wi', Vector3(0.0, 0.0, 0.0))
        pos = Vec3Arg('position', Vector3(0.0, 0.0, 0.0))
        n = Vec3Arg('normal', Vector3(0.0, 0.0, 0.0))
        pdf = FloatArg('pdf', 0.0)
        emission = RGBArg('emission', RGBSpectrum(0.0, 0.0, 0.0))

        code = """
hp = HitPoint()
hp.hit = (4.0, 5, 6)
sp = ShadePoint()
__light_radiance(hp, sp, ptr_func)
spec = sp.light_intensity
wi = sp.wi
position = sp.light_position
normal = sp.light_normal
pdf = sp.light_pdf
emission = sp.material_emission
        """

        shader = Shader(code=code,
                        args=[ptr_func, wi, spec, pos, n, pdf, emission])
        shader.compile()
        shader.prepare(runtimes)
        shader.execute()

        print("Position ", shader.get_value('position'))
        print("Normal ", shader.get_value('normal'))
        print("Light pdf ", shader.get_value('pdf'))
        print("Emission ", shader.get_value('emission'))
        print("Wi ", shader.get_value('wi'))
        print("Intensity ", shader.get_value('spec'))