public byte[] Render(Scene s) { var j = 0; for (int y = 0; y < Height; y++) { var i = y * Stride; for (int x = 0; x < Width; x++) { var color = Vector3.Zero; var u = _screenPoints[j++]; var v = _screenPoints[j++]; for (int n = 0; n < SAMPLE_COUNT; n++) { var u1 = Helper.RandomGaussValue(u, _sigmaX); var v1 = Helper.RandomGaussValue(v, _sigmaX); color += s.Sample(u1, v1, Settings); } color /= SAMPLE_COUNT; _data[i++] = Helper.Clamp8(Helper.GammaCorrectionToSRGB(color.X) * 255); _data[i++] = Helper.Clamp8(Helper.GammaCorrectionToSRGB(color.Y) * 255); _data[i++] = Helper.Clamp8(Helper.GammaCorrectionToSRGB(color.Z) * 255); } } return(_data); }
public Color3 TraceRay(int x, int y, RNG rng) { float v = (float)y / Screen.Height; float u = (float)x / Screen.Width; Color3 color = new Color3(0, 0, 0); var strat = new Stratifier(rng, _sampleSizeX, _sampleSizeY); for (int i = 0; i < SampleSize; i++) { var pos = strat.GetRandomPointInStratum(i); var dx = pos.X / Screen.Width; var dy = pos.Y / Screen.Height; var r = _camera.CreatePrimaryRay(u + dx, v + dy); color += _scene.Sample(r, rng, false); } color /= SampleSize; return(color); }