Пример #1
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);
        }
Пример #2
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);
        }