public static void Main(string[] args) { int level = args.Length == 1 ? int.Parse(args[0]) : 6; byte[] pgm = new byte[RayTracer.PgmLength]; RayTracer.Render(pgm, level); File.WriteAllBytes("cs.pgm", pgm); }
private void RayTracerForm_Load(object sender, EventArgs e) { this.Show(); RayTracer rayTracer = new RayTracer(width, height, (int x, int y, System.Drawing.Color color) => { bitmap.SetPixel(x, y, color); if (x == 0) { pictureBox.Refresh(); } }); rayTracer.Render(rayTracer.DefaultScene); pictureBox.Invalidate(); }
public void Run() { try { Scene scene = UnifiedScenesRepository.Scenes["DistributedRT"]; //Scene scene = Scene.Load(@"D:\Models & Textures\HandAnimation.xml"); //Scene scene = Scene.Load(@"c:\temp\Scene1.xml"); if (scene != null) { RayTracer tracer = new RayTracer(scene); //scene.DefaultCamera = scene.Cameras["MinhaCamera"]; foreach (Primitive primi in scene.Primitives) { if (primi is TriangleModel) { ((TriangleModel)primi).Load(); } } using (Bitmap bFrame = new Bitmap((int)scene.DefaultCamera.ResX, (int)scene.DefaultCamera.ResY)) { Point3D eye = scene.DefaultCamera.Eye; float degreesToRotate = 0.5f; int count = 0; for (float i = 0; i < 360.0; i += degreesToRotate) { //2PI = 360 //xpi = 0.1 = 0.2PI = x * 360 = x = 0.2/360 eye.RotateAxisY(((2f * (float)Math.PI) * degreesToRotate / 360.0f)); scene.DefaultCamera.Eye = eye; tracer.Render(Graphics.FromImage(bFrame)); //FrameViewForm.Instance.FrameView.AddFrame(bFrame); bFrame.Save(@"d:\temp\frames\frame_" + count + ".png", ImageFormat.Png); count++; } } } } catch (Exception ex) { MessageBox.Show("Erro de Execução: " + ex.Message); } }
public void Run() { try { Scene scene = UnifiedScenesRepository.Scenes["DistributedRT"]; //Scene scene = Scene.Load(@"D:\Models & Textures\HandAnimation.xml"); //Scene scene = Scene.Load(@"c:\temp\Scene1.xml"); if(scene != null) { RayTracer tracer = new RayTracer(scene); //scene.DefaultCamera = scene.Cameras["MinhaCamera"]; foreach(Primitive primi in scene.Primitives) { if(primi is TriangleModel) { ((TriangleModel)primi).Load(); } } using(Bitmap bFrame = new Bitmap((int)scene.DefaultCamera.ResX, (int)scene.DefaultCamera.ResY)) { Point3D eye = scene.DefaultCamera.Eye; float degreesToRotate = 0.5f; int count = 0; for(float i = 0; i < 360.0; i += degreesToRotate) { //2PI = 360 //xpi = 0.1 = 0.2PI = x * 360 = x = 0.2/360 eye.RotateAxisY(((2f * (float)Math.PI) * degreesToRotate / 360.0f)); scene.DefaultCamera.Eye = eye; tracer.Render(Graphics.FromImage(bFrame)); //FrameViewForm.Instance.FrameView.AddFrame(bFrame); bFrame.Save(@"d:\temp\frames\frame_" + count + ".png", ImageFormat.Png); count++; } } } } catch(Exception ex) { MessageBox.Show("Erro de Execução: " + ex.Message); } }
private void Render() { RenderTime.Text = "..."; if (bmp == null || bmp.Width != tracer.ViewportSize.width || bmp.Height != tracer.ViewportSize.height) { bmp = new WriteableBitmap(tracer.ViewportSize.width, tracer.ViewportSize.height, 96, 96, PixelFormats.Bgr32, null); RenderedImage.Source = bmp; camera.FovX = camera.FovY * tracer.ViewportSize.width / tracer.ViewportSize.height; sectionTracer.SectionSize = new DoubleSize(sectionTracer.SectionSize.height * sectionTracer.ViewportSize.width / sectionTracer.ViewportSize.height, sectionTracer.SectionSize.height); } Action renderAction = () => { TraceData.ReflectionLimitExceedCount = 0; TraceData.RefractionLimitExceedCount = 0; tracer.Render(); numFramesRendered++; RenderTime.Dispatcher.Invoke(new Action(() => { RenderTime.Text = tracer.LastRenderTime.ToString(); if (TraceData.ReflectionLimitExceedCount > 0) { Console.WriteLine("Reflection limit exceed {0} times", TraceData.ReflectionLimitExceedCount); } if (TraceData.RefractionLimitExceedCount > 0) { Console.WriteLine("Refraction limit exceed {0} times", TraceData.RefractionLimitExceedCount); } })); }; Action <Task> presentAction = task => { Present(); }; if (continuousRendering) { Task.Factory.StartNew(() => { while (!cts.IsCancellationRequested) { renderAction(); presentAction(null); //camera.Pos -= new double4 ( camera.View * 0.1, 1 ); //camera.Pos += new double4 ( 0, 0, 0.25, 0 ); //camera.Pos += new double4 ( camera.View, 0 ); //floor.Plane.n = new double3 ( Math.Sin ( Math.PI * numFramesRendered * 5 / 180 ) / 4, 1, Math.Cos ( Math.PI * numFramesRendered * 5 / 180 ) / 4 ).Normalized; } }, cts.Token); } else { renderTask = Task.Factory.StartNew(renderAction); renderTask.ContinueWith(presentAction); timer.Start(); } }