升级6.4.升级水,升级天气

This commit is contained in:
2026-04-05 00:26:54 +08:00
parent 63bc9b5536
commit 5f7cbfb713
635 changed files with 34718 additions and 22567 deletions

View File

@@ -38,12 +38,15 @@ namespace WaveHarmonic.Crest
int _KernelSpectrumInitial;
int _KernelSpectrumUpdate;
LocalKeyword _AdvancedKeyword;
Parameters _Parameters;
float _GenerationTime = -1f;
// WebGPU claims it does but does not.
static readonly bool s_SupportsRandomWriteRGFloat =
SystemInfo.SupportsRandomWriteOnRenderTextureFormat(RenderTextureFormat.RGFloat);
!Helpers.IsWebGPU && SystemInfo.SupportsRandomWriteOnRenderTextureFormat(RenderTextureFormat.RGFloat);
public static class ShaderIDs
{
@@ -58,6 +61,8 @@ namespace WaveHarmonic.Crest
public static readonly int s_ResultInit = Shader.PropertyToID("_Crest_ResultInit");
public static readonly int s_Time = Shader.PropertyToID("_Crest_Time");
public static readonly int s_Chop = Shader.PropertyToID("_Crest_Chop");
public static readonly int s_ChopScales = Shader.PropertyToID("_Crest_ChopScales");
public static readonly int s_GravityScales = Shader.PropertyToID("_Crest_GravityScales");
public static readonly int s_Init0 = Shader.PropertyToID("_Crest_Init0");
public static readonly int s_ResultHeight = Shader.PropertyToID("_Crest_ResultHeight");
public static readonly int s_ResultDisplaceX = Shader.PropertyToID("_Crest_ResultDisplaceX");
@@ -86,8 +91,9 @@ namespace WaveHarmonic.Crest
public readonly float _WindTurbulence;
public readonly float _WindAlignment;
public readonly float _Gravity;
public readonly bool _Advanced;
public Parameters(WaveSpectrum spectrum, int resolution, float period, float speed, float direction, float turbulence, float alignment, float gravity)
public Parameters(WaveSpectrum spectrum, int resolution, float period, float speed, float direction, float turbulence, float alignment, float gravity, bool advanced)
{
_Spectrum = spectrum;
_Resolution = resolution;
@@ -97,17 +103,28 @@ namespace WaveHarmonic.Crest
_WindTurbulence = turbulence;
_WindAlignment = alignment;
_Gravity = gravity;
_Advanced = advanced;
}
// Implement custom or incur allocations.
public override int GetHashCode()
{
return System.HashCode.Combine(_Spectrum, _LoopPeriod, _WindSpeed, _WindDirectionRadians, _WindTurbulence, _WindAlignment, _Gravity, _Resolution);
return GetHashCode(_Resolution);
}
public int GetHashCode(int resolution)
{
return System.HashCode.Combine(_Spectrum, _LoopPeriod, _WindSpeed, _WindDirectionRadians, _WindTurbulence, _WindAlignment, _Gravity, resolution);
var hash = new System.HashCode();
hash.Add(_Spectrum);
hash.Add(_LoopPeriod);
hash.Add(_WindSpeed);
hash.Add(_WindDirectionRadians);
hash.Add(_WindTurbulence);
hash.Add(_WindAlignment);
hash.Add(_Gravity);
hash.Add(resolution);
hash.Add(_Advanced);
return hash.ToHashCode();
}
}
@@ -201,13 +218,15 @@ namespace WaveHarmonic.Crest
_KernelSpectrumUpdate = _ShaderSpectrum.FindKernel("SpectrumUpdate");
_ShaderFFT = WaterResources.Instance.Compute._FFT;
_AdvancedKeyword = _ShaderSpectrum.keywordSpace.FindKeyword("d_AdvancedControls");
var rtd = new RenderTextureDescriptor(0, 0);
rtd.width = rtd.height = resolution;
rtd.dimension = TextureDimension.Tex2DArray;
rtd.enableRandomWrite = true;
rtd.depthBufferBits = 0;
rtd.volumeDepth = k_CascadeCount;
rtd.colorFormat = RenderTextureFormat.ARGBFloat;
rtd.graphicsFormat = GraphicsFormat.R32G32B32A32_SFloat;
rtd.msaaSamples = 1;
Helpers.SafeCreateRenderTexture(ref _SpectrumInitial, rtd);
@@ -215,7 +234,7 @@ namespace WaveHarmonic.Crest
_SpectrumInitial.Create();
// Raw wave data buffer
WaveBuffers = new(resolution, resolution, 0, GraphicsFormat.R16G16B16A16_SFloat)
WaveBuffers = new(resolution, resolution, 0, Helpers.GetCompatibleTextureFormat(GraphicsFormat.R16G16B16A16_SFloat, randomWrite: true))
{
wrapMode = TextureWrapMode.Repeat,
antiAliasing = 1,
@@ -263,7 +282,7 @@ namespace WaveHarmonic.Crest
offset <<= 1;
}
var texture = new Texture2D(resolution, Mathf.RoundToInt(Mathf.Log(resolution, 2)), TextureFormat.RGBAFloat, false, true);
var texture = new Texture2D(resolution, Mathf.RoundToInt(Mathf.Log(resolution, 2)), TextureFormat.RGFloat, false, true);
texture.SetPixels(colors);
texture.Apply();
s_ButterflyTextures.Add(resolution, texture);
@@ -297,19 +316,18 @@ namespace WaveHarmonic.Crest
var wrapper = new PropertyWrapperCompute(buffer, _ShaderSpectrum, _KernelSpectrumUpdate);
var descriptor = _SpectrumInitial.descriptor;
if (s_SupportsRandomWriteRGFloat)
{
descriptor.colorFormat = RenderTextureFormat.RGFloat;
}
descriptor.graphicsFormat = Helpers.GetCompatibleTextureFormat(GraphicsFormat.R32G32_SFloat, Helpers.s_DataGraphicsFormatUsage, "FFT", randomWrite: true);
// No need to clear as overwritten.
buffer.GetTemporaryRT(ShaderIDs.s_TemporaryFFT1, descriptor);
buffer.GetTemporaryRT(ShaderIDs.s_TemporaryFFT2, descriptor);
buffer.GetTemporaryRT(ShaderIDs.s_TemporaryFFT3, descriptor);
wrapper.SetKeyword(_AdvancedKeyword, _Parameters._Advanced);
wrapper.SetInteger(ShaderIDs.s_Size, resolution);
wrapper.SetFloat(ShaderIDs.s_Time, time * _Parameters._Spectrum._GravityScale);
wrapper.SetFloatArray(ShaderIDs.s_ChopScales, _Parameters._Spectrum._ChopScales);
wrapper.SetFloatArray(ShaderIDs.s_GravityScales, _Parameters._Spectrum._GravityScales);
wrapper.SetFloat(ShaderIDs.s_Chop, _Parameters._Spectrum._Chop);
wrapper.SetFloat(ShaderIDs.s_Period, period < Mathf.Infinity ? period : -1);
wrapper.SetTexture(ShaderIDs.s_Init0, _SpectrumInitial);