升级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

@@ -3,6 +3,8 @@
// Inspired by https://github.com/speps/GX-EncinoWaves
#pragma exclude_renderers glcore gles3
// First SIZE constant must match FFT_KERNEL_0_RESOLUTION in FFTCompute.cs
#pragma kernel ComputeFFT SIZE=8 PASSES=3 CHANNEL=x TX=8 TY=1 FINAL=0
#pragma kernel ComputeFFT SIZE=8 PASSES=3 CHANNEL=y TX=1 TY=8 FINAL=1
@@ -22,11 +24,13 @@
// Must match CASCADE_COUNT in FFTCompute.cs
#define CASCADE_COUNT 16
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.hlsl"
Texture2D<float2> _Crest_InputButterfly;
#if !FINAL
RWTexture2DArray<float2> _Crest_Output1;
RWTexture2DArray<float2> _Crest_Output2;
RWTexture2DArray<float2> _Crest_Output3;
RWTexture2DArray<m_Float2> _Crest_Output1;
RWTexture2DArray<m_Float2> _Crest_Output2;
RWTexture2DArray<m_Float2> _Crest_Output3;
#else
Texture2DArray<float2> _Crest_InputH;
Texture2DArray<float2> _Crest_InputX;
@@ -140,9 +144,9 @@ void ComputeFFT(const uint3 id : SV_DispatchThreadID)
{
const uint coord = id.CHANNEL;
#if !FINAL
_Crest_IntermediatesH[coord] = conj(_Crest_Output1[id]);
_Crest_IntermediatesX[coord] = conj(_Crest_Output2[id]);
_Crest_IntermediatesZ[coord] = conj(_Crest_Output3[id]);
_Crest_IntermediatesH[coord] = conj(_Crest_Output1[id].xy);
_Crest_IntermediatesX[coord] = conj(_Crest_Output2[id].xy);
_Crest_IntermediatesZ[coord] = conj(_Crest_Output3[id].xy);
#else
_Crest_IntermediatesH[coord] = _Crest_InputH[id];
_Crest_IntermediatesX[coord] = _Crest_InputX[id];
@@ -164,9 +168,9 @@ void ComputeFFT(const uint3 id : SV_DispatchThreadID)
const float2 resultZ = pingpong ? _Crest_IntermediatesZ[coord] : _Crest_ScratchZ[coord];
#if !FINAL
_Crest_Output1[id] = resultH;
_Crest_Output2[id] = resultX;
_Crest_Output3[id] = resultZ;
_Crest_Output1[id] = m_Float2FromFloat2(resultH);
_Crest_Output2[id] = m_Float2FromFloat2(resultX);
_Crest_Output3[id] = m_Float2FromFloat2(resultZ);
#else
const float sign = ((id.x + id.y) % 2) == 1 ? -1.0 : 1.0;
const float3 res = float3(sign * resultX.x, sign * resultH.x, sign * resultZ.x);

View File

@@ -3,9 +3,13 @@
// Inspired by https://github.com/speps/GX-EncinoWaves
#pragma exclude_renderers glcore gles3
#pragma kernel SpectrumInitalize
#pragma kernel SpectrumUpdate
#pragma multi_compile_local _ d_AdvancedControls
#define INV2PI 0.15915494309f
#define PI4 0.33661977236f
#define INVPI2 0.63661977236f
@@ -15,9 +19,12 @@
#define HSQRT2 0.70710678118f
// These must match corresponding constants in WaveSpectrum.cs
#define SPECTRUM_OCTAVE_COUNT_INT 14
#define SPECTRUM_OCTAVE_COUNT 14.0
#define SPECTRUM_SMALLEST_WL_POW_2 -4.0
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.hlsl"
uint _Crest_Size;
float _Crest_WindSpeed;
float _Crest_Turbulence;
@@ -219,10 +226,15 @@ void SpectrumInitalize(uint3 id : SV_DispatchThreadID)
float _Crest_Time;
float _Crest_Chop;
#if d_AdvancedControls
float _Crest_ChopScales[SPECTRUM_OCTAVE_COUNT_INT];
float _Crest_GravityScales[SPECTRUM_OCTAVE_COUNT_INT];
#endif
Texture2DArray<float4> _Crest_Init0;
RWTexture2DArray<float2> _Crest_ResultHeight;
RWTexture2DArray<float2> _Crest_ResultDisplaceX;
RWTexture2DArray<float2> _Crest_ResultDisplaceZ;
RWTexture2DArray<m_Float2> _Crest_ResultHeight;
RWTexture2DArray<m_Float2> _Crest_ResultDisplaceX;
RWTexture2DArray<m_Float2> _Crest_ResultDisplaceZ;
float2 cmul(float2 lhs, float2 rhs)
{
@@ -243,13 +255,23 @@ void SpectrumUpdate(uint3 id : SV_DispatchThreadID)
const float2 k = PI2 * coord / worldSize;
const float kMag = length(k);
float time = _Crest_Time;
float chop = _Crest_Chop;
#if d_AdvancedControls
const float wavelength = PI2 / kMag;
const uint octaveIndex = clamp(log2(wavelength) - SPECTRUM_SMALLEST_WL_POW_2, 0.0, SPECTRUM_OCTAVE_COUNT - 1.0);
time *= _Crest_GravityScales[octaveIndex];
chop *= _Crest_ChopScales[octaveIndex];
#endif
// Dispersion
float w; float dwdk;
DeepDispersion(kMag, w, dwdk);
// Advance time
float sw; float cw;
sincos(w * _Crest_Time, sw, cw);
sincos(w * time, sw, cw);
const float2 fwd = float2(cw, -sw);
const float2 bkwd = float2(cw, sw);
@@ -257,7 +279,7 @@ void SpectrumUpdate(uint3 id : SV_DispatchThreadID)
const float4 h0 = _Crest_Init0[id];
const float2 h = cmul(h0.xy, fwd) + cmul(h0.zw, bkwd);
_Crest_ResultHeight[id] = h;
_Crest_ResultDisplaceX[id] = _Crest_Chop * float2(-h.y * k.x, h.x * k.x) / (kMag + 0.00001f);
_Crest_ResultDisplaceZ[id] = _Crest_Chop * float2(-h.y * k.y, h.x * k.y) / (kMag + 0.00001f);
_Crest_ResultHeight[id] = m_Float2FromFloat2(h);
_Crest_ResultDisplaceX[id] = m_Float2FromFloat2((chop * float2(-h.y * k.x, h.x * k.x) / (kMag + 0.00001f)));
_Crest_ResultDisplaceZ[id] = m_Float2FromFloat2((chop * float2(-h.y * k.y, h.x * k.y) / (kMag + 0.00001f)));
}

View File

@@ -3,22 +3,26 @@
// Computes a set of patches of waves, one for each scale.
#pragma kernel Gerstner
#pragma exclude_renderers glcore gles3
#pragma kernel CrestExecute
#pragma multi_compile_local _ d_WavePairs
#include "HLSLSupport.cginc"
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.hlsl"
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Globals.hlsl"
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/InputsDriven.hlsl"
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Helpers.hlsl"
float _Crest_TextureRes;
uint _Crest_FirstCascadeIndex;
static const uint k_CascadeCount = 16;
static const uint k_CascadePackingCount = 4;
struct GerstnerCascadeParams
{
int _StartIndex;
};
StructuredBuffer<GerstnerCascadeParams> _Crest_GerstnerCascadeParams;
uint _Crest_FirstCascadeIndex;
uint4 _Crest_StartIndices[k_CascadeCount / k_CascadePackingCount];
float _Crest_TextureRes;
struct GerstnerWaveComponent4
{
@@ -29,6 +33,7 @@ struct GerstnerWaveComponent4
float4 _Omega;
float4 _Phase;
float4 _ChopAmplitude;
// Waves are generated in pairs, these values are for the second in the pair
float4 _Amplitude2;
float4 _ChopAmplitude2;
@@ -38,6 +43,8 @@ StructuredBuffer<GerstnerWaveComponent4> _Crest_GerstnerWaveData;
RWTexture2DArray<float4> _Crest_WaveBuffer;
m_CrestNameSpace
void ComputeGerstner( float2 worldPosXZ, float worldSize, GerstnerWaveComponent4 data, inout float3 result )
{
// direction
@@ -71,6 +78,7 @@ void ComputeGerstner( float2 worldPosXZ, float worldSize, GerstnerWaveComponent4
resulty = data._Amplitude * cosangle;
}
#if d_WavePairs
{
half4 angle = x + data._Phase2 + data._Omega * g_Crest_Time;
@@ -83,6 +91,7 @@ void ComputeGerstner( float2 worldPosXZ, float worldSize, GerstnerWaveComponent4
resulty += data._Amplitude2 * cosangle;
}
#endif
// sum the vector results
result.x += dot( resultx, 1.0 );
@@ -90,11 +99,11 @@ void ComputeGerstner( float2 worldPosXZ, float worldSize, GerstnerWaveComponent4
result.z += dot( resultz, 1.0 );
}
[numthreads(THREAD_GROUP_SIZE_X, THREAD_GROUP_SIZE_Y, 1)]
void Gerstner(uint3 id : SV_DispatchThreadID)
void Execute(uint3 id)
{
const uint cascadeIndex = id.z + _Crest_FirstCascadeIndex;
const float worldSize = 0.5f * (1 << cascadeIndex);
const uint cascadeIndex0 = id.z + _Crest_FirstCascadeIndex;
const uint cascadeIndex1 = min(cascadeIndex0 + 1, k_CascadeCount - 1);
const float worldSize = 0.5f * (1 << cascadeIndex0);
// Each cascade lies on XZ plane and starts from the origin
const float texelWidth = worldSize / _Crest_TextureRes;
@@ -102,13 +111,18 @@ void Gerstner(uint3 id : SV_DispatchThreadID)
float3 result = 0.0;
const int startIndex = _Crest_GerstnerCascadeParams[cascadeIndex]._StartIndex;
const int endIndex = _Crest_GerstnerCascadeParams[cascadeIndex + 1]._StartIndex;
for( int i = startIndex; i < endIndex; i++ )
const uint startIndex = _Crest_StartIndices[cascadeIndex0 / k_CascadePackingCount][cascadeIndex0 % k_CascadePackingCount];
const uint endIndex = _Crest_StartIndices[(cascadeIndex1 / k_CascadePackingCount)][cascadeIndex1 % k_CascadePackingCount];
for (uint i = startIndex; i < endIndex; i++)
{
// Sum up waves from another buffer
ComputeGerstner( worldPosXZ, worldSize, _Crest_GerstnerWaveData[i], result );
}
_Crest_WaveBuffer[uint3(id.xy, cascadeIndex)] = float4(result, 1.0);
_Crest_WaveBuffer[uint3(id.xy, cascadeIndex0)] = float4(result, 1.0);
}
m_CrestNameSpaceEnd
m_CrestKernelDefault(Execute)