Created
January 12, 2019 09:20
-
-
Save n-taku/5044f2998723fc5e4892f16cf11510bb to your computer and use it in GitHub Desktop.
LWRPに追加するカスタムパス(Transparent)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.Experimental.Rendering; | |
using UnityEngine.Experimental.Rendering.LightweightPipeline; | |
using UnityEngine.Rendering; | |
/// <summary> | |
/// Render all transparent forward objects into the given color and depth target | |
/// | |
/// You can use this pass to render objects that have a material and/or shader | |
/// with the pass names LightweightForward or SRPDefaultUnlit. The pass only renders | |
/// objects in the rendering queue range of Transparent objects. | |
/// </summary> | |
public class RenderTransparentForwardPass2 : ScriptableRenderPass | |
{ | |
const string k_RenderTransparentsTag = "Render Transparents"; | |
FilterRenderersSettings m_TransparentFilterSettings; | |
RenderTargetHandle colorAttachmentHandle { get; set; } | |
RenderTargetHandle depthAttachmentHandle { get; set; } | |
RenderTextureDescriptor descriptor { get; set; } | |
RendererConfiguration rendererConfiguration; | |
public RenderTransparentForwardPass2() | |
{ | |
//ここのRegisterShaderPassNameを変更 | |
RegisterShaderPassName("LightweightForward2"); | |
RegisterShaderPassName("SRPDefaultUnlit"); | |
m_TransparentFilterSettings = new FilterRenderersSettings(true) | |
{ | |
renderQueueRange = RenderQueueRange.transparent, | |
}; | |
} | |
/// <summary> | |
/// Configure the pass before execution | |
/// </summary> | |
/// <param name="baseDescriptor">Current target descriptor</param> | |
/// <param name="colorAttachmentHandle">Color attachment to render into</param> | |
/// <param name="depthAttachmentHandle">Depth attachment to render into</param> | |
/// <param name="configuration">Specific render configuration</param> | |
public void Setup( | |
RenderTextureDescriptor baseDescriptor, | |
RenderTargetHandle colorAttachmentHandle, | |
RenderTargetHandle depthAttachmentHandle, | |
RendererConfiguration configuration) | |
{ | |
this.colorAttachmentHandle = colorAttachmentHandle; | |
this.depthAttachmentHandle = depthAttachmentHandle; | |
descriptor = baseDescriptor; | |
rendererConfiguration = configuration; | |
} | |
/// <inheritdoc/> | |
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData) | |
{ | |
if (renderer == null) | |
throw new ArgumentNullException("renderer"); | |
CommandBuffer cmd = CommandBufferPool.Get(k_RenderTransparentsTag); | |
using (new ProfilingSample(cmd, k_RenderTransparentsTag)) | |
{ | |
RenderBufferLoadAction loadOp = RenderBufferLoadAction.Load; | |
RenderBufferStoreAction storeOp = RenderBufferStoreAction.Store; | |
SetRenderTarget(cmd, colorAttachmentHandle.Identifier(), loadOp, storeOp, | |
depthAttachmentHandle.Identifier(), loadOp, storeOp, ClearFlag.None, Color.black, descriptor.dimension); | |
context.ExecuteCommandBuffer(cmd); | |
cmd.Clear(); | |
Camera camera = renderingData.cameraData.camera; | |
var drawSettings = CreateDrawRendererSettings(camera, SortFlags.CommonTransparent, rendererConfiguration, renderingData.supportsDynamicBatching); | |
context.DrawRenderers(renderingData.cullResults.visibleRenderers, ref drawSettings, m_TransparentFilterSettings); | |
// Render objects that did not match any shader pass with error shader | |
renderer.RenderObjectsWithError(context, ref renderingData.cullResults, camera, m_TransparentFilterSettings, SortFlags.None); | |
} | |
context.ExecuteCommandBuffer(cmd); | |
CommandBufferPool.Release(cmd); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment