예제 #1
0
# In this episode, you'll learn how to use lights and materials in Tina
#
# This tutorial is based on docs/monkey.py, make sure you check that first

import taichi as ti
import tina

ti.init(ti.gpu)

scene = tina.Scene()

# 5. Material - for describing the material of an object
material = tina.CookTorrance(metallic=0.6, roughness=0.2)
# parameters may also be specified by textures (add texturing=True to Scene)
#material = tina.CookTorrance(basecolor=tina.Texture('assets/cloth.jpg'))

model = tina.MeshModel('assets/monkey.obj')
# load our model into the scene with material specified:
scene.add_object(model, material)

gui = ti.GUI('lighting')

# now, let's add some custom light sources into the scene for test
#
# first of all, remove the 'default light' from scene:
scene.lighting.clear_lights()
# adds a directional light with direction (0, 0, 1), with white color
# the direction will be automatically normalized to obtain desired result
scene.lighting.add_light(dir=[0, 0, 1], color=[1, 1, 1])
# adds a point light at position (1, 1.5, 0.3), with red color
scene.lighting.add_light(pos=[1, 1.5, 0.3], color=[1, 0, 0])
예제 #2
0
import taichi as ti
import numpy as np
import tina

ti.init(ti.opengl)

engine = tina.Engine(smoothing=True)
camera = tina.Camera()

img = ti.Vector.field(3, float, engine.res)

lighting = tina.Lighting()
material = tina.CookTorrance()
shader = tina.Shader(img, lighting, material)

obj = tina.readobj('assets/sphere.obj')
verts = obj['v'][obj['f'][:, :, 0]]
norms = obj['vn'][obj['f'][:, :, 2]]

gui = ti.GUI('matball', engine.res)
control = tina.Control(gui)

metallic = gui.slider('metallic', 0.0, 1.0, 0.1)
roughness = gui.slider('roughness', 0.0, 1.0, 0.1)
specular = gui.slider('specular', 0.0, 1.0, 0.1)

metallic.value = material.metallic[None]
roughness.value = material.roughness[None]
specular.value = material.specular[None]

while gui.running:
예제 #3
0
import taichi as ti
import numpy as np
import tina

ti.init(ti.opengl)

engine = tina.Engine(texturing=True)
camera = tina.Camera()

img = ti.Vector.field(3, float, engine.res)

lighting = tina.Lighting()
material = tina.CookTorrance(basecolor=tina.Texture('assets/cloth.jpg'), )
shader = tina.Shader(img, lighting, material)

obj = tina.readobj('assets/monkey.obj')
verts = obj['v'][obj['f'][:, :, 0]]
coors = obj['vt'][obj['f'][:, :, 1]]

gui = ti.GUI('texture', engine.res, fast_gui=True)
control = tina.Control(gui)

while gui.running:
    control.get_camera(camera)
    engine.set_camera(camera)

    img.fill(0)
    engine.clear_depth()

    engine.set_face_verts(verts)
    engine.set_face_coors(coors)
예제 #4
0
import taichi as ti
import tina

ti.init(ti.cpu)

scene = tina.Scene(smoothing=True)

metallic = tina.Param(float)
roughness = tina.Param(float)
material = tina.CookTorrance(metallic=metallic, roughness=roughness)
model = tina.MeshModel('assets/sphere.obj')
scene.add_object(model, material)

gui = ti.GUI('matball')
metallic.make_slider(gui, 'metallic')
roughness.make_slider(gui, 'roughness')

scene.init_control(gui, blendish=True)
while gui.running:
    scene.input(gui)
    scene.render()
    gui.set_image(scene.img)
    gui.show()