Unify field grid and temporal camera lowering
This commit is contained in:
parent
8db5ceeac4
commit
8fb39a1e57
10 changed files with 384 additions and 133 deletions
|
|
@ -40,6 +40,13 @@ presentation counters, and receipt display state are projections. They are not
|
|||
world truth. Temporal targets reset when the volume program, node, or render size
|
||||
changes and can never become provider state.
|
||||
|
||||
Camera-relative field viewports have one generic resolver. The advertised
|
||||
viewport frame owns its extent, spatial-cell scale, raster texels per cell, and
|
||||
snap policy; fog volumes and stateless particle programs consume the identical
|
||||
projected `EveFieldsViewport`. URP TAA state is likewise derived from the
|
||||
world's neutral `temporal-reprojection.v1` camera contract and is restored on
|
||||
release.
|
||||
|
||||
## Forbidden Writers
|
||||
|
||||
Unity transforms, input drivers, camera rigs, scene sinks, asset caches, and
|
||||
|
|
|
|||
|
|
@ -72,6 +72,16 @@ out of Eve's semantic surface while allowing a provider-owned shader to consume
|
|||
portable Eve Fields documents. Volume composition runs as a generic URP render
|
||||
pass before post-processing so the provider-advertised profile grades both the
|
||||
native scene and the provider volume through the same camera pipeline.
|
||||
|
||||
Camera-relative field consumers share `viewportAnchor`, `span`,
|
||||
`cellWorldSize`, `viewportSnapLayer`, and `viewportSnapTexels` as one viewport
|
||||
frame contract. Volume and particle lowerers resolve that frame through the
|
||||
same generic path, so a snapped stateless particle lattice cannot drift from
|
||||
the field textures it samples. A `world.scene3d` may also request
|
||||
`temporal-reprojection.v1`; EveUnity lowers its neutral history blend, jitter,
|
||||
quality, and sharpening values to URP TAA and restores the previous camera
|
||||
state when the world releases the camera.
|
||||
|
||||
Providers may advertise per-layer resolution scales, mipmap use, and filtering
|
||||
through `layerTargetDescriptors`; the Unity lowerer applies those native target
|
||||
requirements without assigning gameplay or product meaning to the layer keys.
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ namespace GameCult.Eve.UnityScene
|
|||
private UniversalAdditionalCameraData? _postProcessCameraData;
|
||||
private bool _createdPostProcessCameraData;
|
||||
private bool _previousRenderPostProcessing;
|
||||
private AntialiasingMode _previousAntialiasing;
|
||||
private TemporalAA.Settings _previousTaaSettings;
|
||||
|
||||
public EveUnityPlayableWorldClientHost? Host
|
||||
{
|
||||
|
|
@ -307,7 +309,17 @@ namespace GameCult.Eve.UnityScene
|
|||
!IsFinite(world.KeyLightColorR) ||
|
||||
!IsFinite(world.KeyLightColorG) ||
|
||||
!IsFinite(world.KeyLightColorB) ||
|
||||
!IsFinite(world.KeyLightIntensity))
|
||||
!IsFinite(world.KeyLightIntensity) ||
|
||||
!IsFinite(world.TemporalHistoryBlend) ||
|
||||
!IsFinite(world.TemporalJitterScale) ||
|
||||
!IsFinite(world.TemporalSharpening) ||
|
||||
(!string.IsNullOrWhiteSpace(world.CameraReconstruction) &&
|
||||
!string.Equals(world.CameraReconstruction, "temporal-reprojection.v1", System.StringComparison.Ordinal)) ||
|
||||
(string.Equals(world.CameraReconstruction, "temporal-reprojection.v1", System.StringComparison.Ordinal) &&
|
||||
(world.TemporalHistoryBlend < 0f || world.TemporalHistoryBlend > 1f ||
|
||||
world.TemporalJitterScale < 0f || world.TemporalJitterScale > 1f ||
|
||||
world.TemporalSharpening < 0f || world.TemporalSharpening > 1f ||
|
||||
!IsTemporalQuality(world.TemporalQuality))))
|
||||
return false;
|
||||
var assets = host.NativeAssetProvider;
|
||||
if (!string.IsNullOrWhiteSpace(world.SkyboxAssetRef))
|
||||
|
|
@ -453,12 +465,19 @@ namespace GameCult.Eve.UnityScene
|
|||
}
|
||||
if (environmentChanged)
|
||||
DynamicGI.UpdateEnvironment();
|
||||
ApplyPostProcess(camera, postProcessProfile);
|
||||
ApplyCameraRendering(camera, postProcessProfile, world);
|
||||
}
|
||||
|
||||
private void ApplyPostProcess(Camera? camera, VolumeProfile? profile)
|
||||
private void ApplyCameraRendering(
|
||||
Camera? camera,
|
||||
VolumeProfile? profile,
|
||||
EveUnityPlayableWorldProjection world)
|
||||
{
|
||||
if (profile == null)
|
||||
var usesTemporalReprojection = string.Equals(
|
||||
world.CameraReconstruction,
|
||||
"temporal-reprojection.v1",
|
||||
System.StringComparison.Ordinal);
|
||||
if (profile == null && !usesTemporalReprojection)
|
||||
{
|
||||
RestorePostProcess();
|
||||
return;
|
||||
|
|
@ -474,19 +493,59 @@ namespace GameCult.Eve.UnityScene
|
|||
if (_postProcessCameraData == null)
|
||||
_postProcessCameraData = camera.gameObject.AddComponent<UniversalAdditionalCameraData>();
|
||||
_previousRenderPostProcessing = _postProcessCameraData.renderPostProcessing;
|
||||
_previousAntialiasing = _postProcessCameraData.antialiasing;
|
||||
_previousTaaSettings = _postProcessCameraData.taaSettings;
|
||||
}
|
||||
_postProcessCameraData.renderPostProcessing = true;
|
||||
if (_postProcessVolumeObject == null)
|
||||
_postProcessCameraData.renderPostProcessing = profile != null || _previousRenderPostProcessing;
|
||||
if (usesTemporalReprojection)
|
||||
{
|
||||
_postProcessVolumeObject = new GameObject("Eve World Post Process");
|
||||
_postProcessVolumeObject.transform.SetParent(transform, worldPositionStays: false);
|
||||
_postProcessVolume = _postProcessVolumeObject.AddComponent<Volume>();
|
||||
_postProcessVolume.isGlobal = true;
|
||||
_postProcessVolume.priority = 1000f;
|
||||
_postProcessVolume.weight = 1f;
|
||||
_postProcessCameraData.antialiasing = AntialiasingMode.TemporalAntiAliasing;
|
||||
ref var settings = ref _postProcessCameraData.taaSettings;
|
||||
settings = TemporalAA.Settings.Create();
|
||||
settings.quality = ParseTemporalQuality(world.TemporalQuality);
|
||||
settings.baseBlendFactor = world.TemporalHistoryBlend;
|
||||
settings.jitterScale = world.TemporalJitterScale;
|
||||
settings.contrastAdaptiveSharpening = world.TemporalSharpening;
|
||||
}
|
||||
else
|
||||
{
|
||||
_postProcessCameraData.antialiasing = _previousAntialiasing;
|
||||
_postProcessCameraData.taaSettings = _previousTaaSettings;
|
||||
}
|
||||
if (profile != null)
|
||||
{
|
||||
if (_postProcessVolumeObject == null)
|
||||
{
|
||||
_postProcessVolumeObject = new GameObject("Eve World Post Process");
|
||||
_postProcessVolumeObject.transform.SetParent(transform, worldPositionStays: false);
|
||||
_postProcessVolume = _postProcessVolumeObject.AddComponent<Volume>();
|
||||
_postProcessVolume.isGlobal = true;
|
||||
_postProcessVolume.priority = 1000f;
|
||||
_postProcessVolume.weight = 1f;
|
||||
}
|
||||
_postProcessVolume!.sharedProfile = profile;
|
||||
_postProcessVolumeObject.SetActive(true);
|
||||
}
|
||||
else if (_postProcessVolumeObject != null)
|
||||
{
|
||||
_postProcessVolumeObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsTemporalQuality(string quality) =>
|
||||
quality == "very-low" || quality == "low" || quality == "medium" ||
|
||||
quality == "high" || quality == "very-high";
|
||||
|
||||
private static TemporalAAQuality ParseTemporalQuality(string quality)
|
||||
{
|
||||
switch (quality)
|
||||
{
|
||||
case "very-low": return TemporalAAQuality.VeryLow;
|
||||
case "low": return TemporalAAQuality.Low;
|
||||
case "medium": return TemporalAAQuality.Medium;
|
||||
case "very-high": return TemporalAAQuality.VeryHigh;
|
||||
default: return TemporalAAQuality.High;
|
||||
}
|
||||
_postProcessVolume!.sharedProfile = profile;
|
||||
_postProcessVolumeObject.SetActive(true);
|
||||
}
|
||||
|
||||
private void RestorePostProcess()
|
||||
|
|
@ -503,6 +562,8 @@ namespace GameCult.Eve.UnityScene
|
|||
else
|
||||
{
|
||||
_postProcessCameraData.renderPostProcessing = _previousRenderPostProcessing;
|
||||
_postProcessCameraData.antialiasing = _previousAntialiasing;
|
||||
_postProcessCameraData.taaSettings = _previousTaaSettings;
|
||||
}
|
||||
}
|
||||
_postProcessCameraData = null;
|
||||
|
|
|
|||
|
|
@ -156,7 +156,12 @@ namespace GameCult.Eve.UnityScene
|
|||
ParseFloat(worldRoot.GetProp("keyLightIntensity"), 0f),
|
||||
fieldVolumes,
|
||||
worldRoot.GetProp("cameraLookAt"),
|
||||
fieldParticles);
|
||||
fieldParticles,
|
||||
worldRoot.GetProp("cameraReconstruction"),
|
||||
worldRoot.GetProp("temporalQuality", "high"),
|
||||
ParseFloat(worldRoot.GetProp("temporalHistoryBlend"), 0f),
|
||||
ParseFloat(worldRoot.GetProp("temporalJitterScale"), 0f),
|
||||
ParseFloat(worldRoot.GetProp("temporalSharpening"), 0f));
|
||||
}
|
||||
|
||||
private static EveUnityFieldVolumeProjection BuildFieldVolume(EveSurfaceComponent component) =>
|
||||
|
|
@ -411,7 +416,12 @@ namespace GameCult.Eve.UnityScene
|
|||
float keyLightIntensity = 0f,
|
||||
IReadOnlyList<EveUnityFieldVolumeProjection>? fieldVolumes = null,
|
||||
string cameraLookAt = "",
|
||||
IReadOnlyList<EveUnityFieldParticlesProjection>? fieldParticles = null)
|
||||
IReadOnlyList<EveUnityFieldParticlesProjection>? fieldParticles = null,
|
||||
string cameraReconstruction = "",
|
||||
string temporalQuality = "high",
|
||||
float temporalHistoryBlend = 0f,
|
||||
float temporalJitterScale = 0f,
|
||||
float temporalSharpening = 0f)
|
||||
{
|
||||
WorldRootId = worldRootId ?? "";
|
||||
StatePointerId = statePointerId ?? "";
|
||||
|
|
@ -459,6 +469,11 @@ namespace GameCult.Eve.UnityScene
|
|||
FieldVolumes = fieldVolumes ?? Array.Empty<EveUnityFieldVolumeProjection>();
|
||||
FieldParticles = fieldParticles ?? Array.Empty<EveUnityFieldParticlesProjection>();
|
||||
CameraLookAt = cameraLookAt ?? "";
|
||||
CameraReconstruction = cameraReconstruction ?? "";
|
||||
TemporalQuality = temporalQuality ?? "";
|
||||
TemporalHistoryBlend = temporalHistoryBlend;
|
||||
TemporalJitterScale = temporalJitterScale;
|
||||
TemporalSharpening = temporalSharpening;
|
||||
}
|
||||
|
||||
public string WorldRootId { get; }
|
||||
|
|
@ -483,6 +498,16 @@ namespace GameCult.Eve.UnityScene
|
|||
|
||||
public string CameraLookAt { get; }
|
||||
|
||||
public string CameraReconstruction { get; }
|
||||
|
||||
public string TemporalQuality { get; }
|
||||
|
||||
public float TemporalHistoryBlend { get; }
|
||||
|
||||
public float TemporalJitterScale { get; }
|
||||
|
||||
public float TemporalSharpening { get; }
|
||||
|
||||
public float CameraDistance { get; }
|
||||
|
||||
public float CameraVerticalFieldOfViewDegrees { get; }
|
||||
|
|
|
|||
|
|
@ -101,44 +101,28 @@ namespace GameCult.Eve.UnityScene.Fields
|
|||
|
||||
var baseWidth = PositiveInt(field, "textureWidth", 512);
|
||||
var baseHeight = PositiveInt(field, "textureHeight", 512);
|
||||
var viewportWidth = (float)(document.Viewport.MaxX - document.Viewport.MinX);
|
||||
var viewportHeight = (float)(document.Viewport.MaxY - document.Viewport.MinY);
|
||||
if (!float.IsFinite(viewportWidth) || !float.IsFinite(viewportHeight) ||
|
||||
viewportWidth <= 0f || viewportHeight <= 0f)
|
||||
return false;
|
||||
|
||||
var center = new Vector2(
|
||||
(float)((document.Viewport.MinX + document.Viewport.MaxX) * 0.5),
|
||||
(float)((document.Viewport.MinY + document.Viewport.MaxY) * 0.5));
|
||||
if (string.Equals(Prop(field, "viewportAnchor"), "active-camera.xz", StringComparison.Ordinal))
|
||||
{
|
||||
var snapLayer = Prop(field, "viewportSnapLayer");
|
||||
var snapTarget = _targets.FirstOrDefault(target =>
|
||||
string.Equals(target.LayerKey, snapLayer, StringComparison.Ordinal));
|
||||
var snapWidth = snapTarget == null
|
||||
? 0
|
||||
: Mathf.Max(1, Mathf.RoundToInt(baseWidth * Mathf.Max(0.01f, snapTarget.WidthScale)));
|
||||
var snapHeight = snapTarget == null
|
||||
? 0
|
||||
: Mathf.Max(1, Mathf.RoundToInt(baseHeight * Mathf.Max(0.01f, snapTarget.HeightScale)));
|
||||
var snapTexels = PositiveInt(field, "viewportSnapTexels", 0);
|
||||
var cellWorldSize = PositiveFloat(field, "cellWorldSize", 0f);
|
||||
var span = PositiveInt(field, "span", 0);
|
||||
if (!TryValidateSpatialLattice(
|
||||
viewportWidth,
|
||||
viewportHeight,
|
||||
snapWidth,
|
||||
snapHeight,
|
||||
span,
|
||||
cellWorldSize,
|
||||
snapTexels)) return false;
|
||||
center.x = SnapCameraCoordinate(camera.transform.position.x, viewportWidth, snapWidth, snapTexels);
|
||||
center.y = SnapCameraCoordinate(camera.transform.position.z, viewportHeight, snapHeight, snapTexels);
|
||||
}
|
||||
var snapLayer = Prop(field, "viewportSnapLayer");
|
||||
var snapTarget = _targets.FirstOrDefault(target =>
|
||||
string.Equals(target.LayerKey, snapLayer, StringComparison.Ordinal));
|
||||
var snapWidth = snapTarget == null
|
||||
? 0
|
||||
: Mathf.Max(1, Mathf.RoundToInt(baseWidth * Mathf.Max(0.01f, snapTarget.WidthScale)));
|
||||
var snapHeight = snapTarget == null
|
||||
? 0
|
||||
: Mathf.Max(1, Mathf.RoundToInt(baseHeight * Mathf.Max(0.01f, snapTarget.HeightScale)));
|
||||
if (!EveUnityFieldsViewportFrame.TryResolve(
|
||||
document,
|
||||
field.Props,
|
||||
new Vector2(camera.transform.position.x, camera.transform.position.z),
|
||||
snapWidth,
|
||||
snapHeight,
|
||||
out var projected,
|
||||
out var center)) return false;
|
||||
var viewportWidth = (float)(projected.Viewport.MaxX - projected.Viewport.MinX);
|
||||
var viewportHeight = (float)(projected.Viewport.MaxY - projected.Viewport.MinY);
|
||||
|
||||
if (_rasterizedFrameId != document.FrameId || _rasterizedCenter != center)
|
||||
{
|
||||
var projected = ProjectViewport(document, center, viewportWidth, viewportHeight);
|
||||
_layers.Render(projected, _targets, baseWidth, baseHeight);
|
||||
_rasterizedFrameId = document.FrameId;
|
||||
_rasterizedCenter = center;
|
||||
|
|
@ -156,70 +140,6 @@ namespace GameCult.Eve.UnityScene.Fields
|
|||
return true;
|
||||
}
|
||||
|
||||
public static float SnapCameraCoordinate(
|
||||
float coordinate,
|
||||
float viewportWidth,
|
||||
int snapTargetWidth,
|
||||
float snapTexels)
|
||||
{
|
||||
if (!float.IsFinite(coordinate) || !float.IsFinite(viewportWidth) ||
|
||||
!float.IsFinite(snapTexels) || viewportWidth <= 0f ||
|
||||
snapTargetWidth <= 0 || snapTexels <= 0f)
|
||||
throw new ArgumentOutOfRangeException(nameof(viewportWidth));
|
||||
var snapLength = viewportWidth * snapTexels / snapTargetWidth;
|
||||
var cell = (int)(coordinate / snapLength);
|
||||
return cell * snapLength;
|
||||
}
|
||||
|
||||
public static bool TryValidateSpatialLattice(
|
||||
float viewportWidth,
|
||||
float viewportHeight,
|
||||
int gravityTextureWidth,
|
||||
int gravityTextureHeight,
|
||||
int span,
|
||||
float cellWorldSize,
|
||||
int gravityTexelsPerCell)
|
||||
{
|
||||
if (!float.IsFinite(viewportWidth) || !float.IsFinite(viewportHeight) ||
|
||||
!float.IsFinite(cellWorldSize) || viewportWidth <= 0f || viewportHeight <= 0f ||
|
||||
gravityTextureWidth <= 0 || gravityTextureHeight <= 0 || span <= 0 ||
|
||||
cellWorldSize <= 0f || gravityTexelsPerCell <= 0)
|
||||
return false;
|
||||
var expectedExtent = span * cellWorldSize;
|
||||
var expectedCellFromX = viewportWidth * gravityTexelsPerCell / gravityTextureWidth;
|
||||
var expectedCellFromY = viewportHeight * gravityTexelsPerCell / gravityTextureHeight;
|
||||
const float tolerance = 0.0001f;
|
||||
return Mathf.Abs(viewportWidth - expectedExtent) <= tolerance &&
|
||||
Mathf.Abs(viewportHeight - expectedExtent) <= tolerance &&
|
||||
Mathf.Abs(expectedCellFromX - cellWorldSize) <= tolerance &&
|
||||
Mathf.Abs(expectedCellFromY - cellWorldSize) <= tolerance;
|
||||
}
|
||||
|
||||
private static EveFieldsSplatsDocument ProjectViewport(
|
||||
EveFieldsSplatsDocument source,
|
||||
Vector2 center,
|
||||
float width,
|
||||
float height) =>
|
||||
new EveFieldsSplatsDocument
|
||||
{
|
||||
Schema = source.Schema,
|
||||
FrameId = source.FrameId,
|
||||
PublishedAtUtc = source.PublishedAtUtc,
|
||||
SimulationTimeSeconds = source.SimulationTimeSeconds,
|
||||
RunId = source.RunId,
|
||||
ZoneIndex = source.ZoneIndex,
|
||||
ZoneName = source.ZoneName,
|
||||
Viewport = new EveFieldsViewport
|
||||
{
|
||||
MinX = center.x - width * 0.5,
|
||||
MinY = center.y - height * 0.5,
|
||||
MaxX = center.x + width * 0.5,
|
||||
MaxY = center.y + height * 0.5
|
||||
},
|
||||
Layers = source.Layers,
|
||||
Splats = source.Splats
|
||||
};
|
||||
|
||||
private bool EnsurePrograms(EveUnityFieldParticlesProjection field)
|
||||
{
|
||||
var provider = _host?.NativeAssetProvider;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,128 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using GameCult.Eve.PluginFields;
|
||||
using UnityEngine;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Eve.UnityScene.Fields
|
||||
{
|
||||
public static class EveUnityFieldsViewportFrame
|
||||
{
|
||||
public static bool TryResolve(
|
||||
EveFieldsSplatsDocument source,
|
||||
IReadOnlyDictionary<string, string> props,
|
||||
Vector2 cameraPosition,
|
||||
int snapTextureWidth,
|
||||
int snapTextureHeight,
|
||||
out EveFieldsSplatsDocument projected,
|
||||
out Vector2 center)
|
||||
{
|
||||
projected = source;
|
||||
center = default;
|
||||
if (source == null || source.Viewport == null) return false;
|
||||
|
||||
var width = (float)(source.Viewport.MaxX - source.Viewport.MinX);
|
||||
var height = (float)(source.Viewport.MaxY - source.Viewport.MinY);
|
||||
if (!float.IsFinite(width) || !float.IsFinite(height) || width <= 0f || height <= 0f)
|
||||
return false;
|
||||
|
||||
center = new Vector2(
|
||||
(float)((source.Viewport.MinX + source.Viewport.MaxX) * 0.5),
|
||||
(float)((source.Viewport.MinY + source.Viewport.MaxY) * 0.5));
|
||||
if (!string.Equals(Prop(props, "viewportAnchor"), "active-camera.xz", StringComparison.Ordinal))
|
||||
return true;
|
||||
|
||||
var span = PositiveInt(props, "span");
|
||||
var cellWorldSize = PositiveFloat(props, "cellWorldSize");
|
||||
var snapTexels = PositiveInt(props, "viewportSnapTexels");
|
||||
if (!TryValidateSpatialLattice(
|
||||
width, height, snapTextureWidth, snapTextureHeight,
|
||||
span, cellWorldSize, snapTexels))
|
||||
return false;
|
||||
|
||||
center.x = SnapCameraCoordinate(cameraPosition.x, width, snapTextureWidth, snapTexels);
|
||||
center.y = SnapCameraCoordinate(cameraPosition.y, height, snapTextureHeight, snapTexels);
|
||||
projected = Project(source, center, width, height);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static float SnapCameraCoordinate(
|
||||
float coordinate,
|
||||
float viewportWidth,
|
||||
int snapTargetWidth,
|
||||
float snapTexels)
|
||||
{
|
||||
if (!float.IsFinite(coordinate) || !float.IsFinite(viewportWidth) ||
|
||||
!float.IsFinite(snapTexels) || viewportWidth <= 0f ||
|
||||
snapTargetWidth <= 0 || snapTexels <= 0f)
|
||||
throw new ArgumentOutOfRangeException(nameof(viewportWidth));
|
||||
var snapLength = viewportWidth * snapTexels / snapTargetWidth;
|
||||
return (int)(coordinate / snapLength) * snapLength;
|
||||
}
|
||||
|
||||
public static bool TryValidateSpatialLattice(
|
||||
float viewportWidth,
|
||||
float viewportHeight,
|
||||
int gravityTextureWidth,
|
||||
int gravityTextureHeight,
|
||||
int span,
|
||||
float cellWorldSize,
|
||||
int gravityTexelsPerCell)
|
||||
{
|
||||
if (!float.IsFinite(viewportWidth) || !float.IsFinite(viewportHeight) ||
|
||||
!float.IsFinite(cellWorldSize) || viewportWidth <= 0f || viewportHeight <= 0f ||
|
||||
gravityTextureWidth <= 0 || gravityTextureHeight <= 0 || span <= 0 ||
|
||||
cellWorldSize <= 0f || gravityTexelsPerCell <= 0)
|
||||
return false;
|
||||
var expectedExtent = span * cellWorldSize;
|
||||
var expectedCellFromX = viewportWidth * gravityTexelsPerCell / gravityTextureWidth;
|
||||
var expectedCellFromY = viewportHeight * gravityTexelsPerCell / gravityTextureHeight;
|
||||
const float tolerance = 0.0001f;
|
||||
return Mathf.Abs(viewportWidth - expectedExtent) <= tolerance &&
|
||||
Mathf.Abs(viewportHeight - expectedExtent) <= tolerance &&
|
||||
Mathf.Abs(expectedCellFromX - cellWorldSize) <= tolerance &&
|
||||
Mathf.Abs(expectedCellFromY - cellWorldSize) <= tolerance;
|
||||
}
|
||||
|
||||
private static EveFieldsSplatsDocument Project(
|
||||
EveFieldsSplatsDocument source,
|
||||
Vector2 center,
|
||||
float width,
|
||||
float height) =>
|
||||
new EveFieldsSplatsDocument
|
||||
{
|
||||
Schema = source.Schema,
|
||||
FrameId = source.FrameId,
|
||||
PublishedAtUtc = source.PublishedAtUtc,
|
||||
SimulationTimeSeconds = source.SimulationTimeSeconds,
|
||||
RunId = source.RunId,
|
||||
ZoneIndex = source.ZoneIndex,
|
||||
ZoneName = source.ZoneName,
|
||||
Viewport = new EveFieldsViewport
|
||||
{
|
||||
MinX = center.x - width * 0.5,
|
||||
MinY = center.y - height * 0.5,
|
||||
MaxX = center.x + width * 0.5,
|
||||
MaxY = center.y + height * 0.5
|
||||
},
|
||||
Layers = source.Layers,
|
||||
Splats = source.Splats
|
||||
};
|
||||
|
||||
private static string Prop(IReadOnlyDictionary<string, string> props, string key) =>
|
||||
props != null && props.TryGetValue(key, out var value) ? value ?? "" : "";
|
||||
|
||||
private static int PositiveInt(IReadOnlyDictionary<string, string> props, string key) =>
|
||||
int.TryParse(Prop(props, key), NumberStyles.Integer, CultureInfo.InvariantCulture, out var value) && value > 0
|
||||
? value
|
||||
: 0;
|
||||
|
||||
private static float PositiveFloat(IReadOnlyDictionary<string, string> props, string key) =>
|
||||
float.TryParse(Prop(props, key), NumberStyles.Float, CultureInfo.InvariantCulture, out var value) &&
|
||||
float.IsFinite(value) && value > 0f
|
||||
? value
|
||||
: 0f;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e9db43b5b96144a3a0df57a791b53547
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -30,11 +30,14 @@ namespace GameCult.Eve.UnityScene.Fields
|
|||
private Matrix4x4 _previousViewProjection;
|
||||
private EveUnityFieldsVolumePass? _renderPass;
|
||||
private string _activeNodeId = "";
|
||||
private long _rasterizedFrameId = -1;
|
||||
private Vector2 _rasterizedCenter = new Vector2(float.NaN, float.NaN);
|
||||
|
||||
public long PresentedFrameId { get; private set; } = -1;
|
||||
public int PresentedLayerCount => _targets.Count(target => target.TargetTexture != null);
|
||||
public long CompositeCount { get; private set; }
|
||||
public bool UsesTemporalHistory => HasTemporalProgram();
|
||||
public Vector2 LastGridCenter { get; private set; }
|
||||
public static RenderPassEvent CompositionRenderPassEvent => RenderPassEvent.BeforeRenderingPostProcessing;
|
||||
|
||||
public void Bind(EveUnityPlayableWorldClientHost host, IEveUnityFieldsSplatsDocumentSource? source)
|
||||
|
|
@ -67,20 +70,47 @@ namespace GameCult.Eve.UnityScene.Fields
|
|||
if (document == null || document.FrameId < PresentedFrameId) return;
|
||||
_document = document;
|
||||
PresentedFrameId = document.FrameId;
|
||||
RenderLayers(document);
|
||||
}
|
||||
|
||||
private void RenderLayers(EveFieldsSplatsDocument document)
|
||||
private bool TryRenderLayers(
|
||||
EveFieldsSplatsDocument document,
|
||||
Camera camera,
|
||||
out EveFieldsSplatsDocument projected)
|
||||
{
|
||||
projected = document;
|
||||
var field = ActiveField();
|
||||
if (field == null) return;
|
||||
if (field == null) return false;
|
||||
EnsureLayerRenderer();
|
||||
EnsureTargets(field);
|
||||
var width = PositiveInt(field, "textureWidth", 512);
|
||||
var height = PositiveInt(field, "textureHeight", 512);
|
||||
_layers!.Render(document, _targets, width, height);
|
||||
if (!EnsureMaterial(field)) return;
|
||||
ApplyFieldBindings(field, document);
|
||||
var snapLayer = Prop(field, "viewportSnapLayer");
|
||||
var snapTarget = _targets.FirstOrDefault(target =>
|
||||
string.Equals(target.LayerKey, snapLayer, StringComparison.Ordinal));
|
||||
var snapWidth = snapTarget == null
|
||||
? 0
|
||||
: Mathf.Max(1, Mathf.RoundToInt(width * Mathf.Max(0.01f, snapTarget.WidthScale)));
|
||||
var snapHeight = snapTarget == null
|
||||
? 0
|
||||
: Mathf.Max(1, Mathf.RoundToInt(height * Mathf.Max(0.01f, snapTarget.HeightScale)));
|
||||
if (!EveUnityFieldsViewportFrame.TryResolve(
|
||||
document,
|
||||
field.Props,
|
||||
new Vector2(camera.transform.position.x, camera.transform.position.z),
|
||||
snapWidth,
|
||||
snapHeight,
|
||||
out projected,
|
||||
out var center)) return false;
|
||||
if (_rasterizedFrameId != document.FrameId || _rasterizedCenter != center)
|
||||
{
|
||||
_layers!.Render(projected, _targets, width, height);
|
||||
_rasterizedFrameId = document.FrameId;
|
||||
_rasterizedCenter = center;
|
||||
}
|
||||
LastGridCenter = center;
|
||||
if (!EnsureMaterial(field)) return false;
|
||||
ApplyFieldBindings(field, projected);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void OnBeginCameraRendering(ScriptableRenderContext context, Camera camera)
|
||||
|
|
@ -101,10 +131,8 @@ namespace GameCult.Eve.UnityScene.Fields
|
|||
if (_host == null || _document == null || camera == null ||
|
||||
_host.ActiveCameraTransform != camera.transform)
|
||||
return;
|
||||
if (PresentedLayerCount == 0) RenderLayers(_document);
|
||||
var field = ActiveField();
|
||||
if (field == null || !EnsureMaterial(field)) return;
|
||||
ApplyFieldBindings(field, _document);
|
||||
if (field == null || !TryRenderLayers(_document, camera, out _)) return;
|
||||
camera.depthTextureMode |= DepthTextureMode.Depth;
|
||||
EnsureVolumeTextures(camera, field);
|
||||
if (_raymarchTexture == null || !ApplyViewportTextureScaleBindings(field, camera)) return;
|
||||
|
|
@ -369,6 +397,9 @@ namespace GameCult.Eve.UnityScene.Fields
|
|||
_programMetadata = null;
|
||||
_assetTexturesByPort.Clear();
|
||||
_activeNodeId = "";
|
||||
_rasterizedFrameId = -1;
|
||||
_rasterizedCenter = new Vector2(float.NaN, float.NaN);
|
||||
LastGridCenter = default;
|
||||
PresentedFrameId = -1;
|
||||
CompositeCount = 0;
|
||||
ResetTemporalHistory();
|
||||
|
|
|
|||
|
|
@ -62,9 +62,9 @@ namespace GameCult.Eve.UnityScene.Tests
|
|||
[TestCase(11f, 6f)]
|
||||
[TestCase(-11f, -6f)]
|
||||
[TestCase(5.999f, 0f)]
|
||||
public void ParticleRendererSnapsToAnIntegralGravityPixelMultiple(float coordinate, float expected)
|
||||
public void FieldViewportFrameSnapsToAnIntegralGravityPixelMultiple(float coordinate, float expected)
|
||||
{
|
||||
Assert.That(EveUnityFieldsParticleRenderer.SnapCameraCoordinate(
|
||||
Assert.That(EveUnityFieldsViewportFrame.SnapCameraCoordinate(
|
||||
coordinate,
|
||||
1536f,
|
||||
2048,
|
||||
|
|
@ -72,19 +72,56 @@ namespace GameCult.Eve.UnityScene.Tests
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void ParticleRendererAcceptsAlignedGravityAndParticleLattices()
|
||||
public void FieldViewportFrameAcceptsAlignedGravityAndParticleLattices()
|
||||
{
|
||||
Assert.That(EveUnityFieldsParticleRenderer.TryValidateSpatialLattice(
|
||||
Assert.That(EveUnityFieldsViewportFrame.TryValidateSpatialLattice(
|
||||
1536f, 1536f, 2048, 2048, 256, 6f, 8), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParticleRendererRejectsAliasedGravityAndParticleLattices()
|
||||
public void FieldViewportFrameRejectsAliasedGravityAndParticleLattices()
|
||||
{
|
||||
Assert.That(EveUnityFieldsParticleRenderer.TryValidateSpatialLattice(
|
||||
Assert.That(EveUnityFieldsViewportFrame.TryValidateSpatialLattice(
|
||||
2000f, 2000f, 2048, 2048, 256, 6f, 8), Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FogAndParticlesResolveTheSameSnappedWorldFrame()
|
||||
{
|
||||
var document = new EveFieldsSplatsDocument
|
||||
{
|
||||
FrameId = 7,
|
||||
Viewport = new EveFieldsViewport
|
||||
{
|
||||
MinX = -768,
|
||||
MinY = -768,
|
||||
MaxX = 768,
|
||||
MaxY = 768
|
||||
}
|
||||
};
|
||||
var contract = new Dictionary<string, string>(StringComparer.Ordinal)
|
||||
{
|
||||
["viewportAnchor"] = "active-camera.xz",
|
||||
["span"] = "256",
|
||||
["cellWorldSize"] = "6",
|
||||
["viewportSnapTexels"] = "8"
|
||||
};
|
||||
|
||||
Assert.That(EveUnityFieldsViewportFrame.TryResolve(
|
||||
document, contract, new Vector2(11f, -11f), 2048, 2048,
|
||||
out var fog, out var fogCenter), Is.True);
|
||||
Assert.That(EveUnityFieldsViewportFrame.TryResolve(
|
||||
document, contract, new Vector2(11f, -11f), 2048, 2048,
|
||||
out var particles, out var particleCenter), Is.True);
|
||||
|
||||
Assert.That(fogCenter, Is.EqualTo(new Vector2(6f, -6f)));
|
||||
Assert.That(particleCenter, Is.EqualTo(fogCenter));
|
||||
Assert.That(particles.Viewport.MinX, Is.EqualTo(fog.Viewport.MinX));
|
||||
Assert.That(particles.Viewport.MinY, Is.EqualTo(fog.Viewport.MinY));
|
||||
Assert.That(particles.Viewport.MaxX, Is.EqualTo(fog.Viewport.MaxX));
|
||||
Assert.That(particles.Viewport.MaxY, Is.EqualTo(fog.Viewport.MaxY));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParticleRendererFailsClosedWithoutCompleteNativeAbi()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1154,7 +1154,12 @@ namespace GameCult.Eve.UnityScene.Tests
|
|||
PlayableArpgDocument(
|
||||
skyboxAssetRef: "material.environment.skybox",
|
||||
reflectionAssetRef: "texture.environment.reflection",
|
||||
postProcessProfileAssetRef: "profile.environment.flight"),
|
||||
postProcessProfileAssetRef: "profile.environment.flight",
|
||||
cameraReconstruction: "temporal-reprojection.v1",
|
||||
temporalQuality: "high",
|
||||
temporalHistoryBlend: "0.99",
|
||||
temporalJitterScale: "0.1",
|
||||
temporalSharpening: "0"),
|
||||
Advertisement("aetheria.daemon.game"),
|
||||
"cultmesh://aetheria/eve/surfaces/aetheria.daemon.game",
|
||||
1),
|
||||
|
|
@ -1205,7 +1210,13 @@ namespace GameCult.Eve.UnityScene.Tests
|
|||
Assert.That(RenderSettings.reflectionIntensity, Is.EqualTo(1f).Within(0.001f));
|
||||
Assert.That(camera.clearFlags, Is.EqualTo(CameraClearFlags.Skybox));
|
||||
Assert.That(camera.GetComponent<UniversalAdditionalCameraData>(), Is.Not.Null);
|
||||
Assert.That(camera.GetComponent<UniversalAdditionalCameraData>().renderPostProcessing, Is.True);
|
||||
var cameraData = camera.GetComponent<UniversalAdditionalCameraData>();
|
||||
Assert.That(cameraData.renderPostProcessing, Is.True);
|
||||
Assert.That(cameraData.antialiasing, Is.EqualTo(AntialiasingMode.TemporalAntiAliasing));
|
||||
Assert.That(cameraData.taaSettings.quality, Is.EqualTo(TemporalAAQuality.High));
|
||||
Assert.That(cameraData.taaSettings.baseBlendFactor, Is.EqualTo(0.99f).Within(0.0001f));
|
||||
Assert.That(cameraData.taaSettings.jitterScale, Is.EqualTo(0.1f).Within(0.0001f));
|
||||
Assert.That(cameraData.taaSettings.contrastAdaptiveSharpening, Is.Zero);
|
||||
var postProcessTransform = hostObject.transform.Find("Eve World Post Process");
|
||||
Assert.That(postProcessTransform, Is.Not.Null);
|
||||
Assert.That(postProcessTransform.GetComponent<Volume>().sharedProfile, Is.SameAs(postProcessProfile));
|
||||
|
|
@ -1894,7 +1905,12 @@ namespace GameCult.Eve.UnityScene.Tests
|
|||
string cameraPositionDamping = "5",
|
||||
string cameraNearClipPlane = "0.3",
|
||||
string cameraFarClipPlane = "4096",
|
||||
string cameraLookAt = "")
|
||||
string cameraLookAt = "",
|
||||
string cameraReconstruction = "",
|
||||
string temporalQuality = "high",
|
||||
string temporalHistoryBlend = "0",
|
||||
string temporalJitterScale = "0",
|
||||
string temporalSharpening = "0")
|
||||
{
|
||||
var playableChildren = new List<EveSurfaceComponent>
|
||||
{
|
||||
|
|
@ -2062,6 +2078,11 @@ namespace GameCult.Eve.UnityScene.Tests
|
|||
["reflectionAssetRef"] = reflectionAssetRef,
|
||||
["reflectionIntensity"] = "1",
|
||||
["postProcessProfileAssetRef"] = postProcessProfileAssetRef,
|
||||
["cameraReconstruction"] = cameraReconstruction,
|
||||
["temporalQuality"] = temporalQuality,
|
||||
["temporalHistoryBlend"] = temporalHistoryBlend,
|
||||
["temporalJitterScale"] = temporalJitterScale,
|
||||
["temporalSharpening"] = temporalSharpening,
|
||||
["keyLightDirection"] = "0.4,-1,0.25",
|
||||
["keyLightColor"] = "1,0.95,0.9",
|
||||
["keyLightIntensity"] = "0.75",
|
||||
|
|
|
|||
Reference in a new issue