Example #1
0
        /// <summary>
        /// Generates a ray going from camera lens towards the scene
        /// (in camera space).
        /// </summary>
        /// <param name="senzorPoint">Position on output image (in image raster
        /// space)</param>
        /// <returns>Outgoint ray or null if the ray is absorbed inside lens.
        /// </returns>
        public Ray GenerateRay(Vector2d imagePos, Vector2d sample)
        {
            // for a position on the sensor generate a position on the lens

            // Generates a ray from senzor to lens back pupil given position on
            // image which corresponds to the senzor position.

            Vector3d senzorPos   = Sensor.ImageToCamera(imagePos);
            Vector3d lensPos     = LensToCamera(Lens.GetBackSurfaceSample(sample));
            Ray      outgoingRay = Lens.Transfer(senzorPos, lensPos);

            return(outgoingRay);
        }
Example #2
0
        public Ray Transfer(Ray incomingRay)
        {
            if (BackStop.Intersect(incomingRay) == null)
            {
                return(null);
            }
            Ray outgoingRay = Lens.Transfer(incomingRay);

            if (outgoingRay == null)
            {
                return(null);
            }
            if (FrontStop.Intersect(outgoingRay) == null)
            {
                return(null);
            }
            return(outgoingRay);
        }
Example #3
0
        public FloatMapImage RenderImage(Size imageSize)
        {
            int           height      = imageSize.Height;
            int           width       = imageSize.Width;
            FloatMapImage outputImage = new FloatMapImage((uint)width, (uint)height, PixelFormat.Greyscale);

            Sensor.RasterSize = imageSize;

            Sampler sampler         = new Sampler();
            int     SqrtSampleCount = (int)Math.Sqrt(SampleCount);

            foreach (Vector2d sample in sampler.GenerateJitteredSamples(SqrtSampleCount))
            {
                // generate a sample at the lens surface
                Vector3d lensPos = Lens.GetBackSurfaceSample(sample);
                lensPos.Z = 0;
                // make an incoming ray from the light source to the lens sample and
                // transfer the incoming ray through the lens creating the outgoing ray
                Ray outgoingRay = Lens.Transfer(LightSourcePosition, lensPos);
                if (outgoingRay == null)
                {
                    continue;
                }
                // intersect the senzor with the outgoing ray
                Intersection intersection = Sensor.Intersect(outgoingRay);
                if (intersection == null)
                {
                    continue;
                }
                Vector3d intersectionPoint      = intersection.Position;
                Vector2d intersectionPixelPoint = Sensor.CameraToImage(intersectionPoint);
                // put a splat on the senzor at the intersection
                Splat(outputImage, LightIntensity, intersectionPixelPoint);
            }

            return(outputImage);
        }