import taichi as ti import taichi_three as t3 ti.init(ti.cpu) mtllib = [None] scene = t3.Scene() model = t3.Model(t3.Mesh.from_obj('assets/monkey.obj')) model.material = t3.DeferredMaterial(mtllib, t3.Material(t3.CookTorrance())) scene.add_model(model) camera = t3.Camera() scene.add_camera_d(camera) gbuff = t3.FrameBuffer(camera, buffers=dict( mid=[(), int], position=[3, float], texcoord=[2, float], normal=[3, float], tangent=[3, float], )) imgbuf = t3.DeferredShading(gbuff, mtllib) scene.add_buffer(imgbuf) light = t3.Light([0.4, -1.5, -0.8], 0.9) scene.add_light(light) ambient = t3.AmbientLight(0.1) scene.add_light(ambient) gui = ti.GUI('Deferred Shading', imgbuf.res) while gui.running: gui.get_event(None) gui.running = not gui.is_pressed(ti.GUI.ESCAPE) camera.from_mouse(gui)
import taichi_three as t3 import numpy as np ti.init(ti.cpu) scene = t3.Scene() cornell = t3.readobj('assets/cornell.obj') cube = t3.readobj('assets/plane.obj') model = t3.Model(t3.Mesh.from_obj(cornell)) scene.add_model(model) light = t3.PointLight(pos=[0.0, 3.9, 0.0], color=15.0) scene.add_light(light) camera = t3.Camera() camera.ctl = t3.CameraCtl(pos=[0, 2, 6], target=[0, 2, 0]) scene.add_camera_d(camera) original = t3.FrameBuffer(camera) mapped = t3.ImgUnaryOp(original, lambda x: 1 - ti.exp(-x)) scene.add_buffer(mapped) #light.L2W[None] = t3.translate(0, 3.9, 0) gui_ldr = ti.GUI('LDR', camera.res) gui_hdr = ti.GUI('HDR', camera.res) while gui_ldr.running and gui_hdr.running: gui_hdr.get_event(None) camera.from_mouse(gui_hdr) scene.render() gui_ldr.set_image(original.img) gui_ldr.show() gui_hdr.set_image(mapped.img) gui_hdr.show()
import taichi as ti import taichi_three as t3 ti.init(ti.cpu) scene = t3.Scene() model = t3.Model(t3.Mesh.from_obj('assets/monkey.obj')) scene.add_model(model) camera = t3.Camera(res=(1024, 1024)) scene.add_camera_d(camera) buffer = t3.SuperSampling2x2(t3.FrameBuffer(camera)) scene.add_buffer(buffer) light = t3.Light([0.4, -1.5, -0.8], 0.9) scene.add_light(light) ambient = t3.AmbientLight(0.1) scene.add_light(ambient) gui = ti.GUI('SSAA 2x2', buffer.res) while gui.running: gui.get_event(None) gui.running = not gui.is_pressed(ti.GUI.ESCAPE) camera.from_mouse(gui) scene.render() gui.set_image(buffer.img) gui.show()
emission=t3.Constant(0.0), )) scene.add_model(model2) light = t3.Model(t3.Mesh.from_obj(plane)) light.material = t3.Material( t3.IdealRT( specular=t3.Constant(0.0), diffuse=t3.Constant(0.0), emission=t3.Constant(1.0), emission_color=t3.Constant(16.0), )) scene.add_model(light) camera = t3.RTCamera(res=res) camera.ctl = t3.CameraCtl(pos=[0, 2, 8], target=[0, 2, 0]) scene.add_camera_d(camera) camfb = t3.FrameBuffer(camera) if isinstance(camera, t3.RTCamera): camfb.clear_buffer = lambda: None else: scene.add_light(t3.PointLight(pos=(0, 3.9, 0), color=6.0)) accum = t3.AccDenoise(camfb) buffer = t3.ImgUnaryOp(accum, lambda x: 1 - ti.exp(-x)) scene.add_buffer(buffer) light.L2W[None] = t3.translate(0, 3.9, 0) @ t3.scale(0.25) gui = ti.GUI('Path tracing', camera.res) while gui.running: gui.get_event(None) gui.running = not gui.is_pressed(ti.GUI.ESCAPE) if camera.from_mouse(gui): accum.reset()
import taichi as ti import taichi_three as t3 import numpy as np ti.init(ti.cpu) scene = t3.Scene() model = t3.Model(t3.Mesh.from_obj('assets/monkey.obj')) scene.add_model(model) camera = t3.Camera() scene.add_camera_d(camera) buffer = t3.GaussianBlur(t3.FrameBuffer(camera), 8) scene.add_buffer(buffer) light = t3.Light([0.4, -1.5, -0.8]) scene.add_light(light) gui = ti.GUI('Gaussian', camera.res) while gui.running: gui.get_event(None) gui.running = not gui.is_pressed(ti.GUI.ESCAPE) camera.from_mouse(gui) scene.render() gui.set_image(buffer.img) gui.show()
import taichi as ti import taichi_three as t3 ti.init(ti.cpu) scene = t3.Scene() model = t3.Model(t3.Mesh.from_obj('assets/monkey.obj')) scene.add_model(model) plane = t3.Model(t3.QuadToTri(t3.MeshGrid(2))) scene.add_model(plane) camera = t3.Camera() scene.add_camera_d(camera) camerafb = t3.FrameBuffer(camera, buffers=dict( img=[3, float], normal=[3, float], )) ssaobuf = t3.LaplacianBlur(t3.SSAO(camerafb)) buffer = t3.ImgBinaryOp(camerafb, ssaobuf, lambda x, y: x * y) #buffer = ssaobuf scene.add_buffer(buffer) light = t3.Light([0.4, -1.5, -0.8], 0.9) scene.add_light(light) ambient = t3.AmbientLight(0.1) scene.add_light(ambient) plane.L2W[None] = t3.translate(0, -1, 0) @ t3.scale(2, 2, 2) gui = ti.GUI('SSAO', buffer.res) while gui.running: gui.get_event(None) gui.running = not gui.is_pressed(ti.GUI.ESCAPE)