Restore the stable legacy Unity project
This commit is contained in:
parent
56a156ee87
commit
7006a6b0dd
2070 changed files with 180490 additions and 169303 deletions
|
|
@ -5,7 +5,6 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.Serialization;
|
||||
|
|
@ -16,7 +15,6 @@ public class MapView : MonoBehaviour
|
|||
public Camera MinimapGravity;
|
||||
public Camera Minimap;
|
||||
public MeshRenderer GravityRenderer;
|
||||
public AetheriaUnityRenderSplatViewportSource GravitySplatSource;
|
||||
public float ZoomSpeed;
|
||||
[FormerlySerializedAs("SectorRenderer")] public ZoneRenderer ZoneRenderer;
|
||||
|
||||
|
|
@ -28,6 +26,7 @@ public class MapView : MonoBehaviour
|
|||
private RenderTexture _minimapGravityTexture;
|
||||
private Transform _gravityRendererTransform;
|
||||
private CopyTransform _gravityRendererCopyTransform;
|
||||
private RenderTexture _fullscreenGravityTexture;
|
||||
private AetheriaInput.UIActions _input;
|
||||
private float _viewDistance = 1024;
|
||||
private float _aspectRatio;
|
||||
|
|
@ -50,14 +49,9 @@ public class MapView : MonoBehaviour
|
|||
_gravityRendererCopyTransform.enabled = false;
|
||||
_previousGravityRendererScale = _gravityRendererTransform.localScale;
|
||||
|
||||
GravitySplatSource = ResolveGravitySplatSource();
|
||||
GravitySplatSource.SetLayerKey(AetheriaRuntimeRenderSplatLayerKeys.GravityHeight);
|
||||
GravitySplatSource.SetViewport(
|
||||
new Vector2(_minimapTransform.position.x, _minimapTransform.position.z),
|
||||
new Vector2(_viewDistance * _aspectRatio * 2, _viewDistance * 2));
|
||||
GravitySplatSource.RenderLatest();
|
||||
GravityRenderer.material.mainTexture = GravitySplatSource.TargetTexture;
|
||||
MinimapGravity.targetTexture = null;
|
||||
_fullscreenGravityTexture = new RenderTexture(Screen.width / 2, Screen.height / 2, 1, RenderTextureFormat.RFloat);
|
||||
GravityRenderer.material.mainTexture = _fullscreenGravityTexture;
|
||||
MinimapGravity.targetTexture = _fullscreenGravityTexture;
|
||||
Minimap.targetTexture = null;
|
||||
SetZoom();
|
||||
}
|
||||
|
|
@ -67,14 +61,6 @@ public class MapView : MonoBehaviour
|
|||
//ZoneRenderer.ViewDistance = _viewDistance * _aspectRatio;
|
||||
Minimap.orthographicSize = MinimapGravity.orthographicSize = _viewDistance;
|
||||
_gravityRendererTransform.localScale = new Vector3(_viewDistance*_aspectRatio*2, _viewDistance*2, 1);
|
||||
if (GravitySplatSource != null && _minimapTransform != null)
|
||||
{
|
||||
GravitySplatSource.SetViewport(
|
||||
new Vector2(_minimapTransform.position.x, _minimapTransform.position.z),
|
||||
new Vector2(_viewDistance * _aspectRatio * 2, _viewDistance * 2));
|
||||
GravitySplatSource.RenderLatest();
|
||||
GravityRenderer.material.mainTexture = GravitySplatSource.TargetTexture;
|
||||
}
|
||||
}
|
||||
|
||||
// public void BindInput(AetheriaInput.UIActions input)
|
||||
|
|
@ -105,7 +91,6 @@ public class MapView : MonoBehaviour
|
|||
|
||||
_gravityRendererTransform.position = gravPos;
|
||||
Main.transform.position = _minimapTransform.position = _minimapGravityTransform.position = pos;
|
||||
SetZoom();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -121,20 +106,6 @@ public class MapView : MonoBehaviour
|
|||
Minimap.targetTexture = _minimapTexture;
|
||||
MinimapGravity.targetTexture = _minimapGravityTexture;
|
||||
GravityRenderer.material.mainTexture = _minimapGravityTexture;
|
||||
}
|
||||
|
||||
private AetheriaUnityRenderSplatViewportSource ResolveGravitySplatSource()
|
||||
{
|
||||
if (GravitySplatSource != null)
|
||||
return GravitySplatSource;
|
||||
|
||||
GravitySplatSource = GetComponent<AetheriaUnityRenderSplatViewportSource>();
|
||||
if (GravitySplatSource == null)
|
||||
GravitySplatSource = gameObject.AddComponent<AetheriaUnityRenderSplatViewportSource>();
|
||||
|
||||
if (GetComponent<AetheriaRenderSplatLayerRenderer>() == null)
|
||||
gameObject.AddComponent<AetheriaRenderSplatLayerRenderer>();
|
||||
|
||||
return GravitySplatSource;
|
||||
_fullscreenGravityTexture.Release();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class SnapToGrid : MonoBehaviour
|
||||
|
|
@ -17,27 +19,31 @@ public class SnapToGrid : MonoBehaviour
|
|||
public float NormalMultiplier = 100;
|
||||
public float GravityGradientStep = .01f;
|
||||
|
||||
private Vector2 _velocity;
|
||||
private Rigidbody _body;
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
_body = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void LateUpdate () {
|
||||
var pos = new Vector2(transform.position.x,transform.position.z);
|
||||
|
||||
if (ApplyForces)
|
||||
{
|
||||
var force = Gravity.GetForce(pos) * ForceScale;
|
||||
_velocity += force * Time.deltaTime;
|
||||
pos += _velocity * Time.deltaTime;
|
||||
transform.position = new Vector3(pos.x, transform.position.y, pos.y);
|
||||
}
|
||||
|
||||
if(SnapPosition)
|
||||
transform.position = new Vector3(pos.x, Gravity.GetHeight(pos) + Offset,pos.y);
|
||||
if (SnapRotation)
|
||||
{
|
||||
var normal = Gravity.GetNormal(pos, GravityGradientStep, NormalMultiplier);
|
||||
var forward = Vector3.Cross(transform.right, normal);
|
||||
var forward = Vector3.Cross(transform.right, normal);
|
||||
transform.rotation = Quaternion.LookRotation(forward, normal);
|
||||
}
|
||||
|
||||
if (ApplyForces)
|
||||
{
|
||||
//var currentVelocity = _body.velocity;
|
||||
var force = Gravity.GetForce(pos) * ForceScale;
|
||||
_body.AddForce(force.x,0,force.y,ForceMode.Acceleration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,9 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using GameCult.Mesh;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.Rendering.RenderGraphModule;
|
||||
|
||||
/// <summary>
|
||||
/// Based on github.com/yangrc1234/VolumeCloud
|
||||
|
|
@ -35,11 +32,11 @@ public class HaltonSequence
|
|||
/// <summary>
|
||||
/// Cloud renderer post processing.
|
||||
/// </summary>
|
||||
[ImageEffectAllowedInSceneView]
|
||||
[ExecuteInEditMode,RequireComponent(typeof(Camera))]
|
||||
[ImageEffectOpaque]
|
||||
public class VolumeCloudRenderer : EffectBase
|
||||
{
|
||||
private static readonly Dictionary<Camera, VolumeCloudRenderer> RenderersByCamera = new Dictionary<Camera, VolumeCloudRenderer>();
|
||||
|
||||
[Header("Render Settings")]
|
||||
[Range(0, 2)]
|
||||
public int downSample = 1;
|
||||
|
|
@ -52,73 +49,16 @@ public class VolumeCloudRenderer : EffectBase
|
|||
private Matrix4x4 prevV;
|
||||
private Camera mcam;
|
||||
private HaltonSequence sequence = new HaltonSequence() { radix = 3 };
|
||||
private const int TemporalHistoryVersion = 4;
|
||||
private int appliedTemporalHistoryVersion = -1;
|
||||
// The index of 4x4 pixels.
|
||||
private int frameIndex = 0;
|
||||
private bool firstFrame = true;
|
||||
private AetheriaClientState _runtimeState;
|
||||
private int _debugRenderCount;
|
||||
private int _debugLastRenderFrame = -1;
|
||||
|
||||
[SerializeField]
|
||||
private Shader cloudShader;
|
||||
|
||||
[SerializeField]
|
||||
private Texture2D ditherTexture;
|
||||
|
||||
public static bool TryGetRenderer(Camera camera, out VolumeCloudRenderer renderer)
|
||||
{
|
||||
renderer = null;
|
||||
return camera != null
|
||||
&& RenderersByCamera.TryGetValue(camera, out renderer)
|
||||
&& renderer != null
|
||||
&& renderer.isActiveAndEnabled;
|
||||
}
|
||||
|
||||
public int DebugRenderCount => _debugRenderCount;
|
||||
public int DebugLastRenderFrame => _debugLastRenderFrame;
|
||||
public RenderTexture DebugUndersampleBuffer => undersampleBuffer;
|
||||
public RenderTexture DebugHistoryBuffer => fullBuffer != null && fullBuffer.Length > 0 ? fullBuffer[fullBufferIndex] : null;
|
||||
public RenderTexture DebugCurrentCloudBuffer => fullBuffer != null && fullBuffer.Length > 1 ? fullBuffer[fullBufferIndex ^ 1] : null;
|
||||
public bool DebugFirstFrame => firstFrame;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
var camera = GetComponent<Camera>();
|
||||
if (camera != null)
|
||||
RenderersByCamera[camera] = this;
|
||||
ResetTemporalHistory();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
var camera = GetComponent<Camera>();
|
||||
if (camera != null && RenderersByCamera.TryGetValue(camera, out var renderer) && renderer == this)
|
||||
RenderersByCamera.Remove(camera);
|
||||
}
|
||||
|
||||
void EnsureMaterial(bool force = false) {
|
||||
if (cloudShader == null)
|
||||
cloudShader = Shader.Find("Aetheria/CloudShader");
|
||||
|
||||
if (mat == null || force) {
|
||||
mat = new Material(cloudShader);
|
||||
ResetTemporalHistory();
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetTemporalHistory()
|
||||
{
|
||||
firstFrame = true;
|
||||
appliedTemporalHistoryVersion = TemporalHistoryVersion;
|
||||
if (fullBuffer != null)
|
||||
{
|
||||
for (var i = 0; i < fullBuffer.Length; i++)
|
||||
{
|
||||
if (fullBuffer[i] != null)
|
||||
fullBuffer[i].DiscardContents();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -138,99 +78,34 @@ public class VolumeCloudRenderer : EffectBase
|
|||
private void Start() {
|
||||
this.EnsureMaterial(true);
|
||||
if (Application.isPlaying)
|
||||
quality = ResolveNebulaQuality(quality);
|
||||
quality = ActionGameManager.PlayerSettings.GraphicsSettings.NebulaQuality;
|
||||
}
|
||||
|
||||
private Quality ResolveNebulaQuality(Quality fallback)
|
||||
{
|
||||
var snapshot = ResolvePlayerSettings();
|
||||
return Enum.TryParse(snapshot?.NebulaQuality, true, out Quality resolved)
|
||||
? resolved
|
||||
: fallback;
|
||||
}
|
||||
|
||||
private AetheriaRuntimePlayerSettingsDocument ResolvePlayerSettings()
|
||||
{
|
||||
try
|
||||
{
|
||||
_runtimeState ??= AetheriaUnityRuntimeClientProvider.RuntimeState("unity-volume-cloud-renderer");
|
||||
return _runtimeState.PlayerSettings.Latest();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogWarning($"Failed to read Aetheria player settings for volume cloud renderer: {ex.Message}");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void RenderClouds(UnsafeCommandBuffer cmd, Camera camera, TextureHandle colorTarget, TextureHandle depthTarget)
|
||||
{
|
||||
mcam = GetComponent<Camera>();
|
||||
if (camera != mcam || cloudShader == null)
|
||||
[ImageEffectOpaque]
|
||||
private void OnRenderImage(RenderTexture source, RenderTexture destination) {
|
||||
if (cloudShader == null) {
|
||||
Graphics.Blit(source, destination);
|
||||
return;
|
||||
}
|
||||
|
||||
_debugRenderCount++;
|
||||
_debugLastRenderFrame = Time.frameCount;
|
||||
|
||||
mcam = GetComponent<Camera>();
|
||||
var width = mcam.pixelWidth >> downSample;
|
||||
var height = mcam.pixelHeight >> downSample;
|
||||
if (width <= 0 || height <= 0)
|
||||
return;
|
||||
|
||||
EnsureMaterial();
|
||||
EnsureDitherTexture();
|
||||
|
||||
if (appliedTemporalHistoryVersion != TemporalHistoryVersion)
|
||||
ResetTemporalHistory();
|
||||
this.EnsureMaterial();
|
||||
|
||||
EnsureArray(ref fullBuffer, 2);
|
||||
firstFrame |= EnsureRenderTarget(ref fullBuffer[0], width, height, RenderTextureFormat.ARGBFloat, FilterMode.Bilinear);
|
||||
firstFrame |= EnsureRenderTarget(ref fullBuffer[1], width, height, RenderTextureFormat.ARGBFloat, FilterMode.Bilinear);
|
||||
firstFrame |= EnsureRenderTarget(ref undersampleBuffer, width, height, RenderTextureFormat.ARGBFloat, FilterMode.Bilinear);
|
||||
firstFrame |= EnsureRenderTarget(ref undersampleBuffer, width , height, RenderTextureFormat.ARGBFloat, FilterMode.Bilinear);
|
||||
|
||||
frameIndex = (frameIndex + 1) % 16;
|
||||
frameIndex = (frameIndex + 1)% 16;
|
||||
fullBufferIndex = (fullBufferIndex + 1) % 2;
|
||||
|
||||
ApplyQualityKeywords();
|
||||
/* Some code is from playdead TAA. */
|
||||
|
||||
var gpuProjection = GL.GetGPUProjectionMatrix(mcam.projectionMatrix, true);
|
||||
mat.SetMatrix("_CamInvProj", (gpuProjection * mcam.worldToCameraMatrix).inverse);
|
||||
mat.SetVector("_ProjectionExtents", mcam.GetProjectionExtents());
|
||||
mat.SetFloat("_RaymarchOffset", sequence.Get());
|
||||
mat.SetVector("_TexelSize", undersampleBuffer.texelSize);
|
||||
mat.SetFloat("_ResetHistory", firstFrame ? 1.0f : 0.0f);
|
||||
|
||||
mat.SetTexture("_UndersampleCloudTex", undersampleBuffer);
|
||||
mat.SetMatrix("_PrevVP", gpuProjection * prevV);
|
||||
|
||||
cmd.SetRenderTarget(undersampleBuffer);
|
||||
cmd.SetViewport(new Rect(0, 0, width, height));
|
||||
cmd.ClearRenderTarget(false, true, Color.clear);
|
||||
cmd.DrawProcedural(Matrix4x4.identity, mat, 0, MeshTopology.Triangles, 3, 1);
|
||||
|
||||
mat.SetTexture("_MainTex", firstFrame ? undersampleBuffer : fullBuffer[fullBufferIndex]);
|
||||
|
||||
cmd.SetRenderTarget(fullBuffer[fullBufferIndex ^ 1]);
|
||||
cmd.SetViewport(new Rect(0, 0, width, height));
|
||||
cmd.ClearRenderTarget(false, true, Color.clear);
|
||||
cmd.DrawProcedural(Matrix4x4.identity, mat, 1, MeshTopology.Triangles, 3, 1);
|
||||
|
||||
mat.SetTexture("_CloudTex", fullBuffer[fullBufferIndex ^ 1]);
|
||||
|
||||
if (depthTarget.IsValid())
|
||||
cmd.SetRenderTarget(colorTarget, depthTarget);
|
||||
else
|
||||
cmd.SetRenderTarget(colorTarget);
|
||||
cmd.SetViewport(mcam.pixelRect);
|
||||
cmd.DrawProcedural(Matrix4x4.identity, mat, 2, MeshTopology.Triangles, 3, 1);
|
||||
|
||||
prevV = mcam.worldToCameraMatrix;
|
||||
firstFrame = false;
|
||||
}
|
||||
|
||||
private void ApplyQualityKeywords()
|
||||
{
|
||||
//1. Pass1, Render a undersampled buffer. The buffer is dithered using blue noise and halton sequence.
|
||||
//If it's first frame, force a high quality sample to make the initial history buffer good enough.
|
||||
if (firstFrame || quality == Quality.Ultra) {
|
||||
mat.EnableKeyword("ULTRA_QUALITY");
|
||||
mat.DisableKeyword("HIGH_QUALITY");
|
||||
|
|
@ -252,22 +127,30 @@ public class VolumeCloudRenderer : EffectBase
|
|||
mat.DisableKeyword("MEDIUM_QUALITY");
|
||||
mat.EnableKeyword("LOW_QUALITY");
|
||||
}
|
||||
|
||||
mat.SetMatrix("_CamInvProj", (Camera.current.projectionMatrix * Camera.current.worldToCameraMatrix).inverse);
|
||||
mat.SetVector("_ProjectionExtents", mcam.GetProjectionExtents());
|
||||
mat.SetFloat("_RaymarchOffset", sequence.Get());
|
||||
mat.SetVector("_TexelSize", undersampleBuffer.texelSize);
|
||||
|
||||
Graphics.Blit(null, undersampleBuffer, mat, 0);
|
||||
|
||||
//2. Pass 2, blend undersampled image with history buffer to new buffer.
|
||||
mat.SetTexture("_UndersampleCloudTex", undersampleBuffer);
|
||||
mat.SetMatrix("_PrevVP", GL.GetGPUProjectionMatrix(mcam.projectionMatrix,false) * prevV);
|
||||
mat.SetVector("_ProjectionExtents", mcam.GetProjectionExtents());
|
||||
|
||||
if (firstFrame) { //Wait, is this the first frame? If it is, the history buffer is empty yet. It will cause glitch if we use it directly. Fill it using the undersample buffer.
|
||||
Graphics.Blit(undersampleBuffer, fullBuffer[fullBufferIndex]);
|
||||
}
|
||||
Graphics.Blit(fullBuffer[fullBufferIndex], fullBuffer[fullBufferIndex ^ 1], mat, 1);
|
||||
|
||||
//3. Pass3, Calculate lighting, blend final cloud image with final image.
|
||||
mat.SetTexture("_CloudTex", fullBuffer[fullBufferIndex ^ 1]);
|
||||
Graphics.Blit(source, destination, mat, 2);
|
||||
|
||||
//4. Cleanup
|
||||
prevV = mcam.worldToCameraMatrix;
|
||||
firstFrame = false;
|
||||
}
|
||||
|
||||
private void EnsureDitherTexture()
|
||||
{
|
||||
if (ditherTexture == null)
|
||||
ditherTexture = Resources.Load<Texture2D>("LDR_LLL1_0");
|
||||
|
||||
if (ditherTexture == null)
|
||||
return;
|
||||
|
||||
Shader.SetGlobalTexture("_DitheringTex", ditherTexture);
|
||||
Shader.SetGlobalVector("_DitheringCoords", new Vector4(
|
||||
(float)Math.Max(1, Screen.width) / ditherTexture.width,
|
||||
(float)Math.Max(1, Screen.height) / ditherTexture.height,
|
||||
0,
|
||||
0));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,8 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
using System;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using GameCult.Eve.PluginFields;
|
||||
using UnityEngine;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine.Experimental.Rendering;
|
||||
|
|
@ -12,7 +10,6 @@ using UnityEngine.Rendering;
|
|||
using UnityEngine.Serialization;
|
||||
using static Unity.Mathematics.math;
|
||||
using static Unity.Mathematics.noise;
|
||||
using System.Collections.Generic;
|
||||
|
||||
/// <summary>
|
||||
/// Drives the volume render.
|
||||
|
|
@ -21,7 +18,6 @@ using System.Collections.Generic;
|
|||
[RequireComponent( typeof( Camera ) )]
|
||||
public class VolumeSampling : MonoBehaviour
|
||||
{
|
||||
private static readonly List<VolumeSampling> ActiveSamplers = new List<VolumeSampling>();
|
||||
public Transform GridMesh;
|
||||
public Camera GridCamera;
|
||||
public GameSettings Settings;
|
||||
|
|
@ -30,96 +26,33 @@ public class VolumeSampling : MonoBehaviour
|
|||
public RenderTexture NebulaPatchHeight;
|
||||
public RenderTexture NebulaPatch;
|
||||
public RenderTexture NebulaTint;
|
||||
public AetheriaUnityRenderSplatViewportSource SplatViewportSource;
|
||||
public AetheriaRenderSplatLayerRenderer SplatLayerRenderer;
|
||||
|
||||
[SerializeField]
|
||||
private bool useRuntimeRenderSplats;
|
||||
|
||||
[SerializeField]
|
||||
private bool renderSplatsEveryFrame;
|
||||
|
||||
[SerializeField]
|
||||
private float splatRenderIntervalSeconds = 0.25f;
|
||||
|
||||
private MeshRenderer _gridMeshRenderer;
|
||||
private float _flowScroll;
|
||||
private Transform _gridTransform;
|
||||
private Camera _ownerCamera;
|
||||
private Vector2 _lastSplatCenter;
|
||||
private Vector2 _lastSplatSize;
|
||||
private Vector2 _publishedSplatCenter;
|
||||
private Vector2 _publishedSplatSize;
|
||||
private float _nextSplatRenderTime;
|
||||
private bool _hasRenderedSplats;
|
||||
private GlobalKeyword _keywordFlowGlobal;
|
||||
private GlobalKeyword _keywordFlowSlope;
|
||||
private GlobalKeyword _keywordNoiseSlope;
|
||||
|
||||
public static void RenderForCamera(Camera camera)
|
||||
{
|
||||
if (camera == null)
|
||||
return;
|
||||
|
||||
for (var i = 0; i < ActiveSamplers.Count; i++)
|
||||
{
|
||||
var sampler = ActiveSamplers[i];
|
||||
if (sampler != null && sampler.TargetsCamera(camera))
|
||||
sampler.RenderSamplingPass();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (!ActiveSamplers.Contains(this))
|
||||
ActiveSamplers.Add(this);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
ActiveSamplers.Remove(this);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_ownerCamera = GetComponent<Camera>();
|
||||
_keywordFlowGlobal = GlobalKeyword.Create("FLOW_GLOBAL");
|
||||
_keywordFlowSlope = GlobalKeyword.Create("FLOW_SLOPE");
|
||||
_keywordNoiseSlope = GlobalKeyword.Create("NOISE_SLOPE");
|
||||
|
||||
if (GridMesh != null)
|
||||
_gridMeshRenderer = GridMesh.GetComponent<MeshRenderer>();
|
||||
|
||||
ResolveSplatRenderers();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(_gridTransform==null)
|
||||
_gridTransform = GridCamera?.transform;
|
||||
// Shader needs to know the position and scale of cameras used to render input textures
|
||||
if(GridCamera != null)
|
||||
Shader.SetGlobalVector("_GridTransform", new Vector4(_gridTransform.position.x,_gridTransform.position.z,GridCamera.orthographicSize*2));
|
||||
|
||||
_flowScroll += Settings.DefaultEnvironment.Flow.GlobalScrollSpeed * Time.deltaTime;
|
||||
UpdateGridMeshBounds();
|
||||
}
|
||||
|
||||
private bool TargetsCamera(Camera camera)
|
||||
{
|
||||
_ownerCamera ??= GetComponent<Camera>();
|
||||
return camera == _ownerCamera;
|
||||
}
|
||||
|
||||
private void RenderSamplingPass()
|
||||
{
|
||||
if (_gridTransform == null)
|
||||
_gridTransform = GridCamera?.transform;
|
||||
|
||||
RenderSplatTexturesIfNeeded();
|
||||
PublishSamplingGlobals();
|
||||
}
|
||||
|
||||
private void UpdateGridMeshBounds()
|
||||
{
|
||||
var environment = Settings.DefaultEnvironment;
|
||||
var environment = ActionGameManager.Instance?.CurrentEnvironment ?? Settings.DefaultEnvironment;
|
||||
|
||||
if (GridMesh != null)
|
||||
{
|
||||
|
|
@ -130,19 +63,7 @@ public class VolumeSampling : MonoBehaviour
|
|||
// GridMesh.position = new Vector3(_gridTransform.position.x, environment.Grid.Offset, _gridTransform.position.z);
|
||||
// GridMesh.localScale = new Vector3(GridCamera.orthographicSize, 1, GridCamera.orthographicSize);
|
||||
}
|
||||
}
|
||||
|
||||
private void PublishSamplingGlobals()
|
||||
{
|
||||
var environment = Settings.DefaultEnvironment;
|
||||
|
||||
ResolveSplatViewport(out var center, out var size);
|
||||
_publishedSplatCenter = center;
|
||||
_publishedSplatSize = size;
|
||||
|
||||
// Shader sampling must use the same world-space viewport that produced the splat textures.
|
||||
Shader.SetGlobalVector("_GridTransform", new Vector4(center.x, center.y, size.x));
|
||||
|
||||
|
||||
// Volumetric sampling parameters are used by several shaders
|
||||
Shader.SetGlobalTexture("_NebulaSurfaceHeight", NebulaSurfaceHeight);
|
||||
Shader.SetGlobalTexture("_NebulaPatchHeight", NebulaPatchHeight);
|
||||
|
|
@ -177,6 +98,7 @@ public class VolumeSampling : MonoBehaviour
|
|||
Shader.SetGlobalFloat("_FlowAmplitude", environment.Flow.GlobalAmplitude);
|
||||
Shader.SetGlobalFloat("_FlowSlopeAmplitude", environment.Flow.SlopeAmplitude);
|
||||
Shader.SetGlobalFloat("_FlowSwirlAmplitude", environment.Flow.SwirlAmplitude);
|
||||
_flowScroll += environment.Flow.GlobalScrollSpeed * Time.deltaTime;
|
||||
Shader.SetGlobalFloat("_FlowScroll", _flowScroll);
|
||||
Shader.SetGlobalFloat("_FlowPeriod", environment.Flow.Period);
|
||||
|
||||
|
|
@ -184,90 +106,4 @@ public class VolumeSampling : MonoBehaviour
|
|||
Shader.SetKeyword(_keywordFlowSlope, environment.Flow.SlopeAmplitude != 0 || environment.Flow.SwirlAmplitude != 0);
|
||||
Shader.SetKeyword(_keywordNoiseSlope, environment.Noise.SlopeExponent != 0);
|
||||
}
|
||||
|
||||
private void RenderSplatTexturesIfNeeded()
|
||||
{
|
||||
ResolveSplatRenderers();
|
||||
if (SplatLayerRenderer == null)
|
||||
return;
|
||||
if (!useRuntimeRenderSplats)
|
||||
return;
|
||||
|
||||
ResolveSplatViewport(out var center, out var size);
|
||||
var document = ResolveRuntimeSplatDocument(center, size);
|
||||
if (document == null)
|
||||
return;
|
||||
|
||||
var viewportChanged = !_hasRenderedSplats ||
|
||||
!Approximately(center, _lastSplatCenter) ||
|
||||
!Approximately(size, _lastSplatSize);
|
||||
var intervalElapsed = Time.unscaledTime >= _nextSplatRenderTime;
|
||||
if (!renderSplatsEveryFrame && !viewportChanged && !intervalElapsed)
|
||||
return;
|
||||
|
||||
SplatLayerRenderer.Render(document, Mathf.RoundToInt(size.x), Mathf.RoundToInt(size.y));
|
||||
_lastSplatCenter = center;
|
||||
_lastSplatSize = size;
|
||||
_publishedSplatCenter = center;
|
||||
_publishedSplatSize = size;
|
||||
_nextSplatRenderTime = Time.unscaledTime + Mathf.Max(0.02f, splatRenderIntervalSeconds);
|
||||
_hasRenderedSplats = true;
|
||||
|
||||
if (SplatLayerRenderer == null)
|
||||
return;
|
||||
|
||||
NebulaSurfaceHeight = ResolveLayerTexture(AetheriaRuntimeRenderSplatLayerKeys.FogSurfaceHeight, NebulaSurfaceHeight);
|
||||
NebulaPatchHeight = ResolveLayerTexture(AetheriaRuntimeRenderSplatLayerKeys.FogPatchHeight, NebulaPatchHeight);
|
||||
NebulaPatch = ResolveLayerTexture(AetheriaRuntimeRenderSplatLayerKeys.FogPatch, NebulaPatch);
|
||||
NebulaTint = ResolveLayerTexture(AetheriaRuntimeRenderSplatLayerKeys.FogTint, NebulaTint);
|
||||
}
|
||||
|
||||
private EveFieldsSplatsDocument ResolveRuntimeSplatDocument(Vector2 center, Vector2 size)
|
||||
{
|
||||
if (SplatViewportSource == null)
|
||||
return null;
|
||||
|
||||
SplatViewportSource.SetViewport(center, size);
|
||||
return SplatViewportSource.CurrentDocument;
|
||||
}
|
||||
|
||||
private void ResolveSplatViewport(out Vector2 center, out Vector2 size)
|
||||
{
|
||||
size = GridCamera != null
|
||||
? new Vector2(GridCamera.orthographicSize * 2, GridCamera.orthographicSize * 2)
|
||||
: new Vector2(1024, 1024);
|
||||
center = _gridTransform != null
|
||||
? new Vector2(_gridTransform.position.x, _gridTransform.position.z)
|
||||
: Vector2.zero;
|
||||
}
|
||||
|
||||
private static bool Approximately(Vector2 lhs, Vector2 rhs)
|
||||
{
|
||||
return Mathf.Abs(lhs.x - rhs.x) < 0.001f &&
|
||||
Mathf.Abs(lhs.y - rhs.y) < 0.001f;
|
||||
}
|
||||
|
||||
private RenderTexture ResolveLayerTexture(string layerKey, RenderTexture fallback)
|
||||
{
|
||||
return SplatLayerRenderer.TryGetTexture(layerKey, out var texture) && texture != null
|
||||
? texture
|
||||
: fallback;
|
||||
}
|
||||
|
||||
private void ResolveSplatRenderers()
|
||||
{
|
||||
if (SplatLayerRenderer == null)
|
||||
SplatLayerRenderer = GetComponent<AetheriaRenderSplatLayerRenderer>();
|
||||
if (SplatLayerRenderer == null)
|
||||
SplatLayerRenderer = gameObject.AddComponent<AetheriaRenderSplatLayerRenderer>();
|
||||
|
||||
if (!useRuntimeRenderSplats)
|
||||
return;
|
||||
|
||||
if (SplatViewportSource == null)
|
||||
SplatViewportSource = GetComponent<AetheriaUnityRenderSplatViewportSource>();
|
||||
if (SplatViewportSource == null)
|
||||
SplatViewportSource = gameObject.AddComponent<AetheriaUnityRenderSplatViewportSource>();
|
||||
SplatViewportSource.RenderInLateUpdate = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue