本文整理汇总了Python中sdl.Shader.get_value方法的典型用法代码示例。如果您正苦于以下问题:Python Shader.get_value方法的具体用法?Python Shader.get_value怎么用?Python Shader.get_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sdl.Shader
的用法示例。
在下文中一共展示了Shader.get_value方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SamplerGenerator
# 需要导入模块: from sdl import Shader [as 别名]
# 或者: from sdl.Shader import get_value [as 别名]
class SamplerGenerator():
def __init__(self, sampler):
self.sampler = sampler
self.prepare_standalone()
def prepare_standalone(self):
self.sampler.create_shader()
runtimes = [Runtime()]
self.sampler.compile()
self.sampler.prepare(runtimes)
code = """
ret = generate_sample(sample)
"""
args = [StructArg('sample', Sample.factory()), IntArg('ret', 11)]
self._standalone = Shader(code=code, args=args)
self._standalone.compile([self.sampler.shader])
self._standalone.prepare(runtimes)
def generate_sample(self):
self._standalone.execute()
ret = self._standalone.get_value('ret')
if ret == 0:
return False
sample = self._standalone.get_value('sample')
return sample
示例2: test_linear
# 需要导入模块: from sdl import Shader [as 别名]
# 或者: from sdl.Shader import get_value [as 别名]
def test_linear(self):
sphere = Sphere(Vector3(0.0, 0.0, 0.0), 2.0, 0)
mgr = ShapeManager()
mgr.add('sph1', sphere)
sphere2 = Sphere(Vector3(0.0, 2.0, 0.0), 3.0, 0)
mgr.add('sph2', sphere2)
isector = LinearIsect(mgr)
runtimes = [Runtime()]
direction = Vector3(-1.0, -1.0, -1.0)
direction.normalize()
ray = Ray(Vector3(5.0, 5.0, 5.0), direction)
isector.compile()
isector.prepare(runtimes)
code = """
min_dist = 99999.0
p1 = isect_scene(ray, hitpoint, min_dist)
"""
direction = Vector3(-1.0, -1.0, -1.0)
direction.normalize()
ray = Ray(Vector3(5.0, 5.0, 5.0), direction)
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)
harg = StructArg('hitpoint', hitpoint)
p1 = IntArg('p1', 6)
args = [r_arg, harg, p1]
shader = Shader(code=code, args=args)
shader.compile([isector.shader])
shader.prepare(runtimes)
hp2 = isector.isect(ray)
shader.execute()
hitpoint = shader.get_value('hitpoint')
self.assertAlmostEqual(hp2.t, hitpoint.t, places=5)
self.assertEqual(hp2.mat_idx, hitpoint.mat_idx)
n1 = hp2.normal
n2 = hitpoint.normal
self.assertAlmostEqual(n1.x, n2.x)
self.assertAlmostEqual(n1.y, n2.y, places=6)
self.assertAlmostEqual(n1.z, n2.z)
self.assertAlmostEqual(hitpoint.hit.x, hp2.hit.x, places=6)
self.assertAlmostEqual(hitpoint.hit.y, hp2.hit.y, places=6)
self.assertAlmostEqual(hitpoint.hit.z, hp2.hit.z, places=6)
result = shader.get_value('p1')
self.assertEqual(result, 1)
示例3: test_isect_rect
# 需要导入模块: from sdl import Shader [as 别名]
# 或者: from sdl.Shader import get_value [as 别名]
def test_isect_rect(self):
rect_shader = Rectangle.isect_shader('isect_rectangle')
rect_shader.compile()
runtimes = [Runtime()]
rect_shader.prepare(runtimes)
code = """
min_dist = 99999.0
p1 = isect_rectangle(ray, rectangle, hitpoint, min_dist)
"""
origin = Vector3(3.0, 2.5, 0.0)
direction = Vector3(0.0, 0.1, 0.88)
direction.normalize()
ray = Ray(origin, direction)
point = Vector3(0.0, 0.0, 55.92)
e1 = Vector3(55.28, 0.0, 0.0)
e2 = Vector3(0.0, 54.88, 0.0)
normal = Vector3(0.0, 0.0, -1.0)
rectangle = Rectangle(point, e1, e2, normal)
hitpoint = HitPoint.factory()
hitpoint.mat_idx = 5
r_arg = StructArg('ray', ray)
sph_arg = StructArg('rectangle', rectangle)
harg = StructArg('hitpoint', hitpoint)
p1 = IntArg('p1', 6)
args = [r_arg, sph_arg, harg, p1]
shader = Shader(code=code, args=args)
shader.compile([rect_shader.shader])
shader.prepare(runtimes)
shader.execute()
hp2 = rectangle.isect(ray)
hitpoint = shader.get_value('hitpoint')
self.assertAlmostEqual(hp2.t, hitpoint.t, places=5)
self.assertEqual(hp2.mat_idx, hitpoint.mat_idx)
n1 = hp2.normal
n2 = hitpoint.normal
self.assertAlmostEqual(n1.x, n2.x)
self.assertAlmostEqual(n1.y, n2.y)
self.assertAlmostEqual(n1.z, n2.z)
self.assertAlmostEqual(hitpoint.hit.x, hp2.hit.x, places=5)
self.assertAlmostEqual(hitpoint.hit.y, hp2.hit.y, places=5)
self.assertAlmostEqual(hitpoint.hit.z, hp2.hit.z, places=5)
result = shader.get_value('p1')
self.assertEqual(result, 1)
示例4: test_sampled_point_light
# 需要导入模块: from sdl import Shader [as 别名]
# 或者: from sdl.Shader import get_value [as 别名]
def test_sampled_point_light(self):
sam_mgr = SampledManager()
register_sampled_shadepoint(sam_mgr)
runtimes = [Runtime()]
lgt = GeneralLight()
lgt.load('point', sam_mgr, spectral=True)
lgt.set_value('intensity', RGBSpectrum(0.3, 0.3, 0.3))
lgt.set_value('position', Vector3(2.0, 2.0, 2.0))
lgt.compile()
lgt.prepare(runtimes)
ptrs = lgt.shader.get_ptrs()
ptr_func = PointerArg('ptr_func', ptrs[0])
spec = SampledArg('spec', sam_mgr.zero())
wi = Vec3Arg('wi', Vector3(0.0, 0.0, 0.0))
pos = Vec3Arg('position', Vector3(0.0, 0.0, 0.0))
code = """
hp = HitPoint()
hp.hit = (4.0, 5, 6)
sp = ShadePoint()
__light_radiance(hp, sp, ptr_func)
spec = sp.light_intensity
wi = sp.wi
position = sp.light_position
"""
shader = Shader(code=code, args=[ptr_func, wi, spec, pos])
shader.compile()
shader.prepare(runtimes)
shader.execute()
wi = Vector3(2.0, 2.0, 2.0) - Vector3(4.0, 5.0, 6.0)
wi.normalize()
wi_s = shader.get_value('wi')
self.assertAlmostEqual(wi.x, wi_s.x)
self.assertAlmostEqual(wi.y, wi_s.y)
self.assertAlmostEqual(wi.z, wi_s.z)
p = Vector3(2.0, 2.0, 2.0)
p_s = shader.get_value('position')
self.assertAlmostEqual(p.x, p_s.x)
self.assertAlmostEqual(p.y, p_s.y)
self.assertAlmostEqual(p.z, p_s.z)
s = sam_mgr.rgb_to_sampled(RGBSpectrum(0.3, 0.3, 0.3), illum=True)
s_s = shader.get_value('spec')
for i in range(len(s.samples)):
self.assertAlmostEqual(s.samples[i], s_s.samples[i])
示例5: test_mesh
# 需要导入模块: from sdl import Shader [as 别名]
# 或者: from sdl.Shader import get_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('------------------------------------------')
示例6: test_sampled_to_rgb
# 需要导入模块: from sdl import Shader [as 别名]
# 或者: from sdl.Shader import get_value [as 别名]
def test_sampled_to_rgb(self):
runtimes = [Runtime()]
color_mgr = SampledManager()
s_to_rgb = spectrum_to_rgb_shader(color_mgr)
s_to_rgb.compile(color_mgr=color_mgr)
s_to_rgb.prepare(runtimes)
code = """
value = spectrum_to_rgb(color)
"""
spec = RGBSpectrum(0.3, 0.5, 0.4)
spec = color_mgr.rgb_to_sampled(spec)
col = SampledArg('color', spec)
val = Vec3Arg('value', Vector3(0.0, 0.0, 0.0))
shader = Shader(code=code, args=[col, val])
shader.compile(shaders=[s_to_rgb], color_mgr=color_mgr)
shader.prepare(runtimes)
shader.execute()
value = shader.get_value('value')
vv = color_mgr.sampled_to_rgb(spec)
self.assertAlmostEqual(value.x, vv.r)
self.assertAlmostEqual(value.y, vv.g)
self.assertAlmostEqual(value.z, vv.b, places=6)
示例7: test_isect_b_rect
# 需要导入模块: from sdl import Shader [as 别名]
# 或者: from sdl.Shader import get_value [as 别名]
def test_isect_b_rect(self):
rect_shader = Rectangle.isect_b_shader('isect_b_rectangle')
rect_shader.compile()
runtimes = [Runtime()]
rect_shader.prepare(runtimes)
code = """
min_dist = 99999.0
p1 = isect_b_rectangle(ray, rectangle, min_dist)
"""
origin = Vector3(3.0, 2.5, 0.0)
direction = Vector3(0.0, 0.1, 0.88)
direction.normalize()
ray = Ray(origin, direction)
point = Vector3(0.0, 0.0, 55.92)
e1 = Vector3(55.28, 0.0, 0.0)
e2 = Vector3(0.0, 54.88, 0.0)
normal = Vector3(0.0, 0.0, -1.0)
rectangle = Rectangle(point, e1, e2, normal)
r_arg = StructArg('ray', ray)
sph_arg = StructArg('rectangle', rectangle)
p1 = IntArg('p1', 6)
args = [r_arg, sph_arg, p1]
shader = Shader(code=code, args=args)
shader.compile([rect_shader.shader])
shader.prepare(runtimes)
shader.execute()
result = shader.get_value('p1')
self.assertEqual(result, 1)
示例8: test_mesh_b
# 需要导入模块: from sdl import Shader [as 别名]
# 或者: from sdl.Shader import get_value [as 别名]
def test_mesh_b(mesh, nrays=1):
dep_shader = type(mesh).isect_b_shader('ray_flat_mesh_b_isect')
dep_shader.compile()
runtimes = [Runtime()]
dep_shader.prepare(runtimes)
code = """
min_dist = 99999.0
ret = ray_flat_mesh_b_isect(ray, mesh, min_dist)
"""
origin = calculate_origin(mesh)
rpoint = random_in_bbox(mesh._grid.bbox)
direction = rpoint - origin
direction.normalize()
ray = Ray(origin, direction)
r_arg = StructArg('ray', ray)
mesh_arg = StructArg('mesh', mesh)
ret = IntArg('ret', 6)
args = [r_arg, mesh_arg, ret]
shader = Shader(code=code, args=args)
shader.compile([dep_shader.shader])
shader.prepare(runtimes)
hp = mesh.isect_b(ray)
shader.execute()
print("Bool isect", hp, shader.get_value('ret'))
示例9: test_isect_b_sph
# 需要导入模块: from sdl import Shader [as 别名]
# 或者: from sdl.Shader import get_value [as 别名]
def test_isect_b_sph(self):
sph_shader = Sphere.isect_b_shader('isect_b_sphere')
sph_shader.compile()
runtimes = [Runtime()]
sph_shader.prepare(runtimes)
code = """
min_dist = 99999.0
p1 = isect_b_sphere(ray, sphere, min_dist)
"""
direction = Vector3(-1.0, -1.0, -1.0)
direction.normalize()
ray = Ray(Vector3(5.0, 5.0, 5.0), direction)
sphere = Sphere(Vector3(0.0, 0.0, 0.0), 2.0, 0)
r_arg = StructArg('ray', ray)
sph_arg = StructArg('sphere', sphere)
p1 = IntArg('p1', 6)
args = [r_arg, sph_arg, p1]
shader = Shader(code=code, args=args)
shader.compile([sph_shader.shader])
shader.prepare(runtimes)
shader.execute()
result = shader.get_value('p1')
self.assertEqual(result, 1)
示例10: atest_material_manager
# 需要导入模块: from sdl import Shader [as 别名]
# 或者: from sdl.Shader import get_value [as 别名]
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)
示例11: test_isect_sph
# 需要导入模块: from sdl import Shader [as 别名]
# 或者: from sdl.Shader import get_value [as 别名]
def test_isect_sph(self):
sph_shader = Sphere.isect_shader('isect_sphere')
sph_shader.compile()
runtimes = [Runtime()]
sph_shader.prepare(runtimes)
code = """
min_dist = 99999.0
p1 = isect_sphere(ray, sphere, hitpoint, min_dist)
"""
direction = Vector3(-1.0, -1.0, -1.0)
direction.normalize()
ray = Ray(Vector3(5.0, 5.0, 5.0), direction)
sphere = Sphere(Vector3(0.0, 0.0, 0.0), 2.0, 0)
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)
sph_arg = StructArg('sphere', sphere)
harg = StructArg('hitpoint', hitpoint)
p1 = IntArg('p1', 6)
args = [r_arg, sph_arg, harg, p1]
shader = Shader(code=code, args=args)
shader.compile([sph_shader.shader])
shader.prepare(runtimes)
shader.execute()
hp2 = sphere.isect(ray)
hitpoint = shader.get_value('hitpoint')
self.assertAlmostEqual(hp2.t, hitpoint.t)
self.assertEqual(hp2.mat_idx, hitpoint.mat_idx)
n1 = hp2.normal
n2 = hitpoint.normal
self.assertAlmostEqual(n1.x, n2.x)
self.assertAlmostEqual(n1.y, n2.y)
self.assertAlmostEqual(n1.z, n2.z)
self.assertAlmostEqual(hitpoint.hit.x, hp2.hit.x)
self.assertAlmostEqual(hitpoint.hit.y, hp2.hit.y)
self.assertAlmostEqual(hitpoint.hit.z, hp2.hit.z)
result = shader.get_value('p1')
self.assertEqual(result, 1)
示例12: test_light_manager
# 需要导入模块: from sdl import Shader [as 别名]
# 或者: from sdl.Shader import get_value [as 别名]
def test_light_manager(self):
sam_mgr = SampledManager()
register_rgb_shadepoint()
runtimes = [Runtime(), Runtime()]
lgt = GeneralLight()
lgt.load('point', sam_mgr, spectral=False)
lgt2 = GeneralLight()
lgt2.load('point', sam_mgr, spectral=False)
lgt2.set_value('intensity', RGBSpectrum(0.3, 0.3, 0.3))
lgt2.set_value('position', Vector3(2.0, 2.0, 2.0))
mgr = LightManager()
mgr.add('light1', lgt)
mgr.add('light2', lgt2)
mgr.compile_shaders(sam_mgr, spectral=False)
mgr.prepare_shaders(runtimes)
code = """
hp = HitPoint()
hp.hit = (4.0, 5, 6)
sp = ShadePoint()
light_radiance(hp, sp, 1)
wi = sp.wi
n = number_of_lights()
"""
wi = Vec3Arg('wi', Vector3(0.0, 0.0, 0.0))
nlights = IntArg('n', 999)
shader = Shader(code=code, args=[wi, nlights])
shader.compile(shaders=[mgr.rad_shader, mgr.nlights_shader])
shader.prepare(runtimes)
shader.execute()
wi = Vector3(2.0, 2.0, 2.0) - Vector3(4.0, 5.0, 6.0)
wi.normalize()
wi_s = shader.get_value('wi')
self.assertAlmostEqual(wi.x, wi_s.x)
self.assertAlmostEqual(wi.y, wi_s.y)
self.assertAlmostEqual(wi.z, wi_s.z)
self.assertEqual(2, shader.get_value('n'))
示例13: test_material_sampling_manager
# 需要导入模块: from sdl import Shader [as 别名]
# 或者: from sdl.Shader import get_value [as 别名]
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))
示例14: test_isect_flat_triangle1
# 需要导入模块: from sdl import Shader [as 别名]
# 或者: from sdl.Shader import get_value [as 别名]
def test_isect_flat_triangle1(self):
runtimes = [Runtime()]
tri_shader = FlatTriangle.isect_shader('isect_flat_triangle')
tri_shader.compile()
tri_shader.prepare(runtimes)
p0 = Vector3(-0.0831229984, 0.0591476, -0.03213749)
p1 = Vector3(-0.082775, 0.059025, -0.031787)
p2 = Vector3(-0.0831229, 0.0591773, -0.031787)
origin = Vector3(-0.21276909825205803,-0.021492251798510553,-0.09822520208358765)
direction = Vector3(0.7788769269741005,0.4843782624535974,0.3984073687694737)
ray = Ray(origin, direction)
hitpoint = HitPoint(0.0, Vector3(0.0, 0.0, 0.0),
Vector3(0.0, 0.0, 0.0), 6, 0.0, 0.0)
t = FlatTriangle(p0, p1, p2)
code = """
min_dist = 150.0
ret = isect_flat_triangle(ray, triangle, hitpoint, min_dist)
"""
r_arg = StructArg('ray', ray)
tri_arg = StructArg('triangle', t)
harg = StructArg('hitpoint', hitpoint)
ret = IntArg('ret', 6)
args = [r_arg, tri_arg, harg, ret]
shader = Shader(code=code, args=args)
shader.compile([tri_shader.shader])
shader.prepare(runtimes)
shader.execute()
min_dist = 150.0
hit = t.isect(ray, min_dist)
hp = shader.get_value('hitpoint')
self.assertAlmostEqual(hit.t, hp.t, places=6)
self._almost_equal_vec3(hit.hit, hp.hit, places=6)
self._almost_equal_vec3(hit.normal, hp.normal, places=6)
self.assertEqual(hit.mat_idx, hp.mat_idx)
self.assertAlmostEqual(hit.u, hp.u)
self.assertAlmostEqual(hit.v, hp.v)
示例15: test_isect_flat_triangle
# 需要导入模块: from sdl import Shader [as 别名]
# 或者: from sdl.Shader import get_value [as 别名]
def test_isect_flat_triangle(self):
runtimes = [Runtime()]
tri_shader = FlatTriangle.isect_shader('isect_flat_triangle')
tri_shader.compile()
tri_shader.prepare(runtimes)
p0 = Vector3(2.2, 4.4, 6.6)
p1 = Vector3(1.1, 1.1, 1.1)
p2 = Vector3(5.1, -1.1, 5.1)
origin = Vector3(0.0, 0.0, 0.0)
direction = Vector3(3, 3.0, 3.01)
direction.normalize()
ray = Ray(origin, direction)
hitpoint = HitPoint(0.0, Vector3(0.0, 0.0, 0.0),
Vector3(0.0, 0.0, 0.0), 6, 0.0, 0.0)
t = FlatTriangle(p0, p1, p2)
code = """
min_dist = 150.0
ret = isect_flat_triangle(ray, triangle, hitpoint, min_dist)
"""
r_arg = StructArg('ray', ray)
tri_arg = StructArg('triangle', t)
harg = StructArg('hitpoint', hitpoint)
ret = IntArg('ret', 6)
args = [r_arg, tri_arg, harg, ret]
shader = Shader(code=code, args=args)
shader.compile([tri_shader.shader])
shader.prepare(runtimes)
shader.execute()
min_dist = 150.0
hit = t.isect(ray, min_dist)
hp = shader.get_value('hitpoint')
self.assertAlmostEqual(hit.t, hp.t, places=6)
self._almost_equal_vec3(hit.hit, hp.hit, places=6)
self._almost_equal_vec3(hit.normal, hp.normal, places=6)
self.assertEqual(hit.mat_idx, hp.mat_idx)
self.assertAlmostEqual(hit.u, hp.u)
self.assertAlmostEqual(hit.v, hp.v)