public void Run() { startTime = DateTime.Now; int samplesCount = 2000; for (p = 0; p < samplesCount; p++) { for (int y = 0; y < canvas.h; y++) { for (int x = 0; x < canvas.w; x++) { Vector position = new Vector(-22, 5, 25);// + new Vector(randomVal(), randomVal(), randomVal()) * 0.7f; //Vec position = new Vec(-20, 5, 18); Vector goal = (new Vector(-3, 4, 0) - position).Normal(); Vector left = -(new Vector(goal.z, 0, -goal.x)).Normal() * (1.0f / canvas.w); // Cross-product to get the up vector Vector up = (new Vector(goal.y * left.z - goal.z * left.y, goal.z * left.x - goal.x * left.z, goal.x * left.y - goal.y * left.x)); //Vec target = (goal + left * (x - w / 2 + randomVal())*0.1f + up * (y - h / 2 + randomVal())*0.1f ).Normal(); Vector target = (goal + left * (x - canvas.w / 2 + randomVal()) + up * (y - canvas.h / 2 + randomVal())).Normal(); Vector color = Trace(position, target); canvas.AddPixel(x, y, (int)color.x, (int)color.y, (int)color.z); } } timeSpan = DateTime.Now - startTime; EndSempl?.Invoke(); } }
public void Run() { startTime = DateTime.Now; int samplesCount = 2000; for (int p = 0; p < samplesCount; p++) { for (int y = 0; y < canvas.h; y++) { for (int x = 0; x < canvas.w; x++) { float cameraX = (x - canvas.w / 2 + RandomVal()) / canvas.w; float cameraY = (y - canvas.h / 2 + RandomVal()) / canvas.w; Vector position = camera.GetPosition(cameraX, cameraY); Vector direction = camera.GetDirection(cameraX, cameraY); Vector color = Trace(position, direction); canvas.AddPixel(x, y, (int)color.x, (int)color.y, (int)color.z); } } timeSpan = DateTime.Now - startTime; EndSempl?.Invoke(); } }