internal void RenderSequential(Scene scene, Int32[] rgb) { for (int y = 0; y < screenHeight; y++) { int stride = y * screenWidth; Camera camera = scene.Camera; for (int x = 0; x < screenWidth; x++) { Color color = TraceRay(new Ray(camera.Pos, GetPoint(x, y, camera)), scene, 0); rgb[x + stride] = color.ToInt32(); } } }
internal void RenderParallel(Scene scene, Int32[] rgb, ParallelOptions options) { try { Parallel.For(0, screenHeight, options, y => { int stride = y * screenWidth; Camera camera = scene.Camera; for (int x = 0; x < screenWidth; x++) { Color color = TraceRay(new Ray(camera.Pos, GetPoint(x, y, camera)), scene, 0); rgb[x + stride] = color.ToInt32(); } }); }catch (Exception ex) { MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }
internal void RenderParallelShowingThreads(Scene scene, Int32[] rgb, ParallelOptions options) { int id = 0; Parallel.For <double>(0, screenHeight, options, () => GetHueShift(Interlocked.Increment(ref id)), (y, state, hue) => { int stride = y * screenWidth; Camera camera = scene.Camera; for (int x = 0; x < screenWidth; x++) { Color color = TraceRay(new Ray(camera.Pos, GetPoint(x, y, camera)), scene, 0); color.ChangeHue(hue); rgb[x + stride] = color.ToInt32(); } return(hue); }, hue => Interlocked.Decrement(ref id)); }