123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310 |
- #if UNITY_EDITOR
- using UnityEditor;
- using UnityEditor.ProjectWindowCallback;
- #endif
- using System;
- using UnityEngine.Scripting.APIUpdating;
- using UnityEngine.Assertions;
- namespace UnityEngine.Rendering.Universal
- {
- [Serializable, ReloadGroup, ExcludeFromPreset]
- public class UniversalRendererData : ScriptableRendererData, ISerializationCallbackReceiver
- {
- #if UNITY_EDITOR
- [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1812")]
- internal class CreateUniversalRendererAsset : EndNameEditAction
- {
- public override void Action(int instanceId, string pathName, string resourceFile)
- {
- var instance = UniversalRenderPipelineAsset.CreateRendererAsset(pathName, RendererType.UniversalRenderer, false) as UniversalRendererData;
- Selection.activeObject = instance;
- }
- }
- [MenuItem("Assets/Create/Rendering/URP Universal Renderer", priority = CoreUtils.Sections.section3 + CoreUtils.Priorities.assetsCreateRenderingMenuPriority + 2)]
- static void CreateUniversalRendererData()
- {
- ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, CreateInstance<CreateUniversalRendererAsset>(), "New Custom Universal Renderer Data.asset", null, null);
- }
- #endif
- [Serializable, ReloadGroup]
- public sealed class ShaderResources
- {
- [Reload("Shaders/Utils/Blit.shader")]
- public Shader blitPS;
- [Reload("Shaders/Utils/CopyDepth.shader")]
- public Shader copyDepthPS;
- [Obsolete("Obsolete, this feature will be supported by new 'ScreenSpaceShadows' renderer feature")]
- public Shader screenSpaceShadowPS;
- [Reload("Shaders/Utils/Sampling.shader")]
- public Shader samplingPS;
- [Reload("Shaders/Utils/StencilDeferred.shader")]
- public Shader stencilDeferredPS;
- [Reload("Shaders/Utils/FallbackError.shader")]
- public Shader fallbackErrorPS;
- [Reload("Shaders/Utils/MaterialError.shader")]
- public Shader materialErrorPS;
- // Core blitter shaders, adapted from HDRP
- // TODO: move to core and share with HDRP
- [Reload("Shaders/Utils/CoreBlit.shader"), SerializeField]
- internal Shader coreBlitPS;
- [Reload("Shaders/Utils/CoreBlitColorAndDepth.shader"), SerializeField]
- internal Shader coreBlitColorAndDepthPS;
- [Reload("Shaders/CameraMotionVectors.shader")]
- public Shader cameraMotionVector;
- [Reload("Shaders/ObjectMotionVectors.shader")]
- public Shader objectMotionVector;
- }
- public PostProcessData postProcessData = null;
- #if ENABLE_VR && ENABLE_XR_MODULE
- [Reload("Runtime/Data/XRSystemData.asset")]
- public XRSystemData xrSystemData = null;
- #endif
- public ShaderResources shaders = null;
- const int k_LatestAssetVersion = 1;
- [SerializeField] int m_AssetVersion = 0;
- [SerializeField] LayerMask m_OpaqueLayerMask = -1;
- [SerializeField] LayerMask m_TransparentLayerMask = -1;
- [SerializeField] StencilStateData m_DefaultStencilState = new StencilStateData() { passOperation = StencilOp.Replace }; // This default state is compatible with deferred renderer.
- [SerializeField] bool m_ShadowTransparentReceive = true;
- [SerializeField] RenderingMode m_RenderingMode = RenderingMode.Forward;
- [SerializeField] DepthPrimingMode m_DepthPrimingMode = DepthPrimingMode.Disabled; // Default disabled because there are some outstanding issues with Text Mesh rendering.
- [SerializeField] bool m_AccurateGbufferNormals = false;
- //[SerializeField] bool m_TiledDeferredShading = false;
- [SerializeField] bool m_ClusteredRendering = false;
- const TileSize k_DefaultTileSize = TileSize._32;
- [SerializeField] TileSize m_TileSize = k_DefaultTileSize;
- [SerializeField] IntermediateTextureMode m_IntermediateTextureMode = IntermediateTextureMode.Auto;
- protected override ScriptableRenderer Create()
- {
- if (!Application.isPlaying)
- {
- ReloadAllNullProperties();
- }
- return new UniversalRenderer(this);
- }
- /// <summary>
- /// Use this to configure how to filter opaque objects.
- /// </summary>
- public LayerMask opaqueLayerMask
- {
- get => m_OpaqueLayerMask;
- set
- {
- SetDirty();
- m_OpaqueLayerMask = value;
- }
- }
- /// <summary>
- /// Use this to configure how to filter transparent objects.
- /// </summary>
- public LayerMask transparentLayerMask
- {
- get => m_TransparentLayerMask;
- set
- {
- SetDirty();
- m_TransparentLayerMask = value;
- }
- }
- public StencilStateData defaultStencilState
- {
- get => m_DefaultStencilState;
- set
- {
- SetDirty();
- m_DefaultStencilState = value;
- }
- }
- /// <summary>
- /// True if transparent objects receive shadows.
- /// </summary>
- public bool shadowTransparentReceive
- {
- get => m_ShadowTransparentReceive;
- set
- {
- SetDirty();
- m_ShadowTransparentReceive = value;
- }
- }
- /// <summary>
- /// Rendering mode.
- /// </summary>
- public RenderingMode renderingMode
- {
- get => m_RenderingMode;
- set
- {
- SetDirty();
- m_RenderingMode = value;
- }
- }
- /// <summary>
- /// Depth priming mode.
- /// </summary>
- public DepthPrimingMode depthPrimingMode
- {
- get => m_DepthPrimingMode;
- set
- {
- SetDirty();
- m_DepthPrimingMode = value;
- }
- }
- /// <summary>
- /// Use Octaedron Octahedron normal vector encoding for gbuffer normals.
- /// The overhead is negligible from desktop GPUs, while it should be avoided for mobile GPUs.
- /// </summary>
- public bool accurateGbufferNormals
- {
- get => m_AccurateGbufferNormals;
- set
- {
- SetDirty();
- m_AccurateGbufferNormals = value;
- }
- }
- /*
- public bool tiledDeferredShading
- {
- get => m_TiledDeferredShading;
- set
- {
- SetDirty();
- m_TiledDeferredShading = value;
- }
- }
- */
- internal bool clusteredRendering
- {
- get => m_ClusteredRendering;
- set
- {
- SetDirty();
- m_ClusteredRendering = value;
- }
- }
- internal TileSize tileSize
- {
- get => m_TileSize;
- set
- {
- Assert.IsTrue(value.IsValid());
- SetDirty();
- m_TileSize = value;
- }
- }
- /// <summary>
- /// Controls when URP renders via an intermediate texture.
- /// </summary>
- public IntermediateTextureMode intermediateTextureMode
- {
- get => m_IntermediateTextureMode;
- set
- {
- SetDirty();
- m_IntermediateTextureMode = value;
- }
- }
- protected override void OnValidate()
- {
- base.OnValidate();
- if (!m_TileSize.IsValid())
- {
- m_TileSize = k_DefaultTileSize;
- }
- }
- protected override void OnEnable()
- {
- base.OnEnable();
- // Upon asset creation, OnEnable is called and `shaders` reference is not yet initialized
- // We need to call the OnEnable for data migration when updating from old versions of UniversalRP that
- // serialized resources in a different format. Early returning here when OnEnable is called
- // upon asset creation is fine because we guarantee new assets get created with all resources initialized.
- if (shaders == null)
- return;
- ReloadAllNullProperties();
- }
- private void ReloadAllNullProperties()
- {
- #if UNITY_EDITOR
- ResourceReloader.TryReloadAllNullIn(this, UniversalRenderPipelineAsset.packagePath);
- #if ENABLE_VR && ENABLE_XR_MODULE
- ResourceReloader.TryReloadAllNullIn(xrSystemData, UniversalRenderPipelineAsset.packagePath);
- #endif
- #endif
- }
- void ISerializationCallbackReceiver.OnBeforeSerialize()
- {
- m_AssetVersion = k_LatestAssetVersion;
- }
- void ISerializationCallbackReceiver.OnAfterDeserialize()
- {
- if (m_AssetVersion <= 0)
- {
- var anyNonUrpRendererFeatures = false;
- foreach (var feature in m_RendererFeatures)
- {
- try
- {
- if (feature.GetType().Assembly == typeof(UniversalRendererData).Assembly)
- {
- continue;
- }
- }
- catch
- {
- // If we hit any exceptions while poking around assemblies,
- // conservatively assume there was a non URP renderer feature.
- }
- anyNonUrpRendererFeatures = true;
- }
- // Replicate old intermediate texture behaviour in case of any non-URP renderer features,
- // where we cannot know if they properly declare needed inputs.
- m_IntermediateTextureMode = anyNonUrpRendererFeatures ? IntermediateTextureMode.Always : IntermediateTextureMode.Auto;
- }
- m_AssetVersion = k_LatestAssetVersion;
- }
- }
- }
|