forked from ltt1598/--Shadertoys
-
Notifications
You must be signed in to change notification settings - Fork 2
/
05_water_caustic.py
50 lines (36 loc) · 1.27 KB
/
05_water_caustic.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
42
43
44
45
46
47
48
49
50
# reference ==> https://www.shadertoy.com/view/MdlXz8
import taichi as ti
import handy_shader_functions as hsf
ti.init(arch = ti.cuda)
res_x = 512
res_y = 512
pixels = ti.Vector.field(3, ti.f32, shape=(res_x, res_y))
PI = 3.1415926
TAU = 2*PI
@ti.kernel
def render(time:ti.f32):
# draw something on your canvas
for i,j in pixels:
color = ti.Vector([0.0, 0.0, 0.0]) # init your canvas to black
uv = ti.Vector([float(i)/res_x, float(j)/res_y])
p = hsf.mod(uv * TAU, TAU) - 250.0
p2 = p
c = 1.0
inten = 0.005
max_iter = 5
for k in range(max_iter):
t = time * (1.0 - (3.5 / float(k+1)))
p2 = p + ti.Vector([ti.cos(t-p2.x) + ti.sin(t+p2.y), ti.sin(t-p2.y)+ti.cos(t+p2.x)])
c += 1.0/(ti.Vector([p.x / (ti.sin(p2.x+t)/inten), p.y / (ti.cos(p2.y + t) / inten)])).norm()
c /= float(max_iter)
c = 1.17 - c**1.4 # reverse
c = c ** 8 # making it sharp
color = ti.Vector([1.0, 1.0, 1.0]) * c
color += hsf.clamp(ti.Vector([0.0, 0.35, 0.5]), 0.0, 1.0) # turning blue
pixels[i,j] = color
gui = ti.GUI("Canvas", res=(res_x, res_y))
for i in range(100000):
t = i * 0.03
render(t)
gui.set_image(pixels)
gui.show()