'push'
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using UnityEngine;
|
||||
using WaveHarmonic.Crest.Internal;
|
||||
|
||||
namespace WaveHarmonic.Crest.ShallowWater
|
||||
{
|
||||
/// <summary>
|
||||
/// Debug helper - designed to be used in conjunction with the SWSProbe shader to visualise simulation state.
|
||||
/// </summary>
|
||||
[@ExecuteDuringEditMode]
|
||||
[@HelpURL("Packages/ShallowWater/Manual.html")]
|
||||
[AddComponentMenu(Constants.k_MenuPrefixDebug + "Shallow Water Visualizer")]
|
||||
sealed class ShallowWaterVisualizer : ManagedBehaviour<WaterRenderer>
|
||||
{
|
||||
[SerializeField, HideInInspector]
|
||||
#pragma warning disable 414
|
||||
int _Version = 0;
|
||||
#pragma warning restore 414
|
||||
|
||||
[SerializeField]
|
||||
ShallowWaterSimulation _ShallowWaterSimulation;
|
||||
|
||||
[SerializeField]
|
||||
bool _RenderFinalHeight = true;
|
||||
|
||||
Material _Material;
|
||||
|
||||
static class ShaderIDs
|
||||
{
|
||||
public static readonly int s_RenderFinalHeight = Shader.PropertyToID("_Crest_RenderFinalHeight");
|
||||
}
|
||||
|
||||
private protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_Material = new Material(WaterResources.Instance.Shaders._ShallowWaterSimulationVisualizer);
|
||||
}
|
||||
|
||||
private protected override void OnDisable()
|
||||
{
|
||||
base.OnDisable();
|
||||
Helpers.Destroy(_Material);
|
||||
}
|
||||
|
||||
// Data is ready in LateUpdate.
|
||||
private protected override System.Action<WaterRenderer> OnLateUpdateMethod => OnLateUpdate;
|
||||
void OnLateUpdate(WaterRenderer water)
|
||||
{
|
||||
var sws = _ShallowWaterSimulation;
|
||||
if (sws == null)
|
||||
{
|
||||
var rect = new Rect(transform.position.XZ() - transform.lossyScale.XZ() * 0.5f, transform.lossyScale.XZ());
|
||||
sws = ShallowWaterSimulation.Get(rect);
|
||||
if (sws == null) return;
|
||||
}
|
||||
|
||||
sws.SetUniforms(_Material);
|
||||
_Material.SetBoolean(ShaderIDs.s_RenderFinalHeight, _RenderFinalHeight);
|
||||
Graphics.RenderMesh(new RenderParams(_Material), Helpers.SphereMesh, 0, transform.localToWorldMatrix);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user