Ejemplo n.º 1
0
    cam_y = cam_x.cross(gaze).normalize() * fov

    Ls = [None] * w * h
    for i in range(w * h):
        Ls[i] = Vector3()

    for y in range(h):
        # pixel row
        print('\rRendering ({0} spp) {1:0.2f}%'.format(nb_samples,
                                                       100.0 * y / (h - 1)))
        for x in range(w):
            # pixel column
            i = (h - 1 - y) * w + x
            for s in range(nb_samples):
                # samples per pixel
                dx = rng.uniform_float()
                dy = rng.uniform_float()

                #create camera vector multipliers that range between screen-space coordinates of -0.5 to 0.5
                cam_x_multiplier = (dx + x) / w - 0.5
                cam_y_multiplier = (dy + y) / h - 0.5

                directional_vec = cam_x * cam_x_multiplier + cam_y * cam_y_multiplier + gaze
                L = Vector3()
                ray = Ray(eye + directional_vec * 130,
                          directional_vec.normalize())

                if args.passtype == "direct":
                    L = shadow_ray_pass(ray, rng)
                elif args.passtype == "albedo":
                    L = albedo_pass(ray, rng)
Ejemplo n.º 2
0
        Ls[i] = Vector3()

    for y in range(h):
        # pixel row
        print('\rRendering ({0} spp) {1:0.2f}%'.format(nb_samples * 4,
                                                       100.0 * y / (h - 1)))
        for x in range(w):
            # pixel column
            for sy in range(2):
                i = (h - 1 - y) * w + x
                # 2 subpixel row
                for sx in range(2):
                    # 2 subpixel column
                    L = Vector3()
                    for s in range(nb_samples):
                        #  samples per subpixel
                        u1 = 2.0 * rng.uniform_float()
                        u2 = 2.0 * rng.uniform_float()
                        dx = sqrt(u1) - 1.0 if u1 < 1 else 1.0 - sqrt(2.0 - u1)
                        dy = sqrt(u2) - 1.0 if u2 < 1 else 1.0 - sqrt(2.0 - u2)
                        d = cx * (((sx + 0.5 + dx) / 2.0 + x) / w - 0.5) + \
                            cy * (((sy + 0.5 + dy) / 2.0 + y) / h - 0.5) + gaze
                        L += radiance(
                            Ray(eye + d * 130,
                                d.normalize(),
                                tmin=Sphere.EPSILON_SPHERE),
                            rng) * (1.0 / nb_samples)
                    Ls[i] += 0.25 * Vector3.clamp(L)

    write_ppm(w, h, Ls)