浏览代码
Merge pull request #686 from Unity-Technologies/feature/ReflectionProbeEditor
Merge pull request #686 from Unity-Technologies/feature/ReflectionProbeEditor
Reflection Probe Editor/feature-ReflectionProbeFit
GitHub
7 年前
当前提交
05de367f
共有 25 个文件被更改,包括 1941 次插入 和 9 次删除
-
15ScriptableRenderPipeline/Core/Editor/PropertyFetcher.cs
-
42ScriptableRenderPipeline/HDRenderPipeline/Lighting/LightLoop/LightLoop.cs
-
2ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.hlsl
-
120ScriptableRenderPipeline/Core/Editor/CoreEditorDrawers.cs
-
11ScriptableRenderPipeline/Core/Editor/CoreEditorDrawers.cs.meta
-
72ScriptableRenderPipeline/HDRenderPipeline/Debug/ReflectionProbesPreview.shader
-
9ScriptableRenderPipeline/HDRenderPipeline/Debug/ReflectionProbesPreview.shader.meta
-
170ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDCubemapInspector.cs
-
13ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDCubemapInspector.cs.meta
-
177ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Data.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Data.cs.meta
-
377ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Drawers.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Drawers.cs.meta
-
321ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Handles.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Handles.cs.meta
-
63ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Preview.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.Preview.cs.meta
-
53ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.ProbeUtility.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.ProbeUtility.cs.meta
-
240ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.cs
-
13ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/HDReflectionProbeEditor.cs.meta
-
155ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/PreviewCubemapMaterial.mat
-
10ScriptableRenderPipeline/HDRenderPipeline/Editor/Lighting/PreviewCubemapMaterial.mat.meta
-
19ScriptableRenderPipeline/HDRenderPipeline/Lighting/HDAdditionalReflectionData.cs
-
13ScriptableRenderPipeline/HDRenderPipeline/Lighting/HDAdditionalReflectionData.cs.meta
|
|||
using System.Collections.Generic; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering |
|||
{ |
|||
public static class CoreEditorDrawer<TUIState, TData> |
|||
{ |
|||
public interface IDrawer |
|||
{ |
|||
void Draw(TUIState s, TData p, Editor owner); |
|||
} |
|||
|
|||
public delegate void ActionDrawer(TUIState s, TData p, Editor owner); |
|||
public delegate float FloatGetter(TUIState s, TData p, Editor owner, int i); |
|||
public delegate SerializedProperty SerializedPropertyGetter(TUIState s, TData p, Editor o); |
|||
|
|||
public static readonly IDrawer space = Action((state, data, owner) => EditorGUILayout.Space()); |
|||
public static readonly IDrawer noop = Action((state, data, owner) => { }); |
|||
|
|||
public static IDrawer Action(params ActionDrawer[] drawers) |
|||
{ |
|||
return new ActionDrawerInternal(drawers); |
|||
} |
|||
|
|||
public static IDrawer FadeGroup(FloatGetter fadeGetter, bool indent, params IDrawer[] groupDrawers) |
|||
{ |
|||
return new FadeGroupsDrawerInternal(fadeGetter, indent, groupDrawers); |
|||
} |
|||
|
|||
public static IDrawer FoldoutGroup(string title, SerializedPropertyGetter root, bool indent, params IDrawer[] bodies) |
|||
{ |
|||
return new FoldoutDrawerInternal(title, root, indent, bodies); |
|||
} |
|||
|
|||
class ActionDrawerInternal : IDrawer |
|||
{ |
|||
ActionDrawer[] actionDrawers { get; set; } |
|||
public ActionDrawerInternal(params ActionDrawer[] actionDrawers) |
|||
{ |
|||
this.actionDrawers = actionDrawers; |
|||
} |
|||
|
|||
void IDrawer.Draw(TUIState s, TData p, Editor owner) |
|||
{ |
|||
for (var i = 0; i < actionDrawers.Length; i++) |
|||
actionDrawers[i](s, p, owner); |
|||
} |
|||
} |
|||
|
|||
class FadeGroupsDrawerInternal : IDrawer |
|||
{ |
|||
IDrawer[] groupDrawers; |
|||
FloatGetter getter; |
|||
bool indent; |
|||
|
|||
public FadeGroupsDrawerInternal(FloatGetter getter, bool indent, params IDrawer[] groupDrawers) |
|||
{ |
|||
this.groupDrawers = groupDrawers; |
|||
this.getter = getter; |
|||
this.indent = indent; |
|||
} |
|||
|
|||
void IDrawer.Draw(TUIState s, TData p, Editor owner) |
|||
{ |
|||
for (var i = 0; i < groupDrawers.Length; ++i) |
|||
{ |
|||
if (EditorGUILayout.BeginFadeGroup(getter(s, p, owner, i))) |
|||
{ |
|||
if (indent) |
|||
++EditorGUI.indentLevel; |
|||
groupDrawers[i].Draw(s, p, owner); |
|||
if (indent) |
|||
--EditorGUI.indentLevel; |
|||
} |
|||
EditorGUILayout.EndFadeGroup(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
class FoldoutDrawerInternal : IDrawer |
|||
{ |
|||
IDrawer[] bodies; |
|||
SerializedPropertyGetter root; |
|||
string title; |
|||
bool indent; |
|||
|
|||
public FoldoutDrawerInternal(string title, SerializedPropertyGetter root, bool indent, params IDrawer[] bodies) |
|||
{ |
|||
this.title = title; |
|||
this.root = root; |
|||
this.bodies = bodies; |
|||
this.indent = indent; |
|||
} |
|||
|
|||
public void Draw(TUIState s, TData p, Editor owner) |
|||
{ |
|||
var r = root(s, p, owner); |
|||
CoreEditorUtils.DrawSplitter(); |
|||
r.isExpanded = CoreEditorUtils.DrawHeaderFoldout(title, r.isExpanded); |
|||
if (r.isExpanded) |
|||
{ |
|||
if (indent) |
|||
++EditorGUI.indentLevel; |
|||
for (var i = 0; i < bodies.Length; i++) |
|||
bodies[i].Draw(s, p, owner); |
|||
if (indent) |
|||
--EditorGUI.indentLevel; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
public static class CoreEditorDrawersExtensions |
|||
{ |
|||
public static void Draw<TUIState, TData>(this IEnumerable<CoreEditorDrawer<TUIState, TData>.IDrawer> drawers, TUIState s, TData p, Editor o) |
|||
{ |
|||
foreach (var drawer in drawers) |
|||
drawer.Draw(s, p, o); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7e9fe0ff34cd022408422f6b92ad7df6 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' |
|||
|
|||
Shader "Debug/ReflectionProbePreview" |
|||
{ |
|||
Properties |
|||
{ |
|||
_Cubemap("_Cubemap", Cube) = "white" {} |
|||
_CameraWorldPosition("_CameraWorldPosition", Vector) = (1,1,1,1) |
|||
_MipLevel("_MipLevel", Range(0.0,7.0)) = 0.0 |
|||
_Exposure("_Exposure", Range(-10.0,10.0)) = 0.0 |
|||
|
|||
} |
|||
SubShader |
|||
{ |
|||
Tags{ "RenderType" = "Opaque" "Queue" = "Transparent" } |
|||
LOD 100 |
|||
ZWrite On |
|||
Cull Back |
|||
LOD 100 |
|||
|
|||
Pass |
|||
{ |
|||
Name "ForwardUnlit" |
|||
Tags{ "LightMode" = "Forward" } |
|||
|
|||
CGPROGRAM |
|||
#pragma vertex vert |
|||
#pragma fragment frag |
|||
|
|||
#include "UnityCG.cginc" |
|||
|
|||
|
|||
struct appdata |
|||
{ |
|||
float4 vertex : POSITION; |
|||
float3 normal : NORMAL; |
|||
}; |
|||
|
|||
struct v2f |
|||
{ |
|||
float4 vertex : SV_POSITION; |
|||
float3 normal : NORMAL; |
|||
float3 worldpos : TEXCOORD0; |
|||
}; |
|||
|
|||
samplerCUBE _Cubemap; |
|||
float3 _CameraWorldPosition; |
|||
float _MipLevel; |
|||
float _Exposure; |
|||
|
|||
v2f vert(appdata v) |
|||
{ |
|||
v2f o; |
|||
o.vertex = UnityObjectToClipPos(v.vertex); |
|||
o.worldpos = mul(unity_ObjectToWorld, v.vertex); |
|||
o.normal = mul(unity_ObjectToWorld, float4(v.normal, 0)).xyz; |
|||
return o; |
|||
} |
|||
|
|||
float4 frag(v2f i) : SV_Target |
|||
{ |
|||
//float3 view = normalize(i.worldpos - _CameraWorldPosition); |
|||
float3 view = normalize(i.worldpos - _WorldSpaceCameraPos); |
|||
float3 reflected = reflect(view, i.normal); |
|||
float4 col = texCUBElod(_Cubemap,float4(reflected,_MipLevel)); |
|||
col = col*exp2(_Exposure); |
|||
return col; |
|||
} |
|||
ENDCG |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 73be0053604e1d54388db4f32739a92f |
|||
ShaderImporter: |
|||
externalObjects: {} |
|||
defaultTextures: [] |
|||
nonModifiableTextures: [] |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
|
|||
[CustomEditorForRenderPipeline(typeof(Cubemap), typeof(HDRenderPipelineAsset))] |
|||
class HDCubemapInspector : Editor |
|||
{ |
|||
private enum NavMode |
|||
{ |
|||
None = 0, |
|||
Zooming = 1, |
|||
Rotating = 2 |
|||
} |
|||
|
|||
static GUIContent s_MipMapLow, s_MipMapHigh, s_ExposureHigh, s_ExposureLow, s_RGBMIcon; |
|||
static GUIStyle s_PreButton, s_PreSlider, s_PreSliderThumb, s_PreLabel; |
|||
static Mesh s_SphereMesh; |
|||
|
|||
static Mesh sphereMesh |
|||
{ |
|||
get { return s_SphereMesh ?? (s_SphereMesh = Resources.GetBuiltinResource(typeof(Mesh), "New-Sphere.fbx") as Mesh); } |
|||
} |
|||
|
|||
Material m_ReflectiveMaterial; |
|||
PreviewRenderUtility m_PreviewUtility; |
|||
float m_CameraPhi = 0.75f; |
|||
float m_CameraTheta = 0.5f; |
|||
float m_CameraDistance = 2.0f; |
|||
NavMode m_NavMode = NavMode.None; |
|||
Vector2 m_PreviousMousePosition = Vector2.zero; |
|||
|
|||
public float previewExposure = 0f; |
|||
public float mipLevelPreview = 0f; |
|||
|
|||
void Awake() |
|||
{ |
|||
m_ReflectiveMaterial = new Material(Shader.Find("Debug/ReflectionProbePreview")) |
|||
{ |
|||
hideFlags = HideFlags.HideAndDontSave |
|||
}; |
|||
InitIcons(); |
|||
} |
|||
|
|||
void OnEnable() |
|||
{ |
|||
if (m_PreviewUtility == null) |
|||
InitPreview(); |
|||
|
|||
m_ReflectiveMaterial.SetTexture("_Cubemap", target as Texture); |
|||
} |
|||
|
|||
void OnDisable() |
|||
{ |
|||
if (m_PreviewUtility != null) |
|||
m_PreviewUtility.Cleanup(); |
|||
} |
|||
|
|||
public override bool HasPreviewGUI() |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
public override void OnPreviewGUI(Rect r, GUIStyle background) |
|||
{ |
|||
if(m_ReflectiveMaterial != null) |
|||
{ |
|||
m_ReflectiveMaterial.SetFloat("_Exposure", previewExposure); |
|||
m_ReflectiveMaterial.SetFloat("_MipLevel", mipLevelPreview); |
|||
} |
|||
|
|||
if(m_PreviewUtility == null) |
|||
InitPreview(); |
|||
|
|||
UpdateCamera(); |
|||
|
|||
m_PreviewUtility.BeginPreview(r, GUIStyle.none); |
|||
m_PreviewUtility.DrawMesh(sphereMesh, Matrix4x4.identity, m_ReflectiveMaterial, 0); |
|||
m_PreviewUtility.camera.Render(); |
|||
m_PreviewUtility.EndAndDrawPreview(r); |
|||
|
|||
if (Event.current.type != EventType.Repaint) |
|||
{ |
|||
if (HandleMouse(r)) |
|||
Repaint(); |
|||
} |
|||
} |
|||
|
|||
public override void OnPreviewSettings() |
|||
{ |
|||
GUI.enabled = true; |
|||
|
|||
GUILayout.Box(s_ExposureLow, s_PreLabel, GUILayout.MaxWidth(20)); |
|||
GUI.changed = false; |
|||
previewExposure = GUILayout.HorizontalSlider(previewExposure, -10f, 10f, GUILayout.MaxWidth(80)); |
|||
GUILayout.Space(5); |
|||
GUILayout.Box(s_MipMapHigh, s_PreLabel, GUILayout.MaxWidth(20)); |
|||
GUI.changed = false; |
|||
mipLevelPreview = GUILayout.HorizontalSlider(mipLevelPreview, 0, ((Cubemap)target).mipmapCount, GUILayout.MaxWidth(80)); |
|||
GUILayout.Box(s_MipMapLow, s_PreLabel, GUILayout.MaxWidth(20)); |
|||
} |
|||
|
|||
void InitPreview() |
|||
{ |
|||
m_PreviewUtility = new PreviewRenderUtility(false, true); |
|||
m_PreviewUtility.cameraFieldOfView = 50.0f; |
|||
m_PreviewUtility.camera.nearClipPlane = 0.01f; |
|||
m_PreviewUtility.camera.farClipPlane = 20.0f; |
|||
m_PreviewUtility.camera.transform.position = new Vector3(0, 0, 2); |
|||
m_PreviewUtility.camera.transform.LookAt(Vector3.zero); |
|||
//m_PreviewUtility.camera.clearFlags = CameraClearFlags.Skybox;
|
|||
} |
|||
|
|||
bool HandleMouse(Rect Viewport) |
|||
{ |
|||
var result = false; |
|||
|
|||
if (Event.current.type == EventType.MouseDown) |
|||
{ |
|||
if (Event.current.button == 0) |
|||
m_NavMode = NavMode.Rotating; |
|||
else if (Event.current.button == 1) |
|||
m_NavMode = NavMode.Zooming; |
|||
|
|||
m_PreviousMousePosition = Event.current.mousePosition; |
|||
result = true; |
|||
} |
|||
|
|||
if (Event.current.type == EventType.MouseUp || Event.current.rawType == EventType.MouseUp) |
|||
m_NavMode = NavMode.None; |
|||
|
|||
if (m_NavMode != NavMode.None) |
|||
{ |
|||
var mouseDelta = Event.current.mousePosition - m_PreviousMousePosition; |
|||
switch (m_NavMode) |
|||
{ |
|||
case NavMode.Rotating: |
|||
m_CameraTheta = (m_CameraTheta - mouseDelta.x * 0.003f) % (Mathf.PI * 2); |
|||
m_CameraPhi = Mathf.Clamp(m_CameraPhi - mouseDelta.y * 0.003f, 0.2f, Mathf.PI - 0.2f); |
|||
break; |
|||
case NavMode.Zooming: |
|||
m_CameraDistance = Mathf.Clamp(mouseDelta.y * 0.01f + m_CameraDistance, 1, 10); |
|||
break; |
|||
} |
|||
result = true; |
|||
} |
|||
|
|||
m_PreviousMousePosition = Event.current.mousePosition; |
|||
return result; |
|||
} |
|||
|
|||
void UpdateCamera() |
|||
{ |
|||
var pos = new Vector3(Mathf.Sin(m_CameraPhi) * Mathf.Cos(m_CameraTheta), Mathf.Cos(m_CameraPhi), Mathf.Sin(m_CameraPhi) * Mathf.Sin(m_CameraTheta)) * m_CameraDistance; |
|||
m_PreviewUtility.camera.transform.position = pos; |
|||
m_PreviewUtility.camera.transform.LookAt(Vector3.zero); |
|||
} |
|||
|
|||
static void InitIcons() |
|||
{ |
|||
s_MipMapLow = EditorGUIUtility.IconContent("PreTextureMipMapLow"); |
|||
s_MipMapHigh = EditorGUIUtility.IconContent("PreTextureMipMapHigh"); |
|||
s_ExposureHigh = EditorGUIUtility.IconContent("SceneViewLighting"); |
|||
s_ExposureLow = EditorGUIUtility.IconContent("SceneViewLighting"); |
|||
s_RGBMIcon = EditorGUIUtility.IconContent("PreMatLight1"); // TODO: proper icon for RGBM preview mode
|
|||
s_PreButton = "preButton"; |
|||
s_PreSlider = "preSlider"; |
|||
s_PreSliderThumb = "preSliderThumb"; |
|||
s_PreLabel = "preLabel"; |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: cdea3bc9038283a42ae5ca2c1956484d |
|||
timeCreated: 1507739065 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEditor.AnimatedValues; |
|||
using UnityEditor.IMGUI.Controls; |
|||
using UnityEditorInternal; |
|||
using UnityEngine; |
|||
using UnityEngine.Events; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering |
|||
{ |
|||
partial class HDReflectionProbeEditor |
|||
{ |
|||
internal class SerializedReflectionProbe |
|||
{ |
|||
internal SerializedObject so; |
|||
|
|||
internal SerializedProperty mode; |
|||
internal SerializedProperty renderDynamicObjects; |
|||
internal SerializedProperty customBakedTexture; |
|||
internal SerializedProperty refreshMode; |
|||
internal SerializedProperty timeSlicingMode; |
|||
internal SerializedProperty intensityMultiplier; |
|||
internal SerializedProperty blendDistance; |
|||
internal SerializedProperty boxSize; |
|||
internal SerializedProperty boxOffset; |
|||
internal SerializedProperty resolution; |
|||
internal SerializedProperty shadowDistance; |
|||
internal SerializedProperty cullingMask; |
|||
internal SerializedProperty useOcclusionCulling; |
|||
internal SerializedProperty nearClip; |
|||
internal SerializedProperty farClip; |
|||
internal SerializedProperty boxProjection; |
|||
|
|||
internal SerializedProperty influenceShape; |
|||
internal SerializedProperty influenceSphereRadius; |
|||
internal SerializedProperty useSeparateProjectionVolume; |
|||
internal SerializedProperty boxReprojectionVolumeSize; |
|||
internal SerializedProperty boxReprojectionVolumeCenter; |
|||
internal SerializedProperty sphereReprojectionVolumeRadius; |
|||
internal SerializedProperty dimmer; |
|||
|
|||
public SerializedReflectionProbe(SerializedObject so, SerializedObject addso) |
|||
{ |
|||
this.so = so; |
|||
|
|||
mode = so.FindProperty("m_Mode"); |
|||
customBakedTexture = so.FindProperty("m_CustomBakedTexture"); |
|||
renderDynamicObjects = so.FindProperty("m_RenderDynamicObjects"); |
|||
refreshMode = so.FindProperty("m_RefreshMode"); |
|||
timeSlicingMode = so.FindProperty("m_TimeSlicingMode"); |
|||
intensityMultiplier = so.FindProperty("m_IntensityMultiplier"); |
|||
blendDistance = so.FindProperty("m_BlendDistance"); |
|||
boxSize = so.FindProperty("m_BoxSize"); |
|||
boxOffset = so.FindProperty("m_BoxOffset"); |
|||
resolution = so.FindProperty("m_Resolution"); |
|||
shadowDistance = so.FindProperty("m_ShadowDistance"); |
|||
cullingMask = so.FindProperty("m_CullingMask"); |
|||
useOcclusionCulling = so.FindProperty("m_UseOcclusionCulling"); |
|||
nearClip = so.FindProperty("m_NearClip"); |
|||
farClip = so.FindProperty("m_FarClip"); |
|||
boxProjection = so.FindProperty("m_BoxProjection"); |
|||
|
|||
influenceShape = addso.Find((HDAdditionalReflectionData d) => d.influenceShape); |
|||
influenceSphereRadius = addso.Find((HDAdditionalReflectionData d) => d.influenceSphereRadius); |
|||
useSeparateProjectionVolume = addso.Find((HDAdditionalReflectionData d) => d.useSeparateProjectionVolume); |
|||
boxReprojectionVolumeSize = addso.Find((HDAdditionalReflectionData d) => d.boxReprojectionVolumeSize); |
|||
boxReprojectionVolumeCenter = addso.Find((HDAdditionalReflectionData d) => d.boxReprojectionVolumeCenter); |
|||
sphereReprojectionVolumeRadius = addso.Find((HDAdditionalReflectionData d) => d.sphereReprojectionVolumeRadius); |
|||
dimmer = addso.Find((HDAdditionalReflectionData d) => d.dimmer); |
|||
} |
|||
} |
|||
|
|||
[Flags] |
|||
internal enum Operation |
|||
{ |
|||
None = 0, |
|||
FitVolumeToSurroundings = 1 << 0 |
|||
} |
|||
|
|||
internal class UIState |
|||
{ |
|||
AnimBool[] m_ModeSettingsDisplays = new AnimBool[Enum.GetValues(typeof(ReflectionProbeMode)).Length]; |
|||
AnimBool[] m_InfluenceShapeDisplays = new AnimBool[Enum.GetValues(typeof(ReflectionInfluenceShape)).Length]; |
|||
|
|||
Editor owner { get; set; } |
|||
Operation operations { get; set; } |
|||
public AnimBool useSeparateProjectionVolumeDisplay { get; private set; } |
|||
public bool HasOperation(Operation op) { return (operations & op) == op; } |
|||
public void ClearOperation(Operation op) { operations &= ~op; } |
|||
public void AddOperation(Operation op) { operations |= op; } |
|||
|
|||
public BoxBoundsHandle boxInfluenceBoundsHandle = new BoxBoundsHandle(); |
|||
public BoxBoundsHandle boxProjectionBoundsHandle = new BoxBoundsHandle(); |
|||
public BoxBoundsHandle boxBlendHandle = new BoxBoundsHandle(); |
|||
public SphereBoundsHandle influenceSphereHandle = new SphereBoundsHandle(); |
|||
public SphereBoundsHandle projectionSphereHandle = new SphereBoundsHandle(); |
|||
public SphereBoundsHandle sphereBlendHandle = new SphereBoundsHandle(); |
|||
public Matrix4x4 oldLocalSpace = Matrix4x4.identity; |
|||
|
|||
public bool HasAndClearOperation(Operation op) |
|||
{ |
|||
var has = HasOperation(op); |
|||
ClearOperation(op); |
|||
return has; |
|||
} |
|||
|
|||
public bool sceneViewEditing |
|||
{ |
|||
get { return IsReflectionProbeEditMode(EditMode.editMode) && EditMode.IsOwner(owner); } |
|||
} |
|||
|
|||
internal UIState() |
|||
{ |
|||
for (var i = 0; i < m_ModeSettingsDisplays.Length; i++) |
|||
m_ModeSettingsDisplays[i] = new AnimBool(); |
|||
for (var i = 0; i < m_InfluenceShapeDisplays.Length; i++) |
|||
m_InfluenceShapeDisplays[i] = new AnimBool(); |
|||
useSeparateProjectionVolumeDisplay = new AnimBool(); |
|||
} |
|||
|
|||
internal void Reset( |
|||
Editor owner, |
|||
UnityAction repaint, |
|||
SerializedReflectionProbe p) |
|||
{ |
|||
this.owner = owner; |
|||
operations = 0; |
|||
|
|||
for (var i = 0; i < m_ModeSettingsDisplays.Length; i++) |
|||
{ |
|||
m_ModeSettingsDisplays[i].valueChanged.RemoveAllListeners(); |
|||
m_ModeSettingsDisplays[i].valueChanged.AddListener(repaint); |
|||
m_ModeSettingsDisplays[i].value = p.mode.intValue == i; |
|||
} |
|||
|
|||
for (var i = 0; i < m_InfluenceShapeDisplays.Length; i++) |
|||
{ |
|||
m_InfluenceShapeDisplays[i].valueChanged.RemoveAllListeners(); |
|||
m_InfluenceShapeDisplays[i].valueChanged.AddListener(repaint); |
|||
m_InfluenceShapeDisplays[i].value = p.influenceShape.intValue == i; |
|||
} |
|||
|
|||
useSeparateProjectionVolumeDisplay.valueChanged.RemoveAllListeners(); |
|||
useSeparateProjectionVolumeDisplay.valueChanged.AddListener(repaint); |
|||
useSeparateProjectionVolumeDisplay.value = p.useSeparateProjectionVolume.boolValue; |
|||
} |
|||
|
|||
public float GetModeFaded(ReflectionProbeMode mode) |
|||
{ |
|||
return m_ModeSettingsDisplays[(int)mode].faded; |
|||
} |
|||
|
|||
public void SetModeTarget(int value) |
|||
{ |
|||
for (var i = 0; i < m_ModeSettingsDisplays.Length; i++) |
|||
m_ModeSettingsDisplays[i].target = i == value; |
|||
} |
|||
|
|||
public float GetShapeFaded(ReflectionInfluenceShape value) |
|||
{ |
|||
return m_InfluenceShapeDisplays[(int)value].faded; |
|||
} |
|||
|
|||
public void SetShapeTarget(int value) |
|||
{ |
|||
for (var i = 0; i < m_InfluenceShapeDisplays.Length; i++) |
|||
m_InfluenceShapeDisplays[i].target = i == value; |
|||
} |
|||
|
|||
internal void UpdateOldLocalSpace(ReflectionProbe target) |
|||
{ |
|||
oldLocalSpace = GetLocalSpace(target); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4e4bdea98ec8e664b95e5c89aa680636 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Reflection; |
|||
using UnityEditorInternal; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering |
|||
{ |
|||
using CED = CoreEditorDrawer<HDReflectionProbeEditor.UIState, HDReflectionProbeEditor.SerializedReflectionProbe>; |
|||
|
|||
partial class HDReflectionProbeEditor |
|||
{ |
|||
#region Sections
|
|||
static readonly CED.IDrawer[] k_PrimarySection = |
|||
{ |
|||
CED.Action(Drawer_ReflectionProbeMode), |
|||
CED.FadeGroup((s, p, o, i) => s.GetModeFaded((ReflectionProbeMode)i), |
|||
true, |
|||
CED.noop, // Baked
|
|||
CED.Action(Drawer_ModeSettingsRealtime), // Realtime
|
|||
CED.Action(Drawer_ModeSettingsCustom) // Custom
|
|||
), |
|||
CED.space, |
|||
CED.Action(Drawer_InfluenceShape), |
|||
//CED.Action(Drawer_IntensityMultiplier),
|
|||
CED.space, |
|||
CED.Action(Drawer_Toolbar), |
|||
CED.space |
|||
}; |
|||
|
|||
static readonly CED.IDrawer k_InfluenceVolumeSection = CED.FoldoutGroup( |
|||
"Influence volume settings", |
|||
(s, p, o) => p.blendDistance, |
|||
true, |
|||
CED.Action(Drawer_DistanceBlend), |
|||
CED.FadeGroup( |
|||
(s, p, o, i) => s.GetShapeFaded((ReflectionInfluenceShape)i), |
|||
false, |
|||
CED.Action(Drawer_InfluenceBoxSettings), // Box
|
|||
CED.Action(Drawer_InfluenceSphereSettings) // Sphere
|
|||
)/*, |
|||
CED.Action(Drawer_UseSeparateProjectionVolume)*/ |
|||
); |
|||
|
|||
static readonly CED.IDrawer k_SeparateProjectionVolumeSection = CED.FadeGroup( |
|||
(s, p, o, i) => s.useSeparateProjectionVolumeDisplay.faded, |
|||
false, |
|||
CED.FoldoutGroup( |
|||
"Reprojection volume settings", |
|||
(s, p, o) => p.useSeparateProjectionVolume, |
|||
true, |
|||
CED.FadeGroup( |
|||
(s, p, o, i) => s.GetShapeFaded((ReflectionInfluenceShape)i), |
|||
false, |
|||
CED.Action(Drawer_ProjectionBoxSettings), // Box
|
|||
CED.Action(Drawer_ProjectionSphereSettings) // Sphere
|
|||
) |
|||
) |
|||
); |
|||
|
|||
static readonly CED.IDrawer k_CaptureSection = CED.FoldoutGroup( |
|||
"Capture settings", |
|||
(s, p, o) => p.shadowDistance, |
|||
true, |
|||
CED.Action(Drawer_CaptureSettings) |
|||
); |
|||
|
|||
static readonly CED.IDrawer k_AdditionalSection = CED.FoldoutGroup( |
|||
"Additional settings", |
|||
(s, p, o) => p.dimmer, |
|||
true, |
|||
CED.Action(Drawer_AdditionalSettings) |
|||
); |
|||
|
|||
static readonly CED.IDrawer k_BakingActions = CED.Action(Drawer_BakeActions); |
|||
#endregion
|
|||
|
|||
static void Drawer_CaptureSettings(UIState s, SerializedReflectionProbe p, Editor owner) |
|||
{ |
|||
var renderPipelineAsset = (HDRenderPipelineAsset)GraphicsSettings.renderPipelineAsset; |
|||
p.resolution.intValue = renderPipelineAsset.GetGlobalFrameSettings().lightLoopSettings.reflectionCubemapSize; |
|||
EditorGUILayout.LabelField(CoreEditorUtils.GetContent("Resolution"), CoreEditorUtils.GetContent(p.resolution.intValue.ToString())); |
|||
|
|||
EditorGUILayout.PropertyField(p.shadowDistance); |
|||
EditorGUILayout.PropertyField(p.cullingMask); |
|||
EditorGUILayout.PropertyField(p.useOcclusionCulling); |
|||
EditorGUILayout.PropertyField(p.nearClip); |
|||
EditorGUILayout.PropertyField(p.farClip); |
|||
} |
|||
|
|||
static void Drawer_AdditionalSettings(UIState s, SerializedReflectionProbe p, Editor owner) |
|||
{ |
|||
EditorGUILayout.PropertyField(p.dimmer); |
|||
|
|||
if (p.so.targetObjects.Length == 1) |
|||
{ |
|||
var probe = (ReflectionProbe)p.so.targetObject; |
|||
if (probe.mode == ReflectionProbeMode.Custom && probe.customBakedTexture != null) |
|||
{ |
|||
var cubemap = probe.customBakedTexture as Cubemap; |
|||
if (cubemap && cubemap.mipmapCount == 1) |
|||
EditorGUILayout.HelpBox("No mipmaps in the cubemap, Smoothness value in Standard shader will be ignored.", MessageType.Warning); |
|||
} |
|||
} |
|||
} |
|||
|
|||
static readonly string[] k_BakeCustomOptionText = { "Bake as new Cubemap..." }; |
|||
static readonly string[] k_BakeButtonsText = { "Bake All Reflection Probes" }; |
|||
static void Drawer_BakeActions(UIState s, SerializedReflectionProbe p, Editor owner) |
|||
{ |
|||
if (p.mode.intValue == (int)ReflectionProbeMode.Realtime) |
|||
{ |
|||
EditorGUILayout.HelpBox("Baking of this reflection probe should be initiated from the scripting API because the type is 'Realtime'", MessageType.Info); |
|||
|
|||
if (!QualitySettings.realtimeReflectionProbes) |
|||
EditorGUILayout.HelpBox("Realtime reflection probes are disabled in Quality Settings", MessageType.Warning); |
|||
return; |
|||
} |
|||
|
|||
if (p.mode.intValue == (int)ReflectionProbeMode.Baked && UnityEditor.Lightmapping.giWorkflowMode != UnityEditor.Lightmapping.GIWorkflowMode.OnDemand) |
|||
{ |
|||
EditorGUILayout.HelpBox("Baking of this reflection probe is automatic because this probe's type is 'Baked' and the Lighting window is using 'Auto Baking'. The cubemap created is stored in the GI cache.", MessageType.Info); |
|||
return; |
|||
} |
|||
|
|||
EditorGUILayout.BeginHorizontal(); |
|||
GUILayout.FlexibleSpace(); |
|||
switch ((ReflectionProbeMode)p.mode.intValue) |
|||
{ |
|||
case ReflectionProbeMode.Custom: |
|||
{ |
|||
if (ButtonWithDropdownList( |
|||
CoreEditorUtils.GetContent("Bake|Bakes Reflection Probe's cubemap, overwriting the existing cubemap texture asset (if any)."), k_BakeCustomOptionText, |
|||
data => |
|||
{ |
|||
var mode = (int)data; |
|||
|
|||
var probe = p.so.targetObject as ReflectionProbe; |
|||
if (mode == 0) |
|||
{ |
|||
BakeCustomReflectionProbe(probe, false, true); |
|||
ResetProbeSceneTextureInMaterial(probe); |
|||
} |
|||
}, |
|||
GUILayout.ExpandWidth(true))) |
|||
{ |
|||
var probe = (ReflectionProbe)p.so.targetObject; |
|||
BakeCustomReflectionProbe(probe, true, true); |
|||
ResetProbeSceneTextureInMaterial(probe); |
|||
GUIUtility.ExitGUI(); |
|||
} |
|||
break; |
|||
} |
|||
|
|||
case ReflectionProbeMode.Baked: |
|||
{ |
|||
GUI.enabled = ((ReflectionProbe)p.so.targetObject).enabled; |
|||
|
|||
// Bake button in non-continous mode
|
|||
if (ButtonWithDropdownList( |
|||
CoreEditorUtils.GetContent("Bake"), |
|||
k_BakeButtonsText, |
|||
data => |
|||
{ |
|||
var mode = (int)data; |
|||
if (mode == 0) |
|||
BakeAllReflectionProbesSnapshots(); |
|||
}, |
|||
GUILayout.ExpandWidth(true))) |
|||
{ |
|||
var probe = (ReflectionProbe)p.so.targetObject; |
|||
BakeReflectionProbeSnapshot(probe); |
|||
ResetProbeSceneTextureInMaterial(probe); |
|||
GUIUtility.ExitGUI(); |
|||
} |
|||
|
|||
GUI.enabled = true; |
|||
break; |
|||
} |
|||
|
|||
case ReflectionProbeMode.Realtime: |
|||
// Not showing bake button in realtime
|
|||
break; |
|||
} |
|||
GUILayout.FlexibleSpace(); |
|||
EditorGUILayout.EndHorizontal(); |
|||
} |
|||
|
|||
#region Influence Volume
|
|||
static void Drawer_DistanceBlend(UIState s, SerializedReflectionProbe p, Editor owner) |
|||
{ |
|||
EditorGUILayout.Slider(p.blendDistance, 0, CalculateMaxBlendDistance(s, p, owner), CoreEditorUtils.GetContent("Blend Distance|Area around the probe where it is blended with other probes. Only used in deferred probes.")); |
|||
EditorGUI.BeginChangeCheck(); |
|||
} |
|||
|
|||
static void Drawer_InfluenceBoxSettings(UIState s, SerializedReflectionProbe p, Editor owner) |
|||
{ |
|||
EditorGUI.BeginChangeCheck(); |
|||
EditorGUILayout.PropertyField(p.boxSize, CoreEditorUtils.GetContent("Box Size|The size of the box in which the reflections will be applied to objects. The value is not affected by the Transform of the Game Object.")); |
|||
EditorGUILayout.PropertyField(p.boxOffset, CoreEditorUtils.GetContent("Box Offset|The center of the box in which the reflections will be applied to objects. The value is relative to the position of the Game Object.")); |
|||
EditorGUILayout.PropertyField(p.boxProjection, CoreEditorUtils.GetContent("Box Projection|Box projection causes reflections to appear to change based on the object's position within the probe's box, while still using a single probe as the source of the reflection. This works well for reflections on objects that are moving through enclosed spaces such as corridors and rooms. Setting box projection to False and the cubemap reflection will be treated as coming from infinitely far away. Note that this feature can be globally disabled from Graphics Settings -> Tier Settings")); |
|||
|
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
var center = p.boxOffset.vector3Value; |
|||
var size = p.boxSize.vector3Value; |
|||
if (ValidateAABB((ReflectionProbe)p.so.targetObject, ref center, ref size)) |
|||
{ |
|||
p.boxOffset.vector3Value = center; |
|||
p.boxSize.vector3Value = size; |
|||
} |
|||
} |
|||
} |
|||
|
|||
static void Drawer_InfluenceSphereSettings(UIState s, SerializedReflectionProbe p, Editor owner) |
|||
{ |
|||
EditorGUILayout.PropertyField(p.influenceSphereRadius, CoreEditorUtils.GetContent("Radius")); |
|||
EditorGUILayout.PropertyField(p.boxProjection, CoreEditorUtils.GetContent("Sphere Projection|Sphere projection causes reflections to appear to change based on the object's position within the probe's sphere, while still using a single probe as the source of the reflection. This works well for reflections on objects that are moving through enclosed spaces such as corridors and rooms. Setting sphere projection to False and the cubemap reflection will be treated as coming from infinitely far away. Note that this feature can be globally disabled from Graphics Settings -> Tier Settings")); |
|||
} |
|||
#endregion
|
|||
|
|||
#region Projection Volume
|
|||
static void Drawer_UseSeparateProjectionVolume(UIState s, SerializedReflectionProbe p, Editor owner) |
|||
{ |
|||
EditorGUILayout.PropertyField(p.useSeparateProjectionVolume); |
|||
s.useSeparateProjectionVolumeDisplay.target = p.useSeparateProjectionVolume.boolValue; |
|||
} |
|||
|
|||
static void Drawer_ProjectionBoxSettings(UIState s, SerializedReflectionProbe p, Editor owner) |
|||
{ |
|||
EditorGUILayout.PropertyField(p.boxReprojectionVolumeSize); |
|||
EditorGUILayout.PropertyField(p.boxReprojectionVolumeCenter); |
|||
} |
|||
|
|||
static void Drawer_ProjectionSphereSettings(UIState s, SerializedReflectionProbe p, Editor owner) |
|||
{ |
|||
EditorGUILayout.PropertyField(p.sphereReprojectionVolumeRadius); |
|||
} |
|||
#endregion
|
|||
|
|||
#region Field Drawers
|
|||
static readonly GUIContent[] k_Content_ReflectionProbeMode = { new GUIContent("Baked"), new GUIContent("Custom"), new GUIContent("Realtime") }; |
|||
static readonly int[] k_Content_ReflectionProbeModeValues = { (int)ReflectionProbeMode.Baked, (int)ReflectionProbeMode.Custom, (int)ReflectionProbeMode.Realtime }; |
|||
static void Drawer_ReflectionProbeMode(UIState s, SerializedReflectionProbe p, Editor owner) |
|||
{ |
|||
EditorGUI.BeginChangeCheck(); |
|||
EditorGUI.showMixedValue = p.mode.hasMultipleDifferentValues; |
|||
EditorGUILayout.IntPopup(p.mode, k_Content_ReflectionProbeMode, k_Content_ReflectionProbeModeValues, CoreEditorUtils.GetContent("Type|'Baked Cubemap' uses the 'Auto Baking' mode from the Lighting window. If it is enabled then baking is automatic otherwise manual bake is needed (use the bake button below). \n'Custom' can be used if a custom cubemap is wanted. \n'Realtime' can be used to dynamically re-render the cubemap during runtime (via scripting).")); |
|||
EditorGUI.showMixedValue = false; |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
s.SetModeTarget(p.mode.intValue); |
|||
foreach (var targetObject in p.so.targetObjects) |
|||
ResetProbeSceneTextureInMaterial((ReflectionProbe)targetObject); |
|||
} |
|||
} |
|||
|
|||
static void Drawer_InfluenceShape(UIState s, SerializedReflectionProbe p, Editor owner) |
|||
{ |
|||
EditorGUI.BeginChangeCheck(); |
|||
EditorGUI.showMixedValue = p.influenceShape.hasMultipleDifferentValues; |
|||
EditorGUILayout.PropertyField(p.influenceShape, CoreEditorUtils.GetContent("Shape")); |
|||
EditorGUI.showMixedValue = false; |
|||
if (EditorGUI.EndChangeCheck()) |
|||
s.SetShapeTarget(p.influenceShape.intValue); |
|||
} |
|||
|
|||
static void Drawer_IntensityMultiplier(UIState s, SerializedReflectionProbe p, Editor owner) |
|||
{ |
|||
EditorGUILayout.PropertyField(p.intensityMultiplier, CoreEditorUtils.GetContent("Intensity")); |
|||
} |
|||
#endregion
|
|||
|
|||
#region Toolbar
|
|||
static readonly EditMode.SceneViewEditMode[] k_Toolbar_SceneViewEditModes = |
|||
{ |
|||
EditMode.SceneViewEditMode.ReflectionProbeBox, |
|||
//EditMode.SceneViewEditMode.GridBox,
|
|||
EditMode.SceneViewEditMode.ReflectionProbeOrigin |
|||
}; |
|||
static GUIContent[] s_Toolbar_Contents = null; |
|||
static GUIContent[] toolbar_Contents |
|||
{ |
|||
get |
|||
{ |
|||
return s_Toolbar_Contents ?? (s_Toolbar_Contents = new [] |
|||
{ |
|||
EditorGUIUtility.IconContent("EditCollider", "|Modify the influence volume of the reflection probe."), |
|||
//EditorGUIUtility.IconContent("PreMatCube", "|Modify the projection volume of the reflection probe."),
|
|||
EditorGUIUtility.IconContent("MoveTool", "|Move the selected objects.") |
|||
}); |
|||
} |
|||
} |
|||
static void Drawer_Toolbar(UIState s, SerializedReflectionProbe p, Editor owner) |
|||
{ |
|||
if (p.so.targetObjects.Length > 1) |
|||
return; |
|||
|
|||
// Show the master tool selector
|
|||
GUILayout.BeginHorizontal(); |
|||
GUILayout.FlexibleSpace(); |
|||
GUI.changed = false; |
|||
var oldEditMode = EditMode.editMode; |
|||
|
|||
Func<Bounds> getBounds = () => |
|||
{ |
|||
var bounds = new Bounds(); |
|||
foreach (var targetObject in p.so.targetObjects) |
|||
{ |
|||
var rp = (ReflectionProbe)targetObject; |
|||
var b = rp.bounds; |
|||
bounds.Encapsulate(b); |
|||
} |
|||
return bounds; |
|||
}; |
|||
|
|||
EditMode.DoInspectorToolbar(k_Toolbar_SceneViewEditModes, toolbar_Contents, getBounds, owner); |
|||
|
|||
//if (GUILayout.Button(EditorGUIUtility.IconContent("Navigation", "|Fit the reflection probe volume to the surrounding colliders.")))
|
|||
// s.AddOperation(Operation.FitVolumeToSurroundings);
|
|||
|
|||
if (oldEditMode != EditMode.editMode) |
|||
{ |
|||
switch (EditMode.editMode) |
|||
{ |
|||
case EditMode.SceneViewEditMode.ReflectionProbeOrigin: |
|||
s.UpdateOldLocalSpace((ReflectionProbe)p.so.targetObject); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
GUILayout.FlexibleSpace(); |
|||
GUILayout.EndHorizontal(); |
|||
} |
|||
#endregion
|
|||
|
|||
#region Mode Specific Settings
|
|||
static void Drawer_ModeSettingsCustom(UIState s, SerializedReflectionProbe p, Editor owner) |
|||
{ |
|||
EditorGUILayout.PropertyField(p.renderDynamicObjects, CoreEditorUtils.GetContent("Dynamic Objects|If enabled dynamic objects are also rendered into the cubemap")); |
|||
|
|||
p.customBakedTexture.objectReferenceValue = EditorGUILayout.ObjectField(CoreEditorUtils.GetContent("Cubemap"), p.customBakedTexture.objectReferenceValue, typeof(Cubemap), false); |
|||
} |
|||
|
|||
static void Drawer_ModeSettingsRealtime(UIState s, SerializedReflectionProbe p, Editor owner) |
|||
{ |
|||
EditorGUILayout.PropertyField(p.refreshMode, CoreEditorUtils.GetContent("Refresh Mode|Controls how this probe refreshes in the Player")); |
|||
EditorGUILayout.PropertyField(p.timeSlicingMode, CoreEditorUtils.GetContent("Time Slicing|If enabled this probe will update over several frames, to help reduce the impact on the frame rate")); |
|||
} |
|||
#endregion
|
|||
|
|||
static float CalculateMaxBlendDistance(UIState s, SerializedReflectionProbe p, Editor o) |
|||
{ |
|||
var shape = (ReflectionInfluenceShape)p.influenceShape.intValue; |
|||
switch (shape) |
|||
{ |
|||
case ReflectionInfluenceShape.Sphere: |
|||
return p.influenceSphereRadius.floatValue * 0.5f; |
|||
default: |
|||
case ReflectionInfluenceShape.Box: |
|||
{ |
|||
var size = p.boxSize.vector3Value; |
|||
var v = Mathf.Min(size.x, Mathf.Min(size.y, size.z)); |
|||
return v * 0.5f; |
|||
} |
|||
} |
|||
} |
|||
|
|||
static MethodInfo k_EditorGUI_ButtonWithDropdownList = typeof(EditorGUI).GetMethod("ButtonWithDropdownList", BindingFlags.Static | BindingFlags.NonPublic, null, CallingConventions.Any, new [] { typeof(GUIContent), typeof(string[]), typeof(GenericMenu.MenuFunction2), typeof(GUILayoutOption[]) }, new ParameterModifier[0]); |
|||
static bool ButtonWithDropdownList(GUIContent content, string[] buttonNames, GenericMenu.MenuFunction2 callback, params GUILayoutOption[] options) |
|||
{ |
|||
return (bool)k_EditorGUI_ButtonWithDropdownList.Invoke(null, new object[] { content, buttonNames, callback, options }); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 4b3481acd0445e340a0737660cab9226 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using UnityEditorInternal; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering |
|||
{ |
|||
partial class HDReflectionProbeEditor |
|||
{ |
|||
internal static Color k_GizmoReflectionProbe = new Color(0xFF / 255f, 0xE5 / 255f, 0x94 / 255f, 0x20 / 255f); |
|||
internal static Color k_GizmoReflectionProbeDisabled = new Color(0x99 / 255f, 0x89 / 255f, 0x59 / 255f, 0x10 / 255f); |
|||
internal static Color k_GizmoHandleReflectionProbe = new Color(0xFF / 255f, 0xE5 / 255f, 0xAA / 255f, 0xFF / 255f); |
|||
|
|||
void OnSceneGUI() |
|||
{ |
|||
var s = m_UIState; |
|||
var p = m_SerializedReflectionProbe; |
|||
var o = this; |
|||
|
|||
if (!s.sceneViewEditing) |
|||
return; |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
|
|||
switch (EditMode.editMode) |
|||
{ |
|||
case EditMode.SceneViewEditMode.ReflectionProbeBox: |
|||
if (p.influenceShape.enumValueIndex == 0) |
|||
Handle_InfluenceBoxEditing(s, p, o); |
|||
if (p.influenceShape.enumValueIndex == 1) |
|||
Handle_InfluenceSphereEditing(s, p, o); |
|||
break; |
|||
case EditMode.SceneViewEditMode.GridBox: |
|||
if (p.influenceShape.enumValueIndex == 0) |
|||
Handle_ProjectionBoxEditing(s, p, o); |
|||
if (p.influenceShape.enumValueIndex == 1) |
|||
Handle_ProjectionSphereEditing(s, p, o); |
|||
break; |
|||
case EditMode.SceneViewEditMode.ReflectionProbeOrigin: |
|||
Handle_OriginEditing(s, p, o); |
|||
break; |
|||
} |
|||
|
|||
if (EditorGUI.EndChangeCheck()) |
|||
Repaint(); |
|||
} |
|||
|
|||
static void Handle_InfluenceBoxEditing(UIState s, SerializedReflectionProbe sp, Editor o) |
|||
{ |
|||
var p = (ReflectionProbe)sp.so.targetObject; |
|||
var a = p.GetComponent<HDAdditionalReflectionData>(); |
|||
|
|||
using (new Handles.DrawingScope(GetLocalSpace(p))) |
|||
{ |
|||
s.boxInfluenceBoundsHandle.center = p.center; |
|||
s.boxInfluenceBoundsHandle.size = p.size; |
|||
s.boxBlendHandle.center = p.center; |
|||
s.boxBlendHandle.size = p.size - Vector3.one * p.blendDistance * 2; |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
s.boxInfluenceBoundsHandle.DrawHandle(); |
|||
var influenceChanged = EditorGUI.EndChangeCheck(); |
|||
EditorGUI.BeginChangeCheck(); |
|||
s.boxBlendHandle.DrawHandle(); |
|||
if (influenceChanged || EditorGUI.EndChangeCheck()) |
|||
{ |
|||
Undo.RecordObject(p, "Modified Reflection Probe AABB"); |
|||
var center = s.boxInfluenceBoundsHandle.center; |
|||
var influenceSize = s.boxInfluenceBoundsHandle.size; |
|||
var blendSize = s.boxBlendHandle.size; |
|||
ValidateAABB(p, ref center, ref influenceSize); |
|||
var blendDistance = influenceChanged |
|||
? p.blendDistance |
|||
: ((influenceSize.x - blendSize.x) * 0.5f + (influenceSize.y - blendSize.y) * 0.5f + (influenceSize.z - blendSize.z) * 0.5f) / 3; |
|||
p.center = center; |
|||
p.size = influenceSize; |
|||
p.blendDistance = Mathf.Max(blendDistance, 0); |
|||
EditorUtility.SetDirty(p); |
|||
} |
|||
} |
|||
} |
|||
|
|||
static void Handle_ProjectionBoxEditing(UIState s, SerializedReflectionProbe sp, Editor o) |
|||
{ |
|||
var p = (ReflectionProbe)sp.so.targetObject; |
|||
var reflectionData = p.GetComponent<HDAdditionalReflectionData>(); |
|||
|
|||
using (new Handles.DrawingScope(GetLocalSpace(p))) |
|||
{ |
|||
s.boxProjectionBoundsHandle.center = reflectionData.boxReprojectionVolumeCenter; |
|||
s.boxProjectionBoundsHandle.size = reflectionData.boxReprojectionVolumeSize; |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
s.boxProjectionBoundsHandle.DrawHandle(); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
Undo.RecordObject(reflectionData, "Modified Reflection Probe AABB"); |
|||
var center = s.boxProjectionBoundsHandle.center; |
|||
var size = s.boxProjectionBoundsHandle.size; |
|||
ValidateAABB(p, ref center, ref size); |
|||
reflectionData.boxReprojectionVolumeCenter = center; |
|||
reflectionData.boxReprojectionVolumeSize = size; |
|||
EditorUtility.SetDirty(reflectionData); |
|||
} |
|||
} |
|||
} |
|||
|
|||
static void Handle_InfluenceSphereEditing(UIState s, SerializedReflectionProbe sp, Editor o) |
|||
{ |
|||
var p = (ReflectionProbe)sp.so.targetObject; |
|||
var reflectionData = p.GetComponent<HDAdditionalReflectionData>(); |
|||
|
|||
using (new Handles.DrawingScope(GetLocalSpace(p))) |
|||
{ |
|||
s.influenceSphereHandle.center = p.center; |
|||
s.influenceSphereHandle.radius = reflectionData.influenceSphereRadius; |
|||
s.sphereBlendHandle.center = p.center; |
|||
s.sphereBlendHandle.radius = Mathf.Min(reflectionData.influenceSphereRadius - p.blendDistance * 2, reflectionData.influenceSphereRadius); |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
s.influenceSphereHandle.DrawHandle(); |
|||
var influenceChanged = EditorGUI.EndChangeCheck(); |
|||
EditorGUI.BeginChangeCheck(); |
|||
s.sphereBlendHandle.DrawHandle(); |
|||
if (influenceChanged || EditorGUI.EndChangeCheck()) |
|||
{ |
|||
Undo.RecordObject(reflectionData, "Modified Reflection influence volume"); |
|||
var center = p.center; |
|||
var influenceRadius = s.influenceSphereHandle.radius; |
|||
var blendRadius = influenceChanged |
|||
? Mathf.Max(influenceRadius - p.blendDistance * 2, 0) |
|||
: s.sphereBlendHandle.radius; |
|||
|
|||
var radius = Vector3.one * influenceRadius; |
|||
|
|||
ValidateAABB(p, ref center, ref radius); |
|||
influenceRadius = radius.x; |
|||
var blendDistance = Mathf.Max(0, (influenceRadius - blendRadius) * 0.5f); |
|||
|
|||
reflectionData.influenceSphereRadius = influenceRadius; |
|||
p.blendDistance = blendDistance; |
|||
EditorUtility.SetDirty(p); |
|||
EditorUtility.SetDirty(reflectionData); |
|||
} |
|||
} |
|||
} |
|||
|
|||
static void Handle_ProjectionSphereEditing(UIState s, SerializedReflectionProbe sp, Editor o) |
|||
{ |
|||
var p = (ReflectionProbe)sp.so.targetObject; |
|||
var reflectionData = p.GetComponent<HDAdditionalReflectionData>(); |
|||
|
|||
using (new Handles.DrawingScope(GetLocalSpace(p))) |
|||
{ |
|||
s.projectionSphereHandle.center = p.center; |
|||
s.projectionSphereHandle.radius = reflectionData.sphereReprojectionVolumeRadius; |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
s.projectionSphereHandle.DrawHandle(); |
|||
if (EditorGUI.EndChangeCheck()) |
|||
{ |
|||
Undo.RecordObject(reflectionData, "Modified Reflection Probe projection volume"); |
|||
var center = s.projectionSphereHandle.center; |
|||
var radius = s.projectionSphereHandle.radius; |
|||
//ValidateAABB(ref center, ref radius);
|
|||
reflectionData.sphereReprojectionVolumeRadius = radius; |
|||
EditorUtility.SetDirty(reflectionData); |
|||
} |
|||
} |
|||
} |
|||
|
|||
static void Handle_OriginEditing(UIState s, SerializedReflectionProbe sp, Editor o) |
|||
{ |
|||
var p = (ReflectionProbe)sp.so.targetObject; |
|||
var transformPosition = p.transform.position; |
|||
var size = p.size; |
|||
|
|||
EditorGUI.BeginChangeCheck(); |
|||
var newPostion = Handles.PositionHandle(transformPosition, GetLocalSpaceRotation(p)); |
|||
|
|||
var changed = EditorGUI.EndChangeCheck(); |
|||
|
|||
if (changed || s.oldLocalSpace != GetLocalSpace(p)) |
|||
{ |
|||
var localNewPosition = s.oldLocalSpace.inverse.MultiplyPoint3x4(newPostion); |
|||
|
|||
var b = new Bounds(p.center, size); |
|||
localNewPosition = b.ClosestPoint(localNewPosition); |
|||
|
|||
Undo.RecordObject(p.transform, "Modified Reflection Probe Origin"); |
|||
p.transform.position = s.oldLocalSpace.MultiplyPoint3x4(localNewPosition); |
|||
|
|||
Undo.RecordObject(p, "Modified Reflection Probe Origin"); |
|||
p.center = GetLocalSpace(p).inverse.MultiplyPoint3x4(s.oldLocalSpace.MultiplyPoint3x4(p.center)); |
|||
|
|||
EditorUtility.SetDirty(p); |
|||
|
|||
s.UpdateOldLocalSpace(p); |
|||
} |
|||
} |
|||
|
|||
[DrawGizmo(GizmoType.Active)] |
|||
static void RenderGizmo(ReflectionProbe reflectionProbe, GizmoType gizmoType) |
|||
{ |
|||
var e = GetEditorFor(reflectionProbe); |
|||
if (e == null) |
|||
return; |
|||
|
|||
var reflectionData = reflectionProbe.GetComponent<HDAdditionalReflectionData>(); |
|||
|
|||
if (e.sceneViewEditing && EditMode.editMode == EditMode.SceneViewEditMode.ReflectionProbeBox) |
|||
{ |
|||
var oldColor = Gizmos.color; |
|||
Gizmos.color = k_GizmoReflectionProbe; |
|||
|
|||
Gizmos.matrix = GetLocalSpace(reflectionProbe); |
|||
if (reflectionData.influenceShape == ReflectionInfluenceShape.Box) |
|||
Gizmos.DrawCube(reflectionProbe.center, -1f * reflectionProbe.size); |
|||
if (reflectionData.influenceShape == ReflectionInfluenceShape.Sphere) |
|||
Gizmos.DrawSphere(reflectionProbe.center, reflectionData.influenceSphereRadius); |
|||
|
|||
Gizmos.matrix = Matrix4x4.identity; |
|||
Gizmos.color = oldColor; |
|||
} |
|||
} |
|||
|
|||
[DrawGizmo(GizmoType.Selected)] |
|||
static void DrawSelectedGizmo(ReflectionProbe reflectionProbe, GizmoType gizmoType) |
|||
{ |
|||
Color oldColor = Gizmos.color; |
|||
Gizmos.color = reflectionProbe.isActiveAndEnabled ? k_GizmoReflectionProbe : k_GizmoReflectionProbeDisabled; |
|||
var reflectionData = reflectionProbe.GetComponent<HDAdditionalReflectionData>(); |
|||
|
|||
if (reflectionData.influenceShape == ReflectionInfluenceShape.Box) |
|||
{ |
|||
DrawBoxInfluenceGizmo(reflectionProbe, oldColor); |
|||
} |
|||
if (reflectionData.influenceShape == ReflectionInfluenceShape.Sphere) |
|||
{ |
|||
DrawSphereInfluenceGizmo(reflectionProbe, oldColor, reflectionData); |
|||
} |
|||
if (reflectionData.useSeparateProjectionVolume) |
|||
{ |
|||
DrawReprojectionVolumeGizmo(reflectionProbe, reflectionData); |
|||
} |
|||
Gizmos.color = oldColor; |
|||
|
|||
DrawVerticalRay(reflectionProbe.transform); |
|||
|
|||
ChangeVisibility(reflectionProbe, true); |
|||
} |
|||
|
|||
[DrawGizmo(GizmoType.NonSelected)] |
|||
static void DrawNonSelectedGizmo(ReflectionProbe reflectionProbe, GizmoType gizmoType) |
|||
{ |
|||
var reflectionData = reflectionProbe.GetComponent<HDAdditionalReflectionData>(); |
|||
if (reflectionData != null) |
|||
ChangeVisibility(reflectionProbe, false); |
|||
} |
|||
|
|||
static void DrawBoxInfluenceGizmo(ReflectionProbe reflectionProbe, Color oldColor) |
|||
{ |
|||
Gizmos.matrix = GetLocalSpace(reflectionProbe); |
|||
Gizmos.DrawWireCube(reflectionProbe.center, reflectionProbe.size); |
|||
if (reflectionProbe.blendDistance > 0) |
|||
{ |
|||
Gizmos.color = new Color(Gizmos.color.r, Gizmos.color.g, Gizmos.color.b, 0.3f); |
|||
Gizmos.DrawWireCube(reflectionProbe.center, new Vector3(reflectionProbe.size.x - reflectionProbe.blendDistance * 2, reflectionProbe.size.y - reflectionProbe.blendDistance * 2, reflectionProbe.size.z - reflectionProbe.blendDistance * 2)); |
|||
} |
|||
Gizmos.matrix = Matrix4x4.identity; |
|||
Gizmos.color = oldColor; |
|||
} |
|||
|
|||
static void DrawSphereInfluenceGizmo(ReflectionProbe reflectionProbe, Color oldColor, HDAdditionalReflectionData reflectionData) |
|||
{ |
|||
Gizmos.matrix = GetLocalSpace(reflectionProbe); |
|||
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.influenceSphereRadius); |
|||
if (reflectionProbe.blendDistance > 0) |
|||
{ |
|||
Gizmos.color = new Color(Gizmos.color.r, Gizmos.color.g, Gizmos.color.b, 0.3f); |
|||
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.influenceSphereRadius - 2 * reflectionProbe.blendDistance); |
|||
} |
|||
Gizmos.matrix = Matrix4x4.identity; |
|||
Gizmos.color = oldColor; |
|||
} |
|||
|
|||
static void DrawReprojectionVolumeGizmo(ReflectionProbe reflectionProbe, HDAdditionalReflectionData reflectionData) |
|||
{ |
|||
Color reprojectionColor = new Color(Color.cyan.r, Color.cyan.g, Color.cyan.b, 0.3f); |
|||
Gizmos.color = reprojectionColor; |
|||
Gizmos.matrix = GetLocalSpace(reflectionProbe); |
|||
if (reflectionData.influenceShape == ReflectionInfluenceShape.Box) |
|||
{ |
|||
Gizmos.DrawWireCube(reflectionData.boxReprojectionVolumeCenter, reflectionData.boxReprojectionVolumeSize); |
|||
} |
|||
if (reflectionData.influenceShape == ReflectionInfluenceShape.Sphere) |
|||
{ |
|||
Gizmos.DrawWireSphere(reflectionProbe.center, reflectionData.sphereReprojectionVolumeRadius); |
|||
} |
|||
Gizmos.matrix = Matrix4x4.identity; |
|||
} |
|||
|
|||
static void DrawVerticalRay(Transform transform) |
|||
{ |
|||
Ray ray = new Ray(transform.position, Vector3.down); |
|||
RaycastHit hit; |
|||
if (Physics.Raycast(ray, out hit)) |
|||
{ |
|||
Handles.color = Color.green; |
|||
Handles.zTest = UnityEngine.Rendering.CompareFunction.LessEqual; |
|||
Handles.DrawLine(transform.position - Vector3.up * 0.5f, hit.point); |
|||
Handles.DrawWireDisc(hit.point, hit.normal, 0.5f); |
|||
|
|||
Handles.color = Color.red; |
|||
Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater; |
|||
Handles.DrawLine(transform.position, hit.point); |
|||
Handles.DrawWireDisc(hit.point, hit.normal, 0.5f); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e389a5db9b96c2a4ba5f60f6a402d6f4 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering |
|||
{ |
|||
partial class HDReflectionProbeEditor |
|||
{ |
|||
HDCubemapInspector m_CubemapEditor; |
|||
|
|||
public override bool HasPreviewGUI() |
|||
{ |
|||
if (targets.Length > 1) |
|||
return false; // We only handle one preview for reflection probes
|
|||
|
|||
// Ensure valid cube map editor (if possible)
|
|||
if (ValidPreviewSetup()) |
|||
{ |
|||
Editor editor = m_CubemapEditor; |
|||
CreateCachedEditor(((ReflectionProbe)target).texture, null, ref editor); |
|||
m_CubemapEditor = editor as HDCubemapInspector; |
|||
} |
|||
|
|||
// If having one probe selected we always want preview (to prevent preview window from popping)
|
|||
return true; |
|||
} |
|||
|
|||
public override void OnPreviewSettings() |
|||
{ |
|||
if (!ValidPreviewSetup() |
|||
|| m_CubemapEditor == null) |
|||
return; |
|||
|
|||
m_CubemapEditor.OnPreviewSettings(); |
|||
} |
|||
|
|||
public override void OnPreviewGUI(Rect position, GUIStyle style) |
|||
{ |
|||
if (!ValidPreviewSetup() |
|||
|| m_CubemapEditor == null) |
|||
{ |
|||
GUILayout.BeginHorizontal(); |
|||
GUILayout.FlexibleSpace(); |
|||
Color prevColor = GUI.color; |
|||
GUI.color = new Color(1, 1, 1, 0.5f); |
|||
GUILayout.Label("Reflection Probe not baked yet"); |
|||
GUI.color = prevColor; |
|||
GUILayout.FlexibleSpace(); |
|||
GUILayout.EndHorizontal(); |
|||
return; |
|||
} |
|||
|
|||
var p = target as ReflectionProbe; |
|||
if (p != null && p.texture != null && targets.Length == 1) |
|||
m_CubemapEditor.DrawPreview(position); |
|||
|
|||
} |
|||
|
|||
bool ValidPreviewSetup() |
|||
{ |
|||
var p = target as ReflectionProbe; |
|||
return p != null && p.texture != null; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 10da9cb15a7644245b87056613737840 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using Object = UnityEngine.Object; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering |
|||
{ |
|||
partial class HDReflectionProbeEditor |
|||
{ |
|||
static Material s_PreviewMaterial; |
|||
static Mesh s_SphereMesh; |
|||
static int _Cubemap = Shader.PropertyToID("_Cubemap"); |
|||
|
|||
|
|||
[InitializeOnLoadMethod] |
|||
static void Initialize() |
|||
{ |
|||
s_PreviewMaterial = new Material(Shader.Find("Debug/ReflectionProbePreview")) |
|||
{ |
|||
hideFlags = HideFlags.HideAndDontSave |
|||
}; |
|||
s_SphereMesh = Resources.GetBuiltinResource(typeof(Mesh), "New-Sphere.fbx") as Mesh; |
|||
} |
|||
|
|||
static void InitializeProbe(ReflectionProbe p, HDAdditionalReflectionData data) |
|||
{ |
|||
var meshFilter = p.GetComponent<MeshFilter>() ?? p.gameObject.AddComponent<MeshFilter>(); |
|||
var meshRenderer = p.GetComponent<MeshRenderer>() ?? p.gameObject.AddComponent<MeshRenderer>(); |
|||
|
|||
meshFilter.sharedMesh = s_SphereMesh; |
|||
|
|||
var material = meshRenderer.sharedMaterial; |
|||
if (material == null |
|||
|| material == s_PreviewMaterial |
|||
|| material.shader != s_PreviewMaterial.shader) |
|||
{ |
|||
material = Object.Instantiate(s_PreviewMaterial); |
|||
material.SetTexture(_Cubemap, p.texture); |
|||
material.hideFlags = HideFlags.HideAndDontSave; |
|||
meshRenderer.material = material; |
|||
} |
|||
|
|||
meshRenderer.lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off; |
|||
meshRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; |
|||
meshRenderer.motionVectorGenerationMode = MotionVectorGenerationMode.ForceNoMotion; |
|||
} |
|||
|
|||
static void ChangeVisibility(ReflectionProbe p, bool visible) |
|||
{ |
|||
var meshRenderer = p.GetComponent<MeshRenderer>() ?? p.gameObject.AddComponent<MeshRenderer>(); |
|||
meshRenderer.enabled = visible; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f6273acc6af56c2469971f9fd835884c |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Reflection; |
|||
using UnityEditorInternal; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
using UnityEngine.SceneManagement; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering |
|||
{ |
|||
[CustomEditorForRenderPipeline(typeof(ReflectionProbe), typeof(HDRenderPipelineAsset))] |
|||
[CanEditMultipleObjects] |
|||
partial class HDReflectionProbeEditor : Editor |
|||
{ |
|||
static Dictionary<ReflectionProbe, HDReflectionProbeEditor> s_ReflectionProbeEditors = new Dictionary<ReflectionProbe, HDReflectionProbeEditor>(); |
|||
|
|||
static HDReflectionProbeEditor GetEditorFor(ReflectionProbe p) |
|||
{ |
|||
HDReflectionProbeEditor e; |
|||
if (s_ReflectionProbeEditors.TryGetValue(p, out e) |
|||
&& e != null |
|||
&& !e.Equals(null) |
|||
&& ArrayUtility.IndexOf(e.targets, p) != -1) |
|||
return e; |
|||
|
|||
return null; |
|||
} |
|||
|
|||
SerializedReflectionProbe m_SerializedReflectionProbe; |
|||
SerializedObject m_AdditionalDataSerializedObject; |
|||
UIState m_UIState = new UIState(); |
|||
|
|||
public bool sceneViewEditing |
|||
{ |
|||
get { return IsReflectionProbeEditMode(EditMode.editMode) && EditMode.IsOwner(this); } |
|||
} |
|||
|
|||
void OnEnable() |
|||
{ |
|||
var additionalData = CoreEditorUtils.GetAdditionalData<HDAdditionalReflectionData>(targets); |
|||
m_AdditionalDataSerializedObject = new SerializedObject(additionalData); |
|||
m_SerializedReflectionProbe = new SerializedReflectionProbe(serializedObject, m_AdditionalDataSerializedObject); |
|||
m_UIState.Reset( |
|||
this, |
|||
Repaint, |
|||
m_SerializedReflectionProbe); |
|||
|
|||
foreach (var t in targets) |
|||
{ |
|||
var p = (ReflectionProbe)t; |
|||
s_ReflectionProbeEditors[p] = this; |
|||
} |
|||
|
|||
for (var i = 0; i < targets.Length; ++i) |
|||
{ |
|||
var p = (ReflectionProbe)targets[i]; |
|||
var a = additionalData[i]; |
|||
InitializeProbe(p, a); |
|||
ChangeVisibility(p, true); |
|||
} |
|||
} |
|||
|
|||
void OnDisable() |
|||
{ |
|||
for (var i = 0; i < targets.Length; ++i) |
|||
{ |
|||
var p = (ReflectionProbe)targets[i]; |
|||
ChangeVisibility(p, false); |
|||
} |
|||
} |
|||
|
|||
public override void OnInspectorGUI() |
|||
{ |
|||
serializedObject.Update(); |
|||
m_AdditionalDataSerializedObject.Update(); |
|||
|
|||
var s = m_UIState; |
|||
var p = m_SerializedReflectionProbe; |
|||
|
|||
k_PrimarySection.Draw(s, p, this); |
|||
k_InfluenceVolumeSection.Draw(s, p, this); |
|||
k_SeparateProjectionVolumeSection.Draw(s, p, this); |
|||
k_CaptureSection.Draw(s, p, this); |
|||
//k_AdditionalSection.Draw(s, p, this);
|
|||
k_BakingActions.Draw(s, p, this); |
|||
|
|||
PerformOperations(s, p, this); |
|||
|
|||
m_AdditionalDataSerializedObject.ApplyModifiedProperties(); |
|||
serializedObject.ApplyModifiedProperties(); |
|||
|
|||
HideAdditionalComponents(false); |
|||
} |
|||
|
|||
static void PerformOperations(UIState s, SerializedReflectionProbe p, HDReflectionProbeEditor o) |
|||
{ |
|||
|
|||
} |
|||
|
|||
void HideAdditionalComponents(bool visible) |
|||
{ |
|||
var adds = CoreEditorUtils.GetAdditionalData<HDAdditionalReflectionData>(targets); |
|||
var flags = visible ? HideFlags.None : HideFlags.HideInInspector; |
|||
for (var i = 0 ; i < targets.Length; ++i) |
|||
{ |
|||
var target = targets[i]; |
|||
var addData = adds[i]; |
|||
var p = (ReflectionProbe)target; |
|||
var meshRenderer = p.GetComponent<MeshRenderer>(); |
|||
var meshFilter = p.GetComponent<MeshFilter>(); |
|||
|
|||
addData.hideFlags = flags; |
|||
meshRenderer.hideFlags = flags; |
|||
meshFilter.hideFlags = flags; |
|||
} |
|||
} |
|||
|
|||
static Matrix4x4 GetLocalSpace(ReflectionProbe probe) |
|||
{ |
|||
var t = probe.transform.position; |
|||
return Matrix4x4.TRS(t, GetLocalSpaceRotation(probe), Vector3.one); |
|||
} |
|||
|
|||
static Quaternion GetLocalSpaceRotation(ReflectionProbe probe) |
|||
{ |
|||
var supportsRotation = (SupportedRenderingFeatures.active.reflectionProbeSupportFlags & SupportedRenderingFeatures.ReflectionProbeSupportFlags.Rotation) != 0; |
|||
return supportsRotation |
|||
? probe.transform.rotation |
|||
: Quaternion.identity; |
|||
} |
|||
|
|||
// Ensures that probe's AABB encapsulates probe's position
|
|||
// Returns true, if center or size was modified
|
|||
static bool ValidateAABB(ReflectionProbe p, ref Vector3 center, ref Vector3 size) |
|||
{ |
|||
var localSpace = GetLocalSpace(p); |
|||
var localTransformPosition = localSpace.inverse.MultiplyPoint3x4(p.transform.position); |
|||
|
|||
var b = new Bounds(center, size); |
|||
|
|||
if (b.Contains(localTransformPosition)) |
|||
return false; |
|||
|
|||
b.Encapsulate(localTransformPosition); |
|||
|
|||
center = b.center; |
|||
size = b.size; |
|||
return true; |
|||
} |
|||
|
|||
static bool IsCollidingWithOtherProbes(string targetPath, ReflectionProbe targetProbe, out ReflectionProbe collidingProbe) |
|||
{ |
|||
ReflectionProbe[] probes = FindObjectsOfType<ReflectionProbe>().ToArray(); |
|||
collidingProbe = null; |
|||
foreach (var probe in probes) |
|||
{ |
|||
if (probe == targetProbe || probe.customBakedTexture == null) |
|||
continue; |
|||
string path = AssetDatabase.GetAssetPath(probe.customBakedTexture); |
|||
if (path == targetPath) |
|||
{ |
|||
collidingProbe = probe; |
|||
return true; |
|||
} |
|||
} |
|||
return false; |
|||
} |
|||
|
|||
static bool IsReflectionProbeEditMode(EditMode.SceneViewEditMode editMode) |
|||
{ |
|||
return editMode == EditMode.SceneViewEditMode.ReflectionProbeBox || editMode == EditMode.SceneViewEditMode.Collider || editMode == EditMode.SceneViewEditMode.GridBox || |
|||
editMode == EditMode.SceneViewEditMode.ReflectionProbeOrigin; |
|||
} |
|||
|
|||
static void BakeCustomReflectionProbe(ReflectionProbe probe, bool usePreviousAssetPath, bool custom) |
|||
{ |
|||
if (!custom && probe.bakedTexture != null) |
|||
probe.customBakedTexture = probe.bakedTexture; |
|||
|
|||
string path = ""; |
|||
if (usePreviousAssetPath) |
|||
path = AssetDatabase.GetAssetPath(probe.customBakedTexture); |
|||
|
|||
string targetExtension = probe.hdr ? "exr" : "png"; |
|||
if (string.IsNullOrEmpty(path) || Path.GetExtension(path) != "." + targetExtension) |
|||
{ |
|||
// We use the path of the active scene as the target path
|
|||
var targetPath = SceneManager.GetActiveScene().path; |
|||
targetPath = Path.Combine(Path.GetDirectoryName(targetPath), Path.GetFileNameWithoutExtension(targetPath)); |
|||
if (string.IsNullOrEmpty(targetPath)) |
|||
targetPath = "Assets"; |
|||
else if (Directory.Exists(targetPath) == false) |
|||
Directory.CreateDirectory(targetPath); |
|||
|
|||
string fileName = probe.name + (probe.hdr ? "-reflectionHDR" : "-reflection") + "." + targetExtension; |
|||
fileName = Path.GetFileNameWithoutExtension(AssetDatabase.GenerateUniqueAssetPath(Path.Combine(targetPath, fileName))); |
|||
|
|||
path = EditorUtility.SaveFilePanelInProject("Save reflection probe's cubemap.", fileName, targetExtension, "", targetPath); |
|||
if (string.IsNullOrEmpty(path)) |
|||
return; |
|||
|
|||
ReflectionProbe collidingProbe; |
|||
if (IsCollidingWithOtherProbes(path, probe, out collidingProbe)) |
|||
{ |
|||
if (!EditorUtility.DisplayDialog("Cubemap is used by other reflection probe", |
|||
string.Format("'{0}' path is used by the game object '{1}', do you really want to overwrite it?", |
|||
path, collidingProbe.name), "Yes", "No")) |
|||
{ |
|||
return; |
|||
} |
|||
} |
|||
} |
|||
|
|||
EditorUtility.DisplayProgressBar("Reflection Probes", "Baking " + path, 0.5f); |
|||
if (!UnityEditor.Lightmapping.BakeReflectionProbe(probe, path)) |
|||
Debug.LogError("Failed to bake reflection probe to " + path); |
|||
EditorUtility.ClearProgressBar(); |
|||
} |
|||
|
|||
static MethodInfo k_Lightmapping_BakeReflectionProbeSnapshot = typeof(UnityEditor.Lightmapping).GetMethod("BakeReflectionProbeSnapshot", BindingFlags.Static | BindingFlags.NonPublic); |
|||
static bool BakeReflectionProbeSnapshot(ReflectionProbe probe) |
|||
{ |
|||
return (bool)k_Lightmapping_BakeReflectionProbeSnapshot.Invoke(null, new object[] { probe }); |
|||
} |
|||
|
|||
static MethodInfo k_Lightmapping_BakeAllReflectionProbesSnapshots = typeof(UnityEditor.Lightmapping).GetMethod("BakeAllReflectionProbesSnapshots", BindingFlags.Static | BindingFlags.NonPublic); |
|||
static bool BakeAllReflectionProbesSnapshots() |
|||
{ |
|||
return (bool)k_Lightmapping_BakeAllReflectionProbesSnapshots.Invoke(null, new object[0]); |
|||
} |
|||
|
|||
static void ResetProbeSceneTextureInMaterial(ReflectionProbe p) |
|||
{ |
|||
var renderer = p.GetComponent<Renderer>(); |
|||
renderer.sharedMaterial.SetTexture(_Cubemap, p.texture); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ad7341012fc407341a64d703beefb011 |
|||
timeCreated: 1507739065 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!21 &2100000 |
|||
Material: |
|||
serializedVersion: 6 |
|||
m_ObjectHideFlags: 0 |
|||
m_PrefabParentObject: {fileID: 0} |
|||
m_PrefabInternal: {fileID: 0} |
|||
m_Name: PreviewCubemapMaterial |
|||
m_Shader: {fileID: 4800000, guid: dfb0f7452ff8af24da7ad152669043b1, type: 3} |
|||
m_ShaderKeywords: _ALBEDOAFFECTEMISSIVE_OFF _ALPHACUTOFFENABLE_OFF _DEPTHOFFSETENABLE_OFF |
|||
_DISTORTIONDEPTHTEST_OFF _DISTORTIONENABLE_OFF _DISTORTIONONLY_OFF _DOUBLESIDEDENABLE_OFF |
|||
_ENABLEPERPIXELDISPLACEMENT_OFF _ENABLESPECULAROCCLUSION_OFF _ENABLEWIND_OFF |
|||
m_LightmapFlags: 4 |
|||
m_EnableInstancingVariants: 0 |
|||
m_DoubleSidedGI: 0 |
|||
m_CustomRenderQueue: -1 |
|||
stringTagMap: {} |
|||
disabledShaderPasses: [] |
|||
m_SavedProperties: |
|||
serializedVersion: 3 |
|||
m_TexEnvs: |
|||
- _AnisotropyMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _BaseColorMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _BentNormalMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _BentNormalMapOS: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _Cubemap: |
|||
m_Texture: {fileID: 8900000, guid: 92b5e3ec0b8d42049a853f0f4f01e4a7, type: 3} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DetailMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _DistortionVectorMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _EmissiveColorMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _HeightMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _MaskMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _NormalMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _NormalMapOS: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _SpecularColorMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _SubsurfaceRadiusMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _TangentMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _TangentMapOS: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
- _ThicknessMap: |
|||
m_Texture: {fileID: 0} |
|||
m_Scale: {x: 1, y: 1} |
|||
m_Offset: {x: 0, y: 0} |
|||
m_Floats: |
|||
- _AlbedoAffectEmissive: 0 |
|||
- _AlphaCutoff: 0.5 |
|||
- _AlphaCutoffEnable: 0 |
|||
- _Anisotropy: 0 |
|||
- _BlendMode: 0 |
|||
- _CoatCoverage: 1 |
|||
- _CoatIOR: 0.5 |
|||
- _CullMode: 2 |
|||
- _DepthOffsetEnable: 0 |
|||
- _DetailAlbedoScale: 1 |
|||
- _DetailNormalScale: 1 |
|||
- _DetailSmoothnessScale: 1 |
|||
- _DistortionDepthTest: 0 |
|||
- _DistortionEnable: 0 |
|||
- _DistortionOnly: 0 |
|||
- _DoubleSidedEnable: 0 |
|||
- _DoubleSidedNormalMode: 1 |
|||
- _Drag: 1 |
|||
- _DstBlend: 0 |
|||
- _EmissiveColorMode: 1 |
|||
- _EmissiveIntensity: 0 |
|||
- _EnablePerPixelDisplacement: 0 |
|||
- _EnableSpecularOcclusion: 0 |
|||
- _EnableWind: 0 |
|||
- _Exposure: 0 |
|||
- _HeightAmplitude: 0.01 |
|||
- _HeightCenter: 0.5 |
|||
- _HeightMax: 1 |
|||
- _HeightMin: -1 |
|||
- _InitialBend: 1 |
|||
- _MaterialID: 1 |
|||
- _Metallic: 0 |
|||
- _MipLevel: 0 |
|||
- _NormalMapSpace: 0 |
|||
- _NormalScale: 1 |
|||
- _PPDLodThreshold: 5 |
|||
- _PPDMaxSamples: 15 |
|||
- _PPDMinSamples: 5 |
|||
- _ShiverDirectionality: 0.5 |
|||
- _ShiverDrag: 0.2 |
|||
- _Smoothness: 1 |
|||
- _SmoothnessRemapMax: 1 |
|||
- _SmoothnessRemapMin: 0 |
|||
- _SrcBlend: 1 |
|||
- _StencilRef: 2 |
|||
- _Stiffness: 1 |
|||
- _SubsurfaceProfile: 0 |
|||
- _SubsurfaceRadius: 1 |
|||
- _SurfaceType: 0 |
|||
- _TexWorldScale: 1 |
|||
- _Thickness: 1 |
|||
- _UVBase: 0 |
|||
- _UVDetail: 0 |
|||
- _ZTestMode: 8 |
|||
- _ZWrite: 1 |
|||
m_Colors: |
|||
- _BaseColor: {r: 1, g: 1, b: 1, a: 1} |
|||
- _CameraWorldPosition: {r: 1, g: 1, b: 1, a: 1} |
|||
- _DoubleSidedConstants: {r: 1, g: 1, b: -1, a: 0} |
|||
- _EmissionColor: {r: 1, g: 1, b: 1, a: 1} |
|||
- _EmissiveColor: {r: 0, g: 0, b: 0, a: 1} |
|||
- _SpecularColor: {r: 1, g: 1, b: 1, a: 1} |
|||
- _UVDetailsMappingMask: {r: 1, g: 0, b: 0, a: 0} |
|||
- _UVMappingMask: {r: 1, g: 0, b: 0, a: 0} |
|
|||
fileFormatVersion: 2 |
|||
guid: 2d429e5e71c1df34791a7779fdf54dc8 |
|||
timeCreated: 1507739089 |
|||
licenseType: Pro |
|||
NativeFormatImporter: |
|||
externalObjects: {} |
|||
mainObjectFileID: 0 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
namespace UnityEngine.Experimental.Rendering |
|||
{ |
|||
public enum ReflectionInfluenceShape { Box, Sphere }; |
|||
|
|||
[RequireComponent(typeof(ReflectionProbe), typeof(MeshFilter), typeof(MeshRenderer))] |
|||
public class HDAdditionalReflectionData : MonoBehaviour |
|||
{ |
|||
public ReflectionInfluenceShape influenceShape; |
|||
[Range(0.0f,1.0f)] |
|||
public float dimmer = 1.0f; |
|||
public float influenceSphereRadius = 3.0f; |
|||
public float sphereReprojectionVolumeRadius = 1.0f; |
|||
public bool useSeparateProjectionVolume = false; |
|||
public Vector3 boxReprojectionVolumeSize = Vector3.one; |
|||
public Vector3 boxReprojectionVolumeCenter = Vector3.zero; |
|||
public float maxSearchDistance = 8.0f; |
|||
public Texture previewCubemap; |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: d0ef8dc2c2eabfa4e8cb77be57a837c0 |
|||
timeCreated: 1507739066 |
|||
licenseType: Pro |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue