Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[example] Add order-independent transparency example #6829

Merged
merged 18 commits into from
Dec 8, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions python/taichi/examples/rendering/oit_renderer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import taichi as ti
from taichi.math import clamp, mix, vec3, vec4
from taichi.math import clamp, mix, vec3, vec4, normalize

ti.init(arch=ti.cuda)
res = (1000, 1000)
Expand Down Expand Up @@ -30,8 +30,8 @@

@ti.func
def gooch_lighting(normal: ti.template()):
light = vec3(-1, 2, 1).normalized()
warmth = normal.normalized() * light * 0.5 + 0.5
light = normalize(vec3(-1, 2, 1))
warmth = normalize(normal) * light * 0.5 + 0.5
return mix(vec3(0, 0.25, 0.75), vec3(1, 1, 1), warmth)


Expand Down Expand Up @@ -70,12 +70,12 @@ def intersect_sphere(light: ti.template(), sphere: ti.template()):
if t1 > 0:
hit_pos1 = light.pos + light.dir * t1
dist1 = t1
normal1 = (hit_pos1 - sphere.center).normalized()
normal1 = normalize((hit_pos1 - sphere.center)
lin-hitonami marked this conversation as resolved.
Show resolved Hide resolved
t2 = tp + tt
if t2 > 0:
hit_pos2 = light.pos + light.dir * t2
dist2 = t2
normal2 = (hit_pos2 - sphere.center).normalized()
normal2 = normalize(hit_pos2 - sphere.center)
return Hit(pos=hit_pos1, normal=normal1, color=sphere.color, depth=dist1), \
Hit(pos=hit_pos2, normal=normal2, color=sphere.color, depth=dist2)

Expand Down Expand Up @@ -143,7 +143,7 @@ def render():
(2 * (v + 0.5) / res[1] - 1),
-1.0 / fov,
])
ray_dir = ray_dir.normalized()
ray_dir = normalize(ray_dir)
get_intersections(u, v, Light(pos=camera_pos, dir=ray_dir))
color = get_color(u, v)
color_buffer[u, v] = ti.pow(color.rgb * color.a, 1 / 2.2)
Expand Down