private async void MergeBuffersGPU(float[] color, float[] normal, float[] p3D, float[] tex) { _pixelBufferImg.Clear((byte)0); var specular = Settings.Specular; Gpu.Default.For(0, _imgHeight * _imgWidth, i => { var k = i * 3; ColorPass(_enviromentLight, color, normal, p3D, tex, specular, k); ArrayMath.Clamp(color, 0, 255, k, 3); _pixelBufferImg[k + 0] = (byte)(color[k + 0]); _pixelBufferImg[k + 1] = (byte)(color[k + 1]); _pixelBufferImg[k + 2] = (byte)(color[k + 2]); }); Gpu.Free(color); Gpu.Free(normal); Gpu.Free(p3D); Gpu.Free(tex); await App.Current?.Dispatcher.InvokeAsync(() => { if (Bitmap == null) { return; } WriteToBitmap(Bitmap, _pixelBufferImg); }); }
private async void MergeBuffersCPU(float[] color, float[] normal, float[] p3D, float[] tex, float[] zBuffer) { _pixelBufferImg.Clear((byte)0); var specular = Settings.Specular; Parallel.For(0, _imgHeight, y => { int i = y * _imgWidth * 3; int k = y * _imgWidth; for (int x = 0; x < _imgWidth; x++, i += 3, k++) { if (float.IsInfinity(zBuffer[k])) { continue; } ColorPass(_enviromentLight, color, normal, p3D, tex, specular, i); ArrayMath.Clamp(color, 0, 255, i, 3); _pixelBufferImg[i + 0] = (byte)(color[i + 0]); _pixelBufferImg[i + 1] = (byte)(color[i + 1]); _pixelBufferImg[i + 2] = (byte)(color[i + 2]); } }); await App.Current?.Dispatcher.InvokeAsync(() => { if (Bitmap == null) { return; } WriteToBitmap(Bitmap, _pixelBufferImg); }); }