def extract(self): if self.pbr is None: return tina.Lambert() kwargs = {} for key, value in self.pbr.items(): if key == 'baseColorFactor': kwargs['basecolor'] = value[:3] elif key == 'baseColorTexture': #assert value.get('texCoord', 0) == 0 img = images[value['index']] kwargs['basecolor'] = tina.Texture(img) elif key == 'metallicFactor': kwargs['metallic'] = value elif key == 'metallicTexture': #assert value.get('texCoord', 0) == 0 img = images[value['index']] kwargs['metallic'] = tina.Texture(img) elif key == 'roughnessFactor': kwargs['roughness'] = value elif key == 'roughnessTexture': #assert value.get('texCoord', 0) == 0 img = images[value['index']] kwargs['roughness'] = tina.Texture(img) elif key == 'metallicRoughnessTexture': img = images[value['index']] print(img.dtype) tina.ti.imshow(img) kwargs['metallic'] = tina.Texture(img[..., 2]) kwargs['roughness'] = tina.Texture(img[..., 1]) return tina.PBR(**kwargs)
import taichi as ti import numpy as np import tina ti.init(ti.gpu) scene = tina.PTScene(smoothing=True, texturing=True) #scene.lighting.skybox = tina.Skybox('assets/skybox.jpg', cubic=True) model = tina.MeshModel('assets/bunny.obj') #material = tina.PBR(roughness=0.0, metallic=0.0) material = tina.PBR(roughness=0.2, metallic=0.8) scene.add_object(model, material) denoise = tina.Denoise(scene.res) if isinstance(scene, tina.PTScene): scene.update() gui = ti.GUI('noise', scene.res) while gui.running: scene.input(gui) if isinstance(scene, tina.PTScene): scene.render(nsteps=5) else: scene.render() #gui.set_image(scene.img) denoise.src.from_numpy(scene.img) denoise.nlm(radius=2, noiseness=0.9) gui.set_image(denoise.dst) gui.show()
# 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.PBR(metallic=0.6, roughness=0.2) # parameters may also be specified by textures (add texturing=True to Scene) #material = tina.PBR(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])
import taichi as ti import tina ti.init(ti.cpu) scene = tina.Scene(smoothing=True) metallic = tina.Param(float, initial=0.0) specular = tina.Param(float, initial=0.5) roughness = tina.Param(float, initial=0.4) material = tina.PBR(metallic=metallic, roughness=roughness, specular=specular) #shineness = tina.Param(float, initial=32) #specular = tina.Param(float, initial=0.5) #material = tina.Classic(shineness=shineness, specular=specular) model = tina.PrimitiveMesh.sphere() scene.add_object(model, material) gui = ti.GUI('matball') if 'roughness' in globals(): roughness.make_slider(gui, 'roughness') if 'metallic' in globals(): metallic.make_slider(gui, 'metallic') if 'shineness' in globals(): shineness.make_slider(gui, 'shineness', 1, 500, 1) if 'specular' in globals(): specular.make_slider(gui, 'specular') while gui.running: scene.input(gui)
import taichi as ti import tina ti.init(ti.opengl) scene = tina.Scene(fxaa=True) model = tina.MeshModel('assets/monkey.obj') scene.add_object(model, tina.PBR(metallic=0.5, roughness=0.3)) gui = ti.GUI(res=scene.res) abs_thresh = gui.slider('abs_thresh', 0, 0.1, 0.002) rel_thresh = gui.slider('rel_thresh', 0, 0.5, 0.01) factor = gui.slider('factor', 0, 1, 0.01) abs_thresh.value = 0.0625 rel_thresh.value = 0.063 factor.value = 1 while gui.running: scene.fxaa.rel_thresh[None] = rel_thresh.value scene.fxaa.abs_thresh[None] = abs_thresh.value scene.fxaa.factor[None] = factor.value scene.input(gui) scene.render() gui.set_image(scene.img) gui.show()
import taichi as ti import numpy as np import tina ti.init(ti.gpu) scene = tina.PTScene(smoothing=True) roughness = tina.Param(float, initial=0.2) metallic = tina.Param(float, initial=1.0) scene.add_object(tina.MeshModel('assets/sphere.obj'), tina.PBR(metallic=metallic, roughness=roughness)) pars = tina.SimpleParticles() scene.add_object(pars, tina.Lamp(color=32)) gui = ti.GUI('path', scene.res) roughness.make_slider(gui, 'roughness', 0, 1, 0.01) metallic.make_slider(gui, 'metallic', 0, 1, 0.01) pars.set_particles(np.array([ [0, 0, 5], ])) scene.update() while gui.running: if scene.input(gui): scene.clear() scene.render(nsteps=6) gui.set_image(scene.img) gui.show()
J[p] *= 1 + dt * new_C.trace() C[p] = new_C @ti.kernel def init(): for i in range(n_particles): x[i] = ti.Vector([ti.random() for i in range(dim)]) * 0.4 + 0.15 v[i] *= 0 J[i] = 1 mciso = tina.MCISO((n_grid, n_grid, n_grid)) scene = tina.Scene(smoothing=True, maxfaces=2**18, ibl=True, ssao=True) material = tina.PBR(metallic=0.15, roughness=0.0) scene.add_object(mciso, material) #boundbox = tina.MeshToWire(tina.MeshTransform(tina.MeshModel('assets/cube.obj'), tina.scale(0.5) @ tina.translate(1))) #scene.add_object(boundbox) gui = ti.GUI('mciso_mpm3d', scene.res) scene.init_control(gui, center=[0.5, 0.5, 0.5], radius=1.5) if not scene.ibl: scene.lighting.clear_lights() scene.lighting.add_light([-0.4, 1.5, 1.8], color=[0.8, 0.8, 0.8]) scene.lighting.set_ambient_light([0.22, 0.22, 0.22]) init() while gui.running:
import taichi as ti import numpy as np import tina ti.init(ti.opengl) scene = tina.PTScene(smoothing=True) roughness = tina.Param(float, initial=0.2) metallic = tina.Param(float, initial=1.0) scene.add_object(tina.MeshModel('assets/sphere.obj'), tina.PBR(metallic=metallic, roughness=roughness)) scene.add_object(tina.MeshTransform(tina.MeshModel('assets/plane.obj'), tina.translate([0, 0, 4]) @ tina.eularXYZ([ti.pi / 2, 0, 0]) #@ tina.scale(0.1)), tina.Lamp(color=32)) @ tina.scale(0.4)), tina.Lamp(color=1)) gui = ti.GUI('path', scene.res) roughness.make_slider(gui, 'roughness', 0, 1, 0.01) metallic.make_slider(gui, 'metallic', 0, 1, 0.01) scene.update() while gui.running: if scene.input(gui): scene.clear() scene.render(nsteps=6) gui.set_image(scene.img) gui.show() #ti.imwrite(scene.img, 'output.png')
import taichi as ti import tina ti.init(ti.gpu) scene = tina.PTScene() #scene.engine.skybox = tina.Atomsphere() model = tina.MeshTransform(tina.MeshModel('assets/plane.obj'), tina.translate([0, 0, 4]) @ tina.eularXYZ([ti.pi / 2, 0, 0])) material = tina.Emission() * 2 scene.add_object(model, material) metallic = tina.Param(float, initial=1.0) roughness = tina.Param(float, initial=0.01) model = tina.MeshModel('assets/monkey.obj') material = tina.PBR(metallic=metallic, roughness=roughness) scene.add_object(model, material) gui = ti.GUI(res=scene.res) metallic.make_slider(gui, 'metallic') roughness.make_slider(gui, 'roughness') scene.update() while gui.running: scene.input(gui) scene.render() gui.set_image(scene.img) gui.show()
import taichi as ti import tina ti.init(ti.gpu) scene = tina.Scene((640, 480), smoothing=True, ssr=True, taa=True) monkey_material = tina.PBR(metallic=0.0, roughness=0.4) monkey = tina.MeshModel('assets/monkey.obj') scene.add_object(monkey, monkey_material) param_metallic = tina.Param() param_roughness = tina.Param() plane_material = tina.PBR(metallic=param_metallic, roughness=param_roughness) plane = tina.MeshTransform(tina.MeshGrid(32), tina.scale(2) @ tina.eularXYZ([-ti.pi / 2, 0, 0])) scene.add_object(plane, plane_material) gui = ti.GUI(res=scene.res) nsteps = gui.slider('nsteps', 1, 128, 1) nsamples = gui.slider('nsamples', 1, 128, 1) stepsize = gui.slider('stepsize', 0, 32, 0.1) tolerance = gui.slider('tolerance', 0, 64, 0.1) blurring = gui.slider('blurring', 1, 8, 1) metallic = gui.slider('metallic', 0, 1, 0.01) roughness = gui.slider('roughness', 0, 1, 0.01) nsteps.value = 64 nsamples.value = 12 blurring.value = 4 stepsize.value = 2 tolerance.value = 15 metallic.value = 1.0