public static Color[] CreateColorFromHitRecord(int width, int height) { var camera = new RayTraceCamera(Vector3.zero, new Vector3(0f, 0f, -1f), Vector3.up, 90f, 2f, 0f, 1f); var colors = new Color[width * height]; var hitableList = new HitableList(); hitableList.List.Add(new Sphere(new Vector3(0, 0, -1), 0.5f, new Lambertian(Color.white))); hitableList.List.Add(new Sphere(new Vector3(0, -100.5f, -1), 100f, new Lambertian(Color.white))); for (int j = height - 1; j >= 0; j--) { for (int i = 0; i < width; i++) { var color = new Color(); for (int s = 0; s < SamplingNumber; s++) { var u = (i + Random.Range(0, 1f)) / width; var v = (j + Random.Range(0, 1f)) / height; var r = camera.GetRay(u, v); color += GetColorFromHitRecord(r, hitableList); } color /= SamplingNumber; colors[i + j * width] = new Color(Mathf.Sqrt(color.r), Mathf.Sqrt(color.g), Mathf.Sqrt(color.b), 1f); } } return(colors); }
public static Color[] CreateColorFromHitRecord(int width, int height) { var camPos = new Vector3(10f, 2f, -3f); var camLookAt = new Vector3(0f, 1f, 0f); var focusDist = (camLookAt - camPos).magnitude; var camera = new RayTraceCamera(camPos, camLookAt, Vector3.up, 40f, 2f, 0f, focusDist); var colors = new Color[width * height]; var hitableList = GetHitableListFromScene(); for (int j = height - 1; j >= 0; j--) { for (int i = 0; i < width; i++) { var color = new Color(); for (int s = 0; s < SamplingNumber; s++) { var u = (i + Random.Range(0, 1f)) / width; var v = (j + Random.Range(0, 1f)) / height; var r = camera.GetRay(u, v); color += GetColorFromHitRecord(r, hitableList, 2); } color /= SamplingNumber; colors[i + j * width] = new Color(Mathf.Sqrt(color.r), Mathf.Sqrt(color.g), Mathf.Sqrt(color.b), 1f); } } return(colors); }