Example #1
0
        public override void RenderScene(World world)
        {
            RGBColor pixelColor;
            Ray      ray = new Ray();
            double   zw = 100.0;
            double   x, y;

            Vector2 sp;
            Vector2 pp = new Vector2();

            ray.origin = this.eye;

            Console.WriteLine("Number objects on scene = " + world.objects.Count);
            Console.WriteLine("Number lights on scene = " + world.lights.Count);
            Console.WriteLine("Render start - perspective camera");
            for (int r = 0; r < height; r++)
            {
                if (r % 10 == 0)
                {
                    Console.WriteLine("pika " + r);
                }
                for (int c = 0; c < width; c++)
                {
                    pixelColor = RGBColor.BLACK;

                    for (int j = 0; j < world.jittered.numSamples; j++)
                    {
                        sp = world.jittered.SampleUnitSquare();
                        double tmpPixelSize = 0.2;
                        pp.x = tmpPixelSize * (c - 0.5 * width + sp.x);

                        //zaczynamy od ćwiartki II, tak to -60 i -60, więc y odwrócone
                        pp.y          = tmpPixelSize * (r - 0.5 * height + sp.y);
                        pp.y          = pp.y * -1;
                        ray.direction = RayDirection(pp);
                        int depthRef = 0;
                        pixelColor = pixelColor + world.tracer.ShadeRay(world, ray, ref depthRef);
                    }

                    pixelColor = pixelColor / world.jittered.numSamples;
                    bitmap.SetPixel(c, r, RGBColor.StripColor(pixelColor));
                }
            }
            bitmap.Save("renderPerspectiveBitmap.bmp");
            Console.WriteLine("Finish render");
        }
Example #2
0
        public override void RenderScene(Renderer.World world)
        {
            RGBColor pixelColor;
            Ray      ray = new Ray();
            double   zw = 100.0;
            double   x, y;

            Vector2 sp;
            Vector2 pp = new Vector2();

            ray.direction = new Vector3(0, 0, -1);

            Console.WriteLine("Number objects on scene = " + world.objects.Count);
            Console.WriteLine("Number lights on scene = " + world.lights.Count);
            Console.WriteLine("Render start - orthogonal camera");
            for (int r = 0; r < height; r++)
            {
                for (int c = 0; c < width; c++)
                {
                    pixelColor = RGBColor.BLACK;

                    for (int j = 0; j < world.jittered.numSamples; j++)
                    {
                        sp = world.jittered.SampleUnitSquare();
                        double tmpPixelSize = 0.2;
                        pp.x = tmpPixelSize * (c - 0.5 * width + sp.x);

                        //zaczynamy od ćwiartki II, tak to -60 i -60, więc y odwrócone
                        pp.y = tmpPixelSize * (r - 0.5 * height + sp.y);
                        pp.y = pp.y * -1;

                        ray.origin = new Vector3(pp.x, pp.y, zw);
                        int depthRef = 0;
                        pixelColor = pixelColor + world.tracer.ShadeRay(world, ray, ref depthRef);
                    }

                    pixelColor = pixelColor / world.jittered.numSamples;
                    //writeToFile.WriteLine( pixelColor.r + " " + pixelColor.g + " " + pixelColor.b);
                    bitmap.SetPixel(c, r, RGBColor.StripColor(pixelColor));
                }
            }
            bitmap.Save("renderBitmap.bmp");
            Console.WriteLine("Finish render");
        }