示例#1
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);
        }
示例#2
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);
        }
示例#3
0
        public static float getShadow(V3 P, Light_Source light)
        {
            float t, t_max = 200;
            V3    direction = -light.direction;

            if (light.point_light)
            {
                direction = light.position - P;
                direction.Normalize();
            }

            foreach (Object obj in Elements.objects_on_screen)
            {
                obj.intersection_RayObject(P, direction, out V3 P1, out V3 N1, out t);
                if (t > MIN_DISTANCE && t < t_max)
                {
                    if (-direction * N1 > 0.1f)
                    {
                        return(0.3f);
                    }
                }
            }
            return(1);
        }
示例#4
0
        public static void add_light(V3 position, Couleur c, bool point)
        {
            Light_Source l = new Light_Source(position, c, true);

            lights.Add(l);
        }
示例#5
0
        public static void add_light(V3 direction, Couleur c)
        {
            Light_Source l = new Light_Source(direction, c);

            lights.Add(l);
        }