升级6.4.升级水,升级天气
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
using UnityEngine;
|
||||
using WaveHarmonic.Crest.Internal;
|
||||
|
||||
namespace WaveHarmonic.Crest
|
||||
{
|
||||
@@ -10,13 +11,8 @@ namespace WaveHarmonic.Crest
|
||||
/// </summary>
|
||||
[CreateAssetMenu(fileName = "Waves", menuName = "Crest/Wave Spectrum", order = 10000)]
|
||||
[@HelpURL("Manual/Waves.html#wave-conditions")]
|
||||
public sealed partial class WaveSpectrum : ScriptableObject
|
||||
public sealed partial class WaveSpectrum : CustomScriptableObject
|
||||
{
|
||||
[SerializeField, HideInInspector]
|
||||
#pragma warning disable 414
|
||||
int _Version = 0;
|
||||
#pragma warning restore 414
|
||||
|
||||
// These must match corresponding constants in FFTSpectrum.compute
|
||||
internal const int k_NumberOfOctaves = 14;
|
||||
internal const float k_SmallestWavelengthPower2 = -4f;
|
||||
@@ -24,21 +20,29 @@ namespace WaveHarmonic.Crest
|
||||
internal static readonly float s_MinimumPowerLog = -8f;
|
||||
internal static readonly float s_MaximumPowerLog = 5f;
|
||||
|
||||
[Tooltip("Variance of wave directions, in degrees.")]
|
||||
[@Range(0f, 180f)]
|
||||
[SerializeField, HideInInspector]
|
||||
internal float _WaveDirectionVariance = 90f;
|
||||
|
||||
[Tooltip("More gravity means faster waves.")]
|
||||
[@Range(0f, 25f)]
|
||||
[SerializeField, HideInInspector]
|
||||
internal float _GravityScale = 1f;
|
||||
|
||||
[Tooltip("Multiplier which scales waves")]
|
||||
[@Range(0f, 10f)]
|
||||
[SerializeField]
|
||||
internal float _Multiplier = 1f;
|
||||
|
||||
[Tooltip("Scales horizontal displacement")]
|
||||
[@Range(0f, 2f)]
|
||||
[SerializeField]
|
||||
internal float _Chop = 1.6f;
|
||||
|
||||
[Tooltip("More gravity means faster waves.")]
|
||||
[@CustomLabel]
|
||||
[@Range(0f, 25f)]
|
||||
[SerializeField]
|
||||
internal float _GravityScale = 1f;
|
||||
|
||||
[Tooltip("Variance of wave directions, in degrees.")]
|
||||
[@Range(0f, 180f)]
|
||||
[SerializeField, HideInInspector]
|
||||
internal float _WaveDirectionVariance = 90f;
|
||||
|
||||
|
||||
[SerializeField, HideInInspector]
|
||||
internal float[] _PowerLogarithmicScales = new float[k_NumberOfOctaves] { -7.10794f, -6.42794f, -5.93794f, -5.27794f, -4.67794f, -3.71794f, -3.17794f, -2.60794f, -1.93794f, -1.11794f, -0.85794f, -0.36794f, 0.04206f, -8f };
|
||||
|
||||
@@ -51,10 +55,8 @@ namespace WaveHarmonic.Crest
|
||||
[SerializeField, HideInInspector]
|
||||
internal float[] _GravityScales = new float[k_NumberOfOctaves] { 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f };
|
||||
|
||||
[Tooltip("Scales horizontal displacement")]
|
||||
[@Range(0f, 2f)]
|
||||
[SerializeField]
|
||||
internal float _Chop = 1.6f;
|
||||
[SerializeField, HideInInspector]
|
||||
internal float[] _Attenuation = new float[k_NumberOfOctaves] { 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f };
|
||||
|
||||
#pragma warning disable 414
|
||||
[SerializeField, HideInInspector]
|
||||
@@ -67,6 +69,8 @@ namespace WaveHarmonic.Crest
|
||||
internal SpectrumModel _Model;
|
||||
#pragma warning restore 414
|
||||
|
||||
internal float[] _PowerLinearScales = new float[k_NumberOfOctaves];
|
||||
|
||||
internal enum SpectrumModel
|
||||
{
|
||||
None,
|
||||
@@ -221,6 +225,7 @@ namespace WaveHarmonic.Crest
|
||||
// we store power on logarithmic scale. this does not include 0, we represent 0 as min value
|
||||
pow = Mathf.Max(pow, Mathf.Pow(10f, s_MinimumPowerLog));
|
||||
|
||||
_PowerLinearScales[octave] = pow;
|
||||
_PowerLogarithmicScales[octave] = Mathf.Log10(pow);
|
||||
}
|
||||
}
|
||||
@@ -271,6 +276,7 @@ namespace WaveHarmonic.Crest
|
||||
void OnDestroy()
|
||||
{
|
||||
Helpers.Destroy(_ControlsTexture);
|
||||
_ControlsTexture = null;
|
||||
}
|
||||
|
||||
internal void InitializeHandControls()
|
||||
@@ -279,6 +285,7 @@ namespace WaveHarmonic.Crest
|
||||
{
|
||||
var power = _PowerDisabled[i] ? 0f : Mathf.Pow(10f, _PowerLogarithmicScales[i]);
|
||||
power *= _Multiplier * _Multiplier;
|
||||
_PowerLinearScales[i] = power;
|
||||
_ScratchData[i] = power * Color.white;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user