def register_sampled_shadepoint(col_mgr): wi = Vector3(0.0, 0.0, 0.0) wo = Vector3(0.0, 0.0, 0.0) ref = col_mgr.zero() register_struct(ShadePoint, 'ShadePoint', fields=[('wi', Vec3Arg), ('wo', Vec3Arg), ('pdf', FloatArg), ('material_reflectance', SampledArg)], factory=lambda: ShadePoint(wi, wo, 0.0, ref)) wi = Vector3(0.0, 0.0, 0.0) wo = Vector3(0.0, 0.0, 0.0) ref = col_mgr.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)] register_prototype('material_reflectance', func_args=func_args)
temp = ray.origin - self.origin a = ray.direction.dot(ray.direction) b = temp.dot(ray.direction) * 2.0 c = temp.dot(temp) - self.radius * self.radius disc = b * b - 4.0 * a * c if disc < 0.0: return False else: e = math.sqrt(disc) denom = 2.0 * a t = (-b - e) / denom # smaller root if t > 0.0005 and t < min_dist: normal = (temp + ray.direction * t) * (1.0 / self.radius) hit_point = ray.origin + ray.direction * t return HitPoint(t, hit_point, normal, self.mat_idx, 0.0, 0.0) t = (-b + e) / denom # larger root if t > 0.0005 and t < min_dist: normal = (temp + ray.direction * t) * (1.0 / self.radius) hit_point = ray.origin + ray.direction * t return HitPoint(t, hit_point, normal, self.mat_idx, 0.0, 0.0) return False register_struct(Sphere, 'Sphere', fields=[('origin', Vec3Arg), ('radius', FloatArg), ('mat_idx', IntArg)], factory=lambda: Sphere(Vector3(0.0, 0.0, 0.0), 0.0, 0))
from renlight.sdl import register_struct, IntArg, FloatArg class Sample: __slots__ = ['x', 'y', 'ix', 'iy', 'weight'] def __init__(self, x, y, ix, iy, weight): self.x = x self.y = y self.ix = ix self.iy = iy self.weight = weight def __repr__(self): return 'x=%f y=%f ix=%i iy=%i weight=%f' % (self.x, self.y, self.ix, self.iy, self.weight) register_struct(Sample, 'Sample', fields=[('x', FloatArg), ('y', FloatArg), ('ix', IntArg), ('iy', IntArg), ('weight', FloatArg)], factory=lambda: Sample(0.0, 0.0, 0, 0, 0.0))
from renlight.vector import Vector3 from renlight.sdl import register_struct, IntArg, FloatArg, Vec3Arg class HitPoint: __slots__ = ['t', 'hit', 'normal', 'mat_idx', 'u', 'v'] def __init__(self, t=0.0, hit=None, normal=None, mat_idx=0, u=0.0, v=0.0): self.t = t self.hit = hit self.normal = normal self.mat_idx = mat_idx self.u = u self.v = v register_struct(HitPoint, 'HitPoint', fields=[('t', FloatArg), ('hit', Vec3Arg), ('normal', Vec3Arg), ('mat_idx', IntArg), ('u', FloatArg), ('v', FloatArg)], factory=lambda: HitPoint(0.0, Vector3(0.0, 0.0, 0.0), Vector3(0.0, 0.0, 0.0), 0, 0.0, 0.0))
a = ray.direction.dot(ray.direction) b = temp.dot(ray.direction) * 2.0 c = temp.dot(temp) - self.radius * self.radius disc = b * b - 4.0 * a * c if disc < 0.0: return False else: e = math.sqrt(disc) denom = 2.0 * a t = (-b - e) / denom # smaller root if t > 0.0005 and t < min_dist: normal = (temp + ray.direction * t) * (1.0 / self.radius) hit_point = ray.origin + ray.direction * t return HitPoint(t, hit_point, normal, self.mat_idx, 0.0, 0.0) t = (-b + e) / denom # larger root if t > 0.0005 and t < min_dist: normal = (temp + ray.direction * t) * (1.0 / self.radius) hit_point = ray.origin + ray.direction * t return HitPoint(t, hit_point, normal, self.mat_idx, 0.0, 0.0) return False register_struct( Sphere, "Sphere", fields=[("origin", Vec3Arg), ("radius", FloatArg), ("mat_idx", IntArg)], factory=lambda: Sphere(Vector3(0.0, 0.0, 0.0), 0.0, 0), )
from renlight.sdl.args import ArgList from .sample import Sample class Tile2D: def __init__(self, x, y, width, height): self.x = x self.y = y self.width = width self.height = height register_struct(Tile2D, 'Tile2D', fields=[('x', IntArg), ('y', IntArg), ('width', IntArg), ('height', IntArg)], factory=lambda: Tile2D(0, 0, 1, 1)) def create_tiles(width, height, nthreads): hp = int(float(height) / nthreads) + 1 lst_tiles = [] for k in range(0, height, hp): nh = hp if k > height - hp: nh = height - k lst_tiles.append(Tile2D(0, k, width, nh)) return lst_tiles
from renlight.sdl.args import ArgList from .sample import Sample class Tile2D: def __init__(self, x, y, width, height): self.x = x self.y = y self.width = width self.height = height register_struct( Tile2D, "Tile2D", fields=[("x", IntArg), ("y", IntArg), ("width", IntArg), ("height", IntArg)], factory=lambda: Tile2D(0, 0, 1, 1), ) def create_tiles(width, height, nthreads): hp = int(float(height) / nthreads) + 1 lst_tiles = [] for k in range(0, height, hp): nh = hp if k > height - hp: nh = height - k lst_tiles.append(Tile2D(0, k, width, nh)) return lst_tiles