Exemple #1
0
def render():
    (w, h) = (640, 480)
    camera = Camera(w, h, fov=np.pi / 6)

    # Materials
    base_finish = SoftDull
    base_finish.reflection = 0.1
    mat_base = Material(colors.P_Chrome3, finish=base_finish)

    mat_s1 = Material(colors.P_Brass3)

    se_ls = LightSourcePoint([-1., 5., 35.],
                             intensity=200.,
                             emission_color=[2., 2., 2.])
    se_base = SceneElement(Plane([0.0, -4.0, 20.], [0., 1., 0.]), mat_base)

    se_s1 = SceneElement(Sphere([0., 0., 40.], 4.), mat_s1)

    scene = Scene([se_ls, se_base, se_s1])
    # scene = Scene([se_ls, se_base])

    # Render
    rt = RayTracer(camera, scene)
    traced = rt.render()
    plt.imshow(traced)
    plt.show()
Exemple #2
0
def render():
    (w, h) = (640, 480)
    camera = Camera(w, h, fov=np.pi / 6)
    
    # Materials
    mat_base = Material([1., 1., 1.])

    # mat_s1 = Material(colors.Aquamarine, finish=Finish(diffuse=0.7, ambient=0.1, specular=0.8, roughness=1./120, transparent=True, ior=1.5))
    # mat_s1 = Material(colors.Glass_Winebottle, finish=Finish(diffuse=0.7, ambient=0.1, specular=0.8, roughness=1./120, transparent=True, ior=1.5))
    mat_s1 = Material(colors.P_Silver3, finish=Finish(diffuse=0.7, ambient=0.1, specular=0.8, roughness=1./120, transparent=True, ior=1.5))

    mat_s2 = Material(colors.P_Copper3, finish=Medium, metallic=True)
    mat_s3 = Material(colors.P_Chrome3, finish=Medium, metallic=True)
    mat_s4 = Material(colors.P_Brass3, finish=Medium, metallic=True)


    # Scene Elements + Scene
    se_ls = LightSourcePoint([-5., 15., 20.], intensity=1000., emission_color=[2., 2., 2.])

    se_base = SceneElement(Sphere([0.0, -10004., 20.], 10000.), mat_base)

    se_s1 = SceneElement(Sphere([0., 0., 20.], 4.), mat_s1)
    se_s2 = SceneElement(Sphere([5.0, -1., 15.], 2.), mat_s2)
    se_s3 = SceneElement(Sphere([3.0, 0, 22.], 2.), mat_s3)
    se_s4 = SceneElement(Sphere([-5.5, 0, 15.], 3.), mat_s4)

    scene = Scene([se_ls, se_base, se_s1, se_s2, se_s3, se_s4])

    # Render
    rt = RayTracer(camera, scene, num_bounces=5)
    traced = rt.render()
    plt.imshow(traced); plt.show()
Exemple #3
0
def render():
    (w, h) = (640, 480)
    camera = Camera(w, h, fov=np.pi / 6)
    
    # Materials
    mat_base = Material([0.2, 0.2, 0.2])

    mat_s1 = Material(colors.P_Brass3, finish=Finish(transparent=True, ior=1.1))
    mat_s2 = Material(colors.CornflowerBlue, finish=Finish(reflection=0.1))
    mat_s3 = Material(colors.ForestGreen, finish=Finish(reflection=0.1))
    mat_s4 = Material(colors.GreenCopper, finish=Finish(reflection=0.1))

    # Scene Elements + Scene
    se_ls = LightSourcePoint([-5., 10., 20.], intensity=1000.)

    se_base = SceneElement(Sphere([0.0, -10004., 20.], 10000.), mat_base)

    se_s1 = SceneElement(Sphere([0., 0., 20.], 4.), mat_s1)
    se_s2 = SceneElement(Sphere([5.0, -1., 15.], 2.), mat_s2)
    se_s3 = SceneElement(Sphere([5.0, 0, 25.], 3.), mat_s3)
    se_s4 = SceneElement(Sphere([-5.5, 0, 15.], 3.), mat_s4)

    scene = Scene([se_ls, se_base, se_s1, se_s2, se_s3, se_s4])

    # Render
    rt = RayTracer(camera, scene)
    traced = rt.render()
    plt.imshow(traced); plt.show()
Exemple #4
0
def render():
    # with open('examples/cube.obj') as f:
    with open('examples/teapot.obj') as f:
        lines = f.readlines()

    # simple (read stupid) parser for obj files
    V = []
    F = []
    for line in lines:
        line = line.replace('  ', ' ')
        if line[0:2] == "v ":
            V.append(map(float, line.strip().split(' ')[1:]))
        elif line[0:2] == "f ":
            f = line.strip().split(' ')[1:]
            f = map(lambda x: int(x.split('/')[0])-1, f)
            F.extend(f)

    n_polys = len(F) / 3
    fi = [3 for _ in range(n_polys)]

    # n_polys, fi, V, F = down_sample(n_polys, fi, V, F)

    tm = TriangleMesh(n_polys, fi, F, np.array(V).T, clockwise=True)

    (w, h) = (640, 480)
    camera = Camera(w, h, fov=np.pi / 2)
    camera.translate([0, 0, -100])
    # camera = Camera(w, h, fov=np.pi / 3)
    
    # Materials
    mat_base = Material([0.2, 0.2, 0.2])

    # mat_s1 = Material(colors.NeonPink, diffuse=0.7, ambient=0.1, specular=0.8, roughness=1./120, reflection=0.)
    mat_s1 = Material(colors.NeonPink, finish=VerySoftDull)

    se_ls = LightSourceDirectional([1, -1, 0], intensity=2., emission_color=[1., 1., 1.])
    se_base = SceneElement(Sphere([0.0, -10004., 20.], 10000.), mat_base)

    se_tm = SceneElement(tm, mat_s1)

    scene = Scene([se_ls, se_tm])

    # Render
    rt = RayTracer(camera, scene, num_bounces=0, background_color=0.5*np.ones((3, 1)))
    traced = rt.render()
    plt.imshow(traced); plt.show()

    import ipdb; ipdb.set_trace()
Exemple #5
0
def render():
    (w, h) = (640, 480)
    camera = Camera(w, h, fov=np.pi / 6)

    # Materials
    mat_base = Material(colors.DimGray)

    mat_s1 = Material(colors.P_Silver3,
                      finish=Finish(reflection=0.,
                                    specular=0.8,
                                    roughness=1. / 20))
    mat_s2 = Material(colors.P_Brass3,
                      finish=Finish(ambient=0.25,
                                    diffuse=0.5,
                                    transparent=True,
                                    specular=0.8,
                                    roughness=1. / 80,
                                    ior=1.5),
                      metallic=True)

    se_ls = LightSourcePoint([-5., 10., 20.], intensity=1000.)
    se_ls2 = LightSourceDirectional([1., -1., 1.], intensity=0.5)

    se_base = SceneElement(Sphere([0.0, -10004., 20.], 10000.), mat_base)

    se_s1 = SceneElement(Sphere([-3., -1., 20.], 2.), mat_s1)
    se_s2 = SceneElement(Sphere([0, -1., 35.], 2.), mat_s1)
    se_s3 = SceneElement(Sphere([4., -1., 40.], 2.), mat_s1)
    se_s4 = SceneElement(Sphere([9., -1., 55.], 2.), mat_s1)

    scene = Scene([se_ls, se_ls2, se_base, se_s1, se_s2, se_s3, se_s4])

    # Render
    rt = RayTracer(camera, scene)
    traced_nodov = rt.render()

    traced = rt.render_dov([-3., -1., 20.], num_samples=8)
    # traced = rt.render_dov([0, -1., 35.], num_samples=8)
    # traced = rt.render_dov([4., -1., 40.], num_samples=8)
    # traced = rt.render_dov([9., -1., 55.], num_samples=4)
    # traced = rt.render()

    plt.subplot(211)
    plt.imshow(traced_nodov)
    plt.subplot(212)
    plt.imshow(traced)
    plt.show()
Exemple #6
0
def render():
    (w, h) = (640 * 2, 480 * 2)
    camera = Camera(w, h, fov=np.pi / 6)

    # Materials
    mat_base = Material([1., 1., 1.], finish=Medium)

    mat_s1 = Material(colors.Sapphire2, finish=HardPolished)
    mat_s2 = Material(colors.Amber3, finish=HardPolished)
    mat_s3 = Material(colors.Tourmaline1, finish=HardPolished)
    mat_s4 = Material(colors.Ruby4, finish=HardPolished)
    mat_s5 = Material(colors.Emerald5, finish=HardPolished)
    mat_s6 = Material(colors.Citrine2, finish=HardPolished)

    mat_s7 = Material(colors.Azurite3, finish=HardPolished)
    mat_s8 = Material(colors.Amethyst3, finish=HardPolished)
    mat_s9 = Material(colors.P_Brass3, finish=HardPolished, metallic=True)

    # Scene Elements + Scene
    se_ls = LightSourcePoint([-5., 15., 15.],
                             intensity=1000.,
                             emission_color=[2., 2., 2.])

    se_base = SceneElement(Sphere([0.0, -10004., 20.], 10000.), mat_base)

    se_s1 = SceneElement(Sphere([0., 0., 20.], 4.), mat_s1)
    se_s2 = SceneElement(Sphere([-7., -2., 23.], 2.), mat_s2)
    se_s3 = SceneElement(Sphere([-5., -3., 27.], 1.), mat_s3)
    se_s4 = SceneElement(Sphere([-10., 3., 50.], 7.), mat_s4)
    se_s5 = SceneElement(Sphere([22., 3., 50.], 7.), mat_s5)
    se_s6 = SceneElement(Sphere([15., -3., 35.], 1.), mat_s6)
    se_s7 = SceneElement(Sphere([10., -1., 33.], 3.), mat_s7)
    se_s8 = SceneElement(Sphere([5., -2., 25.], 2.), mat_s8)
    se_s9 = SceneElement(Sphere([4., -3., 15.], 1.), mat_s9)

    scene = Scene([
        se_ls, se_base, se_s1, se_s2, se_s3, se_s4, se_s5, se_s6, se_s7, se_s8,
        se_s9
    ])

    # Render
    rt = RayTracer(camera, scene, num_bounces=10)
    traced = rt.render()
    # plt.imshow(traced); plt.show()
    misc.imsave('renders/pretty2.png', traced)
def render():
    (w, h) = (640, 480)
    camera = Camera(w, h, fov=np.pi / 6)

    # Materials
    base_finish = SoftDull
    base_finish.reflection = 0.5
    mat_base = Material(colors.P_Chrome1, finish=base_finish)

    mat_f = VeryHardPolished
    mat_f.reflection = 0.1
    mat_s1 = Material(colors.Ruby1, finish=mat_f)
    mat_s2 = Material(colors.Emerald1, finish=mat_f)
    mat_s3 = Material(colors.Aquamarine1, finish=mat_f)

    # se_ls = LightSourcePoint([-5., 15., 20.], intensity=1000., emission_color=[2., 2., 2.])
    se_ls = LightSourceDirectional([1, -1, 0],
                                   intensity=2.,
                                   emission_color=[1., 1., 1.])

    se_base = SceneElement(Plane([0.0, -4.0, 20.], [0., 1., 0.]), mat_base)

    cone = Cone([5., 0., 40.], 2., length=4, closed=True)
    cone.rotate(np.pi / 2. + np.pi / 4, [0, 1, 0])

    cylinder = Cylinder([2., 0., 40.], 2., length=2, closed=True)
    cylinder.rotate(-np.pi / 4, [0, 1, 0])
    se_s1 = SceneElement(cone, mat_s1)
    se_s2 = SceneElement(cylinder, mat_s2)
    se_s3 = SceneElement(Sphere([-5., 0., 40.], 2.), mat_s3)

    scene = Scene([se_ls, se_base, se_s1, se_s2, se_s3])

    # Render
    rt = RayTracer(camera, scene)
    traced = rt.render()
    plt.imshow(traced)
    plt.show()
Exemple #8
0
def render():
    (w, h) = (640, 480)
    camera = Camera(w, h, fov=np.pi / 6)

    # Materials
    mat_base = Material(colors.DimGray)

    mat_s1 = Material(colors.CadetBlue,
                      finish=Finish(reflection=0.,
                                    specular=0.8,
                                    roughness=1. / 20))
    mat_s2 = Material(colors.P_Brass3,
                      finish=Finish(ambient=0.25,
                                    diffuse=0.5,
                                    transparent=True,
                                    specular=0.8,
                                    roughness=1. / 80,
                                    ior=1.5),
                      metallic=True)

    se_ls = LightSourcePoint([-5., 10., 20.], intensity=1000.)
    se_ls2 = LightSourceDirectional([1., -1., 1.], intensity=0.2)

    se_base = SceneElement(Sphere([0.0, -10004., 20.], 10000.), mat_base)

    se_s1 = SceneElement(Sphere([-1., -2., 20.], 2.), mat_s1)
    se_s2 = SceneElement(Sphere([3.25, -1., 22.], 2.), mat_s2)
    se_s3 = SceneElement(Sphere([3.25, -1., 27.], 2.), mat_s1)

    scene = Scene([se_ls, se_ls2, se_base, se_s1, se_s2, se_s3])

    # Render
    rt = RayTracer(camera, scene)
    traced = rt.render()
    plt.imshow(traced)
    plt.show()