Permalink
Fetching contributors…
Cannot retrieve contributors at this time
93 lines (85 sloc) 4.12 KB
using System.Collections.Generic;
using UnityEngine.Rendering;
using UnityEngine.Rendering.LWRP;
namespace UnityEngine.Experimental.Rendering.LWRP
{
/// <summary>
/// Inherit from this class to perform custom rendering in the Lightweight Render Pipeline.
/// </summary>
public abstract class ScriptableRenderPass
{
private List<ShaderTagId> m_ShaderTagIDs = new List<ShaderTagId>();
/// <summary>
/// Cleanup any allocated data that was created during the execution of the pass.
/// </summary>
/// <param name="cmd">Use this CommandBuffer to cleanup any generated data</param>
public virtual void FrameCleanup(CommandBuffer cmd)
{}
/// <summary>
/// Execute the pass. This is where custom rendering occurs. Specific details are left to the implementation
/// </summary>
/// <param name="renderer">The currently executing renderer. Contains configuration for the current execute call.</param>
/// <param name="context">Use this render context to issue any draw commands during execution</param>
/// <param name="renderingData">Current rendering state information</param>
public abstract void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData);
protected void RegisterShaderPassName(string passName)
{
m_ShaderTagIDs.Add(new ShaderTagId(passName));
}
protected DrawingSettings CreateDrawingSettings(Camera camera, SortingCriteria sortingCriteria, PerObjectData perObjectData, bool supportsDynamicBatching, int mainLightIndex = -1)
{
SortingSettings sortingSettings = new SortingSettings(camera) { criteria = sortingCriteria };
DrawingSettings settings = new DrawingSettings(m_ShaderTagIDs[0], sortingSettings)
{
perObjectData = perObjectData,
enableInstancing = true,
mainLightIndex = mainLightIndex,
enableDynamicBatching = supportsDynamicBatching
};
for (int i = 1; i < m_ShaderTagIDs.Count; ++i)
settings.SetShaderPassName(i, m_ShaderTagIDs[i]);
return settings;
}
protected static void SetRenderTarget(
CommandBuffer cmd,
RenderTargetIdentifier colorAttachment,
RenderBufferLoadAction colorLoadAction,
RenderBufferStoreAction colorStoreAction,
ClearFlag clearFlags,
Color clearColor,
TextureDimension dimension)
{
if (dimension == TextureDimension.Tex2DArray)
CoreUtils.SetRenderTarget(cmd, colorAttachment, clearFlags, clearColor, 0, CubemapFace.Unknown, -1);
else
CoreUtils.SetRenderTarget(cmd, colorAttachment, colorLoadAction, colorStoreAction, clearFlags, clearColor);
}
protected static void SetRenderTarget(
CommandBuffer cmd,
RenderTargetIdentifier colorAttachment,
RenderBufferLoadAction colorLoadAction,
RenderBufferStoreAction colorStoreAction,
RenderTargetIdentifier depthAttachment,
RenderBufferLoadAction depthLoadAction,
RenderBufferStoreAction depthStoreAction,
ClearFlag clearFlags,
Color clearColor,
TextureDimension dimension)
{
if (depthAttachment == BuiltinRenderTextureType.CameraTarget)
{
SetRenderTarget(cmd, colorAttachment, colorLoadAction, colorStoreAction, clearFlags, clearColor,
dimension);
}
else
{
if (dimension == TextureDimension.Tex2DArray)
CoreUtils.SetRenderTarget(cmd, colorAttachment, depthAttachment,
clearFlags, clearColor, 0, CubemapFace.Unknown, -1);
else
CoreUtils.SetRenderTarget(cmd, colorAttachment, colorLoadAction, colorStoreAction,
depthAttachment, depthLoadAction, depthStoreAction, clearFlags, clearColor);
}
}
}
}