public PixelBuffer Execute(int width, int height) { var pixelBuffer = new PixelBuffer(width, height); var lowerLeftCorner = new Vector3(-2.0f, -1.0f, -1.0f); var horizontal = new Vector3(4.0f, 0.0f, 0.0f); var vertical = new Vector3(0.0f, 2.0f, 0.0f); var origin = Vector3.Zero; var camera = new BasicCamera(origin, lowerLeftCorner, horizontal, vertical); var hitables = new HitableList { new Sphere(new Vector3(0.0f, 0.0f, -1.0f), 0.5f, new LambertianMaterial(new ColorTexture(0.8f, 0.3f, 0.3f))), new Sphere(new Vector3(0.0f, -100.5f, -1.0f), 100.0f, new LambertianMaterial(new ColorTexture(0.8f, 0.8f, 0.0f))), new Sphere(new Vector3(1.0f, 0.0f, -1.0f), 0.5f, new MetalMaterial(new ColorVector(0.8f, 0.6f, 0.2f), 0.3f)), new Sphere(new Vector3(-1.0f, 0.0f, -1.0f), 0.5f, new DialectricMaterial(1.5f)), new Sphere(new Vector3(-1.0f, 0.0f, -1.0f), -0.45f, new DialectricMaterial(1.5f)), }; var world = new HitableList { hitables }; for (int j = height - 1; j >= 0; j--) { for (int i = 0; i < width; i++) { ColorVector color = new ColorVector(0.0f, 0.0f, 0.0f); for (int sample = 0; sample < _numSamples; sample++) { float u = Convert.ToSingle(i + RandomService.Nextfloat()) / Convert.ToSingle(width); float v = Convert.ToSingle(j + RandomService.Nextfloat()) / Convert.ToSingle(height); var r = camera.GetRay(u, v); color += GetRayColor(r, world, 0); } color /= Convert.ToSingle(_numSamples); color = color.ApplyGamma2(); pixelBuffer.SetPixelColor(i, j, color); } Console.Write("."); } Console.WriteLine(); return(pixelBuffer); }
public PixelBuffer Execute(int width, int height) { var pixelBuffer = new PixelBuffer(width, height); var lowerLeftCorner = new Vector3(-2.0f, -1.0f, -1.0f); var horizontal = new Vector3(4.0f, 0.0f, 0.0f); var vertical = new Vector3(0.0f, 2.0f, 0.0f); var origin = Vector3.Zero; var camera = new BasicCamera(origin, lowerLeftCorner, horizontal, vertical); var hitables = new HitableList { new Sphere(new Vector3(0.0f, 0.0f, -1.0f), 0.5f), new Sphere(new Vector3(0.0f, -100.5f, -1.0f), 100.0f) }; var world = new HitableList { hitables }; for (int j = height - 1; j >= 0; j--) { for (int i = 0; i < width; i++) { ColorVector color = new ColorVector(0.0f, 0.0f, 0.0f); for (int sample = 0; sample < _numSamples; sample++) { float u = Convert.ToSingle(i + GetRandom()) / Convert.ToSingle(width); float v = Convert.ToSingle(j + GetRandom()) / Convert.ToSingle(height); var r = camera.GetRay(u, v); color += GetRayColor(r, world); } color /= Convert.ToSingle(_numSamples); pixelBuffer.SetPixelColor(i, j, color); } Console.Write("."); } Console.WriteLine(); return(pixelBuffer); }