当前位置: 首页>>代码示例>>Python>>正文


Python Shader.set_value方法代码示例

本文整理汇总了Python中sdl.Shader.set_value方法的典型用法代码示例。如果您正苦于以下问题:Python Shader.set_value方法的具体用法?Python Shader.set_value怎么用?Python Shader.set_value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sdl.Shader的用法示例。


在下文中一共展示了Shader.set_value方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from sdl import Shader [as 别名]
# 或者: from sdl.Shader import set_value [as 别名]
class Tmo:
    def __init__(self):
        path = os.path.dirname(__file__)
        path = os.path.join(path, 'shaders')
        self._loader = Loader([path])

        self._shader = None
        self._runtime = None

    @property
    def shader(self):
        return self._shader

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

        in_img = StructArg('input_image', ImagePRGBA(1, 1))
        out_img = StructArg('output_image', ImagePRGBA(1, 1))
        args.extend([in_img, out_img])

        code = self._loader.load(name, 'code.py')
        self._shader = Shader(code=code, args=args)
        self._shader.compile()
        self._runtime = Runtime()
        self._shader.prepare([self._runtime])

    def tmo(self, in_img, out_img):
        """
            Perform tone mapping on input image

            Args:
                in_img:  Input image
                out_img: Output image

        """
        if self._shader is None:
            raise ValueError("Shader is not loaded.")

        if not isinstance(in_img, ImagePRGBA) and not isinstance(out_img, ImagePRGBA):
            raise ValueError("ImagePRGBA is expected insted of", in_img, out_img)

        w1, h1 = in_img.size()
        w2, h2 = out_img.size()
        if w1 != w2 or h1 != h2:
            raise ValueError("Input and output image must be same size!")

        self._shader.set_value('input_image', in_img)
        self._shader.set_value('output_image', out_img)
        self._shader.execute()
开发者ID:mario007,项目名称:renmas,代码行数:54,代码来源:tone.py

示例2: test_mesh

# 需要导入模块: from sdl import Shader [as 别名]
# 或者: from sdl.Shader import set_value [as 别名]
def test_mesh(mesh, nrays=1):
    dep_shader = type(mesh).isect_shader('ray_flat_mesh_isect')
    dep_shader.compile()
    runtimes = [Runtime()]
    dep_shader.prepare(runtimes)

    code = """
min_dist = 99999.0
ret = ray_flat_mesh_isect(ray, mesh, hitpoint, min_dist)
    """

    ray = generate_ray(mesh)
    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)
    mesh_arg = StructArg('mesh', mesh)
    harg = StructArg('hitpoint', hitpoint)
    ret = IntArg('ret', 6)

    args = [r_arg, mesh_arg, harg, ret]
    shader = Shader(code=code, args=args)
    shader.compile([dep_shader.shader])

    shader.prepare(runtimes)

    for i in range(nrays):
        ray = generate_ray(mesh)
        # origin = Vector3(-0.21099534597992897,-0.02090535280108452,-0.09716709856688976)
        # direction = Vector3(0.7856996643888073,0.4629769683728137,0.4102783983292736)
        # ray = Ray(origin, direction)
        shader.set_value('ray', ray)

        hp2 = mesh.isect(ray)
        hp, index = isect_ray_mesh(ray, mesh)
        shader.execute()

        # print(hp, shader.get_value('ret'))
        if hp:
            ret = shader.get_value('ret')
            hp_new = shader.get_value('hitpoint')
            if round(hp.t - hp_new.t, 5) != 0:
                print(hp.t, hp_new.t, ret, index, hp2.t)
                print(ray.origin)
                print(ray.direction)
                p0, p1, p2 = mesh.get_points(index)
                print(p0)
                print(p1)
                print(p2)
                print('------------------------------------------')
开发者ID:mario007,项目名称:renmas,代码行数:52,代码来源:test_load_meshes.py

示例3: EnvironmentLight

# 需要导入模块: from sdl import Shader [as 别名]
# 或者: from sdl.Shader import set_value [as 别名]
class EnvironmentLight(Light):
    def __init__(self):
        path = os.path.dirname(__file__)
        path = os.path.join(path, 'env_shaders')
        self._loader = Loader([path])

    def _func_args(self, spectrum):
        func_args = [StructArgPtr('hitpoint', HitPoint.factory()),
                     StructArgPtr('shadepoint', ShadePoint.factory(spectrum))]
        return func_args

    def load(self, shader_name, color_mgr):
        self._color_mgr = color_mgr
        self._shader_name = shader_name

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

        code = self._loader.load(shader_name, 'env.py')
        if code is None:
            raise ValueError("env.py in %s shader dont exist!" % shader_name)

        name = 'env_light_%i' % id(args)
        func_args = self._func_args(color_mgr.zero())
        self.env_shader = Shader(code=code, args=args, name='environment_emission',
                                 func_args=func_args, is_func=True)

    def get_value(self, name):
        if self.env_shader is None:
            raise ValueError("Environment shader is not loaded!")
        return self.env_shader.get_value(name)

    def set_value(self, name, val):
        if self.env_shader is None:
            raise ValueError("Environment shader is not loaded!")
        if isinstance(val, (RGBSpectrum, SampledSpectrum)):
            val = self._color_mgr.convert_spectrum(val, illum=True)
        self.env_shader.set_value(name, val)
开发者ID:mario007,项目名称:renmas,代码行数:42,代码来源:light.py

示例4: __init__

# 需要导入模块: from sdl import Shader [as 别名]
# 或者: from sdl.Shader import set_value [as 别名]
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, color_mgr):

        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')
        if code is None:
            raise ValueError("Integrator %s code is missing!" % shader_name)

        #array of shadepoints for debuging purpose
        sp = ShadePoint.factory(color_mgr.zero())
        arr = ObjArray(sp)
        for i in range(10):
            arr.append(sp)
        arg = ArrayArg('path_array', arr)
        args.append(arg)

        hdr_buffer = StructArg('hdr_buffer', ImagePRGBA(1, 1))
        args.append(hdr_buffer)
        self.shader = Shader(code=code, args=args)
        self._color_mgr = color_mgr

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

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

    def execute(self, hdr_buffer):
        self.shader.set_value('hdr_buffer', hdr_buffer)
        self.shader.execute()
开发者ID:mario007,项目名称:renmas,代码行数:41,代码来源:integrator.py

示例5: __init__

# 需要导入模块: from sdl import Shader [as 别名]
# 或者: from sdl.Shader import set_value [as 别名]

#.........这里部分代码省略.........
        code = """
r1 = random()
r2 = random()
e = 1.0

phi = 2.0 * 3.14159 * r1
exponent = 1.0 / (e + 1.0)
cos_theta = pow(r2, exponent)

tmp = 1.0 - cos_theta * cos_theta
sin_theta = sqrt(tmp)
sin_phi = sin(phi)
cos_phi = cos(phi)
pu = sin_theta * cos_phi 
pv = sin_theta * sin_phi
pw = cos_theta

w = hitpoint.normal 
tv = (0.0034, 1.0, 0.0071)
v = cross(tv, w)
v = normalize(v)
u = cross(v, w)

ndir = u * pu + v * pv + w * pw
shadepoint.wi = normalize(ndir)

__material_pdf(hitpoint, shadepoint, ptr_mat_pdf)
__material_reflectance(hitpoint, shadepoint, ptr_mat_bsdf)
        """
        return code

    def _default_pdf(self):
        code = """
shadepoint.pdf = dot(hitpoint.normal, shadepoint.wi) * 0.318309886
        """
        return code

    def compile(self, shaders=[]):
        self._bsdf_shader.compile(shaders, color_mgr=self._color_mgr)
        self._sampling_shader.compile(shaders, color_mgr=self._color_mgr)
        self._pdf_shader.compile(shaders, color_mgr=self._color_mgr)

    def prepare(self, runtimes):
        self._bsdf_shader.prepare(runtimes)
        self._pdf_shader.prepare(runtimes)

        ptrs = self._bsdf_shader.get_ptrs()
        args = [PointerArg('ptr_mat_bsdf', p) for p in ptrs]
        ptr_bsdf = self._sampling_shader._get_arg('ptr_mat_bsdf')
        ptr_bsdf.resize(args)

        ptrs = self._pdf_shader.get_ptrs()
        args = [PointerArg('ptr_mat_pdf', p) for p in ptrs]
        ptr_pdf = self._sampling_shader._get_arg('ptr_mat_pdf')
        ptr_pdf.resize(args)

        self._sampling_shader.prepare(runtimes)

    def emission_shader(self, shaders=[]):
        args = self._load_args()
        code = self._loader.load(self._shader_name, 'emission.py')
        if code is None:
            raise ValueError("emission.py in %s dont exist!" % self._shader_name)

        name = 'material_emission_%i' % id(args)
        s = self._color_mgr.zero()
        func_args = self._func_args(s)
        emission_shader = Shader(code=code, args=args, name=name,
                                 func_args=func_args, is_func=True)
        return emission_shader

    def sync_shader_props(self, shader):
        for arg in shader.args:
            val = self.get_value(arg.name)
            shader.set_value(arg.name, val)

    def set_value(self, name, val):
        if self._bsdf_shader is None:
            raise ValueError("Material shader is not loaded!")
        if isinstance(val, (RGBSpectrum, SampledSpectrum)):
            val = self._color_mgr.convert_spectrum(val)
        self._bsdf_shader.set_value(name, val)
        self._sampling_shader.set_value(name, val)
        self._pdf_shader.set_value(name, val)

    def get_value(self, name):
        if self._bsdf_shader is None:
            raise ValueError("Material shader is not loaded!")
        return self._bsdf_shader.get_value(name)

    def output(self, name):
        txt = 'Material\n'
        txt += 'type = %s\n' % self._shader_name
        txt += 'name = %s\n' % name
        args = self._load_args()
        for arg in args:
            value = self.get_value(arg.name)
            txt += output_arg(arg.name, value)
        txt += 'End\n'
        return txt
开发者ID:mario007,项目名称:renmas,代码行数:104,代码来源:material.py

示例6: AreaLight

# 需要导入模块: from sdl import Shader [as 别名]
# 或者: from sdl.Shader import set_value [as 别名]

#.........这里部分代码省略.........

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

    def load(self, shader_name, color_mgr):
        self._color_mgr = color_mgr
        self._shader_name = shader_name

        args = self._load_args()

        ptr_lgt_sample = PointerArg('ptr_light_sample', 0)
        lgt_sample = ArgList('ptr_light_sample', [ptr_lgt_sample])
        args.append(lgt_sample)
        ptr_mat_emission = PointerArg('ptr_mat_emission', 0)
        mat_emission = ArgList('ptr_mat_emission', [ptr_mat_emission])
        args.append(mat_emission)

        code = self._loader.load(shader_name, 'code.py')
        if code is None:
            raise ValueError("code.py in %s shader dont exist!" % shader_name)

        name = 'light_%i' % id(args)
        func_args = self._func_args(color_mgr.zero())
        self.shader = Shader(code=code, args=args, name=name,
                             func_args=func_args, is_func=True)
        
        # area light emission shader
        name = 'light_emission%i' % id(args)
        func_args = self._func_args(color_mgr.zero())
        args = []
        ptr_lgt_pdf = PointerArg('ptr_light_pdf', 0)
        lgt_pdf = ArgList('ptr_light_pdf', [ptr_lgt_pdf])
        args.append(lgt_pdf)
        ptr_mat_emission = PointerArg('ptr_mat_emission', 0)
        mat_emission = ArgList('ptr_mat_emission', [ptr_mat_emission])
        args.append(mat_emission)
        code = """
__light_pdf(hitpoint, shadepoint, ptr_light_pdf)
__material_emission(hitpoint, shadepoint, ptr_mat_emission)
        """
        self.emission_shader = Shader(code=code, args=args, name=name,
                                      func_args=func_args, is_func=True)

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

        spec = self._color_mgr.zero()
        self.light_sample_shader = self.shape.light_sample(spec)
        self.light_sample_shader.compile(shaders, color_mgr=self._color_mgr)

        self.light_pdf_shader = self.shape.light_pdf(spec)
        self.light_pdf_shader.compile(shaders, color_mgr=self._color_mgr)

        self._emission_shader = self.material.emission_shader()
        self._emission_shader.compile(shaders, color_mgr=self._color_mgr)


    def prepare(self, runtimes):
        self.light_sample_shader.prepare(runtimes)
        ptrs = self.light_sample_shader.get_ptrs()
        args = [PointerArg('ptr_light_sample', p) for p in ptrs]
        lgt_sample = self.shader._get_arg('ptr_light_sample')
        lgt_sample.resize(args)

        self.light_pdf_shader.prepare(runtimes)
        ptrs = self.light_pdf_shader.get_ptrs()
        args = [PointerArg('ptr_light_pdf', p) for p in ptrs]
        lgt_pdf = self.emission_shader._get_arg('ptr_light_pdf')
        lgt_pdf.resize(args)

        self._emission_shader.prepare(runtimes)
        self.material.sync_shader_props(self._emission_shader)
        ptrs = self._emission_shader.get_ptrs()
        args = [PointerArg('ptr_mat_emission', p) for p in ptrs]
        ptr_emission = self.shader._get_arg('ptr_mat_emission')
        ptr_emission.resize(args)

        args = [PointerArg('ptr_mat_emission', p) for p in ptrs]
        ptr_emission = self.emission_shader._get_arg('ptr_mat_emission')
        ptr_emission.resize(args)

        self.shader.prepare(runtimes)
        self.emission_shader.prepare(runtimes)

    def get_value(self, name):
        if self.shader is None:
            raise ValueError("Light shader is not loaded!")
        return self.shader.get_value(name)

    def set_value(self, name, val):
        if self.shader is None:
            raise ValueError("Light shader is not loaded!")
        if isinstance(val, (RGBSpectrum, SampledSpectrum)):
            val = self._color_mgr.convert_spectrum(val, illum=True)
        self.shader.set_value(name, val)
开发者ID:mario007,项目名称:renmas,代码行数:104,代码来源:light.py

示例7: GeneralLight

# 需要导入模块: from sdl import Shader [as 别名]
# 或者: from sdl.Shader import set_value [as 别名]
class GeneralLight(Light):
    def __init__(self):
        path = os.path.dirname(__file__)
        path = os.path.join(path, 'light_shaders')
        self._loader = Loader([path])
        self.shader = None

    def _func_args(self, spectrum):
        func_args = [StructArgPtr('hitpoint', HitPoint.factory()),
                     StructArgPtr('shadepoint', ShadePoint.factory(spectrum))]
        return func_args


    def load(self, shader_name, color_mgr):
        args = []
        text = self._loader.load(shader_name, 'props.txt')
        if text is not None:
            args = parse_args(text, color_mgr)

        code = self._loader.load(shader_name, 'code.py')
        if code is None:
            raise ValueError("code.py in %s shader dont exist!" % shader_name)

        name = 'light_%i' % id(args)
        func_args = self._func_args(color_mgr.zero())
        self.shader = Shader(code=code, args=args, name=name,
                             func_args=func_args, is_func=True)
        self._color_mgr = color_mgr
        self._shader_name = shader_name

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

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

    def get_value(self, name):
        if self.shader is None:
            raise ValueError("Light shader is not loaded!")
        return self.shader.get_value(name)

    def set_value(self, name, val):
        if self.shader is None:
            raise ValueError("Light shader is not loaded!")
        if isinstance(val, (RGBSpectrum, SampledSpectrum)):
            val = self._color_mgr.convert_spectrum(val, illum=True)
        self.shader.set_value(name, val)

    def output(self, name):
        txt ='Light\n'
        txt +='type = %s\n' % self._shader_name 
        txt +='name = %s\n' % name

        args = []
        text = self._loader.load(self._shader_name, 'props.txt')
        if text is not None:
            args = parse_args(text)
        for arg in args:
            value = self.get_value(arg.name)
            txt += output_arg(arg.name, value)
        txt +='End\n'
        return txt
开发者ID:mario007,项目名称:renmas,代码行数:64,代码来源:light.py


注:本文中的sdl.Shader.set_value方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。