Migrate native flight environment contract
This commit is contained in:
parent
3d36fe5da4
commit
94d3a7ba84
16 changed files with 260 additions and 47 deletions
|
|
@ -3,13 +3,16 @@ using System.IO;
|
|||
using System.Text;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
[InitializeOnLoad]
|
||||
public static class AetheriaRenderProbe
|
||||
{
|
||||
private const string RelativeOutputDirectory = "Temp/AetheriaRenderProbe";
|
||||
private const string RelativeOutputDirectory = "Library/AetheriaRenderProbe";
|
||||
private const string ReferenceCaptureSessionKey = "AetheriaRenderProbe.CaptureArpgReference";
|
||||
private const string ReferenceCaptureDeadlineSessionKey = "AetheriaRenderProbe.CaptureArpgReference.Deadline";
|
||||
|
||||
private static string ProjectRoot =>
|
||||
Path.GetFullPath(Path.Combine(Application.dataPath, ".."));
|
||||
|
|
@ -23,6 +26,7 @@ public static class AetheriaRenderProbe
|
|||
static AetheriaRenderProbe()
|
||||
{
|
||||
EditorApplication.update += Poll;
|
||||
EditorApplication.update += CaptureArpgWhenReady;
|
||||
}
|
||||
|
||||
private static void Poll()
|
||||
|
|
@ -72,6 +76,9 @@ public static class AetheriaRenderProbe
|
|||
if (camera != null)
|
||||
VolumeSampling.RenderForCamera(camera);
|
||||
|
||||
if (camera != null)
|
||||
DumpCamera(camera, summary);
|
||||
|
||||
DumpVolumeSamplers(summary);
|
||||
DumpVolumeCloudRenderers(camera, summary);
|
||||
DumpGlobalTexture(summary, "_NebulaSurfaceHeight", "nebula-surface-height.png");
|
||||
|
|
@ -80,14 +87,63 @@ public static class AetheriaRenderProbe
|
|||
DumpGlobalTexture(summary, "_NebulaTint", "nebula-tint.png");
|
||||
DumpGlobalTexture(summary, "_AetheriaGravityHeight", "gravity-height.png");
|
||||
|
||||
if (camera != null)
|
||||
DumpCamera(camera, summary);
|
||||
|
||||
File.WriteAllText(Path.Combine(OutputDirectory, "summary.txt"), summary.ToString());
|
||||
AssetDatabase.Refresh();
|
||||
Debug.Log($"Aetheria render probe wrote {Path.GetFullPath(OutputDirectory)}");
|
||||
}
|
||||
|
||||
public static void CaptureArpgReference()
|
||||
{
|
||||
EditorSceneManager.OpenScene("Assets/Scenes/ARPG.unity", OpenSceneMode.Single);
|
||||
AetheriaUrpBootstrap.EnsureUrpAssetsAndAssign();
|
||||
SessionState.SetBool(ReferenceCaptureSessionKey, true);
|
||||
SessionState.SetString(
|
||||
ReferenceCaptureDeadlineSessionKey,
|
||||
(EditorApplication.timeSinceStartup + 15.0).ToString("R", System.Globalization.CultureInfo.InvariantCulture));
|
||||
EditorApplication.EnterPlaymode();
|
||||
}
|
||||
|
||||
private static void CaptureArpgWhenReady()
|
||||
{
|
||||
if (!SessionState.GetBool(ReferenceCaptureSessionKey, false))
|
||||
return;
|
||||
if (!EditorApplication.isPlaying || EditorApplication.isCompiling)
|
||||
return;
|
||||
|
||||
var rendered = false;
|
||||
foreach (var renderer in Resources.FindObjectsOfTypeAll<VolumeCloudRenderer>())
|
||||
{
|
||||
if (renderer != null && renderer.gameObject.scene.IsValid() && renderer.DebugRenderCount > 0)
|
||||
{
|
||||
rendered = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var deadlineText = SessionState.GetString(ReferenceCaptureDeadlineSessionKey, "0");
|
||||
double.TryParse(
|
||||
deadlineText,
|
||||
System.Globalization.NumberStyles.Float,
|
||||
System.Globalization.CultureInfo.InvariantCulture,
|
||||
out var deadline);
|
||||
if (!rendered && EditorApplication.timeSinceStartup < deadline)
|
||||
return;
|
||||
|
||||
SessionState.SetBool(ReferenceCaptureSessionKey, false);
|
||||
try
|
||||
{
|
||||
Capture();
|
||||
EditorApplication.Exit(0);
|
||||
}
|
||||
catch (Exception error)
|
||||
{
|
||||
Directory.CreateDirectory(OutputDirectory);
|
||||
File.WriteAllText(Path.Combine(OutputDirectory, "error.txt"), error.ToString());
|
||||
Debug.LogException(error);
|
||||
EditorApplication.Exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
private static Camera ResolveCamera()
|
||||
{
|
||||
if (Camera.main != null)
|
||||
|
|
@ -155,15 +211,16 @@ public static class AetheriaRenderProbe
|
|||
|
||||
summary.AppendLine($"- {sampler.name} enabled={sampler.enabled} active={sampler.gameObject.activeInHierarchy}");
|
||||
summary.AppendLine($" GridCamera={NameOf(sampler.GridCamera)} GridMesh={NameOf(sampler.GridMesh)}");
|
||||
summary.AppendLine($" SceneSplatSource={NameOf(sampler.SceneSplatSource)} SplatLayerRenderer={NameOf(sampler.SplatLayerRenderer)}");
|
||||
summary.AppendLine($" SplatLayerRenderer={NameOf(sampler.SplatLayerRenderer)}");
|
||||
summary.AppendLine($" Surface={TextureFacts(sampler.NebulaSurfaceHeight)}");
|
||||
summary.AppendLine($" PatchHeight={TextureFacts(sampler.NebulaPatchHeight)}");
|
||||
summary.AppendLine($" Patch={TextureFacts(sampler.NebulaPatch)}");
|
||||
summary.AppendLine($" Tint={TextureFacts(sampler.NebulaTint)}");
|
||||
DumpSamplerEnvironment(sampler, summary);
|
||||
|
||||
if (sampler.SceneSplatSource != null)
|
||||
DumpSceneSplatDocument(sampler, summary);
|
||||
SaveTextureExr(sampler.NebulaSurfaceHeight, Path.Combine(OutputDirectory, "fossil-nebula-surface-height.exr"));
|
||||
SaveTextureExr(sampler.NebulaPatchHeight, Path.Combine(OutputDirectory, "fossil-nebula-patch-height.exr"));
|
||||
SaveTextureExr(sampler.NebulaPatch, Path.Combine(OutputDirectory, "fossil-nebula-patch.exr"));
|
||||
SaveTextureExr(sampler.NebulaTint, Path.Combine(OutputDirectory, "fossil-nebula-tint.exr"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -194,27 +251,6 @@ public static class AetheriaRenderProbe
|
|||
$" Grid Enabled={environment.Grid.Enabled} Offset={environment.Grid.Offset}");
|
||||
}
|
||||
|
||||
private static void DumpSceneSplatDocument(VolumeSampling sampler, StringBuilder summary)
|
||||
{
|
||||
var size = sampler.GridCamera != null
|
||||
? new Vector2(sampler.GridCamera.orthographicSize * 2f, sampler.GridCamera.orthographicSize * 2f)
|
||||
: new Vector2(1024f, 1024f);
|
||||
var centerTransform = sampler.GridCamera != null ? sampler.GridCamera.transform : sampler.transform;
|
||||
var center = centerTransform != null
|
||||
? new Vector2(centerTransform.position.x, centerTransform.position.z)
|
||||
: Vector2.zero;
|
||||
var half = size * 0.5f;
|
||||
var document = sampler.SceneSplatSource.BuildDocument(new AetheriaRuntimeViewportBounds
|
||||
{
|
||||
MinX = center.x - half.x,
|
||||
MinY = center.y - half.y,
|
||||
MaxX = center.x + half.x,
|
||||
MaxY = center.y + half.y
|
||||
});
|
||||
|
||||
summary.AppendLine($" SceneDocument layers={document.Layers?.Count ?? 0} splats={document.Splats?.Count ?? 0}");
|
||||
}
|
||||
|
||||
private static void DumpGlobalTexture(StringBuilder summary, string globalName, string fileName)
|
||||
{
|
||||
var texture = Shader.GetGlobalTexture(globalName);
|
||||
|
|
@ -263,6 +299,37 @@ public static class AetheriaRenderProbe
|
|||
}
|
||||
}
|
||||
|
||||
private static void SaveTextureExr(Texture texture, string path)
|
||||
{
|
||||
if (texture == null)
|
||||
return;
|
||||
var width = Mathf.Max(1, texture.width);
|
||||
var height = Mathf.Max(1, texture.height);
|
||||
var target = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.ARGBFloat);
|
||||
var previous = RenderTexture.active;
|
||||
try
|
||||
{
|
||||
Graphics.Blit(texture, target);
|
||||
RenderTexture.active = target;
|
||||
var image = new Texture2D(width, height, TextureFormat.RGBAFloat, false, true);
|
||||
try
|
||||
{
|
||||
image.ReadPixels(new Rect(0, 0, width, height), 0, 0);
|
||||
image.Apply();
|
||||
File.WriteAllBytes(path, image.EncodeToEXR(Texture2D.EXRFlags.OutputAsFloat));
|
||||
}
|
||||
finally
|
||||
{
|
||||
UnityEngine.Object.DestroyImmediate(image);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
RenderTexture.active = previous;
|
||||
RenderTexture.ReleaseTemporary(target);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SaveRenderTexture(RenderTexture target, string path)
|
||||
{
|
||||
var previous = RenderTexture.active;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ namespace Aetheria.Editor
|
|||
private static void Build(BuildTarget target)
|
||||
{
|
||||
EveThermalProfileMigrator.EnsureGenerated();
|
||||
EveEnvironmentProfileMigrator.EnsureGenerated();
|
||||
var output = ResolveOutput(target);
|
||||
Directory.CreateDirectory(output);
|
||||
|
||||
|
|
@ -529,6 +530,9 @@ namespace Aetheria.Editor
|
|||
var reflection = LoadAuthoredAsset<Cubemap>(bundle, assetNames, "Assets/Textures/studio2.hdr");
|
||||
if (reflection == null)
|
||||
throw new InvalidOperationException("Aetheria Eve bundle has no provider reflection cubemap.");
|
||||
var postProcess = LoadAuthoredAsset<VolumeProfile>(bundle, assetNames, EveEnvironmentProfileMigrator.FlightProfilePath);
|
||||
if (postProcess == null)
|
||||
throw new InvalidOperationException("Aetheria Eve bundle has no provider flight post-process profile.");
|
||||
var gravityFog = LoadAuthoredAsset<Shader>(bundle, assetNames, "Assets/Shaders/Raymarching/CloudShader.shader");
|
||||
if (gravityFog == null || !gravityFog.isSupported)
|
||||
throw new InvalidOperationException("Aetheria Eve bundle has no supported gravity-fog volume shader.");
|
||||
|
|
|
|||
50
Assets/Editor/EveEnvironmentProfileMigrator.cs
Normal file
50
Assets/Editor/EveEnvironmentProfileMigrator.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.Universal;
|
||||
|
||||
namespace Aetheria.Editor
|
||||
{
|
||||
public static class EveEnvironmentProfileMigrator
|
||||
{
|
||||
public const string Root = "Assets/Generated/Eve/Environment";
|
||||
public const string FlightProfilePath = Root + "/Flight.asset";
|
||||
|
||||
public static void EnsureGenerated()
|
||||
{
|
||||
Directory.CreateDirectory(Root);
|
||||
AssetDatabase.DeleteAsset(FlightProfilePath);
|
||||
var profile = ScriptableObject.CreateInstance<VolumeProfile>();
|
||||
profile.name = "Aetheria Flight";
|
||||
AssetDatabase.CreateAsset(profile, FlightProfilePath);
|
||||
|
||||
var tonemapping = profile.Add<Tonemapping>(true);
|
||||
tonemapping.mode.Override(TonemappingMode.ACES);
|
||||
|
||||
var color = profile.Add<ColorAdjustments>(true);
|
||||
// The fossil histogram exposure clamps average luminance to 2^-3 and
|
||||
// uses a 0.5 middle-grey key. At that dark-scene bound the resulting
|
||||
// exposure is 4x, which is the fixed URP equivalent available here.
|
||||
color.postExposure.Override(2f);
|
||||
color.contrast.Override(15f);
|
||||
|
||||
var bloom = profile.Add<Bloom>(true);
|
||||
bloom.intensity.Override(3f);
|
||||
bloom.threshold.Override(1.5f);
|
||||
bloom.scatter.Override(1f);
|
||||
|
||||
var vignette = profile.Add<Vignette>(true);
|
||||
vignette.intensity.Override(0.3f);
|
||||
vignette.smoothness.Override(0.4f);
|
||||
|
||||
var grain = profile.Add<FilmGrain>(true);
|
||||
grain.type.Override(FilmGrainLookup.Thin1);
|
||||
grain.intensity.Override(0.1f);
|
||||
|
||||
EditorUtility.SetDirty(profile);
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Assets/Editor/EveEnvironmentProfileMigrator.cs.meta
Normal file
2
Assets/Editor/EveEnvironmentProfileMigrator.cs.meta
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2fc598800cd0521408627e17b566c973
|
||||
|
|
@ -719,12 +719,17 @@ public class DaemonRuntimeDocumentTests
|
|||
asset.Ref.AssetKey == "shader.environment.gravity-fog" &&
|
||||
asset.Ref.Kind == AetheriaRuntimeAssetKinds.Shader &&
|
||||
asset.Ref.Metadata["unity.volume.texturePort.surfaceHeight"] == "_NebulaSurfaceHeight" &&
|
||||
asset.Ref.Metadata["unity.volume.matrixPort.cameraToWorld"] == "_CamToWorld" &&
|
||||
asset.Ref.Metadata["unity.volume.pass.temporal"] == "1" &&
|
||||
asset.Ref.Metadata["unity.volume.texturePort.currentSample"] == "_UndersampleCloudTex" &&
|
||||
asset.Ref.Metadata["unity.volume.texturePort.history"] == "_MainTex"));
|
||||
Assert.IsTrue(assetManifest.Assets.Any(asset =>
|
||||
asset.Ref.AssetKey == "texture.environment.volume-dither" &&
|
||||
asset.Ref.Kind == AetheriaRuntimeAssetKinds.Texture));
|
||||
Assert.IsTrue(assetManifest.Assets.Any(asset =>
|
||||
asset.Ref.AssetKey == "profile.environment.flight" &&
|
||||
asset.Ref.Kind == AetheriaRuntimeAssetKinds.VolumeProfile &&
|
||||
asset.Ref.Metadata["presentationRole"] == "environment.post-process.flight"));
|
||||
var editorTuiSurface = result.EditorTuiSurface;
|
||||
Assert.AreEqual("aetheria.daemon", editorTuiSurface.ProviderId);
|
||||
Assert.AreEqual("editor.daemon", editorTuiSurface.ProviderKind);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ Shader "Aetheria/CloudShader"
|
|||
[HideInInspector] _NebulaPatch("NebulaPatch", 2D) = "black" {}
|
||||
[HideInInspector] _NebulaTint("NebulaTint", 2D) = "black" {}
|
||||
[HideInInspector] _CloudTex("CloudTex", 2D) = "black" {}
|
||||
[HideInInspector] _UndersampleCloudTex("UndersampleCloudTex", 2D) = "black" {}
|
||||
[HideInInspector] _CompositeOpacity("CompositeOpacity", Range(0, 1)) = 1
|
||||
}
|
||||
|
||||
|
|
@ -49,6 +50,7 @@ Shader "Aetheria/CloudShader"
|
|||
sampler2D _DitheringTex;
|
||||
float4 _DitheringCoords;
|
||||
uniform float4x4 _CamInvProj;
|
||||
uniform float4x4 _CamToWorld;
|
||||
|
||||
float _ExtinctionCoefficient;
|
||||
|
||||
|
|
@ -164,7 +166,7 @@ Shader "Aetheria/CloudShader"
|
|||
float4 frag (Interpolator i) : SV_Target
|
||||
{
|
||||
float3 vspos = float3(i.vsray, 1.0);
|
||||
float4 worldPos = mul(unity_CameraToWorld,float4(vspos,1.0));
|
||||
float4 worldPos = mul(_CamToWorld,float4(vspos,1.0));
|
||||
worldPos /= worldPos.w;
|
||||
float2 screenUV = i.screenPos.xy / i.screenPos.w;
|
||||
float depthSample = tex2D(_CameraDepthTexture, screenUV).r;
|
||||
|
|
@ -205,6 +207,7 @@ Shader "Aetheria/CloudShader"
|
|||
float4 _UndersampleCloudTex_TexelSize;
|
||||
|
||||
float4x4 _PrevVP; //View projection matrix of last frame. Used to temporal reprojection.
|
||||
float4x4 _CamToWorld;
|
||||
float _ResetHistory;
|
||||
|
||||
//These values are needed for doing extra raymarch when out of bound.
|
||||
|
|
@ -279,7 +282,7 @@ Shader "Aetheria/CloudShader"
|
|||
|
||||
half outOfBound;
|
||||
float3 previousWorldPosition = mul(
|
||||
unity_CameraToWorld,
|
||||
_CamToWorld,
|
||||
float4(normalize(vspos) * distance, 1.0f)).xyz;
|
||||
float2 prevUV = PrevUV(float4(previousWorldPosition, 1.0f), outOfBound);
|
||||
float4 prevSample = tex2D(_MainTex, prevUV);
|
||||
|
|
|
|||
Loading…
Reference in a new issue