diff --git a/HDRP/Runtime/OitRenderPass.cs b/HDRP/Runtime/OitRenderPass.cs index 7878069..e40806c 100644 --- a/HDRP/Runtime/OitRenderPass.cs +++ b/HDRP/Runtime/OitRenderPass.cs @@ -12,21 +12,22 @@ class OitRenderPass : CustomPass protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd) { - orderIndependentTransparency ??= new OitLinkedList(); + orderIndependentTransparency ??= new OitLinkedList("OitRenderHDRP"); } protected override void Execute(CustomPassContext ctx) { // draw objects with UAV targets set var preRenderCmd = CommandBufferPool.Get("Order Independent Transparency Pre Render"); - preRenderCmd.Clear(); orderIndependentTransparency.PreRender(preRenderCmd); ctx.renderContext.ExecuteCommandBuffer(preRenderCmd); + preRenderCmd.Clear(); CommandBufferPool.Release(preRenderCmd); CustomPassUtils.DrawRenderers(ctx, objectLayerMask); // fullscreen blend of transparent pixel buffer - orderIndependentTransparency.Render(ctx.cmd, ctx.cameraColorBuffer, ctx.cameraColorBuffer); + var mat = orderIndependentTransparency.Render(ctx.cmd, ctx.cameraColorBuffer, ctx.cameraColorBuffer); + Blitter.BlitCameraTexture(ctx.cmd, ctx.cameraColorBuffer, ctx.cameraColorBuffer, mat, 0); } protected override void Cleanup() diff --git a/PostProcessingStackV2/Runtime/OitPostProcess.cs b/PostProcessingStackV2/Runtime/OitPostProcess.cs index a7d5f8f..c29238a 100644 --- a/PostProcessingStackV2/Runtime/OitPostProcess.cs +++ b/PostProcessingStackV2/Runtime/OitPostProcess.cs @@ -19,7 +19,7 @@ internal class OitPostProcessRenderer : PostProcessEffectRenderer("OitFullscreenRender")); + linkedListMaterial = new Material(Resources.Load(shaderName)); fragmentLinkBufferId = Shader.PropertyToID("FLBuffer"); startOffsetBufferId = Shader.PropertyToID("StartOffsetBuffer"); @@ -44,13 +44,13 @@ public void PreRender(CommandBuffer command) command.SetRandomWriteTarget(2, startOffsetBuffer); } - public void Render(CommandBuffer command, RenderTargetIdentifier src, RenderTargetIdentifier dest) + public Material Render(CommandBuffer command, RenderTargetIdentifier src, RenderTargetIdentifier dest) { command.ClearRandomWriteTargets(); // blend linked list linkedListMaterial.SetBuffer(fragmentLinkBufferId, fragmentLinkBuffer); linkedListMaterial.SetBuffer(startOffsetBufferId, startOffsetBuffer); - command.Blit(src, dest, linkedListMaterial); + return linkedListMaterial; } public void Release() diff --git a/URP/Runtime/OitPass.cs b/URP/Runtime/OitPass.cs index 03d5aad..1437d34 100644 --- a/URP/Runtime/OitPass.cs +++ b/URP/Runtime/OitPass.cs @@ -12,26 +12,28 @@ internal class OitPass : ScriptableRenderPass public OitPass() { renderPassEvent = RenderPassEvent.BeforeRenderingTransparents; - orderIndependentTransparency = new OitLinkedList(); + orderIndependentTransparency = new OitLinkedList("OitRenderURP"); RenderPipelineManager.beginContextRendering += PreRender; } private void PreRender(ScriptableRenderContext context, List cameras) { CommandBuffer cmd = CommandBufferPool.Get("Order Independent Transparency Pre Render"); - cmd.Clear(); orderIndependentTransparency.PreRender(cmd); context.ExecuteCommandBuffer(cmd); + cmd.Clear(); CommandBufferPool.Release(cmd); } public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { CommandBuffer cmd = CommandBufferPool.Get("Order Independent Transparency"); - cmd.Clear(); - orderIndependentTransparency.Render(cmd, renderingData.cameraData.renderer.cameraColorTarget, - renderingData.cameraData.renderer.cameraColorTarget); + var mat = orderIndependentTransparency.Render(cmd, renderingData.cameraData.renderer.cameraColorTargetHandle, + renderingData.cameraData.renderer.cameraColorTargetHandle); + Blitter.BlitCameraTexture(cmd, renderingData.cameraData.renderer.cameraColorTargetHandle, + renderingData.cameraData.renderer.cameraColorTargetHandle, mat, 0); context.ExecuteCommandBuffer(cmd); + cmd.Clear(); CommandBufferPool.Release(cmd); } diff --git a/URP/Runtime/OrderIndependentTransparencyRenderer.cs b/URP/Runtime/OrderIndependentTransparencyRenderer.cs index 38641da..f5394d1 100644 --- a/URP/Runtime/OrderIndependentTransparencyRenderer.cs +++ b/URP/Runtime/OrderIndependentTransparencyRenderer.cs @@ -1,5 +1,3 @@ -using System; -using UnityEngine; using UnityEngine.Rendering.Universal; namespace OrderIndependentTransparency.URP @@ -17,10 +15,10 @@ public override void Create() public override void AddRenderPasses(ScriptableRenderer renderer, ref RenderingData renderingData) { - // Unity does not provide an example how to perform a fullscreen Blit that works in scene view - // Hence only Blit in Game view for now - if (renderingData.cameraData.cameraType != CameraType.Game) + if (renderingData.cameraData.isPreviewCamera) + { return; + } //Calling ConfigureInput with the ScriptableRenderPassInput.Color argument ensures that the opaque texture is available to the Render Pass oitPass.ConfigureInput(ScriptableRenderPassInput.Color); renderer.EnqueuePass(oitPass); diff --git a/package.json b/package.json index 4cf8e99..95e83a2 100644 --- a/package.json +++ b/package.json @@ -1,9 +1,9 @@ { "name": "org.happy-turtle.order-independent-transparency", "version": "3.0.1", + "unity": "2021.2", "displayName": "Order-independent Transparency", "description": "This is an implementation of order-independent transparency for the Built-In Pipeline. It uses Per-Pixel Linked Lists, implemented with RWStructuredBuffers. This is a feature requiring Shader Model 5.0 with ComputeBuffers, see the Unity Manual for supported platforms.", - "unity": "2020.3", "author": { "name": "Till Davin", "email": "code@tilldavin.de"