using System; using UnityEngine.Serialization; using UnityEngine.Experimental.Rendering; namespace UnityEngine.Experimental.Rendering.HDPipeline { [Serializable] public class InfluenceVolume { HDProbe m_Probe; [SerializeField, FormerlySerializedAs("m_ShapeType")] InfluenceShape m_Shape = InfluenceShape.Box; [SerializeField, FormerlySerializedAs("m_BoxBaseOffset")] Vector3 m_Offset; #pragma warning disable 649 //never assigned [SerializeField, Obsolete("Kept only for compatibility. Use m_Offset instead")] Vector3 m_SphereBaseOffset; #pragma warning restore 649 //never assigned // Box [SerializeField, FormerlySerializedAs("m_BoxBaseSize")] Vector3 m_BoxSize = Vector3.one * 10; [SerializeField, FormerlySerializedAs("m_BoxInfluencePositiveFade")] Vector3 m_BoxBlendDistancePositive; [SerializeField, FormerlySerializedAs("m_BoxInfluenceNegativeFade")] Vector3 m_BoxBlendDistanceNegative; [SerializeField, FormerlySerializedAs("m_BoxInfluenceNormalPositiveFade")] Vector3 m_BoxBlendNormalDistancePositive; [SerializeField, FormerlySerializedAs("m_BoxInfluenceNormalNegativeFade")] Vector3 m_BoxBlendNormalDistanceNegative; [SerializeField, FormerlySerializedAs("m_BoxPositiveFaceFade")] Vector3 m_BoxSideFadePositive = Vector3.one; [SerializeField, FormerlySerializedAs("m_BoxNegativeFaceFade")] Vector3 m_BoxSideFadeNegative = Vector3.one; //editor value that need to be saved for easy passing from simplified to advanced and vice et versa // /!\ must not be used outside editor code [SerializeField, FormerlySerializedAs("editorAdvancedModeBlendDistancePositive")] Vector3 m_EditorAdvancedModeBlendDistancePositive; [SerializeField, FormerlySerializedAs("editorAdvancedModeBlendDistanceNegative")] Vector3 m_EditorAdvancedModeBlendDistanceNegative; [SerializeField, FormerlySerializedAs("editorSimplifiedModeBlendDistance")] float m_EditorSimplifiedModeBlendDistance; [SerializeField, FormerlySerializedAs("editorAdvancedModeBlendNormalDistancePositive")] Vector3 m_EditorAdvancedModeBlendNormalDistancePositive; [SerializeField, FormerlySerializedAs("editorAdvancedModeBlendNormalDistanceNegative")] Vector3 m_EditorAdvancedModeBlendNormalDistanceNegative; [SerializeField, FormerlySerializedAs("editorSimplifiedModeBlendNormalDistance")] float m_EditorSimplifiedModeBlendNormalDistance; [SerializeField, FormerlySerializedAs("editorAdvancedModeEnabled")] bool m_EditorAdvancedModeEnabled; // Sphere [SerializeField, FormerlySerializedAs("m_SphereBaseRadius")] float m_SphereRadius = 1; [SerializeField, FormerlySerializedAs("m_SphereInfluenceFade")] float m_SphereBlendDistance; [SerializeField, FormerlySerializedAs("m_SphereInfluenceNormalFade")] float m_SphereBlendNormalDistance; internal void CopyTo(InfluenceVolume data) { //keep the m_Probe as it is used to reset the probe data.m_Shape = m_Shape; data.m_Offset = m_Offset; data.m_BoxSize = m_BoxSize; data.m_BoxBlendDistancePositive = m_BoxBlendDistancePositive; data.m_BoxBlendDistanceNegative = m_BoxBlendDistanceNegative; data.m_BoxBlendNormalDistancePositive = m_BoxBlendNormalDistancePositive; data.m_BoxBlendNormalDistanceNegative = m_BoxBlendNormalDistanceNegative; data.m_BoxSideFadePositive = m_BoxSideFadePositive; data.m_BoxSideFadeNegative = m_BoxSideFadeNegative; data.m_SphereRadius = m_SphereRadius; data.m_SphereBlendDistance = m_SphereBlendDistance; data.m_SphereBlendNormalDistance = m_SphereBlendNormalDistance; data.m_EditorAdvancedModeBlendDistancePositive = m_EditorAdvancedModeBlendDistancePositive; data.m_EditorAdvancedModeBlendDistanceNegative = m_EditorAdvancedModeBlendDistanceNegative; data.m_EditorSimplifiedModeBlendDistance = m_EditorSimplifiedModeBlendDistance; data.m_EditorAdvancedModeBlendNormalDistancePositive = m_EditorAdvancedModeBlendNormalDistancePositive; data.m_EditorAdvancedModeBlendNormalDistanceNegative = m_EditorAdvancedModeBlendNormalDistanceNegative; data.m_EditorSimplifiedModeBlendNormalDistance = m_EditorSimplifiedModeBlendNormalDistance; data.m_EditorAdvancedModeEnabled = m_EditorAdvancedModeEnabled; } /// Shape of this InfluenceVolume. public InfluenceShape shape { get { return m_Shape; } set { m_Shape = value; switch (m_Shape) { case InfluenceShape.Box: m_Probe.UpdatedInfluenceVolumeShape(m_BoxSize, offset); break; case InfluenceShape.Sphere: m_Probe.UpdatedInfluenceVolumeShape(Vector3.one * (2 * m_SphereRadius), offset); break; } } } /// Offset of this influence volume to the component handling him. public Vector3 offset { get { return m_Offset; } set { m_Offset = value; } } /// Size of the InfluenceVolume in Box Mode. public Vector3 boxSize { get { return m_BoxSize; } set { m_BoxSize = value; m_Probe.UpdatedInfluenceVolumeShape(m_BoxSize, offset); } } /// Offset of sub volume defining fading. public Vector3 boxBlendOffset { get { return (boxBlendDistanceNegative - boxBlendDistancePositive) * 0.5f; } } /// Size of sub volume defining fading. public Vector3 boxBlendSize { get { return -(boxBlendDistancePositive + boxBlendDistanceNegative); } } /// /// Position of fade sub volume maxOffset point relative to InfluenceVolume max corner. /// Values between 0 (on InfluenceVolume hull) to half of boxSize corresponding axis. /// public Vector3 boxBlendDistancePositive { get { return m_BoxBlendDistancePositive; } set { m_BoxBlendDistancePositive = value; } } /// /// Position of fade sub volume minOffset point relative to InfluenceVolume min corner. /// Values between 0 (on InfluenceVolume hull) to half of boxSize corresponding axis. /// public Vector3 boxBlendDistanceNegative { get { return m_BoxBlendDistanceNegative; } set { m_BoxBlendDistanceNegative = value; } } /// Offset of sub volume defining fading relative to normal orientation. public Vector3 boxBlendNormalOffset { get { return (boxBlendNormalDistanceNegative - boxBlendNormalDistancePositive) * 0.5f; } } /// Size of sub volume defining fading relative to normal orientation. public Vector3 boxBlendNormalSize { get { return -(boxBlendNormalDistancePositive + boxBlendNormalDistanceNegative); } } /// /// Position of normal fade sub volume maxOffset point relative to InfluenceVolume max corner. /// Values between 0 (on InfluenceVolume hull) to half of boxSize corresponding axis (on origin for this axis). /// public Vector3 boxBlendNormalDistancePositive { get { return m_BoxBlendNormalDistancePositive; } set { m_BoxBlendNormalDistancePositive = value; } } /// /// Position of normal fade sub volume minOffset point relative to InfluenceVolume min corner. /// Values between 0 (on InfluenceVolume hull) to half of boxSize corresponding axis (on origin for this axis). /// public Vector3 boxBlendNormalDistanceNegative { get { return m_BoxBlendNormalDistanceNegative; } set { m_BoxBlendNormalDistanceNegative = value; } } /// Define fading percent of +X, +Y and +Z locally oriented face. (values from 0 to 1) public Vector3 boxSideFadePositive { get { return m_BoxSideFadePositive; } set { m_BoxSideFadePositive = value; } } /// Define fading percent of -X, -Y and -Z locally oriented face. (values from 0 to 1) public Vector3 boxSideFadeNegative { get { return m_BoxSideFadeNegative; } set { m_BoxSideFadeNegative = value; } } /// Radius of the InfluenceVolume in Sphere Mode. public float sphereRadius { get { return m_SphereRadius; } set { m_SphereRadius = value; m_Probe.UpdatedInfluenceVolumeShape(Vector3.one * (2 * m_SphereRadius), offset); } } /// /// Offset of the fade sub volume from InfluenceVolume hull. /// Value between 0 (on InfluenceVolume hull) and sphereRadius (fade sub volume reduced to a point). /// public float sphereBlendDistance { get { return m_SphereBlendDistance; } set { m_SphereBlendDistance = value; } } /// /// Offset of the normal fade sub volume from InfluenceVolume hull. /// Value between 0 (on InfluenceVolume hull) and sphereRadius (fade sub volume reduced to a point). /// public float sphereBlendNormalDistance { get { return m_SphereBlendNormalDistance; } set { m_SphereBlendNormalDistance = value; } } internal void Init(HDProbe probe) { this.m_Probe = probe; } internal BoundingSphere GetBoundingSphereAt(Transform probeTransform) { switch (shape) { default: case InfluenceShape.Sphere: return new BoundingSphere(probeTransform.TransformPoint(offset), sphereRadius); case InfluenceShape.Box: { var position = probeTransform.TransformPoint(offset); var radius = Mathf.Max(boxSize.x, Mathf.Max(boxSize.y, boxSize.z)); return new BoundingSphere(position, radius); } } } internal Bounds GetBoundsAt(Transform probeTransform) { switch (shape) { default: case InfluenceShape.Sphere: return new Bounds(probeTransform.position, Vector3.one * sphereRadius); case InfluenceShape.Box: { var position = probeTransform.TransformPoint(offset); return new Bounds(position, boxSize); } } } internal Vector3 GetWorldPosition(Transform probeTransform) { return probeTransform.TransformPoint(offset); } internal void MigrateOffsetSphere() { if (shape == InfluenceShape.Sphere) { #pragma warning disable CS0618 // Type or member is obsolete m_Offset = m_SphereBaseOffset; #pragma warning restore CS0618 // Type or member is obsolete } } } }