protected override IRenderResult OnRenderDebugSinglePixel(int x, int y, RenderConfig config) { CameraBase camera = m_Scene.camera; if (camera == null) { throw new System.ArgumentNullException(); } Texture result = new Texture(config.width, config.height); result.Fill(Color.black); var sampler = SamplerFactory.Create(config.samplerType, config.numSamples, config.numSets); camera.SetRenderTarget(result); Color col = Color.black; sampler.ResetSampler(); //重置采样器状态 while (sampler.NextSample()) { Ray ray = m_Scene.camera.GetRay(x, y, sampler); col += this.PathTracing(ray, sampler); } col /= sampler.numSamples; col.a = 1.0f; result.SetPixel(x, y, col); return(result); }
protected override IRenderResult OnRender(RenderConfig config, RenderJobCallBackDelegate progressCallBackAction) { CameraBase camera = m_Scene.camera; if (camera == null) { throw new System.ArgumentNullException(); } Texture result = new Texture(config.width, config.height); camera.SetRenderTarget(result); RenderJob <PathTracerRenderJobResult, PathTracer> job = new RenderJob <PathTracerRenderJobResult, PathTracer>(config, m_Scene, this); for (int j = 0; j < camera.renderTarget.height; j += 32) { for (int i = 0; i < camera.renderTarget.width; i += 32) { job.AddWork(new PathTracerRenderWork(i, j, (int)config.width, (int)config.height)); } } job.Render(camera.renderTarget, progressCallBackAction); return(result); }
public Job(RenderConfig config, Scene scene, W renderer, ConcurrentQueue <IRenderWork <T, W> > works, ConcurrentQueue <T> results, ManualResetEvent resetEvent) { m_Works = works; m_Results = results; m_ResetEvent = resetEvent; m_Scene = scene; m_Renderer = renderer; m_Sampler = SamplerFactory.Create(config.samplerType, config.numSamples, config.numSets); }
public RenderJob(RenderConfig config, Scene scene, W renderer) { m_Works = new ConcurrentQueue <IRenderWork <T, W> >(); m_Results = new ConcurrentQueue <T>(); m_Jobs = new Job[Environment.ProcessorCount]; m_ResetEvent = new ManualResetEvent(false); for (int i = 0; i < m_Jobs.Length; i++) { m_Jobs[i] = new Job(config, scene, renderer, m_Works, m_Results, m_ResetEvent); } }
public IRenderResult RenderDebugSinglePixel(int x, int y, RenderConfig config) { if (m_Scene == null) { throw new System.ArgumentNullException(); } this.tracingTimes = config.traceTimes; this.isDebugging = true; try { return(OnRenderDebugSinglePixel(x, y, config)); } catch (System.Exception e) { Log.Err(e.Message); Log.Err(e.StackTrace); } return(null); }
public IRenderResult Render(RenderConfig config, RenderJobCallBackDelegate progressCallBackAction = null) { if (m_Scene == null) { throw new System.ArgumentNullException(); } this.tracingTimes = config.traceTimes; #if DEBUG this.isDebugging = false; #endif try { return(OnRender(config, progressCallBackAction)); } catch (System.Exception e) { Log.Err(e.Message); Log.Err(e.StackTrace); } return(null); }
public bool Execute(RenderJobCallBackDelegate progressCallBackAction = null) { if (string.IsNullOrEmpty(scenePath)) { return(false); } if (File.Exists(scenePath) == false) { return(false); } if (string.IsNullOrEmpty(outputPath)) { return(false); } FileInfo outputFileInfo = new FileInfo(outputPath); if (outputFileInfo.Directory == null) { return(false); } if (bounceTimes <= 0) { return(false); } if (numSamples <= 0) { return(false); } if (width <= 0 || height <= 0) { return(false); } var scene = Scene.Create(scenePath); var pt = new PathTracer(scene); RenderConfig config = new RenderConfig() { traceTimes = bounceTimes, samplerType = samplerType, numSamples = numSamples, numSets = 83, width = (uint)width, height = (uint)height, }; var tex = pt.Render(config, progressCallBackAction); if (outputFileInfo.Directory.Exists) { outputFileInfo.Directory.Create(); } if (saveHDR) { tex.Save(Path.Combine(outputFileInfo.FullName, ".hdr")); //tex.SaveToHDR(Path.Combine(outputFileInfo.FullName, ".hdr")); } else { //var bitmap = tex.TransferToBMP(null, 0.45f, tonemapping ? exposure : -1.0f); //FileStream stream = new FileStream(outputFileInfo.FullName, FileMode.Create, FileAccess.Write); //bitmap.Save(stream, ImageFormat.Bmp); //stream.Close(); //bitmap.Dispose(); tex.Save(outputFileInfo.FullName); } return(true); }
protected abstract IRenderResult OnRenderDebugSinglePixel(int x, int y, RenderConfig config);
protected abstract IRenderResult OnRender(RenderConfig config, RenderJobCallBackDelegate progressCallBackAction);