ã¯ããã«
ããã®RenderGraphçã®ããæ¹ãç´¹ä»ãã¾ã
ç°å¢ã¯ Unity 6.0.0b12ã§ã
ã³ã¼ã
using UnityEngine; using UnityEngine.Rendering.Universal; using UnityEngine.Rendering; using UnityEngine.Rendering.RenderGraphModule; using UnityEngine.Experimental.Rendering; public class TransparentRendererFeature : ScriptableRendererFeature { private CopyTransparentPass copyTransparentsPass = null;//ãã¹ public RenderPassEvent renderPassEvent = RenderPassEvent.AfterRenderingTransparents;//ã¬ã³ããªã³ã°ã¿ã¤ãã³ã° public Downsampling downsampling;//解å度æå® /// <summary> /// ãã¹çæ /// </summary> public override void Create() { copyTransparentsPass = new CopyTransparentPass(renderPassEvent, downsampling); } /// <summary> /// ãã¹ç»é²ãã /// </summary> /// <param name="renderer"></param> /// <param name="renderingData"></param> public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData) { //ãã¹ãå®è¡ã§ããããã«ãã renderer.EnqueuePass(copyTransparentsPass); } protected override void Dispose(bool disposing) { copyTransparentsPass?.Dispose(); copyTransparentsPass = null; } } /// <summary> /// åéæãå«ãã«ã¡ã©ã®æç»çµæãã°ãã¼ãã«ãã¯ã¹ãã£ã«è¨å®ããããã®ãã¹ /// </summary> public class CopyTransparentPass : ScriptableRenderPass { public CopyTransparentPass(RenderPassEvent passEvent, Downsampling downsampling) { renderPassEvent = passEvent; this.downsampling = downsampling; } private class PassData { public TextureHandle CameraColorHandle; } private readonly Vector4 scaleBias = new Vector4(1f, 1f, 0f, 0f); private readonly int textureID = Shader.PropertyToID("_CameraTransparentTexture"); const string ProfilerTag = "TestPass";//FrameDebuggerã§è¡¨ç¤ºãããåå private Downsampling downsampling; private RTHandle outputHandle; //ã³ãã¼å public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData) { var cameraData = frameData.Get<UniversalCameraData>(); var resourceData = frameData.Get<UniversalResourceData>(); var desc = cameraData.cameraTargetDescriptor; //解å度ãä¸ãã var down = downsampling switch { Downsampling._2xBilinear => 2, Downsampling._4xBilinear => 4, Downsampling._4xBox => 4, _ => 1 }; desc.width /= down; desc.height /= down; //depthã¨Stencilã¯ä½¿ç¨ããªãã®ã§ç¡å¹ã«ãã ãããããªãã¨æ£å¸¸ã«æç»ããããªã desc.depthStencilFormat = GraphicsFormat.None; RenderingUtils.ReAllocateHandleIfNeeded(ref outputHandle, desc, FilterMode.Bilinear, TextureWrapMode.Clamp, name: "ScreenCaptureHandle"); //ã³ãã¼å var source = resourceData.activeColorTexture; var destination = renderGraph.ImportTexture(outputHandle); using (var builder = renderGraph.AddRasterRenderPass<PassData>(ProfilerTag, out var passData)) { if (!source.IsValid() || !destination.IsValid()) return; passData.CameraColorHandle = source; builder.UseTexture(source); builder.SetRenderAttachment(destination, 0); builder.SetRenderAttachmentDepth(resourceData.activeDepthTexture); //ã°ãã¼ãã«å¤æ°ã®ä½¿ç¨ãè¨±å¯ builder.AllowGlobalStateModification(true); //ã°ãã¼ãã«å¤æ°è¨å® builder.SetGlobalTextureAfterPass(destination, textureID); //æç» builder.SetRenderFunc((PassData data, RasterGraphContext context) => ExecutePass(data, context)); } } private void ExecutePass(PassData data, RasterGraphContext context) { using (new ProfilingScope(context.cmd, profilingSampler)) { bool bilinear = downsampling == Downsampling._2xBilinear || downsampling == Downsampling._4xBilinear; //æç»çµæãã³ãã¼ãã Blitter.BlitTexture(context.cmd, data.CameraColorHandle, scaleBias, 0, bilinear); } } public void Dispose() { outputHandle?.Release(); } }