Ejemplo n.º 1
0
        public List <Ray> RaysForPixel(double px, double py)
        {
            var rays   = new List <Ray>();
            var inv    = this.Camera.TransformInverse;
            var origin = inv * new Point(0, 0, 0);

            var pixelSize  = this.Camera.PixelSize;
            var halfWidth  = this.Camera.HalfWidth;
            var halfHeight = this.Camera.HalfHeight;

            for (var i = 0; i < this.NumSamples; i++)
            {
                var xOffset = (px + 0.5);
                var yOffset = (py + 0.5);

                var rx = RandomGeneratorThreadSafe.NextDouble();
                var ry = RandomGeneratorThreadSafe.NextDouble();

                xOffset += (0.5 - rx);
                yOffset += (0.5 - ry);

                xOffset *= pixelSize;
                yOffset *= pixelSize;

                var worldX = halfWidth - xOffset;
                var worldY = halfHeight - yOffset;

                var pixel     = inv * new Point(worldX, worldY, -1);
                var direction = (pixel - origin).Normalize();

                rays.Add(new Ray(origin, direction, RayType.Primary));
            }
            return(rays);
        }
Ejemplo n.º 2
0
        private Vector RandomInUnitDisk()
        {
            double r     = Math.Sqrt(RandomGeneratorThreadSafe.NextDouble());
            double theta = RandomGeneratorThreadSafe.NextDouble() * 2 * Math.PI;
            double x     = r * Math.Cos(theta);
            double y     = r * Math.Sin(theta);

            return(new Vector(x, y, 0));
        }