def main(): ru = rv = (-np.pi, 3*np.pi) # use with trefoil() #ru = rv = (0, 2*np.pi) # use with torus() #ru = (0, np.pi) # use with sphere() #rv = (0, 2*np.pi) n = 500 i = np.linspace(ru[0], ru[1], n) j = np.linspace(rv[0], rv[1], n) U, V = np.meshgrid(i, j) S = trefoil(U, V, 5) #S = sphere(U, V, 7) #S = torus(U, V, 3, 5) S = np.swapaxes(S, 0, 2) rt = TkOptiX(width=750, height=900) rt.set_param(min_accumulation_step=2, max_accumulation_frames=500, light_shading="Hard") rt.set_uint("path_seg_range", 6, 15) rt.setup_material("plastic", m_plastic) exposure = 0.8; gamma = 2.2 rt.set_float("tonemap_exposure", exposure) rt.set_float("tonemap_gamma", gamma) rt.add_postproc("Gamma") rt.set_background(0) rt.set_ambient(0.15) rt.set_surface("surface", S, c=0.94, #wrap_u=True, wrap_v=True, # use wrapping to close a gap that can appear on u or v edges make_normals=True, mat="plastic") rt.set_data("plane", geom="Parallelograms", pos=[[-100, -14, -100]], u=[200, 0, 0], v=[0, 0, 200], c=make_color([0.1, 0.2, 0.3], exposure=exposure, gamma=gamma)[0]) rt.setup_camera("cam1", cam_type="DoF", eye=[-50, -7, -15], target=[0, 0, -1], up=[0, 1, 0], aperture_radius=0.4, aperture_fract=0.2, focal_scale=0.92, fov=35) rt.setup_light("light1", pos=[-15, 20, 15], color=5, radius=6) rt.start() print("done")
def main(): rt = TkOptiX() # create and configure, show the window later rt.set_param(max_accumulation_frames=500) # accumulate up to 100 frames rt.set_uint("path_seg_range", 6, 12) # allow some more ray segments rt.set_background(0) # black background rt.set_ambient([0.1, 0.12, 0.15]) # some ambient light #rt.set_param(light_shading="Hard") # nice, accurate caustics, but slower convergence exposure = 1; gamma = 2.2 rt.set_float("tonemap_exposure", exposure) rt.set_float("tonemap_gamma", gamma) rt.add_postproc("Gamma") # gamma correction # setup materials: m_diffuse["VarFloat3"] = { "base_color": [ 0.85, 0.87, 0.89 ] } rt.update_material("diffuse", m_diffuse) m_dispersive_glass["VarFloat3"]["base_color"] = [ 100, 110, 120 ] rt.setup_material("glass", m_dispersive_glass) # read the scene: scene = trimesh.load("data/chemistry.glb") # upload meshes to the ray tracer for name in scene.geometry: mesh = scene.geometry[name] if name in ["bottle", "cap", "testtube"]: rt.set_mesh(name, mesh.vertices, mesh.faces, mat="glass", make_normals=True) else: rt.set_mesh(name, mesh.vertices, mesh.faces) # camera and light rt.setup_light("light1", pos=[6,7.5,-15], color=30, radius=2) rt.setup_camera("cam1", eye=[-2,5,-10], target=[-0.75,1.4,5], fov=23, glock=True) rt.start() print("done")
def main(): ru = rv = (0, 2*np.pi) n = 50 i = np.linspace(ru[0], ru[1], 2*n)[:-1] j = np.linspace(rv[0], rv[1], n)[:-1] U, V = np.meshgrid(i, j) S = torus(U, V, 3, 5) S = np.swapaxes(S, 0, 2) rt = TkOptiX() rt.set_param(min_accumulation_step=2, max_accumulation_frames=500, light_shading="Hard") rt.set_uint("path_seg_range", 6, 15) rt.setup_material("plastic", m_plastic) exposure = 0.8; gamma = 2.2 rt.set_float("tonemap_exposure", exposure) rt.set_float("tonemap_gamma", gamma) rt.add_postproc("Gamma") rt.set_background(0) rt.set_ambient(0.0) rt.set_surface("surface", S, c=0.95, wrap_u=True, wrap_v=True, mat="plastic", make_normals=True ) # make data for a bigger torus using normals calculated automatically # for the firts object; note that this surface has normals oriented # inwards - that's not a problem unless you'd like to have a refractive # glass-like material, then use the code below that will flip normals # (or simply change the surface formula, but this would not illustrate # how to access buffers) #with PinnedBuffer(rt.geometry_data["surface"], "Vectors") as N: # print(S.shape, N.shape) # note that internal buffers are flat arrays of mesh vertex properties # S -= N.reshape(S.shape) # flip normals and update data on gpu, note that both normal vectors # and vertex order should be inverted for correct shading with PinnedBuffer(rt.geometry_data["surface"], "Vectors") as N: with PinnedBuffer(rt.geometry_data["surface"], "FaceIdx") as F: N *= -1 # flip shading normals F[:,[0,1]] = F[:,[1,0]] # invert vertex order in faces, so geometry normals are consistent with shading normals rt.update_geom_buffers("surface", GeomBuffer.Vectors | GeomBuffer.FaceIdx, forced=True) # update data on device S += 0.5 * N.reshape(S.shape) # make data for a bigger torus rt.set_surface("wireframe", S, c=[0.4, 0.01, 0], r=0.015, geom="Graph", wrap_u=True, wrap_v=True, ) rt.set_data("plane", geom="Parallelograms", pos=[[-100, -14, -100]], u=[200, 0, 0], v=[0, 0, 200], c=make_color([0.1, 0.2, 0.3], exposure=exposure, gamma=gamma)[0]) rt.setup_camera("cam1", cam_type="DoF", eye=[-50, -7, -15], target=[0, 0, -1], up=[0, 1, 0], aperture_radius=0.4, aperture_fract=0.2, focal_scale=0.92, fov=25) rt.setup_light("light1", pos=[-15, 20, 15], color=5, radius=6) rt.start() print("done")
def main(): # Setup the raytracer: rt = TkOptiX() rt.set_param(min_accumulation_step=2, # update image every 2 frames max_accumulation_frames=250) # accumulate 250 frames rt.set_uint("path_seg_range", 5, 15) # allow many reflections/refractions exposure = 1.5; gamma = 2.2 rt.set_float("tonemap_exposure", exposure) rt.set_float("tonemap_gamma", gamma) rt.add_postproc("Denoiser") # AI denoiser, or the gamma correction only. #rt.add_postproc("Gamma") # *** but not both together *** rt.set_background(0) rt.set_ambient(0) # Setup texture: # in one go, with gamma and exposure parameters saved to the scene: rt.load_texture("rainbow", "data/rainbow.jpg", prescale=0.3, baseline=0.7, gamma=2.2) # or through ndarray, allowing for custom processing: #rainbow = 0.7 + 0.3 * read_image("data/rainbow.jpg", normalized=True) #rainbow = make_color_2d(rainbow, gamma=2.2, channel_order="RGBA") #rt.set_texture_2d("rainbow", rainbow) # Setup materials: m_thin2 = copy.deepcopy(m_thin_walled) # textured material based on the predefined thin-walled material m_thin2["ColorTextures"] = [ "rainbow" ] # reference texture by name rt.setup_material("glass", m_clear_glass) rt.setup_material("thin", m_thin_walled) rt.setup_material("thin2", m_thin2) # Prepare a simple scene objects, camera and lights: rt.set_data("plane", geom="Parallelograms", pos=[[-15, 0, -15]], u=[30, 0, 0], v=[0, 0, 30], c=0.94) rt.set_data("block1", geom="Parallelepipeds", pos=[[-6, -0.07, -1]], u=[12, 0, 0], v=[0, 0.1, 0], w=[0, 0, 3], c=0.94) rt.set_data("block2", geom="Parallelepipeds", pos=[[-6, 0, -1]], u=[12, 0, 0], v=[0, 4, 0], w=[0, 0, 0.1], c=0.94) # Setup lights and the camera: rt.setup_light("light1", light_type="Parallelogram", pos=[-2.5, 2.5, 3], u=[0.8, 0, 0], v=[0, -0.8, 0], color=[6, 5.7, 5.4]) rt.setup_light("light2", light_type="Parallelogram", pos=[-0.5, 3.2, 0], u=[0.8, 0, 0], v=[0, 0, 0.8], color=[8, 7.6, 7.2]) rt.setup_light("light3", light_type="Parallelogram", pos=[1.5, 2.5, 3], u=[0.8, 0, 0], v=[0, -0.8, 0], color=[6, 5.7, 5.4]) rt.setup_camera("cam1", cam_type="DoF", eye=[0, 0.4, 6], target=[0, 1, 0], aperture_radius=0.025, fov=35, focal_scale=0.9) # Make some bubbles: n = 20 x = np.linspace(-3, 3, n) r = 0.3*np.cos(0.4*x) y = 0.8*np.sin(x) + 1.2 z = 0.8*np.cos(x) + 0.4 b1 = np.stack((x, y, z)).T rt.set_data("bubbles1", mat="thin", pos=b1, r=r, c=0.5+0.5*map_to_colors(x, "rainbow")) y = 0.8*np.sin(x + 3) + 1.2 z = 0.8*np.cos(x + 3) + 0.4 b2 = np.stack((x, y, z)).T rt.set_data("bubbles2", geom="ParticleSetTextured", mat="thin2", pos=b2, r=r) y = np.sin(x + 2) + 1.2 z = np.cos(x + 2) + 0.4 b3 = np.stack((x, y, z)).T rt.set_data("beads", mat="glass", pos=b3, r=0.75*r, c=10) y = np.sin(x + 5) + 1.3 z = np.cos(x + 5) + 0.3 b4 = np.stack((x, y, z)).T rt.set_data("balls", pos=b4, r=0.75*r, c=0.92) # Let's start: rt.start() print("done")
def main(): # Setup the raytracer: rt = TkOptiX() rt.set_param(min_accumulation_step=2, # update image every 2 frames max_accumulation_frames=250) # accumulate 250 frames rt.set_uint("path_seg_range", 5, 15) # allow many reflections/refractions exposure = 1.5; gamma = 2.2 rt.set_float("tonemap_exposure", exposure) rt.set_float("tonemap_igamma", 1 / gamma) rt.add_postproc("Gamma") # Gamma correction, or use AI denoiser. #rt.setup_denoiser() # *** but not both together *** rt.set_background(0) rt.set_ambient(0) # Setup materials: m_thin2 = m_thin_walled.copy() # textured material based on the predefined thin-walled material m_thin2["Textures"] = [ { "Baseline": 0.7, # Prescale the texture to make it bright, as one would expect for a bubbles: "Prescale": 0.3, # color = Baseline + Prescale * original_color "Gamma": 2.2, # And compensate the gamma correction applied in 2D postprocessing. "Source": "data/rainbow.jpg", "Format": RtFormat.Float4.value } ] rt.setup_material("glass", m_clear_glass) rt.setup_material("thin", m_thin_walled) rt.setup_material("thin2", m_thin2) # Prepare a simple scene objects, camera and lights: rt.set_data("plane", geom="Parallelograms", pos=[[-15, 0, -15]], u=[30, 0, 0], v=[0, 0, 30], c=0.94) rt.set_data("block1", geom="Parallelepipeds", pos=[[-6, -0.07, -1]], u=[12, 0, 0], v=[0, 0.1, 0], w=[0, 0, 3], c=0.94) rt.set_data("block2", geom="Parallelepipeds", pos=[[-6, 0, -1]], u=[12, 0, 0], v=[0, 4, 0], w=[0, 0, 0.1], c=0.94) # Setup lights and the camera: rt.setup_light("light1", light_type="Parallelogram", pos=[-2.5, 2.5, 3], u=[0.8, 0, 0], v=[0, -0.8, 0], color=[6, 5.7, 5.4]) rt.setup_light("light2", light_type="Parallelogram", pos=[-0.5, 3.2, 0], u=[0.8, 0, 0], v=[0, 0, 0.8], color=[8, 7.6, 7.2]) rt.setup_light("light3", light_type="Parallelogram", pos=[1.5, 2.5, 3], u=[0.8, 0, 0], v=[0, -0.8, 0], color=[6, 5.7, 5.4]) rt.setup_camera("cam1", cam_type="DoF", eye=[0, 0.4, 6], target=[0, 1, 0], aperture_radius=0.025, fov=35, focal_scale=0.9) # Make some bubbles: n = 20 x = np.linspace(-3, 3, n) r = 0.3*np.cos(0.4*x) y = 0.8*np.sin(x) + 1.2 z = 0.8*np.cos(x) + 0.4 b1 = np.stack((x, y, z)).T rt.set_data("bubbles1", mat="thin", pos=b1, r=r, c=0.5+0.5*map_to_colors(x, "rainbow")) y = 0.8*np.sin(x + 3) + 1.2 z = 0.8*np.cos(x + 3) + 0.4 b2 = np.stack((x, y, z)).T rt.set_data("bubbles2", geom="ParticleSetTextured", mat="thin2", pos=b2, r=r) y = np.sin(x + 2) + 1.2 z = np.cos(x + 2) + 0.4 b3 = np.stack((x, y, z)).T rt.set_data("beads", mat="glass", pos=b3, r=0.75*r, c=10) y = np.sin(x + 5) + 1.3 z = np.cos(x + 5) + 0.3 b4 = np.stack((x, y, z)).T rt.set_data("balls", pos=b4, r=0.75*r, c=0.92) # Let's start: rt.start() print("done")