コード例 #1
0
    def build_cornell_box(self):
        ny, nx, _ = self.image.shape
        self.camera = Camera.lookat(vm.Point3(278., 278., -800.),
                                    vm.Point3(278., 278., 0.), vm.Vec3.yaxis(),
                                    40.,
                                    float(nx) / float(ny))

        self.world = ShapeList()
        self.world.add(ShapeBuilder().color_texture(vm.Color(
            0.12, 0.45, 0.15)).lambertian().rect_yz(0., 555., 0., 555.,
                                                    555.).flip_face().build())
        self.world.add(ShapeBuilder().color_texture(vm.Color(
            0.65, 0.05, 0.05)).lambertian().rect_yz(0., 555., 0., 555.,
                                                    0.).build())
        self.world.add(ShapeBuilder().color_texture(
            vm.Color.full(15.)).diffuse_light().rect_xz(
                213., 343., 227., 332., 554.).flip_face().build())
        self.world.add(ShapeBuilder().color_texture(
            vm.Color.full(0.73)).lambertian().rect_xz(
                0., 555., 0., 555., 555.).flip_face().build())
        self.world.add(ShapeBuilder().color_texture(
            vm.Color.full(0.73)).lambertian().rect_xz(0., 555., 0., 555.,
                                                      0.).build())
        self.world.add(ShapeBuilder().color_texture(
            vm.Color.full(0.73)).lambertian().rect_xy(
                0., 555., 0., 555., 555.).flip_face().build())

        self.world.add(ShapeBuilder().dielectric(1.5).sphere(
            vm.Point3(190., 90., 190.), 90.).build())
        self.world.add(
            ShapeBuilder().color_texture(vm.Color.full(0.73)).lambertian().box(
                vm.Point3(), vm.Point3(165., 330., 165.)).rotate(
                    vm.Vec3.yaxis(), 15.).translate(vm.Point3(265., 0.,
                                                              295.)).build())

        self.light = ShapeList()
        self.light.add(ShapeBuilder().default_material().rect_xz(
            213., 343., 227., 332., 554.).build())
        self.light.add(ShapeBuilder().default_material().sphere(
            vm.Point3(190., 90., 190.), 90.).build())

        self.bgcolor = vm.Color()
コード例 #2
0
    def build(self):
        self.camera = Camera(vm.Point3(), vm.Vec3(4., 0., 0.),
                             vm.Vec3(0., 2., 0.), vm.Vec3(-2., -1., -1.))

        self.world = ShapeList()
        self.world.add(ShapeBuilder().color_texture(vm.Color(
            0.1, 0.2, 0.5)).lambertian().sphere(vm.Point3(0.6, 0, -1.),
                                                0.5).build())
        # self.world.add(ShapeBuilder()
        #     .image_texture('assets/brick_diffuse.jpg')
        #     .lambertian()
        #     .sphere(vm.Point3(0.6, 0, -1.), 0.5)
        #     .build())
        # self.world.add(ShapeBuilder()
        #     .color_texture(vm.Color.full(10.0))
        #     .diffuse_light()
        #     .sphere(vm.Point3(-0.6, 0, -1.), 0.5)
        #     .build())
        self.world.add(ShapeBuilder().color_texture(
            vm.Color.full(0.8)).metal(0.2).sphere(vm.Point3(-0.6, 0, -1.),
                                                  0.5).build())
        # self.world.add(ShapeBuilder()
        #     .dielectric(1.5)
        #     .sphere(vm.Point3(-0.6, 0, -1.), 0.5)
        #     .build())
        # self.world.add(ShapeBuilder()
        #     .dielectric(1.5)
        #     .sphere(vm.Point3(-0.6, 0, -1.), -0.45)
        #     .build())
        # self.world.add(ShapeBuilder()
        #     .color_texture(vm.Color.full(0.8))
        #     .metal(0.2)
        #     .sphere(vm.Point3(0., -0.35, -0.8), 0.15)
        #     .build())
        self.world.add(ShapeBuilder().color_texture(vm.Color(
            10., 0., 0.)).diffuse_light().rect_xy(-2., 2., 0.2, 2.,
                                                  -2.).build())
        self.world.add(ShapeBuilder().checker_texture(
            vm.Color(0.8, 0.8, 0.), vm.Color(0.8, 0.2, 0.),
            10.).lambertian().sphere(vm.Point3(0., -100.5, -1.), 100.).build())
コード例 #3
0
 def render_line(self, y):
     ny, nx, _ = self.image.shape
     image = np.zeros((nx, 3), dtype=np.uint8)
     for i in range(nx):
         c = vm.Color()
         for s in range(self.samples):
             rnd = vm.Float3.random()
             u = (float(i) + rnd.x()) / float(nx)
             v = (float(y) + rnd.y()) / float(ny)
             r = self.camera.get_ray(u, v)
             c = c + self.color(r, 0)
         image[i] = c.div(float(self.samples)).saturate().gamma().as_bgr8()
     return image
コード例 #4
0
 def render(self):
     ny, nx, _ = self.image.shape
     for j in range(ny):
         for i in range(nx):
             c = vm.Color()
             for s in range(self.samples):
                 rnd = vm.Float3.random()
                 u = (float(i) + rnd.x()) / float(nx)
                 v = (float(j) + rnd.y()) / float(ny)
                 r = self.camera.get_ray(u, v)
                 c = c + self.color(rm, 0)
             self.image[ny - j - 1, i] = c.div(float(
                 self.samples)).saturate().gamma().as_bgr8()
コード例 #5
0
 def backgroundSky(self, d):
     t = 0.5 * (d.normalize().y() + 1.)
     return vm.Color.one().lerp(vm.Color(0.5, 0.7, 1.), t)
コード例 #6
0
 def emitted(self, ray, rec):
     if ray.direction.dot(rec.n) < 0.:
         return self.emit.sample(rec.u, rec.v, rec.p)
     else:
         return vm.Color()
コード例 #7
0
 def emitted(self, ray, rec):
     return vm.Color()
コード例 #8
0
 def sample(self, u, v, p):
     x = int(u * float(self.width))
     y = int((1. - v) * float(self.height))
     u = 0 if x < 0 else self.width - 1 if x >= self.width else x
     v = 0 if y < 0 else self.height - 1 if y >= self.height else y
     return vm.Color(*self.albedo[v, u])
コード例 #9
0
 def __init__(self):
     self.ray = Ray(vm.Point3(), vm.Vec3.xaxis())
     self.albedo = vm.Color()
     self.pdf = None
     self.is_specular = False