forked from bsavery/ray-tracing-one-weekend-taichi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqueue.py
41 lines (32 loc) · 1.24 KB
/
queue.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import taichi as ti
@ti.func
def at(origin, direction, t):
return origin + direction * t
@ti.data_oriented
class Queue:
''' An queue of "in flight" rays'''
def __init__(self, total_size):
self.origin = ti.Vector.field(3, dtype=ti.f32)
self.direction = ti.Vector.field(3, dtype=ti.f32)
self.depth = ti.field(ti.i32)
self.attenuation = ti.Vector.field(3, dtype=ti.f32)
ti.root.dense(ti.i, (total_size)).place(self.origin, self.direction,
self.depth, self.attenuation)
@ti.func
def set(self, queue_ind, ray_org, ray_dir, depth, attenuation):
self.origin[queue_ind] = ray_org
self.direction[queue_ind] = ray_dir
self.depth[queue_ind] = depth
self.attenuation[queue_ind] = attenuation
@ti.func
def get(self, queue_ind):
return self.origin[queue_ind], self.direction[queue_ind], self.depth[queue_ind], self.attenuation[queue_ind]
@ti.func
def get_od(self, queue_ind):
return self.origin[queue_ind], self.direction[queue_ind]
@ti.func
def get_depth(self, queue_ind):
return self.depth[queue_ind]
@ti.func
def set_depth(self, queue_ind, d):
self.depth[queue_ind] = d