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

@@ -63,7 +63,7 @@ Shader "Crest/Inputs/Albedo/Color"
float3 positionWS = mul(unity_ObjectToWorld, float4(input.vertex, 1.0)).xyz;
positionWS.xz -= _Crest_DisplacementAtInputPosition.xz;
output.vertex = mul(UNITY_MATRIX_VP, float4(positionWS, 1.0));
output.uv = input.uv;
output.uv = TRANSFORM_TEX(input.uv, _Crest_Texture);
output.color = input.color;
return output;
}

View File

@@ -90,7 +90,7 @@ Shader "Crest/Inputs/Dynamic Waves/Add Bump"
y = pow(y, 0.05);
y *= _Crest_Amplitude;
y /= g_Crest_LodCount;
y /= (float)g_Crest_LodCount;
// Feather edges to reduce streaking without introducing reflections.
y *= FeatherWeightFromUV(input.uv, 0.1);
@@ -107,4 +107,5 @@ Shader "Crest/Inputs/Dynamic Waves/Add Bump"
ENDCG
}
}
CustomEditor "WaveHarmonic.Crest.Editor.CustomShaderGUI"
}

View File

@@ -1,6 +1,8 @@
// Crest Water System
// Copyright © 2024 Wave Harmonic. All rights reserved.
#pragma exclude_renderers glcore gles3
#pragma kernel CrestExecute
#include "HLSLSupport.cginc"

View File

@@ -1,6 +1,8 @@
// Crest Water System
// Copyright © 2024 Wave Harmonic. All rights reserved.
#pragma exclude_renderers glcore gles3
#pragma kernel CrestTransferWaves
#pragma multi_compile_local __ d_Texture d_TextureBlend
@@ -11,6 +13,7 @@
#include "HLSLSupport.cginc"
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Filtering.hlsl"
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.hlsl"
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Constants.hlsl"
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Globals.hlsl"
@@ -23,6 +26,7 @@ Texture2DArray _Crest_WaveBuffer;
RWTexture2DArray<float4> _Crest_Target;
CBUFFER_START(CrestPerMaterial)
float _Crest_WaveBufferAttenuation[k_Crest_WaveOctaveCount];
float4 _Crest_WaveBufferParameters[MAX_LOD_COUNT];
float2 _Crest_AxisX;
float _Crest_Weight;
@@ -32,12 +36,15 @@ float _Crest_RespectShallowWaterAttenuation;
float _Crest_MaximumAttenuationDepth;
float _Crest_WaveResolutionMultiplier;
float _Crest_TransitionalWavelengthThreshold;
uint _Crest_Resolution;
bool _Crest_SeaLevelOnly;
// Texture
#if d_Texture
float2 _Crest_TextureSize;
float2 _Crest_TexturePosition;
float2 _Crest_TextureRotation;
float2 _Crest_Multiplier;
bool _Crest_NegativeValues;
int _Crest_Blend;
#endif
@@ -60,6 +67,8 @@ void TransferWaves(uint3 id)
const uint last = parameters.y;
const half transition = parameters.w;
const uint2 resolution = uint2(_Crest_Resolution, _Crest_Resolution);
#if !d_TextureBlend
// Additive only. All wavelengths filtered out for this LOD so nothing to do.
if (parameters.x < 0 || parameters.y < 0)
@@ -95,7 +104,7 @@ void TransferWaves(uint3 id)
float2 axis; float axisLength = 0.0; float t = 0.0;
float2 axisX0 = 0.0; float2 axisX1 = 0.0; float2 axisZ0 = 0.0; float2 axisZ1 = 0.0;
{
axis = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uvPainted, 0).xy;
axis = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uvPainted, 0).xy * _Crest_Multiplier;
if (!_Crest_NegativeValues)
{
@@ -154,11 +163,12 @@ void TransferWaves(uint3 id)
axisZ1.x = -axisX1.y; axisZ1.y = axisX1.x;
}
#else
const float2 positionWaves = float2(dot(positionWS, _Crest_AxisX), dot(positionWS, float2(-_Crest_AxisX.y, _Crest_AxisX.x)));
#endif // d_Texture
const half depth = Cascade::MakeDepth(slice0).SampleSignedDepthFromSeaLevel(positionWS) +
Cascade::MakeLevel(slice0).SampleLevel(positionWS);
const half level = Cascade::MakeLevel(slice0).SampleLevel(positionWS);
const half depth = Cascade::MakeDepth(slice0).SampleSignedDepthFromSeaLevel(positionWS) + level;
half3 _displacement = 0.0;
@@ -198,8 +208,7 @@ void TransferWaves(uint3 id)
weight = lerp(weight, 1.0, saturate(depth / _Crest_MaximumAttenuationDepth));
}
const float attenuationAmount = _Crest_AttenuationInShallows * _Crest_RespectShallowWaterAttenuation;
const float attenuationAmount = _Crest_AttenuationInShallows * _Crest_RespectShallowWaterAttenuation * _Crest_WaveBufferAttenuation[i];
attenuation = attenuationAmount * weight + (1.0 - attenuationAmount);
}
@@ -217,8 +226,8 @@ void TransferWaves(uint3 id)
const float2 uv1 = float2(dot(positionScaledWS, axisX1), dot(positionScaledWS, axisZ1));
// Sample displacement, rotate into frame.
float3 displacement0 = _Crest_WaveBuffer.SampleLevel(sampler_Crest_linear_repeat, float3(uv0, waveBufferIndex), 0).xyz;
float3 displacement1 = _Crest_WaveBuffer.SampleLevel(sampler_Crest_linear_repeat, float3(uv1, waveBufferIndex), 0).xyz;
const float3 displacement0 = Utility::SampleBicubicRepeat(_Crest_WaveBuffer, uv0, resolution, waveBufferIndex).xyz;
const float3 displacement1 = Utility::SampleBicubicRepeat(_Crest_WaveBuffer, uv1, resolution, waveBufferIndex).xyz;
float3 displacement = lerp(displacement0, displacement1, t);
displacement.xz = displacement.x * axis + displacement.z * float2(-axis.y, axis.x);
@@ -227,7 +236,9 @@ void TransferWaves(uint3 id)
#else // !d_Texture
// Sample displacement, rotate into frame defined by global wind direction.
half3 displacement = _Crest_WaveBuffer.SampleLevel(sampler_Crest_linear_repeat, float3(positionWaves / waveBufferSize, waveBufferIndex), 0).xyz;
// Hardware bilinear produces small noise artifacts. Custom bilinear solves that,
// but we still get texel artifacts that show up in normals, so use bicubic.
float3 displacement = Utility::SampleBicubicRepeat(_Crest_WaveBuffer, positionWaves / waveBufferSize, resolution, waveBufferIndex).xyz;
displacement.xz = displacement.x * _Crest_AxisX + displacement.z * float2(-_Crest_AxisX.y, _Crest_AxisX.x);
_displacement += displacement * weight;
#endif // d_Texture
@@ -239,6 +250,13 @@ void TransferWaves(uint3 id)
_Crest_Target[id] *= 1.0 - saturate(alpha);
#endif
#if !d_Texture
if (_Crest_SeaLevelOnly)
{
_displacement *= saturate(1.0 - abs(level));
}
#endif
// Always write full alpha so textures show up in previews.
_Crest_Target[id] += float4(_displacement, 1.0);
}

View File

@@ -1,6 +1,8 @@
// Crest Water System
// Copyright © 2024 Wave Harmonic. All rights reserved.
#pragma exclude_renderers glcore gles3
#pragma kernel CrestExecute
#pragma multi_compile_local d_Sphere d_Cube d_Rectangle

View File

@@ -3,6 +3,8 @@
// Adds clipping from a provided texture. Used by Painted and Texture input modes.
#pragma exclude_renderers glcore gles3
#pragma kernel CrestExecute
#include "HLSLSupport.cginc"

View File

@@ -6,6 +6,8 @@
// afterwards. It is converted to world-space in another shader before writing into
// the LOD data.
#pragma exclude_renderers glcore gles3
#pragma kernel CrestCopy
#pragma kernel CrestFill
@@ -17,7 +19,7 @@
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Globals.hlsl"
Texture2D<float> _CamDepthBuffer;
RWTexture2D<float2> _Crest_Target;
RWTexture2D<m_Float2> _Crest_Target;
#if d_Crest_BackFaceInclusion
Texture2D<float> _Crest_CameraDepthBufferBackfaces;

View File

@@ -5,6 +5,8 @@
// from an ODC, then they are in object-space and are converted to world-space as
// the LOD data stores world-space height.
#pragma exclude_renderers glcore gles3
#pragma kernel CrestExecute
#pragma multi_compile_local __ d_CrestSDF
@@ -22,14 +24,14 @@
#if d_CrestSDF
#undef m_CrestType
#define m_CrestType float2
#define m_CrestType m_Float2
#endif
Texture2D<m_CrestType> _Crest_Texture;
RWTexture2DArray<m_CrestType> _Crest_Target;
CBUFFER_START(CrestInputTexture)
float2 _Crest_Multiplier;
m_CrestType _Crest_Multiplier;
float2 _Crest_TextureSize;
float2 _Crest_TexturePosition;
float2 _Crest_TextureRotation;

View File

@@ -3,6 +3,8 @@
// Adds flow from a provided texture. Used by Painted and Texture input modes.
#pragma exclude_renderers glcore gles3
#pragma kernel CrestExecute
#include "HLSLSupport.cginc"
@@ -15,7 +17,7 @@
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Cascade.hlsl"
Texture2D _Crest_Texture;
RWTexture2DArray<float2> _Crest_Target;
RWTexture2DArray<m_Float2> _Crest_Target;
CBUFFER_START(CrestPerMaterial)
int _Crest_Blend;
@@ -62,7 +64,8 @@ void Execute(uint3 id)
}
const float2 target = _Crest_Target[id];
_Crest_Target[id] = Blend(_Crest_Blend, weight, 1.0, source, target);
const float2 result = Blend(_Crest_Blend, weight, 1.0, source, target);
_Crest_Target[id] = m_Float2FromFloat2(result);
}
m_CrestNameSpaceEnd

View File

@@ -3,6 +3,8 @@
// Adds foam from a provided texture. Used by Painted and Texture input modes.
#pragma exclude_renderers glcore gles3
#pragma kernel CrestExecute
#include "HLSLSupport.cginc"

View File

@@ -4,6 +4,8 @@
// An implementation of the Jump Flood algorithm by Rong and Tan
// Source: https://www.comp.nus.edu.sg/~tants/jfa.html
#pragma exclude_renderers glcore gles3
#pragma kernel CrestInitialize
#pragma kernel CrestExecute
#pragma kernel CrestApply
@@ -27,13 +29,13 @@ float _Crest_WaterLevel;
CBUFFER_END
// Holds scene depth for initialization.
Texture2D<float2> _Crest_Source;
RWTexture2D<float2> _Crest_Target;
Texture2D<m_Float2> _Crest_Source;
RWTexture2D<m_Float2> _Crest_Target;
// Setting this to zero means that geometry at exactly the origin won't be handled
// gracefully - but it would only affect a single-pixel in the worst-case and would
// doubtfully be noticable anyway. Use infinity instead.
#define m_CrestUninitializedPosition float2(m_Crest_PositiveInfinity, m_Crest_PositiveInfinity)
#define m_CrestUninitializedPosition m_Float2Constructor(m_Crest_PositiveInfinity, m_Crest_PositiveInfinity)
#if d_Crest_Inverted
#define m_DepthCheck depth > 0.0
@@ -62,11 +64,11 @@ void Initialize(const uint3 id)
#ifndef d_Crest_Standalone
// Add height offset.
uint slice0; uint slice1; float alpha;
PosToSliceIndices(position, 0, g_Crest_LodCount - 1, g_Crest_WaterScale, slice0, slice1, alpha);
PositionToSliceIndices(position, 0, g_Crest_LodCount - 1, g_Crest_WaterScale, slice0, slice1, alpha);
depth += lerp(Cascade::MakeLevel(slice0).SampleLevel(position), Cascade::MakeLevel(slice1).SampleLevel(position), alpha);
#endif
_Crest_Target[id.xy] = m_DepthCheck ? position : m_CrestUninitializedPosition;
_Crest_Target[id.xy] = m_DepthCheck ? m_Float2FromFloat2(position) : m_CrestUninitializedPosition;
}
void Execute(const uint3 id)
@@ -111,7 +113,7 @@ void Execute(const uint3 id)
}
}
_Crest_Target[id.xy] = nearest;
_Crest_Target[id.xy] = m_Float2FromFloat2(nearest);
}
void Apply(const uint3 id)
@@ -125,7 +127,7 @@ void Apply(const uint3 id)
#ifndef d_Crest_Standalone
// Get depth including height offset.
uint slice0; uint slice1; float alpha;
PosToSliceIndices(position, 0, g_Crest_LodCount - 1, g_Crest_WaterScale, slice0, slice1, alpha);
PositionToSliceIndices(position, 0, g_Crest_LodCount - 1, g_Crest_WaterScale, slice0, slice1, alpha);
depth += lerp(Cascade::MakeLevel(slice0).SampleLevel(position), Cascade::MakeLevel(slice1).SampleLevel(position), alpha);
#endif
@@ -144,7 +146,7 @@ void Apply(const uint3 id)
result.y = distance;
_Crest_Target[id.xy] = result;
_Crest_Target[id.xy] = m_Float2FromFloat2(result);
}
m_CrestNameSpaceEnd

View File

@@ -3,6 +3,8 @@
// Adds height from a provided texture. Used by Painted and Texture input modes.
#pragma exclude_renderers glcore gles3
#pragma kernel CrestExecute
#pragma multi_compile_local __ d_CatmullRom
@@ -27,7 +29,7 @@ float _Crest_Multiplier;
float2 _Crest_TextureSize;
float2 _Crest_TexturePosition;
float2 _Crest_TextureRotation;
float2 _Crest_Resolution;
float2 _Crest_TextureResolution;
CBUFFER_END
m_CrestNameSpace
@@ -49,7 +51,7 @@ void Execute(uint3 id)
}
#if d_CatmullRom
const float source = Utility::SampleTextureCatmullRom(_Crest_Texture, LODData_linear_clamp_sampler, uv, _Crest_Resolution)
const float source = Utility::SampleTextureCatmullRom(_Crest_Texture, LODData_linear_clamp_sampler, uv, _Crest_TextureResolution)
#else
const float source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0.0)
#endif

View File

@@ -1,6 +1,8 @@
// Crest Water System
// Copyright © 2024 Wave Harmonic. All rights reserved.
#pragma exclude_renderers glcore gles3
#pragma kernel CrestExecute
#include "HLSLSupport.cginc"

View File

@@ -1,6 +1,8 @@
// Crest Water System
// Copyright © 2024 Wave Harmonic. All rights reserved.
#pragma exclude_renderers glcore gles3
#pragma kernel CrestExecute
#include "HLSLSupport.cginc"
@@ -12,7 +14,7 @@
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/InputsDriven.hlsl"
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Cascade.hlsl"
RWTexture2DArray<float2> _Crest_Target;
RWTexture2DArray<m_Float2> _Crest_Target;
CBUFFER_START(CrestPerWaterInput)
float3 _Crest_Position;
@@ -116,7 +118,7 @@ void Execute(uint3 id)
// Helps interaction to work at different scales
acceleration /= minimumWavelength;
_Crest_Target[id] = float2(_Crest_Target[id].x, _Crest_Target[id].y + acceleration * _Crest_SimDeltaTime);
_Crest_Target[id] = m_Float2Constructor(_Crest_Target[id].x, _Crest_Target[id].y + acceleration * _Crest_SimDeltaTime);
}
m_CrestNameSpaceEnd

View File

@@ -110,7 +110,7 @@ Shader "Crest/Inputs/All/Scale"
half4 Frag(Varyings input) : SV_Target
{
#if d_Texture
float scale = _Crest_Texture.Sample(sampler_Crest_Texture, input.uv).r;
float scale = _Crest_Texture.Sample(sampler_Crest_Texture, TRANSFORM_TEX(input.uv, _Crest_Texture)).r;
#else
float scale = _Crest_Scale;
#endif

View File

@@ -50,6 +50,7 @@ Shader "Crest/Inputs/Shape Waves/Add From Geometry"
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Helpers.hlsl"
Texture2DArray _Crest_WaveBuffer;
SamplerState sampler_Crest_linear_repeat;
CBUFFER_START(CrestPerWaterInput)
float _Crest_RespectShallowWaterAttenuation;