Skip to content

Commit

Permalink
[test] [example] Add test and video generator for cornell box. (#4045)
Browse files Browse the repository at this point in the history
  • Loading branch information
ailzhang authored Jan 18, 2022
1 parent 016feb3 commit 3b5b3ef
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 15 deletions.
35 changes: 20 additions & 15 deletions python/taichi/examples/rendering/cornell_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,18 +491,23 @@ def tonemap(accumulated: ti.f32):
100.0)


gui = ti.GUI('Cornell Box', res, fast_gui=True)
gui.fps_limit = 300
last_t = time.time()
i = 0
while gui.running:
render()
interval = 10
if i % interval == 0:
tonemap(i)
print("{:.2f} samples/s ({} iters)".format(
interval / (time.time() - last_t), i))
last_t = time.time()
gui.set_image(tonemapped_buffer)
gui.show()
i += 1
def main():
gui = ti.GUI('Cornell Box', res, fast_gui=True)
gui.fps_limit = 300
last_t = time.time()
i = 0
while gui.running:
render()
interval = 10
if i % interval == 0:
tonemap(i)
print("{:.2f} samples/s ({} iters)".format(
interval / (time.time() - last_t), i))
last_t = time.time()
gui.set_image(tonemapped_buffer)
gui.show()
i += 1


if __name__ == '__main__':
main()
43 changes: 43 additions & 0 deletions tests/python/examples/rendering/test_cornell_box.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import argparse

import taichi as ti

FRAMES = 200


def test_cornell_box():
from taichi.examples.rendering.cornell_box import render, tonemap
for i in range(FRAMES):
render()
interval = 10
if i % interval == 0:
tonemap(i)


def video_cornell_box(result_dir):
from taichi.examples.rendering.cornell_box import (render, tonemap,
tonemapped_buffer)
video_manager = ti.VideoManager(output_dir=result_dir,
framerate=24,
automatic_build=False)
gui = ti.GUI("Taichi Cornell Box",
res=800,
background_color=0x112F41,
show_gui=False)
for i in range(FRAMES):
render()
interval = 10
if i % interval == 0:
tonemap(i)

gui.set_image(tonemapped_buffer)
video_manager.write_frame(gui.get_image())
gui.clear()
video_manager.make_video(mp4=True, gif=False)


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate cornell_box video')
parser.add_argument('output_directory',
help='output directory of generated video')
video_cornell_box(parser.parse_args().output_directory)

1 comment on commit 3b5b3ef

@vercel
Copy link

@vercel vercel bot commented on 3b5b3ef Jan 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.