コード例 #1
0
    public SRPE01Instance(SRPE01 parent)
    {
        m_Parent = parent;

        //Attachments
        m_Albedo   = new RenderPassAttachment(RenderTextureFormat.ARGB32);
        m_Emission = new RenderPassAttachment(RenderTextureFormat.ARGB32);
        m_Output   = new RenderPassAttachment(RenderTextureFormat.ARGB32);
        m_Depth    = new RenderPassAttachment(RenderTextureFormat.Depth);

        m_Albedo.Clear(Color.green, 1f, 0);
        m_Emission.Clear(Color.green, 1f, 0);
        //m_Output.Clear(Color.cyan);
        m_Depth.Clear(Color.black, 1f, 0);

        m_Output.BindSurface(BuiltinRenderTextureType.CameraTarget, false, true);
    }
コード例 #2
0
    public void ExecuteRenderLoop(Camera camera, CullResults cullResults, ScriptableRenderContext scriptableRenderContext)
    {
        // Bind the albedo surface to the current camera target, so the final pass will render the scene to the screen backbuffer
        // The second argument specifies whether the existing contents of the surface need to be loaded as the initial values;
        // in our case we do not need that because we'll be clearing the attachment anyway. This saves a lot of memory
        // bandwidth on tiled GPUs.
        // The third argument specifies whether the rendering results need to be written out to memory at the end of
        // the renderpass. We need this as we'll be generating the final image there.
        // We could do this in the constructor already, but the camera target may change on the fly, esp. in the editor
        m_Albedo.BindSurface(BuiltinRenderTextureType.CameraTarget, false, true);

        // All other attachments are transient surfaces that are not stored anywhere. If the renderer allows,
        // those surfaces do not even have a memory allocated for the pixel values, saving RAM usage.

        // Start the renderpass using the given scriptable rendercontext, resolution, samplecount, array of attachments that will be used within the renderpass and the depth surface
        using (RenderPass rp = new RenderPass(scriptableRenderContext, camera.pixelWidth, camera.pixelHeight, 1, new[] { m_Albedo, m_SpecRough, m_Normal, m_Emission }, m_Depth))
        {
            // Start the first subpass, GBuffer creation: render to albedo, specRough, normal and emission, no need to read any input attachments
            using (new RenderPass.SubPass(rp, new[] { m_Albedo, m_SpecRough, m_Normal, m_Emission }, null))
            {
                // Render the deferred G-Buffer
                RenderGBuffer(cullResults, camera, scriptableRenderContext);
            }
            // Second subpass, lighting: Render to the emission buffer, read from albedo, specRough, normal and depth.
            // The last parameter indicates whether the depth buffer can be bound as read-only.
            // Note that some renderers (notably iOS Metal) won't allow reading from the depth buffer while it's bound as Z-buffer,
            // so those renderers should write the Z into an additional FP32 render target manually in the pixel shader and read from it instead
            using (new RenderPass.SubPass(rp, new[] { m_Emission }, new[] { m_Albedo, m_SpecRough, m_Normal, m_Depth }, true))
            {
                PushGlobalShadowParams(scriptableRenderContext);

                RenderLighting(camera, cullResults, scriptableRenderContext);

                scriptableRenderContext.DrawSkybox(camera);
            }
            // Third subpass, tonemapping: Render to albedo (which is bound to the camera target), read from emission.
            using (new RenderPass.SubPass(rp, new[] { m_Albedo }, new[] { m_Emission }, true))
            {
                // present frame buffer.
                FinalPass(scriptableRenderContext);
            }
        }
    }
        public override void Execute(ScriptableRenderer renderer, ref ScriptableRenderContext context,
                                     ref CullResults cullResults, ref RenderingData renderingData)
        {
            Camera camera = renderingData.cameraData.camera;

            m_CameraTarget.BindSurface(BuiltinRenderTextureType.CameraTarget, false, true);
            context.SetupCameraProperties(camera, false);

            using (RenderPass rp = new RenderPass(context, camera.pixelWidth, camera.pixelHeight, 1, new[] { m_GBufferDiffuse, m_GBufferSpecularAndRoughness, m_GBufferNormal, m_CameraTarget }, m_Depth))
            {
                using (new RenderPass.SubPass(rp, new[] { m_GBufferDiffuse, m_GBufferSpecularAndRoughness, m_GBufferNormal, m_CameraTarget }, null))
                {
                    RenderGBuffer(context, cullResults, camera);
                }

                using (new RenderPass.SubPass(rp, new[] { m_CameraTarget }, new[] { m_GBufferDiffuse, m_GBufferSpecularAndRoughness, m_GBufferNormal, m_Depth }, true))
                {
                    RenderLights(context, cullResults, renderingData.lightData);
                }
            }
        }