Esempio n. 1
0
        public static Hitable_List Two_Perlin_Spheres()
        {
            Hitable_List objects = new Hitable_List();

            var pertext = new Noise_texture();

            objects.Add(new Sphere(new Vector3(0, -1000, 0), 1000, new Lambertian(pertext)));
            objects.Add(new Sphere(new Vector3(0, 2, 0), 2, new Lambertian(pertext)));

            return(objects);
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            float aspect_ratio      = 16.0f / 9.0f;
            int   image_width       = 384;
            int   image_height      = (int)(image_width / aspect_ratio);
            int   samples_per_pixel = 100;
            int   max_depth         = 50;

            string filePath = "image.ppm";

            using (var file = new StreamWriter(filePath))
            {
                file.WriteLine($"P3\n{image_width} {image_height}\n255");

                float viewport_height = 2.0f;
                float viewport_width  = aspect_ratio * viewport_height;
                float focal_length    = 1.0f;

                var origin            = Vector3.Zero;
                var horizontal        = new Vector3(viewport_width, 0, 0);
                var vertical          = new Vector3(0, viewport_height, 0);
                var lower_left_corner = origin - horizontal / 2 - vertical / 2 - new Vector3(0, 0, focal_length);

                Hitable_List world = Two_Perlin_Spheres();

                Vector3 lookfrom      = new Vector3(13, 2, 3);
                Vector3 lookat        = new Vector3(0, 0, 0);
                Vector3 vup           = new Vector3(0, 1, 0);
                float   dist_to_focus = 10.0f;
                float   aperture      = 0.0f;

                Camera cam = new Camera(lookfrom, lookat, vup, 20, aspect_ratio, aperture, dist_to_focus, 0.0f, 1.0f);

                for (int j = image_height - 1; j >= 0; --j)
                {
                    Console.WriteLine($"\rScanlines remaining: {j}");
                    for (int i = 0; i < image_width; ++i)
                    {
                        Vector3 pixel_color = Vector3.Zero;
                        for (int s = 0; s < samples_per_pixel; ++s)
                        {
                            float u = (float)(i + Helpers.random.NextDouble()) / (image_width - 1);
                            float v = (float)(j + Helpers.random.NextDouble()) / (image_height - 1);
                            Ray   r = cam.Get_Ray(u, v);
                            pixel_color += Ray_color(r, world, max_depth);
                        }
                        Write_color(file, pixel_color, samples_per_pixel);
                    }
                }

                Console.WriteLine("Done.");
            }
        }
Esempio n. 3
0
 public BVH_Node(Hitable_List list, float time0, float time1)
     : this(list.Objects, 0, (uint)list.Objects.Count, time0, time1)
 {
 }