Example #1
0
 void build10()
 {
     int ns = 49;
     world.ViewPlane.HRes = 800;
     world.ViewPlane.VRes = 700;
     world.ViewPlane.SetSampler(new Regular(ns));
     world.ViewPlane.MaxDepth = 10;
     world.Tracer = new Whitted(world);
     AmbientOccluder occ = new AmbientOccluder();
     occ.RadianceScale = 1.0f;
     occ.MinAmount = 0f;
     occ.Shadows = true;
     occ.Color = Vector3.One;
     occ.SetSampler(new MultiJittered(ns));
     world.AmbientLight = occ;
     Pinhole cam = new Pinhole();
     cam.Position = new Vector3(40, 30, 20);
     cam.Target = new Vector3(0, 0, 0);
     cam.Distance = 5000;
     cam.Zoom = 1.5f;
     world.Camera = cam;
     Sphere ss = new Sphere(new Vector3(2f, 0.5f, 1f), 0.5f);
     ss.Shadows = true;
     ss.SetMaterial(new Matte(0.25f, 0.5f, new Vector3(1f, 1f, 1f)) { Shadows = true });
     world.Objects.Add(ss);
     Matte matte = new Matte(0.25f, 0.5f, new Vector3(0.5f, 0, 0.5f));
     matte.Shadows = true;
     Box s = new Box(new Vector3(0, 0, 1), new Vector3(1, 1, 2));
     s.Shadows = true;
     s.SetMaterial(matte);
     world.Objects.Add(s);
     Matte m2 = new Matte(0.25f, 0, new Vector3(1, 1, 0));
     m2.Shadows = true;
     Box b2 = new Box(new Vector3(1, 1, 0), new Vector3(2, 2, 1));
     b2.SetMaterial(m2);
     b2.Shadows = true;
     //world.Objects.Add(b2);
     Matte matte2 = new Matte(0.75f, 0.5f, new Vector3(1, 1, 1));
     matte2.Shadows = true;
     Plane p = new Plane(Vector3.Zero, new Vector3(0, 1, 0));
     p.Shadows = true;
     p.SetMaterial(matte2);
     world.Objects.Add(p);
     Matte m5 = new Matte(0.75f, 0.1f, new Vector3(0, 0.5f, 1));
     m5.Shadows = true;
     Annulus an = new Annulus(new Vector3(1, 1.2f, 0), Vector3.Up, 0.4f, 0.2f);
     an.SetMaterial(m5);
     an.Shadows = true;
     world.Objects.Add(an);
     Matte m6 = new Matte(0.75f, 0.1f, new Vector3(1, 0, 0.4f));
     m6.Shadows = true;
     SolidCylinder sc = new SolidCylinder(0, 1, 0.5f);
     sc.Shadows = true;
     sc.SetMaterial(m6);
     world.Objects.Add(sc);
     PointLight pl = new PointLight();
     pl.Color = Vector3.One;
     pl.Position = new Vector3(4, 4, 0);
     pl.RadianceScale = 1.0f;
     pl.Shadows = true;
     world.Lights.Add(pl);
     float exp = 2000;
     Transparent sphere_material = new Transparent();
     sphere_material.SetSpecularRC(0.5f);
     sphere_material.SetExp(exp);
     sphere_material.SetIndexOfRefraction(1.5f);
     sphere_material.SetReflectiveRC(0.1f);
     sphere_material.SetTransmissionCoefficient(0.9f);
     Sphere sph = new Sphere(new Vector3(2f, 0.5f, 0f), 0.5f);
     sph.SetMaterial(sphere_material);
     world.Objects.Add(sph);
     Reflective smatte2 = new Reflective();
     smatte2.SetAmbientRC(0.25f);
     smatte2.SetDiffuseRC(0.5f);
     smatte2.SetRColor(new Vector3(1));
     smatte2.SetSpecularRC(0.15f);
     smatte2.SetExp(100);
     smatte2.SetReflectiveRC(0.75f);
     smatte2.SetCD(new Vector3(1));
     Sphere sphere = new Sphere(new Vector3(0, 2, 0), 0.4f);
     sphere.SetMaterial(smatte2);
     world.Objects.Add(sphere);
 }
Example #2
0
 void build8()
 {
     int ns = 256;
     world.ViewPlane.HRes = 400;
     world.ViewPlane.VRes = 400;
     world.ViewPlane.MaxDepth = 1;
     world.ViewPlane.SetSamples(ns);
     world.Tracer = new Whitted(world);
     AmbientOccluder occ = new AmbientOccluder();
     occ.RadianceScale = 1.0f;
     occ.MinAmount = 0f;
     occ.Shadows = true;
     occ.Color = Vector3.One;
     occ.SetSampler(new MultiJittered(ns));
     world.AmbientLight = occ;
     Pinhole cam = new Pinhole();
     cam.Position = new Vector3(40, 30, 20);
     cam.Target = new Vector3(0, 0, 0);
     cam.Distance = 5000;
     cam.Zoom = 1;
     world.Camera = cam;
     Reflective matte2 = new Reflective();
     matte2.SetAmbientRC(0.001f);
     matte2.SetDiffuseRC(0.5f);
     matte2.SetRColor(new Vector3(1));
     matte2.SetSpecularRC(0);
     matte2.SetExp(100);
     matte2.SetReflectiveRC(0.5f);
     matte2.SetCD(new Vector3(1));
     Sphere ss = new Sphere(new Vector3(2f, 0.5f, 1f), 0.5f);
     ss.Shadows = true;
     ss.SetMaterial(matte2);
     world.Objects.Add(ss);
     Matte matte = new Matte(0.25f, 0.5f, new Vector3(0.5f, 0, 0.5f));
     matte.Shadows = true;
     Box s = new Box(new Vector3(0, 0, 1), new Vector3(1, 1, 2));
     s.Shadows = true;
     s.SetMaterial(matte);
     world.Objects.Add(s);
     Matte m2 = new Matte(0.25f, 0, new Vector3(1, 1, 0));
     m2.Shadows = true;
     Box b2 = new Box(new Vector3(1, 1, 0), new Vector3(2, 2, 1));
     b2.SetMaterial(m2);
     b2.Shadows = true;
     //world.Objects.Add(b2);
     Plane p = new Plane(Vector3.Zero, new Vector3(0, 1, 0));
     p.Shadows = true;
     p.SetMaterial(new Matte(0.25f, 0.5f, new Vector3(1f, 1f, 1f)) { Shadows = true });
     world.Objects.Add(p);
     Matte m3 = new Matte(1, 1, Vector3.One);
     m3.Shadows = true;
     Disk d = new Disk(new Vector3(0f, 1.6f, 1), new Vector3(1, 1, 1), 0.5f);
     d.SetMaterial(m3);
     d.Shadows = true;
     world.Objects.Add(d);
     Matte m5 = new Matte(0.75f, 0.1f, new Vector3(0, 0.5f, 1));
     m5.Shadows = true;
     Annulus an = new Annulus(new Vector3(1, 1.2f, 0), Vector3.Up, 0.4f, 0.2f);
     an.SetMaterial(m5);
     an.Shadows = true;
     world.Objects.Add(an);
     Matte m6 = new Matte(0.75f, 0.1f, new Vector3(1, 0, 0.4f));
     m6.Shadows = true;
     SolidCylinder sc = new SolidCylinder(0, 1, 0.5f);
     sc.Shadows = true;
     sc.SetMaterial(m6);
     world.Objects.Add(sc);
     PointLight pl = new PointLight();
     pl.Color = Vector3.One;
     pl.Position = new Vector3(0, 4, 0);
     pl.RadianceScale = 1.0f;
     pl.Shadows = true;
     world.Lights.Add(pl);
 }
Example #3
0
 public static GeometricObject CreateObjectFromElement(this RElement ele, Dictionary<string, Texture> txts, ref bool instance)
 {
     string n = ele.Name;
     string name = getName(ele);
     bool shad = getShadow(ele);
     instance = !getInstance(ele);
     Material m = getMaterial(ele, txts);
     if (n == P.Obj.Sph)
     {
         Sphere sph = new Sphere(ele.Attributes[P.Pos].ToVector3(), ele.Attributes[P.Rad].ToFloat(), name);
         sph.SetShadows(shad);
         sph.SetMaterial(m);
         return sph;
     }
     else if (n == P.Obj.Box)
     {
         Box box = new Box(ele.Attributes[P.Min].ToVector3(), ele.Attributes[P.Max].ToVector3(), name);
         box.SetShadows(shad);
         box.SetMaterial(m);
         return box;
     }
     else if (n == P.Obj.Plane)
     {
         Plane p = new Plane(ele.Attributes[P.Pos].ToVector3(), ele.Attributes[P.Dir].ToVector3(), name);
         p.SetShadows(shad);
         p.SetMaterial(m);
         return p;
     }
     else if (n == P.Obj.Disk)
     {
         Disk d = new Disk(ele.Attributes[P.Pos].ToVector3(), ele.Attributes[P.Dir].ToVector3(), ele.Attributes[P.Rad].ToFloat(), name);
         d.SetShadows(shad);
         d.SetMaterial(m);
         return d;
     }
     else if (n == P.Obj.Annulus)
     {
         Annulus d = new Annulus(ele.Attributes[P.Pos].ToVector3(), ele.Attributes[P.Dir].ToVector3(), float.Parse(ele.Attributes[P.IRad].Value), float.Parse(ele.Attributes[P.ORad].Value), name);
         d.SetShadows(shad);
         d.SetMaterial(m);
         return d;
     }
     else if (n == P.Obj.Tri)
     {
         Triangle t = new Triangle(ele.Attributes["P1"].ToVector3(), ele.Attributes["P2"].ToVector3(), ele.Attributes["P3"].ToVector3(), name);
         t.SetShadows(shad);
         t.SetMaterial(m);
         return t;
     }
     else if (n == P.Obj.STri)
     {
         SmoothTriangle t = new SmoothTriangle(ele.Attributes["P1"].ToVector3(), ele.Attributes["P2"].ToVector3(), ele.Attributes["P3"].ToVector3(), name);
         t.SetShadows(shad);
         t.SetMaterial(m);
         return t;
     }
     else if (n == P.Obj.Rect)
     {
         Rectangle r = new Rectangle(ele.Attributes["P"].ToVector3(), GetVector(ele.Attributes["A"]), GetVector(ele.Attributes["B"]), name);
         r.SetShadows(shad);
         r.SetMaterial(m);
         return r;
     }
     else if (n == P.Obj.OCyl)
     {
         OpenCylinder oc = new OpenCylinder(float.Parse(ele.Attributes[P.Bottom].Value), float.Parse(ele.Attributes[P.Top].Value), float.Parse(ele.Attributes[P.Rad].Value), name);
         oc.SetShadows(shad);
         oc.SetMaterial(m);
         return oc;
     }
     else if (n == P.Obj.Cyl)
     {
         SolidCylinder oc = new SolidCylinder(float.Parse(ele.Attributes[P.Bottom].Value), float.Parse(ele.Attributes[P.Top].Value), float.Parse(ele.Attributes[P.Rad].Value), name);
         oc.SetShadows(shad);
         oc.SetMaterial(m);
         return oc;
     }
     else if (n == P.Obj.OC)
     {
         OpenCone oc = new OpenCone(float.Parse(ele.Attributes[P.Rad].Value), float.Parse(ele.Attributes[P.Height].Value), name);
         oc.SetShadows(shad);
         oc.SetMaterial(m);
         return oc;
     }
     else if (n == P.Obj.COCyl)
     {
         ConvexOpenCylinder oc = new ConvexOpenCylinder(float.Parse(ele.Attributes[P.Bottom].Value), float.Parse(ele.Attributes[P.Top].Value), float.Parse(ele.Attributes[P.Rad].Value), name);
         oc.SetShadows(shad);
         oc.SetMaterial(m);
         return oc;
     }
     else if (n == P.Obj.Ins)
     {
         Instance ins = new Instance(GeometricObject.GetObject(ele.Attributes["ObjectRef"].Value), name);
         ins.SetShadows(shad);
         transform(ins, ele);
         if (m != null)
             ins.SetMaterial(m);
         return ins;
     }
     else if (n == P.Obj.Tor)
     {
         Torus tor = new Torus(ele.Attributes[P.Srad].ToFloat(), ele.Attributes[P.Trad].ToFloat(), name);
         tor.SetShadows(shad);
         if (m != null)
             tor.SetMaterial(m);
         return tor;
     }
     else if (n == P.Obj.ConSph)
     {
         ConcaveSphere conc = new ConcaveSphere(ele.Attributes[P.Pos].ToVector3(), ele.Attributes[P.Rad].ToFloat(), name);
         conc.SetShadows(shad);
         if (m != null)
             conc.SetMaterial(m);
         return conc;
     }
     else if (n == P.Obj.ConHsph)
     {
         ConcaveHemisphere conc = new ConcaveHemisphere(ele.Attributes[P.Pos].ToVector3(), ele.Attributes[P.Rad].ToFloat(), name);
         conc.SetShadows(shad);
         if (m != null)
             conc.SetMaterial(m);
         return conc;
     }
     else if (n == P.Obj.Mesh)
     {
         Mesh mesh = new Mesh(name);
         mesh.SetShadows(shad);
         getVertices(mesh, ele);
         getNormals(mesh, ele);
         getFaces(mesh, ele);
         if (m != null)
             mesh.SetMaterial(m);
         return mesh;
     }
     else
     {
         return getCObject(ele);
     }
 }
Example #4
0
 void build13()
 {
     int ns = 9;
     world.ViewPlane.HRes = 400;
     world.ViewPlane.VRes = 400;
     world.ViewPlane.SetSampler(new MultiJittered(ns));
     world.ViewPlane.MaxDepth = 10;
     world.Tracer = new Whitted(world);
     AmbientOccluder occ = new AmbientOccluder();
     occ.RadianceScale = 1.0f;
     occ.MinAmount = 0f;
     occ.Shadows = true;
     occ.Color = Vector3.One;
     occ.SetSampler(new MultiJittered(ns));
     world.AmbientLight = occ;
     Pinhole cam = new Pinhole();
     cam.Position = new Vector3(0, 20, -60);
     cam.Target = new Vector3(0, 7.5f, 0);
     cam.Distance = 200;
     cam.Zoom = 3.5f;
     world.Camera = cam;
     float refl = 0.8f;
     float spec = 0.2f;
     float amb = 0.2f;
     float diff = 0.2f;
     float exp = 100;
     Plane p = new Plane(Vector3.Zero, new Vector3(0, 1, 0));
     p.Shadows = true;
     p.SetMaterial(new Matte(0.75f, 0.75f, new Vector3(0.56, 0.45, 0.32)));
     world.Objects.Add(p);
     ImageTexture im = new ImageTexture();
     Disque.Raytracer.Textures.Image imm = Extensions.CreateFromBitmap(@"C:\Users\Belal\Downloads\Earth_Diffuse_2.jpg");
     im.SetImage(imm);
     im.SetMapping(new SphericalMap());
     SV_Phong sphere_m = new SV_Phong();
     sphere_m.SetCD(im);
     sphere_m.SetSpecularColor(new ConstantColor(Vector3.One));
     sphere_m.SetExp(1);
     sphere_m.SetSpecularRC(1f);
     sphere_m.SetDiffuseRC(1f);
     sphere_m.SetAmbientRC(1f);
     Sphere sphere = new Sphere(new Vector3(0, 0f, 0), 1f);
     ins = new Instance(sphere);
     ins.SetMaterial(sphere_m);
     ins.RotateY(45);
     ins.Scale(new Vector3(10));
     ins.Translate(new Vector3(0, 13, 0));
     Reflective smatte2 = new Reflective();
     smatte2.SetAmbientRC(amb);
     smatte2.SetDiffuseRC(diff);
     smatte2.SetCD(new Vector3(1, 0, 0));
     smatte2.SetRColor(new Vector3(1));
     smatte2.SetSpecularRC(spec);
     smatte2.SetExp(exp);
     smatte2.SetReflectiveRC(refl);
     SolidCylinder sc = new SolidCylinder(0, 3, 13);
     sc.SetMaterial(new Matte(0.5f, 0.5f, new Vector3(0.5f, 0.5f, 0)));
     world.Objects.Add(sc);
     world.Objects.Add(ins);
     PointLight light = new PointLight();
     light.Color = Vector3.One;
     light.Position = new Vector3(0, 40, -20);
     light.RadianceScale = 2f;
     world.Lights.Add(light);
 }
Example #5
0
 static GeometricObject getCObject(XElement ele)
 {
     string typ = ele.Name.LocalName;
     if (typ == "Group")
     {
         bool va = false;
         Group group = new Group(getAttribute("Name", ele));
         foreach (XElement xele in ele.Elements())
             group.AddObject(getPObject(ele, ref va));
         group.SetShadows(bool.Parse(getAttribute("Shadows", ele)));
         return group;
     }
     else if (typ == "SolidCone")
     {
         SolidCone oc = new SolidCone(float.Parse(getAttribute("Radius", ele)), float.Parse(getAttribute("Height", ele)), getAttribute("Name", ele));
         oc.SetShadows(bool.Parse(getAttribute("Shadows", ele)));
         oc.SetMaterial(getMaterial(ele));
         return oc;
     }
     else if (typ == "SolidCylinder")
     {
         SolidCylinder oc = new SolidCylinder(float.Parse(getAttribute("Bottom", ele)), float.Parse(getAttribute("Top", ele)), float.Parse(getAttribute("Radius", ele)), getAttribute("Name", ele));
         oc.SetShadows(bool.Parse(getAttribute("Shadows", ele)));
         oc.SetMaterial(getMaterial(ele));
         return oc;
     }
     else if (typ == "ThickAnnulus")
     {
         ThickAnnulus oc = new ThickAnnulus(float.Parse(getAttribute("Bottom", ele)), float.Parse(getAttribute("Top", ele)), float.Parse(getAttribute("InnerRadius", ele)), float.Parse(getAttribute("OuterRadius", ele)), getAttribute("Name", ele));
         oc.SetShadows(bool.Parse(getAttribute("Shadows", ele)));
         oc.SetMaterial(getMaterial(ele));
         return oc;
     }
     throw new Exception("No recognized elements");
 }