Ejemplo n.º 1
0
        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:
Ejemplo n.º 2
0
    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]
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
0
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()
Ejemplo n.º 5
0
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()
Ejemplo n.º 6
0
import taichi as ti
import taichi_three as t3
import numpy as np

ti.init(ti.cpu)

scene = t3.Scene()
obj = t3.readobj('assets/sphere.obj', scale=0.9)
model = t3.Model(t3.Mesh.from_obj(obj))
model.material = t3.Material(t3.CookTorrance(
    roughness=t3.Uniform((), float),
    metallic=t3.Uniform((), float),
    ))
scene.add_model(model)
camera = t3.Camera()
camera.ctl = t3.CameraCtl(pos=[0, 1, 1.8])
scene.add_camera(camera)
light = t3.Light(dir=[0.9, -1.5, -1.3])
scene.add_light(light)

gui = ti.GUI('Material Ball', camera.res)
roughness = gui.slider('roughness', 0, 1, step=0.05)
metallic = gui.slider('metallic', 0, 1, step=0.05)
roughness.value = 0.3
metallic.value = 0.0
while gui.running:
    gui.get_event(None)
    gui.running = not gui.is_pressed(ti.GUI.ESCAPE)
    model.material.shader.params['roughness'].fill(roughness.value)
    model.material.shader.params['metallic'].fill(metallic.value)
    if any(x < 0.6 for x in gui.get_cursor_pos()):
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
import taichi as ti
import taichi_three as t3
import numpy as np

ti.init(ti.cpu)

scene = t3.Scene()
obj = t3.readobj('assets/sphere.obj', scale=0.9)
model = t3.Model(t3.Mesh.from_obj(obj))
model.material = t3.Material(
    t3.CookTorrance(
        roughness=t3.Uniform((), float),
        metallic=t3.Uniform((), float),
    ))
scene.add_model(model)
camera = t3.Camera()
camera.fb.post_process = t3.make_tonemap()
camera.ctl = t3.CameraCtl(pos=[0, 1, 1.8])
scene.add_camera(camera)
light = t3.Light(dir=[0.9, -1.5, -1.3])
scene.add_light(light)

gui = ti.GUI('Material Ball', camera.res)
roughness = gui.slider('roughness', 0, 1, step=0.05)
metallic = gui.slider('metallic', 0, 1, step=0.05)
roughness.value = 0.3
metallic.value = 0.0
while gui.running:
    gui.get_event(None)
    gui.running = not gui.is_pressed(ti.GUI.ESCAPE)
    model.material.shader.params['roughness'].fill(roughness.value)
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)
Ejemplo n.º 10
0
import taichi as ti
import taichi_three as t3
import numpy as np

ti.init(ti.cpu)

scene = t3.Scene()
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.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.Material(
    t3.CookTorrance(  # Down: cloth
        color=t3.Texture(ti.imread('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(camera)
light = t3.Light([0, -0.5, -1], 0.9)
scene.add_light(light)
ambient = t3.AmbientLight(0.1)
scene.add_light(ambient)
Ejemplo n.º 11
0
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)

mesh = t3.Mesh.from_obj(t3.Geometry.cube())
xplus = t3.Model(mesh)
xplus.material = t3.Material(t3.CookTorrance(
    color=t3.Constant(t3.RGB(1, 0, 0)),
))
scene.add_model(xplus)
yplus = t3.Model(mesh)
yplus.material = t3.Material(t3.CookTorrance(
    color=t3.Constant(t3.RGB(0, 1, 0)),
))
scene.add_model(yplus)
zplus = t3.Model(mesh)
zplus.material = t3.Material(t3.CookTorrance(
    color=t3.Constant(t3.RGB(0, 0, 1)),
))
scene.add_model(zplus)
center = t3.Model(mesh)
center.material = t3.Material(t3.CookTorrance(
    color=t3.Constant(t3.RGB(1, 1, 1)),
))
scene.add_model(center)