예제 #1
0
        public Color_dbl Blend(Color_dbl other, double weight)
        {
            Color_dbl result = new Color_dbl(this);

            result = this * (1 - weight) + other * weight;
            return(result);
        }
예제 #2
0
        public Light(Vector pos, Color_dbl color)
        {
            Position = pos;
            Color    = color;

            strength = 10;
        }
예제 #3
0
        static public Color_dbl operator /(Color_dbl col, double f)
        {
            Color_dbl result = new Color_dbl();

            result.R = col.R / f;
            result.G = col.G / f;
            result.B = col.B / f;

            return(result);
        }
예제 #4
0
        static public Color_dbl operator *(Color_dbl c1, Color_dbl c2)
        {
            Color_dbl result = new Color_dbl();

            result.R = c1.R * c2.R;
            result.G = c1.G * c2.G;
            result.B = c1.B * c2.B;

            return(result);
        }
예제 #5
0
        private Color_dbl RayTrace(IntersectionInfo info, Ray ray, Scene scene, int depth)
        {
            Color_dbl color = info.Color * scene.ambience;

            foreach (Light l in scene.lights)
            {
                Vector v = (l.Position - info.pos).normalize(); // diffuse
                double L = v.dot(info.normal);
                if (L > 0.0f)
                {
                    color += info.Color * l.Color * L;
                }

                if (depth < 5)
                {
                    //shadows
                    IntersectionInfo shadow_info = new IntersectionInfo();
                    Ray toLight = new Ray(info.pos, v);
                    shadow_info = TestIntersection(toLight, scene, info.hit_object);
                    if (shadow_info.is_hit && shadow_info.hit_object != info.hit_object)
                    {
                        color *= 0.5;
                    }

                    //reflections
                    if (info.hit_object.Material.Reflection > 0)
                    {
                        Ray reflectionray         = new Ray(info.pos, ray.Direction + info.normal * 2 * -info.normal.dot(ray.Direction));
                        IntersectionInfo ref_info = TestIntersection(reflectionray, scene, info.hit_object);
                        if (ref_info.is_hit && ref_info.dist > 0)
                        {
                            ref_info.Color = RayTrace(ref_info, reflectionray, scene, depth + 1);
                        }
                        else
                        {
                            ref_info.Color = scene.backColor;
                        }
                        color = color.Blend(ref_info.Color, info.hit_object.Material.Reflection);
                    }
                }
            }
            color.Correct();
            return(color);
        }
예제 #6
0
        public void SetTest()
        {
            //eye_pos = new Vector(0, 0, -15);
            //eye_dir = new Vector(-0.2,0,5);

            eye_pos = new Vector(0, 0, -15);
            eye_dir = new Vector(-0.2, 0, 5);

            backColor = new Color_dbl(0.5, 0.5, 0.5);
            ambience  = 0.4;

            lights.Add(new Light(new Vector(5, 10, -1), new Color_dbl(0.8, 0.0, 0.0)));
            lights.Add(new Light(new Vector(-3, 5, -10), new Color_dbl(0.8, 0.8, 0.8)));

            Vector   t = new Vector(-0.5, 0.5, -2);
            Material m = new Material(new Color_dbl(1.0, 0.85, 0.85));   // black mirror

            m.Reflection = 0.2;
            Sphere s = new Sphere(t, 1.2, m);

            objects.Add(s);

            Vector   t1 = new Vector(-2, 2, -4);
            Material m1 = new Material(new Color_dbl(0.1, 0.2, 0.2)); // pink glossy

            m1.Reflection = 0.7;
            Sphere s1 = new Sphere(t1, 0.5, m1);

            objects.Add(s1);

            Vector   t2 = new Vector(2, 0, -2);
            Material m2 = new Material(new Color_dbl(0.8, 0.9, 0.8));   // black glossy

            m2.Reflection = 0.1;
            Sphere s2 = new Sphere(t2, 0.7, m2);

            objects.Add(s2);

            Plane p = new Plane(new Vector(-0.1, 0.9, -0.5).normalize(), 0, new Material(new Color_dbl(0.4, 1.0, 1.0)));

            p.Material.Reflection = 0.5;
            objects.Add(p);
        }
예제 #7
0
 public Color_dbl(Color_dbl other)
 {
     R = other.R;
     G = other.G;
     B = other.B;
 }
예제 #8
0
 public Material(int r, int g, int b)
 {
     color = new Color_dbl(r, g, b);
 }
예제 #9
0
 public Material(Color_dbl c)
 {
     color = c;
 }