def render(self): self.src.render() for i in self.kern: self.kern[i] = ts.randUnit3D() * ti.random()**2 * self.radius for i in ti.grouped(self.repa): u = ts.randUnit3D() v = ts.randUnit3D() w = u.cross(v).normalized() v = w.cross(u) self.repa[i] = ti.Matrix.rows([u, v, w]) for i in ti.grouped(self.img): count = 0 normal = self.src['normal'][i] d0 = self.invdep(self.src.idepth[i]) for j in range(self.samples): r = self.repa[i % ts.vec2(*self.repa.shape)] @ self.kern[j] r = v4trans(self.src.camera.L2W.inverse(), r, 0) if r.dot(normal) < 0: r = -r rxy = self.src.camera.uncook(ts.vec3(r.xy, d0), False).xy d1 = self.invdep(ts.bilerp(self.src.idepth, i + rxy)) d1 = d1 - r.z if d1 < d0 - 1e-6: count += 1 ao = 1 - count / self.samples self.img[i] = ao
def add_random_particles(angular_velocity: ti.f32): num = ti.static(1) particle_id = alloc_particle() if ti.static(kDim == 2): particle_pos[particle_id] = tl.randSolid2D() * 0.2 + 0.5 velocity = (particle_pos[particle_id] - 0.5) * angular_velocity * 250 particle_vel[particle_id] = tl.vec(-velocity.y, velocity.x) else: particle_pos[particle_id] = tl.randUnit3D() * 0.2 + 0.5 velocity = (particle_pos[particle_id].xy - 0.5) * angular_velocity * 180 particle_vel[particle_id] = tl.vec(-velocity.y, velocity.x, 0.0) particle_mass[particle_id] = tl.randRange(0.0, 1.5)
def generate(): r = x[0] - sun ir = 1 / r.norm(1e-3)**2 pps = int(pps_scale * ir) for _ in range(pps): r = x[0] if ti.static(dim == 3): r = tl.randUnit3D() else: r = tl.randUnit2D() xi = ti.atomic_add(xcnt[None], 1) % (N - 1) + 1 x[xi] = x[0] v[xi] = r * initvel + v[0] inv_m[xi] = 0.5 + ti.random() color[xi] = colorinit
def radiance(self): outdir = ts.vec3(0.0) clr = ts.vec3(0.0) if ti.random() < self.emission: clr = ts.vec3(self.emission_color) elif ti.random() < self.specular: clr = ts.vec3(self.specular_color) outdir = ts.reflect(self.indir, self.normal) elif ti.random() < self.diffuse: clr = ts.vec3(self.diffuse_color) outdir = ts.randUnit3D() if outdir.dot(self.normal) < 0: outdir = -outdir #s = ti.random() #outdir = ts.vec3(ti.sqrt(1 - s**2) * ts.randUnit2D(), s) #outdir = ti.Matrix.cols([self.tangent, self.bitangent, self.normal]) @ outdir return self.pos, outdir, clr
def init(): for i in x: x[i] = (tl.randND(3) * 2 - 1) * (bound - radius) v[i] = tl.randUnit3D() * 4
def init(): for i in x: r = tl.randInt(0, 2) * 2 - 1 x[i] = tl.randUnit3D() + r * 7 v[i].x = 0.1 * r