Пример #1
0
    def render_scene(self,objects,lights,res):
        #create a viewport and image
        v = ViewPort(res[0],res[1])
        im = Image.new("RGB",(v.w,v.h))
        pix = im.load()

        #define a ray
        #FIX BUG -- STILL ORTHO
        ray = Ray(np.array([0,0,0]),np.array([0,0,-1]))

        # Perform perspective ray-tracing
        print("...generating "+str(v)+" image")
        for col in range(v.w):
            for row in range(v.h):
                color = np.zeros(3)
                print(color)
                ray.o = v.getPixelCenter(col,row)
                for s in objects:
                    t = s.intersectRay(ray)
                    if (t != None):
                        xp = ray.getPoint(t)
                        for light in lights:
                            color+= phongShader(xp,s.getNormal(xp),s.material,light,self.eye)
                            print(color)
                        #pix[col,v.h-1-row] = color
                        pix[col,v.h-1-row]=(1,1,1)   
        # Show the image in a window
        im.show()
Пример #2
0
    def render_scene(self, objects, lights, res):
        #create a viewport and image
        v = ViewPort(res[0], res[1])
        im = Image.new("RGB", (v.w, v.h))
        pix = im.load()

        #define a ray
        #FIX BUG -- STILL ORTHO
        ray = Ray(np.array([0, 0, 0]), np.array([0, 0, -1]))

        # Perform perspective ray-tracing
        print("...generating " + str(v) + " image")
        for col in range(v.w):
            for row in range(v.h):
                color = np.zeros(3)
                print(color)
                ray.o = v.getPixelCenter(col, row)
                for s in objects:
                    t = s.intersectRay(ray)
                    if (t != None):
                        xp = ray.getPoint(t)
                        for light in lights:
                            color += phongShader(xp, s.getNormal(xp),
                                                 s.material, light, self.eye)
                            print(color)
                        #pix[col,v.h-1-row] = color
                        pix[col, v.h - 1 - row] = (1, 1, 1)
        # Show the image in a window
        im.show()
Пример #3
0
    def render_scene(objects,res):
        #create a viewport and image
        v = ViewPort(res[0],res[1])
        im = Image.new("RGB",(v.w,v.h))
        pix = im.load()

        #define a ray
        ray = Ray(np.array([0,0,0]),np.array([0,0,-1]))

        # Perform perspective ray-tracing

        for col in range(v.w):
            for row in range(v.h):
                ray.o = v.getPixelCenter(col,row)
                t = s.intersectRay(ray)
                if (t != None):
                    xp = ray.getPoint(t) 
                    pix[col,(v.h-1)-row] = phongShader(xp,s.getNormal(xp),s.material,light,eye)

        # Show the image in a window
        im.show()
        
Пример #4
0
    def render_scene(objects, res):
        #create a viewport and image
        v = ViewPort(res[0], res[1])
        im = Image.new("RGB", (v.w, v.h))
        pix = im.load()

        #define a ray
        ray = Ray(np.array([0, 0, 0]), np.array([0, 0, -1]))

        # Perform perspective ray-tracing

        for col in range(v.w):
            for row in range(v.h):
                ray.o = v.getPixelCenter(col, row)
                t = s.intersectRay(ray)
                if (t != None):
                    xp = ray.getPoint(t)
                    pix[col,
                        (v.h - 1) - row] = phongShader(xp, s.getNormal(xp),
                                                       s.material, light, eye)

        # Show the image in a window
        im.show()