protected override void GenerateSamles() { int N = (int) Math.Sqrt(NumSamples); NumSamples = N*N; for (int p = 0; p < NumSets; p++) { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { double rx, ry; if (NumSamples==1) { rx = 0.5; ry = 0.5; } else { rx = MathUtils.RandomDouble(); ry = MathUtils.RandomDouble(); } Point2d sp = new Point2d((j + rx)/N, (i + ry)/N); samples.Add(sp); } } } }
public override void RenderScene(World world) { //Stopwatch sw = Stopwatch.StartNew(); //while (true) //{ // sw.Restart(); RGBColor L = new RGBColor(); ViewPlane viewPlane = (ViewPlane) world.ViewPlane.Clone(); Ray ray = new Ray(); int depth = 0; Point2d samplePoint = new Point2d(); Point2d pixelPoint = new Point2d(); viewPlane.PixelSize /= zoom; ray.Origin = Eye; Bitmap bitmap = new Bitmap(viewPlane.HRes, viewPlane.VRes); for (int r = 0; r < viewPlane.VRes; r++) { for (int c = 0; c < viewPlane.HRes; c++) { L = new RGBColor(0, 0, 0); for (int i = 0; i < viewPlane.Sampler.NumSamples; i++) { samplePoint = viewPlane.Sampler.SampleUnitSquare(); pixelPoint.X = viewPlane.PixelSize*(c - 0.5*viewPlane.HRes + samplePoint.X); pixelPoint.Y = viewPlane.PixelSize*(r - 0.5*viewPlane.VRes + samplePoint.Y); ray.Direction = GetRayDirection(pixelPoint); L += world.Tracer.TraceRay(ray, depth); } L /= viewPlane.Sampler.NumSamples; L *= eposureTime; L.MaxToOne(); bitmap.SetPixel(c, viewPlane.VRes - r - 1, Color.FromArgb((int) (L.R*255), (int) (L.G*255), (int) (L.B*255))); } Console.Out.WriteLine("r = {0}", r); } bitmap.Save("TracedImage.bmp", ImageFormat.Bmp); //Console.Out.WriteLine("sw = {0}", sw.ElapsedMilliseconds); }
private void ShuffleYCoords() { for (int p = 0; p < NumSets; p++) { for (int i = 0; i < NumSamples - 1; i++) { int target = MathUtils.RandomInt()%NumSamples + p * NumSamples; int currendInd = i + p * NumSamples + 1; double temp = samples[currendInd].Y; samples[currendInd] = new Point2d(samples[currendInd].X, samples[target].Y); samples[target] = new Point2d(samples[target].X, temp); } } }
public Vector3d GetRayDirection(Point2d point) { Vector3d dir = point.X*u + point.Y*v - distToViewPlane*w; dir.Normalize(); return dir; }