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


Python Shader.get_ptrs方法代码示例

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


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

示例1: __init__

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


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