Example #1
0
        /// <inheritdoc />
        public override void Pdf_We(Ray ray, out double pdfPos, out double pdfDir)
        {
            // Interpolate camera matrix and fail if $\w{}$ is not 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)
            {
                pdfPos = pdfDir = 0.0;
                return;
            }

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

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

            if (pRaster.X < sampleBounds.MinPoint.X || pRaster.X >= sampleBounds.MaxPoint.X ||
                pRaster.Y < sampleBounds.MinPoint.Y || pRaster.Y >= sampleBounds.MaxPoint.Y)
            {
                pdfPos = pdfDir = 0.0;
                return;
            }

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

            pdfPos = 1.0 / lensArea;
            pdfDir = 1.0 / (_a * cosTheta * cosTheta * cosTheta);
        }
Example #2
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);
        }
Example #3
0
        //public PerspectiveCamera(Transform c2w) { }
        override public float GenerateRay(CameraSample sample, out Ray ray)
        {
            Point3 Pras = new Point3(sample.imageX, sample.imageY, 0); //光栅坐标
            Point3 Pcamera;

            Pcamera = RasterToCamera.Caculate(Pras);//光栅坐标转换为相机坐标 相机为原点

            ray = new Ray(new Point3(0, 0, 0), LR.Normalize(new Vector(Pcamera)), 0.0f, 1.0f / 0);
            // Modify ray for depth of field
            if (lensRadius > 0.0)
            {
                // Sample point on lens
                float lensU, lensV;
                //  ConcentricSampleDisk(sample.lensU, sample.lensV, &lensU, &lensV);
                //lensU *= lensRadius;
                //lensV *= lensRadius;

                // Compute point on plane of focus
                //    float ft = focalDistance / ray->d.z;
                //    Point Pfocus = (*ray)(ft);

                //    // Update ray for effect of lens
                //    ray->o = Point(lensU, lensV, 0.f);
                //    ray->d = Normalize(Pfocus - ray->o);
                //}
                //ray->time = sample.time;
                //CameraToWorld(*ray, ray);
            }

            return(1.0f);
        }
Example #4
0
        public override float GenerateRayDifferential(CameraSample sample, out RayDifferential ray)
        {
            // Generate raster and camera samples
            Point Pras    = new Point(sample.ImageX, sample.ImageY, 0);
            Point Pcamera = RasterToCamera.TransformPoint(ref Pras);

            ray = new RayDifferential(new Point(0, 0, 0), Vector.Normalize((Vector)Pcamera), 0.0f);
            // Modify ray for depth of field
            if (LensRadius > 0.0f)
            {
                // Sample point on lens
                float lensU, lensV;
                MonteCarloUtilities.ConcentricSampleDisk(sample.LensU, sample.LensV, out lensU, out lensV);
                lensU *= LensRadius;
                lensV *= LensRadius;

                // Compute point on plane of focus
                float ft     = FocalDistance / ray.Direction.Z;
                Point Pfocus = ray.Evaluate(ft);

                // Update ray for effect of lens
                ray.Origin    = new Point(lensU, lensV, 0.0f);
                ray.Direction = Vector.Normalize(Pfocus - ray.Origin);
            }
            // Compute offset rays for _PerspectiveCamera_ ray differentials
            ray.RxOrigin    = ray.RyOrigin = ray.Origin;
            ray.RxDirection = Vector.Normalize((Vector)Pcamera + _dxCamera);
            ray.RyDirection = Vector.Normalize((Vector)Pcamera + _dyCamera);
            ray.Time        = sample.Time;
            ray             = CameraToWorld.TransformRayDifferential(ray);
            return(1.0f);
        }
Example #5
0
        // float GenerateRay()
        public override float GenerateRay(CameraSample sample, out Ray ray)
        {
            Point3 Pras    = new Point3(sample.imageX, sample.imageY);
            Point3 Pcamera = RasterToCamera.Caculate(Pras);

            ray = new Ray(Pcamera, new Vector(0, 0, 1), 0, LR.INFINITY);//正交相机方向固定

            #region modify ray for depth of filed
            if (lensRadius > 0.0f)
            {
                // Sample point on lens
                float lensU = 0, lensV = 0;

                LR.ConcentricSampleDisk(sample.lensU, sample.lensV, ref lensU, ref lensV);
                lensU *= lensRadius;
                lensV *= lensRadius;

                // Compute point on plane of focus
                float  ft     = focalDistance / ray.d.z;
                Point3 Pfocus = ray.Transfer(ft);

                // Update ray for effect of lens
                ray.o = new Point3(lensU, lensV, 0.0f);
                ray.d = LR.Normalize(Pfocus - ray.o);
            }
            #endregion
            ray.time = sample.time;
            ray      = CameraToWorld.Caculate(ray);
            return(1.0f);
        }
Example #6
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);
        }
Example #7
0
 public PerspectiveCamera(
     AnimatedTransform cameraToWorld, float[] screenWindow,
     float shutterOpen, float shutterClose,
     float lensRadius, float focalDistance,
     float fieldOfView,
     Film film)
     : base(cameraToWorld, Transform.Perspective(fieldOfView, 1e-2f, 1000.0f), screenWindow, shutterOpen, shutterClose, lensRadius, focalDistance, film)
 {
     // Compute differential changes in origin for perspective camera rays
     _dxCamera = RasterToCamera.TransformPoint(new Point(1, 0, 0)) - RasterToCamera.TransformPoint(new Point(0, 0, 0));
     _dyCamera = RasterToCamera.TransformPoint(new Point(0, 1, 0)) - RasterToCamera.TransformPoint(new Point(0, 0, 0));
 }
Example #8
0
        /// <inheritdoc />
        public PerspectiveCamera(AnimatedTransform cameraToWorld, Bounds2D screenWindow, double shutterOpen, double shutterClose, double lensr, double focald, double fov, Film film, Medium medium)
            : base(cameraToWorld, Transform.Perspective(fov, 1e-2f, 1000.0), screenWindow, shutterOpen, shutterClose, lensr, focald, film, medium)
        {
            // Compute differential changes in origin for perspective camera rays
            _dxCamera =
                (RasterToCamera.AtPoint(new Point3D(1.0, 0.0, 0.0)) - RasterToCamera.AtPoint(new Point3D(0.0, 0.0, 0.0))).ToVector3D();
            _dyCamera =
                (RasterToCamera.AtPoint(new Point3D(0.0, 1.0, 0.0)) - RasterToCamera.AtPoint(new Point3D(0.0, 0.0, 0.0))).ToVector3D();

            // Compute image plane bounds at $z=1$ for _PerspectiveCamera_
            Point2I res      = film.FullResolution;
            Point3D MinPoint = RasterToCamera.AtPoint(new Point3D(0.0, 0.0, 0.0));
            Point3D MaxPoint = RasterToCamera.AtPoint(new Point3D(res.X, res.Y, 0.0));

            MinPoint /= MinPoint.Z;
            MaxPoint /= MaxPoint.Z;
            _a        = Math.Abs((MaxPoint.X - MinPoint.X) * (MaxPoint.Y - MinPoint.Y));
        }
Example #9
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)));
        }
Example #10
0
 /// <summary>
 /// PerspectiveCamera
 /// </summary>
 /// <param name="c2w">c2w</param>
 /// <param name="proj">camer2screen</param>
 /// <param name="f">film</param>
 /// <param name="lensr">lenser</param>
 /// <param name="focald">focald</param>
 /// <param name="screenWindow">float[4]</param>
 ///
 public PerspectiveCamera(AnimatedTransform c2w, float[] screenWindow, float sopen, float sclose, float lensr, float focald, float fov, Film f) : base(c2w, LR.Perspective(fov, 1e-2f, 1000f), screenWindow, sopen, sclose, lensr, focald, f)
 {
     dxCamera = RasterToCamera.Caculate(new Point3(1, 0, 0)) - RasterToCamera.Caculate(new Point3(0, 0, 0));
     dyCamera = RasterToCamera.Caculate(new Point3(0, 1, 0)) - RasterToCamera.Caculate(new Point3(0, 0, 0));
 }
Example #11
0
 public OrthoCamera(AnimatedTransform c2w, float[] screenWindow, float sopen, float sclose, float lensr, float focald, Film f) : base(c2w, LR.Orthographic(0, 1), screenWindow, sopen, sclose, lensr, focald, f)
 {
     dxCamera = RasterToCamera.Caculate(new Vector(1, 0, 0));
     dyCamera = RasterToCamera.Caculate(new  Vector(0, 1, 0));
 }
Example #12
0
        public override float GenerateRayDifferential(CameraSample sample, out RayDifferential ray)
        {
            Point3 Pras    = new Point3(sample.imageX, sample.imageY);
            Point3 Pcamera = RasterToCamera.Caculate(Pras);

            ray = new RayDifferential(Pcamera, new Vector(0, 0, 1), 0, 1.0f / 0);

            #region Modify ray for depth of field
            if (lensRadius > 0.0)
            {
                // Sample point on lens
                float lensU = 0, lensV = 0;
                LR.ConcentricSampleDisk(sample.lensU, sample.lensV, ref lensU, ref lensV);
                lensU *= lensRadius;
                lensV *= lensRadius;

                // Compute point on plane of focus
                float  ft     = focalDistance / ray.d.z;
                Point3 Pfocus = ray.Transfer(ft);

                // Update ray for effect of lens
                ray.o = new Point3(lensU, lensV, 0.0f);
                ray.d = LR.Normalize(Pfocus - ray.o);
            }
            #endregion
            ray.time = sample.time;

            #region Compute ray differentials for _OrthoCamera_
            if (lensRadius > 0)
            {
                // Compute _OrthoCamera_ ray differentials with defocus blur

                // Sample point on lens
                float lensU = 0, lensV = 0;
                LR.ConcentricSampleDisk(sample.lensU, sample.lensV, ref lensU, ref lensV);
                lensU *= lensRadius;
                lensV *= lensRadius;

                float ft = focalDistance / ray.d.z;

                Point3 pFocus = Pcamera + dxCamera + (ft * new Vector(0, 0, 1));
                ray.rxOrigin    = new Point3(lensU, lensV, 0.0f);
                ray.rxDirection = LR.Normalize(pFocus - ray.rxOrigin);

                pFocus          = Pcamera + dyCamera + (ft * new Vector(0, 0, 1));
                ray.ryOrigin    = new Point3(lensU, lensV, 0.0f);
                ray.ryDirection = LR.Normalize(pFocus - ray.ryOrigin);
            }
            else
            {
                ray.rxOrigin    = ray.o + dxCamera;
                ray.ryOrigin    = ray.o + dyCamera;
                ray.rxDirection = ray.ryDirection = ray.d;
            }
            #endregion

            ray.hasDifferentials = true;
            ray = CameraToWorld.Caculate(ray);

            return(1.0f);
        }