Esempio n. 1
0
    def atest_material_manager(self):
        sam_mgr = SampledManager()
        register_rgb_shadepoint()

        runtimes = [Runtime(), Runtime()]
        mat = Material()
        mat.load('lambertian', sam_mgr, spectral=False)
        mat.set_value('diffuse', RGBSpectrum(0.2, 0.3, 0.4))

        mgr = MaterialManager()
        mgr.add('material1', mat)

        mgr.compile_shaders(sam_mgr, spectral=False)
        mgr.prepare_shaders(runtimes)

        code = """
hp = HitPoint()
sp = ShadePoint()
material_reflectance(hp, sp, 0)
spec = sp.material_reflectance
        """
        spec = RGBArg('spec', RGBSpectrum(0.5, 0.5, 0.5))
        shader = Shader(code=code, args=[spec])
        shader.compile(shaders=[mgr.ref_shader])
        shader.prepare(runtimes)
        shader.execute()

        s = shader.get_value('spec')
        ls = RGBSpectrum(0.2, 0.3, 0.4) * (1.0 / math.pi)

        self.assertAlmostEqual(s.r, ls.r)
        self.assertAlmostEqual(s.g, ls.g)
        self.assertAlmostEqual(s.b, ls.b)
Esempio n. 2
0
    def atest_material_manager(self):
        sam_mgr = SampledManager()
        register_rgb_shadepoint()

        runtimes = [Runtime(), Runtime()]
        mat = Material()
        mat.load('lambertian', sam_mgr, spectral=False)
        mat.set_value('diffuse', RGBSpectrum(0.2, 0.3, 0.4))

        mgr = MaterialManager()
        mgr.add('material1', mat)

        mgr.compile_shaders(sam_mgr, spectral=False)
        mgr.prepare_shaders(runtimes)

        code = """
hp = HitPoint()
sp = ShadePoint()
material_reflectance(hp, sp, 0)
spec = sp.material_reflectance
        """
        spec = RGBArg('spec', RGBSpectrum(0.5, 0.5, 0.5))
        shader = Shader(code=code, args=[spec])
        shader.compile(shaders=[mgr.ref_shader])
        shader.prepare(runtimes)
        shader.execute()

        s = shader.get_value('spec')
        ls = RGBSpectrum(0.2, 0.3, 0.4) * (1.0 / math.pi)

        self.assertAlmostEqual(s.r, ls.r)
        self.assertAlmostEqual(s.g, ls.g)
        self.assertAlmostEqual(s.b, ls.b)
Esempio n. 3
0
    def test_material_sampling_manager(self):
        sam_mgr = SampledManager()
        register_rgb_shadepoint()

        runtimes = [Runtime(), Runtime()]
        mat = Material()
        mat.load('lambertian', sam_mgr, spectral=False)
        mat.set_value('diffuse', RGBSpectrum(0.2, 0.3, 0.4))

        mgr = MaterialManager()
        mgr.add('material1', mat)

        mgr.compile_shaders(sam_mgr, spectral=False)
        mgr.prepare_shaders(runtimes)

        code = """
hp = HitPoint()
hp.normal = (0.1, 0.4, 0.66)
hp.normal = normalize(hp.normal)
sp = ShadePoint()
material_sampling(hp, sp, 0)
pdf = sp.pdf
wi = sp.wi
spec = sp.material_reflectance
        """
        pdf = FloatArg('pdf', 0.0)
        wi = Vec3Arg('wi', Vector3(0.0, 0.0, 0.0))
        spec = RGBArg('spec', RGBSpectrum(0.5, 0.5, 0.5))
        shader = Shader(code=code, args=[pdf, wi, spec])
        shader.compile(shaders=[mgr.sampling_shader])
        shader.prepare(runtimes)
        shader.execute()

        s = shader.get_value('pdf')
        print(s)
        s = shader.get_value('wi')
        print(s)
        s = shader.get_value('spec')
        print(s)
        normal = Vector3(0.1, 0.4, 0.66)
        normal.normalize()
        print(cos_hemisphere(r1=0.1, r2=0.06, normal=normal,e=1.0))
Esempio n. 4
0
    def test_material_sampling_manager(self):
        sam_mgr = SampledManager()
        register_rgb_shadepoint()

        runtimes = [Runtime(), Runtime()]
        mat = Material()
        mat.load('lambertian', sam_mgr, spectral=False)
        mat.set_value('diffuse', RGBSpectrum(0.2, 0.3, 0.4))

        mgr = MaterialManager()
        mgr.add('material1', mat)

        mgr.compile_shaders(sam_mgr, spectral=False)
        mgr.prepare_shaders(runtimes)

        code = """
hp = HitPoint()
hp.normal = (0.1, 0.4, 0.66)
hp.normal = normalize(hp.normal)
sp = ShadePoint()
material_sampling(hp, sp, 0)
pdf = sp.pdf
wi = sp.wi
spec = sp.material_reflectance
        """
        pdf = FloatArg('pdf', 0.0)
        wi = Vec3Arg('wi', Vector3(0.0, 0.0, 0.0))
        spec = RGBArg('spec', RGBSpectrum(0.5, 0.5, 0.5))
        shader = Shader(code=code, args=[pdf, wi, spec])
        shader.compile(shaders=[mgr.sampling_shader])
        shader.prepare(runtimes)
        shader.execute()

        s = shader.get_value('pdf')
        print(s)
        s = shader.get_value('wi')
        print(s)
        s = shader.get_value('spec')
        print(s)
        normal = Vector3(0.1, 0.4, 0.66)
        normal.normalize()
        print(cos_hemisphere(r1=0.1, r2=0.06, normal=normal, e=1.0))
Esempio n. 5
0
    def atest_material_glass(self):
        sam_mgr = SampledManager()
        register_rgb_shadepoint()

        runtimes = [Runtime()]
        mat = Material()
        mat.load('glass', sam_mgr, spectral=False)
        mat.set_value('ior', 1.5)

        mgr = MaterialManager()
        mgr.add('material1', mat)

        shaders = shaders_functions()
        for shader in shaders:
            shader.compile()
            shader.prepare(runtimes)

        mgr.compile_shaders(sam_mgr, spectral=False, shaders=shaders)
        mgr.prepare_shaders(runtimes)

        code = """
hp = HitPoint()
hp.normal = normal
sp = ShadePoint()
sp.wo = wo
material_sampling(hp, sp, 0)
pdf = sp.pdf
wi = sp.wi
spec = sp.material_reflectance
        """
        pdf = FloatArg('pdf', 0.0)
        wi = Vec3Arg('wi', Vector3(0.0, 0.0, 0.0))
        ww = Vector3(5.0, 1.0, 0.0)
        ww.normalize()
        wo = Vec3Arg('wo', ww)
        nn = Vector3(0.0, 1.0, 0.0)
        nn.normalize()
        normal = Vec3Arg('normal', nn)
        spec = RGBArg('spec', RGBSpectrum(0.5, 0.5, 0.5))

        shader = Shader(code=code, args=[pdf, wi, wo, normal, spec])
        shader.compile(shaders=[mgr.sampling_shader])
        shader.prepare(runtimes)

        shader.execute()

        s = shader.get_value('wi')
        print(s)
        s = shader.get_value('pdf')
        print(s)
        s = shader.get_value('spec')
        print(s)
        print('------------------------------')
        print('wo', ww)
        wi, pdf, ref = sampling_glass(1.5, ww, nn)
        print("wi", wi)
        print("pdf", pdf)
        print("ref", ref)
        ndotwi = abs(nn.dot(wi))
        print("ndotwi", ndotwi)

        tmp = ndotwi / pdf
        path_weight = ref * tmp
        print("path weight", path_weight)
Esempio n. 6
0
    def atest_material_glass(self):
        sam_mgr = SampledManager()
        register_rgb_shadepoint()

        runtimes = [Runtime()]
        mat = Material()
        mat.load('glass', sam_mgr, spectral=False)
        mat.set_value('ior', 1.5)

        mgr = MaterialManager()
        mgr.add('material1', mat)

        shaders = shaders_functions()
        for shader in shaders:
            shader.compile()
            shader.prepare(runtimes)

        mgr.compile_shaders(sam_mgr, spectral=False, shaders=shaders)
        mgr.prepare_shaders(runtimes)

        code = """
hp = HitPoint()
hp.normal = normal
sp = ShadePoint()
sp.wo = wo
material_sampling(hp, sp, 0)
pdf = sp.pdf
wi = sp.wi
spec = sp.material_reflectance
        """
        pdf = FloatArg('pdf', 0.0)
        wi = Vec3Arg('wi', Vector3(0.0, 0.0, 0.0))
        ww = Vector3(5.0, 1.0, 0.0)
        ww.normalize()
        wo = Vec3Arg('wo', ww)
        nn = Vector3(0.0, 1.0, 0.0)
        nn.normalize()
        normal = Vec3Arg('normal', nn)
        spec = RGBArg('spec', RGBSpectrum(0.5, 0.5, 0.5))

        shader = Shader(code=code, args=[pdf, wi, wo, normal, spec])
        shader.compile(shaders=[mgr.sampling_shader])
        shader.prepare(runtimes)

        shader.execute()

        s = shader.get_value('wi')
        print(s)
        s = shader.get_value('pdf')
        print(s)
        s = shader.get_value('spec')
        print(s)
        print('------------------------------')
        print('wo', ww)
        wi, pdf, ref = sampling_glass(1.5, ww, nn)
        print("wi", wi)
        print("pdf", pdf)
        print("ref", ref)
        ndotwi = abs(nn.dot(wi))
        print("ndotwi", ndotwi)

        tmp = ndotwi / pdf
        path_weight = ref * tmp
        print("path weight", path_weight)