static public hitable_list random_scene() { var n = 500; var list = new hitable_list(); list.Add(new sphere(new Vector3(0, -1000, -0), 1000, new lambertian(new Color(0.5f, 0.5f, 0.5f)))); for (var a = -11; a < 11; a++) { for (var b = -11; b < 11; b++) { var choose_mat = Random.value; var center = new Vector3(a + 0.9f * Random.value, 0.2f, b + 0.9f * Random.value); if (choose_mat < 0.8f) // diffuse { list.Add(new sphere(center, 0.2f, new lambertian(new Color(Random.value * Random.value, Random.value * Random.value, Random.value * Random.value)))); } else if (choose_mat < 0.95f) // metal { list.Add(new sphere(center, 0.2f, new metal(new Color(0.5f * (Random.value + 1), .5f * (Random.value + 1), .5f * (Random.value + 1)), 1))); } else // glass { list.Add(new sphere(center, 0.2f, new dielectric(1.5f))); } } } list.Add(new sphere(new Vector3(0, 1, 0), 1, new dielectric(1.5f))); list.Add(new sphere(new Vector3(-4, 1, 0), 1, new lambertian(new Color(0.4f, 0.2f, 0.1f)))); list.Add(new sphere(new Vector3(4, 1, 0), 1, new metal(new Color(0.7f, 0.6f, 0.5f), 0))); return(list); }
static private Color color(Ray r, hitable_list world, int depth) { hit_record rec; UnityEngine.Profiling.Profiler.BeginSample("hit"); var isHit = world.hit(r, 0.001f, float.MaxValue, out rec); UnityEngine.Profiling.Profiler.EndSample(); if (isHit) { Ray scatteded; Color attenuation; if (depth < 50) { UnityEngine.Profiling.Profiler.BeginSample("scattter"); var b = rec.mat.scatter(r, rec, out attenuation, out scatteded); UnityEngine.Profiling.Profiler.EndSample(); if (b) { return(attenuation * color(scatteded, world, depth + 1)); } else { return(Color.black); } } else { return(Color.black); } } else { var unit_direction = r.direction().normalized; var t = 0.5f * (unit_direction.y + 1.0f); return((1.0f - t) * (new Color(1, 1, 1)) + t * (new Color(0.5f, 0.7f, 1.0f))); } }
static private Color color(Ray r, hitable_list world, int depth) { hit_record rec; if (world.hit(r, 0.001f, float.MaxValue, out rec)) { Ray scatteded; Color attenuation; if (depth < 50 && rec.mat.scatter(r, rec, out attenuation, out scatteded)) { return(attenuation * color(scatteded, world, depth + 1)); } else { return(Color.black); } } else { var unit_direction = r.direction().normalized; var t = 0.5f * (unit_direction.y + 1.0f); return((1.0f - t) * (new Color(1, 1, 1)) + t * (new Color(0.5f, 0.7f, 1.0f))); } }