Ejemplo n.º 1
0
import taichi as ti
import taichi_three as t3
import numpy as np

res = 512, 512
ti.init(ti.cpu)

scene = t3.Scene()
cornell = t3.readobj('assets/cornell.obj', orient='-xyz')
cube = t3.readobj('assets/plane.obj')
model = t3.Model(t3.Mesh.from_obj(cornell))
model.material = t3.Material(
    t3.IdealRT(
        diffuse=t3.Constant(1.0),
        emission=t3.Constant(0.0),
    ))
scene.add_model(model)
light = t3.Model(t3.Mesh.from_obj(cube))
light.material = t3.Material(
    t3.IdealRT(
        diffuse=t3.Constant(0.0),
        emission=t3.Constant(1.0),
        emission_color=t3.Constant(10.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(camera)
accumator = t3.Accumator(camera.res)

light.L2W[None] = t3.translate(0, 3.9, 0) @ t3.scale(0.25)
Ejemplo n.º 2
0
        v[i] = tl.ballBoundReflect(x[i], v[i], ball_pos, ball_radius, 6)
    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
import time

ti.init(ti.cpu)

scene = t3.Scene()
model = t3.Model(t3.Mesh.from_obj(t3.readobj('assets/torus.obj', scale=0.8)))
scene.add_model(model)
ball = t3.Model(t3.Mesh.from_obj(t3.readobj('assets/sphere.obj', scale=0.1)))
ball.material = t3.Material(
    t3.BlinnPhong(emission=t3.Constant(t3.RGB(1.0, 1.0, 1.0)), ))
scene.add_model(ball)
camera = t3.Camera()
camera.ctl = t3.CameraCtl(pos=[0, 1.8, 1.8])
scene.add_camera(camera)
light = t3.PointLight(pos=[0, 1, 0])
scene.add_light(light)
ambient = t3.AmbientLight(0.2)
scene.add_light(ambient)

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)
    light.pos[None].y = ti.cos(time.time())
    ball.L2W[None] = t3.translate(light.pos[None].value)
    scene.render()
    gui.set_image(camera.img)
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/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.º 5
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)

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()
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/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.º 7
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.º 8
0
import taichi as ti
import taichi_three as t3
import numpy as np

ti.init(ti.cpu)

scene = t3.Scene()
skybox = t3.Skybox('assets/skybox.jpg')
scene.add_model(skybox)
scene.add_light(skybox)
model = t3.Model(t3.Mesh.from_obj('assets/sphere.obj'))
model.material = t3.Material(t3.IdealRT(specular=t3.Constant(1.0), ))
scene.add_model(model)
camera = t3.Camera(res=(600, 400))
camera.ctl = t3.CameraCtl(pos=[0, 0, 3])
scene.add_camera(camera)

gui = ti.GUI('Skybox', 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.º 9
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)
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.º 11
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.º 12
0
import taichi as ti
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),
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
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