Example #1
0
    def __init__(self, eye, lookat, distance):
        self._eye = eye
        self._lookat = lookat
        self._up = Vector3(0.0, 1.0, 0.0)
        self._distance = float(distance)  # distance of image plane form eye
        self._compute_uvw()

        path = os.path.dirname(__file__)
        path = os.path.join(path, 'cam_shaders')
        self._loader = Loader([path])
Example #2
0
    def __init__(self):

        path = os.path.dirname(__file__)
        path = os.path.join(path, 'sam_shaders')
        self._loader = Loader([path])
        self.shader = None

        #default values
        self._width = 200
        self._height = 200
        self._pixel_size = 1.0
        self._pass_number = 1
        self._nthreads = 1
Example #3
0
    def __init__(self):
        self.bsdf = None
        self.sampling = None
        self.emission = None

        path = os.path.dirname(__file__)
        path = os.path.join(path, 'mat_shaders')
        self._loader = Loader([path])
Example #4
0
    def __init__(self, eye, lookat, distance):
        self._eye = eye
        self._lookat = lookat
        self._up = Vector3(0.0, 1.0, 0.0)
        self._distance = float(distance)  # distance of image plane form eye
        self._compute_uvw()

        path = os.path.dirname(__file__)
        path = os.path.join(path, 'cam_shaders')
        self._loader = Loader([path])
Example #5
0
    def __init__(self):

        path = os.path.dirname(__file__)
        path = os.path.join(path, "sam_shaders")
        self._loader = Loader([path])
        self.shader = None

        # default values
        self._width = 200
        self._height = 200
        self._pixel_size = 1.0
        self._pass_number = 1
        self._nthreads = 1
Example #6
0
class Integrator:
    def __init__(self):

        path = os.path.dirname(__file__)
        path = os.path.join(path, 'int_shaders')
        self._loader = Loader([path])

    def load(self, shader_name):

        text = self._loader.load(shader_name, 'props.txt')
        args = []
        if text is not None:
            args = parse_args(text)
        code = self._loader.load(shader_name, 'code.py')
        self.shader = Shader(code=code, args=args)

    def compile(self, shaders=[]):
        self.shader.compile(shaders)

    def prepare(self, runtimes):
        self.shader.prepare(runtimes)

    def execute(self):
        self.shader.execute()
Example #7
0
    def __init__(self):

        path = os.path.dirname(__file__)
        path = os.path.join(path, 'int_shaders')
        self._loader = Loader([path])
Example #8
0
class Camera:
    def __init__(self, eye, lookat, distance):
        self._eye = eye
        self._lookat = lookat
        self._up = Vector3(0.0, 1.0, 0.0)
        self._distance = float(distance)  # distance of image plane form eye
        self._compute_uvw()

        path = os.path.dirname(__file__)
        path = os.path.join(path, 'cam_shaders')
        self._loader = Loader([path])

    def _compute_uvw(self):
        self._w = self._eye - self._lookat  # w is in oposite direction of view
        self._w.normalize()
        self._u = self._up.cross(self._w)
        self._u.normalize()
        self._v = self._w.cross(self._u)
        #singularity
        if self._eye.x == self._lookat.x and self._eye.z == self._lookat.z\
                and self._eye.y > self._lookat.y:  # looking vertically down
            self._u = Vector3(0.0, 0.0, 1.0)
            self._v = Vector3(1.0, 0.0, 0.0)
            self._w = Vector3(0.0, 1.0, 0.0)

        if self._eye.x == self._lookat.x and self._eye.z == self._lookat.z\
                and self._eye.y < self._lookat.y:  # looking vertically up
            self._u = Vector3(1.0, 0.0, 0.0)
            self._v = Vector3(0.0, 0.0, 1.0)
            self._w = Vector3(0.0, -1.0, 0.0)

    def load(self, shader_name):
        #TODO props
        props = self._loader.load(shader_name, 'props.txt')
        code = self._loader.load(shader_name, 'code.py')
        w = Vec3Arg('w', self._w)
        u = Vec3Arg('u', self._u)
        v = Vec3Arg('v', self._v)
        distance = FloatArg('distance', self._distance)
        eye = Vec3Arg('eye', self._eye)
        lookat = Vec3Arg('lookat', self._lookat)
        args = [w, u, v, distance, eye, lookat]

        origin = Vector3(0.0, 0.0, 0.0)
        direction = Vector3(0.0, 0.0, 0.0)
        ray = Ray(origin, direction)
        sample = Sample(0.0, 0.0, 0, 0, 0.0)
        func_args = [StructArgPtr('ray', ray), StructArgPtr('sample', sample)]

        self.shader = Shader(code=code,
                             args=args,
                             name='generate_ray',
                             func_args=func_args,
                             is_func=True)

        codepy = self._loader.load(shader_name, 'codepy.py')
        self._py_code = compile(codepy, 'codepy.py', 'exec')

    def compile(self):
        self.shader.compile()

    def prepare(self, runtimes):
        self.shader.prepare(runtimes)

    def execute_py(self, ray, sample):
        d = {'camera': self, 'sample': sample, 'ray': ray}
        exec(self._py_code, d, d)
Example #9
0
class Camera:
    def __init__(self, eye, lookat, distance):
        self._eye = eye
        self._lookat = lookat
        self._up = Vector3(0.0, 1.0, 0.0)
        self._distance = float(distance)  # distance of image plane form eye
        self._compute_uvw()

        path = os.path.dirname(__file__)
        path = os.path.join(path, 'cam_shaders')
        self._loader = Loader([path])

    def _compute_uvw(self):
        self._w = self._eye - self._lookat  # w is in oposite direction of view
        self._w.normalize()
        self._u = self._up.cross(self._w)
        self._u.normalize()
        self._v = self._w.cross(self._u)
        #singularity
        if self._eye.x == self._lookat.x and self._eye.z == self._lookat.z\
                and self._eye.y > self._lookat.y:  # looking vertically down
            self._u = Vector3(0.0, 0.0, 1.0)
            self._v = Vector3(1.0, 0.0, 0.0)
            self._w = Vector3(0.0, 1.0, 0.0)

        if self._eye.x == self._lookat.x and self._eye.z == self._lookat.z\
                and self._eye.y < self._lookat.y:  # looking vertically up
            self._u = Vector3(1.0, 0.0, 0.0)
            self._v = Vector3(0.0, 0.0, 1.0)
            self._w = Vector3(0.0, -1.0, 0.0)

    def load(self, shader_name):
        #TODO props
        props = self._loader.load(shader_name, 'props.txt')
        code = self._loader.load(shader_name, 'code.py')
        w = Vec3Arg('w', self._w)
        u = Vec3Arg('u', self._u)
        v = Vec3Arg('v', self._v)
        distance = FloatArg('distance', self._distance)
        eye = Vec3Arg('eye', self._eye)
        lookat = Vec3Arg('lookat', self._lookat)
        args = [w, u, v, distance, eye, lookat]

        origin = Vector3(0.0, 0.0, 0.0)
        direction = Vector3(0.0, 0.0, 0.0)
        ray = Ray(origin, direction)
        sample = Sample(0.0, 0.0, 0, 0, 0.0)
        func_args = [StructArgPtr('ray', ray), StructArgPtr('sample', sample)]

        self.shader = Shader(code=code, args=args, name='generate_ray',
                             func_args=func_args, is_func=True)

        codepy = self._loader.load(shader_name, 'codepy.py')
        self._py_code = compile(codepy, 'codepy.py', 'exec')

    def compile(self):
        self.shader.compile()

    def prepare(self, runtimes):
        self.shader.prepare(runtimes)

    def execute_py(self, ray, sample):
        d = {'camera': self, 'sample': sample, 'ray': ray}
        exec(self._py_code, d, d)
Example #10
0
class Material:
    def __init__(self):
        self.bsdf = None
        self.sampling = None
        self.emission = None

        path = os.path.dirname(__file__)
        path = os.path.join(path, 'mat_shaders')
        self._loader = Loader([path])

    def _load_args(self, name):
        args = []
        props = self._loader.load(name, 'props.txt')
        if props is not None:
            args = parse_args(props)
        return args

    def _func_args(self, spectrum):
        wi = Vector3(0.0, 0.0, 0.0)
        wo = Vector3(0.0, 0.0, 0.0)
        ref = spectrum.zero()
        sh = ShadePoint(wi, wo, 0.0, ref)
        hp = HitPoint(0.0, Vector3(0.0, 0.0, 0.0), Vector3(0.0, 0.0, 0.0), 0, 0.0, 0.0)
        func_args = [StructArgPtr('hitpoint', hp), StructArgPtr('shadepoint', sh)]
        return func_args

    def load(self, shader_name, spectrum):
        self.bsdf = None
        self.sampling = None
        self.emission = None
        code = self._loader.load(shader_name, 'bsdf.py')
        #TODO hitpoint, shadepoint function arguments
        if code is not None:
            args = self._load_args(shader_name)
            name = 'bsdf_' + str(id(args))
            func_args = self._func_args(spectrum)
            self.bsdf = Shader(code=code, args=args, name=name,
                               func_args=func_args, is_func=True)

        code = self._loader.load(shader_name, 'sampling.py')
        if code is not None:
            args = self._load_args(shader_name)
            self.sampling = Shader(code=code, args=args)

        code = self._loader.load(shader_name, 'emission.py')
        if code is not None:
            args = self._load_args(shader_name)
            self.emission = Shader(code=code, args=args)

    def compile(self, shaders=[]):
        if self.bsdf is not None:
            self.bsdf.compile(shaders)
        if self.sampling is not None:
            self.sampling.compile(shaders)
        if self.emission is not None:
            self.emission.compile(shaders)

    def prepare(self, runtimes):
        if self.bsdf is not None:
            self.bsdf.prepare(runtimes)
        if self.sampling is not None:
            self.sampling.prepare(runtimes)
        if self.emission is not None:
            self.emission.prepare(runtimes)
Example #11
0
class Sampler:
    def __init__(self):

        path = os.path.dirname(__file__)
        path = os.path.join(path, 'sam_shaders')
        self._loader = Loader([path])
        self.shader = None

        #default values
        self._width = 200
        self._height = 200
        self._pixel_size = 1.0
        self._pass_number = 1
        self._nthreads = 1

    def set_resolution(self, width, height):
        self._width = int(width)
        self._height = int(height)
        if self.shader is not None:
            self.shader.set_value('width', self._width)
            self.shader.set_value('height', self._height)

    def set_pass(self, n):
        self._pass_number = int(n)
        if self.shader is not None:
            self.shader.set_value('pass_number', self._pass_number)

    def set_pixel_size(self, size):
        self._pixel_size = float(size)
        if self.shader is not None:
            self.shader.set_value('pixel_size', self._pixel_size)

    def set_nthreads(self, n):
        self._nthreads = int(n)

    def load(self, shader_name):
        text = self._loader.load(shader_name, 'props.txt')
        #args = create_args(text)
        code = self._loader.load(shader_name, 'code.py')

        sample = Sample(0.0, 0.0, 0, 0, 0.0)
        func_args = [StructArgPtr('sample', sample)]

        args = [
            IntArg('width', self._width),
            IntArg('height', self._height),
            IntArg('pass_number', self._pass_number),
            FloatArg('pixel_size', self._pixel_size)
        ]

        tiles = create_tiles(self._width, self._height, self._nthreads)
        targs = [StructArg('tile', tile) for tile in tiles]
        targ = ArgList('tile', targs)
        args.append(targ)
        curx_args = [IntArg('curx', 0) for tile in tiles]
        curx_arg = ArgList('curx', curx_args)
        args.append(curx_arg)
        cury_args = [IntArg('cury', tile.y) for tile in tiles]
        cury_arg = ArgList('cury', cury_args)
        args.append(cury_arg)
        endx_args = [IntArg('endx', tile.width) for tile in tiles]
        endx_arg = ArgList('endx', endx_args)
        args.append(endx_arg)
        endy_args = [IntArg('endy', tile.y + tile.height) for tile in tiles]
        endy_arg = ArgList('endy', endy_args)
        args.append(endy_arg)

        self.shader = Shader(code=code,
                             args=args,
                             name='generate_sample',
                             func_args=func_args,
                             is_func=True)

    def compile(self):
        self.shader.compile()

    def prepare(self, runtimes):
        self.shader.prepare(runtimes)
Example #12
0
class Sampler:
    def __init__(self):

        path = os.path.dirname(__file__)
        path = os.path.join(path, "sam_shaders")
        self._loader = Loader([path])
        self.shader = None

        # default values
        self._width = 200
        self._height = 200
        self._pixel_size = 1.0
        self._pass_number = 1
        self._nthreads = 1

    def set_resolution(self, width, height):
        self._width = int(width)
        self._height = int(height)
        if self.shader is not None:
            self.shader.set_value("width", self._width)
            self.shader.set_value("height", self._height)

    def set_pass(self, n):
        self._pass_number = int(n)
        if self.shader is not None:
            self.shader.set_value("pass_number", self._pass_number)

    def set_pixel_size(self, size):
        self._pixel_size = float(size)
        if self.shader is not None:
            self.shader.set_value("pixel_size", self._pixel_size)

    def set_nthreads(self, n):
        self._nthreads = int(n)

    def load(self, shader_name):
        text = self._loader.load(shader_name, "props.txt")
        # args = create_args(text)
        code = self._loader.load(shader_name, "code.py")

        sample = Sample(0.0, 0.0, 0, 0, 0.0)
        func_args = [StructArgPtr("sample", sample)]

        args = [
            IntArg("width", self._width),
            IntArg("height", self._height),
            IntArg("pass_number", self._pass_number),
            FloatArg("pixel_size", self._pixel_size),
        ]

        tiles = create_tiles(self._width, self._height, self._nthreads)
        targs = [StructArg("tile", tile) for tile in tiles]
        targ = ArgList("tile", targs)
        args.append(targ)
        curx_args = [IntArg("curx", 0) for tile in tiles]
        curx_arg = ArgList("curx", curx_args)
        args.append(curx_arg)
        cury_args = [IntArg("cury", tile.y) for tile in tiles]
        cury_arg = ArgList("cury", cury_args)
        args.append(cury_arg)
        endx_args = [IntArg("endx", tile.width) for tile in tiles]
        endx_arg = ArgList("endx", endx_args)
        args.append(endx_arg)
        endy_args = [IntArg("endy", tile.y + tile.height) for tile in tiles]
        endy_arg = ArgList("endy", endy_args)
        args.append(endy_arg)

        self.shader = Shader(code=code, args=args, name="generate_sample", func_args=func_args, is_func=True)

    def compile(self):
        self.shader.compile()

    def prepare(self, runtimes):
        self.shader.prepare(runtimes)