Beispiel #1
0
    def test_sampled_spec_to_vec(self):
        mgr = SampledManager()
        shader = sampled_to_vec_shader(mgr)
        shader.compile()
        runtime = Runtime()
        shader.prepare([runtime])
        code = """
rez = spectrum_to_vec(r1)
        """

        vals = [(450, 0.13), (480, 0.45), (620, 0.58)]
        samples = create_samples(vals, 32, 400, 700)
        sam_spec = SampledSpectrum(samples)
        s = SampledArg('r1', sam_spec)

        rez = Vec3Arg('rez', Vector3(0.0, 0.0, 0.0))
        shader2 = Shader(code=code, args=[rez, s])
        shader2.compile([shader])
        shader2.prepare([runtime])
        shader2.execute()

        val = shader2.get_value('rez')
        conv = mgr.sampled_to_rgb(sam_spec)

        self.assertAlmostEqual(val.x, conv.r, places=6)
        self.assertAlmostEqual(val.y, conv.g, places=6)
        self.assertAlmostEqual(val.z, conv.b, places=6)
Beispiel #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)
Beispiel #3
0
    def test_rgb_arithmetic(self):
        code = """
tmp = p1 + p2
p3 = tmp
p4 = 2 * p3
p5 = p3 * 2.66
        """
        p1 = RGBArg('p1', RGBSpectrum(0.36, 0.85, 0.14))
        p2 = RGBArg('p2', RGBSpectrum(0.22, 0.11, 0.58))
        p3 = RGBArg('p3', RGBSpectrum(0.0, 0.0, 0.0))
        p4 = RGBArg('p4', RGBSpectrum(0.0, 0.0, 0.0))
        p5 = RGBArg('p5', RGBSpectrum(0.0, 0.0, 0.0))
        shader = Shader(code=code, args=[p1, p2, p3, p4, p5])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        v = shader.get_value('p3')
        self.assertAlmostEqual(v.r, 0.36 + 0.22)
        self.assertAlmostEqual(v.g, 0.85 + 0.11)
        self.assertAlmostEqual(v.b, 0.14 + 0.58)
        v = shader.get_value('p4')
        self.assertAlmostEqual(v.r, (0.36 + 0.22) * 2, places=6)
        self.assertAlmostEqual(v.g, (0.85 + 0.11) * 2, places=6)
        self.assertAlmostEqual(v.b, (0.14 + 0.58) * 2, places=6)
        v = shader.get_value('p5')
        self.assertAlmostEqual(v.r, (0.36 + 0.22) * 2.66, places=6)
        self.assertAlmostEqual(v.g, (0.85 + 0.11) * 2.66, places=6)
        self.assertAlmostEqual(v.b, (0.14 + 0.58) * 2.66, places=6)
Beispiel #4
0
    def test_sampled_spectrum(self):

        code = """
spec2 = Spectrum(spec, 0.23)
        """

        vals = [(450, 0.13), (480, 0.45), (620, 0.58)]
        samples = create_samples(vals, 32, 400, 700)
        sam_spec = SampledSpectrum(samples)
        spec = SampledArg('spec', sam_spec)

        vals = [(450, 0.11)]
        samples = create_samples(vals, 32, 400, 700)
        sam_spec = SampledSpectrum(samples)
        spec2 = SampledArg('spec2', sam_spec)

        shader = Shader(code=code, args=[spec, spec2])
        shader.compile()
        runtime = Runtime()
        shader.prepare([runtime])
        shader.execute()

        val = shader.get_value('spec2')
        for i in range(len(val.samples)):
            self.assertAlmostEqual(val.samples[i], 0.23)
Beispiel #5
0
    def test_array(self):

        p = SuperPoint(3.0, 4.0)
        arr = Array(p)
        arr.append(p)
        arr.append(p)
        p = SuperPoint(7.0, 9.0)
        arr.append(p)

        code = """
index = 2
temp = arr[index]
p1 = temp.x
temp.y = 12.34
        """
        arg = ArrayArg("arr", arr)
        arg1 = FloatArg("p1", 4.4)
        shader = Shader(code=code, args=[arg, arg1])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()
        val = shader.get_value("p1")
        self.assertAlmostEqual(val, 7.0)
        obj = arr[2]
        self.assertAlmostEqual(obj.y, 12.34, 6)
Beispiel #6
0
    def test_sampled_spectrum(self):

        code = """
spec2 = Spectrum(spec, 0.23)
        """

        vals = [(450, 0.13), (480, 0.45), (620, 0.58)]
        samples = create_samples(vals, 32, 400, 700)
        sam_spec = SampledSpectrum(samples)
        spec = SampledArg('spec', sam_spec)

        vals = [(450, 0.11)]
        samples = create_samples(vals, 32, 400, 700)
        sam_spec = SampledSpectrum(samples)
        spec2 = SampledArg('spec2', sam_spec)

        shader = Shader(code=code, args=[spec, spec2])
        shader.compile()
        runtime = Runtime()
        shader.prepare([runtime])
        shader.execute()

        val = shader.get_value('spec2')
        for i in range(len(val.samples)):
            self.assertAlmostEqual(val.samples[i], 0.23)
Beispiel #7
0
    def test_rgb_arithmetic(self):
        code = """
tmp = p1 + p2
p3 = tmp
p4 = 2 * p3
p5 = p3 * 2.66
        """
        p1 = RGBArg('p1', RGBSpectrum(0.36, 0.85, 0.14))
        p2 = RGBArg('p2', RGBSpectrum(0.22, 0.11, 0.58))
        p3 = RGBArg('p3', RGBSpectrum(0.0, 0.0, 0.0))
        p4 = RGBArg('p4', RGBSpectrum(0.0, 0.0, 0.0))
        p5 = RGBArg('p5', RGBSpectrum(0.0, 0.0, 0.0))
        shader = Shader(code=code, args=[p1, p2, p3, p4, p5])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        v = shader.get_value('p3')
        self.assertAlmostEqual(v.r, 0.36 + 0.22)
        self.assertAlmostEqual(v.g, 0.85 + 0.11)
        self.assertAlmostEqual(v.b, 0.14 + 0.58)
        v = shader.get_value('p4')
        self.assertAlmostEqual(v.r, (0.36 + 0.22) * 2, places=6)
        self.assertAlmostEqual(v.g, (0.85 + 0.11) * 2, places=6)
        self.assertAlmostEqual(v.b, (0.14 + 0.58) * 2, places=6)
        v = shader.get_value('p5')
        self.assertAlmostEqual(v.r, (0.36 + 0.22) * 2.66, places=6)
        self.assertAlmostEqual(v.g, (0.85 + 0.11) * 2.66, places=6)
        self.assertAlmostEqual(v.b, (0.14 + 0.58) * 2.66, places=6)
Beispiel #8
0
    def test_call(self):
        code = """
tmp = p1 + p2 + p3
p4.x = 55.99
return tmp
        """
        p1 = FloatArg("p1", 2.0)
        p2 = IntArg("p2", 0)
        p3 = FloatArg("p3", 0.0)
        p4 = StructArgPtr("p4", TestPoint(4.4, 5.5))
        shader = Shader(code=code, args=[], name="adding", func_args=[p1, p2, p3, p4], is_func=True)
        shader.compile()
        shader.prepare(self.runtimes)

        code2 = """
p1 = 44
p2 = 7
point = TestPoint()
rez = adding(55.4, p1, p2, point)
rez2 = point.x
        """
        rez = FloatArg("rez", 11.33)
        rez2 = FloatArg("rez2", 1.0)
        shader2 = Shader(code=code2, args=[rez, rez2])
        shader2.compile([shader])
        shader2.prepare(self.runtimes)
        shader2.execute()

        rez = shader2.get_value("rez")
        rez2 = shader2.get_value("rez2")
        self.assertAlmostEqual(rez, 55.4 + 44 + 7, places=5)
        self.assertAlmostEqual(rez2, 55.99, places=5)
Beispiel #9
0
    def test_array(self):

        p = SuperPoint(3.0, 4.0)
        arr = Array(p)
        arr.append(p)
        arr.append(p)
        p = SuperPoint(7.0, 9.0)
        arr.append(p)

        code = """
index = 2
temp = arr[index]
p1 = temp.x
temp.y = 12.34
        """
        arg = ArrayArg('arr', arr)
        arg1 = FloatArg('p1', 4.4)
        shader = Shader(code=code, args=[arg, arg1])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()
        val = shader.get_value('p1')
        self.assertAlmostEqual(val, 7.0)
        obj = arr[2]
        self.assertAlmostEqual(obj.y, 12.34, 6)
Beispiel #10
0
    def test_float(self):
        code = """
temp = 5
p1 = float(temp)
p2 = float(88)
p3 = float()
p4 = float(6.6)
        """
        p1 = FloatArg('p1', 333.3)
        p2 = FloatArg('p2', 333.3)
        p3 = FloatArg('p3', 333.3)
        p4 = FloatArg('p4', 333.3)

        shader = Shader(code=code, args=[p1, p2, p3, p4])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        p = shader.get_value('p1')
        self.assertAlmostEqual(p, 5.0)
        p = shader.get_value('p2')
        self.assertAlmostEqual(p, 88.0)
        p = shader.get_value('p3')
        self.assertAlmostEqual(p, 0.0)
        p = shader.get_value('p4')
        self.assertAlmostEqual(p, 6.6, places=6)
Beispiel #11
0
    def test_sampled_lum(self):

        mgr = SampledManager()
        shader = lum_sampled_shader(mgr)
        shader.compile()
        runtime = Runtime()
        shader.prepare([runtime])
        code = """
rez = lumminance(r1)
        """

        vals = [(450, 0.13), (480, 0.45), (620, 0.58)]
        samples = create_samples(vals, 32, 400, 700)
        sam_spec = SampledSpectrum(samples)
        s = SampledArg('r1', sam_spec)

        rez = FloatArg('rez', 0.0)
        shader2 = Shader(code=code, args=[rez, s])
        shader2.compile([shader])
        shader2.prepare([runtime])
        shader2.execute()

        val = shader2.get_value('rez')
        lum = mgr.lumminance(sam_spec)
        self.assertAlmostEqual(lum, val)
Beispiel #12
0
    def test_int(self):
        code = """
temp = 5.6
p1 = int(temp)
p2 = int(8.8)
p3 = int()
p4 = int(11)
        """
        p1 = IntArg('p1', 333)
        p2 = IntArg('p2', 555)
        p3 = IntArg('p3', 555)
        p4 = IntArg('p4', 555)

        shader = Shader(code=code, args=[p1, p2, p3, p4])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        p = shader.get_value('p1')
        self.assertEqual(p, 5)
        p = shader.get_value('p2')
        self.assertEqual(p, 8)
        p = shader.get_value('p3')
        self.assertEqual(p, 0)
        p = shader.get_value('p4')
        self.assertEqual(p, 11)
Beispiel #13
0
    def test_call(self):
        code = """
tmp = p1 + p2 + p3
p4.x = 55.99
return tmp
        """
        p1 = FloatArg('p1', 2.0)
        p2 = IntArg('p2', 0)
        p3 = FloatArg('p3', 0.0)
        p4 = StructArgPtr('p4', TestPoint(4.4, 5.5))
        shader = Shader(code=code, args=[], name='adding',
                        func_args=[p1, p2, p3, p4], is_func=True)
        shader.compile()
        shader.prepare(self.runtimes)

        code2 = """
p1 = 44
p2 = 7
point = TestPoint()
rez = adding(55.4, p1, p2, point)
rez2 = point.x
        """
        rez = FloatArg('rez', 11.33)
        rez2 = FloatArg('rez2', 1.0)
        shader2 = Shader(code=code2, args=[rez, rez2])
        shader2.compile([shader])
        shader2.prepare(self.runtimes)
        shader2.execute()

        rez = shader2.get_value('rez')
        rez2 = shader2.get_value('rez2')
        self.assertAlmostEqual(rez, 55.4 + 44 + 7, places=5)
        self.assertAlmostEqual(rez2, 55.99, places=5)
Beispiel #14
0
    def test_sampled_lum(self):

        mgr = SampledManager()
        shader = lum_sampled_shader(mgr)
        shader.compile()
        runtime = Runtime()
        shader.prepare([runtime])
        code = """
rez = lumminance(r1)
        """

        vals = [(450, 0.13), (480, 0.45), (620, 0.58)]
        samples = create_samples(vals, 32, 400, 700)
        sam_spec = SampledSpectrum(samples)
        s = SampledArg('r1', sam_spec)

        rez = FloatArg('rez', 0.0)
        shader2 = Shader(code=code, args=[rez, s])
        shader2.compile([shader])
        shader2.prepare([runtime])
        shader2.execute()

        val = shader2.get_value('rez')
        lum = mgr.lumminance(sam_spec)
        self.assertAlmostEqual(lum, val)
Beispiel #15
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)
Beispiel #16
0
    def test_sampled_spec_to_vec(self):
        mgr = SampledManager()
        shader = sampled_to_vec_shader(mgr)
        shader.compile()
        runtime = Runtime()
        shader.prepare([runtime])
        code = """
rez = spectrum_to_vec(r1)
        """

        vals = [(450, 0.13), (480, 0.45), (620, 0.58)]
        samples = create_samples(vals, 32, 400, 700)
        sam_spec = SampledSpectrum(samples)
        s = SampledArg('r1', sam_spec)

        rez = Vec3Arg('rez', Vector3(0.0, 0.0, 0.0))
        shader2 = Shader(code=code, args=[rez, s])
        shader2.compile([shader])
        shader2.prepare([runtime])
        shader2.execute()

        val = shader2.get_value('rez')
        conv = mgr.sampled_to_rgb(sam_spec)

        self.assertAlmostEqual(val.x, conv.r, places=6)
        self.assertAlmostEqual(val.y, conv.g, places=6)
        self.assertAlmostEqual(val.z, conv.b, places=6)
Beispiel #17
0
    def test_linear(self):
        sphere = Sphere(Vector3(0.0, 0.0, 0.0), 2.0, 0)
        mgr = ShapeManager()
        mgr.add('sph1', sphere)
        sphere2 = Sphere(Vector3(0.0, 2.0, 0.0), 3.0, 0)
        mgr.add('sph2', sphere2)

        isector = LinearIsect(mgr)
        runtimes = [Runtime()]

        direction = Vector3(-1.0, -1.0, -1.0)
        direction.normalize()
        ray = Ray(Vector3(5.0, 5.0, 5.0), direction)

        isect_sph = Sphere.isect_shader()
        isect_sph.compile()
        isect_sph.prepare(runtimes)

        isect_shader = isector.isect_shader()
        isect_shader.compile([isect_sph])
        isect_shader.prepare(runtimes)

        code = """
min_dist = 99999.0
p1 = isect_scene(ray, hitpoint, min_dist)
        """
        direction = Vector3(-1.0, -1.0, -1.0)
        direction.normalize()
        ray = Ray(Vector3(5.0, 5.0, 5.0), direction)
        hitpoint = HitPoint(0.0, Vector3(0.0, 0.0, 0.0),
                            Vector3(0.0, 0.0, 0.0), 6, 0.0, 0.0)

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

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

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

        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, places=6)
        self.assertAlmostEqual(n1.z, n2.z)
        self.assertAlmostEqual(hitpoint.hit.x, hp2.hit.x, places=6)
        self.assertAlmostEqual(hitpoint.hit.y, hp2.hit.y, places=6)
        self.assertAlmostEqual(hitpoint.hit.z, hp2.hit.z, places=6)

        result = shader.get_value('p1')
        self.assertEqual(result, 1)
Beispiel #18
0
 def test_expr(self):
     #TODO
     code = """
     """
     shader = Shader(code=code, args=[])
     shader.compile()
     shader.prepare([Runtime()])
     shader.execute()
Beispiel #19
0
 def test_expr(self):
     #TODO
     code = """
     """
     shader = Shader(code=code, args=[])
     shader.compile()
     shader.prepare([Runtime()])
     shader.execute()
Beispiel #20
0
    def test_arithmetic(self):
        code = """
a1 = 33
a2 = 22
p1 = a1 + a2
a1 = 22.3
a2 = 11.1
p2 = a1 + a2
a1 = 44
a2 = -2.36
p3 = a1 * a2
a1 = (2.3, 4)
a2 = 5
p4 = a1 * a2

a1 = (3, 4, 6.6)
a2 = (7, 4.3, 2.6)
p5 = a1 - a2

a1 = (1, 4.1, 5.5, 9.9)
a2 = (0.22, 3.3, 2.6, 6.6)
p6 = a1 / a2
        """
        p1 = IntArg('p1', 33)
        p2 = FloatArg('p2', 55.5)
        p3 = FloatArg('p3', 55.5)
        p4 = Vec2Arg('p4', Vector2(0.0, 0.0))
        p5 = Vec3Arg('p5', Vector3(0.0, 0.0, 0.0))
        p6 = Vec4Arg('p6', Vector4(0.0, 0.0, 0.0, 0.0))

        shader = Shader(code=code, args=[p1, p2, p3, p4, p5, p6])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        rez = shader.get_value('p1')
        self.assertEqual(rez, 33 + 22)
        rez = shader.get_value('p2')
        self.assertAlmostEqual(rez, 22.3 + 11.1, places=5)
        rez = shader.get_value('p3')
        self.assertAlmostEqual(rez, 44 * -2.36, places=5)
        rez = shader.get_value('p4')
        self.assertAlmostEqual(rez.x, 5 * 2.3, places=5)
        self.assertAlmostEqual(rez.y, 5 * 4, places=5)
        rez = shader.get_value('p5')
        self.assertAlmostEqual(rez.x, 3 - 7.0, places=5)
        self.assertAlmostEqual(rez.y, 4 - 4.3, places=5)
        self.assertAlmostEqual(rez.z, 6.6 - 2.6, places=5)
        rez = shader.get_value('p6')
        self.assertAlmostEqual(rez.x, 1 / 0.22, places=5)
        self.assertAlmostEqual(rez.y, 4.1 / 3.3, places=5)
        self.assertAlmostEqual(rez.z, 5.5 / 2.6, places=5)
        self.assertAlmostEqual(rez.w, 9.9 / 6.6, places=5)
Beispiel #21
0
    def test_arithmetic(self):
        code = """
a1 = 33
a2 = 22
p1 = a1 + a2
a1 = 22.3
a2 = 11.1
p2 = a1 + a2
a1 = 44
a2 = -2.36
p3 = a1 * a2
a1 = (2.3, 4)
a2 = 5
p4 = a1 * a2

a1 = (3, 4, 6.6)
a2 = (7, 4.3, 2.6)
p5 = a1 - a2

a1 = (1, 4.1, 5.5, 9.9)
a2 = (0.22, 3.3, 2.6, 6.6)
p6 = a1 / a2
        """
        p1 = IntArg('p1', 33)
        p2 = FloatArg('p2', 55.5)
        p3 = FloatArg('p3', 55.5)
        p4 = Vec2Arg('p4', Vector2(0.0, 0.0))
        p5 = Vec3Arg('p5', Vector3(0.0, 0.0, 0.0))
        p6 = Vec4Arg('p6', Vector4(0.0, 0.0, 0.0, 0.0))

        shader = Shader(code=code, args=[p1, p2, p3, p4, p5, p6])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        rez = shader.get_value('p1')
        self.assertEqual(rez, 33 + 22)
        rez = shader.get_value('p2')
        self.assertAlmostEqual(rez, 22.3 + 11.1, places=5)
        rez = shader.get_value('p3')
        self.assertAlmostEqual(rez, 44 * -2.36, places=5)
        rez = shader.get_value('p4')
        self.assertAlmostEqual(rez.x, 5 * 2.3, places=5)
        self.assertAlmostEqual(rez.y, 5 * 4, places=5)
        rez = shader.get_value('p5')
        self.assertAlmostEqual(rez.x, 3 - 7.0, places=5)
        self.assertAlmostEqual(rez.y, 4 - 4.3, places=5)
        self.assertAlmostEqual(rez.z, 6.6 - 2.6, places=5)
        rez = shader.get_value('p6')
        self.assertAlmostEqual(rez.x, 1 / 0.22, places=5)
        self.assertAlmostEqual(rez.y, 4.1 / 3.3, places=5)
        self.assertAlmostEqual(rez.z, 5.5 / 2.6, places=5)
        self.assertAlmostEqual(rez.w, 9.9 / 6.6, places=5)
Beispiel #22
0
    def test_struct(self):
        code = """
a1 = MyPoint()
tmp = 66
a1.x = tmp
p1 = a1.x

tmp = 4.4
a1.y = tmp
p2 = a1.y

tmp = (6, 7)
a1.k = tmp
p3 = a1.k

tmp = (3, 4, 6)
a1.m = tmp
p4 = a1.m

tmp = (2, 4, 6, 7)
a1.p = tmp
p5 = a1.p

        """
        #p1 = IntArg('p1', 44) #TODO implicit conversion int to float
        p1 = IntArg('p1', 44)
        p2 = FloatArg('p2', 2.2)
        p3 = Vec2Arg('p3', Vector2(5.5, 7.7))
        p4 = Vec3Arg('p4', Vector3(2.2, 2.2, 4.4))
        p5 = Vec4Arg('p5', Vector4(8.8, 5.5, 3.3, 1.1))
        shader = Shader(code=code, args=[p1, p2, p3, p4, p5])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        v = shader.get_value('p1')
        self.assertEqual(v, 66)
        v = shader.get_value('p2')
        self.assertAlmostEqual(v, 4.4, places=6)
        v = shader.get_value('p3')
        self.assertAlmostEqual(v.x, 6.0, places=6)
        self.assertAlmostEqual(v.y, 7.0, places=6)
        v = shader.get_value('p4')
        self.assertAlmostEqual(v.x, 3.0, places=6)
        self.assertAlmostEqual(v.y, 4.0, places=6)
        self.assertAlmostEqual(v.z, 6.0, places=6)
        v = shader.get_value('p5')
        self.assertAlmostEqual(v.x, 2.0, places=6)
        self.assertAlmostEqual(v.y, 4.0, places=6)
        self.assertAlmostEqual(v.z, 6.0, places=6)
        self.assertAlmostEqual(v.w, 7.0, places=6)
Beispiel #23
0
    def test_struct(self):
        code = """
a1 = MyPoint()
tmp = 66
a1.x = tmp
p1 = a1.x

tmp = 4.4
a1.y = tmp
p2 = a1.y

tmp = (6, 7)
a1.k = tmp
p3 = a1.k

tmp = (3, 4, 6)
a1.m = tmp
p4 = a1.m

tmp = (2, 4, 6, 7)
a1.p = tmp
p5 = a1.p

        """
        #p1 = IntArg('p1', 44) #TODO implicit conversion int to float
        p1 = IntArg('p1', 44)
        p2 = FloatArg('p2', 2.2)
        p3 = Vec2Arg('p3', Vector2(5.5, 7.7))
        p4 = Vec3Arg('p4', Vector3(2.2, 2.2, 4.4))
        p5 = Vec4Arg('p5', Vector4(8.8, 5.5, 3.3, 1.1))
        shader = Shader(code=code, args=[p1, p2, p3, p4, p5])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        v = shader.get_value('p1')
        self.assertEqual(v, 66)
        v = shader.get_value('p2')
        self.assertAlmostEqual(v, 4.4, places=6)
        v = shader.get_value('p3')
        self.assertAlmostEqual(v.x, 6.0, places=6)
        self.assertAlmostEqual(v.y, 7.0, places=6)
        v = shader.get_value('p4')
        self.assertAlmostEqual(v.x, 3.0, places=6)
        self.assertAlmostEqual(v.y, 4.0, places=6)
        self.assertAlmostEqual(v.z, 6.0, places=6)
        v = shader.get_value('p5')
        self.assertAlmostEqual(v.x, 2.0, places=6)
        self.assertAlmostEqual(v.y, 4.0, places=6)
        self.assertAlmostEqual(v.z, 6.0, places=6)
        self.assertAlmostEqual(v.w, 7.0, places=6)
Beispiel #24
0
    def test_assign_rgb_spectrum(self):
        code = """
p2 = p1
        """
        p1 = RGBArg('p1', RGBSpectrum(0.36, 0.85, 0.14))
        p2 = RGBArg('p2', RGBSpectrum(0.0, 0.0, 0.0))
        shader = Shader(code=code, args=[p1, p2])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        v = shader.get_value('p2')
        self.assertAlmostEqual(v.r, 0.36)
        self.assertAlmostEqual(v.g, 0.85)
        self.assertAlmostEqual(v.b, 0.14)
Beispiel #25
0
    def test_assign_rgb_spectrum(self):
        code = """
p2 = p1
        """
        p1 = RGBArg('p1', RGBSpectrum(0.36, 0.85, 0.14))
        p2 = RGBArg('p2', RGBSpectrum(0.0, 0.0, 0.0))
        shader = Shader(code=code, args=[p1, p2])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        v = shader.get_value('p2')
        self.assertAlmostEqual(v.r, 0.36)
        self.assertAlmostEqual(v.g, 0.85)
        self.assertAlmostEqual(v.b, 0.14)
Beispiel #26
0
    def test_rgb_spectrum(self):
        code = """
spec2 = Spectrum(spec, 0.23)
        """
        spec = RGBArg('spec', RGBSpectrum(0.2, 0.3, 0.4))
        spec2 = RGBArg('spec2', RGBSpectrum(0.0, 0.0, 0.0))
        shader = Shader(code=code, args=[spec, spec2])
        shader.compile()
        runtime = Runtime()
        shader.prepare([runtime])
        shader.execute()

        val = shader.get_value('spec2')
        self.assertAlmostEqual(val.r, 0.23)
        self.assertAlmostEqual(val.g, 0.23)
        self.assertAlmostEqual(val.b, 0.23)
Beispiel #27
0
    def test_rgb_spectrum(self):
        code = """
spec2 = Spectrum(spec, 0.23)
        """
        spec = RGBArg('spec', RGBSpectrum(0.2, 0.3, 0.4))
        spec2 = RGBArg('spec2', RGBSpectrum(0.0, 0.0, 0.0))
        shader = Shader(code=code, args=[spec, spec2])
        shader.compile()
        runtime = Runtime()
        shader.prepare([runtime])
        shader.execute()

        val = shader.get_value('spec2')
        self.assertAlmostEqual(val.r, 0.23)
        self.assertAlmostEqual(val.g, 0.23)
        self.assertAlmostEqual(val.b, 0.23)
Beispiel #28
0
    def test_set_prgba(self):
        code = """
val = (0.67, 0.88, 0.11, 0.55)
v1 = set_rgba(image1, 10, 10, val)
        """
        image = ImagePRGBA(200, 200)
        p1 = StructArg('image1', image)
        shader = Shader(code=code, args=[p1])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        r, g, b, a = image.get_pixel(10, 10)
        self.assertAlmostEqual(r, 0.67)
        self.assertAlmostEqual(g, 0.88)
        self.assertAlmostEqual(b, 0.11)
        self.assertAlmostEqual(a, 0.55)
Beispiel #29
0
    def test_set_prgba(self):
        code = """
val = (0.67, 0.88, 0.11, 0.55)
v1 = set_rgba(image1, 10, 10, val)
        """
        image = ImagePRGBA(200, 200)
        p1 = StructArg('image1', image)
        shader = Shader(code=code, args=[p1])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        r, g, b, a = image.get_pixel(10, 10)
        self.assertAlmostEqual(r, 0.67)
        self.assertAlmostEqual(g, 0.88)
        self.assertAlmostEqual(b, 0.11)
        self.assertAlmostEqual(a, 0.55)
Beispiel #30
0
    def test_isect_sph(self):
        sph_shader = Sphere.isect_shader()
        sph_shader.compile()
        runtimes = [Runtime()]
        sph_shader.prepare(runtimes)

        code = """
min_dist = 99999.0
p1 = isect_sphere(ray, sphere, hitpoint, 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)
        hitpoint = HitPoint(0.0, Vector3(0.0, 0.0, 0.0),
                            Vector3(0.0, 0.0, 0.0), 6, 0.0, 0.0)

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

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

        shader.prepare(runtimes)
        shader.execute()

        hp2 = sphere.isect(ray)
        hitpoint = shader.get_value('hitpoint')
        self.assertAlmostEqual(hp2.t, hitpoint.t)
        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)
        self.assertAlmostEqual(hitpoint.hit.y, hp2.hit.y)
        self.assertAlmostEqual(hitpoint.hit.z, hp2.hit.z)

        result = shader.get_value('p1')
        self.assertEqual(result, 1)
Beispiel #31
0
    def test_isect_sph(self):
        sph_shader = Sphere.isect_shader()
        sph_shader.compile()
        runtimes = [Runtime()]
        sph_shader.prepare(runtimes)

        code = """
min_dist = 99999.0
p1 = isect_sphere(ray, sphere, hitpoint, 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)
        hitpoint = HitPoint(0.0, Vector3(0.0, 0.0, 0.0),
                            Vector3(0.0, 0.0, 0.0), 6, 0.0, 0.0)

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

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

        shader.prepare(runtimes)
        shader.execute()

        hp2 = sphere.isect(ray)
        hitpoint = shader.get_value('hitpoint')
        self.assertAlmostEqual(hp2.t, hitpoint.t)
        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)
        self.assertAlmostEqual(hitpoint.hit.y, hp2.hit.y)
        self.assertAlmostEqual(hitpoint.hit.z, hp2.hit.z)

        result = shader.get_value('p1')
        self.assertEqual(result, 1)
Beispiel #32
0
    def test_float4(self):
        code = """
temp = 5
temp2 = 9.9
p1 = float4(temp, temp2, 2, 5.5)
        """
        p1 = Vec4Arg('p1', Vector4(0.0, 1.0, 0.0, 0.0))

        shader = Shader(code=code, args=[p1])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        p = shader.get_value('p1')
        self.assertAlmostEqual(p.x, 5.0)
        self.assertAlmostEqual(p.y, 9.9, places=6)
        self.assertAlmostEqual(p.z, 2.0)
        self.assertAlmostEqual(p.w, 5.5)
Beispiel #33
0
    def test_dot_fun(self):
        code = """
p3 = dot(p1, p2)
        """
        v1 = Vector3(2.5, 1.8, 2.9)
        v2 = Vector3(2.2, 1.1, 5.22)
        p1 = Vec3Arg('p1', v1)
        p2 = Vec3Arg('p2', v2)
        p3 = FloatArg('p3', 2.2)

        shader = Shader(code=code, args=[p1, p2, p3])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        rez = v1.dot(v2)
        p = shader.get_value('p3')
        self.assertAlmostEqual(rez, p)
Beispiel #34
0
    def test_assign_sampled_spectrum(self):
        code = """
p2 = p1
        """
        vals = [(450, 0.33), (480, 0.45)]
        samples = create_samples(vals, 32, 400, 700)
        p1 = SampledArg('p1', SampledSpectrum(samples))
        vals = [(430, 0.23), (480, 0.55), (600, 0.77)]
        samples2 = create_samples(vals, 32, 400, 700)
        p2 = SampledArg('p2', SampledSpectrum(samples2))

        shader = Shader(code=code, args=[p1, p2])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        v = shader.get_value('p2')
        for val1, val2 in zip(samples, v.samples):
            self.assertAlmostEqual(val1, val2)
Beispiel #35
0
    def test_cameras(self):
        eye = Vector3(0.0, 10.0, 5.0)
        lookat = Vector3(0.0, 0.0, 0.0)
        distance = 100.0

        cam = Camera(eye, lookat, distance)
        cam.load('pinhole')
        cam.compile()
        runtimes = [Runtime()]
        cam.prepare(runtimes)

        code = """
ray = Ray()
sample = Sample()
sample.x = 2.2
sample.y = 2.5
generate_ray(ray, sample)
origin = ray.origin
direction = ray.direction
        """
        origin = Vec3Arg('origin', Vector3(0.0, 0.0, 0.0))
        direction = Vec3Arg('direction', Vector3(0.0, 0.0, 0.0))
        args = [origin, direction]
        shader = Shader(code=code, args=args)
        shader.compile([cam.shader])
        shader.prepare(runtimes)
        shader.execute()

        ray = Ray(Vector3(0.0, 0.0, 0.0), Vector3(0.0, 0.0, 0.0))
        sample = Sample(2.2, 2.5, 2, 2, 1.0)
        cam.execute_py(ray, sample)

        v = shader.get_value('origin')
        o = ray.origin
        self.assertAlmostEqual(v.x, o.x)
        self.assertAlmostEqual(v.y, o.y)
        self.assertAlmostEqual(v.z, o.z)

        v = shader.get_value('direction')
        d = ray.direction
        self.assertAlmostEqual(v.x, d.x)
        self.assertAlmostEqual(v.y, d.y)
        self.assertAlmostEqual(v.z, d.z)
Beispiel #36
0
    def test_get_rgba(self):
        code = """
v1 = get_rgba(image1, 10, 10)
        """
        image = ImageRGBA(200, 200)
        image.set_pixel(10, 10, 25, 77, 142, 185)
        p1 = StructArg('image1', image)
        p2 = Vec4Arg('v1', Vector4(0.0, 0.0, 0.0, 0.0))

        shader = Shader(code=code, args=[p1, p2])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        val = shader.get_value('v1')
        self.assertAlmostEqual(val.x, 25 * 0.0039, places=6)
        self.assertAlmostEqual(val.y, 77 * 0.0039)
        self.assertAlmostEqual(val.z, 142 * 0.0039)
        self.assertAlmostEqual(val.w, 185 * 0.0039)
Beispiel #37
0
    def test_get_prgba(self):
        code = """
v1 = get_rgba(image1, 10, 10)
        """
        image = ImagePRGBA(200, 200)
        image.set_pixel(10, 10, 0.23, 0.28, 0.55, 0.8)
        p1 = StructArg('image1', image)
        p2 = Vec4Arg('v1', Vector4(0.0, 0.0, 0.0, 0.0))

        shader = Shader(code=code, args=[p1, p2])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        val = shader.get_value('v1')
        self.assertAlmostEqual(val.x, 0.23)
        self.assertAlmostEqual(val.y, 0.28)
        self.assertAlmostEqual(val.z, 0.55)
        self.assertAlmostEqual(val.w, 0.8)
Beispiel #38
0
    def test_get_rgba(self):
        code = """
v1 = get_rgba(image1, 10, 10)
        """
        image = ImageRGBA(200, 200)
        image.set_pixel(10, 10, 25, 77, 142, 185)
        p1 = StructArg('image1', image)
        p2 = Vec4Arg('v1', Vector4(0.0, 0.0, 0.0, 0.0))

        shader = Shader(code=code, args=[p1, p2])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        val = shader.get_value('v1')
        self.assertAlmostEqual(val.x, 25 * 0.0039, places=6)
        self.assertAlmostEqual(val.y, 77 * 0.0039)
        self.assertAlmostEqual(val.z, 142 * 0.0039)
        self.assertAlmostEqual(val.w, 185 * 0.0039)
Beispiel #39
0
    def test_get_prgba(self):
        code = """
v1 = get_rgba(image1, 10, 10)
        """
        image = ImagePRGBA(200, 200)
        image.set_pixel(10, 10, 0.23, 0.28, 0.55, 0.8)
        p1 = StructArg('image1', image)
        p2 = Vec4Arg('v1', Vector4(0.0, 0.0, 0.0, 0.0))

        shader = Shader(code=code, args=[p1, p2])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        val = shader.get_value('v1')
        self.assertAlmostEqual(val.x, 0.23)
        self.assertAlmostEqual(val.y, 0.28)
        self.assertAlmostEqual(val.z, 0.55)
        self.assertAlmostEqual(val.w, 0.8)
Beispiel #40
0
    def test_assign_sampled_spectrum(self):
        code = """
p2 = p1
        """
        vals = [(450, 0.33), (480, 0.45)]
        samples = create_samples(vals, 32, 400, 700)
        p1 = SampledArg('p1', SampledSpectrum(samples))
        vals = [(430, 0.23), (480, 0.55), (600, 0.77)]
        samples2 = create_samples(vals, 32, 400, 700)
        p2 = SampledArg('p2', SampledSpectrum(samples2))

        shader = Shader(code=code, args=[p1, p2])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        v = shader.get_value('p2')
        for val1, val2 in zip(samples, v.samples):
            self.assertAlmostEqual(val1, val2)
Beispiel #41
0
    def test_rgb_lum(self):

        shader = lum_rgb_shader()
        shader.compile()
        runtime = Runtime()
        shader.prepare([runtime])

        code = """
rez = lumminance(r1)
        """
        s = RGBArg('r1', RGBSpectrum(0.2, 0.3, 0.4))
        rez = FloatArg('rez', 0.0)
        shader2 = Shader(code=code, args=[rez, s])
        shader2.compile([shader])
        shader2.prepare([runtime])
        shader2.execute()

        lum = 0.2 * 0.212671 + 0.3 * 0.715160 + 0.4 * 0.072169
        val = shader2.get_value('rez')
        self.assertAlmostEqual(lum, val)
Beispiel #42
0
    def test_rgb_lum(self):

        shader = lum_rgb_shader()
        shader.compile()
        runtime = Runtime()
        shader.prepare([runtime])

        code = """
rez = lumminance(r1)
        """
        s = RGBArg('r1', RGBSpectrum(0.2, 0.3, 0.4))
        rez = FloatArg('rez', 0.0)
        shader2 = Shader(code=code, args=[rez, s])
        shader2.compile([shader])
        shader2.prepare([runtime])
        shader2.execute()

        lum = 0.2 * 0.212671 + 0.3 * 0.715160 + 0.4 * 0.072169
        val = shader2.get_value('rez')
        self.assertAlmostEqual(lum, val)
Beispiel #43
0
    def test_rgb_spec_to_vec(self):

        shader = rgb_to_vec_shader()
        shader.compile()
        runtime = Runtime()
        shader.prepare([runtime])

        code = """
rez = spectrum_to_vec(r1)
        """
        s = RGBArg('r1', RGBSpectrum(0.2, 0.3, 0.4))
        rez = Vec3Arg('rez', Vector3(0.0, 0.0, 0.0))
        shader2 = Shader(code=code, args=[rez, s])
        shader2.compile([shader])
        shader2.prepare([runtime])
        shader2.execute()

        val = shader2.get_value('rez')
        self.assertAlmostEqual(val.x, 0.2)
        self.assertAlmostEqual(val.y, 0.3)
        self.assertAlmostEqual(val.z, 0.4)
Beispiel #44
0
    def test_normalize_fun(self):
        code = """
p2 = normalize(p1)
        """
        v1 = Vector3(2.5, 1.8, 2.9)
        v2 = Vector3(6.5, 9.8, 3.9)
        p1 = Vec3Arg('p1', v1)
        p2 = Vec3Arg('p2', v2)

        shader = Shader(code=code, args=[p1, p2])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        v3 = Vector3(2.5, 1.8, 2.9)
        v3.normalize()

        p = shader.get_value('p2')
        self.assertAlmostEqual(p.x, v3.x)
        self.assertAlmostEqual(p.y, v3.y)
        self.assertAlmostEqual(p.z, v3.z)
Beispiel #45
0
    def test_float2(self):
        code = """
temp = 5
temp2 = 9.9
p1 = float2(temp, temp2)
p2 = float2(2, 3.3)
        """
        p1 = Vec2Arg('p1', Vector2(0.0, 1.0))
        p2 = Vec2Arg('p2', Vector2(0.0, 1.0))

        shader = Shader(code=code, args=[p1, p2])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        p = shader.get_value('p1')
        self.assertAlmostEqual(p.x, 5.0)
        self.assertAlmostEqual(p.y, 9.9, places=6)
        p = shader.get_value('p2')
        self.assertAlmostEqual(p.x, 2.0)
        self.assertAlmostEqual(p.y, 3.3)
Beispiel #46
0
    def test_rgb_spec_to_vec(self):

        shader = rgb_to_vec_shader()
        shader.compile()
        runtime = Runtime()
        shader.prepare([runtime])

        code = """
rez = spectrum_to_vec(r1)
        """
        s = RGBArg('r1', RGBSpectrum(0.2, 0.3, 0.4))
        rez = Vec3Arg('rez', Vector3(0.0, 0.0, 0.0))
        shader2 = Shader(code=code, args=[rez, s])
        shader2.compile([shader])
        shader2.prepare([runtime])
        shader2.execute()

        val = shader2.get_value('rez')
        self.assertAlmostEqual(val.x, 0.2)
        self.assertAlmostEqual(val.y, 0.3)
        self.assertAlmostEqual(val.z, 0.4)
Beispiel #47
0
    def test_corss_fun(self):
        code = """
p3 = cross(p1, p2)
        """
        v1 = Vector3(2.5, 1.8, 2.9)
        v2 = Vector3(2.5, 1.8, 3.9)
        v3 = Vector3(0.0, 0.0, 0.0)
        p1 = Vec3Arg('p1', v1)
        p2 = Vec3Arg('p2', v2)
        p3 = Vec3Arg('p3', v3)

        shader = Shader(code=code, args=[p1, p2, p3])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        v4 = v1.cross(v2)

        p = shader.get_value('p3')
        self.assertAlmostEqual(p.x, v4.x, places=6)
        self.assertAlmostEqual(p.y, v4.y, places=6)
        self.assertAlmostEqual(p.z, v4.z, places=6)
Beispiel #48
0
    def test_con(self):
        code = """
a = 33
if a:
    p1 = 22

b = 22
if b > 15:
    p2 = 1.1

tmp = 4.4
tmp2 = 1.2
if tmp > tmp2:
    p3 = 2.2

tmp = 5.5
if tmp2 < tmp:
    p4 = 1.5

        """

        p1 = IntArg('p1', 55)
        p2 = FloatArg('p2', 4.4)
        p3 = FloatArg('p3', 9.4)
        p4 = FloatArg('p4', 2.4)

        shader = Shader(code=code, args=[p1, p2, p3, p4])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        p = shader.get_value('p1')
        self.assertEqual(p, 22)
        p = shader.get_value('p2')
        self.assertAlmostEqual(p, 1.1)
        p = shader.get_value('p3')
        self.assertAlmostEqual(p, 2.2)
        p = shader.get_value('p4')
        self.assertAlmostEqual(p, 1.5)
Beispiel #49
0
    def test_sampler(self):
        sam = Sampler()
        sam.set_resolution(2, 2)
        sam.load('regular')
        sam.compile()
        runtimes = [Runtime()]
        sam.prepare(runtimes)

        code = """
sample = Sample()
r1 = generate_sample(sample)
p1 = sample.x
p2 = sample.y
p3 = sample.ix
p4 = sample.iy
        """

        p1 = FloatArg('p1', 566.6)
        p2 = FloatArg('p2', 566.6)

        p3 = IntArg('p3', 5655)
        p4 = IntArg('p4', 5655)
        r1 = IntArg('r1', 5655)
        args = [p1, p2, p3, p4, r1]
        shader = Shader(code=code, args=args)
        shader.compile([sam.shader])
        shader.prepare(runtimes)

        shader.execute()
        self._check_result(shader, -0.5, -0.5, 0, 0, 1)
        shader.execute()
        self._check_result(shader, 0.5, -0.5, 1, 0, 1)
        shader.execute()
        self._check_result(shader, -0.5, 0.5, 0, 1, 1)
        shader.execute()
        self._check_result(shader, 0.5, 0.5, 1, 1, 1)
        shader.execute()
        ret = shader.get_value('r1')
        self.assertEqual(ret, 0)
Beispiel #50
0
    def test_con(self):
        code = """
a = 33
if a:
    p1 = 22

b = 22
if b > 15:
    p2 = 1.1

tmp = 4.4
tmp2 = 1.2
if tmp > tmp2:
    p3 = 2.2

tmp = 5.5
if tmp2 < tmp:
    p4 = 1.5

        """

        p1 = IntArg('p1', 55)
        p2 = FloatArg('p2', 4.4)
        p3 = FloatArg('p3', 9.4)
        p4 = FloatArg('p4', 2.4)

        shader = Shader(code=code, args=[p1, p2, p3, p4])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()

        p = shader.get_value('p1')
        self.assertEqual(p, 22)
        p = shader.get_value('p2')
        self.assertAlmostEqual(p, 1.1)
        p = shader.get_value('p3')
        self.assertAlmostEqual(p, 2.2)
        p = shader.get_value('p4')
        self.assertAlmostEqual(p, 1.5)
Beispiel #51
0
    def test_assign(self):
        code = """
k = 55
p1 = k
m = (4, 7)
p2 = m
h = (3.13, 8, 9)
p3 = h
t = (6.6, 2.2, 9, 1)
p4 = t
r = 3.3
p5 = r
        """
        p1 = IntArg('p1', 33)
        p2 = Vec2Arg('p2', Vector2(9, 22))
        p3 = Vec3Arg('p3', Vector3(1, 4.4, 29))
        p4 = Vec4Arg('p4', Vector4(2, 3, 1.1, 2))
        p5 = FloatArg('p5', 87.33)
        shader = Shader(code=code, args=[p1, p2, p3, p4, p5])
        shader.compile()
        shader.prepare([Runtime()])
        shader.execute()
        self.assertEqual(shader.get_value('p1'), 55)
        v = shader.get_value('p2')
        self.assertAlmostEqual(v.x, 4.0)
        self.assertAlmostEqual(v.y, 7.0)
        v = shader.get_value('p3')
        self.assertAlmostEqual(v.x, 3.13, places=6)
        self.assertAlmostEqual(v.y, 8.0)
        self.assertAlmostEqual(v.z, 9.0)
        v = shader.get_value('p4')
        self.assertAlmostEqual(v.x, 6.6, places=6)
        self.assertAlmostEqual(v.y, 2.2)
        self.assertAlmostEqual(v.z, 9.0)
        self.assertAlmostEqual(v.w, 1.0)
        v = shader.get_value('p5')
        self.assertAlmostEqual(v, 3.3)