Beispiel #1
0
    def test_min(self):

        code = """
ret = min(v1, v2)
ret2 = min(r1, r2)
        """
        v1 = Vector3(0.3, 0.2, 0.4)
        v2 = Vector3(0.1, 0.2, 0.5)
        ret = Vector3(0.0, 0.0, 0.0)
        r1 = 0.3
        r2 = 0.6
        ret2 = 0.0

        props = {'ret':ret, 'v1':v1, 'v2':v2, 'r1':r1, 'r2':r2,
                'ret2':ret2}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('ret')
        self.assertAlmostEqual(val.x, min(v1.x, v2.x), 5)
        self.assertAlmostEqual(val.y, min(v1.y, v2.y), 5)
        self.assertAlmostEqual(val.z, min(v1.z, v2.z), 5)
        
        val = bs.shader.get_value('ret2')
        self.assertAlmostEqual(val, min(r1, r2), 5)
Beispiel #2
0
    def test_assign3(self):
        code = """
spec1 = sh.spectrum1
sh.spectrum2 = spec2
        """
        rgb = RGBSpectrum(0.2, 0.3, 0.2)
        rgb2 = RGBSpectrum(0.1, 0.8, 0.9)
        rgb3 = RGBSpectrum(0.5, 0.3, 0.1)
        rgb4 = RGBSpectrum(0.1, 0.2, 0.2)
        sh = ShadePoint(rgb3, rgb4)
        props = {"spec1": rgb, "spec2": rgb2, "sh": sh}
        col_mgr = ColorManager(spectral=False)
        bs = BasicShader(code, props, col_mgr=col_mgr)
        runtime = Runtime()
        bs.prepare([runtime])
        # print (bs.shader._code)

        bs.execute()
        val1 = bs.shader.get_value("spec1")
        val2 = bs.shader.get_value("sh.spectrum1")
        self.assertAlmostEqual(val1.r, val2.r, places=5)
        self.assertAlmostEqual(val1.g, val2.g, places=5)
        self.assertAlmostEqual(val1.b, val2.b, places=5)
        val1 = bs.shader.get_value("spec2")
        val2 = bs.shader.get_value("sh.spectrum2")
        self.assertAlmostEqual(val1.r, val2.r, places=5)
        self.assertAlmostEqual(val1.g, val2.g, places=5)
        self.assertAlmostEqual(val1.b, val2.b, places=5)
Beispiel #3
0
    def test_pow(self):
        code = """
ret = pow(1.4, 4.4)
ret2 = pow((1.1, 1.25), (2.1, 3.1))
ret3 = pow((1.3, 1.7, 1.8), (1.11, 2.11, 1.45))
ret4 = pow((1.9, 1.15, 2.11, 2.22), (1.77, 2.21, 2.5, 2.71))
        """
        props = {
            'ret': 1.1,
            'ret2': Vector2(2.2, 4),
            'ret3': Vector3(5, 6, 7),
            'ret4': Vector4(11, 1, 1, 1)
        }
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('ret')
        self.assertAlmostEqual(val, pow(1.4, 4.4), places=3)
        val = bs.shader.get_value('ret2')
        self.assertAlmostEqual(val.x, pow(1.1, 2.1), places=3)
        self.assertAlmostEqual(val.y, pow(1.25, 3.1), places=3)
        val = bs.shader.get_value('ret3')
        self.assertAlmostEqual(val.x, pow(1.3, 1.11), places=3)
        self.assertAlmostEqual(val.y, pow(1.7, 2.11), places=3)
        self.assertAlmostEqual(val.z, pow(1.8, 1.45), places=3)
        val = bs.shader.get_value('ret4')
        self.assertAlmostEqual(val.x, pow(1.9, 1.77), places=3)
        self.assertAlmostEqual(val.y, pow(1.15, 2.21), places=3)
        self.assertAlmostEqual(val.z, pow(2.11, 2.5), places=3)
        self.assertAlmostEqual(val.w, pow(2.22, 2.71), places=3)
Beispiel #4
0
    def math_fun_test(self, fun, py_fun):
        num = random()
        nums = (random(), random())

        line1 = "ret = %s(%f)\n" % (fun, num)
        line2 = "ret2 = %s((%f, %f))\n" % (fun, nums[0], nums[1])
        code = line1 + line2

        props = {
            'ret': 1.1,
            'ret2': Vector2(2.2, 4),
            'ret3': Vector3(5, 6, 7),
            'ret4': Vector4(11, 1, 1, 1)
        }
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()

        val = bs.shader.get_value('ret')
        self.assertAlmostEqual(val, py_fun(num), places=3)
        val = bs.shader.get_value('ret2')
        self.assertAlmostEqual(val.x, py_fun(nums[0]), places=3)
        self.assertAlmostEqual(val.y, py_fun(nums[1]), places=3)
Beispiel #5
0
def performance_regular_sampler(width, height):
    sam = RegularSampler(width, height)
    runtimes = [Runtime(), Runtime(), Runtime(), Runtime()]
    sam.prepare(runtimes)
    sam.set_pass(0)

    code = """
ret = 1
nsamples = 0
while ret != 0:
    ret = generate_sample(sample)
    if ret == 0:
        break
    nsamples = nsamples + 1
    """
    sample = Sample(0.0, 0.0, 0, 0, 1.0)
    props = {'sample': sample, 'ret': 0, 'nsamples': 0}
    bas = BasicShader(code, props)
    bas.prepare(runtimes, [sam.shader])

    start = time.clock()
    bas.execute()
    end = time.clock()
    print("Exectution of generating %i samples took %f" %
          (bas.shader.get_value('nsamples'), end - start))
Beispiel #6
0
    def test_float1(self):
        v = Vector2(1,1)
        v2 = Vector2(1,1)
        v3 = Vector3(1,1,1)
        v4 = Vector4(1,1,1,1)

        code = """
ret = float2(5,6)
ret2 = float2(aa, bb)
ret3 = float3(8,9.5,3)
temp = (8,9,1,2)
ret4 = float4(temp[1],5.3,6, aa)
        """
        props = {'aa':3.4, 'bb':77, 'ret':v, 'ret2':v2, 'ret3':v3, 'ret4':v4}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('ret')
        self.assertAlmostEqual(val.x, 5.0, places=5)
        self.assertAlmostEqual(val.y, 6.0, places=5)
        val = bs.shader.get_value('ret2')
        self.assertAlmostEqual(val.x, 3.4, places=5)
        self.assertAlmostEqual(val.y, 77.0, places=5)
        val = bs.shader.get_value('ret3')
        self.assertAlmostEqual(val.x, 8.0, places=5)
        self.assertAlmostEqual(val.y, 9.5, places=5)
        self.assertAlmostEqual(val.z, 3.0, places=5)
        val = bs.shader.get_value('ret4')
        self.assertAlmostEqual(val.x, 9.0, places=5)
        self.assertAlmostEqual(val.y, 5.3, places=5)
        self.assertAlmostEqual(val.z, 6.0, places=5)
        self.assertAlmostEqual(val.w, 3.4, places=5)
Beispiel #7
0
    def test_assign3(self):
        code = """
spec1 = sh.spectrum1
sh.spectrum2 = spec2
        """
        rgb = RGBSpectrum(0.2, 0.3, 0.2)
        rgb2 = RGBSpectrum(0.1, 0.8, 0.9)
        rgb3 = RGBSpectrum(0.5, 0.3, 0.1)
        rgb4 = RGBSpectrum(0.1, 0.2, 0.2)
        sh = ShadePoint(rgb3, rgb4)
        props = {'spec1': rgb, 'spec2': rgb2, 'sh': sh}
        col_mgr = ColorManager(spectral=False)
        bs = BasicShader(code, props, col_mgr=col_mgr)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val1 = bs.shader.get_value('spec1')
        val2 = bs.shader.get_value('sh.spectrum1')
        self.assertAlmostEqual(val1.r, val2.r, places=5)
        self.assertAlmostEqual(val1.g, val2.g, places=5)
        self.assertAlmostEqual(val1.b, val2.b, places=5)
        val1 = bs.shader.get_value('spec2')
        val2 = bs.shader.get_value('sh.spectrum2')
        self.assertAlmostEqual(val1.r, val2.r, places=5)
        self.assertAlmostEqual(val1.g, val2.g, places=5)
        self.assertAlmostEqual(val1.b, val2.b, places=5)
Beispiel #8
0
    def test_assign4(self):
        code = """
spec1 = sh.spectrum1
sh.spectrum2 = spec2
        """

        nsamples = 32
        rgb = SampledSpectrum([0.1] * nsamples)
        rgb2 = SampledSpectrum([0.2] * nsamples)
        rgb3 = SampledSpectrum([0.3] * nsamples)
        rgb4 = SampledSpectrum([0.4] * nsamples)

        sh = ShadePoint(rgb3, rgb4)
        props = {'spec1': rgb, 'spec2': rgb2, 'sh': sh}
        col_mgr = ColorManager(spectral=True)
        col_mgr._nsamples = 32  #NOTE HACK - just for testing spectrum asm commands
        bs = BasicShader(code, props, col_mgr=col_mgr)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val1 = bs.shader.get_value('spec1')
        val2 = bs.shader.get_value('sh.spectrum1')
        for i in range(nsamples):
            self.assertAlmostEqual(val1.samples[i], val2.samples[i], places=5)
        val1 = bs.shader.get_value('spec2')
        val2 = bs.shader.get_value('sh.spectrum2')
        for i in range(nsamples):
            self.assertAlmostEqual(val1.samples[i], val2.samples[i], places=5)
Beispiel #9
0
    def test_assign4(self):
        code = """
spec1 = sh.spectrum1
sh.spectrum2 = spec2
        """

        nsamples = 32
        rgb = SampledSpectrum([0.1] * nsamples)
        rgb2 = SampledSpectrum([0.2] * nsamples)
        rgb3 = SampledSpectrum([0.3] * nsamples)
        rgb4 = SampledSpectrum([0.4] * nsamples)

        sh = ShadePoint(rgb3, rgb4)
        props = {"spec1": rgb, "spec2": rgb2, "sh": sh}
        col_mgr = ColorManager(spectral=True)
        col_mgr._nsamples = 32  # NOTE HACK - just for testing spectrum asm commands
        bs = BasicShader(code, props, col_mgr=col_mgr)
        runtime = Runtime()
        bs.prepare([runtime])
        # print (bs.shader._code)

        bs.execute()
        val1 = bs.shader.get_value("spec1")
        val2 = bs.shader.get_value("sh.spectrum1")
        for i in range(nsamples):
            self.assertAlmostEqual(val1.samples[i], val2.samples[i], places=5)
        val1 = bs.shader.get_value("spec2")
        val2 = bs.shader.get_value("sh.spectrum2")
        for i in range(nsamples):
            self.assertAlmostEqual(val1.samples[i], val2.samples[i], places=5)
Beispiel #10
0
    def test_arith2(self):
        code = """
spec3 = spec1 + spec2
spec4 = spec1 * 0.3
spec5 = 2 * spec2
        """

        nsamples = 32
        rgb = SampledSpectrum([0.1]*nsamples)
        rgb2 = SampledSpectrum([0.2]*nsamples)
        rgb3 = SampledSpectrum([0.3]*nsamples)
        rgb4 = SampledSpectrum([0.4]*nsamples)
        rgb5 = SampledSpectrum([0.5]*nsamples)

        props = {'spec1':rgb, 'spec2':rgb2, 'spec3':rgb3, 'spec4':rgb4, 'spec5':rgb5}
        col_mgr = ColorManager(spectral=True)
        col_mgr._nsamples = 32 #NOTE HACK - just for testing spectrum asm commands 
        bs = BasicShader(code, props, col_mgr=col_mgr)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()

        val = bs.shader.get_value('spec3')
        for i in range(nsamples):
            self.assertAlmostEqual(val.samples[i], rgb.samples[i] + rgb2.samples[i], places=5)
        val = bs.shader.get_value('spec4')
        for i in range(nsamples):
            self.assertAlmostEqual(val.samples[i], rgb.samples[i] * 0.3, places=5)
        val = bs.shader.get_value('spec5')
        for i in range(nsamples):
            self.assertAlmostEqual(val.samples[i], rgb2.samples[i] * 2, places=5)
Beispiel #11
0
    def test_arith1(self):

        code = """
spec3 = spec1 + spec2
spec4 = spec1 * 4
spec5 = 8 * spec2
        """
        rgb = RGBSpectrum(0.2, 0.3, 0.2)
        rgb2 = RGBSpectrum(0.1, 0.2, 0.3)
        rgb3 = RGBSpectrum(0.0, 0.0, 0.0)
        rgb4 = RGBSpectrum(0.0, 0.0, 0.0)
        rgb5 = RGBSpectrum(0.0, 0.0, 0.0)
        props = {'spec1':rgb, 'spec2':rgb2, 'spec3':rgb3, 'spec4':rgb4,
                'spec5':rgb5}
        col_mgr = ColorManager(spectral=False)
        bs = BasicShader(code, props, col_mgr=col_mgr)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val1 = bs.shader.get_value('spec3')
        self.assertAlmostEqual(val1.r, 0.2+0.1, places=5)
        self.assertAlmostEqual(val1.g, 0.3+0.2, places=5)
        self.assertAlmostEqual(val1.b, 0.2+0.3, places=5)
        val1 = bs.shader.get_value('spec4')
        self.assertAlmostEqual(val1.r, 0.2*4, places=5)
        self.assertAlmostEqual(val1.g, 0.3*4, places=5)
        self.assertAlmostEqual(val1.b, 0.2*4, places=5)
        val1 = bs.shader.get_value('spec5')
        self.assertAlmostEqual(val1.r, 0.1*8, places=5)
        self.assertAlmostEqual(val1.g, 0.2*8, places=5)
        self.assertAlmostEqual(val1.b, 0.3*8, places=5)
Beispiel #12
0
    def test_assign1(self):

        code = """
v2[1] = v1[0]
p1.position[2] = p1.size[0]

        """
        p1 = Point(Vector3(2.2, 4.4, 7.7), Vector2(3.3, 5.5),
                   Vector4(1.1, 2.2, 3.3, 4.4))
        props = {
            'v1': Vector2(8.3, 6.0),
            'v2': Vector3(5.6, 3.3, 2.2),
            'v3': Vector4(4.4, 6.6, 2.2, 9.9),
            'ret': 0.0,
            'p1': p1
        }
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val1 = bs.shader.get_value('v2')
        val2 = bs.shader.get_value('v1')
        self.assertAlmostEqual(val1.y, val2.x, places=5)
        val1 = bs.shader.get_value('p1.position')
        val2 = bs.shader.get_value('p1.size')
        self.assertAlmostEqual(val1.z, val2.x, places=5)
Beispiel #13
0
    def test_assign1(self):

        code = """
m1 = 77
a = m1
m1 = -45
b = m1
m1 = 3.4
c = m1
m1 = -8.8
d = m1
m1 = (-8, 5.1)
e = m1
m1 = (-1, 2.25, 7)
f = m1
m1 = (8, -2.33, -7, 1)
k = m1
        """
        props = {
            'aa': 333,
            'a': 111,
            'b': 250,
            'c': 4.4,
            'd': 1.1,
            'e': Vector2(2.3, 6.0),
            'f': Vector3(5.6, 3.3, 2.2),
            'k': Vector4(4.4, 6.6, 2.2, 9.9)
        }
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()

        val = bs.shader.get_value('a')
        self.assertEqual(77, val)
        val = bs.shader.get_value('b')
        self.assertEqual(-45, val)
        val = bs.shader.get_value('c')
        self.assertAlmostEqual(val, 3.4, places=5)
        val = bs.shader.get_value('d')
        self.assertAlmostEqual(val, -8.8, places=5)

        val = bs.shader.get_value('e')
        self.assertAlmostEqual(val.x, -8.0, places=5)
        self.assertAlmostEqual(val.y, 5.1, places=5)

        val = bs.shader.get_value('f')
        self.assertAlmostEqual(val.x, -1.0, places=5)
        self.assertAlmostEqual(val.y, 2.25, places=5)
        self.assertAlmostEqual(val.z, 7.0, places=5)

        val = bs.shader.get_value('k')
        self.assertAlmostEqual(val.x, 8.0, places=5)
        self.assertAlmostEqual(val.y, -2.33, places=5)
        self.assertAlmostEqual(val.z, -7.0, places=5)
        self.assertAlmostEqual(val.w, 1.0, places=5)
Beispiel #14
0
    def test_assign1(self):

        code = """
shadepoint.light_intensity = spectrum(0.25)

sample = sample_hemisphere()
sample = (0.6, 0.4, 0.8)
#w = hitpoint.normal 

w = (2.3, 2.5, 8.8)
w = normalize(w)
tv = (0.0034, 1.0, 0.0071)
v = cross(tv, w)
v = normalize(v)
u = cross(v, w)
ndir = u * sample[0] + v * sample[1] + w * sample[2]
shadepoint.wi = normalize(ndir)

shadepoint.pdf = dot(w, shadepoint.wi) * 0.318309886

        """
        props = {}
        col_mgr = ColorManager(spectral=True)
        brdf = SurfaceShader(code, props, col_mgr=col_mgr)
        mat = Material(bsdf=brdf)
        mgr = MaterialManager()
        mgr.add('blue_velvet', mat)
        runtime = Runtime()
        runtime2 = Runtime()
        runtimes = [runtime, runtime2]

        #bs.prepare([runtime])
        shader = mgr.prepare_bsdf('brdf', runtimes)
        #print (bs.shader._code)

        #bs.execute()
        sh = ShadePoint()
        code = """
hp = Hitpoint()
sp = Shadepoint()
brdf(hp, sp, 0)
spec = sp.light_intensity
wi = sp.wi
pdf = sp.pdf
        """
        wi = Vector3(2, 2, 2)
        spec = col_mgr.black()
        props = {'spec': spec, 'wi': wi, 'pdf': 0.0}
        bs = BasicShader(code, props, col_mgr=col_mgr)
        bs.prepare(runtimes, shaders=[shader])
        print (bs.shader._code)

        bs.execute()

        print(bs.shader.get_value('spec'))
        print(bs.shader.get_value('wi'))
        print(bs.shader.get_value('pdf'))
        print(next_direction())
Beispiel #15
0
    def test_arith1(self):

        code = """
r1 = a1 + a2
r2 = a1 * a2 
r3 = a4 * (0.5, 0.5)
r4 = a5 / (0.5, 0.5, 0.5)
r5 = (7,7,7,7) + a6 
r6 = a3 / 3
r7 = a7 % 18
        """
        props = {
            'a1': 1.1,
            'a2': 2.2,
            'r1': 1.1,
            'r2': 3.3,
            'a3': 55,
            'a4': Vector2(2.2, 4),
            'a5': Vector3(5, 6, 7),
            'a6': Vector4(3, 4, 5, 6),
            'r3': Vector2(3, 4),
            'r4': Vector3(1, 1, 1),
            'r5': Vector4(11, 1, 1, 1),
            'r6': 88,
            'a7': 789,
            'r7': 1
        }
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('r1')
        self.assertAlmostEqual(val, 2.2 + 1.1, places=5)
        val = bs.shader.get_value('r2')
        self.assertAlmostEqual(val, 1.1 * 2.2, places=5)
        val = bs.shader.get_value('r3')
        self.assertAlmostEqual(val.x, 2.2 * 0.5, places=5)
        self.assertAlmostEqual(val.y, 4.0 * 0.5, places=5)
        val = bs.shader.get_value('r4')
        self.assertAlmostEqual(val.x, 5 * 2.0, places=5)
        self.assertAlmostEqual(val.y, 6 * 2.0, places=5)
        self.assertAlmostEqual(val.z, 7 * 2.0, places=5)
        val = bs.shader.get_value('r5')
        self.assertAlmostEqual(val.x, 7 + 3.0, places=5)
        self.assertAlmostEqual(val.y, 7 + 4.0, places=5)
        self.assertAlmostEqual(val.z, 7 + 5.0, places=5)
        self.assertAlmostEqual(val.w, 7 + 6.0, places=5)
        val = bs.shader.get_value('r6')
        self.assertEqual(val, 55 // 3)
        val = bs.shader.get_value('r7')
        self.assertEqual(val, 789 % 18)
Beispiel #16
0
    def test_const1(self):
        pass

        code = """
a = 555
b = -36
c = 2.3
d = -9.8
e = (2.3, 5)
f = (2.2, 4.77, -2.66)
k = (-1.23, 1.44, 9, 7.7)
        """

        props = {
            'a': 111,
            'b': 250,
            'c': 4.4,
            'd': 1.1,
            'e': Vector2(2.3, 6.0),
            'f': Vector3(5.6, 3.3, 2.2),
            'k': Vector4(4.4, 6.6, 2.2, 9.9)
        }
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('a')
        val2 = bs.shader.get_value('b')
        val3 = bs.shader.get_value('c')
        val4 = bs.shader.get_value('d')
        self.assertEqual(555, val)
        self.assertEqual(-36, val2)
        self.assertAlmostEqual(val3, 2.3, places=5)
        self.assertAlmostEqual(val4, -9.8, places=5)

        val5 = bs.shader.get_value('e')
        self.assertAlmostEqual(val5.x, 2.3, places=5)
        self.assertAlmostEqual(val5.y, 5.0, places=5)

        val6 = bs.shader.get_value('f')
        self.assertAlmostEqual(val6.x, 2.2, places=5)
        self.assertAlmostEqual(val6.y, 4.77, places=5)
        self.assertAlmostEqual(val6.z, -2.66, places=5)

        val7 = bs.shader.get_value('k')
        self.assertAlmostEqual(val7.x, -1.23, places=5)
        self.assertAlmostEqual(val7.y, 1.44, places=5)
        self.assertAlmostEqual(val7.z, 9.0, places=5)
        self.assertAlmostEqual(val7.w, 7.7, places=5)
Beispiel #17
0
    def test_assign1(self):

        code = """
m1 = 77
a = m1
m1 = -45
b = m1
m1 = 3.4
c = m1
m1 = -8.8
d = m1
m1 = (-8, 5.1)
e = m1
m1 = (-1, 2.25, 7)
f = m1
m1 = (8, -2.33, -7, 1)
k = m1
        """
        props = {'aa':333, 'a':111, 'b':250, 'c':4.4, 'd':1.1,
                'e': Vector2(2.3, 6.0), 'f': Vector3(5.6, 3.3, 2.2),
                'k': Vector4(4.4, 6.6, 2.2, 9.9)}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()

        val = bs.shader.get_value('a')
        self.assertEqual(77, val)
        val = bs.shader.get_value('b')
        self.assertEqual(-45, val)
        val = bs.shader.get_value('c')
        self.assertAlmostEqual(val, 3.4, places=5)
        val = bs.shader.get_value('d')
        self.assertAlmostEqual(val, -8.8, places=5)

        val = bs.shader.get_value('e')
        self.assertAlmostEqual(val.x, -8.0, places=5)
        self.assertAlmostEqual(val.y, 5.1, places=5)

        val = bs.shader.get_value('f')
        self.assertAlmostEqual(val.x, -1.0, places=5)
        self.assertAlmostEqual(val.y, 2.25, places=5)
        self.assertAlmostEqual(val.z, 7.0, places=5)

        val = bs.shader.get_value('k')
        self.assertAlmostEqual(val.x, 8.0, places=5)
        self.assertAlmostEqual(val.y, -2.33, places=5)
        self.assertAlmostEqual(val.z, -7.0, places=5)
        self.assertAlmostEqual(val.w, 1.0, places=5)
Beispiel #18
0
    def test_get_item(self):
        arr = FloatArray(values=(2, 3, 4, 5, 6, 7))
        code = """
index = 3
num = get_item(arr, index)
        """
        props = {'arr': arr, 'num': 2.3}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('num')
        self.assertAlmostEqual(val, 5.0, places=5)
Beispiel #19
0
    def test_get_item(self):
        arr = FloatArray(values=(2,3,4,5,6,7))
        code = """
index = 3
num = get_item(arr, index)
        """
        props = {'arr': arr, 'num': 2.3}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('num')
        self.assertAlmostEqual(val, 5.0, places=5)
Beispiel #20
0
    def test_arith2(self):

        code = """
r1 = a1 + 5
r2 = 4 * a2

r3 = 8 * a4
r4 = a5 * 1.1

r5 = a6 * 0.5

        """
        props = {
            'a1': 1.1,
            'a2': 2.2,
            'r1': 1.1,
            'r2': 3.3,
            'a3': 55,
            'a4': Vector2(2.2, 4),
            'a5': Vector3(5, 6, 7),
            'a6': Vector4(3, 4, 5, 6),
            'r3': Vector2(3, 4),
            'r4': Vector3(1, 1, 1),
            'r5': Vector4(11, 1, 1, 1)
        }
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('r1')
        self.assertAlmostEqual(val, 1.1 + 5, places=5)
        val = bs.shader.get_value('r2')
        self.assertAlmostEqual(val, 4 * 2.2, places=5)
        val = bs.shader.get_value('r3')
        self.assertAlmostEqual(val.x, 8 * 2.2, places=5)
        self.assertAlmostEqual(val.y, 8 * 4.0, places=5)
        val = bs.shader.get_value('r4')
        self.assertAlmostEqual(val.x, 1.1 * 5, places=5)
        self.assertAlmostEqual(val.y, 1.1 * 6, places=5)
        self.assertAlmostEqual(val.z, 1.1 * 7, places=5)
        val = bs.shader.get_value('r5')
        self.assertAlmostEqual(val.x, 0.5 * 3, places=5)
        self.assertAlmostEqual(val.y, 0.5 * 4, places=5)
        self.assertAlmostEqual(val.z, 0.5 * 5, places=5)
        self.assertAlmostEqual(val.w, 0.5 * 6, places=5)
Beispiel #21
0
    def test_lum2(self):

        code = """
ret = luminance(spec1)
        """
        rgb = RGBSpectrum(0.2, 0.3, 0.2)
        props = {'spec1': rgb, 'ret': 0.0}
        col_mgr = ColorManager(spectral=False)
        bs = BasicShader(code, props, col_mgr=col_mgr)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        lum1 = col_mgr.Y(rgb)
        lum2 = bs.shader.get_value('ret')
        self.assertAlmostEqual(lum1, lum2, places=5)
Beispiel #22
0
    def test_arith1(self):

        code = """
ret = dot(v1, v2)
        """
        v1 = Vector3(0.3, 0.2, 0.4)
        v2 = Vector3(0.1, 0.2, 0.5)
        props = {"ret": 0.0, "v1": v1, "v2": v2}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        # print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value("ret")
        val2 = v1.dot(v2)
        self.assertAlmostEqual(val, val2, 4)
Beispiel #23
0
    def test_int1(self):

        code = """
aa = int(-3.4)
ret = int(bb)
        """
        props = {'aa': 333, 'bb': 4.4, 'ret': 0}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('aa')
        self.assertEqual(-3, val)
        val = bs.shader.get_value('ret')
        self.assertEqual(4, val)
Beispiel #24
0
    def test_lum2(self):

        code = """
ret = luminance(spec1)
        """
        rgb = RGBSpectrum(0.2, 0.3, 0.2)
        props = {'spec1':rgb, 'ret':0.0}
        col_mgr = ColorManager(spectral=False)
        bs = BasicShader(code, props, col_mgr=col_mgr)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        lum1 = col_mgr.Y(rgb)
        lum2 = bs.shader.get_value('ret')
        self.assertAlmostEqual(lum1, lum2, places=5)
Beispiel #25
0
    def test_arith1(self):

        code = """
ret = dot(v1, v2)
        """
        v1 = Vector3(0.3, 0.2, 0.4)
        v2 = Vector3(0.1, 0.2, 0.5)
        props = {'ret':0.0, 'v1':v1, 'v2':v2}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('ret')
        val2 = v1.dot(v2)
        self.assertAlmostEqual(val, val2, 4)
Beispiel #26
0
    def test_int1(self):

        code = """
aa = int(-3.4)
ret = int(bb)
        """
        props = {'aa':333, 'bb':4.4, 'ret':0}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('aa')
        self.assertEqual(-3, val)
        val = bs.shader.get_value('ret')
        self.assertEqual(4, val)
Beispiel #27
0
    def test_const1(self):
        pass

        code = """
a = 555
b = -36
c = 2.3
d = -9.8
e = (2.3, 5)
f = (2.2, 4.77, -2.66)
k = (-1.23, 1.44, 9, 7.7)
        """

        props = {'a':111, 'b':250, 'c':4.4, 'd':1.1,
                'e': Vector2(2.3, 6.0), 'f': Vector3(5.6, 3.3, 2.2),
                'k': Vector4(4.4, 6.6, 2.2, 9.9)}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('a')
        val2 = bs.shader.get_value('b')
        val3 = bs.shader.get_value('c')
        val4 = bs.shader.get_value('d')
        self.assertEqual(555, val)
        self.assertEqual(-36, val2)
        self.assertAlmostEqual(val3, 2.3, places=5)
        self.assertAlmostEqual(val4, -9.8, places=5)

        val5 = bs.shader.get_value('e')
        self.assertAlmostEqual(val5.x, 2.3, places=5)
        self.assertAlmostEqual(val5.y, 5.0, places=5)

        val6 = bs.shader.get_value('f')
        self.assertAlmostEqual(val6.x, 2.2, places=5)
        self.assertAlmostEqual(val6.y, 4.77, places=5)
        self.assertAlmostEqual(val6.z, -2.66, places=5)

        val7 = bs.shader.get_value('k')
        self.assertAlmostEqual(val7.x, -1.23, places=5)
        self.assertAlmostEqual(val7.y, 1.44, places=5)
        self.assertAlmostEqual(val7.z, 9.0, places=5)
        self.assertAlmostEqual(val7.w, 7.7, places=5)
Beispiel #28
0
    def test_assign2(self):
        register_user_type(Point)
        p1 = Point(33, 77, 99, 3.5, Vector3(2.2, 4.4, 7.7), Vector2(3.3, 5.5),
                   Vector4(1.1, 2.2, 3.3, 4.4))
        code = """
idx = p1.idx
p1.x = 55
pp = 555
p1.y = pp
g = 4.8
p1.radius = g
g = (4,5,6)
p1.position = g
p1.size = (6,7)
p1.pp = (8,1,3,4)

        """
        props = {'p1': p1, 'idx': 44}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()

        val = bs.shader.get_value('idx')
        self.assertEqual(33, val)
        val = bs.shader.get_value('p1.x')
        self.assertEqual(55, val)
        val = bs.shader.get_value('p1.y')
        self.assertEqual(555, val)
        val = bs.shader.get_value('p1.radius')
        self.assertAlmostEqual(val, 4.8, places=5)
        val = bs.shader.get_value('p1.position')
        self.assertAlmostEqual(val.x, 4.0, places=5)
        self.assertAlmostEqual(val.y, 5.0, places=5)
        self.assertAlmostEqual(val.z, 6.0, places=5)
        val = bs.shader.get_value('p1.size')
        self.assertAlmostEqual(val.x, 6.0, places=5)
        self.assertAlmostEqual(val.y, 7.0, places=5)
        val = bs.shader.get_value('p1.pp')
        self.assertAlmostEqual(val.x, 8.0, places=5)
        self.assertAlmostEqual(val.y, 1.0, places=5)
        self.assertAlmostEqual(val.z, 3.0, places=5)
        self.assertAlmostEqual(val.w, 4.0, places=5)
Beispiel #29
0
    def test_assign2(self):
        register_user_type(Point)
        p1 = Point(33, 77, 99, 3.5, Vector3(2.2, 4.4, 7.7), 
                Vector2(3.3, 5.5), Vector4(1.1, 2.2, 3.3, 4.4))
        code = """
idx = p1.idx
p1.x = 55
pp = 555
p1.y = pp
g = 4.8
p1.radius = g
g = (4,5,6)
p1.position = g
p1.size = (6,7)
p1.pp = (8,1,3,4)

        """
        props = {'p1': p1, 'idx': 44}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()

        val = bs.shader.get_value('idx')
        self.assertEqual(33, val)
        val = bs.shader.get_value('p1.x')
        self.assertEqual(55, val)
        val = bs.shader.get_value('p1.y')
        self.assertEqual(555, val)
        val = bs.shader.get_value('p1.radius')
        self.assertAlmostEqual(val, 4.8, places=5)
        val = bs.shader.get_value('p1.position')
        self.assertAlmostEqual(val.x, 4.0, places=5)
        self.assertAlmostEqual(val.y, 5.0, places=5)
        self.assertAlmostEqual(val.z, 6.0, places=5)
        val = bs.shader.get_value('p1.size')
        self.assertAlmostEqual(val.x, 6.0, places=5)
        self.assertAlmostEqual(val.y, 7.0, places=5)
        val = bs.shader.get_value('p1.pp')
        self.assertAlmostEqual(val.x, 8.0, places=5)
        self.assertAlmostEqual(val.y, 1.0, places=5)
        self.assertAlmostEqual(val.z, 3.0, places=5)
        self.assertAlmostEqual(val.w, 4.0, places=5)
Beispiel #30
0
    def test_spec2(self):

        code = """
spec = spectrum(0.2)
        """
        col_mgr = ColorManager(spectral=True)
        rgb = col_mgr.create_spectrum((0.2, 0.3, 0.2))
        props = {'spec': rgb}
        bs = BasicShader(code, props, col_mgr=col_mgr)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('spec')
        nsamples = col_mgr.nsamples
        for i in range(nsamples):
            self.assertAlmostEqual(val.samples[i], 0.2, places=5)
Beispiel #31
0
    def test_set_rgba(self):
        img1 = ImagePRGBA(200, 200)
        code = """
set_rgba(img, 25, 25, (0.1, 0.2, 0.3, 0.4))
        """
        props = {'img': img1}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()

        val = img1.get_pixel(25, 25)
        self.assertAlmostEqual(val[0], 0.1, places=5)
        self.assertAlmostEqual(val[1], 0.2, places=5)
        self.assertAlmostEqual(val[2], 0.3, places=5)
        self.assertAlmostEqual(val[3], 0.4, places=5)
Beispiel #32
0
    def test_set_rgba(self):
        img1 = ImagePRGBA(200, 200)
        code = """
set_rgba(img, 25, 25, (0.1, 0.2, 0.3, 0.4))
        """
        props = {'img': img1}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()

        val = img1.get_pixel(25, 25)
        self.assertAlmostEqual(val[0], 0.1, places=5)
        self.assertAlmostEqual(val[1], 0.2, places=5)
        self.assertAlmostEqual(val[2], 0.3, places=5)
        self.assertAlmostEqual(val[3], 0.4, places=5)
Beispiel #33
0
    def test_arith1(self):

        code = """
vec1 = normalize(vec2)
        """
        vec1 = Vector3(0.0, 0.0, 0.0)
        vec2 = Vector3(0.3, 0.4, 0.5)
        props = {"vec1": vec1, "vec2": vec2}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        # print (bs.shader._code)

        bs.execute()
        vec2.normalize()
        val = bs.shader.get_value("vec1")
        self.assertAlmostEqual(val.x, vec2.x, 4)
        self.assertAlmostEqual(val.y, vec2.y, 4)
        self.assertAlmostEqual(val.z, vec2.z, 4)
Beispiel #34
0
    def test_spec1(self):

        code = """
spec = spectrum(0.1)
        """
        rgb = RGBSpectrum(0.0, 0.0, 0.0)
        props = {'spec': rgb}
        col_mgr = ColorManager(spectral=False)
        bs = BasicShader(code, props, col_mgr=col_mgr)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()

        val = bs.shader.get_value('spec')
        self.assertAlmostEqual(val.r, 0.1, 4)
        self.assertAlmostEqual(val.g, 0.1, 4)
        self.assertAlmostEqual(val.b, 0.1, 4)
Beispiel #35
0
    def test_float1(self):
        v = Vector2(1, 1)
        v2 = Vector2(1, 1)
        v3 = Vector3(1, 1, 1)
        v4 = Vector4(1, 1, 1, 1)

        code = """
ret = float2(5,6)
ret2 = float2(aa, bb)
ret3 = float3(8,9.5,3)
temp = (8,9,1,2)
ret4 = float4(temp[1],5.3,6, aa)
        """
        props = {
            'aa': 3.4,
            'bb': 77,
            'ret': v,
            'ret2': v2,
            'ret3': v3,
            'ret4': v4
        }
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('ret')
        self.assertAlmostEqual(val.x, 5.0, places=5)
        self.assertAlmostEqual(val.y, 6.0, places=5)
        val = bs.shader.get_value('ret2')
        self.assertAlmostEqual(val.x, 3.4, places=5)
        self.assertAlmostEqual(val.y, 77.0, places=5)
        val = bs.shader.get_value('ret3')
        self.assertAlmostEqual(val.x, 8.0, places=5)
        self.assertAlmostEqual(val.y, 9.5, places=5)
        self.assertAlmostEqual(val.z, 3.0, places=5)
        val = bs.shader.get_value('ret4')
        self.assertAlmostEqual(val.x, 9.0, places=5)
        self.assertAlmostEqual(val.y, 5.3, places=5)
        self.assertAlmostEqual(val.z, 6.0, places=5)
        self.assertAlmostEqual(val.w, 3.4, places=5)
Beispiel #36
0
def test_regular_sampler(width, height):
    sam = RegularSampler(width, height, 0.1)
    runtime = Runtime()
    sam.prepare([runtime])
    sam.set_pass(0)

    code = """
ret = generate_sample(sample)
    """
    sample = Sample(0.0, 0.0, 0, 0, 1.0)
    props = {'sample': sample, 'ret': 0}
    bas = BasicShader(code, props)
    bas.prepare([runtime], [sam.shader])

    while True:
        bas.execute()
        sample = sam.generate_sample()
        test_values(sample, bas.shader)
        if sample is None:
            break
Beispiel #37
0
    def test_float1(self):

        code = """
aa = float(55)
ret = float(bb)
ret2 = float()
        """
        props = {'aa': 0.0, 'bb': 77, 'ret': 0.0, 'ret2': 6.6}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('aa')
        self.assertAlmostEqual(val, 55.0, places=5)
        val = bs.shader.get_value('ret')
        self.assertAlmostEqual(val, 77.0, places=5)
        val = bs.shader.get_value('ret2')
        self.assertAlmostEqual(val, 0.0, places=5)
Beispiel #38
0
    def test_get_rgba(self):
        img1 = ImagePRGBA(200, 200)
        img1.set_pixel(25, 25, 0.2, 0.3, 0.4, 0.5)
        v1 = Vector4(0, 0, 0, 0)
        
        code = """
v1 = get_rgba(img, 25, 25)
        """
        props = {'img': img1, 'v1': v1}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('v1')
        self.assertAlmostEqual(val.x, 0.2, places=5)
        self.assertAlmostEqual(val.y, 0.3, places=5)
        self.assertAlmostEqual(val.z, 0.4, places=5)
        self.assertAlmostEqual(val.w, 0.5, places=5)
Beispiel #39
0
    def test_float1(self):

        code = """
aa = float(55)
ret = float(bb)
ret2 = float()
        """
        props = {'aa':0.0, 'bb':77, 'ret':0.0, 'ret2':6.6}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('aa')
        self.assertAlmostEqual(val, 55.0, places=5)
        val = bs.shader.get_value('ret')
        self.assertAlmostEqual(val, 77.0, places=5)
        val = bs.shader.get_value('ret2')
        self.assertAlmostEqual(val, 0.0, places=5)
Beispiel #40
0
    def test_arith1(self):

        code = """
ret = cross(v1, v2)
        """
        v1 = Vector3(0.32, 0.27, 0.45)
        v2 = Vector3(0.111, 0.22, 0.533)
        ret = Vector3(0.1, 0.2, 0.5)
        props = {'ret':ret, 'v1':v1, 'v2':v2}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('ret')
        val2 = v1.cross(v2)
        self.assertAlmostEqual(val.x, val2.x, 4)
        self.assertAlmostEqual(val.y, val2.y, 4)
        self.assertAlmostEqual(val.z, val2.z, 4)
Beispiel #41
0
    def test_get_rgba(self):
        img1 = ImagePRGBA(200, 200)
        img1.set_pixel(25, 25, 0.2, 0.3, 0.4, 0.5)
        v1 = Vector4(0, 0, 0, 0)

        code = """
v1 = get_rgba(img, 25, 25)
        """
        props = {'img': img1, 'v1': v1}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('v1')
        self.assertAlmostEqual(val.x, 0.2, places=5)
        self.assertAlmostEqual(val.y, 0.3, places=5)
        self.assertAlmostEqual(val.z, 0.4, places=5)
        self.assertAlmostEqual(val.w, 0.5, places=5)
Beispiel #42
0
def test_regular_sampler(width, height):
    sam = RegularSampler(width, height, 0.1)
    runtime = Runtime()
    sam.prepare([runtime])
    sam.set_pass(0)

    code = """
ret = generate_sample(sample)
    """
    sample = Sample(0.0, 0.0, 0, 0, 1.0)
    props = {'sample': sample, 'ret': 0}
    bas = BasicShader(code, props)
    bas.prepare([runtime], [sam.shader])

    while True:
        bas.execute()
        sample = sam.generate_sample()
        test_values(sample, bas.shader)
        if sample is None:
            break
Beispiel #43
0
    def test_arith1(self):

        code = """
r1 = a1 + a2
r2 = a1 * a2 
r3 = a4 * (0.5, 0.5)
r4 = a5 / (0.5, 0.5, 0.5)
r5 = (7,7,7,7) + a6 
r6 = a3 / 3
r7 = a7 % 18
        """
        props = {'a1':1.1, 'a2':2.2, 'r1':1.1, 'r2':3.3,
                'a3':55, 'a4':Vector2(2.2, 4), 'a5':Vector3(5,6,7),
                'a6':Vector4(3,4,5,6), 'r3':Vector2(3,4), 'r4':Vector3(1,1,1),
                'r5':Vector4(11,1,1,1), 'r6':88, 'a7':789, 'r7':1}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('r1')
        self.assertAlmostEqual(val, 2.2 + 1.1, places=5)
        val = bs.shader.get_value('r2')
        self.assertAlmostEqual(val, 1.1 * 2.2, places=5)
        val = bs.shader.get_value('r3')
        self.assertAlmostEqual(val.x, 2.2*0.5, places=5)
        self.assertAlmostEqual(val.y, 4.0*0.5, places=5)
        val = bs.shader.get_value('r4')
        self.assertAlmostEqual(val.x, 5*2.0, places=5)
        self.assertAlmostEqual(val.y, 6*2.0, places=5)
        self.assertAlmostEqual(val.z, 7*2.0, places=5)
        val = bs.shader.get_value('r5')
        self.assertAlmostEqual(val.x, 7+3.0, places=5)
        self.assertAlmostEqual(val.y, 7+4.0, places=5)
        self.assertAlmostEqual(val.z, 7+5.0, places=5)
        self.assertAlmostEqual(val.w, 7+6.0, places=5)
        val = bs.shader.get_value('r6')
        self.assertEqual(val, 55//3)
        val = bs.shader.get_value('r7')
        self.assertEqual(val, 789 % 18)
Beispiel #44
0
    def test_get_item2(self):
        arr = FloatArray2D(3, 4)
        arr[1,2] = 5.0
        arr[0,1] = 1.45
        code = """
ix = 1
iy = 2
num = get_item(arr, ix, iy)
num2 = get_item(arr, 0, 1)
        """
        props = {'arr': arr, 'num': 2.3, 'num2': 1.1}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('num')
        self.assertAlmostEqual(val, 5.0, places=5)
        val = bs.shader.get_value('num2')
        self.assertAlmostEqual(val, 1.45, places=5)
Beispiel #45
0
    def test_chromacity_to_spec(self):

        code = """
spec1 = chromacity_to_spectrum(0.41, 0.45)

        """
        col_mgr = ColorManager(spectral=True)
        rgb = col_mgr.black()
        props = {'spec1': rgb}
        bs = BasicShader(code, props, col_mgr=col_mgr)

        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        spec2 = col_mgr.chromacity_to_spectrum(0.41, 0.45)

        val = bs.shader.get_value('spec1')
        for i in range(len(val.samples)):
            self.assertAlmostEqual(val.samples[i], spec2.samples[i], places=4)
Beispiel #46
0
    def test_get_item2(self):
        arr = FloatArray2D(3, 4)
        arr[1, 2] = 5.0
        arr[0, 1] = 1.45
        code = """
ix = 1
iy = 2
num = get_item(arr, ix, iy)
num2 = get_item(arr, 0, 1)
        """
        props = {'arr': arr, 'num': 2.3, 'num2': 1.1}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('num')
        self.assertAlmostEqual(val, 5.0, places=5)
        val = bs.shader.get_value('num2')
        self.assertAlmostEqual(val, 1.45, places=5)
    def test_chromacity_to_spec(self):

        code = """
spec1 = chromacity_to_spectrum(0.41, 0.45)

        """
        col_mgr = ColorManager(spectral=True)
        rgb = col_mgr.black()
        props = {"spec1": rgb}
        bs = BasicShader(code, props, col_mgr=col_mgr)

        runtime = Runtime()
        bs.prepare([runtime])
        # print (bs.shader._code)

        bs.execute()
        spec2 = col_mgr.chromacity_to_spectrum(0.41, 0.45)

        val = bs.shader.get_value("spec1")
        for i in range(len(val.samples)):
            self.assertAlmostEqual(val.samples[i], spec2.samples[i], places=4)
Beispiel #48
0
    def test_sampled_spec_to_rgb(self):

        code = """
vec = spectrum_to_rgb(spec1)
        """
        col_mgr = ColorManager(spectral=True)
        rgb = col_mgr.create_spectrum((0.2, 0.3, 0.2))

        vec = Vector3(0.0, 0.0, 0.0)
        props = {'spec1': rgb, 'vec': vec}
        bs = BasicShader(code, props, col_mgr=col_mgr)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()

        val = bs.shader.get_value('vec')
        val2 = col_mgr.to_RGB(rgb)
        self.assertAlmostEqual(val.x, val2.r, places=5)
        self.assertAlmostEqual(val.y, val2.g, places=5)
        self.assertAlmostEqual(val.z, val2.b, places=5)
Beispiel #49
0
    def test_assign1(self):

        code = """
p = spec1
spec2 = p

        """
        rgb = RGBSpectrum(0.2, 0.3, 0.2)
        rgb2 = RGBSpectrum(0.1, 0.8, 0.9)
        props = {"spec1": rgb, "spec2": rgb2}
        col_mgr = ColorManager(spectral=False)
        bs = BasicShader(code, props, col_mgr=col_mgr)
        runtime = Runtime()
        bs.prepare([runtime])
        # print (bs.shader._code)

        bs.execute()
        val1 = bs.shader.get_value("spec1")
        val2 = bs.shader.get_value("spec2")
        self.assertAlmostEqual(val1.r, val2.r, places=5)
        self.assertAlmostEqual(val1.g, val2.g, places=5)
        self.assertAlmostEqual(val1.b, val2.b, places=5)
Beispiel #50
0
    def test_lum1(self):
        code = """
ret1 = luminance(v1)
ret2 = luminance(v2)
        """
        v1 = Vector3(0.2, 0.3, 0.4)
        v2 = Vector4(0.4, 0.1, 0.2, 0.5)
        props = {'v1':v1, 'v2':v2, 'ret1':0.0, 'ret2':0.0}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()

        lum1 = v1.x * 0.2126 + v1.y * 0.7152 + v1.z * 0.0722
        lum2 = bs.shader.get_value('ret1')
        lum3 = v2.x * 0.2126 + v2.y * 0.7152 + v2.z * 0.0722
        lum4 = bs.shader.get_value('ret2')

        self.assertAlmostEqual(lum1, lum2, places=5)
        self.assertAlmostEqual(lum3, lum4, places=5)
Beispiel #51
0
    def test_rgb_to_spec2(self):

        code = """
spec1 = rgb_to_spectrum(vec)

        """
        vec = Vector3(0.2, 0.3, 0.2)
        col_mgr = ColorManager(spectral=True)
        rgb = col_mgr.black()
        props = {'spec1':rgb, 'vec':vec}
        bs = BasicShader(code, props, col_mgr=col_mgr)

        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()

        val = bs.shader.get_value('spec1')
        val2 = col_mgr.create_spectrum((0.2, 0.3, 0.2), illum=False)
        for i in range(len(val2.samples)):
            self.assertAlmostEqual(val.samples[i], val2.samples[i], places=5)
    def test_chromacity_to_rgb(self):

        code = """
spec1 = chromacity_to_spectrum(0.41, 0.45)

        """
        rgb = RGBSpectrum(0.0, 0.0, 0.0)
        props = {"spec1": rgb}
        col_mgr = ColorManager(spectral=False)
        bs = BasicShader(code, props, col_mgr=col_mgr)

        runtime = Runtime()
        bs.prepare([runtime])
        # print (bs.shader._code)

        bs.execute()
        spec2 = col_mgr.chromacity_to_spectrum(0.41, 0.45)

        val = bs.shader.get_value("spec1")
        self.assertAlmostEqual(spec2.r, val.r, places=4)
        self.assertAlmostEqual(spec2.g, val.g, places=4)
        self.assertAlmostEqual(spec2.b, val.b, places=4)
Beispiel #53
0
    def test_rgb_to_spec(self):

        code = """
spec1 = rgb_to_spectrum(vec)

        """
        rgb = RGBSpectrum(0.0, 0.0, 0.0)
        vec = Vector3(0.2, 0.3, 0.2)
        props = {'spec1':rgb, 'vec':vec}
        col_mgr = ColorManager(spectral=False)
        bs = BasicShader(code, props, col_mgr=col_mgr)

        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()

        val = bs.shader.get_value('spec1')
        self.assertAlmostEqual(vec.x, val.r, places=5)
        self.assertAlmostEqual(vec.y, val.g, places=5)
        self.assertAlmostEqual(vec.z, val.b, places=5)
Beispiel #54
0
    def test_sampled_spec_to_rgb(self):

        code = """
vec = spectrum_to_rgb(spec1)
        """
        col_mgr = ColorManager(spectral=True)
        rgb = col_mgr.create_spectrum((0.2, 0.3, 0.2))

        vec = Vector3(0.0, 0.0, 0.0)
        props = {'spec1':rgb, 'vec':vec}
        bs = BasicShader(code, props, col_mgr=col_mgr)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()

        val = bs.shader.get_value('vec')
        val2 = col_mgr.to_RGB(rgb)
        self.assertAlmostEqual(val.x, val2.r, places=5)
        self.assertAlmostEqual(val.y, val2.g, places=5)
        self.assertAlmostEqual(val.z, val2.b, places=5)
Beispiel #55
0
    def test_arith2(self):

        code = """
r1 = a1 + 5
r2 = 4 * a2

r3 = 8 * a4
r4 = a5 * 1.1

r5 = a6 * 0.5

        """
        props = {'a1':1.1, 'a2':2.2, 'r1':1.1, 'r2':3.3,
                'a3':55, 'a4':Vector2(2.2, 4), 'a5':Vector3(5,6,7),
                'a6':Vector4(3,4,5,6), 'r3':Vector2(3,4), 'r4':Vector3(1,1,1),
                'r5':Vector4(11,1,1,1)}
        bs = BasicShader(code, props)
        runtime = Runtime()
        bs.prepare([runtime])
        #print (bs.shader._code)

        bs.execute()
        val = bs.shader.get_value('r1')
        self.assertAlmostEqual(val, 1.1 + 5, places=5)
        val = bs.shader.get_value('r2')
        self.assertAlmostEqual(val, 4 * 2.2, places=5)
        val = bs.shader.get_value('r3')
        self.assertAlmostEqual(val.x, 8 * 2.2, places=5)
        self.assertAlmostEqual(val.y, 8 * 4.0, places=5)
        val = bs.shader.get_value('r4')
        self.assertAlmostEqual(val.x, 1.1 * 5, places=5)
        self.assertAlmostEqual(val.y, 1.1 * 6, places=5)
        self.assertAlmostEqual(val.z, 1.1 * 7, places=5)
        val = bs.shader.get_value('r5')
        self.assertAlmostEqual(val.x, 0.5 * 3, places=5)
        self.assertAlmostEqual(val.y, 0.5 * 4, places=5)
        self.assertAlmostEqual(val.z, 0.5 * 5, places=5)
        self.assertAlmostEqual(val.w, 0.5 * 6, places=5)