public MonteCarloLightingModel(Scene scene, RNG rng, bool nee, bool cosineDist, bool russianRoulette) { _scene = scene; _rng = rng; _nee = nee; _cosineDist = cosineDist; _russianRoulette = russianRoulette; }
public Stratifier(RNG rng, int width, int height) { _rng = rng; _width = width; _height = height; _invWidth = 1f/_width; _invHeight = 1f/_height; }
public static RNG[] CreateMultipleRNGs(int count) { var m = new Random(); var r = new RNG[count]; for (int i = 0; i < count; i++) { r[i] = new RNG(m.Next()); } return r; }
public Color3 Sample(Scene scene, Ray ray, RNG rng, bool ignoreLight) { if (ray.BouncesLeft < 1) { return Color4.Black; } //get nearest intersection var intersection = IntersectionHelper.GetClosestIntersection(ray, scene.Objects); if (intersection == null) { return scene.Skybox.Intersect(ray.Direction); } var lightingModel = new MonteCarloLightingModel(scene, rng, nee: true, cosineDist: true, russianRoulette: false); return lightingModel.Calculate(intersection, ignoreLight); }
public Color3 Sample(Scene scene, Ray ray, RNG random, bool ignoreLight) { //Debug.Assert(scene.BVH != null); if (ray.BouncesLeft < 1) { return Color4.Red; } //get nearest intersection var intersection = IntersectionHelper.GetClosestIntersection(ray, scene.Objects); if (intersection == null) { return scene.Skybox.Intersect(ray.Direction); } var lightingModel = new WhittedStyleLightingModel(scene, random); return lightingModel.Calculate(intersection); }
public WhittedStyleLightingModel(Scene scene, RNG rng) { _scene = scene; _rng = rng; }
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; }
public Color3 Sample(Ray ray, RNG random, bool ignoreLight) { return _tracer.Sample(this, ray, random, ignoreLight); }