您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
74 行
3.5 KiB
74 行
3.5 KiB
using UnityEngine.Rendering;
|
|
|
|
namespace UnityEngine.Experimental.Rendering.LightweightPipeline
|
|
{
|
|
public class RenderOpaqueForwardPass : ScriptableRenderPass
|
|
{
|
|
const string k_RenderOpaquesTag = "Render Opaques";
|
|
FilterRenderersSettings m_OpaqueFilterSettings;
|
|
|
|
RenderTargetHandle colorAttachmentHandle { get; set; }
|
|
RenderTargetHandle depthAttachmentHandle { get; set; }
|
|
RenderTextureDescriptor descriptor { get; set; }
|
|
ClearFlag clearFlag { get; set; }
|
|
Color clearColor { get; set; }
|
|
|
|
RendererConfiguration rendererConfiguration;
|
|
|
|
public RenderOpaqueForwardPass()
|
|
{
|
|
RegisterShaderPassName("LightweightForward");
|
|
RegisterShaderPassName("SRPDefaultUnlit");
|
|
|
|
m_OpaqueFilterSettings = new FilterRenderersSettings(true)
|
|
{
|
|
renderQueueRange = RenderQueueRange.opaque,
|
|
};
|
|
}
|
|
|
|
public void Setup(
|
|
RenderTextureDescriptor baseDescriptor,
|
|
RenderTargetHandle colorAttachmentHandle,
|
|
RenderTargetHandle depthAttachmentHandle,
|
|
ClearFlag clearFlag,
|
|
Color clearColor,
|
|
RendererConfiguration configuration)
|
|
{
|
|
this.colorAttachmentHandle = colorAttachmentHandle;
|
|
this.depthAttachmentHandle = depthAttachmentHandle;
|
|
this.clearColor = CoreUtils.ConvertSRGBToActiveColorSpace(clearColor);
|
|
this.clearFlag = clearFlag;
|
|
descriptor = baseDescriptor;
|
|
this.rendererConfiguration = configuration;
|
|
}
|
|
|
|
public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
|
|
{
|
|
CommandBuffer cmd = CommandBufferPool.Get(k_RenderOpaquesTag);
|
|
using (new ProfilingSample(cmd, k_RenderOpaquesTag))
|
|
{
|
|
RenderBufferLoadAction loadOp = RenderBufferLoadAction.DontCare;
|
|
RenderBufferStoreAction storeOp = RenderBufferStoreAction.Store;
|
|
SetRenderTarget(cmd, colorAttachmentHandle.Identifier(), loadOp, storeOp,
|
|
depthAttachmentHandle.Identifier(), loadOp, storeOp, clearFlag, clearColor, descriptor.dimension);
|
|
|
|
// TODO: We need a proper way to handle multiple camera/ camera stack. Issue is: multiple cameras can share a same RT
|
|
// (e.g, split screen games). However devs have to be dilligent with it and know when to clear/preserve color.
|
|
// For now we make it consistent by resolving viewport with a RT until we can have a proper camera management system
|
|
//if (colorAttachmentHandle == -1 && !cameraData.isDefaultViewport)
|
|
// cmd.SetViewport(camera.pixelRect);
|
|
context.ExecuteCommandBuffer(cmd);
|
|
cmd.Clear();
|
|
|
|
Camera camera = renderingData.cameraData.camera;
|
|
var drawSettings = CreateDrawRendererSettings(camera, SortFlags.CommonOpaque, rendererConfiguration, renderingData.supportsDynamicBatching);
|
|
context.DrawRenderers(renderingData.cullResults.visibleRenderers, ref drawSettings, m_OpaqueFilterSettings);
|
|
|
|
// Render objects that did not match any shader pass with error shader
|
|
renderer.RenderObjectsWithError(context, ref renderingData.cullResults, camera, m_OpaqueFilterSettings, SortFlags.None);
|
|
}
|
|
context.ExecuteCommandBuffer(cmd);
|
|
CommandBufferPool.Release(cmd);
|
|
}
|
|
}
|
|
}
|