Beispiel #1
0
        public override void RenderScene(World world)
        {
            Vector3 L;
            ViewPlane vp = new ViewPlane(world.ViewPlane);
            Ray ray = new Ray();
            int depth = 0;
            Vector2 pp  = new Vector2();
            vp.S /= Zoom;
            ray.Position = Position;
            int n = (int)MathHelper.Sqrt((float)vp.NumSamples);
            for (int r = 0; r < vp.VRes; r++)
                for (int c = 0; c < vp.HRes; c++)
                {
                    L = new Vector3(0, 0, 0);
                    for (int p = 0; p < n; p++)
                        for (int q = 0; q < n; q++)
                        {
                            pp.X = vp.S * (c - 0.5f * vp.HRes + (q + 0.5f) / n);
                            pp.Y = vp.S * (r - 0.5f * vp.VRes + (p + 0.5f) / n);
                            ray.Direction = GetDirection(pp);
                            L += world.Tracer.TraceRay(ray, depth);
                        }

                    L /= ((float)vp.NumSamples);
                    L *= ExposureTime;
                    world.Screen.AddPixel(r, c, L);
                }
        }
Beispiel #2
0
        public override void RenderScene(World world)
        {
            Vector3 L;
            ViewPlane vp = (world.ViewPlane);
            int hres = vp.HRes;
            int vres = vp.VRes;
            float s = vp.S;
            Ray ray = new Ray();
            int depth = 0;
            Vector2 sp; 					// sample point in [0, 1] X [0, 1]
            Vector2 pp;						// sample point on the pixel
            ray.Position = Position;
            for (int r = 0; r < vres; r++)		// up
                for (int c = 0; c < hres; c++)
                {	// across 					
                    L = new Vector3(0, 0, 0);

                    for (int j = 0; j < vp.NumSamples; j++)
                    {
                        sp = vp.Sampler.SampleUnitSquare();
                        pp = new Vector2();
                        pp.X = s * (c - 0.5f * hres + sp.X);
                        pp.Y = s * (r - 0.5f * vres + sp.Y);
                        ray.Direction = ray_direction(pp, hres, vres, s);
                        L += world.Tracer.TraceRay(ray, depth);
                    }
                    L /= vp.NumSamples;
                    L *= ExposureTime;
                    world.Screen.AddPixel(r, c, L);
                }
        }
Beispiel #3
0
        public override void RenderStereo(World world, float x, int offset)
        {
            Vector3 L;
            ViewPlane vp = world.ViewPlane;
            Ray ray = new Ray();
            int depth = 0;
            Vector2 pp, sp;
            int n = (int)MathHelper.Sqrt((float)vp.NumSamples);
            vp.S /= Zoom;
            ray.Position = Position;

            for (int r = 0; r < vp.VRes; r++)
                for (int c = 0; c < vp.HRes; c++)
                {
                    L = Vector3.Zero; ;
                    for (int p = 0; p < n; p++)
                        for (int q = 0; q < n; q++)
                        {
                            sp = vp.Sampler.SampleUnitSquare();
                            pp = new Vector2();
                            pp.X = vp.S * (((float)c) - 0.5f * ((float)vp.HRes) + sp.X) + x;
                            pp.Y = vp.S * (((float)r) - 0.5f * ((float)vp.VRes) + sp.Y);
                            ray.Direction = get_direction(pp);
                            L += world.Tracer.TraceRay(ray, depth);
                        }

                    L /= vp.NumSamples;
                    L *= ExposureTime;
                    world.Screen.AddPixel(r, c + offset, L);
                }
        }
Beispiel #4
0
        public override void RenderScene(World world)
        {
            Vector3 L;
            ViewPlane vp = world.ViewPlane;
            Ray ray = new Ray();
            int depth = 0;
            Vector2 pp;
            int n = (int)MathHelper.Sqrt((float)vp.NumSamples);
            vp.S /= Zoom;
            ray.Position = Position;

            for (int r = 0; r < vp.VRes; r++)
                for (int c = 0; c < vp.HRes; c++)
                {
                    L = Vector3.Zero; ;
                    for (int p = 0; p < n; p++)
                        for (int q = 0; q < n; q++)
                        {
                            pp.X = vp.S * (((float)c) - 0.5f * ((float)vp.HRes) + (((float)q) + 0.5f) / ((float)n));
                            pp.Y = vp.S * (((float)r) - 0.5f * ((float)vp.VRes) + (((float)p) + 0.5f) / ((float)n));
                            ray.Direction = Target - Position;
                            ray.Direction.Normalize();
                            Vector3 temp = get_direction(pp);
                            ray.Position = Position + temp;
                            L += world.Tracer.TraceRay(ray, depth);
                        }

                    L /= vp.NumSamples;
                    L *= ExposureTime;
                    world.Screen.AddPixel(r, c, L);
                }
        }
Beispiel #5
0
 public override void RenderStereo(World world, float x, int offset)
 {
     Vector3 L = Vector3.Zero;
     ViewPlane vp = world.ViewPlane;
     Ray ray = new Ray();
     int depth = 0;
     Vector2 pp = new Vector2();
     Vector2 sp = new Vector2();
     vp.S /= Zoom;
     ray.Position = Position;
     for (int r = 0; r < vp.VRes; r++)
         for (int c = 0; c < vp.HRes; c++)
         {
             L = new Vector3(0, 0, 0);
             for (int j = 0; j < vp.NumSamples; j++)
             {
                 sp = vp.Sampler.SampleUnitSquare();
                 pp.X = vp.S * (c - 0.5f * vp.HRes + sp.X) + x;
                 pp.Y = vp.S * (r - 0.5f * vp.VRes + sp.Y);
                 ray.Direction = GetDirection(pp);
                 L += world.Tracer.TraceRay(ray, depth);
             }
             L /= vp.NumSamples;
             L *= ExposureTime;
             world.Screen.AddPixel(r, c + offset, L);
         }
 }
Beispiel #6
0
        public override void RenderStereo(World world, float x, int offset)
        {
            Vector3 L = Vector3.Zero;
            Ray ray = new Ray();
            ViewPlane vp = (world.ViewPlane);
            int depth = 0;
            Vector2 sp, pp, dp, lp;			// sample point in [0, 1] X [0, 1]	
            vp.S /= Zoom;
            for (int r = 0; r < vp.VRes; r++)			// up
                for (int c = 0; c < vp.HRes; c++)
                {		// across 
                    L = Vector3.Zero;
                    for (int n = 0; n < vp.NumSamples; n++)
                    {
                        sp = vp.Sampler.SampleUnitSquare();
                        pp = new Vector2();
                        pp.X = vp.S * (c - vp.HRes / 2.0f + sp.X);
                        pp.Y = vp.S * (r - vp.VRes / 2.0f + sp.Y);
                        dp = Sampler.SampleUnitDisk();
                        lp = dp * Radius;
                        ray.Position = Position + lp.X * U + lp.Y * V;
                        ray.Direction = ray_direction(pp, lp);
                        L += world.Tracer.TraceRay(ray, depth);
                    }

                    L /= vp.NumSamples;
                    L *= ExposureTime;
                    world.Screen.AddPixel(r, c + offset, L);
                }
        }
Beispiel #7
0
        public override void RenderScene(World world)
        {
            Vector3 L;
            Ray ray = new Ray();
            ViewPlane vp = world.ViewPlane;
            int depth = 0;
            Vector2 sp;			// sample point in [0, 1] X [0, 1]
            Vector2 pp;			// sample point on a pixel
            Vector2 dp; 		// sample point on unit disk
            Vector2 lp;			// sample point on lens
            vp.S /= Zoom;
            for (int r = 0; r < vp.VRes; r++)			// up
                for (int c = 0; c < vp.HRes; c++)
                {		// across 
                    L = new Vector3(0, 0, 0);
                    for (int n = 0; n < vp.NumSamples; n++)
                    {
                        sp = vp.Sampler.SampleUnitSquare();
                        pp = new Vector2();
                        pp.X = vp.S * (((float)c) - ((float)vp.HRes) / 2.0f + sp.X);
                        pp.Y = vp.S * (((float)r) - ((float)vp.VRes) / 2.0f + sp.Y);

                        dp = Sampler.SampleUnitDisk();
                        lp = dp * Radius;
                        ray.Position = Position + lp.Y * U + lp.Y * V;
                        ray.Direction = ray_direction(pp, lp);
                        L += world.Tracer.TraceRay(ray, depth);
                    }

                    L /= vp.NumSamples;
                    L *= ExposureTime;
                    world.Screen.AddPixel(r, c, L);
                }
        }
Beispiel #8
0
 public World Compile()
 {
     World world = new World();
     getWorldAttributes(world);
     getTextures();
     getObjects(world);
     getLights(world);
     return world;
 }
Beispiel #9
0
 byte[] RenderImage(World screen)
 {
     System.Drawing.Bitmap bm = new System.Drawing.Bitmap(screen.ViewPlane.HRes, screen.ViewPlane.VRes);
     for (int i = 0; i < screen.Screen.Pixels.Count; i++)
     {
         Pixel p = screen.Screen.Pixels[i];
         bm.SetPixel((int)p.X, (int)p.Y, System.Drawing.Color.FromArgb((int)(MathHelper.Clamp(p.Color.R, 0, 1.0f) * 255.0f), (int)(MathHelper.Clamp(p.Color.G, 0, 1.0f) * 255.0f), (int)(MathHelper.Clamp(p.Color.B, 0, 1.0f) * 255.0f)));
     }
     return (byte[])new ImageConverter().ConvertTo(bm, typeof(byte[]));
 }
 public EditWindow(EditMode mode, World world)
 {
     if (mode == EditMode.Animation)
     {
         animation.Visibility = Visibility.Visible;
         image.Visibility = Visibility.Collapsed;
     }
     currentMode = mode;
     world2render = world;
     InitializeComponent();
 }
Beispiel #11
0
 protected void render_Click(object sender, EventArgs e)
 {
     try
     {
         Disque.Raytracer.GeometricObjects.GeometricObject.Clear();
         world = RmlReader.Compile(textEditor.Text.Replace('[', '<').Replace(']', '>'), ref saveDirectory);
         worker.RunWorkerAsync();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Beispiel #12
0
 public void RenderImage(World screen)
 {
     System.Drawing.Bitmap bm = new System.Drawing.Bitmap(screen.ViewPlane.HRes, screen.ViewPlane.VRes);
     for (int i = 0; i < screen.Screen.Pixels.Count; i++)
     {
         Pixel p = screen.Screen.Pixels[i];
         Color r = Color.FromScRgb(1.0f, p.Color.R, p.Color.G, p.Color.B);
         bm.SetPixel((int)p.X, (int)p.Y, System.Drawing.Color.FromArgb(r.R, r.G, r.B));
     }
     string name = DateTime.Now.Millisecond.ToString() + ".png";
     while (File.Exists(name))
     {
         name = DateTime.Now.Millisecond.ToString() +".png";
     }
     string file = @"C:\Users\Belal\Pictures\3D\" + name;
     bm.Save(file, System.Drawing.Imaging.ImageFormat.Png);
     collection.Clear();
     collection.Add(new Image() { Source = new BitmapImage(new Uri(file)), Height = bm.Height, Width = bm.Width });
 }
Beispiel #13
0
        public override void RenderScene(World world)
        {
            ViewPlane vp = world.ViewPlane;
            int hres = vp.HRes;
            int vreh = vp.VRes;
            float r = Vector3.Distance(Position, Target);
            float x = r * MathHelper.Tan(0.5f * Beta * MathHelper.PIOn180);
            switch (ViewType)
            {
                case ViewType.Parallel:
                    LeftCamera.RenderStereo(world, x, 0);
                    RightCamera.RenderStereo(world, -x, hres + PixelGap);
                    break;
                case ViewType.Transverse:
                    RightCamera.RenderStereo(world, -x, 0);
                    LeftCamera.RenderStereo(world, x, hres + PixelGap);
                    break;
            }

        }
Beispiel #14
0
        public override Vector3 RenderRay(World world, int c, int r, int n)
        {
            Vector3 L = Vector3.Zero;
            Vector2 pp = new Vector2();
            var ray = new Ray();
            int depth = 0;
            ray.Position = Position;
            ViewPlane vp = world.ViewPlane;
            for (int p = 0; p < n; p++)
                for (int q = 0; q < n; q++)
                {
                    pp.X = vp.S * (c - 0.5f * vp.HRes + (q + 0.5f) / n);
                    pp.Y = vp.S * (r - 0.5f * vp.VRes + (p + 0.5f) / n);
                    ray.Direction = GetDirection(pp);
                    L += world.Tracer.TraceRay(ray, depth);
                }

            L /= ((float)vp.NumSamples);
            L *= ExposureTime;
            return L;
        }
Beispiel #15
0
 public static World Compile(string file, ref string directory)
 {
     World world = new World();
     XDocument xdoc = XDocument.Parse(file);
     directory = getAttribute("Directory", xdoc.Element("World"));
     world.Tracer = getTracer(getAttribute("Tracer", xdoc.Element("World")), world);
     foreach(XElement xele in xdoc.Element("World").Elements())
     {
         if (xele.Name == "ViewPlane")
             getViewPlane(world, xele);
         else if (xele.Name == "Camera")
         {
             foreach (XElement ele in xele.Elements())
             {
                 world.Camera = getCamera(ele);
                 break;
             }
         }
         else if (xele.Name == "Textures")
         {
             getTextures(xele);
         }
         else if (xele.Name == "EnviromentalLight")
         {
             foreach (XElement ele in xele.Elements())
             {
                 world.AmbientLight = getLight(ele, world);
                 break;
             }
         }
         else if (xele.Name == "Lights")
             getLights(world, xele);
         else if (xele.Name == "Objects")
             getObjects(world, xele);
     }
     textures.Clear();
     return world;
 }
Beispiel #16
0
 static void build1(int ns)
 {
     world2 = new World();
     world2.ViewPlane.HRes = 400;
     world2.ViewPlane.VRes = 400;
     world2.ViewPlane.MaxDepth = 5;
     world2.ViewPlane.SetSamples(ns);
     world2.Tracer = new Whitted(world2);
     Ambient occ = new Ambient();
     occ.RadianceScale = 0f;
     occ.Shadows = true;
     occ.Color = Vector3.One;
     world2.AmbientLight = occ;
     Pinhole cam = new Pinhole();
     cam.Position = new Vector3(0, 60, 120);
     cam.Distance = 100;
     cam.Zoom = 1400;
     world2.Camera = cam;
     PointLight pl = new PointLight();
     pl.Color = Vector3.One;
     pl.Position = new Vector3(0, 1000, 0);
     pl.RadianceScale = 1.0f;
     pl.Shadows = true;
     world2.Lights.Add(pl);
     OBJReader obj = new OBJReader(File.ReadAllText(@"C:\Users\Belal\Downloads\bunny.obj.txt"));
     Mesh mesh = obj.GetMesh();
     mesh.SetShadows(false);
     mesh.SetMaterial(Material.Glass);
     world2.Objects.Add(mesh);
     BBox bb = mesh.GetBoundingBox();
     cam.Target = (bb.Min + bb.Max) * 0.5f;
     Matte matte2 = new Matte(0.5f, 0.5f, new Vector3(1, 1, 1));
     matte2.Shadows = true;
     Plane p = new Plane(new Vector3(0, -20, 0), new Vector3(0, 1, 0), "p1");
     p.SetShadows(true);
     p.SetMaterial(matte2);
     world2.Objects.Add(p);
 }
Beispiel #17
0
 public AreaLighting(World world)
     : base(world)
 {
 }
Beispiel #18
0
 string RenderImage(World screen)
 {
     System.Drawing.Bitmap bm = new System.Drawing.Bitmap(screen.ViewPlane.HRes, screen.ViewPlane.VRes);
     for (int i = 0; i < screen.Screen.Pixels.Count; i++)
     {
         Pixel p = screen.Screen.Pixels[i];
         System.Windows.Media.Color r = System.Windows.Media.Color.FromScRgb(1.0f, p.Color.R, p.Color.G, p.Color.B);
         bm.SetPixel((int)p.X, (int)p.Y, System.Drawing.Color.FromArgb(r.R, r.G, r.B));
     }
     string name = getLogCount() + ".png";
     string file = saveDirectory + @"\";
     bm.Save(file + name, System.Drawing.Imaging.ImageFormat.Png);
     addToLog(file + name, world.ViewPlane.NumSamples, DateTime.Now, renderTimer.Elapsed);
     return file + name;
 }
Beispiel #19
0
 private void Render_Executed(object sender, ExecutedRoutedEventArgs e)
 {
     try
     {
         saveFile();
         Disque.Raytracer.GeometricObjects.GeometricObject.Clear();
         world = RmlReader.Compile(textEditor.Text, ref saveDirectory);
         worker.RunWorkerAsync();
         dt.Start();
         textEditor.IsEnabled = false;
         status.Text = "Rendering...";
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.StackTrace);
     }
 }
Beispiel #20
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;
 }
Beispiel #21
0
 public ShadeRec(World world)
 {
     World = world;
 }
Beispiel #22
0
 void getObjects(World world)
 {
     foreach (RElement ele in root.GetElement("Objects").Elements)
     {
         bool add = true;
         GeometricObject go = ele.CreateObjectFromElement(textures, ref add);
         if (add)
             world.Objects.Add(go);
         else
             world.FreeObjects.Add(go);
     }
 }
Beispiel #23
0
 static void getViewPlane(World world, XElement ele)
 {
     world.ViewPlane.VRes = int.Parse(getAttribute("Height", ele));
     world.ViewPlane.HRes = int.Parse(getAttribute("Width", ele));
     world.ViewPlane.NumSamples = int.Parse(getAttribute("Samples", ele));
     world.ViewPlane.S = float.Parse(getAttribute("PixelSize", ele));
     world.ViewPlane.MaxDepth = int.Parse(getAttribute("MaxDepth", ele));
     world.ViewPlane.SetSampler(getSampler(getAttribute("Sampler", ele), world.ViewPlane.NumSamples));
 }
Beispiel #24
0
 void getEnvLight(World w)
 {
     w.AmbientLight = root.GetElement("World.AmbientLight").Elements[0].CreateLightFromElement(w.ViewPlane.NumSamples);
 }
Beispiel #25
0
 void getLights(World world)
 {
     if (root.HasElement("Lights"))
         foreach (RElement ele in root.GetElement("Lights").Elements)
             world.Lights.Add(ele.CreateLightFromElement(world.ViewPlane.NumSamples));
 }
Beispiel #26
0
 static Tracer getTracer(string tr, World world)
 {
     if (tr == "Whitted")
         return new Whitted(world);
     else if (tr == "RayCast")
         return new RayCast(world);
     else if (tr == "Global")
         return new GlobalTrace(world);
     else if (tr == "Area")
         return new AreaLighting(world);
     else if (tr == "Path")
         return new PathTrace(world);
     throw new NotCorrectValue("World", "Tracer");
 }
Beispiel #27
0
 public PathTrace(World world)
     : base(world)
 {
 }
Beispiel #28
0
 public static Tracer CreateTracerFromAttribute(this RAttribute att, World world)
 {
     string tr = att.Value;
     if (tr == "Whitted")
         return new Whitted(world);
     else if (tr == "RayCast")
         return new RayCast(world);
     else if (tr == "Global")
         return new GlobalTrace(world);
     else if (tr == "Area")
         return new AreaLighting(world);
     else if (tr == "Path")
         return new PathTrace(world);
     throw new Exception();
 }
Beispiel #29
0
 public GlobalTrace(World world)
     : base(world)
 {
 }
Beispiel #30
0
 void getWorldAttributes(World w)
 {
     if (root.HasAttribute("Background"))
         w.Background = Extensions.GetVector(root.Attributes["Background"]);
     w.Tracer = root.Attributes["Tracer"].CreateTracerFromAttribute(w);
     w.ViewPlane = root.GetElement("World.ViewPlane").CreateViewPlaneFromElement();
     w.Camera = root.GetElement("World.Camera").Elements[0].CreateCameraFromElement();
     getEnvLight(w);
 }