using System;
namespace UnityEngine.Rendering.HighDefinition
{
///
/// A bitflags for the probe settings field.
///
[Flags]
public enum ProbeSettingsFields
{
/// No fields
none = 0,
/// type
type = 1 << 0,
/// mode
mode = 1 << 1,
/// lightingMultiplier
lightingMultiplier = 1 << 2,
/// lightingWeight
lightingWeight = 1 << 3,
/// lightingLightLayer
lightingLightLayer = 1 << 4,
/// lightingRangeCompression
lightingRangeCompression = 1 << 5,
/// proxy.useInfluenceVolumeAsProxyVolume
proxyUseInfluenceVolumeAsProxyVolume = 1 << 6,
/// proxy.capturePositionProxySpace
proxyCapturePositionProxySpace = 1 << 7,
/// proxy.captureRotationProxySpace
proxyCaptureRotationProxySpace = 1 << 8,
/// proxy.mirrorPositionProxySpace
proxyMirrorPositionProxySpace = 1 << 9,
/// proxy.mirrorRotationProxySpace
proxyMirrorRotationProxySpace = 1 << 10,
/// frustum.fieldOfViewMode
frustumFieldOfViewMode = 1 << 11,
/// frustum.fixedValue
frustumFixedValue = 1 << 12,
/// frustum.automaticScale
frustumAutomaticScale = 1 << 13,
/// frustum.viewerScale
frustumViewerScale = 1 << 14,
/// lighting.fadeDistance
lightingFadeDistance = 1 << 15,
/// resolution.
resolution = 1 << 16,
/// Rough reflections.
roughReflections = 1 << 17,
}
///
/// The overriden fields of a probe.
///
[Serializable]
struct ProbeSettingsOverride
{
/// Overriden probe settings
public ProbeSettingsFields probe;
/// Overriden camera settings
public CameraSettingsOverride camera;
}
/// Settings that defines the rendering of a probe.
[Serializable]
public struct ProbeSettings
{
/// The type of the probe.
public enum ProbeType
{
///
/// Standard reflection probe.
///
/// A reflection probe captures a cubemap around a capture position.
///
ReflectionProbe,
///
/// Planar reflection probe.
///
/// A planar reflection probe captures a single camera render.
/// The capture position is the mirrored viewer's position against a mirror plane.
/// This plane is defined by the probe's transform:
/// * center = center of the probe
/// * normal = forward of the probe
///
/// The viewer's transform must be provided with
/// and when calling .
///
PlanarProbe
}
/// The rendering mode of the probe.
public enum Mode
{
/// Capture data is baked in editor and loaded as assets.
Baked,
/// Capture data is computed during runtime.
Realtime,
/// Capture data provided as an assets.
Custom
}
/// Realtime mode of the probe.
public enum RealtimeMode
{
/// The real time probe will be rendered when a camera see its influence, once per frame.
EveryFrame,
/// The real time probe will be rendered when a camera see its influence, once after OnEnable.
OnEnable,
/// The real time probe will be rendered when a camera see its influence and the udpate was requested by a script. .
OnDemand
}
/// Lighting parameters for the probe.
[Serializable]
public struct Lighting
{
/// Default value.
[Obsolete("Since 2019.3, use Lighting.NewDefault() instead.")]
public static readonly Lighting @default = default;
/// Default value.
/// The default value.
public static Lighting NewDefault() => new Lighting
{
multiplier = 1.0f,
weight = 1.0f,
lightLayer = LightLayerEnum.LightLayerDefault,
fadeDistance = 10000f,
rangeCompressionFactor = 1.0f
};
/// A multiplier applied to the radiance of the Probe.
public float multiplier;
/// A weight applied to the influence of the Probe.
[Range(0, 1)]
public float weight;
/// An enum flag to select which Light Layers this Probe interacts with.
public LightLayerEnum lightLayer;
/// The distance at which reflections smoothly fade out before HDRP cut them completely.
public float fadeDistance;
/// The result of the rendering of the probe will be divided by this factor. When the probe is read, this factor is undone as the probe data is read.
/// This is to simply avoid issues with values clamping due to precision of the storing format.
[Min(1e-6f)]
public float rangeCompressionFactor;
}
/// Settings of this probe in the current proxy.
[Serializable]
public struct ProxySettings
{
/// Default value.
[Obsolete("Since 2019.3, use ProxySettings.NewDefault() instead.")]
public static readonly ProxySettings @default = default;
/// Default value.
/// The default value.
public static ProxySettings NewDefault() => new ProxySettings
{
capturePositionProxySpace = Vector3.zero,
captureRotationProxySpace = Quaternion.identity,
useInfluenceVolumeAsProxyVolume = false
};
///
/// Whether to use the influence volume as proxy volume
/// when == null.
///
public bool useInfluenceVolumeAsProxyVolume;
/// Position of the capture in proxy space. (Reflection Probe only)
public Vector3 capturePositionProxySpace;
/// Rotation of the capture in proxy space. (Reflection Probe only)
public Quaternion captureRotationProxySpace;
/// Position of the mirror in proxy space. (Planar Probe only)
public Vector3 mirrorPositionProxySpace;
/// Rotation of the mirror in proxy space. (Planar Probe only)
public Quaternion mirrorRotationProxySpace;
}
/// Describe how frustum is handled when rendering probe.
[Serializable]
public struct Frustum
{
/// Obsolete
[Obsolete("Since 2019.3, use Frustum.NewDefault() instead.")]
public static readonly Frustum @default = default;
/// Default value.
/// The default value.
public static Frustum NewDefault() => new Frustum
{
fieldOfViewMode = FOVMode.Viewer,
fixedValue = 90,
automaticScale = 1.0f,
viewerScale = 1.0f
};
///
/// The FOV mode of a probe.
///
public enum FOVMode
{
/// FOV is fixed, its value is in degree.
Fixed,
/// FOV is the one used by the viewer's camera.
Viewer,
/// FOV is computed to encompass the influence volume, then it is multiplied by .
Automatic
}
///
/// Mode to use when computing the field of view.
///
/// For planar reflection probes: this value is used.
/// For reflection probes: this value is ignored, FOV will be 90°.
///
public FOVMode fieldOfViewMode;
/// Value to use when FOV is fixed.
[Range(0, 179f)]
public float fixedValue;
/// The automatic value of the FOV is multiplied by this factor at the end.
[Min(0)]
public float automaticScale;
/// The viewer's FOV is multiplied by this factor at the end.
[Min(0)]
public float viewerScale;
}
/// Default value.
[Obsolete("Since 2019.3, use ProbeSettings.NewDefault() instead.")]
public static ProbeSettings @default = default;
/// Default value.
/// The default value.
public static ProbeSettings NewDefault()
{
ProbeSettings probeSettings = new ProbeSettings
{
type = ProbeType.ReflectionProbe,
realtimeMode = RealtimeMode.EveryFrame,
mode = Mode.Baked,
cameraSettings = CameraSettings.NewDefault(),
influence = null,
lighting = Lighting.NewDefault(),
proxy = null,
proxySettings = ProxySettings.NewDefault(),
frustum = Frustum.NewDefault(),
resolutionScalable = new PlanarReflectionAtlasResolutionScalableSettingValue(),
roughReflections = true,
distanceBasedRoughness = false,
};
probeSettings.resolutionScalable.@override = PlanarReflectionAtlasResolution.Resolution512;
return probeSettings;
}
/// The way the frustum is handled by the probe.
public Frustum frustum;
/// The type of the probe.
public ProbeType type;
/// The mode of the probe.
public Mode mode;
/// The mode of the probe.
public RealtimeMode realtimeMode;
/// The lighting of the probe.
public Lighting lighting;
/// The influence volume of the probe.
public InfluenceVolume influence;
/// Set this variable to explicitly set the proxy volume to use.
public ProxyVolume proxy;
/// The proxy settings of the probe for the current volume.
public ProxySettings proxySettings;
/// An int scalable setting value
[Serializable] public class PlanarReflectionAtlasResolutionScalableSettingValue : ScalableSettingValue {}
/// Camera settings to use when capturing data.
/// The resolution of the probe.
public PlanarReflectionAtlasResolutionScalableSettingValue resolutionScalable;
[SerializeField]
internal PlanarReflectionAtlasResolution resolution;
/// Probe camera settings.
[Serialization.FormerlySerializedAs("camera")]
public CameraSettings cameraSettings;
/// Indicates whether the ReflectionProbe supports rough reflections.
public bool roughReflections;
/// Indicates whether the ReflectionProbe supports distance-based roughness.
public bool distanceBasedRoughness;
///
/// Compute a hash of the settings.
///
/// The computed hash.
public Hash128 ComputeHash()
{
var h = new Hash128();
var h2 = new Hash128();
HashUtilities.ComputeHash128(ref type, ref h);
HashUtilities.ComputeHash128(ref mode, ref h2);
HashUtilities.AppendHash(ref h2, ref h);
HashUtilities.ComputeHash128(ref lighting, ref h2);
HashUtilities.AppendHash(ref h2, ref h);
HashUtilities.ComputeHash128(ref proxySettings, ref h2);
HashUtilities.AppendHash(ref h2, ref h);
h2 = cameraSettings.GetHash();
HashUtilities.AppendHash(ref h2, ref h);
if (influence != null)
{
h2 = influence.ComputeHash();
HashUtilities.AppendHash(ref h2, ref h);
}
if (proxy != null)
{
h2 = proxy.ComputeHash();
HashUtilities.AppendHash(ref h2, ref h);
}
return h;
}
}
}