Example #1
0
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)
gui = ti.GUI('Model', camera.res)
while gui.running:
    gui.get_event(None)
    gui.running = not gui.is_pressed(ti.GUI.ESCAPE)
    if camera.from_mouse(gui):
        accumator.reset()
    accumator.render(camera, 3)
    #gui.set_image(accumator.buf)
    gui.set_image(1 - np.exp(-1.6 * accumator.buf.to_numpy()))
    gui.show()
    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)

xplus.L2W[None] = t3.translate(1, 0, 0) @ t3.scale(0.1)
yplus.L2W[None] = t3.translate(0, 1, 0) @ t3.scale(0.1)
zplus.L2W[None] = t3.translate(0, 0, 1) @ t3.scale(0.1)
center.L2W[None] = t3.scale(0.1)

gui = t3.GUI('Coordinate system')
while gui.running:
    gui.get_event(None)
    camera.from_mouse(gui)
    scene.render()
    gui.set_image(camera.img)
    gui.show()
Example #3
0
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]


init()
sphere.L2W[None] = t3.translate(ball_pos) @ t3.scale(ball_radius)
with ti.GUI('Mass Spring', camera.res) as gui:
    while gui.running and not gui.get_event(gui.ESCAPE):
        if not gui.is_pressed(gui.SPACE):
            for i in range(steps):
                substep()
        if gui.is_pressed('r'):
            init()
        update_display()

        camera.from_mouse(gui)

        scene.render()
        gui.set_image(camera.img)
        gui.show()
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)
    camera.from_mouse(gui)
    scene.render()
    gui.set_image(buffer.img)
    gui.show()