Ejemplo n.º 1
0
 def func():
     ti.parallelize(1)
     for i in range(2):
         t = 0.0
         if x[i] > 0:
             t = 1 / x[i]
         y[i] = t
Ejemplo n.º 2
0
def render():
    ti.parallelize(6)
    for u, v in color_buffer(0):
        pos = camera_pos
        d = ti.Vector([(2 * fov * (u + ti.random(ti.f32)) / res[1] -
                        fov * aspect_ratio - 1e-5),
                       2 * fov * (v + ti.random(ti.f32)) / res[1] - fov - 1e-5,
                       -1.0])
        d = ti.Matrix.normalized(d)
        if u < res[0] and v < res[1]:
            t = (ti.random() - 0.5) * shutter_time

            contrib = ti.Vector([0.0, 0.0, 0.0])
            throughput = ti.Vector([1.0, 1.0, 1.0])

            depth = 0
            hit_sky = 1
            ray_depth = 0

            while depth < max_ray_depth:
                closest, normal, c = next_hit(pos, d, t)
                hit_pos = pos + closest * d
                depth += 1
                ray_depth = depth
                if normal.norm() != 0:
                    d = out_dir(normal)
                    pos = hit_pos + 1e-4 * d
                    throughput *= c

                    if ti.static(use_directional_light):
                        dir_noise = ti.Vector([
                            ti.random() - 0.5,
                            ti.random() - 0.5,
                            ti.random() - 0.5
                        ]) * light_direction_noise
                        direct = ti.Matrix.normalized(
                            ti.Vector(light_direction) + dir_noise)
                        dot = direct.dot(normal)
                        if dot > 0:
                            dist, _, _ = next_hit(pos, direct, t)
                            if dist > dist_limit:
                                contrib += throughput * ti.Vector(
                                    light_color) * dot
                else:  # hit sky
                    hit_sky = 1
                    depth = max_ray_depth

                max_c = throughput.max()
                if ti.random() > max_c:
                    depth = max_ray_depth
                    throughput = [0, 0, 0]
                else:
                    throughput /= max_c

            if hit_sky:
                if ray_depth != 1:
                    # contrib *= ti.max(d[1], 0.05)
                    pass
                else:
                    # directly hit sky
                    pass
            else:
                throughput *= 0

            # contrib += throughput
            color_buffer[u, v] += contrib
Ejemplo n.º 3
0
 def fill():
     ti.parallelize(8)
     ti.block_dim(8)
     for i in range(n):
         val[i] = i