예제 #1
0
        void OnEnable()
        {
            m_outputDir.CreateDirectory();
            m_quad     = FrameCapturerUtils.CreateFullscreenQuad();
            m_mat_copy = new Material(m_shCopy);

            // initialize png context
            fcAPI.fcPngConfig conf = fcAPI.fcPngConfig.default_value;
            m_ctx = fcAPI.fcPngCreateContext(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);
                }
            }
        }
예제 #2
0
        public void BeginRecording()
        {
            if (recording)
            {
                return;
            }

            context = CreateContext();

            recording = true;
        }
예제 #3
0
        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("PngRecorder: Rendering Path must be deferred to use Capture GBuffer mode.");
                m_captureGBuffer = false;
            }
#endif // UNITY_EDITOR

            // initialize png context
            fcAPI.fcPngConfig conf = fcAPI.fcPngConfig.default_value;
            m_ctx = fcAPI.fcPngCreateContext(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();

                var formats = new RenderTextureFormat[7] {
                    RenderTextureFormat.ARGBHalf,   // albedo (RGB)
                    RenderTextureFormat.RHalf,      // occlusion (R)
                    RenderTextureFormat.ARGBHalf,   // specular (RGB)
                    RenderTextureFormat.RHalf,      // smoothness (R)
                    RenderTextureFormat.ARGBHalf,   // normal (RGB)
                    RenderTextureFormat.ARGBHalf,   // emission (RGB)
                    RenderTextureFormat.RHalf,      // depth (R)
                };
                m_gbuffer = new RenderTexture[7];
                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, formats[i]);
                    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 = "PngRecorder: 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 = "PngRecorder: 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, 4);
                m_cb_copy_gb.SetRenderTarget(
                    new RenderTargetIdentifier[] { m_gbuffer[4], m_gbuffer[5], m_gbuffer[6], m_gbuffer[3] }, m_gbuffer[0]);
                m_cb_copy_gb.DrawMesh(m_quad, Matrix4x4.identity, m_mat_copy, 0, 5);
            }
        }
예제 #4
0
        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("PngRecorder: Rendering Path must be deferred to use Capture GBuffer mode.");
                m_captureGBuffer = false;
            }
            #endif // UNITY_EDITOR

            // initialize png context
            fcAPI.fcPngConfig conf = fcAPI.fcPngConfig.default_value;
            m_ctx = fcAPI.fcPngCreateContext(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();

                var formats = new RenderTextureFormat[7] {
                    RenderTextureFormat.ARGBHalf,   // albedo (RGB)
                    RenderTextureFormat.RHalf,      // occlusion (R)
                    RenderTextureFormat.ARGBHalf,   // specular (RGB)
                    RenderTextureFormat.RHalf,      // smoothness (R)
                    RenderTextureFormat.ARGBHalf,   // normal (RGB)
                    RenderTextureFormat.ARGBHalf,   // emission (RGB)
                    RenderTextureFormat.RHalf,      // depth (R)
                };
                m_gbuffer = new RenderTexture[7];
                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, formats[i]);
                    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 = "PngRecorder: 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 = "PngRecorder: 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, 4);
                m_cb_copy_gb.SetRenderTarget(
                    new RenderTargetIdentifier[] { m_gbuffer[4], m_gbuffer[5], m_gbuffer[6], m_gbuffer[3] }, m_gbuffer[0]);
                m_cb_copy_gb.DrawMesh(m_quad, Matrix4x4.identity, m_mat_copy, 0, 5);
            }
        }
        void OnEnable()
        {
            m_outputDir.CreateDirectory();
            m_quad = FrameCapturerUtils.CreateFullscreenQuad();
            m_mat_copy = new Material(m_shCopy);

            // initialize png context
            fcAPI.fcPngConfig conf = fcAPI.fcPngConfig.default_value;
            m_ctx = fcAPI.fcPngCreateContext(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);
                }
            }
        }
예제 #6
0
 private static void ExportTexture(ref int?eventID, fcAPI.fcPNGContext context, string path, RenderTexture texture)
 {
     eventID = fcAPI.fcPngExportTexture(context, path, texture, eventID ?? 0);
     GL.IssuePluginEvent(fcAPI.fcGetRenderEventFunc(), eventID ?? 0);
 }