|
|
|
|
|
|
using System; |
|
|
|
using UnityEngine.Serialization; |
|
|
|
|
|
|
|
namespace UnityEngine.Experimental.Rendering.HDPipeline |
|
|
|
{ |
|
|
|
|
|
|
[SerializeField] |
|
|
|
ShapeType m_ShapeType = ShapeType.Box; |
|
|
|
[SerializeField, FormerlySerializedAs("m_ShapeType")] |
|
|
|
Shape m_Shape = Shape.Box; |
|
|
|
[SerializeField, FormerlySerializedAs("m_BoxBaseOffset")] |
|
|
|
Vector3 m_Offset; |
|
|
|
[SerializeField, Obsolete("Kept only for compatibility. Use m_Offset instead")] |
|
|
|
Vector3 m_SphereBaseOffset; |
|
|
|
[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_BoxInfluencePositiveFade")] |
|
|
|
Vector3 m_BoxPositiveFade; |
|
|
|
[SerializeField, FormerlySerializedAs("m_BoxInfluenceNegativeFade")] |
|
|
|
Vector3 m_BoxNegativeFade; |
|
|
|
[SerializeField, FormerlySerializedAs("m_BoxInfluenceNormalPositiveFade")] |
|
|
|
Vector3 m_BoxNormalPositiveFade; |
|
|
|
[SerializeField, FormerlySerializedAs("m_BoxInfluenceNormalNegativeFade")] |
|
|
|
Vector3 m_BoxNormalNegativeFade; |
|
|
|
[SerializeField, FormerlySerializedAs("m_BoxPositiveFaceFade")] |
|
|
|
Vector3 m_BoxFacePositiveFade = Vector3.one; |
|
|
|
[SerializeField, FormerlySerializedAs("m_BoxNegativeFaceFade")] |
|
|
|
Vector3 m_BoxFaceNegativeFade = 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] private bool editorAdvancedModeEnabled; |
|
|
|
|
|
|
|
// Sphere
|
|
|
|
[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; } } |
|
|
|
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 boxSize { get { return m_BoxBaseSize; } set { m_BoxBaseSize = value; } } |
|
|
|
|
|
|
|
public Vector3 boxBlendOffset { get { return (boxBlendDistanceNegative - boxBlendDistancePositive) * 0.5f; } } |
|
|
|
public Vector3 boxBlendSize { get { return -(boxBlendDistancePositive + boxBlendDistanceNegative); } } |
|
|
|
public Vector3 boxBlendDistancePositive { get { return m_BoxPositiveFade; } set { m_BoxPositiveFade = value; } } |
|
|
|
public Vector3 boxBlendDistanceNegative { get { return m_BoxNegativeFade; } set { m_BoxNegativeFade = 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); } } |
|
|
|
public Vector3 boxBlendNormalOffset { get { return (boxBlendNormalDistanceNegative - boxBlendNormalDistancePositive) * 0.5f; } } |
|
|
|
public Vector3 boxBlendNormalSize { get { return -(boxBlendNormalDistancePositive + boxBlendNormalDistanceNegative); } } |
|
|
|
public Vector3 boxBlendNormalDistancePositive { get { return m_BoxNormalPositiveFade; } set { m_BoxNormalPositiveFade = value; } } |
|
|
|
public Vector3 boxBlendNormalDistanceNegative { get { return m_BoxNormalNegativeFade; } set { m_BoxNormalNegativeFade = value; } } |
|
|
|
public Vector3 boxSideFadePositive { get { return m_BoxFacePositiveFade; } set { m_BoxFacePositiveFade = value; } } |
|
|
|
public Vector3 boxSideFadeNegative { get { return m_BoxFaceNegativeFade; } set { m_BoxFaceNegativeFade = 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; } } |
|
|
|
public float sphereInfluenceRadiusOffset { get { return -sphereInfluenceFade; } } |
|
|
|
public float sphereInfluenceNormalRadiusOffset { get { return -sphereInfluenceNormalFade; } } |
|
|
|
public float sphereRadius { get { return m_SphereRadius; } set { m_SphereRadius = value; } } |
|
|
|
public float sphereBlendDistance { get { return m_SphereBlendDistance; } set { m_SphereBlendDistance = value; } } |
|
|
|
public float sphereBlendNormalDistance { get { return m_SphereBlendNormalDistance; } set { m_SphereBlendNormalDistance = value; } } |
|
|
|
switch (shapeType) |
|
|
|
switch (shape) |
|
|
|
case ShapeType.Sphere: |
|
|
|
return new BoundingSphere(transform.TransformPoint(sphereBaseOffset), sphereBaseRadius); |
|
|
|
case ShapeType.Box: |
|
|
|
case Shape.Sphere: |
|
|
|
return new BoundingSphere(transform.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 = transform.TransformPoint(offset); |
|
|
|
var radius = Mathf.Max(boxSize.x, Mathf.Max(boxSize.y, boxSize.z)); |
|
|
|
return new BoundingSphere(position, radius); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
{ |
|
|
|
switch (shapeType) |
|
|
|
switch (shape) |
|
|
|
case ShapeType.Sphere: |
|
|
|
return new Bounds(transform.position, Vector3.one * sphereBaseRadius); |
|
|
|
case ShapeType.Box: |
|
|
|
case Shape.Sphere: |
|
|
|
return new Bounds(transform.position, Vector3.one * sphereRadius); |
|
|
|
case Shape.Box: |
|
|
|
var position = transform.TransformPoint(boxBaseOffset); |
|
|
|
var position = transform.TransformPoint(offset); |
|
|
|
return new Bounds(position, boxBaseSize); |
|
|
|
return new Bounds(position, boxSize); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
switch (shapeType) |
|
|
|
return transform.TransformPoint(offset); |
|
|
|
} |
|
|
|
|
|
|
|
internal void MigrateOffsetSphere() |
|
|
|
{ |
|
|
|
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
|
|
|
|
} |
|
|
|
} |
|
|
|
} |