using System.Collections.Generic; using UnityEngine.Rendering; using UnityEngine.Experimental.Rendering; using System; namespace UnityEngine.Rendering.HighDefinition { /// /// FullScreen Custom Pass /// [System.Serializable] public class FullScreenCustomPass : CustomPass { /// /// Material used for the fullscreen pass, it's shader must have been created with. /// public Material fullscreenPassMaterial; [SerializeField] int materialPassIndex = 0; /// /// Name of the pass to use in the fullscreen material. /// public string materialPassName = "Custom Pass 0"; /// /// Set to true if your shader will sample in the camera color buffer. /// public bool fetchColorBuffer; int fadeValueId; /// /// Called before the first execution of the pass occurs. /// Allow you to allocate custom buffers. /// /// The render context /// Current command buffer of the frame protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd) { fadeValueId = Shader.PropertyToID("_FadeValue"); // In case there was a pass index assigned, we retrieve the name of this pass if (String.IsNullOrEmpty(materialPassName) && fullscreenPassMaterial != null) materialPassName = fullscreenPassMaterial.GetPassName(materialPassIndex); } /// /// Execute the pass with the fullscreen setup /// /// The context of the custom pass. Contains command buffer, render context, buffer, etc. protected override void Execute(CustomPassContext ctx) { if (fullscreenPassMaterial != null) { if (fetchColorBuffer) { ResolveMSAAColorBuffer(ctx.cmd, ctx.hdCamera); // reset the render target to the UI SetRenderTargetAuto(ctx.cmd); } fullscreenPassMaterial.SetFloat(fadeValueId, fadeValue); CoreUtils.DrawFullScreen(ctx.cmd, fullscreenPassMaterial, shaderPassId: fullscreenPassMaterial.FindPass(materialPassName)); } } /// /// List all the materials that need to be displayed at the bottom of the component. /// All the materials gathered by this method will be used to create a Material Editor and then can be edited directly on the custom pass. /// /// An enumerable of materials to show in the inspector. These materials can be null, the list is cleaned afterwards public override IEnumerable RegisterMaterialForInspector() { yield return fullscreenPassMaterial; } } }