using System; namespace UnityEngine.Rendering.HighDefinition { /// /// HDRI Sky Volume Component. /// This component setups HDRI sky for rendering. /// [VolumeComponentMenu("Sky/HDRI Sky")] [SupportedOnRenderPipeline(typeof(HDRenderPipelineAsset))] [SkyUniqueID((int)SkyType.HDRI)] [HDRPHelpURL("create-an-hdri-sky")] public partial class HDRISky : SkySettings { /// /// Distortion Mode. /// public enum DistortionMode { /// No distortion. None, /// Procedural distortion. Procedural, /// Distortion from a flowmap. Flowmap, } /// Cubemap used to render the HDRI sky. [Tooltip("Specify the cubemap HDRP uses to render the sky.")] public CubemapParameter hdriSky = new CubemapParameter(null); /// Distortion mode. [Tooltip("Distortion mode to simulate sky movement.\nIn Scene View, requires Always Refresh to be enabled.")] public VolumeParameter distortionMode = new VolumeParameter(); /// Texture used to distort the uv for the HDRI sky. [Tooltip("Specify the flowmap HDRP uses for sky distortion (in LatLong layout).")] public Texture2DParameter flowmap = new Texture2DParameter(null); /// Enable to affect only the upper part of the sky. [Tooltip("Check this box if the flowmap covers only the upper part of the sky.")] public BoolParameter upperHemisphereOnly = new BoolParameter(true); /// Direction of the distortion. This value can be relative to the Global Wind Orientation defined in the Visual Environment. public WindOrientationParameter scrollOrientation = new WindOrientationParameter(); /// Speed of the distortion. This value can be relative to the Global Wind Speed defined in the Visual Environment. public WindSpeedParameter scrollSpeed = new WindSpeedParameter(); /// Sets the initial rotation of the sun to allow us to rotate the sun with the sky if the sun is locked public FloatParameter sunInitialRotation = new FloatParameter(float.NegativeInfinity); /// Locks the sun to the backplate rotation [Tooltip("Enable to have the sun locked to the rotation")] public BoolParameter lockSun = new BoolParameter(false); /// Enable Backplate to have it visible. [AdditionalProperty] [Tooltip("Enable or disable the backplate.")] public BoolParameter enableBackplate = new BoolParameter(false); /// Backplate Type {Disc, Rectangle, Ellipse, Infinite (Plane)}. [AdditionalProperty] [Tooltip("Backplate type.")] public BackplateTypeParameter backplateType = new BackplateTypeParameter(BackplateType.Disc); /// Define the ground level of the Backplate. [AdditionalProperty] [Tooltip("Define the ground level of the Backplate.")] public FloatParameter groundLevel = new FloatParameter(0.0f); /// Extent of the Backplate (if circle only the X value is considered). [AdditionalProperty] [Tooltip("Extent of the Backplate (if circle only the X value is considered).")] public Vector2Parameter scale = new Vector2Parameter(Vector2.one * 32.0f); /// Backplate's projection distance to varying the cubemap projection on the plate. [AdditionalProperty] [Tooltip("Backplate's projection distance to varying the cubemap projection on the plate.")] public MinFloatParameter projectionDistance = new MinFloatParameter(16.0f, 1e-7f); /// Backplate rotation parameter for the geometry. [AdditionalProperty] [Tooltip("Backplate rotation parameter for the geometry.")] public ClampedFloatParameter plateRotation = new ClampedFloatParameter(0.0f, 0.0f, 360.0f); /// Backplate rotation parameter for the projected texture. [AdditionalProperty] [Tooltip("Backplate rotation parameter for the projected texture.")] public ClampedFloatParameter plateTexRotation = new ClampedFloatParameter(0.0f, 0.0f, 360.0f); /// Backplate projection offset on the plane. [AdditionalProperty] [Tooltip("Backplate projection offset on the plane.")] public Vector2Parameter plateTexOffset = new Vector2Parameter(Vector2.zero); /// Backplate blend parameter to blend the edge of the backplate with the background. [AdditionalProperty] [Tooltip("Backplate blend parameter to blend the edge of the backplate with the background.")] public ClampedFloatParameter blendAmount = new ClampedFloatParameter(0.0f, 0.0f, 100.0f); /// Backplate Shadow Tint projected on the plane. [AdditionalProperty] [Tooltip("Backplate Shadow Tint projected on the plane.")] public ColorParameter shadowTint = new ColorParameter(Color.grey); /// Allow backplate to receive shadow from point light. [AdditionalProperty] [Tooltip("Allow backplate to receive shadow from point light.")] public BoolParameter pointLightShadow = new BoolParameter(false); /// Allow backplate to receive shadow from directional light. [AdditionalProperty] [Tooltip("Allow backplate to receive shadow from directional light.")] public BoolParameter dirLightShadow = new BoolParameter(false); /// Allow backplate to receive shadow from Area light. [AdditionalProperty] [Tooltip("Allow backplate to receive shadow from Area light.")] public BoolParameter rectLightShadow = new BoolParameter(false); /// /// Unity calls this method when it loads the class. /// protected override void OnEnable() { base.OnEnable(); // This is kind of a migration step, as on previous HDRP versions, HDRI sky editor // didn't correctly set these values upperHemisphereLuxValue.overrideState = hdriSky.overrideState; upperHemisphereLuxColor.overrideState = hdriSky.overrideState; } /// /// Returns the hash code of the HDRI sky parameters. /// /// The hash code of the HDRI sky parameters. public override int GetHashCode() { int hash = base.GetHashCode(); unchecked { #if UNITY_2019_3 // In 2019.3, when we call GetHashCode on a VolumeParameter it generate garbage (due to the boxing of the generic parameter) hash = hdriSky.value != null ? hash * 23 + hdriSky.value.GetHashCode() : hash; hash = flowmap.value != null ? hash * 23 + flowmap.value.GetHashCode() : hash; hash = hash * 23 + enableDistortion.value.GetHashCode(); hash = hash * 23 + procedural.value.GetHashCode(); hash = hash * 23 + upperHemisphereOnly.value.GetHashCode(); hash = hash * 23 + scrollDirection.value.GetHashCode(); hash = hash * 23 + scrollSpeed.value.GetHashCode(); hash = hash * 23 + enableBackplate.value.GetHashCode(); hash = hash * 23 + backplateType.value.GetHashCode(); hash = hash * 23 + groundLevel.value.GetHashCode(); hash = hash * 23 + scale.value.GetHashCode(); hash = hash * 23 + projectionDistance.value.GetHashCode(); hash = hash * 23 + plateRotation.value.GetHashCode(); hash = hash * 23 + plateTexRotation.value.GetHashCode(); hash = hash * 23 + plateTexOffset.value.GetHashCode(); hash = hash * 23 + blendAmount.value.GetHashCode(); hash = hash * 23 + shadowTint.value.GetHashCode(); hash = hash * 23 + pointLightShadow.value.GetHashCode(); hash = hash * 23 + dirLightShadow.value.GetHashCode(); hash = hash * 23 + rectLightShadow.value.GetHashCode(); hash = hdriSky.value != null ? hash * 23 + hdriSky.overrideState.GetHashCode() : hash; hash = flowmap.value != null ? hash * 23 + flowmap.overrideState.GetHashCode() : hash; hash = hash * 23 + enableDistortion.overrideState.GetHashCode(); hash = hash * 23 + procedural.overrideState.GetHashCode(); hash = hash * 23 + upperHemisphereOnly.overrideState.GetHashCode(); hash = hash * 23 + scrollDirection.overrideState.GetHashCode(); hash = hash * 23 + scrollSpeed.overrideState.GetHashCode(); hash = hash * 23 + enableBackplate.overrideState.GetHashCode(); hash = hash * 23 + backplateType.overrideState.GetHashCode(); hash = hash * 23 + groundLevel.overrideState.GetHashCode(); hash = hash * 23 + scale.overrideState.GetHashCode(); hash = hash * 23 + projectionDistance.overrideState.GetHashCode(); hash = hash * 23 + plateRotation.overrideState.GetHashCode(); hash = hash * 23 + plateTexRotation.overrideState.GetHashCode(); hash = hash * 23 + plateTexOffset.overrideState.GetHashCode(); hash = hash * 23 + blendAmount.overrideState.GetHashCode(); hash = hash * 23 + shadowTint.overrideState.GetHashCode(); hash = hash * 23 + pointLightShadow.overrideState.GetHashCode(); hash = hash * 23 + dirLightShadow.overrideState.GetHashCode(); hash = hash * 23 + rectLightShadow.overrideState.GetHashCode(); #else hash = hash * 23 + hdriSky.GetHashCode(); hash = hash * 23 + flowmap.GetHashCode(); hash = hash * 23 + distortionMode.GetHashCode(); hash = hash * 23 + upperHemisphereOnly.GetHashCode(); hash = hash * 23 + scrollOrientation.GetHashCode(); hash = hash * 23 + scrollSpeed.GetHashCode(); hash = hash * 23 + enableBackplate.GetHashCode(); hash = hash * 23 + backplateType.GetHashCode(); hash = hash * 23 + groundLevel.GetHashCode(); hash = hash * 23 + scale.GetHashCode(); hash = hash * 23 + projectionDistance.GetHashCode(); hash = hash * 23 + plateRotation.GetHashCode(); hash = hash * 23 + plateTexRotation.GetHashCode(); hash = hash * 23 + plateTexOffset.GetHashCode(); hash = hash * 23 + blendAmount.GetHashCode(); hash = hash * 23 + shadowTint.GetHashCode(); hash = hash * 23 + pointLightShadow.GetHashCode(); hash = hash * 23 + dirLightShadow.GetHashCode(); hash = hash * 23 + rectLightShadow.GetHashCode(); #endif } return hash; } /// /// Determines if the SkySettings is significantly divergent from another. This is going to be used to determine whether /// to reset completely the ambient probe instead of using previous one when waiting for current data upon changes. /// In addition to the checks done with the base function, this HDRISky override checks whether the cubemap parameter /// has changed if both settings are HDRISky. /// /// The settings to compare with. /// Whether the settings are deemed very different. public override bool SignificantlyDivergesFrom(SkySettings otherSettings) { HDRISky otherHdriSkySettings = otherSettings as HDRISky; return base.SignificantlyDivergesFrom(otherSettings) || hdriSky.value != otherHdriSkySettings.hdriSky.value; } /// /// Returns HDRISkyRenderer type. /// /// HDRISkyRenderer type. public override Type GetSkyRendererType() { return typeof(HDRISkyRenderer); } } }