Example #1
0
        public override Color3 colorNormal(Color3 existing, Ray r, Hit h, Shape s, Light bulb)
        {
            switch (shader)
             {
            case ProcShading.Circle:
               return mapCircle(h);

            case ProcShading.Texture:
               return mapTexture(h);

            default:
               return mapSquare(h);
             }
        }
Example #2
0
        public override Color3 colorShadow(Color3 existing, Hit h, double factor)
        {
            switch (shader)
             {
            case ProcShading.Circle:
               return Color3.shade(mapCircle(h), factor);

            case ProcShading.Texture:
               return Color3.shade(mapTexture(h), factor);

            default:
               return Color3.shade(mapSquare(h), factor);
             }
        }
Example #3
0
        public static Color3 specular(Ray r, Hit h, Shape s, Light bulb)
        {
            Color3  specular = Black;
            Vector3 normal   = s.calcNormal(h);

            Vector3 lightDir    = Point3.vectorize(bulb.Location, h.intersect);
            Vector3 refDir      = lightDir - (2 * (Vector3.DotProduct(lightDir, normal) / Math.Pow(normal.Abs(), 2)) * normal);
            double  specularDot = Vector3.DotProduct(r.direction, refDir);

            if (specularDot >= 0)
            {
                specular = (bulb.Color * s.Material.Specular) * Math.Pow(specularDot, s.Material.Ke);
            }

            return(specular);
        }
Example #4
0
        public override bool Equals(object obj)
        {
            if (obj is Color3)
            {
                Color3 other = (Color3)obj;

                if (other.R == this.R && other.B == this.B && other.G == this.G)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Example #5
0
 public override Color3 colorShadow(Color3 existing, Hit h, double factor)
 {
     return Color3.shade(existing, factor);
 }
Example #6
0
 public override Color3 colorNormal(Color3 existing, Ray r, Hit h, Shape s, Light bulb)
 {
     return Color3.Black;
 }
Example #7
0
 public abstract Color3 colorShadow(Color3 existing, Hit h, double factor);
Example #8
0
 public Light(Point3 location, Color3 color)
 {
     this._Location = location;
     this._Color    = color;
 }
Example #9
0
 public Light(Point3 location, Color3 color)
 {
     this._Location = location;
      this._Color = color;
 }
Example #10
0
 public static Color3 floor(Color3 existing, Hit h, Plane p)
 {
     return Color3.Green;
 }
Example #11
0
        public static Color3 operator +(Color3 c1, Color3 c2)
        {
            double r = ((c1.R / MAX) + (c2.R / MAX));
             double g = ((c1.G / MAX) + (c2.G / MAX));
             double b = ((c1.B / MAX) + (c2.B / MAX));

             Color3 c = new Color3(r, b, g);
             c.ScaleAndCheck();

             return c;
        }
Example #12
0
 public override Color3 colorShadow(Color3 existing, Hit h, double factor)
 {
     return(Color3.shade(existing, factor));
 }
Example #13
0
 public override Color3 colorNormal(Color3 existing, Ray r, Hit h, Shape s, Light bulb)
 {
     return(Color3.Black);
 }
Example #14
0
 public abstract Color3 colorShadow(Color3 existing, Hit h, double factor);
Example #15
0
 public abstract Color3 colorNormal(Color3 existing, Ray r, Hit h, Shape s, Light bulb);
Example #16
0
        public static Color3 shade(Color3 existing, double factor)
        {
            Color3 shade = Black;

             shade.R = existing.R / factor;
             shade.G = existing.G / factor;
             shade.B = existing.B / factor;

             return shade;
        }
Example #17
0
        public static Color3 operator *(Color3 c1, double coef)
        {
            double r = ((c1.R / MAX) * (coef));
             double g = ((c1.G / MAX) * (coef));
             double b = ((c1.B / MAX) * (coef));

             Color3 c = new Color3(r, b, g);
             c.ScaleAndCheck();

             return c;
        }
Example #18
0
 public Pixel()
 {
     rect = new System.Drawing.Rectangle(0, 0, 1, 1);
      color = Color3.Black;
 }
Example #19
0
        private Color3 mapTexture(Hit h)
        {
            Color3 shadeColor = Color3.Black;

             int texWidth = TextureLoader.Texture.Width;
             int texHeight = TextureLoader.Texture.Height;

             int row = (int)Math.Round(h.intersect.x / texWidth);
             int col = (int)Math.Round(h.intersect.z / texHeight);

             int startX = row * texWidth;
             int startY = col * texHeight;

             int texX = (int) Math.Round(Math.Abs(h.intersect.x - startX));
             int texY = (int) Math.Round(Math.Abs(h.intersect.z - startY));

             if (texX < TextureLoader.Texture.Width && texY < TextureLoader.Texture.Height)
             {
            System.Drawing.Color texColor = TextureLoader.Texture.GetPixel(texX, texY);
            shadeColor = new Color3(texColor.R, texColor.G, texColor.B);
             }

             return shadeColor;
        }
Example #20
0
 public static Color3 floor(Color3 existing, Hit h, Plane p)
 {
     return(Color3.Green);
 }
Example #21
0
 public abstract Color3 colorNormal(Color3 existing, Ray r, Hit h, Shape s, Light bulb);
Example #22
0
        private static Color3 fireRay(Ray incomingRay, int depth, Shape fromShape)
        {
            double closest = Constants.FAR_AWAY;
            Color3 retColor = Constants.BGCOLOR;
            int    whichObject = 0, hitObject = 0;
            Hit    finalHit = new Hit();

            foreach (Shape s in layout.Shapes)
            {
                Hit rayHit = s.intersect(incomingRay);
                whichObject++;

                if (rayHit.intersect.z == Constants.FAR_AWAY)
                {
                    continue;
                }

                double dist = Point3.distance(layout.Cam.Eye, rayHit.intersect);

                if (dist < closest && !s.Equals(fromShape))
                {
                    closest   = dist;
                    hitObject = whichObject;
                    finalHit  = rayHit;
                }
            }

            if (hitObject <= 0)
            {
                return(Constants.BGCOLOR);
            }

            Shape hitShape = layout.Shapes[hitObject - 1];

            retColor = Color3.ambient(hitShape);

            // phongphongphongphongphongphongphongphongphongphongphongphongphongphongphongphongphongphongphongphongphongphongphong
            Color3 diffuseColor = Color3.Black, specularColor = Color3.Black;

            foreach (Light bulb in layout.Lights)
            {
                if (spawnShadow(bulb, finalHit, hitShape, fromShape))
                {
                    retColor = hitShape.colorShadow(retColor, finalHit, layout.Lights.Count * 3);
                }
                else
                {
                    if (hitShape is Plane)
                    {
                        retColor = hitShape.colorNormal(retColor, incomingRay, finalHit, hitShape, bulb);
                    }
                    else
                    {
                        diffuseColor  += Color3.diffuse(finalHit, hitShape, bulb);
                        specularColor += Color3.specular(incomingRay, finalHit, hitShape, bulb);
                    }
                }
            }

            if (hitShape is Sphere)
            {
                retColor += diffuseColor * hitShape.Material.Kd;
                retColor += specularColor * hitShape.Material.Ks;
            }

            if (depth < Constants.MAX_DEPTH)
            {
                Color3 reflectColor = Color3.Black;

                if (hitShape.Material.Kr > 0)
                {
                    Ray reflectRay = new Ray();
                    reflectRay.start = finalHit.intersect;

                    Vector3 normalVec = hitShape.calcNormal(finalHit);

                    double c = -Vector3.DotProduct(normalVec, incomingRay.direction);
                    reflectRay.direction = -(incomingRay.direction + (2 * normalVec * c));
                    reflectRay.direction.Normalize();
                    reflectColor = fireRay(reflectRay, depth + 1, hitShape);

                    retColor += reflectColor * hitShape.Material.Kr;
                }

                if (hitShape.Material.Kt > 0)
                {
                    Ray     transRay = new Ray();
                    double  indexRefract;
                    Vector3 normalVec = Vector3.FaceForward(hitShape.calcNormal(finalHit), -incomingRay.direction);

                    if (Vector3.DotProduct(-incomingRay.direction, hitShape.calcNormal(finalHit)) < 0)
                    {
                        indexRefract = Constants.REFRACTION_INDEX_SPHERE / Constants.REFRACTION_INDEX_AIR;
                    }
                    else
                    {
                        indexRefract = Constants.REFRACTION_INDEX_AIR / Constants.REFRACTION_INDEX_SPHERE;
                    }

                    double discrim = 1 + (Math.Pow(indexRefract, 2) * (Math.Pow(Vector3.DotProduct(-incomingRay.direction, normalVec), 2) - 1));

                    // Total internal reflection!
                    if (discrim < 0)
                    {
                        retColor += reflectColor * hitShape.Material.Kt;
                    }
                    else
                    {
                        discrim = indexRefract * Vector3.DotProduct(-incomingRay.direction, normalVec) - Math.Sqrt(discrim);

                        transRay.direction = (indexRefract * incomingRay.direction) + (discrim * normalVec);
                        transRay.start     = finalHit.intersect;

                        Color3 transColor = fireRay(transRay, depth + 1, hitShape);
                        retColor += transColor * hitShape.Material.Kt;
                    }
                }
            }

            return(retColor);
        }
Example #23
0
 public Pixel()
 {
     rect  = new System.Drawing.Rectangle(0, 0, 1, 1);
     color = Color3.Black;
 }