예제 #1
0
파일: material.py 프로젝트: mario007/renmas
    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())
예제 #2
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)
예제 #3
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)
예제 #4
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)
예제 #5
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)