示例#1
0
    def test_isect_b_sph(self):
        sph_shader = Sphere.isect_b_shader()
        sph_shader.compile()
        runtimes = [Runtime()]
        sph_shader.prepare(runtimes)

        code = """
min_dist = 99999.0
p1 = isect_b_sphere(ray, sphere, min_dist)
        """

        direction = Vector3(-1.0, -1.0, -1.0)
        direction.normalize()
        ray = Ray(Vector3(5.0, 5.0, 5.0), direction)
        sphere = Sphere(Vector3(0.0, 0.0, 0.0), 2.0, 0)

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

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

        shader.prepare(runtimes)
        shader.execute()

        result = shader.get_value('p1')
        self.assertEqual(result, 1)
示例#2
0
    def test_isect_b_sph(self):
        sph_shader = Sphere.isect_b_shader()
        sph_shader.compile()
        runtimes = [Runtime()]
        sph_shader.prepare(runtimes)

        code = """
min_dist = 99999.0
p1 = isect_b_sphere(ray, sphere, min_dist)
        """

        direction = Vector3(-1.0, -1.0, -1.0)
        direction.normalize()
        ray = Ray(Vector3(5.0, 5.0, 5.0), direction)
        sphere = Sphere(Vector3(0.0, 0.0, 0.0), 2.0, 0)

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

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

        shader.prepare(runtimes)
        shader.execute()

        result = shader.get_value('p1')
        self.assertEqual(result, 1)