Esempio n. 1
0
        //======================================================================================================================
        //==            DRAW SCENE - créer un image ppm de la scene actuelle, lance les rayons etc.                           ==
        //======================================================================================================================
        public void DrawScene(int rayCastNb)
        {
            Vector3[,] pixMat = new Vector3[camera.width, camera.height];

            for (int y = 0; y < camera.height; y++)
            {
                for (int x = 0; x < camera.width; x++)
                {
                    Vector3 color = new Vector3(0, 0, 0);

                    for (int i = 0; i < rayCastNb; i++)
                    {
                        Vector3 start     = new Vector3(camera.center.X + x + (float)(rdm.NextDouble() - 0.5), camera.center.Y + y + (float)(rdm.NextDouble() - 0.5), camera.center.Z);
                        Vector3 direction = Vector3.Subtract(start, camera.focus);
                        direction = Vector3.Normalize(direction);
                        Ray r = new Ray(start, direction);
                        color = Vector3.Add(color, Radiance(r, 0));
                    }

                    pixMat[x, y] = Vector3.Divide(color, rayCastNb);
                }
            }
            ImagePPM img = new ImagePPM(name, camera.width, camera.height).FromMatrix(pixMat);

            img.ToPPM();
        }
        public void DrawScene()
        {
            Tree Arbre = ConstructTree(boites);

            Vector3[,] pixMat = new Vector3[camera.width, camera.height];
            //nb_rayon_rebond est le nombre de rayon envoyé par pixel pour éviter le bruit pour les zones ombrées (car les rebond se font aléatoirement)
            int nb_rayon_rebond = 10;

            for (int y = 0; y < camera.height; y++)
            {
                for (int x = 0; x < camera.width; x++)
                {
                    //pour les spheres

                    Vector3 couleur_rayon = new Vector3(0.0f, 0.0f, 0.0f);
                    for (int c = 0; c < nb_rayon_rebond; c++)
                    {
                        Vector3 start     = new Vector3(camera.center.X + x, camera.center.Y + y, camera.center.Z);
                        Vector3 direction = Vector3.Subtract(start, camera.focus);
                        direction = Vector3.Normalize(direction);
                        Ray r = new Ray(start, direction);
                        //couleur_rayon = Vector3.Add(Radiance(r, 0), couleur_rayon);
                        couleur_rayon = Vector3.Add(Radiance(r, 0, Arbre), couleur_rayon);
                    }
                    pixMat[x, y] = couleur_rayon / nb_rayon_rebond;
                }
            }
            ImagePPM img = new ImagePPM(name, camera.width, camera.height).FromMatrix(pixMat);

            img.ToPPM();
        }