public static void Main3() { int nx = 1280; int ny = 640; int ns = 16; Vector3 lookfrom = new Vector3(-2, 2, 1); Vector3 lookat = new Vector3(0, 0, -1); Vector3 up = new Vector3(0, 1, 0); RayCamera camera = new RayCamera(lookfrom, lookat, up, 35, (float)(nx) / (float)(ny)); HitList list = new HitList(); list.Add(new Sphere(new Vector3(0, 0, -1), 0.5f, new Lambertian(new Vector3(0.1f, 0.2f, 0.5f)))); list.Add(new Sphere(new Vector3(0, -100.5f, -1), 100, new Lambertian(new Vector3(0.8f, 0.8f, 0.0f)))); list.Add(new Sphere(new Vector3(1, 0, -1), 0.5f, new Metal(new Vector3(0.8f, 0.6f, 0.2f), 0.3f))); list.Add(new Sphere(new Vector3(-1, 0, -1), 0.5f, new DielectricShlick(1.5f))); list.Add(new Sphere(new Vector3(-1, 0, -1), -0.45f, new DielectricShlick(1.5f))); Texture2D tex = ImageHelper.CreateImg(nx, ny); for (int j = ny - 1; j >= 0; --j) { for (int i = 0; i < nx; ++i) { Vector3 color = Vector3.zero; for (int k = 0; k < ns; ++k) { float u = (float)(i + Random.Range(0f, 1f)) / (float)(nx); float v = (float)(j + Random.Range(0f, 1f)) / (float)(ny); Ray r = camera.GetRay(u, v); color += RayCast(r, list, 0); } color = color / (float)(ns); color.x = Mathf.Sqrt(color.x); color.y = Mathf.Sqrt(color.y); color.z = Mathf.Sqrt(color.z); ImageHelper.SetPixel(tex, i, j, color); } } ImageHelper.SaveImg(tex, "Img/chapter10_3.png"); Debug.Log("Chapter 10_3 done"); }
public static void Main() { int nx = 1280; int ny = 640; int ns = 16; RayCamera camera = new RayCamera(); float R = Mathf.Cos(Mathf.PI / 4); HitList list = new HitList(); list.Add(new Sphere(new Vector3(-R, 0, -1), R, new Lambertian(new Vector3(0f, 0f, 1f)))); list.Add(new Sphere(new Vector3(R, 0, -1), R, new Lambertian(new Vector3(1f, 0f, 0f)))); Texture2D tex = ImageHelper.CreateImg(nx, ny); for (int j = ny - 1; j >= 0; --j) { for (int i = 0; i < nx; ++i) { Vector3 color = Vector3.zero; for (int k = 0; k < ns; ++k) { float u = (float)(i + Random.Range(-1f, 1f)) / (float)(nx); float v = (float)(j + Random.Range(-1f, 1f)) / (float)(ny); Ray r = camera.GetRay(u, v); color += RayCast(r, list, 0); } color = color / (float)(ns); color.x = Mathf.Sqrt(color.x); color.y = Mathf.Sqrt(color.y); color.z = Mathf.Sqrt(color.z); ImageHelper.SetPixel(tex, i, j, color); } } ImageHelper.SaveImg(tex, "Img/chapter10_1.png"); Debug.Log("Chapter 10_1 done"); }