void OnEnable() { m_outputDir.CreateDirectory(); m_quad = FrameCapturerUtils.CreateFullscreenQuad(); m_mat_copy = new Material(m_shCopy); // initialize exr context fcAPI.fcExrConfig conf = fcAPI.fcExrConfig.default_value; m_ctx = fcAPI.fcExrCreateContext(ref conf); // initialize render targets m_scratch_buffers = new RenderTexture[m_targets.Length]; for (int i = 0; i < m_scratch_buffers.Length; ++i) { var rt = m_targets[i]; m_scratch_buffers[i] = new RenderTexture(rt.width, rt.height, 0, rt.format); m_scratch_buffers[i].Create(); } // initialize command buffers { m_cb_copy = new CommandBuffer(); m_cb_copy.name = "PngOffscreenRecorder: Copy"; for (int i = 0; i < m_targets.Length; ++i) { m_cb_copy.SetRenderTarget(m_scratch_buffers[i]); m_cb_copy.SetGlobalTexture("_TmpRenderTarget", m_targets[i]); m_cb_copy.DrawMesh(m_quad, Matrix4x4.identity, m_mat_copy, 0, 3); } } }
private static fcAPI.fcEXRContext CreateContext() { fcAPI.fcExrConfig config = fcAPI.fcExrConfig.default_value; return(fcAPI.fcExrCreateContext(ref config)); }
void OnEnable() { m_outputDir.CreateDirectory(); m_quad = FrameCapturerUtils.CreateFullscreenQuad(); m_mat_copy = new Material(m_shCopy); var cam = GetComponent <Camera>(); if (cam.targetTexture != null) { m_mat_copy.EnableKeyword("OFFSCREEN"); } #if UNITY_EDITOR if (m_captureGBuffer && !FrameCapturerUtils.IsRenderingPathDeferred(cam)) { Debug.LogWarning("ExrRecorder: Rendering Path must be deferred to use Capture GBuffer mode."); m_captureGBuffer = false; } #endif // UNITY_EDITOR // initialize exr context fcAPI.fcExrConfig conf = fcAPI.fcExrConfig.default_value; m_ctx = fcAPI.fcExrCreateContext(ref conf); // initialize render targets { m_frame_buffer = new RenderTexture(cam.pixelWidth, cam.pixelHeight, 0, RenderTextureFormat.ARGBHalf); m_frame_buffer.wrapMode = TextureWrapMode.Repeat; m_frame_buffer.Create(); m_gbuffer = new RenderTexture[5]; for (int i = 0; i < m_gbuffer.Length; ++i) { // last one is depth (1 channel) m_gbuffer[i] = new RenderTexture(cam.pixelWidth, cam.pixelHeight, 0, i == 4 ? RenderTextureFormat.RHalf : RenderTextureFormat.ARGBHalf); m_gbuffer[i].filterMode = FilterMode.Point; m_gbuffer[i].Create(); } } // initialize command buffers { int tid = Shader.PropertyToID("_TmpFrameBuffer"); m_cb_copy_fb = new CommandBuffer(); m_cb_copy_fb.name = "ExrRecorder: Copy FrameBuffer"; m_cb_copy_fb.GetTemporaryRT(tid, -1, -1, 0, FilterMode.Point); m_cb_copy_fb.Blit(BuiltinRenderTextureType.CurrentActive, tid); m_cb_copy_fb.SetRenderTarget(m_frame_buffer); m_cb_copy_fb.DrawMesh(m_quad, Matrix4x4.identity, m_mat_copy, 0, 0); m_cb_copy_fb.ReleaseTemporaryRT(tid); m_cb_copy_gb = new CommandBuffer(); m_cb_copy_gb.name = "ExrRecorder: Copy G-Buffer"; m_cb_copy_gb.SetRenderTarget( new RenderTargetIdentifier[] { m_gbuffer[0], m_gbuffer[1], m_gbuffer[2], m_gbuffer[3] }, m_gbuffer[0]); m_cb_copy_gb.DrawMesh(m_quad, Matrix4x4.identity, m_mat_copy, 0, 1); m_cb_copy_gb.SetRenderTarget(m_gbuffer[4]); // depth m_cb_copy_gb.DrawMesh(m_quad, Matrix4x4.identity, m_mat_copy, 0, 2); } }