Пример #1
0
 public override Light Clone()
 {
     Directional s = new Directional();
     s.RadianceScale = RadianceScale;
     s.Color = Color;
     s.Direction = Direction;
     return s;
 }
Пример #2
0
        void build3()
        {
            world.ViewPlane = new ViewPlane();
            world.ViewPlane.HRes = world.ViewPlane.VRes = 400;
            world.ViewPlane.S = 0.5f;
            world.ViewPlane.NumSamples = 1;
            world.ViewPlane.SetSamples(1);
            Ambient ambient_ptr = new Ambient();
            ambient_ptr.RadianceScale = (1.0f);
            world.AmbientLight = (ambient_ptr);
            world.Tracer = new RayCast(world);
            Pinhole pinhole_ptr = new Pinhole();
            pinhole_ptr.Position = new Vector3(0, 500, 500);
            pinhole_ptr.Target = new Vector3(0, 25, 0);
            pinhole_ptr.Distance = (600.0f);
            pinhole_ptr.ComputeUVW();
            world.Camera = (pinhole_ptr);
            Directional light_ptr1 = new Directional();
            light_ptr1.Direction = Vector3.Normalize(new Vector3(100, 100, 200));
            light_ptr1.RadianceScale = 3.0f;
            world.Lights.Add(light_ptr1);
            Vector3 yellow = new Vector3(1, 1, 0);										// yellow
            Vector3 brown = new Vector3(0.71f, 0.40f, 0.16f);								// brown
            Vector3 darkGreen = new Vector3(0.0f, 0.41f, 0.41f);							// darkGreen
            Vector3 orange = new Vector3(1f, 0.75f, 0f);									// orange
            Vector3 green = new Vector3(0f, 0.6f, 0.3f);									// green
            Vector3 lightGreen = new Vector3(0.65f, 1, 0.30f);								// light green
            Vector3 darkYellow = new Vector3(0.61f, 0.61f, 0);								// dark yellow
            Vector3 lightPurple = new Vector3(0.65f, 0.3f, 1);								// light purple
            Vector3 darkPurple = new Vector3(0.5f, 0, 1);									// dark purple
            Vector3 grey = new Vector3(0.25f);											// grey	
            float ka = 0.25f;
            float kd = 0.75f;
            Matte matte_ptr1 = new Matte(ka, kd, yellow);
            Sphere sphere_ptr1 = new Sphere(new Vector3(5, 3, 0), 30);
            sphere_ptr1.SetMaterial(matte_ptr1);   							// yellow
            world.Objects.Add(sphere_ptr1);

            Matte matte_ptr2 = new Matte(ka, kd, brown);
            Sphere sphere_ptr2 = new Sphere(new Vector3(45, -7, -60), 20);
            sphere_ptr2.SetMaterial((matte_ptr2));								// brown
            world.Objects.Add(sphere_ptr2);
            Matte matte_ptr3 = new Matte(ka, kd, darkGreen);
            Sphere sphere_ptr3 = new Sphere(new Vector3(40, 43, -100), 17);
            sphere_ptr3.SetMaterial((matte_ptr3));								// dark green
            world.Objects.Add(sphere_ptr3);
            Matte matte_ptr4 = new Matte(ka, kd, orange);
            Sphere sphere_ptr4 = new Sphere(new Vector3(-20, 28, -15), 20);
            sphere_ptr4.SetMaterial((matte_ptr4));							// orange
            world.Objects.Add(sphere_ptr4);
            Matte matte_ptr5 = new Matte(ka, kd, green);
            Sphere sphere_ptr5 = new Sphere(new Vector3(-25, -7, -35), 27);
            sphere_ptr5.SetMaterial((matte_ptr5));								// green
            world.Objects.Add(sphere_ptr5);
            Matte matte_ptr6 = new Matte(ka, kd, lightGreen);
            Sphere sphere_ptr6 = new Sphere(new Vector3(20, -27, -35), 25);
            sphere_ptr6.SetMaterial((matte_ptr6));								// light green
            world.Objects.Add(sphere_ptr6);
            Matte matte_ptr7 = new Matte(ka, kd, green);
            Sphere sphere_ptr7 = new Sphere(new Vector3(35, 18, -35), 22);
            sphere_ptr7.SetMaterial((matte_ptr7));   							// green
            world.Objects.Add(sphere_ptr7);
            Matte matte_ptr8 = new Matte(ka, kd, brown);
            Sphere sphere_ptr8 = new Sphere(new Vector3(-57, -17, -50), 15);
            sphere_ptr8.SetMaterial((matte_ptr8));								// brown
            world.Objects.Add(sphere_ptr8);
            Matte matte_ptr9 = new Matte(ka, kd, lightGreen);
            Sphere sphere_ptr9 = new Sphere(new Vector3(-47, 16, -80), 23);
            sphere_ptr9.SetMaterial((matte_ptr9));								// light green
            world.Objects.Add(sphere_ptr9);
            Matte matte_ptr10 = new Matte(ka, kd, darkGreen);
            Sphere sphere_ptr10 = new Sphere(new Vector3(-15, -32, -60), 22);
            sphere_ptr10.SetMaterial((matte_ptr10));     						// dark green
            world.Objects.Add(sphere_ptr10);
            Matte matte_ptr11 = new Matte(ka, kd, darkYellow);
            Sphere sphere_ptr11 = new Sphere(new Vector3(-35, -37, -80), 22);
            sphere_ptr11.SetMaterial((matte_ptr11));							// dark yellow
            world.Objects.Add(sphere_ptr11);
            Matte matte_ptr12 = new Matte(ka, kd, darkYellow);
            Sphere sphere_ptr12 = new Sphere(new Vector3(10, 43, -80), 22);
            sphere_ptr12.SetMaterial((matte_ptr12));							// dark yellow
            world.Objects.Add(sphere_ptr12);
            Matte matte_ptr13 = new Matte(ka, kd, darkYellow);
            Sphere sphere_ptr13 = new Sphere(new Vector3(30, -7, -80), 10);
            sphere_ptr13.SetMaterial((matte_ptr13));
            world.Objects.Add(sphere_ptr13);											// dark yellow (hidden)
            Matte matte_ptr14 = new Matte(ka, kd, darkGreen);
            Sphere sphere_ptr14 = new Sphere(new Vector3(-40, 48, -110), 18);
            sphere_ptr14.SetMaterial((matte_ptr14)); 							// dark green
            world.Objects.Add(sphere_ptr14);
            Matte matte_ptr15 = new Matte(ka, kd, brown);
            Sphere sphere_ptr15 = new Sphere(new Vector3(-10, 53, -120), 18);
            sphere_ptr15.SetMaterial((matte_ptr15)); 							// brown
            world.Objects.Add(sphere_ptr15);
            Matte matte_ptr16 = new Matte(ka, kd, lightPurple);
            Sphere sphere_ptr16 = new Sphere(new Vector3(-55, -52, -100), 10);
            sphere_ptr16.SetMaterial((matte_ptr16));							// light purple
            world.Objects.Add(sphere_ptr16);
            Matte matte_ptr17 = new Matte(ka, kd, brown);
            Sphere sphere_ptr17 = new Sphere(new Vector3(5, -52, -100), 15);
            sphere_ptr17.SetMaterial((matte_ptr17));							// browm
            world.Objects.Add(sphere_ptr17);
            Matte matte_ptr18 = new Matte(ka, kd, darkPurple);
            Sphere sphere_ptr18 = new Sphere(new Vector3(-20, -57, -120), 15);
            sphere_ptr18.SetMaterial((matte_ptr18));							// dark purple
            world.Objects.Add(sphere_ptr18);
            Matte matte_ptr19 = new Matte(ka, kd, darkGreen);
            Sphere sphere_ptr19 = new Sphere(new Vector3(55, -27, -100), 17);
            sphere_ptr19.SetMaterial((matte_ptr19));							// dark green
            world.Objects.Add(sphere_ptr19);

            Matte matte_ptr20 = new Matte(ka, kd, brown);
            Sphere sphere_ptr20 = new Sphere(new Vector3(50, -47, -120), 15);
            sphere_ptr20.SetMaterial((matte_ptr20));							// browm
            world.Objects.Add(sphere_ptr20);

            Matte matte_ptr21 = new Matte(ka, kd, lightPurple);
            Sphere sphere_ptr21 = new Sphere(new Vector3(70, -42, -150), 10);
            sphere_ptr21.SetMaterial((matte_ptr21));							// light purple
            world.Objects.Add(sphere_ptr21);

            Matte matte_ptr22 = new Matte(ka, kd, lightPurple);
            Sphere sphere_ptr22 = new Sphere(new Vector3(5, 73, -130), 12);
            sphere_ptr22.SetMaterial((matte_ptr22));							// light purple
            world.Objects.Add(sphere_ptr22);

            Matte matte_ptr23 = new Matte(ka, kd, darkPurple);
            Sphere sphere_ptr23 = new Sphere(new Vector3(66, 21, -130), 13);
            sphere_ptr23.SetMaterial((matte_ptr23));							// dark purple
            world.Objects.Add(sphere_ptr23);

            Matte matte_ptr24 = new Matte(ka, kd, lightPurple);
            Sphere sphere_ptr24 = new Sphere(new Vector3(72, -12, -140), 12);
            sphere_ptr24.SetMaterial((matte_ptr24));							// light purple
            world.Objects.Add(sphere_ptr24);

            Matte matte_ptr25 = new Matte(ka, kd, lightPurple);
            Sphere sphere_ptr25 = new Sphere(new Vector3(64, 5, -160), 11);
            sphere_ptr25.SetMaterial((matte_ptr25));					 		// green
            world.Objects.Add(sphere_ptr25);

            Matte matte_ptr26 = new Matte(ka, kd, lightPurple);
            Sphere sphere_ptr26 = new Sphere(new Vector3(55, 38, -160), 12);
            sphere_ptr26.SetMaterial((matte_ptr26));							// light purple
            world.Objects.Add(sphere_ptr26);
            Matte matte_ptr27 = new Matte(ka, kd, lightPurple);
            Sphere sphere_ptr27 = new Sphere(new Vector3(-73, -2, -160), 12);
            sphere_ptr27.SetMaterial((matte_ptr27));							// light purple
            world.Objects.Add(sphere_ptr27);
            Matte matte_ptr28 = new Matte(ka, kd, darkPurple);
            Sphere sphere_ptr28 = new Sphere(new Vector3(30, -62, -140), 15);
            sphere_ptr28.SetMaterial((matte_ptr28)); 							// dark purple
            world.Objects.Add(sphere_ptr28);
            Matte matte_ptr29 = new Matte(ka, kd, darkPurple);
            Sphere sphere_ptr29 = new Sphere(new Vector3(25, 63, -140), 15);
            sphere_ptr29.SetMaterial((matte_ptr29));							// dark purple
            world.Objects.Add(sphere_ptr29);
            Matte matte_ptr30 = new Matte(ka, kd, darkPurple);
            Sphere sphere_ptr30 = new Sphere(new Vector3(-60, 46, -140), 15);
            sphere_ptr30.SetMaterial((matte_ptr30)); 							// dark purple
            world.Objects.Add(sphere_ptr30);
            Matte matte_ptr31 = new Matte(ka, kd, lightPurple);
            Sphere sphere_ptr31 = new Sphere(new Vector3(-30, 68, -130), 12);
            sphere_ptr31.SetMaterial((matte_ptr31)); 							// light purple
            world.Objects.Add(sphere_ptr31);
            Matte matte_ptr32 = new Matte(ka, kd, green);
            Sphere sphere_ptr32 = new Sphere(new Vector3(58, 56, -180), 11);
            sphere_ptr32.SetMaterial((matte_ptr32));							//  green
            world.Objects.Add(sphere_ptr32);
            Matte matte_ptr33 = new Matte(ka, kd, green);
            Sphere sphere_ptr33 = new Sphere(new Vector3(-63, -39, -180), 11);
            sphere_ptr33.SetMaterial((matte_ptr33));							// green 
            world.Objects.Add(sphere_ptr33);
            Matte matte_ptr34 = new Matte(ka, kd, lightPurple);
            Sphere sphere_ptr34 = new Sphere(new Vector3(46, 68, -200), 10);
            sphere_ptr34.SetMaterial((matte_ptr34));							// light purple
            world.Objects.Add(sphere_ptr34);
            Matte matte_ptr35 = new Matte(ka, kd, lightPurple);
            Sphere sphere_ptr35 = new Sphere(new Vector3(-3, -72, -130), 12);
            sphere_ptr35.SetMaterial((matte_ptr35));							// light purple
            world.Objects.Add(sphere_ptr35);
            Matte matte_ptr36 = new Matte(ka, kd, grey);
            Disque.Raytracer.GeometricObjects.Primitives.Plane plane_ptr = new Plane(new Vector3(0, 0, -150), new Vector3(0, 0, 1));
            plane_ptr.SetMaterial((matte_ptr36));
            world.Objects.Add(plane_ptr);
        }
Пример #3
0
 void build2()
 {
     int ns = 100;
     world.ViewPlane = new ViewPlane();
     world.ViewPlane.HRes = world.ViewPlane.VRes = 400;
     world.ViewPlane.SetSamples(ns);
     world.Tracer = new RayCast(world);
     MultiJittered sampler = new MultiJittered(ns);
     AmbientOccluder occulder = new AmbientOccluder();
     occulder.RadianceScale = 1.0f;
     occulder.Color = Vector3.One;
     occulder.MinAmount = 0.0f;
     occulder.SetSampler(sampler);
     occulder.Shadows = true;
     world.AmbientLight = occulder;
     Directional light_ptr = new Directional();
     light_ptr.Direction = Vector3.Normalize(new Vector3(100, 100, 100));
     light_ptr.RadianceScale = 1.0f;
     light_ptr.Shadows = true;
     light_ptr.Color = new Vector3(1);
     world.Lights.Add(light_ptr);
     Pinhole cam = new Pinhole();
     cam.Position = new Vector3(25, 20, 45);
     cam.Target = new Vector3(0, 1, 0);
     cam.Distance = 5000;
     world.Camera = cam;
     Matte matte = new Matte(0.25f, 0.7f, new Vector3(1, 1, 0));
     matte.Shadows = true;
     Sphere s = new Sphere(new Vector3(0, 1, 0), 1);
     s.Shadows = true;
     s.SetMaterial(matte);
     world.Objects.Add(s);
     Matte matte2 = new Matte(0.75f, 0, 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);
 }
Пример #4
0
 public static Light CreateLightFromElement(this RElement ele, int ns)
 {
     bool shad = getShadow(ele);
     float rad = ele.Attributes[P.Radi].ToFloat();
     string n = ele.Name;
     if (n == P.Lights.Amb)
     {
         Ambient amb = new Ambient();
         amb.RadianceScale = rad;
         amb.Color = ele.Attributes[P.Col].ToVector3();
         amb.Shadows = shad;
         return amb;
     }
     else if (n == P.Lights.AmbOcc)
     {
         AmbientOccluder amb = new AmbientOccluder();
         amb.SetSampler(ele.Attributes[P.Sampler].CreateSamplerFromAttribute(ns));
         amb.RadianceScale = rad;
         amb.Color = ele.Attributes[P.Col].ToVector3();
         amb.Shadows = shad;
         return amb;
     }
     else if (n == P.Lights.PL)
     {
         PointLight pl = new PointLight();
         pl.Position = ele.Attributes[P.Pos].ToVector3();
         pl.RadianceScale = rad;
         pl.Color = ele.Attributes[P.Col].ToVector3();
         pl.Shadows = shad;
         return pl;
     }
     else if (n == P.Lights.Direc)
     {
         Directional d = new Directional();
         d.Direction = ele.Attributes[P.Dir].ToVector3();
         d.RadianceScale = rad;
         d.Color = ele.Attributes[P.Col].ToVector3();
         d.Shadows = shad;
         return d;
     }
     else if (n == P.Lights.AL)
     {
         AreaLight al = new AreaLight();
         al.SetObject(GeometricObject.GetObject(ele.Attributes[P.Name].Value));
         al.Shadows = shad;
         return al;
     }
     throw new Exception();
 }
Пример #5
0
 static Light getLight(XElement ele, World world)
 {
     Light l = new Ambient();
     string typ = ele.Name.LocalName;
     if (typ == "Ambient")
     {
         Ambient amb = new Ambient();
         amb.Color = getVector(getAttribute("Color", ele));
         amb.RadianceScale = float.Parse(getAttribute("Radiance", ele));
         l = amb;
     }
     else if (typ == "AmbientOcculder")
     {
         AmbientOccluder amb = new AmbientOccluder();
         amb.Color = getVector(getAttribute("Color", ele));
         amb.RadianceScale = float.Parse(getAttribute("Radiance", ele));
         amb.SetSampler(getSampler(getAttribute("Sampler", ele), world.ViewPlane.NumSamples));
         l = amb;
     }
     else if (typ == "PointLight")
     {
         PointLight p = new PointLight();
         p.Color = getVector(getAttribute("Color", ele));
         p.RadianceScale = float.Parse(getAttribute("Radiance", ele));
         p.Position = getVector(getAttribute("Position", ele));
         l = p;
     }
     else if (typ == "Directional")
     {
         Directional d = new Directional();
         d.Color = getVector(getAttribute("Color", ele));
         d.RadianceScale = float.Parse(getAttribute("Radiance", ele));
         d.Direction = getVector(getAttribute("Direction", ele));
         l = d;
     }
     l.Shadows = bool.Parse(getAttribute("Shadows", ele));
     return l;
 }