您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
64 行
2.8 KiB
64 行
2.8 KiB
using UnityEngine.Rendering;
|
|
|
|
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
|
|
{
|
|
public class RenderTransparentForwardPass : 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 RenderTransparentForwardPass()
|
|
{
|
|
RegisterShaderPassName("LightweightForward");
|
|
RegisterShaderPassName("SRPDefaultUnlit");
|
|
|
|
m_TransparentFilterSettings = new FilterRenderersSettings(true)
|
|
{
|
|
renderQueueRange = RenderQueueRange.transparent,
|
|
};
|
|
}
|
|
|
|
public void Setup(
|
|
RenderTextureDescriptor baseDescriptor,
|
|
RenderTargetHandle colorAttachmentHandle,
|
|
RenderTargetHandle depthAttachmentHandle,
|
|
RendererConfiguration configuration)
|
|
{
|
|
this.colorAttachmentHandle = colorAttachmentHandle;
|
|
this.depthAttachmentHandle = depthAttachmentHandle;
|
|
descriptor = baseDescriptor;
|
|
rendererConfiguration = configuration;
|
|
}
|
|
|
|
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
}
|