def main():

    # tetrahedron vertices and faces:
    pt = 1 / np.sqrt(2)

    points = [[1, 0, -pt], [-1, 0, -pt], [0, 1, pt], [0, -1, pt]]

    faces = [[0, 1, 2], [0, 1, 3], [1, 2, 3], [0, 2, 3]]

    # colors assigned to vertices
    colors = [
        [0.7, 0, 0],
        [0, 0.7, 0],
        [0, 0, 0.7],
        [1, 1, 1],
    ]

    rt = TkOptiX()  # create and configure, show the window later

    rt.set_param(min_accumulation_step=2, max_accumulation_frames=100)
    rt.setup_camera("cam1",
                    cam_type="DoF",
                    eye=[1, -6, 4],
                    focal_scale=0.9,
                    fov=25)
    rt.setup_light("light1", pos=[10, -9, -8], color=[14, 13, 12], radius=4)
    rt.set_ambient([0.2, 0.3, 0.4])

    # add mesh geometry to the scene
    rt.set_mesh("m", points, faces, c=colors)

    rt.start()
    print("done")
Beispiel #2
0
def main():

    optix = TkOptiX() # create and configure, show the window later

    optix.set_param(max_accumulation_frames=100)  # accumulate up to 100 frames
    optix.set_background(0) # black background
    optix.set_ambient(0.25) # some ambient light


    # original Stanford Utah teapot (try also with default value of make_normals=False):
    # note: this file has no named objects specified, and you have to use load_merged_mesh_obj
    # method
    #optix.load_merged_mesh_obj("https://graphics.stanford.edu/courses/cs148-10-summer/as3/code/as3/teapot.obj",
    #                           "teapot", c=0.92, make_normals=True)

    # another public-domain version with normals included:
    optix.load_mesh_obj("data/utah-teapot.obj", c=0.92)

    # camera and light position auto-fit the scene geometry
    optix.setup_camera("cam1")
    d = np.linalg.norm(optix.get_camera_target() - optix.get_camera_eye())
    optix.setup_light("light1", color=10, radius=0.3 * d)

    optix.start()
    print("done")
Beispiel #3
0
def main():

    if len(sys.argv) < 2:
        print("Usage: python 7_panorama_viewer.py image_file.ext")
        print("ext: jpg, png, tif and bmp files are accepted.")
        exit(0)

    fname = str(sys.argv[1])
    # just in case you have white spaces in the path...
    for s in sys.argv[2:]:
        fname += " " + str(s)
    print("Reading:", fname)

    # create and configure, show the window later
    rt = TkOptiX()

    rt.set_background_mode("TextureEnvironment")

    rt.set_background(fname)

    rt.start()

    rt.set_camera_glock(True)

    print("done")
Beispiel #4
0
def main():

    n = 100
    xyz = 3 * (np.random.random((n, 3)) - 0.5)
    r = 0.4 * np.random.random(n) + 0.002

    rt = TkOptiX()
    rt.set_param(min_accumulation_step=4, max_accumulation_frames=500)

    rt.setup_light("light1", pos=[4, 5, 5], color=[8, 7, 6], radius=1.5)
    rt.setup_light("light2", pos=[4, 15, -5], color=[8, 7, 6], radius=1.5)
    rt.set_ambient([0.1, 0.2, 0.3])
    rt.set_background(1)

    rt.set_data("plot", xyz, r=r, c=0.8)

    # shadow catcher makes the object transparent except regions where a light casts shadows,
    # this can be useful e.g. for making packshot style images
    rt.setup_material("shadow", m_shadow_catcher)
    rt.set_data("plane",
                pos=[-50, -2, -50],
                u=[100, 0, 0],
                v=[0, 0, 100],
                c=1,
                geom="Parallelograms",
                mat="shadow")

    rt.start()

    print("done")
Beispiel #5
0
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

    exposure = 1.1; gamma = 2.2
    rt.set_float("tonemap_exposure", exposure)
    rt.set_float("tonemap_gamma", gamma)
    rt.add_postproc("Denoiser")                # Gamma correction, or use AI denoiser.
    #rt.add_postproc("Gamma")                  #    *** but not both together ***

    rt.set_background(0)
    rt.set_ambient(0)

    # 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.6, 3], u=[0.8, 0, 0], v=[0, -0.8, 0], color=[4, 4.7, 5])
    rt.setup_light("light2", light_type="Parallelogram", pos=[-0.5, 3.2, 0], u=[0.8, 0, 0], v=[0, 0, 0.8], color=[6, 5.6, 5.2])
    rt.setup_light("light3", light_type="Parallelogram", pos=[1.5, 2.6, 3], u=[0.8, 0, 0], v=[0, -0.8, 0], color=[4, 4.7, 5])
    rt.setup_camera("cam1", cam_type="DoF", eye=[0, 0.4, 6], target=[0, 1.2, 0], aperture_radius=0.025, fov=35, focal_scale=0.9)

    # Make some data:

    n = 20
    x = np.linspace(-3, 3, n)
    r = 0.8*np.cos(0.4*x)
    y = np.sin(x + 5) + 1.3
    z = np.cos(x + 5) + 0.3
    data = np.stack((x, y, z)).T

    # Add object to scene:
    rt.set_data("balls", pos=data, r=r, c=0.93)
    # or use another geometry and save it in the second scene file:
    #rt.set_data("cubes", geom="Parallelepipeds", pos=data, r=r, c=0.92)

    # Let's start:
    rt.start()

    # Save the scene. This actually can be called also before starting.
    rt.save_scene("strange_object.json")
    #rt.save_scene("strange_object_2.json") # the second file will be usefull in the scene loading example

    print("done")
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")
Beispiel #7
0
def main():

    # make some data first:
    rx = (-15, 5)
    rz = (-10, 10)
    n = 50

    x = np.linspace(rx[0], rx[1], n)
    z = np.linspace(rz[0], rz[1], n)

    X, Z = np.meshgrid(x, z)
    Y = f(X, Z)

    rt = TkOptiX()  # create and configure, show the window later

    rt.set_param(max_accumulation_frames=50)  # accumulate up to 50 frames
    rt.set_background(0)  # black background
    rt.set_ambient(0.25)  # some ambient light

    # try commenting out optional arguments
    rt.set_data_2d("surface",
                   Y,
                   range_x=rx,
                   range_z=rz,
                   c=map_to_colors(Y, "OrRd"),
                   floor_c=[0.05, 0.12, 0.38],
                   floor_y=-1.75,
                   make_normals=True)

    # add wireframe above the surface
    rt.set_data_2d("wireframe",
                   Y + 3,
                   range_x=rx,
                   range_z=rz,
                   r=0.06 * np.abs(Y),
                   geom="Graph",
                   c=0.92)

    # set camera and light position to fit the scene
    rt.setup_camera("cam1")
    eye = rt.get_camera_eye()
    eye[1] = 0.5 * eye[2]
    rt.update_camera("cam1", eye=eye)

    d = np.linalg.norm(rt.get_camera_target() - eye)
    rt.setup_light("light1", color=8, radius=0.3 * d)

    rt.start()

    print("done")
def main():

    # a mesh from pygmsh example:
    with pygmsh.geo.Geometry() as geom:

        poly = geom.add_polygon(
            [
                [+0.0, +0.5],
                [-0.1, +0.1],
                [-0.5, +0.0],
                [-0.1, -0.1],
                [+0.0, -0.5],
                [+0.1, -0.1],
                [+0.5, +0.0],
                [+0.1, +0.1],
            ],
            mesh_size=0.05,
        )

        geom.twist(
            poly,
            translation_axis=[0, 0, 1],
            rotation_axis=[0, 0, 1],
            point_on_axis=[0, 0, 0],
            angle=np.pi / 3,
        )

        mesh = geom.generate_mesh()

    rt = TkOptiX()  # create and configure, show the window later

    rt.set_param(min_accumulation_step=2, max_accumulation_frames=100)
    rt.setup_camera("cam1",
                    cam_type="DoF",
                    eye=[0.5, -3, 2],
                    target=[0, 0, 0.5],
                    focal_scale=0.9,
                    fov=25)
    rt.setup_light("light1", pos=[15, 0, 10], color=[8, 7, 6], radius=4)
    rt.set_ambient([0.1, 0.15, 0.2])

    # add mesh geometry to the scene
    rt.set_mesh("m", mesh.points, mesh.cells_dict['triangle'])

    rt.start()
    print("done")
def main():
    rt = TkOptiX(on_scene_compute=compute_changes,
                 on_rt_completed=update_scene)

    # 4 accumulation passes on each compute-update cycle:
    rt.set_param(min_accumulation_step=4)

    n = 1000000
    xyz = 3 * (np.random.random((n, 3)) - 0.5)
    r = 0.02 * np.random.random(n) + 0.002

    rt.set_data("plot", xyz, r=r)
    rt.set_ambient(0.9)

    rt.setup_camera("cam", eye=params.eye)

    rt.start()
Beispiel #10
0
def main():

    if not os.path.isfile("strange_object.json") or not os.path.isfile(
            "strange_object.json"):
        print(
            "Prepare two files: strange_object.json and strange_object_2.json with the scene saving example 9_1_save_scene.py."
        )

    # Load scene, but don't start yet:
    rt = TkOptiX("strange_object.json")

    # Apply some modification:
    if "balls" in rt.get_geometry_names():
        rt.scale_geometry("balls", 0.5)

    rt.start()

    input("Press Enter to continue...")

    # Now, let's save the current scene to a dictionary and load
    # the second scene from the file made with 9_1_save_scene.py:

    d = rt.get_scene()

    rt.load_scene("strange_object_2.json")

    # Apply some modification:
    if "cubes" in rt.get_geometry_names():
        rt.update_data("cubes", c=[0.5, 0, 0.1])

    input("Press Enter to continue...")

    # Manipulate something in the scene saved in the dictionary,
    # and load it back:

    if "light2" in d["Lights"]:
        d["Lights"]["light2"]["Color"] = [12, 6, 2]

    rt.set_scene(d)

    print("done")
def main():

    # a mesh from pygmsh example:
    geom = pygmsh.built_in.Geometry()

    # Draw a cross.
    poly = geom.add_polygon(
        [[0.0, 0.5, 0.0], [-0.1, 0.1, 0.0], [-0.5, 0.0, 0.0
                                             ], [-0.1, -0.1, 0.0],
         [0.0, -0.5, 0.0], [0.1, -0.1, 0.0], [0.5, 0.0, 0.0], [0.1, 0.1, 0.0]],
        lcar=0.05)

    axis = [0, 0, 1]

    geom.extrude(poly,
                 translation_axis=axis,
                 rotation_axis=axis,
                 point_on_axis=[0, 0, 0],
                 angle=2.0 / 6.0 * np.pi)

    mesh = pygmsh.generate_mesh(geom)

    rt = TkOptiX()  # create and configure, show the window later

    rt.set_param(min_accumulation_step=2, max_accumulation_frames=100)
    rt.setup_camera("cam1",
                    cam_type="DoF",
                    eye=[0.5, -3, 2],
                    target=[0, 0, 0.5],
                    focal_scale=0.9,
                    fov=25)
    rt.setup_light("light1", pos=[15, 0, 10], color=[8, 7, 6], radius=4)
    rt.set_ambient([0.1, 0.15, 0.2])

    # add mesh geometry to the scene
    rt.set_mesh("m", mesh.points, mesh.cells_dict['triangle'])

    rt.start()
    print("done")
Beispiel #12
0
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")
Beispiel #13
0
def main():

    rt = TkOptiX()  # create and configure, show the window later

    rt.set_param(max_accumulation_frames=100)  # accumulate up to 100 frames
    rt.set_background(0.99)  # white background
    rt.set_ambient(0.25)  # some ambient light

    # setup materials:
    m_diffuse["VarFloat3"] = {"base_color": [0.15, 0.17, 0.2]}
    rt.update_material("diffuse", m_diffuse)

    m_matt_plastic["VarFloat3"]["base_color"] = [0.5, 0.1, 0.05]
    rt.setup_material("plastic", m_matt_plastic)

    rt.load_texture("wing", "data/wing.png")

    m_transparent_plastic["ColorTextures"] = ["wing"]
    rt.setup_material("transparent", m_transparent_plastic)

    rt.load_normal_tilt("transparent", "data/wing.png", prescale=0.002)

    # prepare dictionary and load meshes; note that both eyes and wings
    # are assigned with single material by providing only a part of
    # the mesh name:
    materials = {"eye": "plastic", "wing": "transparent"}
    rt.load_multiple_mesh_obj("data/fly.obj",
                              materials,
                              parent="head_Icosphere")

    # camera and light position auto-fit the scene geometry
    rt.setup_camera("cam1")
    d = np.linalg.norm(rt.get_camera_target() - rt.get_camera_eye())
    rt.setup_light("light1", color=10, radius=0.3 * d)

    rt.start()
    print("done")
Beispiel #14
0
def main():

    # make some data first:
    rx = (-1, 1.8)
    rz = (-1, 1.8)
    n = 18

    x = np.linspace(rx[0], rx[1], n)
    z = np.linspace(rz[0], rz[1], n)

    X, Z = np.meshgrid(x, z)
    Y = np.sqrt(X**2 + Z**2)

    # positions of blocks
    data = np.stack((X.flatten(), np.zeros(n * n), Z.flatten())).T
    # heights of blocks
    v = np.zeros(data.shape)
    v[:, 1] = (Y.flatten() + 0.3 * np.random.rand(n * n))[:]

    optix = TkOptiX()  # create and configure, show the window later

    optix.set_param(max_accumulation_frames=50)  # accumulate up to 50 frames
    optix.set_background(0)  # black background
    optix.set_ambient([0, 0.2, 0.4])  # cold ambient light

    # add plot geometry
    size_u = 0.98 * (rx[1] - rx[0]) / (n - 1)
    size_w = 0.98 * (rz[1] - rz[0]) / (n - 1)
    optix.set_data("blocks",
                   pos=data,
                   u=[size_u, 0, 0],
                   v=v,
                   w=[0, 0, size_w],
                   c=np.random.rand(n * n),
                   geom="Parallelepipeds")

    # set camera and light position
    optix.setup_camera("cam1",
                       cam_type="DoF",
                       eye=[-0.3, 2, -0.3],
                       target=[1, 1, 1],
                       fov=60,
                       focal_scale=0.85)
    optix.setup_light("light1", pos=[3, 4.5, 1], color=[6, 5, 4.5], radius=2)

    # Postprocessing configuration - uncomment what you'd like to include
    # or comment out all stages to see raw image. Try also combining
    # the mask overlay with one of tonal or levels corrections.

    # 1. Levels adjustment.
    #optix.set_float("levels_low_range", 0.1, 0.05, -0.05)
    #optix.set_float("levels_high_range", 0.9, 0.85, 0.8)
    #optix.add_postproc("Levels")

    # 2. Gamma correction.
    #optix.set_float("tonemap_exposure", 0.8)
    #optix.set_float("tonemap_igamma", 1 / 1.0)
    #optix.add_postproc("Gamma")

    # 3. Tonal correction with a custom curve.
    optix.set_float("tonemap_exposure", 0.8)
    # correction curve set explicitly:
    optix.set_texture_1d("tone_curve_gray", np.sqrt(np.linspace(0, 1, 64)))
    # correction curve calculated from control input/output values
    # (convenient if the curve was prepared in an image editor)
    #optix.set_correction_curve([[13,51], [54, 127], [170, 192]])
    optix.add_postproc("GrayCurve")

    # 4. Tonal correction with a custom RGB curves.
    #optix.set_float("tonemap_exposure", 0.8)
    #optix.set_texture_1d("tone_curve_r", np.sqrt(np.linspace(0.1, 1, 64)))
    #optix.set_texture_1d("tone_curve_g", np.sqrt(np.linspace(0, 1, 64)))
    #optix.set_texture_1d("tone_curve_b", np.sqrt(np.linspace(0, 1, 64)))
    #optix.add_postproc("RgbCurve")

    # 5. Overlay with a mask.
    #mx = (-1, 1)
    #mz = (-1, 1)
    #nm = 20

    #x = np.linspace(mx[0], mx[1], nm)
    #z = np.linspace(mz[0], mz[1], nm)

    #Mx, Mz = np.meshgrid(x, z)
    #M = np.abs(Mx) ** 3 + np.abs(Mz) ** 3
    #M = 1 - (0.6 / np.max(M)) * M

    #optix.set_texture_2d("frame_mask", M)
    #optix.add_postproc("Mask")

    optix.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")
Beispiel #16
0
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")
Beispiel #17
0
def main():

    # make some data first:
    b = 4
    n = 200
    k = 9.1
    l = 1.1
    m = 7.1

    r0 = 0.06
    q = 11

    x = np.sin(np.linspace(0, 2 * b * k * np.pi, b * n))
    y = np.cos(np.linspace(0, 2 * b * l * np.pi, b * n))
    z = np.sin(np.linspace(0, 2 * b * m * np.pi, b * n))
    pos = np.stack((x, y, z)).T

    r = r0 * 0.5 * (1 +
                    np.sin(np.linspace(0, 2 * b * q * np.pi, b * n))) + 0.002

    # create and configure, show the window later
    optix = TkOptiX()

    optix.set_param(min_accumulation_step=2, max_accumulation_frames=64)
    optix.setup_material("plastic", m_plastic)

    optix.setup_camera("dof_cam",
                       cam_type="DoF",
                       eye=[-4, 3, 4],
                       target=[0, 0, 0],
                       up=[0.21, 0.86, -0.46],
                       focal_scale=0.75)

    # some exposure and gamma adjutments
    optix.set_float("tonemap_exposure", 0.9)
    optix.set_float("tonemap_gamma", 1.4)
    optix.add_postproc("Gamma")

    ################################################################################
    # Try one of the background / lighting settings:

    # ------------------------------------------------------------------------------
    # 1. Ray tracer is initialized in `AmbientLight` mode. There is a constant
    #    background color and an omnidirectional light with the color independent
    #    from the background:

    #optix.setup_light("l1", color=4*np.array([0.99, 0.95, 0.9]), radius=3)
    #optix.set_background([0, 0.02, 0.1]) # ambient and background colors can be
    #optix.set_ambient(0.4)               # RGB array or a gray level

    # ------------------------------------------------------------------------------
    # 2. `Default` (although not set by default initialization) mode uses
    #    background color to paint the background and as the ambient light,
    #    so a brighter one is better looking here:

    #optix.set_background_mode("Default")
    #optix.setup_light("l1", color=np.array([0.99, 0.95, 0.9]), radius=3) # just a little light from the side
    #optix.set_background(0.94)

    # ------------------------------------------------------------------------------
    # 3. Environment map. Background texture is projected on the sphere with
    #    infinite radius, and it is also the source of the ambient light.

    # make a small RGB texture with a vertical gradient
    a = np.linspace(0.94, 0, 10)
    b = np.zeros((10, 2, 3))
    for i in range(10):
        b[i, 0] = np.full(3, a[i])
        b[i, 1] = np.full(3, a[i])

    # extend to RGBA (RGB is fine to use with `set_background()`, but is converted to
    # RGBA internally anyway)
    bg = np.zeros((10, 2, 4), dtype=np.float32)
    bg[:, :, :-1] = b

    optix.set_background_mode("TextureEnvironment")
    optix.setup_light("l1", color=np.array([0.99, 0.95, 0.9]),
                      radius=3)  # just a little light from the side
    optix.set_background(bg)

    # ------------------------------------------------------------------------------
    # 4. Fixed background texture. Background is just a wallpaper, you need to setup
    #    ambient light and/or other lights.

    # make a small RGB texture with a vertical gradient
    #a = np.linspace(0.94, 0, 10)
    #b = np.zeros((10, 2, 3))
    #for i in range(10):
    #    b[i,0]=np.full(3, a[i])
    #    b[i,1]=np.full(3, a[i])

    #optix.set_background_mode("TextureFixed")
    #optix.setup_light("l1", color=4*np.array([0.99, 0.95, 0.9]), radius=3)
    #optix.set_background(b)
    #optix.set_ambient(0.4)

    # ------------------------------------------------------------------------------
    # Note: background mode, lights, colors and textures can be all updated also
    # after the window is open, while the ray tracing running.
    ################################################################################

    # create a plot of parametric curve calculated above, and open the window
    optix.set_data("plot",
                   pos=pos,
                   r=r,
                   c=0.94,
                   geom="BezierChain",
                   mat="plastic")
    #optix.set_data("plot", pos=pos, r=r, c=0.94, geom="BSplineQuad", mat="plastic")
    #optix.set_data("plot", pos=pos, r=r, c=0.94, geom="BSplineCubic", mat="plastic")
    #optix.set_data("plot", pos=pos, r=r, c=0.94, geom="SegmentChain", mat="plastic")

    optix.start()

    print(optix.get_background_mode())

    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")
Beispiel #19
0
def main():

    # make some data first:
    rx = (-1, 1.8)
    rz = (-1, 1.8)
    n = 18

    x = np.linspace(rx[0], rx[1], n)
    z = np.linspace(rz[0], rz[1], n)

    X, Z = np.meshgrid(x, z)
    Y = np.sqrt(X**2 + Z**2)

    # positions of blocks
    data = np.stack((X.flatten(), np.zeros(n * n), Z.flatten())).T
    # heights of blocks
    v = np.zeros(data.shape)
    v[:, 1] = (Y.flatten() + 0.3 * np.random.rand(n * n))[:]

    optix = TkOptiX()  # create and configure, show the window later

    optix.set_param(max_accumulation_frames=50)  # accumulate up to 50 frames
    optix.set_background(0)  # black background
    optix.set_ambient([0, 0.2, 0.4])  # cold ambient light

    # add plot geometry
    size_u = 0.98 * (rx[1] - rx[0]) / (n - 1)
    size_w = 0.98 * (rz[1] - rz[0]) / (n - 1)
    optix.set_data("blocks",
                   pos=data,
                   u=[size_u, 0, 0],
                   v=v,
                   w=[0, 0, size_w],
                   c=np.random.rand(n * n),
                   geom="Parallelepipeds")

    # set camera and light position
    optix.setup_camera("cam1",
                       cam_type="DoF",
                       eye=[-0.3, 2, -0.3],
                       target=[1, 1, 1],
                       fov=60,
                       focal_scale=0.85)
    optix.setup_light("light1", pos=[3, 4.5, 1], color=[6, 5, 4.5], radius=2)

    # AI denoiser includes exposure and gamma corection, configured with the
    # same variables as the Gamma postprocessing algorithm.
    optix.set_float("tonemap_exposure", 0.5)
    optix.set_float("tonemap_gamma", 2.2)

    # Denoiser blend allows for different mixing with the raw image. Its value
    # can be modified also during the ray tracing.
    # Note: denoising is applied when > 4 accumulation frames are completed.
    optix.set_float("denoiser_blend", 0.25)
    optix.add_postproc("Denoiser")

    # Postprocessing stages are applied after AI denoiser (even if configured
    # in a different order).

    optix.set_float("levels_low_range", 0.1, 0.05, -0.05)
    optix.set_float("levels_high_range", 0.95, 0.85, 0.8)
    optix.add_postproc("Levels")

    optix.start()
    print("done")