using System; using UnityEngine.Rendering.HighDefinition.Attributes; namespace UnityEngine.Rendering.HighDefinition { /// Engine lighting property. public enum LightingProperty { /// No debug output. None = 0, /// Render only diffuse. DiffuseOnly, /// Render only specular. SpecularOnly, /// Render only direct diffuse. DirectDiffuseOnly, /// Render only direct specular. DirectSpecularOnly, /// Render only indirect diffuse. IndirectDiffuseOnly, /// Render only reflection. ReflectionOnly, /// Render only refraction. RefractionOnly, /// Render only emissive. EmissiveOnly } /// Output a specific debug mode. public enum DebugFullScreen { /// No debug output. None, /// Depth buffer. Depth, /// Screen space ambient occlusion buffer. ScreenSpaceAmbientOcclusion, /// Motion vectors buffer. MotionVectors, /// The world space position of visible surfaces. WorldSpacePosition, /// Render only volumetric fog VolumetricFogOnly } /// Use this request to define how to render an AOV. public unsafe struct AOVRequest { /// Default settings. [Obsolete("Since 2019.3, use AOVRequest.NewDefault() instead.")] public static readonly AOVRequest @default = default; /// Default settings. /// public static AOVRequest NewDefault() => new AOVRequest { m_MaterialProperty = MaterialSharedProperty.None, m_LightingProperty = LightingProperty.None, m_DebugFullScreen = DebugFullScreen.None, m_LightFilterProperty = DebugLightFilterMode.None, m_OverrideRenderFormat = false }; MaterialSharedProperty m_MaterialProperty; LightingProperty m_LightingProperty; DebugLightFilterMode m_LightFilterProperty; DebugFullScreen m_DebugFullScreen; // When this variable is true, HDRP will render internally with the graphics format of teh user provided AOV output buffer // Use the SetOverrideRenderFormat member function to change the value of this parameter. internal bool overrideRenderFormat => m_OverrideRenderFormat; internal bool m_OverrideRenderFormat; AOVRequest* thisPtr { get { fixed (AOVRequest* pThis = &this) return pThis; } } /// Create a new instance by copying values from . /// public AOVRequest(AOVRequest other) { m_MaterialProperty = other.m_MaterialProperty; m_LightingProperty = other.m_LightingProperty; m_DebugFullScreen = other.m_DebugFullScreen; m_LightFilterProperty = other.m_LightFilterProperty; m_OverrideRenderFormat = other.m_OverrideRenderFormat; } /// State the property to render. In case of several SetFullscreenOutput chained call, only last will be used. /// The property to render. /// A ref return to chain calls. public ref AOVRequest SetFullscreenOutput(MaterialSharedProperty materialProperty) { m_MaterialProperty = materialProperty; return ref *thisPtr; } /// State the property to render. In case of several SetFullscreenOutput chained call, only last will be used. /// The property to render. /// A ref return to chain calls. public ref AOVRequest SetFullscreenOutput(LightingProperty lightingProperty) { m_LightingProperty = lightingProperty; return ref *thisPtr; } /// State the property to render. In case of several SetFullscreenOutput chained call, only last will be used. /// The property to render. /// A ref return to chain calls. public ref AOVRequest SetFullscreenOutput(DebugFullScreen debugFullScreen) { m_DebugFullScreen = debugFullScreen; return ref *thisPtr; } /// Set the light filter to use. /// The light filter to use /// A ref return to chain calls. public ref AOVRequest SetLightFilter(DebugLightFilterMode filter) { m_LightFilterProperty = filter; return ref *thisPtr; } /// Allows AOVs to be rendered at the same format/precision as the user allocated buffers. /// Set to true to override the rendering buffer format /// A ref return to chain calls. public ref AOVRequest SetOverrideRenderFormat(bool flag) { m_OverrideRenderFormat = flag; return ref *thisPtr; } /// /// Populate the debug display settings with the AOV data. /// /// The debug display settings to fill. public void FillDebugData(DebugDisplaySettings debug) { debug.SetDebugViewCommonMaterialProperty(m_MaterialProperty); switch (m_LightingProperty) { case LightingProperty.DiffuseOnly: debug.SetDebugLightingMode(DebugLightingMode.DiffuseLighting); break; case LightingProperty.SpecularOnly: debug.SetDebugLightingMode(DebugLightingMode.SpecularLighting); break; case LightingProperty.DirectDiffuseOnly: debug.SetDebugLightingMode(DebugLightingMode.DirectDiffuseLighting); break; case LightingProperty.DirectSpecularOnly: debug.SetDebugLightingMode(DebugLightingMode.DirectSpecularLighting); break; case LightingProperty.IndirectDiffuseOnly: debug.SetDebugLightingMode(DebugLightingMode.IndirectDiffuseLighting); break; case LightingProperty.ReflectionOnly: debug.SetDebugLightingMode(DebugLightingMode.ReflectionLighting); break; case LightingProperty.RefractionOnly: debug.SetDebugLightingMode(DebugLightingMode.RefractionLighting); break; case LightingProperty.EmissiveOnly: debug.SetDebugLightingMode(DebugLightingMode.EmissiveLighting); break; default: { debug.SetDebugLightingMode(DebugLightingMode.None); break; } } debug.SetDebugLightFilterMode(m_LightFilterProperty); switch (m_DebugFullScreen) { case DebugFullScreen.None: debug.SetFullScreenDebugMode(FullScreenDebugMode.None); break; case DebugFullScreen.Depth: debug.SetFullScreenDebugMode(FullScreenDebugMode.DepthPyramid); break; case DebugFullScreen.ScreenSpaceAmbientOcclusion: debug.SetFullScreenDebugMode(FullScreenDebugMode.ScreenSpaceAmbientOcclusion); break; case DebugFullScreen.MotionVectors: debug.SetFullScreenDebugMode(FullScreenDebugMode.MotionVectors); break; case DebugFullScreen.WorldSpacePosition: debug.SetFullScreenDebugMode(FullScreenDebugMode.WorldSpacePosition); break; case DebugFullScreen.VolumetricFogOnly: debug.SetFullScreenDebugMode(FullScreenDebugMode.VolumetricFog); break; default: throw new ArgumentException("Unknown DebugFullScreen"); } } /// /// Equality operator. /// /// The AOV request to compare to. /// True if the provided AOV request is equal to this. public override bool Equals(object obj) { return obj is AOVRequest && ((AOVRequest)obj) == this; } /// /// Compares if two AOV requests have the same settings. /// /// The first AOVRequest to compare. /// The second AOVRequest to compare. /// True if the two AOV requests have the same settings. public static bool operator ==(AOVRequest a, AOVRequest b) { return a.m_DebugFullScreen == b.m_DebugFullScreen && a.m_LightFilterProperty == b.m_LightFilterProperty && a.m_LightingProperty == b.m_LightingProperty && a.m_MaterialProperty == b.m_MaterialProperty && a.m_OverrideRenderFormat == b.m_OverrideRenderFormat; } /// /// Compares if two AOV requests have the same settings. /// /// The first AOVRequest to compare. /// The second AOVRequest to compare. /// True if the two AOV requests have not the same settings. public static bool operator !=(AOVRequest a, AOVRequest b) { return !(a == b); } /// /// Computes a hash code for the AOV Request. /// /// A hash code for the AOV Request. public override int GetHashCode() { int hash = 17; hash = hash * 23 + (int)m_DebugFullScreen; hash = hash * 23 + (int)m_LightFilterProperty; hash = hash * 23 + (int)m_LightingProperty; hash = hash * 23 + (int)m_MaterialProperty; hash = m_OverrideRenderFormat ? hash * 23 + 1 : hash; return hash; } } }