/// <inheritdoc />
        public override double GenerateRayDifferential(CameraSample sample, out RayDifferential ray)
        {
            //ProfilePhase prof(Prof::GenerateCameraRay);
            // Compute raster and camera sample positions
            Point3D  pFilm   = new Point3D(sample.FilmPoint.X, sample.FilmPoint.Y, 0.0);
            Point3D  pCamera = RasterToCamera.ExecuteTransform(pFilm);
            Vector3D dir     = new Vector3D(pCamera.X, pCamera.Y, pCamera.Z).Normalize();

            ray = new RayDifferential(new Point3D(0.0, 0.0, 0.0), dir);
            // Modify ray for depth of field
            if (LensRadius > 0.0)
            {
                // Sample point on lens
                Point2D pLens = LensRadius * Sampling.ConcentricSampleDisk(sample.LensPoint);

                // Compute point on plane of focus
                double  ft     = FocalDistance / ray.Direction.Z;
                Point3D pFocus = ray.AtPoint(ft);

                // Update ray for effect of lens
                ray.Origin    = new Point3D(pLens.X, pLens.Y, 0.0);
                ray.Direction = (pFocus - ray.Origin).ToVector3D().Normalize();
            }

            // Compute offset rays for _PerspectiveCamera_ ray differentials
            if (LensRadius > 0.0)
            {
                // Compute _PerspectiveCamera_ ray differentials accounting for lens

                // Sample point on lens
                Point2D  pLens  = LensRadius * Sampling.ConcentricSampleDisk(sample.LensPoint);
                Vector3D dx     = (pCamera.ToVector3D() + _dxCamera).Normalize();
                double   ft     = FocalDistance / dx.Z;
                Point3D  pFocus = new Point3D(0.0, 0.0, 0.0) + (ft * dx).ToPoint3D();
                ray.RxOrigin    = new Point3D(pLens.X, pLens.Y, 0.0);
                ray.RxDirection = (pFocus - ray.RxOrigin).ToVector3D().Normalize();

                Vector3D dy = (pCamera.ToVector3D() + _dyCamera).Normalize();
                ft              = FocalDistance / dy.Z;
                pFocus          = new Point3D(0.0, 0.0, 0.0) + (ft * dy).ToPoint3D();
                ray.RyOrigin    = new Point3D(pLens.X, pLens.Y, 0.0);
                ray.RyDirection = (pFocus - ray.RyOrigin).ToVector3D().Normalize();
            }
            else
            {
                ray.RxOrigin    = ray.RyOrigin = ray.Origin;
                ray.RxDirection = (pCamera.ToVector3D() + _dxCamera).Normalize();
                ray.RyDirection = (pCamera.ToVector3D() + _dyCamera).Normalize();
            }
            ray.Time   = PbrtMath.Lerp(sample.Time, ShutterOpen, ShutterClose);
            ray.Medium = Medium;
            ray        = new RayDifferential(CameraToWorld.ExecuteTransform(ray))
            {
                HasDifferentials = true
            };
            return(1.0);
        }
        /// <inheritdoc />
        public override Spectrum We(Ray ray, out Point2D pRaster2)
        {
            // Interpolate camera matrix and check if $\w{}$ is forward-facing
            CameraToWorld.Interpolate(ray.Time, out Transform c2w);
            double cosTheta = ray.Direction.Dot(c2w.ExecuteTransform(new Vector3D(0.0, 0.0, 1.0)));

            if (cosTheta <= 0.0)
            {
                pRaster2 = null;
                return(Spectrum.Create(0.0));
            }

            // Map ray $(\p{}, \w{})$ onto the raster grid
            Point3D pFocus  = ray.AtPoint((LensRadius > 0.0 ? FocalDistance : 1.0) / cosTheta);
            Point3D pRaster = RasterToCamera.ExecuteTransform(c2w.Inverse().ExecuteTransform(pFocus));

            //Point3D pRaster = Inverse(RasterToCamera)(Inverse(c2w.Inverse)(pFocus));

            // Return raster position if requested
            pRaster2 = new Point2D(pRaster.X, pRaster.Y);

            // Return zero importance for out of bounds points
            Bounds2I sampleBounds = Film.GetSampleBounds();

            if (pRaster.X < sampleBounds.MinPoint.X || pRaster.Z >= sampleBounds.MaxPoint.X ||
                pRaster.Y < sampleBounds.MinPoint.Y || pRaster.Y >= sampleBounds.MaxPoint.Y)
            {
                return(Spectrum.Create(0.0));
            }

            // Compute lens area of perspective camera
            double lensArea = LensRadius != 0.0 ? (Math.PI * LensRadius * LensRadius) : 1.0;

            // Return importance for point on image plane
            double cos2Theta = cosTheta * cosTheta;

            return(Spectrum.Create(1.0 / (_a * lensArea * cos2Theta * cos2Theta)));
        }