static void Main(string[] args) { RNG rng = new RNG(); int nb_samples = (args.Length > 0) ? int.Parse(args[0]) / 4 : 1; const int w = 1024; const int h = 768; Vector3 eye = new Vector3(50, 52, 295.6); Vector3 gaze = new Vector3(0, -0.042612, -1).Normalize(); const double fov = 0.5135; Vector3 cx = new Vector3(w * fov / h, 0.0, 0.0); Vector3 cy = (cx.Cross(gaze)).Normalize() * fov; Vector3[] Ls = new Vector3[w * h]; for (int i = 0; i < w * h; ++i) { Ls[i] = new Vector3(); } for (int y = 0; y < h; ++y) { // pixel row Console.Write("\rRendering ({0} spp) {1:0.00}%", nb_samples * 4, 100.0 * y / (h - 1)); for (int x = 0; x < w; ++x) { // pixel column for (int sy = 0, i = (h - 1 - y) * w + x; sy < 2; ++sy) { // 2 subpixel row for (int sx = 0; sx < 2; ++sx) { // 2 subpixel column Vector3 L = new Vector3(); for (int s = 0; s < nb_samples; ++s) { // samples per subpixel double u1 = 2.0 * rng.UniformFloat(); double u2 = 2.0 * rng.UniformFloat(); double dx = u1 < 1 ? Math.Sqrt(u1) - 1.0 : 1.0 - Math.Sqrt(2.0 - u1); double dy = u2 < 1 ? Math.Sqrt(u2) - 1.0 : 1.0 - Math.Sqrt(2.0 - u2); Vector3 d = cx * (((sx + 0.5 + dx) / 2 + x) / w - 0.5) + cy * (((sy + 0.5 + dy) / 2 + y) / h - 0.5) + gaze; L += Radiance(new Ray(eye + d * 130, d.Normalize(), Sphere.EPSILON_SPHERE), rng) * (1.0 / nb_samples); } Ls[i] += 0.25 * Vector3.Clamp(L); } } } } ImageIO.WritePPM(w, h, Ls); }
static void Main(string[] args) { RNG rng = new RNG(); int nb_samples = (args.Length > 0) ? int.Parse(args[0]) / 4 : 1; const int w = 1024; const int h = 768; Vector3 eye = new Vector3(50, 52, 295.6); Vector3 gaze = new Vector3(0, -0.042612, -1).Normalize(); const double fov = 0.5135; Vector3 cx = new Vector3(w * fov / h, 0.0, 0.0); Vector3 cy = (cx.Cross(gaze)).Normalize() * fov; Vector3[] Ls = new Vector3[w * h]; for (int i = 0; i < w * h; ++i) { Ls[i] = new Vector3(); } Parallel.For(0, h, y => RenderFunc(y, w, h, nb_samples, eye, gaze, cx, cy, Ls, rng)); ImageIO.WritePPM(w, h, Ls); }