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

@@ -5,6 +5,7 @@
#define CREST_WATER_NORMAL_H
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Settings.Crest.hlsl"
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Constants.hlsl"
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.hlsl"
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Texture.hlsl"
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Flow.hlsl"
@@ -13,12 +14,43 @@
#include "Packages/com.waveharmonic.crest.shifting-origin/Runtime/Shaders/ShiftingOrigin.hlsl"
#endif
#if _CREST_CUSTOM_MESH
float4 _Crest_NormalMapParameters[MAX_LOD_COUNT];
#define _Crest_ChunkNormalMapParameters _Crest_NormalMapParameters[i_CascadeData._IndexI]
#else
// These are per cascade, set per chunk instance.
float _Crest_ChunkFarNormalsWeight;
float2 _Crest_ChunkNormalScrollSpeed;
#define _Crest_ChunkNormalMapParameters float3(_Crest_ChunkNormalScrollSpeed, _Crest_ChunkFarNormalsWeight)
#endif
m_CrestNameSpace
// Limit how close to horizontal reflection ray can get, useful to avoid unsightly below-horizon reflections.
half3 ApplyMinimumReflectionDirectionY
(
const half i_MinimumReflectionDirectionY,
const half3 i_ViewDirectionWS,
const half3 i_NormalWS
)
{
half3 normal = i_NormalWS;
float3 refl = reflect(-i_ViewDirectionWS, normal);
if (refl.y < i_MinimumReflectionDirectionY)
{
// Find the normal that keeps the reflection direction above the horizon. Compute
// the reflection dir that does work, normalize it, and then normal is half vector
// between this good reflection direction and view direction.
float3 FL = refl;
FL.y = i_MinimumReflectionDirectionY;
FL = normalize(FL);
normal = normalize(FL + i_ViewDirectionWS);
}
return normal;
}
half2 SampleNormalMaps
(
const TiledTexture i_NormalMap,
@@ -35,28 +67,33 @@ half2 SampleNormalMaps
worldXZUndisplaced -= ShiftingOriginOffset(i_NormalMap, i_CascadeData);
#endif
const float3 parameters = _Crest_ChunkNormalMapParameters.xyz;
const float2 speed = parameters.xy;
const float farWeight = parameters.z;
const float2 v0 = float2(0.94, 0.34), v1 = float2(-0.85, -0.53);
float scale = i_NormalMap._scale * i_CascadeData._Scale / 10.0;
const float spdmulL = _Crest_ChunkNormalScrollSpeed.x * i_NormalMap._speed;
float scale = i_NormalMap._scale * i_CascadeData._Scale * 0.1;
const float time = i_NormalMap._speed * g_Crest_Time;
const float spdmulL = speed.x * time;
half2 norm =
UnpackNormal(i_NormalMap.Sample((worldXZUndisplaced + v0 * g_Crest_Time * spdmulL) / scale)).xy +
UnpackNormal(i_NormalMap.Sample((worldXZUndisplaced + v1 * g_Crest_Time * spdmulL) / scale)).xy;
UnpackNormal(i_NormalMap.Sample((worldXZUndisplaced + v0 * spdmulL) / scale)).xy +
UnpackNormal(i_NormalMap.Sample((worldXZUndisplaced + v1 * spdmulL) / scale)).xy;
// blend in next higher scale of normals to obtain continuity
const half nblend = i_LodAlpha * _Crest_ChunkFarNormalsWeight;
const half nblend = i_LodAlpha * farWeight;
if (nblend > 0.001)
{
// next lod level
scale *= 2.0;
const float spdmulH = _Crest_ChunkNormalScrollSpeed.y * i_NormalMap._speed;
const float spdmulH = speed.y * time;
norm = lerp(norm,
UnpackNormal(i_NormalMap.Sample((worldXZUndisplaced + v0 * g_Crest_Time * spdmulH) / scale)).xy +
UnpackNormal(i_NormalMap.Sample((worldXZUndisplaced + v1 * g_Crest_Time * spdmulH) / scale)).xy,
UnpackNormal(i_NormalMap.Sample((worldXZUndisplaced + v0 * spdmulH) / scale)).xy +
UnpackNormal(i_NormalMap.Sample((worldXZUndisplaced + v1 * spdmulH) / scale)).xy,
nblend);
}
// approximate combine of normals. would be better if normals applied in local frame.
return i_Strength * norm;
return norm;
}
half2 SampleNormalMaps
@@ -86,42 +123,66 @@ half2 SampleNormalMaps
) * i_Flow._Weight1;
}
half NormalMapTurbulence
(
const half3 i_NormalWS,
const half2 i_NormalMap,
const half i_NormalMapStrength,
const half i_Coverage,
const half i_Strength,
const half3 i_ViewDirectionWS,
const half i_Determinant,
const half i_WaterLevel,
const float i_PixelZ,
const half3 i_PrimaryLightDirection
)
{
half strength = i_NormalMapStrength;
if (saturate(i_Coverage - i_Determinant) > 0)
{
// Add boosted normal map.
half3 normal = i_NormalWS;
normal.xz += i_NormalMap * i_Strength;
normal = normalize(normal);
// Increase normal map strength only if "sparkle".
if (dot(normal, normalize(i_ViewDirectionWS + i_PrimaryLightDirection)) >= 0.99)
{
// Height (100m) & distance (2m) cull. Looks odd up close and degrades up high.
const half cull = max(saturate(abs(_WorldSpaceCameraPos.y - i_WaterLevel) * 0.01), 1.0 - saturate(i_PixelZ * 0.5));
strength = lerp(i_Strength, strength, cull);
}
}
return strength;
}
void WaterNormal
(
const float2 i_WaterLevelDerivatives,
const half3 i_ViewDirectionWS,
const half i_MinimumReflectionDirectionY,
const half i_Strength,
const bool i_Underwater,
inout half3 io_NormalWS
)
{
// Account for water level changes which change angle of water surface, impacting normal.
io_NormalWS.xz += -i_WaterLevelDerivatives;
// Finalise normal
io_NormalWS = normalize(io_NormalWS);
if (i_Underwater)
if (i_Strength < 1.0)
{
return;
io_NormalWS.xz *= i_Strength;
io_NormalWS.y = lerp(1.0, io_NormalWS.y, i_Strength);
}
// Limit how close to horizontal reflection ray can get, useful to avoid unsightly below-horizon reflections.
if (i_Underwater)
{
float3 refl = reflect(-i_ViewDirectionWS, io_NormalWS);
if (refl.y < i_MinimumReflectionDirectionY)
{
// Find the normal that keeps the reflection direction above the horizon. Compute
// the reflection dir that does work, normalize it, and then normal is half vector
// between this good reflection direction and view direction.
float3 FL = refl;
FL.y = i_MinimumReflectionDirectionY;
FL = normalize(FL);
io_NormalWS = normalize(FL + i_ViewDirectionWS);
}
// Flip when underwater.
io_NormalWS.xyz *= -1.0;
}
}
m_CrestNameSpaceEnd
#endif