Пример #1
0
def advect(fn: ti.template(), f: ti.template(), v: ti.template()):
    for I in ti.grouped(f):
        btI = backtrace(v, I, dt)
        ftI = backtrace(v, btI, -dt)
        f_btI = tl.bilerp(f, btI)
        f_ftI = tl.bilerp(f, ftI)
        fn[I] = f_btI + 0.5 * (f_ftI - f[I])
Пример #2
0
 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
Пример #3
0
 def sample(self, dir):
     I = ts.vec2(0.0)
     eps = 1e-5
     dps = 1 - 12 / self.texture.shape[0]
     if dir.z >= 0 and dir.z >= abs(dir.y) - eps and dir.z >= abs(
             dir.x) - eps:
         I = ts.vec(3 / 8, 3 / 8) + dir.xy / dir.z / 8 * dps
     if dir.z <= 0 and -dir.z >= abs(dir.y) - eps and -dir.z >= abs(
             dir.x) - eps:
         I = ts.vec(7 / 8, 3 / 8) + dir.Xy / -dir.z / 8 * dps
     if dir.x <= 0 and -dir.x >= abs(dir.y) - eps and -dir.x >= abs(
             dir.z) - eps:
         I = ts.vec(1 / 8, 3 / 8) + dir.zy / -dir.x / 8 * dps
     if dir.x >= 0 and dir.x >= abs(dir.y) - eps and dir.x >= abs(
             dir.z) - eps:
         I = ts.vec(5 / 8, 3 / 8) + dir.Zy / dir.x / 8 * dps
     if dir.y >= 0 and dir.y >= abs(dir.x) - eps and dir.y >= abs(
             dir.z) - eps:
         I = ts.vec(3 / 8, 5 / 8) + dir.xZ / dir.y / 8 * dps
     if dir.y <= 0 and -dir.y >= abs(dir.x) - eps and -dir.y >= abs(
             dir.z) - eps:
         I = ts.vec(3 / 8, 1 / 8) + dir.xz / -dir.y / 8 * dps
     I = ts.vec2(self.texture.shape[0]) * I
     return ts.bilerp(self.texture, I)
Пример #4
0
 def sample(self, name: ti.template(), texcoor, default):
     if ti.static(name in self.textures.keys()):
         tex = ti.static(self.textures[name])
         return ts.bilerp(tex, texcoor * ts.vec(*tex.shape))
     else:
         return default
Пример #5
0
def backtrace(v: ti.template(), I, dt):
    midI = I - 0.5 * tl.bilerp(v, I) * dt
    finI = I - dt * tl.bilerp(v, midI)
    return finI
Пример #6
0
 def velocity(self, P):
     return ts.bilerp(self.vel.old, P)
Пример #7
0
 def get(self):
     return ts.bilerp(self.texture,
                      self.texcoor * ts.vec(*self.texture.shape))
Пример #8
0
 def texSample(self, coor):
     if ti.static(self.tex is not None):
         return ts.bilerp(self.tex, coor * ts.vec(*self.tex.shape))
     else:
         return 1