升级6.4.升级水,升级天气
This commit is contained in:
@@ -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)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user