using System ;
using UnityEngine.Serialization ;
using UnityEngine.Experimental.Rendering ;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[SerializeField]
ShapeType m_ShapeType = ShapeType . Box ;
HDProbe probe ;
[SerializeField, FormerlySerializedAs("m_ShapeType")]
Shape m_Shape = Shape . 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
[SerializeField]
Vector3 m_BoxBaseSize = Vector3 . one ;
[SerializeField]
Vector3 m_BoxBaseOffset ;
[SerializeField]
Vector3 m_BoxInfluencePositiveFade ;
[SerializeField]
Vector3 m_BoxInfluenceNegativeFade ;
[SerializeField]
Vector3 m_BoxInfluenceNormalPositiveFade ;
[SerializeField]
Vector3 m_BoxInfluenceNormalNegativeFade ;
[SerializeField]
Vector3 m_BoxPositiveFaceFade = Vector3 . one ;
[SerializeField]
Vector3 m_BoxNegativeFaceFade = Vector3 . one ;
[SerializeField, FormerlySerializedAs("m_BoxBaseSize")]
Vector3 m_BoxSize = Vector3 . one * 1 0 ;
[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 ;
[SerializeField] private Vector3 editorAdvancedModeBlendDistancePositive ;
[SerializeField] private Vector3 editorAdvancedModeBlendDistanceNegative ;
[SerializeField] private float editorSimplifiedModeBlendDistance ;
[SerializeField] private Vector3 editorAdvancedModeBlendNormalDistancePositive ;
[SerializeField] private Vector3 editorAdvancedModeBlendNormalDistanceNegative ;
[SerializeField] private float editorSimplifiedModeBlendNormalDistance ;
[SerializeField] private bool editorAdvancedModeEnabled ;
[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 ;
[SerializeField]
float m_SphereBaseRadius = 1 ;
[SerializeField]
Vector3 m_SphereBaseOffset ;
[SerializeField]
float m_SphereInfluenceFade ;
[SerializeField]
float m_SphereInfluenceNormalFade ;
[SerializeField, FormerlySerializedAs("m_SphereBaseRadius")]
float m_SphereRadius = 1 ;
[SerializeField, FormerlySerializedAs("m_SphereInfluenceFade")]
float m_SphereBlendDistance ;
[SerializeField, FormerlySerializedAs("m_SphereInfluenceNormalFade")]
float m_SphereBlendNormalDistance ;
public ShapeType shapeType { get { return m_ShapeType ; } }
/// <summary>Shape of this InfluenceVolume.</summary>
public Shape shape
{
get { return m_Shape ; }
set
{
m_Shape = value ;
switch ( m_Shape )
{
case Shape . Box :
probe . UpdatedInfluenceVolumeShape ( m_BoxSize , offset ) ;
break ;
case Shape . Sphere :
probe . UpdatedInfluenceVolumeShape ( Vector3 . one * ( 2 * m_SphereRadius ) , offset ) ;
break ;
}
}
}
public Vector3 boxBaseSize { get { return m_BoxBaseSize ; } set { m_BoxBaseSize = value ; } }
public Vector3 boxBaseOffset { get { return m_BoxBaseOffset ; } set { m_BoxBaseOffset = value ; } }
public Vector3 boxInfluencePositiveFade { get { return m_BoxInfluencePositiveFade ; } set { m_BoxInfluencePositiveFade = value ; } }
public Vector3 boxInfluenceNegativeFade { get { return m_BoxInfluenceNegativeFade ; } set { m_BoxInfluenceNegativeFade = value ; } }
public Vector3 boxInfluenceNormalPositiveFade { get { return m_BoxInfluenceNormalPositiveFade ; } set { m_BoxInfluenceNormalPositiveFade = value ; } }
public Vector3 boxInfluenceNormalNegativeFade { get { return m_BoxInfluenceNormalNegativeFade ; } set { m_BoxInfluenceNormalNegativeFade = value ; } }
public Vector3 boxPositiveFaceFade { get { return m_BoxPositiveFaceFade ; } set { m_BoxPositiveFaceFade = value ; } }
public Vector3 boxNegativeFaceFade { get { return m_BoxNegativeFaceFade ; } set { m_BoxNegativeFaceFade = value ; } }
/// <summary>Offset of this influence volume to the component handling him.</summary>
public Vector3 offset { get { return m_Offset ; } set { m_Offset = value ; } }
public Vector3 boxInfluenceOffset { get { return ( boxInfluenceNegativeFade - boxInfluencePositiveFade ) * 0.5f ; } }
public Vector3 boxInfluenceSizeOffset { get { return - ( boxInfluencePositiveFade + boxInfluenceNegativeFade ) ; } }
public Vector3 boxInfluenceNormalOffset { get { return ( boxInfluenceNormalNegativeFade - boxInfluenceNormalPositiveFade ) * 0.5f ; } }
public Vector3 boxInfluenceNormalSizeOffset { get { return - ( boxInfluenceNormalPositiveFade + boxInfluenceNormalNegativeFade ) ; } }
/// <summary>Size of the InfluenceVolume in Box Mode.</summary>
public Vector3 boxSize
{
get { return m_BoxSize ; }
set
{
m_BoxSize = value ;
probe . UpdatedInfluenceVolumeShape ( m_BoxSize , offset ) ;
}
}
/// <summary>Offset of sub volume defining fading.</summary>
public Vector3 boxBlendOffset { get { return ( boxBlendDistanceNegative - boxBlendDistancePositive ) * 0.5f ; } }
/// <summary>Size of sub volume defining fading.</summary>
public Vector3 boxBlendSize { get { return - ( boxBlendDistancePositive + boxBlendDistanceNegative ) ; } }
/// <summary>
/// Position of fade sub volume maxOffset point relative to InfluenceVolume max corner.
/// Values between 0 (on InfluenceVolume hull) to half of boxSize corresponding axis.
/// </summary>
public Vector3 boxBlendDistancePositive { get { return m_BoxBlendDistancePositive ; } set { m_BoxBlendDistancePositive = value ; } }
/// <summary>
/// Position of fade sub volume minOffset point relative to InfluenceVolume min corner.
/// Values between 0 (on InfluenceVolume hull) to half of boxSize corresponding axis.
/// </summary>
public Vector3 boxBlendDistanceNegative { get { return m_BoxBlendDistanceNegative ; } set { m_BoxBlendDistanceNegative = value ; } }
/// <summary>Offset of sub volume defining fading relative to normal orientation.</summary>
public Vector3 boxBlendNormalOffset { get { return ( boxBlendNormalDistanceNegative - boxBlendNormalDistancePositive ) * 0.5f ; } }
/// <summary>Size of sub volume defining fading relative to normal orientation.</summary>
public Vector3 boxBlendNormalSize { get { return - ( boxBlendNormalDistancePositive + boxBlendNormalDistanceNegative ) ; } }
/// <summary>
/// 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).
/// </summary>
public Vector3 boxBlendNormalDistancePositive { get { return m_BoxBlendNormalDistancePositive ; } set { m_BoxBlendNormalDistancePositive = value ; } }
/// <summary>
/// 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).
/// </summary>
public Vector3 boxBlendNormalDistanceNegative { get { return m_BoxBlendNormalDistanceNegative ; } set { m_BoxBlendNormalDistanceNegative = value ; } }
/// <summary>Define fading percent of +X, +Y and +Z locally oriented face. (values from 0 to 1)</summary>
public Vector3 boxSideFadePositive { get { return m_BoxSideFadePositive ; } set { m_BoxSideFadePositive = value ; } }
/// <summary>Define fading percent of -X, -Y and -Z locally oriented face. (values from 0 to 1)</summary>
public Vector3 boxSideFadeNegative { get { return m_BoxSideFadeNegative ; } set { m_BoxSideFadeNegative = value ; } }
public float sphereBaseRadius { get { return m_SphereBaseRadius ; } set { m_SphereBaseRadius = value ; } }
public Vector3 sphereBaseOffset { get { return m_SphereBaseOffset ; } set { m_SphereBaseOffset = value ; } }
public float sphereInfluenceFade { get { return m_SphereInfluenceFade ; } set { m_SphereInfluenceFade = value ; } }
public float sphereInfluenceNormalFade { get { return m_SphereInfluenceNormalFade ; } set { m_SphereInfluenceNormalFade = value ; } }
/// <summary>Radius of the InfluenceVolume in Sphere Mode.</summary>
public float sphereRadius
{
get { return m_SphereRadius ; }
set
{
m_SphereRadius = value ;
probe . UpdatedInfluenceVolumeShape ( Vector3 . one * ( 2 * m_SphereRadius ) , offset ) ;
}
}
/// <summary>
/// Offset of the fade sub volume from InfluenceVolume hull.
/// Value between 0 (on InfluenceVolume hull) and sphereRadius (fade sub volume reduced to a point).
/// </summary>
public float sphereBlendDistance { get { return m_SphereBlendDistance ; } set { m_SphereBlendDistance = value ; } }
/// <summary>
/// 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).
/// </summary>
public float sphereBlendNormalDistance { get { return m_SphereBlendNormalDistance ; } set { m_SphereBlendNormalDistance = value ; } }
internal InfluenceVolume ( HDProbe probe )
{
Init ( probe ) ;
}
public float sphereInfluenceRadiusOffset { get { return - sphereInfluenceFade ; } }
public float sphereInfluenceNormalRadiusOffset { get { return - sphereInfluenceNormalFade ; } }
internal void Init ( HDProbe probe )
{
this . probe = probe ;
}
public BoundingSphere GetBoundingSphereAt ( Transform transform )
internal BoundingSphere GetBoundingSphereAt ( Transform probeTransform )
switch ( shapeType )
switch ( shape )
case ShapeType . Sphere :
return new BoundingSphere ( transform . TransformPoint ( sphereBaseOffset ) , sphereBaseRadius ) ;
case ShapeType . Box :
case Shape . Sphere :
return new BoundingSphere ( probeTransform . TransformPoint ( offset ) , sphereRadius ) ;
case Shape . Box :
var position = transform . TransformPoint ( boxBaseOffset ) ;
var radius = Mathf . Max ( boxBaseSize . x , Mathf . Max ( boxBaseSize . y , boxBaseSize . z ) ) ;
var position = probeTransform . TransformPoint ( offset ) ;
var radius = Mathf . Max ( boxSize . x , Mathf . Max ( boxSize . y , boxSize . z ) ) ;
public Bounds GetBoundsAt ( Transform transform )
internal Bounds GetBoundsAt ( Transform probeTransform )
switch ( shapeType )
switch ( shape )
case ShapeType . Sphere :
return new Bounds ( transform . position , Vector3 . one * sphereBaseRadius ) ;
case ShapeType . Box :
case Shape . Sphere :
return new Bounds ( probeTransform . position , Vector3 . one * sphereRadius ) ;
case Shape . Box :
var position = transform . TransformPoint ( boxBaseOffset ) ;
// TODO: Return a proper AABB based on influence box volume
return new Bounds ( position , boxBaseSize ) ;
var position = probeTransform . TransformPoint ( offset ) ;
return new Bounds ( position , boxSize ) ;
public Vector3 GetWorldPosition ( Transform transform )
internal Vector3 GetWorldPosition ( Transform probeTransform )
{
return probeTransform . TransformPoint ( offset ) ;
}
internal void MigrateOffsetSphere ( )
switch ( shapeType )
if ( shape = = Shape . Sphere )
default :
case ShapeType . Sphere :
return transform . TransformPoint ( sphereBaseOffset ) ;
case ShapeType . Box :
return transform . TransformPoint ( boxBaseOffset ) ;
#pragma warning disable CS0618 // Type or member is obsolete
m_Offset = m_SphereBaseOffset ;
#pragma warning restore CS0618 // Type or member is obsolete
}
}
}