Frédéric Vauchelles
7 年前
当前提交
d3b61a0b
共有 11 个文件被更改,包括 388 次插入 和 158 次删除
-
60ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDReflectionProbeEditorUtility.cs
-
82ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/HDReflectionProbeUI.Drawers.cs
-
46ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/PlanarReflectionProbeEditor.cs
-
74ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/PlanarReflectionProbeUI.Drawers.cs
-
18ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/PlanarReflectionProbeUI.cs
-
8ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/SerializedPlanarReflectionProbe.cs
-
8ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/PlanarReflectionProbe.cs
-
92ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/EditorReflectionSystem.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/EditorReflectionSystem.cs.meta
-
136ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/EditorReflectionSystemGUI.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/EditorReflectionSystemGUI.cs.meta
|
|||
using System; |
|||
using System.IO; |
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
using UnityEngine.SceneManagement; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public static class EditorReflectionSystem |
|||
{ |
|||
static int _Cubemap = Shader.PropertyToID("_Cubemap"); |
|||
|
|||
public static void BakeCustomReflectionProbe(PlanarReflectionProbe probe, bool usePreviousAssetPath, bool custom) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public 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 (HDReflectionProbeEditorUtility.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(); |
|||
} |
|||
|
|||
public static void ResetProbeSceneTextureInMaterial(ReflectionProbe p) |
|||
{ |
|||
var renderer = p.GetComponent<Renderer>(); |
|||
renderer.sharedMaterial.SetTexture(_Cubemap, p.texture); |
|||
} |
|||
|
|||
public static void ResetProbeSceneTextureInMaterial(PlanarReflectionProbe p) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
static MethodInfo k_Lightmapping_BakeReflectionProbeSnapshot = typeof(UnityEditor.Lightmapping).GetMethod("BakeReflectionProbeSnapshot", BindingFlags.Static | BindingFlags.NonPublic); |
|||
public static bool BakeReflectionProbeSnapshot(ReflectionProbe probe) |
|||
{ |
|||
return (bool)k_Lightmapping_BakeReflectionProbeSnapshot.Invoke(null, new object[] { probe }); |
|||
} |
|||
|
|||
public static bool BakeReflectionProbeSnapshot(PlanarReflectionProbe probe) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
static MethodInfo k_Lightmapping_BakeAllReflectionProbesSnapshots = typeof(UnityEditor.Lightmapping).GetMethod("BakeAllReflectionProbesSnapshots", BindingFlags.Static | BindingFlags.NonPublic); |
|||
public static bool BakeAllReflectionProbesSnapshots() |
|||
{ |
|||
return (bool)k_Lightmapping_BakeAllReflectionProbesSnapshots.Invoke(null, new object[0]); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 3720f06e345541048b495e66d61a1405 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Reflection; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
using UnityEngine.Rendering; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
using _ = CoreEditorUtils; |
|||
|
|||
public static class EditorReflectionSystemGUI |
|||
{ |
|||
static readonly string[] k_BakeCustomOptionText = { "Bake as new Cubemap..." }; |
|||
static readonly string[] k_BakeButtonsText = { "Bake All Reflection Probes" }; |
|||
|
|||
public static void DrawBakeButton(ReflectionProbeMode reflectionProbeMode, ReflectionProbe probe) |
|||
{ |
|||
DrawBakeButton(reflectionProbeMode, probe, null); |
|||
} |
|||
|
|||
public static void DrawBakeButton(ReflectionProbeMode reflectionProbeMode, PlanarReflectionProbe probe) |
|||
{ |
|||
DrawBakeButton(reflectionProbeMode, null, probe); |
|||
} |
|||
|
|||
static void DrawBakeButton(ReflectionProbeMode reflectionProbeMode, ReflectionProbe probe, PlanarReflectionProbe planarProbe) |
|||
{ |
|||
if (reflectionProbeMode == ReflectionProbeMode.Realtime) |
|||
{ |
|||
EditorGUILayout.HelpBox("Refresh 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 (reflectionProbeMode == 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) |
|||
{ |
|||
case ReflectionProbeMode.Custom: |
|||
{ |
|||
if (ButtonWithDropdownList( |
|||
_.GetContent("Bake|Bakes Reflection Probe's cubemap, overwriting the existing cubemap texture asset (if any)."), k_BakeCustomOptionText, |
|||
data => |
|||
{ |
|||
var mode = (int)data; |
|||
|
|||
if (mode == 0) |
|||
{ |
|||
if (probe != null) |
|||
{ |
|||
EditorReflectionSystem.BakeCustomReflectionProbe(probe, false, true); |
|||
EditorReflectionSystem.ResetProbeSceneTextureInMaterial(probe); |
|||
} |
|||
if (planarProbe != null) |
|||
{ |
|||
EditorReflectionSystem.BakeCustomReflectionProbe(planarProbe, false, true); |
|||
EditorReflectionSystem.ResetProbeSceneTextureInMaterial(planarProbe); |
|||
} |
|||
} |
|||
}, |
|||
GUILayout.ExpandWidth(true))) |
|||
{ |
|||
if (probe != null) |
|||
{ |
|||
EditorReflectionSystem.BakeCustomReflectionProbe(probe, true, true); |
|||
EditorReflectionSystem.ResetProbeSceneTextureInMaterial(probe); |
|||
} |
|||
if (planarProbe != null) |
|||
{ |
|||
EditorReflectionSystem.BakeCustomReflectionProbe(planarProbe, true, true); |
|||
EditorReflectionSystem.ResetProbeSceneTextureInMaterial(planarProbe); |
|||
} |
|||
GUIUtility.ExitGUI(); |
|||
} |
|||
break; |
|||
} |
|||
|
|||
case ReflectionProbeMode.Baked: |
|||
{ |
|||
GUI.enabled = probe != null && probe.enabled |
|||
|| planarProbe != null && planarProbe.enabled; |
|||
|
|||
// Bake button in non-continous mode
|
|||
if (ButtonWithDropdownList( |
|||
_.GetContent("Bake"), |
|||
k_BakeButtonsText, |
|||
data => |
|||
{ |
|||
var mode = (int)data; |
|||
if (mode == 0) |
|||
EditorReflectionSystem.BakeAllReflectionProbesSnapshots(); |
|||
}, |
|||
GUILayout.ExpandWidth(true))) |
|||
{ |
|||
if (probe != null) |
|||
{ |
|||
EditorReflectionSystem.BakeReflectionProbeSnapshot(probe); |
|||
EditorReflectionSystem.ResetProbeSceneTextureInMaterial(probe); |
|||
} |
|||
if (planarProbe != null) |
|||
{ |
|||
EditorReflectionSystem.BakeReflectionProbeSnapshot(planarProbe); |
|||
EditorReflectionSystem.ResetProbeSceneTextureInMaterial(planarProbe); |
|||
} |
|||
GUIUtility.ExitGUI(); |
|||
} |
|||
|
|||
GUI.enabled = true; |
|||
break; |
|||
} |
|||
|
|||
case ReflectionProbeMode.Realtime: |
|||
|
|||
// Not showing bake button in realtime
|
|||
break; |
|||
} |
|||
GUILayout.FlexibleSpace(); |
|||
EditorGUILayout.EndHorizontal(); |
|||
} |
|||
|
|||
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: fb27d019fde27554a896566dad3d488b |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue