コード例 #1
0
        /// <summary>
        /// Lambertian shading
        /// </summary>
        /// <param name="p"></param>
        /// <param name="l"></param>
        /// <param name="ray"></param>
        /// <returns></returns>
        public Vector3D Phong(Vector3D p, Light l, Ray ray)
        {
            // Object color
            Vector3D k = GetCheckerBoardColor(p);

            // normal of object
            Vector3D n = Normal(p);

            // Diffuse shading
            Vector3D diffuse = k * Math.Max(0, Vector3D.DotProduct(l.Position, n));

            Vector3D v = (ray.E - p);

            v.Normalize();
            double p_phong = 128;

            Vector3D h = v + l.Position;

            h.Normalize();

            // Reflection vector
            Vector3D r = 2 * (Vector3D.DotProduct(n, v)) * n - v;

            // Reflective color
            Ray      reflectionRay = new Ray(p, p - r);
            Vector3D pPrime        = reflectionRay.GetPoint3D(.005);

            reflectionRay = new Raycast.Ray(pPrime, pPrime - r);
            Vector3D lm = ColorOfReflection(new Ray(p, p - r), l);

            Vector3D ls = k * Math.Pow(Math.Max(0, Vector3D.DotProduct(h, n)), p_phong);

            return(diffuse + ls + lm);
        }
コード例 #2
0
ファイル: Sphere.cs プロジェクト: S4NT14G0/RenderEngine
        public Vector3D Phong(Vector3D p, Light l, Ray ray)
        {
            double p_phong = 128;

            Vector3D k = AlbedoColor;

            if (image != null)
            {
                k       = TextureColorAtPoint(p);
                p_phong = 512;
            }

            // normal of object
            Vector3D n = Normal(p);

            // Diffuse shading
            Vector3D diffuse = k * Math.Max(0, Vector3D.DotProduct(l.Position, n));

            if (image != null)
            {
                return(diffuse);
            }

            Vector3D v = (ray.E - p);

            v.Normalize();

            // Direction of the bounced light
            Vector3D h = v + l.Position;

            h.Normalize();

            // Reflection vector
            Vector3D r = 2 * (Vector3D.DotProduct(n, v)) * n - v;

            // Reflective color
            Ray      reflectionRay = new Ray(p, p - r);
            Vector3D pPrime        = reflectionRay.GetPoint3D(.005);

            reflectionRay = new Raycast.Ray(pPrime, pPrime - r);
            Vector3D lm = ColorOfReflection(new Ray(p, p - r), l);

            Vector3D ls = k * Math.Pow(Math.Max(0, Vector3D.DotProduct(h, n)), p_phong);

            return(diffuse + ls + lm);
        }