public VolumeScene(double aspect) { var red = new Lambertian(ConstantTexture.Create(0.65, 0.05, 0.05)); var white = new Lambertian(ConstantTexture.Create(0.73, 0.73, 0.73)); var green = new Lambertian(ConstantTexture.Create(0.12, 0.45, 0.12)); var light = new DiffuseLight(ConstantTexture.Create(7, 7, 7)); var box1 = new Translate(new RotateY(new Box(Vec3.Create(0), Vec3.Create(165), white), -18), Vec3.Create(130, 0, 65)); var box2 = new Translate(new RotateY(new Box(Vec3.Create(0), Vec3.Create(165, 330, 165), white), 15), Vec3.Create(265, 0, 295)); IHitable[] hitables = { new FlipNormals(new YZRect(0, 555, 0, 555, 555, green)), new YZRect(0, 555, 0, 555, 0, red), new XZRect(113, 443, 127, 432, 554, light), new FlipNormals(new XZRect(0, 555, 0, 555, 555, white)), new XZRect(0, 555, 0, 555, 0, white), new FlipNormals(new XYRect(0, 555, 0, 555, 555, white)), new ConstantMedium(box1, 0.01, new ConstantTexture(Vec3.Create(1))), new ConstantMedium(box2, 0.01, new ConstantTexture(Vec3.Create(0))), }; World = new BVHNode(hitables, 0, 1); var lookFrom = Vec3.Create(278, 278, -800); var lookAt = Vec3.Create(278, 278, 0); double dist_to_focus = 10; double aderpture = 0; double vfov = 40; Camera = Camera.CreateLookAt(lookFrom, lookAt, Vec3.Create(0, 1, 0), vfov, aspect, aderpture, dist_to_focus); }
public static (List <IHitable>, Camera) PoolScene(ImSoRandom rnd, int nx, int ny) { var world = new List <IHitable>(); world.Add(new Sphere(new Vector3(0, -1000f, 0), 1000, new Lambertian(new ConstantTexture(0.33f, 0.67f, 0.0f)))); var red = new ConstantTexture(0.68f, 0.13f, 0.16f); var yellow = new ConstantTexture(1f, 0.74f, 0.13f); var black = new ConstantTexture(0.14f, 0.07f, 0.07f); var white = new ConstantTexture(1f, 1f, 0.9f); for (var a = 1f; a <= 5; a += 1f) { var counter = 0 - a; for (var b = 0f; b < a; b += 1f) { var center = new Vector3(a * 0.9f - 5f, 0.5f, a / 2f - b - 0.5f); var colour = counter % 2 == 0 ? red : yellow; if (a == 3 && b == 1) { colour = black; } if (a == 3 && b == 2) { colour = red; } if (a == 5 && b == 4) { colour = red; } world.Add(new Sphere(center, 0.45f, new Lambertian(colour))); world.Add(new Sphere(center, 0.5f, new Dialectric(1.5f))); counter++; } } var cueCenter = new Vector3(-6, 0.5f, 0); var cueCenter1 = cueCenter + new Vector3(0.75f * rnd.NextFloat(), 0, 0); world.Add(new MovingSphere(cueCenter, cueCenter1, 0.0f, 1.0f, 0.5f, new Dialectric(1.5f))); world.Add(new MovingSphere(cueCenter, cueCenter1, 0.0f, 1.0f, 0.45f, new Lambertian(white))); world.Add(new RectXZ(-3, 3, -2, 2, 5, new DiffuseLight(new ConstantTexture(new Vector3(15, 15, 15))))); var lookFrom = new Vector3(-9, 3.5f, 12); var lookAt = new Vector3(-3, 0, 0); var distToFocus = (lookFrom - new Vector3(-6, 0.5f, 0)).Length(); var aperture = 0.5f; var cam = new Camera(lookFrom, lookAt, new Vector3(0, 1, 0), 20, (float)nx / (float)ny, aperture, distToFocus, 0.0f, 1.0f); return(world, cam); }
public override Hitable GetObjects() { Texture earth = new ImageTexture(_earthTexturePath); Texture color = new ConstantTexture(new Vec3(0.75, 0.75, 0.75)); List <Hitable> list = new List <Hitable>(); list.Add(new Sphere(new Vec3(0.0, -1000.0, 0), 1000, new Lambertian(color))); list.Add(new Sphere(new Vec3(0.0, 2.0, 0.0), 2, new Lambertian(earth))); return((Hitable) new HitableList(list)); }
public TestScene2(double aspect) { double R = Math.Cos(Math.PI / 4); IHitable[] hitables = { new Sphere(Vec3.Create(-R, 0, -1), R, new Lambertian(ConstantTexture.Create(1, 0, 0))), new Sphere(Vec3.Create(R, 0, -1), R, new Lambertian(ConstantTexture.Create(0, 0, 1))) }; World = new BVHNode(hitables, 0, 1); Camera = Camera.CreateByVerticalFiled(90, aspect); }
private HitableList ImageSpheres() { Texture imageText = new Imagetexture(new Bitmap("Earth.jpg")); Texture constantText = new ConstantTexture(new Vector3D(0.8, 0.2, 0.1)); List <IHitable> list = new List <IHitable>(); list.Add(new Sphere(new Vector3D(0, -1000, 0), 998, new Metal(constantText, 0))); list.Add(new Sphere(new Vector3D(0, 0, 0), 2, new Lambertian(imageText))); return(new HitableList(list, list.Count)); }
public MaterialsScene(double aspect) { IHitable[] hitables = { new Sphere(Vec3.Create(0, -100.5, 0), 100, new Lambertian(ConstantTexture.Create(0.8, 0.8, 0.0))), new Sphere(Vec3.Create(0, 0, 0), 0.5, new Lambertian(ConstantTexture.Create(0.1, 0.2, 0.5))), new Sphere(Vec3.Create(1, 0, 0), 0.5, new Metal(ConstantTexture.Create(0.8, 0.6, 0.2),0.3)), new Sphere(Vec3.Create(-1, 0, 0), 0.5, new Dielectric(1.5)), new Sphere(Vec3.Create(-1, 0, 0), -0.45, new Dielectric(1.5)) }; World = new BVHNode(hitables, 0, 1); Camera = Camera.CreateLookAt(Vec3.Create(0.25, 0.5, 2.2), Vec3.Create(0.1, 0.0, 0), Vec3.Create(0, 1, 0), 45, aspect, 0, 1); }
public TestScene1(double aspect) { IHitable[] hitables = { new Sphere(Vec3.Create(0, 0, -1), 0.5, new Lambertian(ConstantTexture.Create(0.5, 0.1, 0.1))), new Sphere(Vec3.Create(0, -100.5, -1), 100.0, new Lambertian(ConstantTexture.Create(0.1, 0.1, 0.1))) }; World = new BVHNode(hitables, 0, 1); Camera = Camera.CreateByVerticalFiled(90, aspect); World = new BVHNode(hitables, 0, 1); Camera = new Camera( Vec3.Create(-2, -1, -1), Vec3.Create(4, 0, 0), Vec3.Create(0, 2, 0), Vec3.Create(0, 0, 0), 0, 0, 0); }
public CoverSceneRT1Motion(double aspect) { var sampler = new Random(); List <IHitable> hitables = new List <IHitable>(); hitables.Add(new Sphere(Vec3.Create(0, -1000, 0), 1000, new Lambertian(CheckerTexture.Create(0.2, 0.3, 0.1, 0.9, 0.9, 0.9)))); for (int a = -11; a < 11; ++a) { for (int b = -11; b < 11; ++b) { double choos_mat = sampler.NextDouble(); Vec3 center = Vec3.Create(a + 0.9 * sampler.NextDouble(), 0.2, b + 0.9 * sampler.NextDouble()); if ((center - Vec3.Create(4, 0.2, 0)).Length > 0.9) { if (choos_mat < 0.8) // diffuse { hitables.Add(new MovingSphere(center, center + Vec3.Create(0, 0.5, 0) * sampler.NextDouble(), 0, 1, 0.2, new Lambertian(ConstantTexture.Create(sampler.NextDouble() * sampler.NextDouble(), sampler.NextDouble() * sampler.NextDouble(), sampler.NextDouble() * sampler.NextDouble())))); } else if (choos_mat < 0.9) // metal { hitables.Add(new Sphere(center, 0.2, new Metal(ConstantTexture.Create(0.5 * (1 + sampler.NextDouble()), 0.5 * (1 + sampler.NextDouble()), 0.5 * (1 + sampler.NextDouble())), 0.5 * sampler.NextDouble()))); } else // glass { hitables.Add(new Sphere(center, 0.2, new Dielectric(1.5))); } } } } hitables.Add(new Sphere(Vec3.Create(0, 1, 0), 1, new Dielectric(1.5))); hitables.Add(new Sphere(Vec3.Create(-4, 1, 0), 1, new Lambertian(ConstantTexture.Create(0.4, 0.2, 0.1)))); hitables.Add(new Sphere(Vec3.Create(4, 1, 0), 1, new Metal(ConstantTexture.Create(0.7, 0.6, 0.5), 0))); double time0 = 0; double time1 = 1; World = new BVHNode(hitables.ToArray(), time0, time1); var lookFrom = Vec3.Create(12, 2, 3); var lookAt = Vec3.Create(0, 0, 0); double dist_to_focus = 10; double aderpture = 0.1; Camera = Camera.CreateLookAt(lookFrom, lookAt, Vec3.Create(0, 1, 0), 20, aspect, aderpture, dist_to_focus, time0, time1); }
public DefocusBlurScene(double aspect) { IHitable[] hitables = { new Sphere(Vec3.Create(0, -100.5, -1), 100, new Lambertian(ConstantTexture.Create(0.8, 0.8, 0.0))), new Sphere(Vec3.Create(0, 0, -1), 0.5, new Lambertian(ConstantTexture.Create(0.1, 0.2, 0.5))), new Sphere(Vec3.Create(1, 0, -1), 0.5, new Metal(ConstantTexture.Create(0.8, 0.6, 0.2),0.3)), new Sphere(Vec3.Create(-1, 0, -1), 0.5, new Dielectric(1.5)), new Sphere(Vec3.Create(-1, 0, -1), -0.45, new Dielectric(1.5)) }; World = new BVHNode(hitables, 0, 1); var lookFrom = Vec3.Create(3, 3, 2); var lookAt = Vec3.Create(0, 0, -1); var dist_to_focus = (lookFrom - lookAt).Length; double aderpture = 2; Camera = Camera.CreateLookAt(lookFrom, lookAt, Vec3.Create(0, 1, 0), 25, aspect, aderpture, dist_to_focus); }
public SimpleLightScene(double aspect) { var perlin_texture = NoiseTexture.Create(4, NoiseTexture.Type.SIN_Z); IHitable[] hitables = { new Sphere(Vec3.Create(0, -1000, 0), 1000, new Lambertian(perlin_texture)), new Sphere(Vec3.Create(0, 2, 0), 2, new Lambertian(perlin_texture)), new Sphere(Vec3.Create(0, 7, 0), 2, new DiffuseLight(ConstantTexture.Create(4, 4, 4))), new XYRect(3, 5, 1, 3, -2,new DiffuseLight(ConstantTexture.Create(4, 4, 4))) }; World = new BVHNode(hitables, 0, 1); var lookFrom = Vec3.Create(25, 4, 5); var lookAt = Vec3.Create(0, 2, 0); double dist_to_focus = 10; double aderpture = 0; Camera = Camera.CreateLookAt(lookFrom, lookAt, Vec3.Create(0, 1, 0), 20, aspect, aderpture, dist_to_focus); }
/// <summary> /// Scene from pdf 2, texture; two checker balls touching. /// </summary> private void CreateScene3() { // Set up camera this.hFovDeg = 25; var lookFrom = new Vec3(13, 2, 3); var lookAt = new Vec3(0, 0, 0); var lookUp = new Vec3(0, 1, 0); float focusDist = 10; float aperture = 0; this.camera = new CartesianCamera(this.rows, this.columns, this.hFovDeg, lookFrom, lookAt, lookUp, aperture, focusDist); // Add items var hitables = new List <Hitable>(); var oddTexture = new ConstantTexture(new Vec3(0.2f, 0.3f, 0.1f)); var evenTexture = new ConstantTexture(new Vec3(0.9f, 0.9f, 0.9f)); var checkerTexture = new CheckerTexture(evenTexture, oddTexture); hitables.Add(new Sphere(new Vec3(0, -10, 0), 10, new Lambertian(checkerTexture))); hitables.Add(new Sphere(new Vec3(0, 10, 0), 10, new Lambertian(checkerTexture))); this.world = new HitableList(hitables); }
private static IHitable RandomScene() { var checkerTexture = new ConstantTexture(new Vector3(0.5f, 0.5f, 0.5f)); var list = new List <IHitable> { new Sphere(new Vector3(0, -1000.0f, 0), 1000, new Lambertian(checkerTexture)) }; for (int a = -11; a < 11; a++) { for (int b = -11; b < 11; b++) { float chooseMat = Rand.Float; var center = new Vector3(a + 0.9f * Rand.Float, 0.2f, b + 0.9f * Rand.Float); if ((center - new Vector3(4, 0.2f, 0)).Length() > 0.9f) { if (chooseMat < 0.8) { // diffuse list.Add(new Sphere(center, 0.2f, new Lambertian(new ConstantTexture(new Vector3(Rand .Float * Rand .Float, Rand .Float * Rand .Float, Rand .Float * Rand .Float))))); } else if (chooseMat < 0.95) { // metal list.Add(new Sphere(center, 0.2f, new Metal(new Vector3(0.5f * (1 + Rand.Float), 0.5f * (1 + Rand.Float), 0.5f * (1 + Rand.Float)), 0.5f * Rand.Float))); } 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 ConstantTexture(new Vector3(0.4f, 0.2f, 0.1f))))); list.Add(new Sphere(new Vector3(4, 1, 0), 1, new Metal(new Vector3(0.7f, 0.6f, 0.6f), 0))); return(new BVHNode(list, 0, 1)); }
/// <summary> /// Scene from pdf 1; three spheres with lots around. /// </summary> private void CreateScene1() { Console.WriteLine("Populating scene.."); // Set up camera this.hFovDeg = 35; var lookFrom = new Vec3(13, 2, 3); var lookAt = new Vec3(0, 0, 0); var lookUp = new Vec3(0, 1, 0); float focusDist = (lookAt - lookFrom).Length; float aperture = 0.1f; this.camera = new CartesianCamera(this.rows, this.columns, this.hFovDeg, lookFrom, lookAt, lookUp, aperture, focusDist); // Add spheres var hitables = new List <Hitable>(); var oddTexture = new ConstantTexture(new Vec3(0.2f, 0.3f, 0.1f)); var evenTexture = new ConstantTexture(new Vec3(0.9f, 0.9f, 0.9f)); var checkerTexture = new CheckerTexture(evenTexture, oddTexture); hitables.Add(new Sphere(new Vec3(0, -1000, 0), 1000, new Lambertian(checkerTexture))); Random random = new Random(10); int dim = this.ballPlacementDimension; for (int a = -dim; a < dim; a++) { for (int b = -dim; b < dim; b++) { double chooseMat = random.NextDouble(); var center = new Vec3(a + 0.9f * (float)random.NextDouble(), 0.2f, b + 0.9f * (float)random.NextDouble()); if ((center - new Vec3(4, 0.2f, 0)).Length > 0.9) { if (chooseMat < 0.4) // diffuse { hitables.Add(new Sphere(center, 0.2f, new Lambertian( new ConstantTexture(new Vec3((float)(random.NextDouble() * random.NextDouble()), (float)(random.NextDouble() * random.NextDouble()), (float)(random.NextDouble() * random.NextDouble())))))); } else if (chooseMat < 0.65) // metal { hitables.Add(new Sphere(center, 0.2f, new Metal( new Vec3(0.5f * (float)(1 + random.NextDouble()), 0.5f * (float)(1 + random.NextDouble()), 0.5f * (float)(1 + random.NextDouble())), 0.5f * (float)random.NextDouble()))); } else // glass { hitables.Add(new Sphere(center, 0.2f, new Dielectric(1.5f))); } } } } hitables.Add(new Sphere(new Vec3(0, 1, 0), 1, new Dielectric(1.5f))); hitables.Add(new Sphere(new Vec3(-4, 1, 0), 1, new Lambertian(new ConstantTexture(new Vec3(0.4f, 0.2f, 0.1f))))); hitables.Add(new Sphere(new Vec3(4, 1, 0), 1, new Metal(new Vec3(0.7f, 0.6f, 0.5f), 0))); //this.world = new HitableList(hitables); this.world = new BVHNode(hitables, this.tMin, this.tMax, new Random()); Console.WriteLine("Populated Scene!"); }
public static IShape CreateShape(Transform o2w, Transform w2o, bool reverseOrientation, ParameterSet parameters, Dictionary<string, ITexture<double>> floatTextures, Dictionary<string, ITexture<Spectrum>> spectrumTextures) { int nvi = 0, npi = 0, nuvi = 0, nsi = 0, nni = 0; int[] vi = parameters.FindInt ("indices", ref nvi); Point[] P = parameters.FindPoint ("P", ref npi); double[] uvs = parameters.FindDouble ("uv", ref nuvi); if (uvs == null) uvs = parameters.FindDouble ("st", ref nuvi); bool discardDegnerateUVs = parameters.FindOneBool ("discarddegenerateUVs", false); // XXX should complain if uvs aren't an array of 2... if (uvs != null) { if (nuvi < 2 * npi) { uvs = null; } } if (vi == null || P == null) return null; Vector[] S = parameters.FindVector ("S", ref nsi); if (S != null && nsi != npi) { S = null; } Normal[] N = parameters.FindNormal ("N", ref nni); if (N != null && nni != npi) { N = null; } if (discardDegnerateUVs && uvs != null && N != null) { // if there are normals, check for bad uv's that // give degenerate mappings; discard them if so int vp = 0; for (int i = 0; i < nvi; i += 3,vp += 3) { double area = 0.5 * ((P[vi[vp + 0]] - P[vi[vp + 1]]) % (P[vi[vp + 2]] - P[vi[vp + 1]])).Length; if (area < 1E-07) continue; // ignore degenerate tris. if ((uvs[2 * vi[vp + 0]] == uvs[2 * vi[vp + 1]] && uvs[2 * vi[vp + 0] + 1] == uvs[2 * vi[vp + 1] + 1]) || (uvs[2 * vi[vp + 1]] == uvs[2 * vi[vp + 2]] && uvs[2 * vi[vp + 1] + 1] == uvs[2 * vi[vp + 2] + 1]) || (uvs[2 * vi[vp + 2]] == uvs[2 * vi[vp + 0]] && uvs[2 * vi[vp + 2] + 1] == uvs[2 * vi[vp + 0] + 1])) { uvs = null; break; } } } for (int i = 0; i < nvi; ++i) if (vi[i] >= npi) { return null; } ITexture<double> alphaTex = null; string alphaTexName = parameters.FindTexture ("alpha"); if (alphaTexName != "") { if (floatTextures.ContainsKey (alphaTexName)) alphaTex = floatTextures[alphaTexName]; } else if (parameters.FindOneDouble ("alpha", 1.0) == 0.0) alphaTex = new ConstantTexture<double> (0.0); return new TriangleMesh (o2w, w2o, reverseOrientation, nvi / 3, npi, vi, P, N, S, uvs, alphaTex); }
public CoverSceneRT2(double aspect) { Assembly assembly = Assembly.GetExecutingAssembly(); //string[] names = assembly.GetManifestResourceNames(); var resource_stream = assembly.GetManifestResourceStream("rt_2_the_next_week.raytrace.Resource.worldmap1.png"); var worldmap_texture = Texture.Create(resource_stream); var perlin_texture = NoiseTexture.Create(0.05, NoiseTexture.Type.SIN_Z); var hitables = new List <IHitable>(); var sampler = new Random(); var white = new Lambertian(ConstantTexture.Create(0.73, 0.73, 0.73)); var ground = new Lambertian(ConstantTexture.Create(0.48, 0.83, 0.53)); var light = new DiffuseLight(ConstantTexture.Create(7, 7, 7)); var emat = new Lambertian(worldmap_texture); var boxList1 = new List <IHitable>(); var nb = 20; for (int i = 0; i < nb; i++) { for (int j = 0; j < nb; j++) { double w = 100; var v_min = Vec3.Create(-1000 + i * w, 0, -1000 + j * w); var v_max = Vec3.Create(v_min.X + w, 100 * (sampler.NextDouble() + 0.01), v_min.Z + w); boxList1.Add(new Box(v_min, v_max, ground)); } } var boxList2 = new List <IHitable>(); int ns = 1000; for (int i = 0; i < ns; ++i) { boxList2.Add(new Sphere(Vec3.Create(165 * sampler.NextDouble(), 165 * sampler.NextDouble(), 165 * sampler.NextDouble()), 10, white)); } hitables.Add(new BVHNode(boxList1.ToArray(), 0, 1)); hitables.Add(new XZRect(123, 423, 147, 412, 554, light)); var center = Vec3.Create(400, 400, 200); hitables.Add(new MovingSphere(center, center + Vec3.Create(30, 0, 0), 0, 1, 50, new Lambertian(new ConstantTexture(Vec3.Create(0.7, 0.3, 0.1))))); hitables.Add(new Sphere(Vec3.Create(260, 150, 45), 50, new Dielectric(1.5))); hitables.Add(new Sphere(Vec3.Create(0, 150, 145), 50, new Metal(new ConstantTexture(Vec3.Create(0.8, 0.8, 0.9)), 10))); var boundary1 = new Sphere(Vec3.Create(360, 150, 145), 70, new Dielectric(1.5)); hitables.Add(boundary1); hitables.Add(new ConstantMedium(boundary1, 0.2, new ConstantTexture(Vec3.Create(0.2, 0.4, 0.5)))); var boundary2 = new Sphere(Vec3.Create(0), 5000, new Dielectric(1.5)); hitables.Add(new ConstantMedium(boundary2, 0.0001, new ConstantTexture(Vec3.Create(1.0, 1.0, 1.0)))); hitables.Add(new Sphere(Vec3.Create(400, 200, 400), 100, emat)); hitables.Add(new Sphere(Vec3.Create(220, 280, 300), 80, new Lambertian(perlin_texture))); hitables.Add(new Translate(new RotateY(new BVHNode(boxList2.ToArray(), 0, 1), 15), Vec3.Create(-100, 270, 395))); World = new BVHNode(hitables.ToArray(), 0, 1); var lookFrom = Vec3.Create(478, 278, -600); var lookAt = Vec3.Create(278, 278, 0); double dist_to_focus = 10; double aderpture = 0; double vfov = 40; Camera = Camera.CreateLookAt(lookFrom, lookAt, Vec3.Create(0, 1, 0), vfov, aspect, aderpture, dist_to_focus); }