本文整理匯總了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