public void RenderScene(RenderingContext context) { Ensure.That("context", context).IsNotNull(); //// transforms from image space into camera space //var imageMatrix = Matrix.Scaling(1d / context.Target.Width, 1d / context.Target.Height, 1); foreach (var pixel in context.Target.GetPixels()) { var colorAccumulator = Color.Black; foreach (var pixelSpaceSample in _pixelSampleGenerator.GenerateSamples(context.SamplesPerPixel)) { var imageSpaceSample = new Point(pixel.X + pixelSpaceSample.X, pixel.Y + pixelSpaceSample.Y, 1); var projectionSpaceRay = new Ray(context.ImageMatrix * imageSpaceSample, Vector.UnitZ); var cameraSpaceRay = context.ProjectionMatrix * projectionSpaceRay; // TODO: transform camera space ray into world space colorAccumulator += _algorithm.DetermineRayColor(cameraSpaceRay, context.World); } context.Target.SetPixelColor(pixel, colorAccumulator / context.SamplesPerPixel); } }
public IEnumerable <Point2> GenerateSamples(int count) { foreach (var sample in _underlyingGenerator.GenerateSamples(count)) { var transformed = (sample - new Vector2(.5f, .5f)) * 2; yield return (new Point2( System.Math.Pow(System.Math.Abs(transformed.X), _bias) * System.Math.Sign(transformed.X), System.Math.Pow(System.Math.Abs(transformed.Y), _bias) * System.Math.Sign(transformed.Y) ) / 2 + new Vector2(.5f, .5f)); } }