public static float Randf() { return(StaticRandom.Randf()); }
private static IHitable CreateRandomScene() { var hitables = new List <IHitable>(500); hitables.Add(new Sphere(new Vector3(0f, -1000f, 0f), 1000f, new Lambertian(new Vector3(0.5f, 0.5f, 0.5f)))); for (int a = -11; a < 11; a++) { for (int b = -11; b < 11; b++) { float randomMat = (float)StaticRandom.NextDouble(); var center = new Vector3(a + 0.9f * (float)StaticRandom.NextDouble(), 0.2f, b + 0.9f * (float)StaticRandom.NextDouble()); if ((center - new Vector3(4f, 0.2f, 0f)).Length() > 0.9f) { if (randomMat < 0.8f) //diffuse { hitables.Add(new Sphere(center, 0.2f, new Lambertian(new Vector3((float)StaticRandom.NextDouble() * (float)StaticRandom.NextDouble(), (float)StaticRandom.NextDouble() * (float)StaticRandom.NextDouble(), (float)StaticRandom.NextDouble() * (float)StaticRandom.NextDouble())))); } else if (randomMat < 0.95f) //metal { hitables.Add(new Sphere(center, 0.2f, new Metal(new Vector3(0.5f * (1f + (float)StaticRandom.NextDouble()), 0.5f * (1 + (float)StaticRandom.NextDouble()), 0.5f * (float)StaticRandom.NextDouble()), 0.2f))); } else //glass { hitables.Add(new Sphere(center, 0.2f, new Dielectric(1.5f))); } } } } hitables.Add(new Sphere(new Vector3(0f, 1f, 0f), 1.0f, new Dielectric(1.5f))); hitables.Add(new Sphere(new Vector3(-4f, 1f, 0f), 1.0f, new Lambertian(new Vector3(0.4f, 0.2f, 0.1f)))); hitables.Add(new Sphere(new Vector3(4f, 1f, 0f), 1.0f, new Metal(new Vector3(0.7f, 0.6f, 0.5f), 0f))); return(new HitableCollection(hitables)); }