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