示例#1
0
        /// <summary>
        /// 根据焦距和透镜半径计算光线
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="sampler"></param>
        /// <returns></returns>
        private Ray GetThinLensRayFromPixel(int x, int y, SamplerBase sampler)
        {
            if (renderTarget == null)
            {
                throw new System.NullReferenceException();
            }
            var    sample = sampler.SampleUnitSquare();
            double px     = (renderTarget.width - 1 - (sample.x + x)) / renderTarget.width * 2 - 1;
            double py     = (sample.y + y) / renderTarget.height * 2 - 1;

            px *= m_Width;
            py *= m_Height;
            double per = focal / near;

            px = px * per;
            py = py * per;
            Vector3 p = position + right * px + up * py + forward * focal;

            Vector2 disk = sampler.SampleUnitDisk();

            Vector3 ori = position + right * disk.x * radius + up * disk.y * radius;

            Vector3 dir = (p - ori).normalized;

            return(new Ray(ori, dir));
        }
示例#2
0
        public override Vector3 Sample(SamplerBase sampler)
        {
            Vector2 pos = sampler.SampleUnitDisk();

            return(position + right * (pos.x) + up * (pos.y));
        }