Frédéric Vauchelles
7 年前
当前提交
4d0d4da6
共有 10 个文件被更改,包括 617 次插入 和 556 次删除
-
144SampleScenes/HDTest/ReflectionProbeTest.unity
-
8ScriptableRenderPipeline/Core/CoreRP/Editor/CoreEditorUtils.cs
-
716ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/EditorReflectionSystem.cs
-
5ScriptableRenderPipeline/HDRenderPipeline/HDRP/Lighting/Reflection/HDAdditionalReflectionData.cs
-
104ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/BakeReflectionProbesJob.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/BakeReflectionProbesJob.cs.meta
-
40ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/EditorHDLightingDataAsset.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/EditorHDLightingDataAsset.cs.meta
-
123ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/ReflectionProbeCustomBakingIntegration.cs
-
11ScriptableRenderPipeline/HDRenderPipeline/HDRP/Editor/Lighting/Reflection/ReflectionProbeCustomBakingIntegration.cs.meta
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
class ReflectionBakeJob : IDisposable |
|||
{ |
|||
enum Stage |
|||
{ |
|||
BakeReflectionProbe, |
|||
BakePlanarProbe, |
|||
Completed |
|||
} |
|||
|
|||
delegate void BakingStage(ReflectionBakeJob job); |
|||
|
|||
static readonly BakingStage[] s_Stages = |
|||
{ |
|||
StageBakeReflectionProbe, |
|||
StageBakePlanarProbe, |
|||
}; |
|||
|
|||
Stage m_CurrentStage = Stage.BakeReflectionProbe; |
|||
int m_StageIndex; |
|||
|
|||
public bool isComplete { get { return m_CurrentStage == Stage.Completed; } } |
|||
public BakeReflectionProbeRequest request; |
|||
public List<ReflectionProbe> reflectionProbesToBake = new List<ReflectionProbe>(); |
|||
public List<PlanarReflectionProbe> planarReflectionProbesToBake = new List<PlanarReflectionProbe>(); |
|||
|
|||
public ReflectionBakeJob(BakeReflectionProbeRequest request) |
|||
{ |
|||
this.request = request; |
|||
} |
|||
|
|||
public void Tick() |
|||
{ |
|||
if (m_StageIndex == -1 && m_CurrentStage != Stage.Completed) |
|||
{ |
|||
m_CurrentStage = (Stage)((int)m_CurrentStage + 1); |
|||
m_StageIndex = 0; |
|||
} |
|||
|
|||
if (m_CurrentStage == Stage.Completed) |
|||
{ |
|||
request.Progress = 1; |
|||
return; |
|||
} |
|||
|
|||
s_Stages[(int)m_CurrentStage](this); |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
request.Progress = 1; |
|||
m_CurrentStage = Stage.Completed; |
|||
m_StageIndex = 0; |
|||
} |
|||
|
|||
static void StageBakeReflectionProbe(ReflectionBakeJob job) |
|||
{ |
|||
if (job.m_StageIndex >= job.reflectionProbesToBake.Count) |
|||
{ |
|||
job.m_StageIndex = -1; |
|||
return; |
|||
} |
|||
|
|||
// 1. Setup stage information
|
|||
var stageProgress = job.reflectionProbesToBake.Count > 0 |
|||
? 1f - job.m_StageIndex / (float)job.reflectionProbesToBake.Count |
|||
: 1f; |
|||
|
|||
job.request.Progress = ((float)Stage.BakeReflectionProbe + stageProgress) / (float)Stage.Completed; |
|||
job.request.ProgressMessage = string.Format("Reflection Probes ({0}/{1})", job.m_StageIndex + 1, job.reflectionProbesToBake.Count); |
|||
|
|||
EditorReflectionSystem.BakeReflectionProbeSnapshot(job.reflectionProbesToBake[job.m_StageIndex]); |
|||
|
|||
++job.m_StageIndex; |
|||
} |
|||
|
|||
static void StageBakePlanarProbe(ReflectionBakeJob job) |
|||
{ |
|||
if (job.m_StageIndex >= job.planarReflectionProbesToBake.Count) |
|||
{ |
|||
job.m_StageIndex = -1; |
|||
return; |
|||
} |
|||
|
|||
// 1. Setup stage information
|
|||
var stageProgress = job.planarReflectionProbesToBake.Count > 0 |
|||
? 1f - job.m_StageIndex / (float)job.planarReflectionProbesToBake.Count |
|||
: 1f; |
|||
|
|||
job.request.Progress = ((float)Stage.BakePlanarProbe + stageProgress) / (float)Stage.Completed; |
|||
job.request.ProgressMessage = string.Format("Reflection Probes ({0}/{1})", job.m_StageIndex + 1, job.planarReflectionProbesToBake.Count); |
|||
|
|||
EditorReflectionSystem.BakeReflectionProbeSnapshot(job.planarReflectionProbesToBake[job.m_StageIndex]); |
|||
|
|||
++job.m_StageIndex; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: bad5b9c08ef04724fbcaa1e144127d3f |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.IO; |
|||
using UnityEngine; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
using UnityEngine.SceneManagement; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
public static class EditorHDLightingDataAsset |
|||
{ |
|||
public static HDLightingDataAsset GetLightingDataAssetForScene(Scene scene) |
|||
{ |
|||
var filePath = GetLightingDataAssetPathForScene(scene); |
|||
var asset = AssetDatabase.LoadAssetAtPath<HDLightingDataAsset>(filePath); |
|||
return asset; |
|||
} |
|||
|
|||
public static HDLightingDataAsset GetOrCreateLightingDataAssetForScene(Scene scene) |
|||
{ |
|||
var filePath = GetLightingDataAssetPathForScene(scene); |
|||
var filePathInfo = new FileInfo(filePath); |
|||
if (!filePathInfo.Directory.Exists) |
|||
filePathInfo.Directory.Create(); |
|||
|
|||
var asset = AssetDatabase.LoadAssetAtPath<HDLightingDataAsset>(filePath); |
|||
if (asset == null) |
|||
{ |
|||
asset = ScriptableObject.CreateInstance<HDLightingDataAsset>(); |
|||
AssetDatabase.CreateAsset(asset, filePath); |
|||
} |
|||
|
|||
return asset; |
|||
} |
|||
|
|||
static string GetLightingDataAssetPathForScene(Scene scene) |
|||
{ |
|||
var parentFolder = Path.GetFileNameWithoutExtension(scene.path); |
|||
return Path.Combine(Path.GetDirectoryName(scene.path), Path.Combine(parentFolder, "HDLightingData.asset")); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c930b5a4c3d4d884aa99ba287cf4cd91 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using UnityEditor.SceneManagement; |
|||
using UnityEngine; |
|||
using UnityEngine.Assertions; |
|||
using UnityEngine.Experimental.Rendering; |
|||
using UnityEngine.Experimental.Rendering.HDPipeline; |
|||
using UnityEngine.Rendering; |
|||
using UnityEngine.SceneManagement; |
|||
|
|||
namespace UnityEditor.Experimental.Rendering.HDPipeline |
|||
{ |
|||
static class ReflectionProbeCustomBakingIntegration |
|||
{ |
|||
static ReflectionBakeJob s_CurrentBakeJob = null; |
|||
|
|||
[InitializeOnLoadMethod] |
|||
static void Initialize() |
|||
{ |
|||
GraphicsSettings.useBuiltinReflectionProbeSystem = false; |
|||
Lightmapping.BakeReflectionProbeRequest += LightmappingOnBakeReflectionProbeRequest; |
|||
Lightmapping.ClearBakedReflectionProbeRequest += LightmappingOnClearBakedReflectionProbeRequest; |
|||
EditorSceneManager.sceneOpened += EditorSceneManagerOnSceneOpened; |
|||
EditorApplication.update += Update; |
|||
} |
|||
|
|||
static void EditorSceneManagerOnSceneOpened(Scene scene, OpenSceneMode mode) |
|||
{ |
|||
var asset = EditorHDLightingDataAsset.GetLightingDataAssetForScene(scene); |
|||
if (asset == null) |
|||
return; |
|||
|
|||
var roots = scene.GetRootGameObjects(); |
|||
var probes = new List<ReflectionProbe>(); |
|||
for (var i = 0; i < roots.Length; i++) |
|||
{ |
|||
var root = roots[i]; |
|||
root.GetComponentsInChildren(probes); |
|||
for (var j = 0; j < probes.Count; j++) |
|||
{ |
|||
var probe = probes[j]; |
|||
var id = SceneObjectIdentifierUtils.GetSceneObjectIdentifierFor(probe); |
|||
if (id == SceneObjectIdentifier.Invalid) |
|||
continue; |
|||
var bakedTexture = asset.GetBakedTextureFor(id); |
|||
if (bakedTexture == null) |
|||
continue; |
|||
probe.bakedTexture = bakedTexture; |
|||
} |
|||
} |
|||
} |
|||
|
|||
static void LightmappingOnClearBakedReflectionProbeRequest() |
|||
{ |
|||
for (int i = 0, c = SceneManager.sceneCount; i < c; ++i) |
|||
{ |
|||
var scene = SceneManager.GetSceneAt(i); |
|||
if (!scene.IsValid() || !scene.isLoaded) |
|||
continue; |
|||
|
|||
var asset = EditorHDLightingDataAsset.GetLightingDataAssetForScene(scene); |
|||
if (asset == null) |
|||
continue; |
|||
|
|||
asset.DeleteAssets(); |
|||
|
|||
var path = AssetDatabase.GetAssetPath(asset); |
|||
Assert.IsFalse(string.IsNullOrEmpty(path)); |
|||
|
|||
AssetDatabase.DeleteAsset(path); |
|||
} |
|||
} |
|||
|
|||
static void Update() |
|||
{ |
|||
if (s_CurrentBakeJob != null) |
|||
{ |
|||
s_CurrentBakeJob.Tick(); |
|||
if (s_CurrentBakeJob.isComplete) |
|||
{ |
|||
s_CurrentBakeJob.Dispose(); |
|||
s_CurrentBakeJob = null; |
|||
} |
|||
} |
|||
} |
|||
|
|||
static void LightmappingOnBakeReflectionProbeRequest(BakeReflectionProbeRequest request) |
|||
{ |
|||
if (request.IsCompleted) |
|||
return; |
|||
|
|||
// Custom probe hashes should be handled here by the user
|
|||
// var customProbeHash = CalculateCustomProbeHashes()
|
|||
// dependencyHash = CombineHashes(dependencyHash, customProbeHash);
|
|||
|
|||
// Currently only one bounce is handled
|
|||
// TODO: Use UnityEngine.RenderSettings.reflectionBounces and handle bounces
|
|||
|
|||
if (s_CurrentBakeJob != null) |
|||
{ |
|||
s_CurrentBakeJob.Dispose(); |
|||
s_CurrentBakeJob = null; |
|||
} |
|||
|
|||
var job = new ReflectionBakeJob(request); |
|||
ReflectionSystem.QueryReflectionProbes(job.reflectionProbesToBake, mode: ReflectionProbeMode.Baked); |
|||
ReflectionSystem.QueryPlanarProbes(job.planarReflectionProbesToBake, mode: ReflectionProbeMode.Baked); |
|||
s_CurrentBakeJob = job; |
|||
|
|||
request.Cancelled += LightmappingOnBakeReflectionProbeRequestCancelled; |
|||
} |
|||
|
|||
static void LightmappingOnBakeReflectionProbeRequestCancelled(BakeReflectionProbeRequest request) |
|||
{ |
|||
Debug.Log("Cancel: " + request.RequestHash); |
|||
request.Cancelled -= LightmappingOnBakeReflectionProbeRequestCancelled; |
|||
if (s_CurrentBakeJob != null && s_CurrentBakeJob.request == request) |
|||
{ |
|||
s_CurrentBakeJob.Dispose(); |
|||
s_CurrentBakeJob = null; |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 853f88d9c68e9b5419b7c03a685d9de9 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue