您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
160 行
5.8 KiB
160 行
5.8 KiB
using UnityEngine.Rendering;
|
|
|
|
namespace UnityEngine.Experimental.Rendering.HDPipeline
|
|
{
|
|
[ExecuteInEditMode]
|
|
public class PlanarReflectionProbe : MonoBehaviour
|
|
{
|
|
public enum CapturePositionMode
|
|
{
|
|
Static,
|
|
MirrorCamera
|
|
}
|
|
|
|
[SerializeField]
|
|
ProxyVolumeComponent m_ProxyVolumeReference;
|
|
[SerializeField]
|
|
InfluenceVolume m_InfluenceVolume;
|
|
[SerializeField]
|
|
Vector3 m_CaptureLocalPosition;
|
|
[SerializeField]
|
|
[Range(0, 1)]
|
|
float m_Dimmer = 1;
|
|
[SerializeField]
|
|
ReflectionProbeMode m_Mode = ReflectionProbeMode.Baked;
|
|
[SerializeField]
|
|
ReflectionProbeRefreshMode m_RefreshMode = ReflectionProbeRefreshMode.OnAwake;
|
|
[SerializeField]
|
|
Texture m_CustomTexture;
|
|
[SerializeField]
|
|
Texture m_BakedTexture;
|
|
[SerializeField]
|
|
RenderTexture m_RealtimeTexture;
|
|
[SerializeField]
|
|
FrameSettings m_FrameSettings;
|
|
[SerializeField]
|
|
float m_CaptureNearPlane = 1;
|
|
[SerializeField]
|
|
float m_CaptureFarPlane = 1000;
|
|
[SerializeField]
|
|
CapturePositionMode m_CapturePositionMode = CapturePositionMode.Static;
|
|
[SerializeField]
|
|
Vector3 m_CaptureMirrorPlaneLocalPosition;
|
|
[SerializeField]
|
|
Vector3 m_CaptureMirrorPlaneLocalNormal = Vector3.forward;
|
|
|
|
public ProxyVolumeComponent proxyVolumeReference { get { return m_ProxyVolumeReference; } }
|
|
public InfluenceVolume influenceVolume { get { return m_InfluenceVolume; } }
|
|
public BoundingSphere boundingSphere { get { return m_InfluenceVolume.GetBoundingSphereAt(transform); } }
|
|
|
|
public Texture texture
|
|
{
|
|
get
|
|
{
|
|
switch (m_Mode)
|
|
{
|
|
default:
|
|
case ReflectionProbeMode.Baked:
|
|
return bakedTexture;
|
|
case ReflectionProbeMode.Custom:
|
|
return customTexture;
|
|
case ReflectionProbeMode.Realtime:
|
|
return realtimeTexture;
|
|
}
|
|
}
|
|
}
|
|
public Bounds bounds { get { return m_InfluenceVolume.GetBoundsAt(transform); } }
|
|
public Vector3 captureLocalPosition { get { return m_CaptureLocalPosition; } set { m_CaptureLocalPosition = value; } }
|
|
public float dimmer { get { return m_Dimmer; } }
|
|
public ReflectionProbeMode mode { get { return m_Mode; } }
|
|
public Matrix4x4 influenceToWorld
|
|
{
|
|
get
|
|
{
|
|
var tr = transform;
|
|
var influencePosition = influenceVolume.GetWorldPosition(tr);
|
|
return Matrix4x4.TRS(
|
|
influencePosition,
|
|
tr.rotation,
|
|
Vector3.one
|
|
);
|
|
}
|
|
}
|
|
public Texture customTexture { get { return m_CustomTexture; } set { m_CustomTexture = value; } }
|
|
public Texture bakedTexture { get { return m_BakedTexture; } set { m_BakedTexture = value; }}
|
|
public RenderTexture realtimeTexture { get { return m_RealtimeTexture; } internal set { m_RealtimeTexture = value; } }
|
|
public ReflectionProbeRefreshMode refreshMode { get { return m_RefreshMode; } }
|
|
public FrameSettings frameSettings { get { return m_FrameSettings; } }
|
|
public float captureNearPlane { get { return m_CaptureNearPlane; } }
|
|
public float captureFarPlane { get { return m_CaptureFarPlane; } }
|
|
public CapturePositionMode capturePositionMode { get { return m_CapturePositionMode; } }
|
|
public Vector3 captureMirrorPlaneLocalPosition
|
|
{
|
|
get { return m_CaptureMirrorPlaneLocalPosition; }
|
|
set { m_CaptureMirrorPlaneLocalPosition = value; }
|
|
}
|
|
public Vector3 captureMirrorPlanePosition { get { return transform.TransformPoint(m_CaptureMirrorPlaneLocalPosition); } }
|
|
public Vector3 captureMirrorPlaneLocalNormal
|
|
{
|
|
get { return m_CaptureMirrorPlaneLocalNormal; }
|
|
set { m_CaptureMirrorPlaneLocalNormal = value; }
|
|
}
|
|
public Vector3 captureMirrorPlaneNormal { get { return transform.TransformDirection(m_CaptureMirrorPlaneLocalNormal); } }
|
|
|
|
#region Proxy Properties
|
|
public Matrix4x4 proxyToWorld
|
|
{
|
|
get
|
|
{
|
|
return m_ProxyVolumeReference != null
|
|
? m_ProxyVolumeReference.transform.localToWorldMatrix
|
|
: influenceToWorld;
|
|
}
|
|
}
|
|
public ShapeType proxyShape
|
|
{
|
|
get
|
|
{
|
|
return m_ProxyVolumeReference != null
|
|
? m_ProxyVolumeReference.proxyVolume.shapeType
|
|
: influenceVolume.shapeType;
|
|
}
|
|
}
|
|
public Vector3 proxyExtents
|
|
{
|
|
get
|
|
{
|
|
return m_ProxyVolumeReference != null
|
|
? m_ProxyVolumeReference.proxyVolume.boxSize
|
|
: influenceVolume.boxBaseSize;
|
|
}
|
|
}
|
|
public bool infiniteProjection { get { return m_ProxyVolumeReference != null && m_ProxyVolumeReference.proxyVolume.infiniteProjection; } }
|
|
#endregion
|
|
|
|
public void RequestRealtimeRender()
|
|
{
|
|
if (enabled)
|
|
ReflectionSystem.RequestRealtimeRender(this);
|
|
}
|
|
|
|
void OnEnable()
|
|
{
|
|
ReflectionSystem.RegisterProbe(this);
|
|
}
|
|
|
|
void OnDisable()
|
|
{
|
|
ReflectionSystem.UnregisterProbe(this);
|
|
}
|
|
|
|
void OnValidate()
|
|
{
|
|
if (enabled)
|
|
{
|
|
ReflectionSystem.UnregisterProbe(this);
|
|
ReflectionSystem.RegisterProbe(this);
|
|
}
|
|
}
|
|
}
|
|
}
|