Esempio n. 1
0
 public PointColore(V3 spatialLocator, V3 normale, Couleur couleur, Formes proprio)
 {
     SpatialLocator    = spatialLocator;
     Couleur           = couleur;
     this.normale      = normale;
     this.proprietaire = proprio;
 }
Esempio n. 2
0
        /*public override void Draw(Couleur C_ambiant, Lumiere L, V3 camera)
        {
            //float cosln;
            //Couleur final_ambiant, final_diff, final_spec;
            //Couleur C_lampe = L.getClampe();

            //L1 = (new V3(0.0f, 1.0f, 0.0f)) ^ (L1 ^ (new V3(0.0f, 1.0f, 0.0f)));
            //L2 = (new V3(0.0f, 1.0f, 0.0f)) ^ (L2 ^ (new V3(0.0f, 1.0f, 0.0f)));
            // 4 sommets : origin, origin + L1, origin + L2, origin + L1 + L2
            for (V3 u = new V3(0.0f, 0.0f, 0.0f); (u.x < Math.Abs(L1.x) || L1.x == 0) && (u.y < Math.Abs(L1.y) || L1.y == 0) && (u.z < Math.Abs(L1.z) || L1.z == 0); u += (L1 * (float)pas))
            {
                for (V3 v = new V3(0.0f, 0.0f, 0.0f); (v.x < Math.Abs(L2.x) || L2.x == 0) && (v.y < Math.Abs(L2.y) || L2.y == 0) && (v.z < Math.Abs(L2.z) || L2.z == 0); v += (L2 * (float)pas))
                {
                    float dhdu, dhdv;
                    float x = u.x + v.x + origin.x;
                    float y = u.y + v.y + origin.y;
                    float z = u.z + v.z + origin.z;

                    int x_ecran = (int)x;
                    int z_ecran = (int)z;

                    Couleur C_obj = T.LireCouleur((float)(u.Norm() / L1.Norm()), (float)(v.Norm() / L2.Norm()));
                    //final_ambiant = C_obj * C_ambiant;

                    if (ZBuffer.test(y, x_ecran, z_ecran))
                    {
                        // BUMP MAP
                        V3 Np = N;
                        if (T_bump != null)
                        {
                            V3 dmdu = L1;
                            V3 dmdv = L2;
                            this.T_bump.Bump((float)(u.Norm() / L1.Norm()), (float)(v.Norm() / L2.Norm()), out dhdu, out dhdv);
                            Np = N + bump_coeff * ((dmdu ^ (N * dhdv)) + ((N * dhdu) ^ dmdv));
                        }
                        // FIN BUMP MAP

                        V3 O = new V3(x, y, z);
                        O = camera - O;
                        //Couleur finalColor = computeLights(C_obj, C_ambiant, Np, O, L, k);
                        //BitmapEcran.DrawPixel(x_ecran, z_ecran, finalColor);
                    }
                }
            }
        }*/
        public override Couleur DrawPoint(Couleur C_ambiant, List<Lampe> lampList, V3 camera, V3 R, bool[] occs)
        {
            V3 N = this.N;
            N.Normalize();
            V3 O = camera - R;

            // TEXTURE
            V3 AI = R - this.origin;
            float a = (this.L1 * AI) / (this.L1.Norme2());
            float b = ((AI - a * this.L1).Norm()) / (this.L2.Norm());
            Couleur C_obj = T.LireCouleur(a, 1 - b);

            // BUMP MAP
            if (T_bump != null)
            {
                float dhdu, dhdv;
                V3 dmdu = L1;
                V3 dmdv = L2;
                this.T_bump.Bump(a, b, out dhdu, out dhdv);
                N = N + bump_coeff * ((dmdu ^ (N * dhdv)) + ((N * dhdu) ^ dmdv));
            }
            // FIN BUMP MAP

            Point I = new Point(C_obj, C_ambiant, N, O, this.k);
            Couleur finalColor = computeLights(I, lampList, occs);
            return finalColor;
        }
Esempio n. 3
0
        public static Couleur Color_Specular(Light_Source light, V3 P, V3 N, int k)
        {
            V3 L = -light.direction;

            if (light.point_light)
            {
                L = light.position - P;
                L.Normalize();
            }
            float cos_alpha = (N * L);

            if (light.point_light && cos_alpha < 0)
            {
                cos_alpha = -cos_alpha;
            }

            V3 R = (N * 2 * cos_alpha) - L;

            R.Normalize();

            V3 D = Elements.camera_position - P;

            D.Normalize();

            float f = (R * D);

            if (f < 0)
            {
                f = 0;        // if cos is negative there won't be any specularity
            }
            Couleur c = (float)Math.Pow(f, k) * (light.color);

            return(c);
        }
Esempio n. 4
0
 public Light_Source(V3 direction, Couleur color)
 {
     ;
     this.direction = direction;
     this.direction.Normalize();
     this.color = color;
 }
Esempio n. 5
0
        public static Couleur Color_Diffused(Light_Source light, Couleur px_color, V3 P, V3 N)
        {
            V3 L = -light.direction;

            if (light.point_light)
            {
                L = light.position - P;
                //L = P-light.position;
                L.Normalize();
            }
            float cos_theta = N * L;


            if (cos_theta < 0)
            {
                cos_theta = 0;
            }



            float   on_shadow = getShadow(P, light);
            Couleur c         = cos_theta * (light.color * px_color);

            return(c * on_shadow);
        }
Esempio n. 6
0
        private Couleur processLumiere(V3 rayon, PointColore point)
        {
            V3 normalPoint = point.GetNormale();
            //V3 directionOculaire = new V3(camera - point.GetLoc());
            //directionOculaire.Normalize();

            Couleur lumiereTotale = new Couleur(0, 0, 0);

            lumiereTotale += point.GetCouleur() * couleurAmbiance * intensiteAmbiance;
            foreach (Lumiere lampe in lampes)
            {
                if (!(lampe.isOccluded(point, objets)))
                {
                    V3 directionLampeNormale = new V3(lampe.GetDirection(point.GetLoc()));
                    directionLampeNormale.Normalize();

                    float cosAlpha      = normalPoint * directionLampeNormale;
                    float facteurDiffus = Math.Max(0, cosAlpha);
                    lumiereTotale += point.GetCouleur() * lampe.GetCouleur() * facteurDiffus * lampe.GetIntensite(point.GetLoc());

                    V3    reflet            = (2 * cosAlpha * normalPoint) - directionLampeNormale;
                    float produitSpeculaire = Math.Max(0, (reflet * (-rayon)) / (reflet.Norm() * rayon.Norm()));
                    float facteurSpeculaire = (float)Math.Pow(produitSpeculaire, puissanceSpeculaire);
                    lumiereTotale += lampe.GetCouleur() * lampe.GetIntensite(point.GetLoc()) * facteurSpeculaire;
                }
            }
            return(lumiereTotale);
        }
Esempio n. 7
0
 public Materiel(Couleur pcouleur, Texture ptextureBump, float pforceSpeculaire, float pforceBumping)
 {
     couleur         = pcouleur;
     textureBump     = ptextureBump;
     forceSpeculaire = pforceSpeculaire;
     forceBumping    = pforceBumping;
 }
Esempio n. 8
0
        /*
         * getPixelColor adds all lights and "shadows" at each point P of the image
         */
        public static Couleur getPixelColor(V3 P, Couleur c, V3 N, int object_index)
        {
            Couleur pixel_color = c;
            float   decay       = 1;

            pixel_color = Color_Ambient(c);

            foreach (Light_Source light in lights)
            {
                if (light.point_light)
                {
                    Elements.objects_on_screen[object_index].intersection_RayObject(light.position, P - light.position, out V3 P1, out V3 N1, out float t);
                    decay = (float)Math.PI / (float)(Math.Pow(t, 2));
                    if (decay > 1)
                    {
                        decay = 1;
                    }
                }
                pixel_color += decay * Color_Diffused(light, c, P, N);
                decay        = 1;
                if (Elements.objects_on_screen[object_index].is_spec)
                { // if the light creates a specular effect
                    pixel_color += Color_Specular(light, P, N, 200);
                }
            }
            pixel_color.check();

            return(pixel_color);
        }
Esempio n. 9
0
 public Sphere(float R, V3 center, Couleur c, int index)
 {
     this.R       = R;
     Center       = center;
     color        = c;
     object_index = index;
 }
Esempio n. 10
0
        public static void Go()
        {
            int screen_w = BitmapEcran.GetWidth(), screen_h = BitmapEcran.GetHeight();
            V3  camera_position = new V3(screen_w / 2, -400, screen_h / 2);


            /* Lights */

            // Light sources
            V3      key_light_dir   = new V3(-1, 1, -1);
            Couleur key_light_color = new Couleur(0.8f, 0.8f, 0.8f);
            //Lights.add_light(key_light_dir, key_light_color);

            V3      fill_light_dir   = new V3(1, 1, -1);
            Couleur fill_light_color = new Couleur(0.5f, 0.5f, 0.5f);
            //Lights.add_light(fill_light_dir, fill_light_color);

            V3      point_light_position = new V3(screen_w * 0.5f, Scene.max_y_position / 2, screen_h - 43);
            Couleur point_light_color    = new Couleur(1f, 1f, 1f);

            Lights.add_light(point_light_position, point_light_color, true);

            /* Objects */
            // list of all objects appearing on screen
            List <Object> objects_on_screen = new List <Object>();

            Scene.Room(ref objects_on_screen);
            Scene.Boxes(ref objects_on_screen);
            Scene.Mirror(ref objects_on_screen);
            Scene.Bed(ref objects_on_screen);
            Scene.Ball(ref objects_on_screen);
            Scene.Shelf(ref objects_on_screen);

            // Creates and initialize Z_buffer/ray casting activate + determines the camera position
            Elements.inicialize_Elements(camera_position, true, objects_on_screen);

            // Plot all objects on the screen with the ray casting method

            /*for (int i = 0; i < screen_w; i++)
             * {
             *  for(int j = 0; j < screen_h; j++)
             *  {
             *      Elements.RayCasting(new V3(i, 0, j), objects_on_screen);
             *  }
             * }*/

            V3      ray_direction;
            Couleur c;

            for (int i = 0; i < screen_w; i++)
            {
                for (int j = 0; j < screen_h; j++)
                {
                    ray_direction = new V3(i, 0, j) - Elements.camera_position;
                    ray_direction.Normalize();
                    c = Elements.RayTracer(Elements.camera_position, ray_direction, 0);
                    BitmapEcran.DrawPixel(i, j, c);
                }
            }
        }
Esempio n. 11
0
        /* Prints the pixel of point P on the screen:
         *
         *  receives the color of the pixel without the lights
         *  and the normal vector.
         *
         *  if P is set outside of the screen bounds, doesn't print anything
         *
         *  compare its position on the Z_Buffer
         *
         *  draws the pixel with its final color (adding the lights effects)
         */
        public int printPixel(V3 P, Couleur color)
        {
            int x, y, z;

            x = (int)P.x;
            y = (int)P.y;
            z = (int)P.z;


            if (x < 0 || x >= BitmapEcran.GetWidth() || z < 0 || z >= BitmapEcran.GetHeight())
            {
                return(-1);
            }
            if (Elements.raycasting) // using ray casting
            {
                BitmapEcran.DrawPixel(x, z, color);
            }
            else
            { //using Z-Buffer
                if (y < Elements.Z_Buffer[x, z])
                {
                    Elements.Z_Buffer[x, z] = y;
                    BitmapEcran.DrawPixel(x, z, color);
                }
            }

            return(0);
        }
Esempio n. 12
0
 public Lumiere()
 {
     type = 0; // directional light
     direction = new V3(0.0f,0.0f,0.0f);
     position = new V3(0.0f, 0.0f, 0.0f);
     C_lampe = new Couleur(1.0f, 1.0f, 1.0f);
 }
Esempio n. 13
0
        public Couleur RayCast(V3 PosCamera, V3 DirRayon, List <Objet3D> Objets)
        {
            Couleur c;
            float   t;
            float   tmin            = float.MaxValue;
            Objet3D ObjectAAfficher = null;

            foreach (Objet3D Objet in Objets)
            {
                //Console.WriteLine("OBJET: " + Objet.GetType().ToString());
                t = Objet.gettIntersect(PosCamera, DirRayon);
                //Console.WriteLine("   Distance " + t);
                if (t > 0 && t < tmin)
                {
                    ObjectAAfficher = Objet;
                    tmin            = t;
                }
            }
            //Console.WriteLine("");
            //Console.WriteLine("Distance min: " + tmin );

            if (ObjectAAfficher != null)
            {
                V3 PointIntersection = new V3(PosCamera + tmin * DirRayon);
                c = ObjectAAfficher.getCouleurRaycast(PointIntersection, this);
                return(c);
            }
            else
            {
                c = new Couleur(0.3f, 0.3f, 0.3f);
                return(c);
            }
        }
Esempio n. 14
0
 public Lumiere(int pType, V3 pDirection, V3 pPosition, Couleur pC_lampe)
 {
     this.type = pType;
     this.direction = pDirection;
     this.position = pPosition;
     this.C_lampe = pC_lampe;
 }
Esempio n. 15
0
        /*public override void Draw(Couleur C_ambiant, Lumiere L, V3 camera)
        {
            Couleur final_ambiant;
            Couleur C_lampe = L.getClampe();

            for (double u = 0; u < 2 * Math.PI; u += pas)
            {
                for (double v = -1 * Math.PI / 2; v < Math.PI / 2; v += pas)
                {
                    float dhdu, dhdv;
                    Couleur C_obj = T.LireCouleur((float)(u / (2 * Math.PI)), (float)((v + Math.PI / 2) / Math.PI));
                    final_ambiant = C_obj * C_ambiant;
                    double x = rayon * Math.Cos(v) * Math.Cos(u);
                    double y = rayon * Math.Cos(v) * Math.Sin(u);
                    double z = rayon * Math.Sin(v);
                    int x_ecran = (int)x + (int)origin.x;
                    int z_ecran = (int)z + (int)origin.z;
                    if (ZBuffer.test(y, x_ecran, z_ecran))
                    {
                        V3 N = new V3((float)x, (float)y, (float)z); //ne pas toucher

                        // BUMP MAP
                        if (T_bump != null)
                        {
                            V3 dmdu = new V3((float)(-rayon * Math.Cos(v) * Math.Sin(u)),
                                            (float)(rayon * Math.Cos(v) * Math.Cos(u)),
                                            0.0f);
                            V3 dmdv = new V3((float)(-rayon * Math.Sin(v) * Math.Cos(u)),
                                                (float)(-rayon * Math.Sin(v) * Math.Sin(u)),
                                                (float)(rayon * Math.Cos(v)));
                            this.T_bump.Bump((float)(u / (2 * Math.PI)), (float)((v + Math.PI / 2) / Math.PI), out dhdu, out dhdv);
                            N = N + bump_coeff * ((dmdu ^ (N * dhdv)) + ((N * dhdu) ^ dmdv));
                        }

                        // FIN BUMP MAP

                        V3 O = new V3((float)x, (float)y, (float)z);
                        O = camera - O;
                        //Couleur finalColor = computeLights(C_obj, C_ambiant, N, O, L, k);
                        //BitmapEcran.DrawPixel(x_ecran, z_ecran, finalColor);
                    }
                }
            }
        }*/
        public override Couleur DrawPoint(Couleur C_ambiant, List<Lampe> lampList, V3 camera, V3 R, bool[] occs)
        {
            V3 N = R - this.origin;
            N.Normalize();
            V3 O = camera - R;

            // TEXTURE
            float u, v;
            IMA.Invert_Coord_Spherique(R - this.origin, this.rayon, out u, out v);
            Couleur C_obj = T.LireCouleur((float)(u / (Math.PI)), (float)((v + IMA.PI2) / Math.PI));

            // BUMP MAP
            if (T_bump != null)
            {
                float dhdu, dhdv;
                V3 dmdu = new V3((float)(-rayon * Math.Cos(v) * Math.Sin(u)),
                                (float)(rayon * Math.Cos(v) * Math.Cos(u)),
                                0.0f);
                V3 dmdv = new V3((float)(-rayon * Math.Sin(v) * Math.Cos(u)),
                                    (float)(-rayon * Math.Sin(v) * Math.Sin(u)),
                                    (float)(rayon * Math.Cos(v)));
                this.T_bump.Bump((float)(u / (Math.PI)), (float)((v + IMA.PI2) / Math.PI), out dhdu, out dhdv);
                N = N + bump_coeff * ((dmdu ^ (N * dhdv)) + ((N * dhdu) ^ dmdv));
            }
            // FIN BUMP MAP

            Point I = new Point(C_obj, C_ambiant, N, O, this.k);
            Couleur finalColor = computeLights(I, lampList, occs);
            return finalColor;
        }
Esempio n. 16
0
 public Light_Source(V3 position, Couleur color, bool point_light)
 {
     ;
     this.position    = position;
     this.color       = color;
     this.point_light = true;
 }
Esempio n. 17
0
 public Scene(Couleur couleurAmbiante, float intensiteAmbiante, int puissanceSpeculaire)
 {
     this.couleurAmbiance     = couleurAmbiante;
     this.intensiteAmbiance   = intensiteAmbiante;
     this.lampes              = new List <Lumiere>();
     this.objets              = new List <Formes>();
     this.puissanceSpeculaire = puissanceSpeculaire;
 }
Esempio n. 18
0
 public Point()
 {
     this.C_obj = new Couleur (1.0f, 1.0f, 1.0f);
     this.C_ambiant = new Couleur(0.2f, 0.2f, 0.2f);
     this.N = new V3(0, -1, 0);
     this.O = new V3(0, 0, 0);
     this.k = 30;
 }
Esempio n. 19
0
        public void Draw(double x, double y, Couleur couleur)
        {
            int x_sceem  = (int)((x / (20.0 * this.ration)) * this.resolution_X + this.resolution_X / 2);
            int y_screem = (int)((y / 20.0) * this.resolution_Y + this.resolution_Y / 2);

            //Console.WriteLine("x:"+x_sceem+" y:"+y_screem);
            BitmapEcran.DrawPixel(x_sceem, y_screem, couleur);
        }
Esempio n. 20
0
 public Rectangle_2(V3 a, V3 b, V3 c, Couleur color, int index)
 {
     A            = a;
     B            = b;
     C            = c;
     this.color   = color;
     object_index = index;
 }
Esempio n. 21
0
 public Point(Couleur C_obj, Couleur C_ambiant, V3 N, V3 O, int k)
 {
     this.C_obj = C_obj;
     this.C_ambiant = C_ambiant;
     this.N = N;
     this.O = O;
     this.k = k;
 }
Esempio n. 22
0
        public static void DrawPixel(int x, int y, Couleur c)
        {
            int x_ecran = x;
            int y_ecran = Hauteur - y;

            if ((x_ecran >= 0) && (x_ecran < Largeur) && (y_ecran >= 0) && (y_ecran < Hauteur))
                if (Mode == ModeAff.SLOW_MODE) DrawSlowPixel(x_ecran, y_ecran, c);
                else DrawFastPixel(x_ecran, y_ecran, c);
        }
Esempio n. 23
0
 //dessine tous les objets de la scène
 public void DrawScene()
 {
     for (int x_ecran = 0; x_ecran <= BitmapEcran.GetWidth(); x_ecran++)
     {
         for (int y_ecran = 0; y_ecran <= BitmapEcran.GetHeight(); y_ecran++)
         {
             V3 PosPixScene = new V3(x_ecran, 0, y_ecran);
             V3 DirRayon    = PosPixScene - PosCamera;
             DirRayon.Normalize();
             Couleur C = RayCast(PosCamera, DirRayon, Objets);
             BitmapEcran.DrawPixel(x_ecran, y_ecran, C);
         }
     }
 }
Esempio n. 24
0
        public override Couleur drawPixel(V3 positionInScene)
        {
            V3 posionForSphere = positionInScene - this.getPosition();

            float v;
            float u;

            IMA.Invert_Coord_Spherique(posionForSphere, this.rayon, out u, out v);

            V3 vectSphere = new V3((float)(this.rayon * Math.Cos(v) * Math.Cos(u)),
                                   (float)(this.rayon * Math.Cos(v) * Math.Sin(u)),
                                   (float)(this.rayon * Math.Sin(v)));

            V3 copyvectSphere = new V3(vectSphere);

            copyvectSphere.Normalize();

            float dhsdu;
            float dhsdv;

            this.getBump(u / (Math.PI * 2), v / Math.PI + Math.PI / 2, out dhsdu, out dhsdv);


            V3 dmsdu = new V3((float)(-1 * Math.Cos(v) * Math.Sin(u)),
                              (float)(1 * Math.Cos(v) * Math.Cos(u)),
                              0.0f);

            V3 dmsdv = new V3((float)(-1 * Math.Sin(v) * Math.Cos(u)),
                              (float)(-1 * Math.Sin(v) * Math.Sin(u)),
                              (float)(1 * Math.Cos(v)));

            V3 dmpsdu = dmsdu + dhsdu * copyvectSphere;
            V3 dmpsdv = dmsdv + dhsdv * copyvectSphere;


            V3 Np = ((dmpsdu ^ dmpsdv) / (dmpsdu ^ dmpsdv).Norm());

            V3 vecteurBump = Np;

            V3 vect = this.getPosition() + vectSphere;

            Couleur vcolor = new Couleur();

            foreach (Light light in RenderSing.getCurrentRender().getLight())
            {
                vcolor += light.applyLight(this, vect, vecteurBump, this.getColor(u / (2 * Math.PI), v / Math.PI + Math.PI / 2));
            }

            return(vcolor);
        }
Esempio n. 25
0
        static void DrawFastPixel(int x, int y, Couleur c)
        {
            unsafe
            {
                byte RR, VV, BB;
                c.Check();
                c.To255(out RR, out VV, out BB);

                byte *ptr = (byte *)data.Scan0;
                ptr[(x * 3) + y * stride]     = BB;
                ptr[(x * 3) + y * stride + 1] = VV;
                ptr[(x * 3) + y * stride + 2] = RR;
            }
        }
Esempio n. 26
0
        static void DrawSlowPixel(int x, int y, Couleur c)
        {
            Color cc = c.Convertion();

            B.SetPixel(x, y, cc);

            Program.MyForm.PictureBoxInvalidate();
            nb_pix++;
            if (nb_pix > refresh_every)  // force l'affichage à l'écran tous les 1000pix
            {
                Program.MyForm.PictureBoxRefresh();
                nb_pix = 0;
            }
        }
Esempio n. 27
0
        private void outColor()
        {
            if (this.color_rb.Checked)
            {
                Couleur cl = new Couleur();

                cl.B = ((float)(this.colorDialog1.Color.B)) / 256.0f;
                cl.R = ((float)(this.colorDialog1.Color.R)) / 256.0f;
                cl.V = ((float)(this.colorDialog1.Color.G)) / 256.0f;
                this.formToModif.setCouleur(cl);
            }
            else
            {
                this.formToModif.setCouleur(new Couleur());
            }
        }
Esempio n. 28
0
        public Couleur getPixelColor(V3 P)
        {
            V3 N = getRectangleNormal(P);

            // get pixel's color
            getUV(P, out float u, out float v);

            Couleur c = getColor(u, v);

            if (bump_activate)
            {
                N = bumpN(N, u, v);
            }
            c = Lights.getPixelColor(P, c, N, object_index);
            return(c);
        }
Esempio n. 29
0
        public Couleur computeLights(Point I, List<Lampe> lampList, bool[] occs)
        {
            Couleur C_obj = I.C_obj;
            Couleur C_ambiant = I.C_ambiant;
            V3 N = I.N;
            V3 O = I.O;
            int k = I.k;

            float cosln;
            Couleur black = new Couleur(0f, 0f, 0f);
            Couleur final_ambiant;
            Couleur final_diff = black;
            Couleur final_spec = black;
            Couleur finalColor = black;
            final_ambiant = C_obj * C_ambiant;

            for(int i = 0; i < lampList.Count; i++)
            {
                Lumiere L = (Lumiere)lampList.ElementAt(i);
                if (occs[i] == false)
                {
                    /* DIFFUS */
                    N.Normalize();
                    L.getDirection().Normalize();
                    cosln = L.getDirection() * N;
                    cosln = cosln < 0 ? 0 : cosln;
                    final_diff += C_obj * L.getClampe() * cosln;
                    /* FIN DIFFUS */

                    /* SPECULAIRE */
                    V3 S = 2 * N * cosln - L.getDirection();
                    S.Normalize();
                    O.Normalize();
                    double cosso = S * O;
                    final_spec += L.getClampe() * (float)Math.Pow(cosso, k);
                    /* FIN SPECULAIRE */

                    finalColor += final_diff + final_spec;
                }
            }

            finalColor += final_ambiant;
            //Console.WriteLine("Couleur 1 " + finalColor.R + " " + finalColor.V + " " + finalColor.B);
            finalColor.check();
            //Console.WriteLine("Couleur 2 " + finalColor.R + " " + finalColor.V + " " + finalColor.B);
            return finalColor;
        }
Esempio n. 30
0
        public static void DrawPixel(int x, int y, Couleur c)
        {
            int x_ecran = x;
            int y_ecran = Hauteur - y;

            if ((x_ecran >= 0) && (x_ecran < Largeur) && (y_ecran >= 0) && (y_ecran < Hauteur))
            {
                if (Mode == ModeAff.SLOW_MODE)
                {
                    DrawSlowPixel(x_ecran, y_ecran, c);
                }
                else
                {
                    DrawFastPixel(x_ecran, y_ecran, c);
                }
            }
        }
Esempio n. 31
0
        public static Scene Scene2()
        {
            Couleur blanc      = new Couleur(1.0f, 1.0f, 1.0f);
            Scene   scene      = new Scene(blanc, 0.05f, 50);
            Couleur orangesque = new Couleur(1.0f, 0.78f, 0.59f);
            Couleur bleuesque  = new Couleur(0.78f, 0.59f, 1.0f);
            Couleur rouge      = new Couleur(1.0f, 0.0f, 0.0f);


            Quadrilatere sol = new Quadrilatere("wood.jpg", "bump1.jpg", new V3(500.0f, 0.0f, 0.0f), new V3(1000.0f, 500.0f, 0.0f), new V3(0.0f, 500.0f, 0.0f));

            scene.AddObjet(sol);

            Quadrilatere mur = new Quadrilatere(blanc, "bump.jpg", new V3(0.0f, 500.0f, 0.0f), new V3(500.0f, 1000.0f, 0.0f), new V3(0.0f, 500.0f, 1000.0f));

            scene.AddObjet(mur);

            Quadrilatere mur2 = new Quadrilatere(blanc, "bump.jpg", new V3(500.0f, 1000.0f, 0.0f), new V3(1000.0f, 500.0f, 0.0f), new V3(500.0f, 1000.0f, 1000.0f));

            scene.AddObjet(mur2);

            Lumiere key = new LampeDirectionelle(orangesque, 0.48f, new V3(1.0f, -1.0f, 1.0f));

            scene.AddLampe(key);
            Lumiere fill = new LampeDirectionelle(bleuesque, 0.27f, new V3(-1.0f, -1.0f, 1.0f));

            scene.AddLampe(fill);
            Lumiere back = new LampeDirectionelle(blanc, 0.2f, new V3(-1.0f, 1.0f, -1.0f));

            scene.AddLampe(back);

            Mesh mesh = new Mesh("teapot.obj", "gold.jpg");

            mesh.Rescale(100.0f);
            mesh.Translate(new V3(500.0f, 300.0f, 70.0f));



            foreach (Triangle t in mesh.GetPolygons())
            {
                scene.AddObjet(t);
            }

            return(scene);
        }
Esempio n. 32
0
 /// /////////////////   public methods ///////////////////////
 public static void RefreshScreen(Couleur c)
 {
     if (Program.MyForm.Checked())
     {
         Mode = ModeAff.SLOW_MODE;
         Graphics g = Graphics.FromImage(B);
         Color cc = c.Convertion();
         g.Clear(cc);
     }
     else
     {
         Mode = ModeAff.FULL_SPEED;
         data = B.LockBits(new Rectangle(0, 0, B.Width, B.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
         stride = data.Stride;
         for (int x = 0; x < Largeur; x++)
             for (int y = 0; y < Hauteur; y++)
                 DrawFastPixel(x, y, c);
     }
 }
Esempio n. 33
0
        //récupère la couleur du pixel en prenant compte des lumières de la scène
        public Couleur CouleurEclairee(V3 position, V3 normal, Couleur couleurDeBase, Materiel mat, Objet3D ObjetToDraw)
        {
            //initialisation de la couleur
            Couleur couleurFinale = new Couleur(0, 0, 0);


            //---------------------------Lumiere AMBIANTE----------------------------------//
            if (LumAmb != null)
            {
                couleurFinale += new Couleur(couleurDeBase * LumAmb.Couleur);
            }

            if (Lumieres.Count > 0)
            {
                foreach (Lumiere l in Lumieres)
                {
                    V3 DirectionLumiere = l.getDirection(position);
                    DirectionLumiere.Normalize();



                    if (!CheckIfObjectBetweenLightSource(DirectionLumiere, position, ObjetToDraw))
                    {
                        //Console.WriteLine("Je dessine la lumière");
                        //-------------------------------Lumiere DIFFUSE------------------------------------//
                        float diff = Math.Max((DirectionLumiere * normal), 0);
                        couleurFinale += new Couleur((couleurDeBase * l.getCouleur()) * diff);

                        //--------------------------------Reflet SPECULAIRE--------------------------------//
                        float forceSeculaire            = mat.GetForceSpeculaire();
                        V3    positionOeil              = new V3(BitmapEcran.GetHeight() / 2, -3000, BitmapEcran.GetWidth() / 2);
                        V3    directionDuRayonReflechis = new V3(2 * normal - DirectionLumiere);
                        directionDuRayonReflechis.Normalize();
                        V3 directionObservateur = new V3(positionOeil - position);
                        directionObservateur.Normalize();

                        couleurFinale += new Couleur(l.getCouleur() * (float)Math.Pow((directionDuRayonReflechis * directionObservateur), forceSeculaire));
                    }
                }
            }
            return(couleurFinale);
        }
Esempio n. 34
0
        public void DessineRaycast()
        {
            V3 camera = new V3((float)BitmapEcran.GetWidth() / 2, (float)BitmapEcran.GetWidth() * -1.5f, (float)BitmapEcran.GetHeight() / 2);

            int xmax = BitmapEcran.GetWidth();
            int ymax = BitmapEcran.GetHeight();

            Couleur[,] colorbuffer = new Couleur[xmax, ymax];
            for (int x_ecran = 0; x_ecran < BitmapEcran.GetWidth(); x_ecran++)
            {
                for (int y_ecran = 0; y_ecran < BitmapEcran.GetHeight(); y_ecran++)
                {
                    V3 pixel = new V3((float)x_ecran, 0, (float)y_ecran);
                    V3 rayon = pixel - camera;
                    rayon.Normalize();
                    colorbuffer[x_ecran, y_ecran] = Raycast(camera, rayon);

                    BitmapEcran.DrawPixel(x_ecran, y_ecran, colorbuffer[x_ecran, y_ecran]);
                }
            }
        }
Esempio n. 35
0
 private void inTextureOrColor()
 {
     if (this.formToModif.getTexture() == null)
     {
         this.color_rb.Checked = true;
         Couleur cl  = this.formToModif.getCouleur();
         Color   cl2 = Color.FromArgb(
             (int)(cl.R * 256),
             (int)(cl.V * 256),
             (int)(cl.B * 256)
             );
         this.colorDialog1.Color = cl2;
         this.button3.BackColor  = cl2;
     }
     else
     {
         this.image_rb.Checked         = true;
         this.openFileDialog1.FileName = this.formToModif.getTexture().path;
         this.button4.Image            = new Bitmap(this.openFileDialog1.FileName);
     }
 }
Esempio n. 36
0
        override public Couleur getCouleurRaycast(V3 PointIntersection, Scene scene)
        {
            //Console.WriteLine("Sphere Pt Intersect: " + PointIntersection.x + " " + PointIntersection.y + " " + PointIntersection.z);

            V3 pixel_position = PointIntersection - center;

            //Console.WriteLine("                      " + PointIntersection.x + " " + PointIntersection.y + " " + PointIntersection.z);

            IMA.Invert_Coord_Spherique(pixel_position, rayon, out float u, out float v);
            //Console.WriteLine("        u: " + u+" ,v " + v);



            //------------------------------BUMP MAPING---------------------------------------//
            float pi         = (float)Math.PI;
            float uNormalise = u / (2 * pi);
            float vNormalise = v / pi + pi;

            Partial_derivative(u, v, out V3 dMdu, out V3 dMdv);
            materiel.GetTextureBump().Bump(uNormalise, vNormalise, out float dhdu, out float dhdv);
            V3 normal = getNormal(u, v) + materiel.GetForceBumping() * (dhdu * (getNormal(u, v) ^ dMdv) + dhdv * (getNormal(u, v) ^ dMdu));

            //------------------------------TEXTURE---------------------------------------//
            Couleur couleur = new Couleur();

            if (materiel.GetTexture() != null)
            {
                couleur = materiel.GetTexture().LireCouleur(uNormalise, vNormalise);
            }
            else
            {
                couleur = materiel.GetCouleur();
            }

            //------------------------------LUMIERE---------------------------------------//
            couleur = scene.CouleurEclairee(PointIntersection, normal, couleur, materiel, this);

            return(couleur);
        }
Esempio n. 37
0
        /// /////////////////   public methods ///////////////////////

        static public void RefreshScreen(Couleur c)
        {
            if (Program.MyForm.Checked())
            {
                Mode = ModeAff.SLOW_MODE;
                Graphics g  = Graphics.FromImage(B);
                Color    cc = c.Convertion();
                g.Clear(cc);
            }
            else
            {
                Mode   = ModeAff.FULL_SPEED;
                data   = B.LockBits(new System.Drawing.Rectangle(0, 0, B.Width, B.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
                stride = data.Stride;
                for (int x = 0; x < Largeur; x++)
                {
                    for (int y = 0; y < Hauteur; y++)
                    {
                        DrawFastPixel(x, y, c);
                    }
                }
            }
        }
Esempio n. 38
0
        override public Couleur getCouleurRaycast(V3 PointIntersection, Scene scene)
        {
            float u = ((PointIntersection - A) * (B - A)) / ((B - A) * (B - A));
            float v = ((PointIntersection - A) * (C - A)) / ((C - A) * (C - A));


            //V3 pixel_position = getPixel3DPosition(u, v);
            V3 pixel_position = PointIntersection;


            //------------------------------BUMP MAPING---------------------------------------//
            float uNormalise = u;
            float vNormalise = v;

            Partial_derivative(u, v, out V3 dMdu, out V3 dMdv);
            materiel.GetTextureBump().Bump(u, v, out float dhdu, out float dhdv);
            V3 normal = getNormal() + materiel.GetForceBumping() * (dhdu * (getNormal() ^ dMdv) + dhdv * (getNormal() ^ dMdu));

            //V3 normal = getNormal(u,v);
            //------------------------------TEXTURE---------------------------------------//
            Couleur couleur = new Couleur();

            if (materiel.GetTexture() != null)
            {
                couleur = materiel.GetTexture().LireCouleur(uNormalise, vNormalise);
            }
            else
            {
                couleur = materiel.GetCouleur();
            }

            //------------------------------LUMIERE---------------------------------------//
            couleur = scene.CouleurEclairee(pixel_position, normal, couleur, materiel, this);
            //System.Console.WriteLine(couleur.R+" "+couleur.V+" "+couleur.B);
            //------------------------------DESSIN FINAL---------------------------------------//
            return(couleur);
        }
Esempio n. 39
0
 public LumiereAmbiante(Couleur pCouleurLumiereAmbiante)
 {
     Couleur = pCouleurLumiereAmbiante;
 }
Esempio n. 40
0
        public static void Go()
        {
            int width = BitmapEcran.GetWidth();
            int height = BitmapEcran.GetHeight()+1;

            Couleur C_ambiant = new Couleur(0.2f, 0.2f, 0.2f);
            V3 camera = new V3(width / 2, -1000, height / 2);

            // LAMPES
            List<Lampe> lampList = new List<Lampe>();
            lampList.Add(new Lumiere(0, new V3(1f, -1f, 1f), new V3(0f, 0f, 0f), new Couleur(0.4f, 0.4f, 0.4f)));
            lampList.Add(new Lumiere(0, new V3(-1f, -1f, 1f), new V3(0f, 0f, 0f), new Couleur(0.4f, 0.4f, 0.4f)));

            // TEXTURES
            Texture T_carreau = new Texture("carreau.jpg");
            Texture T_lead = new Texture("lead.jpg");
            Texture T_Aymeric = new Texture("aymeric.jpg");
            Texture T_stone = new Texture("stone2.jpg");
            Texture T_fibre = new Texture("fibre.jpg");
            Texture T_brick = new Texture("brick01.jpg");
            Texture T_gold = new Texture("gold.jpg");
            // BUMP TEXTURES
            Texture T_bump = new Texture("bump38.jpg");
            Texture T_leadbump = new Texture("lead_bump.jpg");

            // OBJETS
            List<Objet3D> objList = new List<Objet3D>();

            //SPHERES
            objList.Add(new Sphere(new V3(width / 2, 500, height - 50), 150, T_carreau, T_bump, 0.008f));
            objList.Add(new Sphere(new V3(50, 500, height / 2), 150, T_lead, T_leadbump, 0.01f));
            objList.Add(new Sphere(new V3(175, 300, height / 2 + 75), 50, T_gold, T_bump, 0.1f));
            //RECTS
            //fond
            objList.Add(new Rect(new V3(50, 1000, 50), new V3(width - 100, 0, 0), new V3(0, 0, height - 100), T_brick, null));
            //bas
            objList.Add(new Rect(new V3(50, 0, 50), new V3(width - 100, 0, 0), new V3(0, 1000, 0), T_stone, null));
            //haut
            //objList.Add(new Rect(new V3(width-50, 0, height-50), new V3(-(width-100), 0, 0), new V3(0, 1000, 0), T_fibre, null));
            //gauche
            objList.Add(new Rect(new V3(50, 0, 50), new V3(0, 1000, 0), new V3(0, 0, height - 100), T_brick, null));
            //droite
            objList.Add(new Rect(new V3(width - 50, 1000, 50), new V3(0, -1000, 0), new V3(0, 0, height - 100), T_brick, null));
            //milieu
            objList.Add(new Rect(new V3(width / 2 + 100, 750, 50), new V3(0, -500, 0), new V3(0, 0, height / 3), T_brick, null));

            // RAY CASTING

            V3 Rd, R;
            float t, tnew;
            bool[] occs = new bool[lampList.Count];

            //parcourir les pixels en x
            for (int pxx = 0; pxx < width; pxx++) {
                //parcourir les pixels en z
                for (int pxz = 0; pxz < height; pxz++) {
                    t = float.MaxValue;
                    // pour chaque pixel générer un rayon Rd
                    Rd = new V3(pxx - camera.x, -camera.y, pxz - camera.z);
                    Rd.Normalize();
                    // parcourir la liste des objets
                    foreach (Objet3D obj in objList) {
                        // appeler l'intersection et récupérer le point
                        tnew = obj.getIntersect(Rd, camera);
                        if (tnew != -1)
                        {
                            if (tnew <= t)
                            {
                                t = tnew;
                                // R est le point d'intersection de Rd et de l'objet
                                R = camera + t * Rd;
                                occs = obj.occultation(R, objList, lampList);
                                //Console.WriteLine(occs[0]+" "+occs[1]);
                                Couleur finalColor = obj.DrawPoint(C_ambiant, lampList, camera, R, occs);
                                BitmapEcran.DrawPixel(pxx, pxz, finalColor);
                            }
                        }

                    }
                }
            }

            //s1.Draw(C_ambiant, L, camera);
            //s2.Draw(C_ambiant, L, camera);

            //r1.Draw(C_ambiant, L, camera);
            //r2.Draw(C_ambiant, L, camera);
        }
Esempio n. 41
0
        static void DrawFastPixel(int x, int y, Couleur c)
        {
            unsafe
            {
                byte RR, VV, BB;
                c.check();
                c.To255(out RR, out  VV, out  BB);

                byte* ptr = (byte*)data.Scan0;
                ptr[(x * 3) + y * stride    ] = BB;
                ptr[(x * 3) + y * stride + 1] = VV;
                ptr[(x * 3) + y * stride + 2] = RR;
            }
        }
Esempio n. 42
0
 public abstract Couleur DrawPoint(Couleur C_ambiant, List<Lampe> lampList, V3 camera, V3 R, bool[] occs);
Esempio n. 43
0
        static void DrawSlowPixel(int x, int y, Couleur c)
        {
            Color cc = c.Convertion();
            B.SetPixel(x, y, cc);

            Program.MyForm.PictureBoxInvalidate();
            nb_pix++;
            if (nb_pix > refresh_every)  // force l'affichage à l'écran tous les 1000pix
            {
               Program.MyForm.PictureBoxRefresh();
               nb_pix = 0;
            }
        }
Esempio n. 44
0
 public Couleur(Couleur c)
 {
     this.R = c.R;
     this.V = c.V;
     this.B = c.B;
 }
Esempio n. 45
0
 public static void Transpose(ref Couleur cc, System.Drawing.Color c)
 {
     cc.R = (float) (c.R / 255.0);
     cc.V = (float) (c.G / 255.0);
     cc.B = (float) (c.B / 255.0);
 }
Esempio n. 46
0
 public void setClampe(Couleur pClampe)
 {
     this.C_lampe = pClampe;
 }