123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826 |
- using System;
- using System.Diagnostics;
- using System.Collections.Generic;
- using Unity.Collections;
- using UnityEngine.Scripting.APIUpdating;
- namespace UnityEngine.Rendering.Universal
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
- [MovedFrom("UnityEngine.Rendering.LWRP")] public abstract class ScriptableRenderer : IDisposable
- {
-
-
-
-
- public class RenderingFeatures
- {
-
-
-
-
-
-
- public bool cameraStacking { get; set; } = false;
- }
- void SetShaderTimeValues(float time, float deltaTime, float smoothDeltaTime, CommandBuffer cmd = null)
- {
-
- float timeEights = time / 8f;
- float timeFourth = time / 4f;
- float timeHalf = time / 2f;
-
- Vector4 timeVector = time * new Vector4(1f / 20f, 1f, 2f, 3f);
- Vector4 sinTimeVector = new Vector4(Mathf.Sin(timeEights), Mathf.Sin(timeFourth), Mathf.Sin(timeHalf), Mathf.Sin(time));
- Vector4 cosTimeVector = new Vector4(Mathf.Cos(timeEights), Mathf.Cos(timeFourth), Mathf.Cos(timeHalf), Mathf.Cos(time));
- Vector4 deltaTimeVector = new Vector4(deltaTime, 1f / deltaTime, smoothDeltaTime, 1f / smoothDeltaTime);
- Vector4 timeParametersVector = new Vector4(time, Mathf.Sin(time), Mathf.Cos(time), 0.0f);
- if (cmd == null)
- {
- Shader.SetGlobalVector(UniversalRenderPipeline.PerFrameBuffer._Time, timeVector);
- Shader.SetGlobalVector(UniversalRenderPipeline.PerFrameBuffer._SinTime, sinTimeVector);
- Shader.SetGlobalVector(UniversalRenderPipeline.PerFrameBuffer._CosTime, cosTimeVector);
- Shader.SetGlobalVector(UniversalRenderPipeline.PerFrameBuffer.unity_DeltaTime, deltaTimeVector);
- Shader.SetGlobalVector(UniversalRenderPipeline.PerFrameBuffer._TimeParameters, timeParametersVector);
- }
- else
- {
- cmd.SetGlobalVector(UniversalRenderPipeline.PerFrameBuffer._Time, timeVector);
- cmd.SetGlobalVector(UniversalRenderPipeline.PerFrameBuffer._SinTime, sinTimeVector);
- cmd.SetGlobalVector(UniversalRenderPipeline.PerFrameBuffer._CosTime, cosTimeVector);
- cmd.SetGlobalVector(UniversalRenderPipeline.PerFrameBuffer.unity_DeltaTime, deltaTimeVector);
- cmd.SetGlobalVector(UniversalRenderPipeline.PerFrameBuffer._TimeParameters, timeParametersVector);
- }
- }
- public RenderTargetIdentifier cameraColorTarget
- {
- get => m_CameraColorTarget;
- }
- public RenderTargetIdentifier cameraDepth
- {
- get => m_CameraDepthTarget;
- }
- protected List<ScriptableRendererFeature> rendererFeatures
- {
- get => m_RendererFeatures;
- }
- protected List<ScriptableRenderPass> activeRenderPassQueue
- {
- get => m_ActiveRenderPassQueue;
- }
-
-
-
-
- public RenderingFeatures supportedRenderingFeatures { get; set; } = new RenderingFeatures();
- static class RenderPassBlock
- {
-
-
- public static readonly int BeforeRendering = 0;
-
-
- public static readonly int MainRenderingOpaque = 1;
- public static readonly int MainRenderingTransparent = 2;
-
- public static readonly int AfterRendering = 3;
- }
- const int k_RenderPassBlockCount = 4;
- List<ScriptableRenderPass> m_ActiveRenderPassQueue = new List<ScriptableRenderPass>(32);
- List<ScriptableRendererFeature> m_RendererFeatures = new List<ScriptableRendererFeature>(10);
- RenderTargetIdentifier m_CameraColorTarget;
- RenderTargetIdentifier m_CameraDepthTarget;
- bool m_FirstTimeCameraColorTargetIsBound = true;
- bool m_FirstTimeCameraDepthTargetIsBound = true;
- bool m_XRRenderTargetNeedsClear = false;
- const string k_SetCameraRenderStateTag = "Clear Render State";
- const string k_SetRenderTarget = "Set RenderTarget";
- const string k_ReleaseResourcesTag = "Release Resources";
- static RenderTargetIdentifier[] m_ActiveColorAttachments = new RenderTargetIdentifier[]{0, 0, 0, 0, 0, 0, 0, 0 };
- static RenderTargetIdentifier m_ActiveDepthAttachment;
- static bool m_InsideStereoRenderBlock;
-
-
-
-
- static RenderTargetIdentifier[][] m_TrimmedColorAttachmentCopies = new RenderTargetIdentifier[][]
- {
- new RenderTargetIdentifier[0],
- new RenderTargetIdentifier[]{0},
- new RenderTargetIdentifier[]{0, 0},
- new RenderTargetIdentifier[]{0, 0, 0},
- new RenderTargetIdentifier[]{0, 0, 0, 0},
- new RenderTargetIdentifier[]{0, 0, 0, 0, 0},
- new RenderTargetIdentifier[]{0, 0, 0, 0, 0, 0},
- new RenderTargetIdentifier[]{0, 0, 0, 0, 0, 0, 0},
- new RenderTargetIdentifier[]{0, 0, 0, 0, 0, 0, 0, 0 },
- };
- internal static void ConfigureActiveTarget(RenderTargetIdentifier colorAttachment,
- RenderTargetIdentifier depthAttachment)
- {
- m_ActiveColorAttachments[0] = colorAttachment;
- for (int i = 1; i < m_ActiveColorAttachments.Length; ++i)
- m_ActiveColorAttachments[i] = 0;
- m_ActiveDepthAttachment = depthAttachment;
- }
- public ScriptableRenderer(ScriptableRendererData data)
- {
- foreach (var feature in data.rendererFeatures)
- {
- if (feature == null)
- continue;
- feature.Create();
- m_RendererFeatures.Add(feature);
- }
- Clear(CameraRenderType.Base);
- }
- public void Dispose()
- {
- Dispose(true);
- GC.SuppressFinalize(this);
- }
- protected virtual void Dispose(bool disposing)
- {
- }
-
-
-
-
-
- public void ConfigureCameraTarget(RenderTargetIdentifier colorTarget, RenderTargetIdentifier depthTarget)
- {
- m_CameraColorTarget = colorTarget;
- m_CameraDepthTarget = depthTarget;
- }
-
-
-
-
-
-
-
-
- public abstract void Setup(ScriptableRenderContext context, ref RenderingData renderingData);
-
-
-
-
-
-
- public virtual void SetupLights(ScriptableRenderContext context, ref RenderingData renderingData)
- {
- }
-
-
-
-
-
-
- public virtual void SetupCullingParameters(ref ScriptableCullingParameters cullingParameters,
- ref CameraData cameraData)
- {
- }
-
-
-
-
- public virtual void FinishRendering(CommandBuffer cmd)
- {
- }
-
-
-
-
-
- public void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
- {
- ref CameraData cameraData = ref renderingData.cameraData;
- Camera camera = cameraData.camera;
- CommandBuffer cmd = CommandBufferPool.Get(k_SetCameraRenderStateTag);
-
- SetCameraRenderState(cmd, ref cameraData);
- context.ExecuteCommandBuffer(cmd);
- cmd.Clear();
-
-
- SortStable(m_ActiveRenderPassQueue);
-
-
-
-
- #if UNITY_EDITOR
- float time = Application.isPlaying ? Time.time : Time.realtimeSinceStartup;
- #else
- float time = Time.time;
- #endif
- float deltaTime = Time.deltaTime;
- float smoothDeltaTime = Time.smoothDeltaTime;
- SetShaderTimeValues(time, deltaTime, smoothDeltaTime);
-
- NativeArray<RenderPassEvent> blockEventLimits = new NativeArray<RenderPassEvent>(k_RenderPassBlockCount, Allocator.Temp);
- blockEventLimits[RenderPassBlock.BeforeRendering] = RenderPassEvent.BeforeRenderingPrepasses;
- blockEventLimits[RenderPassBlock.MainRenderingOpaque] = RenderPassEvent.AfterRenderingOpaques;
- blockEventLimits[RenderPassBlock.MainRenderingTransparent] = RenderPassEvent.AfterRenderingPostProcessing;
- blockEventLimits[RenderPassBlock.AfterRendering] = (RenderPassEvent)Int32.MaxValue;
- NativeArray<int> blockRanges = new NativeArray<int>(blockEventLimits.Length + 1, Allocator.Temp);
-
-
-
- FillBlockRanges(blockEventLimits, blockRanges);
- blockEventLimits.Dispose();
- SetupLights(context, ref renderingData);
-
-
-
- ExecuteBlock(RenderPassBlock.BeforeRendering, blockRanges, context, ref renderingData);
- for (int eyeIndex = 0; eyeIndex < renderingData.cameraData.numberOfXRPasses; ++eyeIndex)
- {
-
-
-
-
-
-
-
-
- bool stereoEnabled = renderingData.cameraData.isStereoEnabled;
- context.SetupCameraProperties(camera, stereoEnabled, eyeIndex);
-
-
-
-
-
- if (cameraData.renderType == CameraRenderType.Overlay)
- {
- cmd.SetViewProjectionMatrices(cameraData.viewMatrix, cameraData.projectionMatrix);
- }
-
-
-
- SetShaderTimeValues(time, deltaTime, smoothDeltaTime, cmd);
- context.ExecuteCommandBuffer(cmd);
- cmd.Clear();
- if (stereoEnabled)
- BeginXRRendering(context, camera, eyeIndex);
- #if VISUAL_EFFECT_GRAPH_0_0_1_OR_NEWER
- var localCmd = CommandBufferPool.Get(string.Empty);
-
- VFX.VFXManager.ProcessCameraCommand(camera, localCmd);
- context.ExecuteCommandBuffer(localCmd);
- CommandBufferPool.Release(localCmd);
- #endif
-
-
- ExecuteBlock(RenderPassBlock.MainRenderingOpaque, blockRanges, context, ref renderingData, eyeIndex);
-
- ExecuteBlock(RenderPassBlock.MainRenderingTransparent, blockRanges, context, ref renderingData, eyeIndex);
-
- DrawGizmos(context, camera, GizmoSubset.PreImageEffects);
-
- ExecuteBlock(RenderPassBlock.AfterRendering, blockRanges, context, ref renderingData, eyeIndex);
- if (stereoEnabled)
- EndXRRendering(context, renderingData, eyeIndex);
- }
- DrawGizmos(context, camera, GizmoSubset.PostImageEffects);
- InternalFinishRendering(context, renderingData.resolveFinalTarget);
- blockRanges.Dispose();
- CommandBufferPool.Release(cmd);
- }
-
-
-
-
- public void EnqueuePass(ScriptableRenderPass pass)
- {
- m_ActiveRenderPassQueue.Add(pass);
- }
- #region deprecated
- [Obsolete("Use GetCameraClearFlag(ref CameraData cameraData) instead")]
- protected static ClearFlag GetCameraClearFlag(CameraClearFlags cameraClearFlags)
- {
- #if UNITY_EDITOR
-
-
-
- cameraClearFlags = CameraClearFlags.SolidColor;
- #endif
-
- if (Application.isMobilePlatform)
- return ClearFlag.All;
- if ((cameraClearFlags == CameraClearFlags.Skybox && RenderSettings.skybox != null) ||
- cameraClearFlags == CameraClearFlags.Nothing)
- return ClearFlag.Depth;
- return ClearFlag.All;
- }
- #endregion
-
-
-
-
-
- protected static ClearFlag GetCameraClearFlag(ref CameraData cameraData)
- {
- var cameraClearFlags = cameraData.camera.clearFlags;
- #if UNITY_EDITOR
-
-
-
- cameraClearFlags = CameraClearFlags.SolidColor;
- #endif
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (cameraData.renderType == CameraRenderType.Overlay)
- return (cameraData.clearDepth) ? ClearFlag.Depth : ClearFlag.None;
-
- if (Application.isMobilePlatform)
- return ClearFlag.All;
- if ((cameraClearFlags == CameraClearFlags.Skybox && RenderSettings.skybox != null) ||
- cameraClearFlags == CameraClearFlags.Nothing)
- return ClearFlag.Depth;
- return ClearFlag.All;
- }
-
-
- void SetCameraRenderState(CommandBuffer cmd, ref CameraData cameraData)
- {
-
- cmd.DisableShaderKeyword(ShaderKeywordStrings.MainLightShadows);
- cmd.DisableShaderKeyword(ShaderKeywordStrings.MainLightShadowCascades);
- cmd.DisableShaderKeyword(ShaderKeywordStrings.AdditionalLightsVertex);
- cmd.DisableShaderKeyword(ShaderKeywordStrings.AdditionalLightsPixel);
- cmd.DisableShaderKeyword(ShaderKeywordStrings.AdditionalLightShadows);
- cmd.DisableShaderKeyword(ShaderKeywordStrings.SoftShadows);
- cmd.DisableShaderKeyword(ShaderKeywordStrings.MixedLightingSubtractive);
- cmd.DisableShaderKeyword(ShaderKeywordStrings.LinearToSRGBConversion);
- }
- internal void Clear(CameraRenderType cameraType)
- {
- m_ActiveColorAttachments[0] = BuiltinRenderTextureType.CameraTarget;
- for (int i = 1; i < m_ActiveColorAttachments.Length; ++i)
- m_ActiveColorAttachments[i] = 0;
- m_ActiveDepthAttachment = BuiltinRenderTextureType.CameraTarget;
- m_InsideStereoRenderBlock = false;
- m_FirstTimeCameraColorTargetIsBound = cameraType == CameraRenderType.Base;
- m_FirstTimeCameraDepthTargetIsBound = true;
- m_ActiveRenderPassQueue.Clear();
- m_CameraColorTarget = BuiltinRenderTextureType.CameraTarget;
- m_CameraDepthTarget = BuiltinRenderTextureType.CameraTarget;
- }
- void ExecuteBlock(int blockIndex, NativeArray<int> blockRanges,
- ScriptableRenderContext context, ref RenderingData renderingData, int eyeIndex = 0, bool submit = false)
- {
- int endIndex = blockRanges[blockIndex + 1];
- for (int currIndex = blockRanges[blockIndex]; currIndex < endIndex; ++currIndex)
- {
- var renderPass = m_ActiveRenderPassQueue[currIndex];
- ExecuteRenderPass(context, renderPass, ref renderingData, eyeIndex);
- }
- if (submit)
- context.Submit();
- }
- void ExecuteRenderPass(ScriptableRenderContext context, ScriptableRenderPass renderPass, ref RenderingData renderingData, int eyeIndex)
- {
- ref CameraData cameraData = ref renderingData.cameraData;
- Camera camera = cameraData.camera;
- bool firstTimeStereo = false;
- CommandBuffer cmd = CommandBufferPool.Get(k_SetRenderTarget);
- renderPass.Configure(cmd, cameraData.cameraTargetDescriptor);
- renderPass.eyeIndex = eyeIndex;
- ClearFlag cameraClearFlag = GetCameraClearFlag(ref cameraData);
-
- if (RenderingUtils.IsMRT(renderPass.colorAttachments))
- {
-
-
-
- bool needCustomCameraColorClear = false;
- bool needCustomCameraDepthClear = false;
- int cameraColorTargetIndex = RenderingUtils.IndexOf(renderPass.colorAttachments, m_CameraColorTarget);
- if (cameraColorTargetIndex != -1 && (m_FirstTimeCameraColorTargetIsBound || (cameraData.isXRMultipass && m_XRRenderTargetNeedsClear) ))
- {
- m_FirstTimeCameraColorTargetIsBound = false;
- firstTimeStereo = true;
-
-
-
-
-
-
- needCustomCameraColorClear = (cameraClearFlag & ClearFlag.Color) != (renderPass.clearFlag & ClearFlag.Color)
- || CoreUtils.ConvertSRGBToActiveColorSpace(camera.backgroundColor) != renderPass.clearColor;
- if(cameraData.isXRMultipass && m_XRRenderTargetNeedsClear)
-
- needCustomCameraDepthClear = (cameraClearFlag & ClearFlag.Depth) != (renderPass.clearFlag & ClearFlag.Depth);
- m_XRRenderTargetNeedsClear = false;
- }
-
-
-
-
-
- if (renderPass.depthAttachment == m_CameraDepthTarget && m_FirstTimeCameraDepthTargetIsBound)
-
- {
- m_FirstTimeCameraDepthTargetIsBound = false;
-
- needCustomCameraDepthClear = (cameraClearFlag & ClearFlag.Depth) != (renderPass.clearFlag & ClearFlag.Depth);
-
-
- }
-
-
-
- if (needCustomCameraColorClear)
- {
-
- if ((cameraClearFlag & ClearFlag.Color) != 0)
- SetRenderTarget(cmd, renderPass.colorAttachments[cameraColorTargetIndex], renderPass.depthAttachment, ClearFlag.Color, CoreUtils.ConvertSRGBToActiveColorSpace(camera.backgroundColor));
- if ((renderPass.clearFlag & ClearFlag.Color) != 0)
- {
- uint otherTargetsCount = RenderingUtils.CountDistinct(renderPass.colorAttachments, m_CameraColorTarget);
- var nonCameraAttachments = m_TrimmedColorAttachmentCopies[otherTargetsCount];
- int writeIndex = 0;
- for (int readIndex = 0; readIndex < renderPass.colorAttachments.Length; ++readIndex)
- {
- if (renderPass.colorAttachments[readIndex] != m_CameraColorTarget && renderPass.colorAttachments[readIndex] != 0)
- {
- nonCameraAttachments[writeIndex] = renderPass.colorAttachments[readIndex];
- ++writeIndex;
- }
- }
- if (writeIndex != otherTargetsCount)
- Debug.LogError("writeIndex and otherTargetsCount values differed. writeIndex:" + writeIndex + " otherTargetsCount:" + otherTargetsCount);
- SetRenderTarget(cmd, nonCameraAttachments, m_CameraDepthTarget, ClearFlag.Color, renderPass.clearColor);
- }
- }
-
- ClearFlag finalClearFlag = ClearFlag.None;
- finalClearFlag |= needCustomCameraDepthClear ? (cameraClearFlag & ClearFlag.Depth) : (renderPass.clearFlag & ClearFlag.Depth);
- finalClearFlag |= needCustomCameraColorClear ? 0 : (renderPass.clearFlag & ClearFlag.Color);
-
- if (!RenderingUtils.SequenceEqual(renderPass.colorAttachments, m_ActiveColorAttachments) || renderPass.depthAttachment != m_ActiveDepthAttachment || finalClearFlag != ClearFlag.None)
- {
- int lastValidRTindex = RenderingUtils.LastValid(renderPass.colorAttachments);
- if (lastValidRTindex >= 0)
- {
- int rtCount = lastValidRTindex + 1;
- var trimmedAttachments = m_TrimmedColorAttachmentCopies[rtCount];
- for (int i = 0; i < rtCount; ++i)
- trimmedAttachments[i] = renderPass.colorAttachments[i];
- SetRenderTarget(cmd, trimmedAttachments, renderPass.depthAttachment, finalClearFlag, renderPass.clearColor);
- }
- }
- }
- else
- {
-
- RenderTargetIdentifier passColorAttachment = renderPass.colorAttachment;
- RenderTargetIdentifier passDepthAttachment = renderPass.depthAttachment;
-
-
- if (!renderPass.overrideCameraTarget)
- {
- passColorAttachment = m_CameraColorTarget;
- passDepthAttachment = m_CameraDepthTarget;
- }
- ClearFlag finalClearFlag = ClearFlag.None;
- Color finalClearColor;
- if (passColorAttachment == m_CameraColorTarget && (m_FirstTimeCameraColorTargetIsBound || (cameraData.isXRMultipass && m_XRRenderTargetNeedsClear)))
- {
- m_FirstTimeCameraColorTargetIsBound = false;
- finalClearFlag |= (cameraClearFlag & ClearFlag.Color);
- finalClearColor = CoreUtils.ConvertSRGBToActiveColorSpace(camera.backgroundColor);
- firstTimeStereo = true;
- if (m_FirstTimeCameraDepthTargetIsBound || (cameraData.isXRMultipass && m_XRRenderTargetNeedsClear))
- {
-
-
- m_FirstTimeCameraDepthTargetIsBound = false;
- finalClearFlag |= (cameraClearFlag & ClearFlag.Depth);
- }
- m_XRRenderTargetNeedsClear = false;
- }
- else
- {
- finalClearFlag |= (renderPass.clearFlag & ClearFlag.Color);
- finalClearColor = renderPass.clearColor;
- }
-
- if ( (m_CameraDepthTarget!=BuiltinRenderTextureType.CameraTarget ) && (passDepthAttachment == m_CameraDepthTarget || passColorAttachment == m_CameraDepthTarget) && m_FirstTimeCameraDepthTargetIsBound )
-
- {
- m_FirstTimeCameraDepthTargetIsBound = false;
- finalClearFlag |= (cameraClearFlag & ClearFlag.Depth);
-
-
-
-
- }
- else
- finalClearFlag |= (renderPass.clearFlag & ClearFlag.Depth);
-
- if (passColorAttachment != m_ActiveColorAttachments[0] || passDepthAttachment != m_ActiveDepthAttachment || finalClearFlag != ClearFlag.None)
- SetRenderTarget(cmd, passColorAttachment, passDepthAttachment, finalClearFlag, finalClearColor);
- }
-
-
- context.ExecuteCommandBuffer(cmd);
- CommandBufferPool.Release(cmd);
- if (firstTimeStereo && cameraData.isStereoEnabled )
- {
-
-
- context.StartMultiEye(camera, eyeIndex);
- XRUtils.DrawOcclusionMesh(cmd, camera);
- }
- renderPass.Execute(context, ref renderingData);
- }
- void BeginXRRendering(ScriptableRenderContext context, Camera camera, int eyeIndex)
- {
- context.StartMultiEye(camera, eyeIndex);
- m_InsideStereoRenderBlock = true;
- m_XRRenderTargetNeedsClear = true;
- }
- void EndXRRendering(ScriptableRenderContext context, in RenderingData renderingData, int eyeIndex)
- {
- Camera camera = renderingData.cameraData.camera;
- context.StopMultiEye(camera);
- bool isLastPass = renderingData.resolveFinalTarget && (eyeIndex == renderingData.cameraData.numberOfXRPasses - 1);
- context.StereoEndRender(camera, eyeIndex, isLastPass);
- m_InsideStereoRenderBlock = false;
- }
- internal static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier colorAttachment, RenderTargetIdentifier depthAttachment, ClearFlag clearFlag, Color clearColor)
- {
- m_ActiveColorAttachments[0] = colorAttachment;
- for (int i = 1; i < m_ActiveColorAttachments.Length; ++i)
- m_ActiveColorAttachments[i] = 0;
- m_ActiveDepthAttachment = depthAttachment;
- RenderBufferLoadAction colorLoadAction = ((uint)clearFlag & (uint)ClearFlag.Color) != 0 ?
- RenderBufferLoadAction.DontCare : RenderBufferLoadAction.Load;
- RenderBufferLoadAction depthLoadAction = ((uint)clearFlag & (uint)ClearFlag.Depth) != 0 ?
- RenderBufferLoadAction.DontCare : RenderBufferLoadAction.Load;
- TextureDimension dimension = (m_InsideStereoRenderBlock) ? XRGraphics.eyeTextureDesc.dimension : TextureDimension.Tex2D;
- SetRenderTarget(cmd, colorAttachment, colorLoadAction, RenderBufferStoreAction.Store,
- depthAttachment, depthLoadAction, RenderBufferStoreAction.Store, clearFlag, clearColor, dimension);
- }
- 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);
- }
- 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);
- }
- }
- static void SetRenderTarget(CommandBuffer cmd, RenderTargetIdentifier[] colorAttachments, RenderTargetIdentifier depthAttachment, ClearFlag clearFlag, Color clearColor)
- {
- m_ActiveColorAttachments = colorAttachments;
- m_ActiveDepthAttachment = depthAttachment;
- CoreUtils.SetRenderTarget(cmd, colorAttachments, depthAttachment, clearFlag, clearColor);
- }
- [Conditional("UNITY_EDITOR")]
- void DrawGizmos(ScriptableRenderContext context, Camera camera, GizmoSubset gizmoSubset)
- {
- #if UNITY_EDITOR
- if (UnityEditor.Handles.ShouldRenderGizmos())
- context.DrawGizmos(camera, gizmoSubset);
- #endif
- }
-
- void FillBlockRanges(NativeArray<RenderPassEvent> blockEventLimits, NativeArray<int> blockRanges)
- {
- int currRangeIndex = 0;
- int currRenderPass = 0;
- blockRanges[currRangeIndex++] = 0;
-
-
- for (int i = 0; i < blockEventLimits.Length - 1; ++i)
- {
- while (currRenderPass < m_ActiveRenderPassQueue.Count &&
- m_ActiveRenderPassQueue[currRenderPass].renderPassEvent < blockEventLimits[i])
- currRenderPass++;
- blockRanges[currRangeIndex++] = currRenderPass;
- }
- blockRanges[currRangeIndex] = m_ActiveRenderPassQueue.Count;
- }
- void InternalFinishRendering(ScriptableRenderContext context, bool resolveFinalTarget)
- {
- CommandBuffer cmd = CommandBufferPool.Get(k_ReleaseResourcesTag);
- for (int i = 0; i < m_ActiveRenderPassQueue.Count; ++i)
- m_ActiveRenderPassQueue[i].FrameCleanup(cmd);
-
- if (resolveFinalTarget)
- {
- for (int i = 0; i < m_ActiveRenderPassQueue.Count; ++i)
- m_ActiveRenderPassQueue[i].OnFinishCameraStackRendering(cmd);
- FinishRendering(cmd);
- }
- context.ExecuteCommandBuffer(cmd);
- CommandBufferPool.Release(cmd);
- }
- internal static void SortStable(List<ScriptableRenderPass> list)
- {
- int j;
- for (int i = 1; i < list.Count; ++i)
- {
- ScriptableRenderPass curr = list[i];
- j = i - 1;
- for (; j >= 0 && curr < list[j]; --j)
- list[j + 1] = list[j];
- list[j + 1] = curr;
- }
- }
- }
- }
|