还原水插件

This commit is contained in:
2026-03-05 00:14:42 +08:00
parent 0de35591e7
commit e82f2ea6b7
270 changed files with 2773 additions and 12445 deletions

View File

@@ -5,7 +5,6 @@
#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"
@@ -14,43 +13,12 @@
#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,
@@ -67,24 +35,20 @@ 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 = speed.x * i_NormalMap._speed;
const float spdmulL = _Crest_ChunkNormalScrollSpeed.x * i_NormalMap._speed;
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;
// blend in next higher scale of normals to obtain continuity
const half nblend = i_LodAlpha * farWeight;
const half nblend = i_LodAlpha * _Crest_ChunkFarNormalsWeight;
if (nblend > 0.001)
{
// next lod level
scale *= 2.0;
const float spdmulH = speed.y * i_NormalMap._speed;
const float spdmulH = _Crest_ChunkNormalScrollSpeed.y * i_NormalMap._speed;
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,
@@ -92,7 +56,7 @@ half2 SampleNormalMaps
}
// approximate combine of normals. would be better if normals applied in local frame.
return norm;
return i_Strength * norm;
}
half2 SampleNormalMaps
@@ -122,41 +86,6 @@ 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,
@@ -177,11 +106,22 @@ void WaterNormal
return;
}
io_NormalWS = ApplyMinimumReflectionDirectionY(i_MinimumReflectionDirectionY, i_ViewDirectionWS, io_NormalWS);
// Limit how close to horizontal reflection ray can get, useful to avoid unsightly below-horizon reflections.
{
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);
}
}
}
m_CrestNameSpaceEnd
#endif