Ejemplo n.º 1
0
        public override PointColore GetCouleurIntersect(V3 camera, V3 directionOculaire, float intersection)
        {
            V3 point = camera + (intersection * directionOculaire);

            IMA.Invert_Coord_Spherique(point - this.position, this.rayon, out float u, out float v);

            float offsetU = u / (float)(Math.PI * 2);
            float offsetV = (v + (float)(Math.PI / 2)) / (float)(Math.PI);

            V3    dMdu = new V3((float)(-Math.Sin(u) * Math.Cos(v) * rayon), (float)(rayon * (float)(Math.Cos(u) * Math.Cos(v))), 0);
            V3    dMdv = new V3((float)(-Math.Sin(v) * Math.Cos(v) * rayon), (float)(rayon * (float)(-Math.Sin(u) * Math.Sin(v))), rayon * (float)Math.Cos(v));
            float dhdu, dhdv;

            BumpMap.Bump(offsetU, offsetV, out dhdu, out dhdv);

            V3 normalPoint = new V3(point - position);

            normalPoint.Normalize();

            V3 T2          = dMdu ^ (dhdv * normalPoint);
            V3 T3          = (dhdu * normalPoint) ^ dMdv;
            V3 normaleBump = normalPoint + 0.008f * (T2 + T3);

            normaleBump.Normalize();
            return(new PointColore(point, normaleBump, texture.LireCouleur(offsetU, offsetV), this));
        }
Ejemplo n.º 2
0
        public V3 getPixelSphereNormal(V3 P)
        {
            V3 N = P - Center;

            IMA.Invert_Coord_Spherique(N, R, out float u, out float v);
            N.Normalize();
            // calculate the new normal vector for the bump mapping effect
            if (bump_activate)
            {
                N = bumpN(N, u, v);
            }
            return(N);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
 static public void Invert_Coord_Spherique(V3 P, float r, out float u, out float v)
 {
     P = P / r;
     if (P.z >= 1)
     {
         u = (float)IMA.PI2; v = 0;
     }
     else if (P.z <= -1)
     {
         u = (float)-IMA.PI2; v = 0;
     }
     else
     {
         v = (float)Math.Asin(P.z);
         float t = (float)(P.x / IMA.Cosf(v));
         if (t <= -1)
         {
             u = (float)IMA.PI;
         }
         else if (t >= 1)
         {
             u = 0;
         }
         else
         {
             if (P.y < 0)
             {
                 u = (float)(2 * IMA.PI - Math.Acos(t));
             }
             else
             {
                 u = (float)Math.Acos(t);
             }
         }
     }
 }
Ejemplo n.º 6
0
 public float Norm()             // retourne la norme du vecteur
 {
     return((float)IMA.Sqrtf(x * x + y * y + z * z));
 }