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); }
private void RenderMultiThread(Scene scene, System.Action <int, int> progressCallBackAction) { List <ManualResetEvent> eventList = new List <ManualResetEvent>(); int samplerIndex = 0; int total = m_RenderTarget.width * m_RenderTarget.height; int finished = 0; for (int j = 0; j < m_RenderTarget.height; j++) { for (int i = 0; i < m_RenderTarget.width; i++) { var job = new RenderJob(i, j, m_Samplers[samplerIndex], scene, this); samplerIndex += 1; if (samplerIndex >= m_Samplers.Length) { samplerIndex = 0; } eventList.Add(job.resetEvent); ThreadPool.QueueUserWorkItem(job.Render); if (eventList.Count >= Environment.ProcessorCount) { WaitRender(eventList); progressCallBackAction?.Invoke(finished, total); finished++; } } } while (eventList.Count > 0) { WaitRender(eventList); progressCallBackAction?.Invoke(finished, total); finished++; } }