您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

178 行
6.4 KiB

using UnityEngine.Rendering;
namespace UnityEngine.Experimental.Rendering.HDPipeline
{
[ExecuteInEditMode]
public class PlanarReflectionProbe : MonoBehaviour
{
public enum CapturePositionMode
{
Static,
MirrorCamera
}
[SerializeField]
ReflectionProxyVolumeComponent 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]
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;
[SerializeField]
bool m_OverrideFieldOfView = false;
[SerializeField]
[Range(0, 180)]
float m_FieldOfViewOverride = 90;
RenderTexture m_RealtimeTexture;
public bool overrideFieldOfView { get { return m_OverrideFieldOfView; } }
public float fieldOfViewOverride { get { return m_FieldOfViewOverride; } }
public ReflectionProxyVolumeComponent 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 * 0.5f
: influenceVolume.boxBaseSize;
}
}
public bool infiniteProjection { get { return m_ProxyVolumeReference != null && m_ProxyVolumeReference.proxyVolume.infiniteProjection; } }
public bool useMirrorPlane
{
get
{
return mode == ReflectionProbeMode.Realtime
&& refreshMode == ReflectionProbeRefreshMode.EveryFrame
&& capturePositionMode == CapturePositionMode.MirrorCamera;
}
}
#endregion
public void RequestRealtimeRender()
{
if (isActiveAndEnabled)
ReflectionSystem.RequestRealtimeRender(this);
}
void OnEnable()
{
ReflectionSystem.RegisterProbe(this);
}
void OnDisable()
{
ReflectionSystem.UnregisterProbe(this);
}
void OnValidate()
{
ReflectionSystem.UnregisterProbe(this);
if (isActiveAndEnabled)
ReflectionSystem.RegisterProbe(this);
}
}
}