void build12() { int ns = 256; world.ViewPlane.HRes = 400; world.ViewPlane.VRes = 400; 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(10, 20, 40); cam.Target = new Vector3(0, 0, 0); cam.Distance = 200; cam.Zoom = 3f; world.Camera = cam; 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); Transparent smatte2 = new Transparent(); smatte2.SetIndexOfRefraction(1.37896f); smatte2.SetReflectiveRC(0.1f); smatte2.SetExp(2000); smatte2.SetTransmissionCoefficient(0.9f); smatte2.SetSpecularColor(new Vector3(1)); smatte2.SetSpecularRC(0.5f); Sphere s = new Sphere(new Vector3(0, 7, 0), 5); s.SetMaterial(smatte2); world.Objects.Add(s); Matte stage_m = new Matte(0.5f, 0.5f, new Vector3(1, 0, 0)); PointLight light = new PointLight(); light.Color = Vector3.One; light.Position = new Vector3(12, 12, 12); light.RadianceScale = 1.0f; world.Lights.Add(light); Matte wall_m = new Matte(0.75f, 0.75f, new Vector3(1)); Box b = getbox(new Vector3(-20, 5, 0), new Vector3(2, 50, 50)); b.SetMaterial(wall_m); Box b2 = getbox(new Vector3(0, 5, -20), new Vector3(50, 50, 2)); b2.SetMaterial(wall_m); world.Objects.Add(b2); world.Objects.Add(b); Box stage = getbox(new Vector3(0, 1, 0), new Vector3(5, 2, 5)); stage.SetMaterial(stage_m); world.Objects.Add(stage); }
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); }
public static Material CreateMaterialFromElement(this RElement ele, Dictionary<string, Texture> textures) { string n = ele.Name; bool shad = getShadow(ele); Sampler s = null; if (ele.Attributes.ContainsKey(P.Sampler)) { s = ele.Attributes[P.Sampler].CreateSamplerFromAttribute(ele.Attributes[P.Samples].ToInt()); } if (n == P.Mate.Matt) { Matte m = new Matte(ele.Attributes[P.AmbRefCoeff].ToFloat(), ele.Attributes[P.DiffRefCoeff].ToFloat(), ele.Attributes[P.Col].ToVector3()); m.Shadows = shad; if (s != null) m.SetSampler(s); return m; } else if (n == P.Mate.Pho) { Phong p = new Phong(); p.SetSpecularColor(ele.Attributes[P.SpCol].ToVector3()); p.SetExp(ele.Attributes[P.Exp].ToFloat()); p.SetCD(GetVector(ele.Attributes[P.Col])); p.SetAmbientRC(ele.Attributes[P.AmbRefCoeff].ToFloat()); p.SetDiffuseRC(ele.Attributes[P.DiffRefCoeff].ToFloat()); p.SetSpecularRC(ele.Attributes[P.SpecCoeff].ToFloat()); p.Shadows = shad; if (s != null) p.SetSampler(s); return p; } else if (n == P.Mate.Refl) { Reflective r = new Reflective(); r.SetSpecularColor(ele.Attributes[P.SpCol].ToVector3()); r.SetSpecularRC(ele.Attributes[P.SpecCoeff].ToFloat()); r.SetRColor(GetVector(ele.Attributes[P.RefCol])); r.SetReflectiveRC(ele.Attributes[P.RefCoeff].ToFloat()); r.SetExp(ele.Attributes[P.Exp].ToFloat()); r.SetCD(GetVector(ele.Attributes[P.Col])); r.SetAmbientRC(ele.Attributes[P.AmbRefCoeff].ToFloat()); r.SetDiffuseRC(ele.Attributes[P.DiffRefCoeff].ToFloat()); r.Shadows = shad; if (s != null) r.SetSampler(s); return r; } else if (n == P.Mate.Trans) { Transparent t = new Transparent(); t.SetSpecularColor(ele.Attributes[P.SpCol].ToVector3()); t.SetSpecularRC(ele.Attributes[P.SpecCoeff].ToFloat()); t.SetReflectiveRC(ele.Attributes[P.RefCoeff].ToFloat()); t.SetExp(ele.Attributes[P.Exp].ToFloat()); t.SetCD(GetVector(ele.Attributes[P.Col])); t.SetAmbientRC(ele.Attributes[P.AmbRefCoeff].ToFloat()); t.SetDiffuseRC(ele.Attributes[P.DiffRefCoeff].ToFloat()); t.SetIndexOfRefraction(ele.Attributes[P.IOR].ToFloat()); t.SetTransmissionCoefficient(ele.Attributes[P.TransCoeff].ToFloat()); t.Shadows = shad; if (s != null) t.SetSampler(s); return t; } else if (n == P.Mate.GlosRef) { GlossyReflective p = new GlossyReflective(); p.SetSpecularColor(ele.Attributes[P.SpCol].ToVector3()); p.SetSpecularRC(ele.Attributes[P.SpecCoeff].ToFloat()); p.SetExp(ele.Attributes[P.Exp].ToFloat()); p.SetCD(ele.Attributes[P.Col].ToVector3()); p.SetAmbientRC(ele.Attributes[P.AmbRefCoeff].ToFloat()); p.SetDiffuseRC(ele.Attributes[P.DiffRefCoeff].ToFloat()); p.SetCR(ele.Attributes[P.GlosCol].ToVector3()); p.SetKR(ele.Attributes[P.GlosCoeff].ToFloat()); p.Shadows = shad; if (s != null) p.SetSampler(s); return p; } else if (n == P.Mate.Emis) { Emissive em = new Emissive(); em.Color = ele.Attributes[P.Col].ToVector3(); em.Radiance = ele.Attributes[P.Radi].ToFloat(); em.Shadows = shad; if (s != null) em.SetSampler(s); return em; } else if (n == (P.Text + P.Mate.Matt)) { SV_Matte p = new SV_Matte(ele.Attributes[P.AmbRefCoeff].ToFloat(), ele.Attributes[P.DiffRefCoeff].ToFloat(), textures[ele.Attributes[P.Text].Value]) { Shadows = shad }; if (s != null) p.SetSampler(s); return p; } else if (n == (P.Text + P.Mate.Pho)) { SV_Phong p = new SV_Phong(); p.SetSpecularColor(textures[ele.Attributes[P.SpTxt].Value]); p.SetExp(ele.Attributes[P.Exp].ToFloat()); p.SetCD(textures[ele.Attributes[P.Text].Value]); p.SetAmbientRC(ele.Attributes[P.AmbRefCoeff].ToFloat()); p.SetDiffuseRC(ele.Attributes[P.DiffRefCoeff].ToFloat()); p.Shadows = shad; if (s != null) p.SetSampler(s); return p; } throw new Exception(); //Create an exception for not found elements; }
void build9() { int ns = 256; world.ViewPlane.HRes = 400; world.ViewPlane.VRes = 400; world.ViewPlane.MaxDepth = 20; world.ViewPlane.SetSampler(new Hammersley(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 Jittered(ns)); world.AmbientLight = occ; Pinhole cam = new Pinhole(); cam.Position = new Vector3(10, 10, 10); cam.Target = new Vector3(0, 0, 0); cam.Distance = 5000; cam.Zoom = 1f; world.Camera = cam; Matte floor_material = new Matte(0.75f, 0.25f, Vector3.One); Plane floor = new Plane(Vector3.Zero, Vector3.Up); floor.SetMaterial(floor_material); world.Objects.Add(floor); Reflective matte2 = new Reflective(); matte2.SetAmbientRC(0.25f); matte2.SetDiffuseRC(0.5f); matte2.SetRColor(new Vector3(1)); matte2.SetSpecularRC(0.15f); matte2.SetExp(100); matte2.SetReflectiveRC(0.75f); matte2.SetCD(new Vector3(1)); Box wall1 = new Box(Vector3.Zero, new Vector3(0.5f, 0.5f, 0.1f)); Box wall2 = new Box(Vector3.Zero, new Vector3(0.1f, 0.5f, 0.5f)); wall2.SetMaterial(matte2); wall1.SetMaterial(matte2); float exp = 2000; Transparent sphere_material = new Transparent(); sphere_material.SetSpecularRC(0.5f); sphere_material.SetExp(exp); sphere_material.SetIndexOfRefraction(1.5f); sphere_material.SetTransmissionCoefficient(0.1f); sphere_material.SetTransmissionCoefficient(0.9f); Sphere s = new Sphere(new Vector3(0.3f, 0.1f, 0.3f), 0.1f); s.SetMaterial(sphere_material); world.Objects.Add(s); world.Objects.Add(wall1); world.Objects.Add(wall2); PointLight pl = new PointLight(); pl.RadianceScale = 1.0f; pl.Color = Vector3.One; pl.Position = new Vector3(0, 8, 0); world.Lights.Add(pl); }
static Material getMaterial(XElement xele) { foreach (XElement ele in xele.Elements()) { string typ = ele.Name.LocalName; if (typ == "Matte") { return new Matte(float.Parse(getAttribute("ReflectionCoff", ele)), float.Parse(getAttribute("DiffuseCoff", ele)), getVector(getAttribute("Color", ele))) { Shadows = bool.Parse(getAttribute("Shadows", ele)) }; } else if (typ == "Phong") { Phong p = new Phong(); p.SetSpecularColor(getVector(getAttribute("SpecularColor", ele))); p.SetExp(float.Parse(getAttribute("Exponent", ele))); p.SetCD(getVector(getAttribute("Color", ele))); p.SetAmbientRC(float.Parse(getAttribute("AmbientRelfectionCoff", ele))); p.SetDiffuseRC(float.Parse(getAttribute("DiffuseRelfectionCoff", ele))); p.Shadows = bool.Parse(getAttribute("Shadows", ele)); return p; } else if (typ == "Reflective") { Reflective r = new Reflective(); r.SetSpecularColor(getVector(getAttribute("SpecularColor", ele))); r.SetSpecularRC(float.Parse(getAttribute("SpecularCoff", ele))); r.SetRColor(getVector(getAttribute("ReflectiveColor", ele))); r.SetReflectiveRC(float.Parse(getAttribute("ReflectiveCoff", ele))); r.SetExp(float.Parse(getAttribute("Exponent", ele))); r.SetCD(getVector(getAttribute("Color", ele))); r.SetAmbientRC(float.Parse(getAttribute("AmbientRelfectionCoff", ele))); r.SetDiffuseRC(float.Parse(getAttribute("DiffuseRelfectionCoff", ele))); r.Shadows = bool.Parse(getAttribute("Shadows", ele)); return r; } else if (typ == "Transparent") { Transparent t = new Transparent(); t.SetSpecularColor(getVector(getAttribute("SpecularColor", ele))); t.SetSpecularRC(float.Parse(getAttribute("SpecularCoff", ele))); t.SetReflectiveRC(float.Parse(getAttribute("ReflectiveCoff", ele))); t.SetExp(float.Parse(getAttribute("Exponent", ele))); t.SetCD(getVector(getAttribute("Color", ele))); t.SetAmbientRC(float.Parse(getAttribute("AmbientRelfectionCoff", ele))); t.SetDiffuseRC(float.Parse(getAttribute("DiffuseRelfectionCoff", ele))); t.SetIndexOfRefraction(float.Parse(getAttribute("IOR", ele))); t.SetTransmissionCoefficient(float.Parse(getAttribute("TransCoff", ele))); t.Shadows = bool.Parse(getAttribute("Shadows", ele)); return t; } else if (typ == "TextureMatte") { return new SV_Matte(float.Parse(getAttribute("ReflectionCoff", ele)), float.Parse(getAttribute("DiffuseCoff", ele)), textures[getAttribute("Texture", ele)]); } else if (typ == "TexturePhong") { SV_Phong p = new SV_Phong(); p.SetSpecularColor(textures[getAttribute("SpecularTexture", ele)]); p.SetExp(float.Parse(getAttribute("Exponent", ele))); p.SetCD(textures[getAttribute("Texture", ele)]); p.SetAmbientRC(float.Parse(getAttribute("AmbientRelfectionCoff", ele))); p.SetDiffuseRC(float.Parse(getAttribute("DiffuseRelfectionCoff", ele))); p.Shadows = bool.Parse(getAttribute("Shadows", ele)); return p; } break; } throw new ElementNotFound("Material"); }