x[i] += dt * v[i] ### Rendering GUI scene = t3.Scene() camera = t3.Camera() camera.ctl = t3.CameraCtl(pos=[0, 0.8, -1.1], target=[0, 0.25, 0]) scene.add_camera(camera) light = t3.Light(dir=[0.4, -1.5, 1.8]) #scene.add_shadow_camera(light.make_shadow_camera()) # comment this if you get too poor FPS scene.add_light(light) mesh = t3.MeshGrid((N, N)) model = t3.Model(t3.QuadToTri(mesh)) model.material = t3.Material(t3.CookTorrance(color=t3.Texture('assets/cloth.jpg'))) scene.add_model(model) sphere = t3.Model(t3.Mesh.from_obj('assets/sphere.obj')) scene.add_model(sphere) @ti.kernel def update_display(): for i in ti.grouped(x): mesh.pos[i] = x[i] init() sphere.L2W[None] = t3.translate(ball_pos) @ t3.scale(ball_radius) with ti.GUI('Mass Spring', camera.res) as gui:
for i in ti.grouped(x): v[i] *= ti.exp(-damping * dt) x[i] += dt * v[i] ### Rendering GUI scene = t3.Scene() camera = t3.Camera() camera.ctl = t3.CameraCtl(pos=[0, 0.8, -1.1], target=[0, 0.25, 0]) scene.add_camera(camera) mesh = t3.MeshGrid((N, N)) model = t3.Model(t3.QuadToTri(mesh)) model.material = t3.Material( t3.CookTorrance(color=t3.Texture('assets/cloth.jpg'))) scene.add_model(model) sphere = t3.Model(t3.Mesh.from_obj('assets/sphere.obj')) scene.add_model(sphere) light = t3.Light(dir=[0.4, -1.5, 1.8]) scene.add_light(light) scene.add_camera(light.make_shadow_camera()) @ti.kernel def update_display(): for i in ti.grouped(x): mesh.pos[i] = x[i]
import taichi_three as t3 scene = t3.Scene() camera = t3.Camera() scene.add_camera(camera) light = t3.Light(dir=[-0.2, -0.6, -1.0]) scene.add_light(light) obj = t3.Geometry.cube() model = t3.Model(t3.Mesh.from_obj(obj)) model.material = t3.Material(t3.BlinnPhong( color=t3.Texture('container2.png'), specular=t3.Texture('container2_specular.png'), )) scene.add_model(model) gui = t3.GUI('Binding Textures') while gui.running: scene.render() gui.get_event(None) camera.from_mouse(gui) gui.set_image(camera.img) gui.show()
import taichi as ti import taichi_three as t3 import numpy as np ti.init(ti.cpu) scene = t3.Scene() obj = t3.readobj('assets/torus.obj', scale=0.8) model = t3.Model(t3.Mesh.from_obj(obj)) model.material = t3.Material( t3.CookTorrance(color=t3.Texture(ti.imread('assets/cloth.jpg')), )) scene.add_model(model) camera = t3.Camera() camera.ctl = t3.CameraCtl(pos=[0, 1, -1.8]) scene.add_camera(camera) light = t3.Light([0.4, -1.5, 1.8]) scene.add_light(light) gui = ti.GUI('Model', 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(camera.img) gui.show()
import taichi as ti import taichi_three as t3 import numpy as np ti.init(ti.cpu) scene = t3.Scene() obj = t3.readobj('assets/torus.obj', scale=0.8) model = t3.Model(t3.Mesh.from_obj(obj)) model.material = t3.Material( t3.CookTorrance( color=t3.Texture(ti.imread('assets/cloth.jpg')), ambient=t3.Texture(ti.imread('assets/pattern.jpg')), )) scene.add_model(model) camera = t3.Camera() camera.ctl = t3.CameraCtl(pos=[0, 1, -1.8]) scene.add_camera(camera) ambient_light = t3.AmbientLight() scene.add_light(ambient_light) gui = ti.GUI('Model', 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(camera.img) gui.show()
import taichi as ti import taichi_three as t3 import numpy as np ti.init(ti.cpu) scene = t3.Scene() obj = t3.readobj('assets/cube.obj', scale=0.6) model = t3.Model(t3.Mesh.from_obj(obj)) model.material = t3.Material( t3.CookTorrance( color=t3.Texture(ti.imread('assets/cloth.jpg')), normal=t3.NormalMap( texture=t3.Texture(ti.imread('assets/normal.png'))), )) scene.add_model(model) camera = t3.Camera() camera.ctl = t3.CameraCtl(pos=[0, 1, 1.8]) scene.add_camera(camera) light = t3.Light([0.4, -0.8, -1.7]) scene.add_light(light) gui = ti.GUI('Normal map', 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(camera.img) #gui.set_image(camera.fb['normal'].to_numpy() * 0.5 + 0.5) gui.show()
import taichi as ti import taichi_three as t3 import numpy as np ti.init(ti.cpu) scene = t3.Scene() obj = t3.readobj('assets/torus.obj', scale=0.8) model = t3.Model(t3.Mesh.from_obj(obj)) model.material = t3.Material(t3.CookTorrance( color=t3.Texture(ti.imread('assets/cloth.jpg')), )) scene.add_model(model) camera = t3.Camera() camera.ctl = t3.CameraCtl(pos=[0, 1, -1.8]) scene.add_camera(camera) light = t3.Light([0.4, -1.5, 1.8]) scene.add_light(light) gui = ti.GUI('Textures', 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(camera.img) gui.show()
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(t3.readobj('assets/torus.obj', scale=0.8))) model.material = t3.Material( t3.CookTorrance( color=t3.Texture(ti.imread('assets/cloth.jpg')), roughness=t3.Texture(ti.imread('assets/pattern.jpg')), metallic=t3.Constant(0.5), )) scene.add_model(model) camera = t3.Camera() camera.ctl = t3.CameraCtl(pos=[0.8, 0, 2.5]) scene.add_camera(camera) light = t3.Light([0, -0.5, -1]) scene.add_light(light) ambient = t3.AmbientLight(0.3) scene.add_light(ambient) gui = ti.GUI('PBR demo', camera.res) while gui.running: gui.get_event(None) gui.running = not gui.is_pressed(ti.GUI.ESCAPE) camera.from_mouse(gui) model.L2W[None] = t3.rotateX(angle=t3.get_time()) scene.render() gui.set_image(camera.img)
import taichi_three as t3 import numpy as np res = 512, 512 ti.init(ti.cpu) scene = t3.Scene() cornell = t3.objunpackmtls(t3.readobj('assets/cornell.obj')) plane = t3.readobj('assets/plane.obj') model1 = t3.Model(t3.Mesh.from_obj(cornell[b'Material'])) model1.material = t3.Material( t3.IdealRT( specular=t3.Constant(0.0), diffuse=t3.Constant(1.0), emission=t3.Constant(0.0), diffuse_color=t3.Texture('assets/smallptwall.png'), )) scene.add_model(model1) model2 = t3.Model(t3.Mesh.from_obj(cornell[b'Material.001'])) model2.material = t3.Material( t3.IdealRT( specular=t3.Constant(0.7), diffuse=t3.Constant(1.0), 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),
parts = t3.objunpackmtls(t3.readobj('assets/multimtl.obj', scale=0.8)) model1 = t3.Model(t3.Mesh.from_obj(parts[b'Material1'])) model2 = t3.Model(t3.Mesh.from_obj(parts[b'Material2'])) model1.material = t3.DeferredMaterial( mtllib, t3.Material( t3.CookTorrance( # Up: gold color=t3.Constant(t3.RGB(1.0, 0.96, 0.88)), roughness=t3.Constant(0.2), metallic=t3.Constant(0.75), ))) model2.material = t3.DeferredMaterial( mtllib, t3.Material( t3.CookTorrance( # Down: cloth color=t3.Texture('assets/cloth.jpg'), roughness=t3.Constant(0.3), metallic=t3.Constant(0.0), ))) scene.add_model(model1) scene.add_model(model2) camera = t3.Camera() camera.ctl = t3.CameraCtl(pos=[0.8, 0, 2.5]) 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],
import taichi as ti import taichi_three as t3 import numpy as np ti.init(ti.cpu) scene = t3.Scene() obj = t3.Geometry.cube() model = t3.Model(t3.Mesh.from_obj(obj)) model.material = t3.Material( t3.BlinnPhong( # https://learnopengl.com/img/textures/container2.png color=t3.Texture('docs/_media/container2.png'), specular=t3.Texture('docs/_media/container2_specular.png'), )) scene.add_model(model) camera = t3.Camera() scene.add_camera_d(camera) original = t3.FrameBuffer(camera) filted = t3.ImgUnaryOp(original, lambda x: ti.max(0, x - 1)) blurred = t3.GaussianBlur(filted, radius=21) final = t3.ImgBinaryOp(original, blurred, lambda x, y: x + y) scene.add_buffer(final) light = t3.Light(dir=[-0.2, -0.6, -1.0], color=1.6) scene.add_light(light) gui_original = ti.GUI('Original', filted.res) gui_filted = ti.GUI('Filted', filted.res) gui_blurred = ti.GUI('Blurred', blurred.res) gui_final = ti.GUI('Final', final.res) gui_original.fps_limit = None