还原水插件
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#pragma exclude_renderers glcore gles3
|
||||
|
||||
#pragma kernel CrestExecute
|
||||
|
||||
#include "HLSLSupport.cginc"
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// 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
|
||||
@@ -13,7 +11,6 @@
|
||||
|
||||
#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"
|
||||
@@ -35,8 +32,6 @@ float _Crest_RespectShallowWaterAttenuation;
|
||||
float _Crest_MaximumAttenuationDepth;
|
||||
float _Crest_WaveResolutionMultiplier;
|
||||
float _Crest_TransitionalWavelengthThreshold;
|
||||
uint _Crest_Resolution;
|
||||
bool _Crest_SeaLevelOnly;
|
||||
|
||||
// Texture
|
||||
#if d_Texture
|
||||
@@ -65,8 +60,6 @@ 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)
|
||||
@@ -161,12 +154,11 @@ 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 level = Cascade::MakeLevel(slice0).SampleLevel(positionWS);
|
||||
const half depth = Cascade::MakeDepth(slice0).SampleSignedDepthFromSeaLevel(positionWS) + level;
|
||||
const half depth = Cascade::MakeDepth(slice0).SampleSignedDepthFromSeaLevel(positionWS) +
|
||||
Cascade::MakeLevel(slice0).SampleLevel(positionWS);
|
||||
|
||||
half3 _displacement = 0.0;
|
||||
|
||||
@@ -225,8 +217,8 @@ void TransferWaves(uint3 id)
|
||||
const float2 uv1 = float2(dot(positionScaledWS, axisX1), dot(positionScaledWS, axisZ1));
|
||||
|
||||
// Sample displacement, rotate into frame.
|
||||
const float3 displacement0 = Utility::SampleBicubicRepeat(_Crest_WaveBuffer, uv0, resolution, waveBufferIndex).xyz;
|
||||
const float3 displacement1 = Utility::SampleBicubicRepeat(_Crest_WaveBuffer, uv1, resolution, waveBufferIndex).xyz;
|
||||
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;
|
||||
|
||||
float3 displacement = lerp(displacement0, displacement1, t);
|
||||
displacement.xz = displacement.x * axis + displacement.z * float2(-axis.y, axis.x);
|
||||
@@ -235,9 +227,7 @@ void TransferWaves(uint3 id)
|
||||
|
||||
#else // !d_Texture
|
||||
// Sample displacement, rotate into frame defined by global wind direction.
|
||||
// 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;
|
||||
half3 displacement = _Crest_WaveBuffer.SampleLevel(sampler_Crest_linear_repeat, float3(positionWaves / waveBufferSize, waveBufferIndex), 0).xyz;
|
||||
displacement.xz = displacement.x * _Crest_AxisX + displacement.z * float2(-_Crest_AxisX.y, _Crest_AxisX.x);
|
||||
_displacement += displacement * weight;
|
||||
#endif // d_Texture
|
||||
@@ -249,13 +239,6 @@ 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);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// 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
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
|
||||
// Adds clipping from a provided texture. Used by Painted and Texture input modes.
|
||||
|
||||
#pragma exclude_renderers glcore gles3
|
||||
|
||||
#pragma kernel CrestExecute
|
||||
|
||||
#include "HLSLSupport.cginc"
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
// 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
|
||||
|
||||
@@ -19,7 +17,7 @@
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Globals.hlsl"
|
||||
|
||||
Texture2D<float> _CamDepthBuffer;
|
||||
RWTexture2D<m_Float2> _Crest_Target;
|
||||
RWTexture2D<float2> _Crest_Target;
|
||||
|
||||
#if d_Crest_BackFaceInclusion
|
||||
Texture2D<float> _Crest_CameraDepthBufferBackfaces;
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
// 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
|
||||
@@ -24,14 +22,14 @@
|
||||
|
||||
#if d_CrestSDF
|
||||
#undef m_CrestType
|
||||
#define m_CrestType m_Float2
|
||||
#define m_CrestType float2
|
||||
#endif
|
||||
|
||||
Texture2D<m_CrestType> _Crest_Texture;
|
||||
RWTexture2DArray<m_CrestType> _Crest_Target;
|
||||
|
||||
CBUFFER_START(CrestInputTexture)
|
||||
m_CrestType _Crest_Multiplier;
|
||||
float2 _Crest_Multiplier;
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
|
||||
// Adds flow from a provided texture. Used by Painted and Texture input modes.
|
||||
|
||||
#pragma exclude_renderers glcore gles3
|
||||
|
||||
#pragma kernel CrestExecute
|
||||
|
||||
#include "HLSLSupport.cginc"
|
||||
@@ -17,7 +15,7 @@
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Cascade.hlsl"
|
||||
|
||||
Texture2D _Crest_Texture;
|
||||
RWTexture2DArray<m_Float2> _Crest_Target;
|
||||
RWTexture2DArray<float2> _Crest_Target;
|
||||
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
int _Crest_Blend;
|
||||
@@ -64,8 +62,7 @@ void Execute(uint3 id)
|
||||
}
|
||||
|
||||
const float2 target = _Crest_Target[id];
|
||||
const float2 result = Blend(_Crest_Blend, weight, 1.0, source, target);
|
||||
_Crest_Target[id] = m_Float2FromFloat2(result);
|
||||
_Crest_Target[id] = Blend(_Crest_Blend, weight, 1.0, source, target);
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
|
||||
// Adds foam from a provided texture. Used by Painted and Texture input modes.
|
||||
|
||||
#pragma exclude_renderers glcore gles3
|
||||
|
||||
#pragma kernel CrestExecute
|
||||
|
||||
#include "HLSLSupport.cginc"
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
// 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
|
||||
@@ -29,13 +27,13 @@ float _Crest_WaterLevel;
|
||||
CBUFFER_END
|
||||
|
||||
// Holds scene depth for initialization.
|
||||
Texture2D<m_Float2> _Crest_Source;
|
||||
RWTexture2D<m_Float2> _Crest_Target;
|
||||
Texture2D<float2> _Crest_Source;
|
||||
RWTexture2D<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 m_Float2Constructor(m_Crest_PositiveInfinity, m_Crest_PositiveInfinity)
|
||||
#define m_CrestUninitializedPosition float2(m_Crest_PositiveInfinity, m_Crest_PositiveInfinity)
|
||||
|
||||
#if d_Crest_Inverted
|
||||
#define m_DepthCheck depth > 0.0
|
||||
@@ -68,7 +66,7 @@ void Initialize(const uint3 id)
|
||||
depth += lerp(Cascade::MakeLevel(slice0).SampleLevel(position), Cascade::MakeLevel(slice1).SampleLevel(position), alpha);
|
||||
#endif
|
||||
|
||||
_Crest_Target[id.xy] = m_DepthCheck ? m_Float2FromFloat2(position) : m_CrestUninitializedPosition;
|
||||
_Crest_Target[id.xy] = m_DepthCheck ? position : m_CrestUninitializedPosition;
|
||||
}
|
||||
|
||||
void Execute(const uint3 id)
|
||||
@@ -113,7 +111,7 @@ void Execute(const uint3 id)
|
||||
}
|
||||
}
|
||||
|
||||
_Crest_Target[id.xy] = m_Float2FromFloat2(nearest);
|
||||
_Crest_Target[id.xy] = nearest;
|
||||
}
|
||||
|
||||
void Apply(const uint3 id)
|
||||
@@ -146,7 +144,7 @@ void Apply(const uint3 id)
|
||||
|
||||
result.y = distance;
|
||||
|
||||
_Crest_Target[id.xy] = m_Float2FromFloat2(result);
|
||||
_Crest_Target[id.xy] = result;
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
|
||||
// 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
|
||||
@@ -29,7 +27,7 @@ float _Crest_Multiplier;
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
float2 _Crest_TextureResolution;
|
||||
float2 _Crest_Resolution;
|
||||
CBUFFER_END
|
||||
|
||||
m_CrestNameSpace
|
||||
@@ -51,7 +49,7 @@ void Execute(uint3 id)
|
||||
}
|
||||
|
||||
#if d_CatmullRom
|
||||
const float source = Utility::SampleTextureCatmullRom(_Crest_Texture, LODData_linear_clamp_sampler, uv, _Crest_TextureResolution)
|
||||
const float source = Utility::SampleTextureCatmullRom(_Crest_Texture, LODData_linear_clamp_sampler, uv, _Crest_Resolution)
|
||||
#else
|
||||
const float source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0.0)
|
||||
#endif
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#pragma exclude_renderers glcore gles3
|
||||
|
||||
#pragma kernel CrestExecute
|
||||
|
||||
#include "HLSLSupport.cginc"
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#pragma exclude_renderers glcore gles3
|
||||
|
||||
#pragma kernel CrestExecute
|
||||
|
||||
#include "HLSLSupport.cginc"
|
||||
@@ -14,7 +12,7 @@
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/InputsDriven.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Cascade.hlsl"
|
||||
|
||||
RWTexture2DArray<m_Float2> _Crest_Target;
|
||||
RWTexture2DArray<float2> _Crest_Target;
|
||||
|
||||
CBUFFER_START(CrestPerWaterInput)
|
||||
float3 _Crest_Position;
|
||||
@@ -118,7 +116,7 @@ void Execute(uint3 id)
|
||||
// Helps interaction to work at different scales
|
||||
acceleration /= minimumWavelength;
|
||||
|
||||
_Crest_Target[id] = m_Float2Constructor(_Crest_Target[id].x, _Crest_Target[id].y + acceleration * _Crest_SimDeltaTime);
|
||||
_Crest_Target[id] = float2(_Crest_Target[id].x, _Crest_Target[id].y + acceleration * _Crest_SimDeltaTime);
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
Reference in New Issue
Block a user