/// <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); }
/// <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)); }