コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }