Пример #1
0
        /// <inheritdoc />
        public override double GenerateRay(CameraSample sample, out Ray 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.AtPoint(pFilm);

            ray = new Ray(new Point3D(0.0, 0.0, 0.0), pCamera.ToVector3D().Normalize());
            // 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();
            }
            ray.Time   = PbrtMath.Lerp(sample.Time, ShutterOpen, ShutterClose);
            ray.Medium = Medium;
            ray        = CameraToWorld.ExecuteTransform(ray);
            return(1.0);
        }
Пример #2
0
        /// <inheritdoc />
        public override Spectrum Sample_Wi(
            Interaction it,
            Point2D u,
            out Vector3D wi,
            out double pdf,
            out Point2D pRaster,
            out VisibilityTester vis)
        {
            // Uniformly sample a lens interaction _lensIntr_
            Point2D     pLens      = LensRadius * Sampling.ConcentricSampleDisk(u);
            Point3D     pLensWorld = CameraToWorld.ExecuteTransform(it.Time, new Point3D(pLens.X, pLens.Y, 0.0));
            Interaction lensIntr   = new Interaction(pLensWorld, it.Time, new MediumInterface(Medium));

            lensIntr.N = (CameraToWorld.ExecuteTransform(it.Time, new Point3D(0.0, 0.0, 1.0))).ToVector3D().ToNormal3D();

            // Populate arguments and compute the importance value
            vis = new VisibilityTester(it, lensIntr);
            wi  = (lensIntr.P - it.P).ToVector3D();
            double dist = wi.Length();

            wi /= dist;

            // Compute PDF for importance arriving at _ref_

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

            pdf = (dist * dist) / (lensIntr.N.AbsDot(wi) * lensArea);
            return(We(lensIntr.SpawnRay(-wi), out pRaster));
        }
Пример #3
0
        /// <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);
        }