升级水插件
This commit is contained in:
@@ -20,10 +20,12 @@ Shader "Crest/Inputs/Absorption/Color"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ZWrite Off
|
||||
ColorMask RGB
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
@@ -19,12 +19,13 @@ Shader "Crest/Inputs/Albedo/Color"
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend [_Crest_BlendModeSource] [_Crest_BlendModeTarget]
|
||||
|
||||
ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
|
||||
@@ -18,6 +18,8 @@ Shader "Crest/Inputs/Animated Waves/Add From Texture"
|
||||
SubShader
|
||||
{
|
||||
Blend One One
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
@@ -25,7 +27,7 @@ Shader "Crest/Inputs/Animated Waves/Add From Texture"
|
||||
#pragma vertex Vert
|
||||
#pragma fragment Frag
|
||||
|
||||
#pragma shader_feature_local d_HeightsOnly
|
||||
#pragma shader_feature_local_fragment d_HeightsOnly
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Push water under the geometry. Needs to be rendered into all LODs - set Octave Wave length to 0.
|
||||
@@ -13,6 +13,9 @@ Shader "Crest/Inputs/Animated Waves/Push Water Under Convex Hull"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
BlendOp Min
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// This writes straight into the displacement texture and sets the water height to the y value of the geometry.
|
||||
@@ -16,6 +16,9 @@ Shader "Crest/Inputs/Animated Waves/Set Water Height Using Geometry"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend Off
|
||||
|
||||
@@ -16,6 +16,9 @@ Shader "Crest/Inputs/Animated Waves/Wave Particle"
|
||||
{
|
||||
Tags { "DisableBatching" = "True" }
|
||||
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend One One
|
||||
|
||||
@@ -14,6 +14,9 @@ Shader "Crest/Inputs/Dynamic Waves/Add Bump"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend One One
|
||||
|
||||
@@ -14,6 +14,9 @@ Shader "Crest/Inputs/Dynamic Waves/Dampen Circle"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
|
||||
@@ -26,6 +26,8 @@ Shader "Crest/Inputs/Flow/Add From Texture"
|
||||
SubShader
|
||||
{
|
||||
Blend One One
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
@@ -33,10 +35,10 @@ Shader "Crest/Inputs/Flow/Add From Texture"
|
||||
#pragma vertex Vert
|
||||
#pragma fragment Frag
|
||||
|
||||
#pragma shader_feature_local d_FlipX
|
||||
#pragma shader_feature_local d_FlipZ
|
||||
#pragma shader_feature_local d_Feather
|
||||
#pragma shader_feature_local d_NegativeValues
|
||||
#pragma shader_feature_local_fragment d_FlipX
|
||||
#pragma shader_feature_local_fragment d_FlipZ
|
||||
#pragma shader_feature_local_fragment d_Feather
|
||||
#pragma shader_feature_local_fragment d_NegativeValues
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
|
||||
@@ -21,6 +21,9 @@ Shader "Crest/Inputs/Flow/Fixed Direction"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
@@ -28,7 +31,7 @@ Shader "Crest/Inputs/Flow/Fixed Direction"
|
||||
#pragma fragment Frag
|
||||
|
||||
#pragma shader_feature_local d_Feather
|
||||
#pragma shader_feature_local d_ApplyRotation
|
||||
#pragma shader_feature_local_fragment d_ApplyRotation
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ Shader "Crest/Inputs/Foam/Add From Texture"
|
||||
SubShader
|
||||
{
|
||||
Blend One One
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Crest/Inputs/Foam/Add From Vertex Colors"
|
||||
@@ -14,6 +14,8 @@ Shader "Crest/Inputs/Foam/Add From Vertex Colors"
|
||||
SubShader
|
||||
{
|
||||
Blend One One
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
|
||||
@@ -18,6 +18,7 @@ RWTexture2DArray<float3> _Crest_Target;
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
int _Crest_Blend;
|
||||
float _Crest_Weight;
|
||||
float4 _Crest_Multiplier;
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
@@ -42,7 +43,7 @@ void Execute(uint3 id)
|
||||
return;
|
||||
}
|
||||
|
||||
const half4 source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0);
|
||||
const half4 source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0) * _Crest_Multiplier;
|
||||
const half3 target = _Crest_Target[id];
|
||||
weight *= source.a;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Renders convex hull to the clip surface texture.
|
||||
@@ -70,8 +70,9 @@ Shader "Hidden/Crest/Inputs/Clip/Convex Hull"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZWrite Off
|
||||
ColorMask R
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
|
||||
@@ -18,6 +18,7 @@ Texture2D _Crest_Texture;
|
||||
RWTexture2DArray<float> _Crest_Target;
|
||||
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
float _Crest_Multiplier;
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
@@ -36,7 +37,7 @@ void Execute(uint3 id)
|
||||
return;
|
||||
}
|
||||
|
||||
const float result = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0).x;
|
||||
const float result = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0).x * _Crest_Multiplier;
|
||||
|
||||
// Painted clip defines a minimum value of the clip.
|
||||
_Crest_Target[id] = max(_Crest_Target[id], result);
|
||||
|
||||
@@ -29,6 +29,7 @@ Texture2D<m_CrestType> _Crest_Texture;
|
||||
RWTexture2DArray<m_CrestType> _Crest_Target;
|
||||
|
||||
CBUFFER_START(CrestInputTexture)
|
||||
float2 _Crest_Multiplier;
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
@@ -50,7 +51,7 @@ void Execute(uint3 id)
|
||||
}
|
||||
|
||||
m_CrestType current = _Crest_Target[id];
|
||||
m_CrestType result = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0);
|
||||
m_CrestType result = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0) * _Crest_Multiplier;
|
||||
result.x += _Crest_HeightOffset;
|
||||
|
||||
// Take highest terrain height.
|
||||
|
||||
@@ -20,6 +20,7 @@ RWTexture2DArray<float2> _Crest_Target;
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
int _Crest_Blend;
|
||||
float _Crest_Weight;
|
||||
float2 _Crest_Multiplier;
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
@@ -53,6 +54,8 @@ void Execute(uint3 id)
|
||||
source = source * 2.0 - 1.0;
|
||||
}
|
||||
|
||||
source *= _Crest_Multiplier;
|
||||
|
||||
if (_Crest_Blend == m_CrestBlendAlpha)
|
||||
{
|
||||
weight *= saturate(length(source));
|
||||
|
||||
@@ -20,6 +20,7 @@ RWTexture2DArray<float> _Crest_Target;
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
int _Crest_Blend;
|
||||
float _Crest_Weight;
|
||||
float _Crest_Multiplier;
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
@@ -45,7 +46,7 @@ void Execute(uint3 id)
|
||||
return;
|
||||
}
|
||||
|
||||
const float source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0).x;
|
||||
const float source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0).x * _Crest_Multiplier;
|
||||
const float target = _Crest_Target[id];
|
||||
|
||||
_Crest_Target[id] = Blend(_Crest_Blend, weight, _Crest_SimDeltaTime, source, target);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// An implementation of the Jump Flood algorithm by Rong and Tan
|
||||
|
||||
@@ -23,6 +23,7 @@ RWTexture2DArray<float> _Crest_Target;
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
int _Crest_Blend;
|
||||
float _Crest_Weight;
|
||||
float _Crest_Multiplier;
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
@@ -48,10 +49,11 @@ void Execute(uint3 id)
|
||||
}
|
||||
|
||||
#if d_CatmullRom
|
||||
const float source = Utility::SampleTextureCatmullRom(_Crest_Texture, LODData_linear_clamp_sampler, uv, _Crest_Resolution).x;
|
||||
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).x;
|
||||
const float source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0.0)
|
||||
#endif
|
||||
.x * _Crest_Multiplier;
|
||||
|
||||
const float target = _Crest_Target[id];
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ RWTexture2DArray<float3> _Crest_Target;
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
int _Crest_Blend;
|
||||
float _Crest_Weight;
|
||||
float4 _Crest_Multiplier;
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
@@ -42,7 +43,7 @@ void Execute(uint3 id)
|
||||
return;
|
||||
}
|
||||
|
||||
const half4 source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0);
|
||||
const half4 source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0) * _Crest_Multiplier;
|
||||
const half3 target = _Crest_Target[id];
|
||||
weight *= source.a;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Crest/Inputs/All/Override"
|
||||
@@ -15,11 +15,13 @@ Shader "Crest/Inputs/All/Override"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend Off
|
||||
ColorMask [_Crest_ColorMask]
|
||||
ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex Vertex
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// 0-1 scaling of existing water data using multiplicative blending.
|
||||
@@ -32,6 +32,9 @@ Shader "Crest/Inputs/All/Scale"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
// Multiply
|
||||
@@ -42,8 +45,8 @@ Shader "Crest/Inputs/All/Scale"
|
||||
#pragma fragment Frag
|
||||
|
||||
#pragma shader_feature_local d_Texture
|
||||
#pragma shader_feature_local d_Invert
|
||||
#pragma shader_feature_local d_Feather
|
||||
#pragma shader_feature_local_fragment d_Invert
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
|
||||
@@ -17,10 +17,12 @@ Shader "Crest/Inputs/Scattering/Color"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ZWrite Off
|
||||
ColorMask RGB
|
||||
|
||||
CGPROGRAM
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Generates waves from geometry that is rendered into the water simulation from a top down camera. Expects
|
||||
@@ -39,7 +39,7 @@ Shader "Crest/Inputs/Shape Waves/Add From Geometry"
|
||||
#pragma fragment Fragment
|
||||
// #pragma enable_d3d11_debug_symbols
|
||||
|
||||
#pragma shader_feature_local d_Feather
|
||||
#pragma shader_feature_local_fragment d_Feather
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Crest/Inputs/All/Utility"
|
||||
@@ -17,12 +17,14 @@ Shader "Crest/Inputs/All/Utility"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend [_Crest_BlendModeSource] [_Crest_BlendModeTarget]
|
||||
BlendOp [_Crest_BlendOperation]
|
||||
ColorMask [_Crest_ColorMask]
|
||||
ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex Vertex
|
||||
|
||||
@@ -12,6 +12,9 @@ Shader "Crest/Inputs/Depth/Water Depth From Geometry"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
BlendOp Max
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// This sets base water height to Y value of geometry.
|
||||
@@ -17,6 +17,9 @@ Shader "Crest/Inputs/Level/Water Level From Geometry"
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZTest Always
|
||||
ZWrite Off
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend [_Crest_BlendSource] [_Crest_BlendTarget]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#pragma kernel CrestPackLevel
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#pragma kernel CrestQueryDisplacement d_CrestDisplacement
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Merged into Query.compute.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Merged into Query.compute.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Compute shader to perform combine of displacements. Reads and writes to texture array which saves
|
||||
@@ -14,6 +14,7 @@
|
||||
#pragma kernel ShapeCombine_FLOW_ON_DYNAMIC_WAVE_SIM_ON _FLOW_ON _DYNAMIC_WAVE_SIM_ON
|
||||
#pragma kernel ShapeCombine_FLOW_ON_DYNAMIC_WAVE_SIM_ON_DISABLE_COMBINE _FLOW_ON _DYNAMIC_WAVE_SIM_ON _DISABLE_COMBINE
|
||||
#pragma kernel ShapeCombineDynamicWaves
|
||||
#pragma kernel ShapeCombineDynamicWaves_DISABLE_COMBINE _DISABLE_COMBINE
|
||||
#pragma kernel ShapeCombineCopyDynamicWaves
|
||||
|
||||
#include "HLSLSupport.cginc"
|
||||
@@ -107,6 +108,7 @@ void ShapeCombineBase(uint3 id)
|
||||
#endif // _FLOW_ON
|
||||
}
|
||||
|
||||
// Disabled for last LOD.
|
||||
#if !_DISABLE_COMBINE
|
||||
{
|
||||
const Cascade cascade = Cascade::MakeAnimatedWaves(slice0 + 1);
|
||||
@@ -136,14 +138,19 @@ void ShapeCombineDynamicWaves(uint3 id)
|
||||
const float2 positionWSXZ = cascade.UVToWorld(uv);
|
||||
float3 result = 0.0;
|
||||
|
||||
// Disabled for last LOD.
|
||||
#if !_DISABLE_COMBINE
|
||||
{
|
||||
const Cascade cascade = Cascade::MakeDynamicWaves(slice0 + 1);
|
||||
// We are sampling from the target which matches Animated Waves descriptor.
|
||||
const Cascade cascade = Cascade::MakeAnimatedWaves(slice0 + 1);
|
||||
const float3 uv = cascade.WorldToUV(positionWSXZ);
|
||||
// Waves to combine down from the next lod up the chain.
|
||||
SampleDisplacementsCompute(_Crest_DynamicWavesTarget, cascade._Resolution, uv, 1.0, result);
|
||||
}
|
||||
#endif
|
||||
|
||||
{
|
||||
// We are sampling from Dynamic Waves.
|
||||
const Cascade cascade = Cascade::MakeDynamicWaves(slice0);
|
||||
const float3 uv = cascade.WorldToUV(positionWSXZ);
|
||||
result += cascade.SampleDynamicWavesDisplacement(uv, _Crest_HorizontalDisplace, _Crest_DisplaceClamp);
|
||||
@@ -168,4 +175,5 @@ m_CrestNameSpaceEnd
|
||||
[numthreads(THREAD_GROUP_SIZE_X, THREAD_GROUP_SIZE_Y, 1)] void ShapeCombine_FLOW_ON_DYNAMIC_WAVE_SIM_ON(uint3 id : SV_DispatchThreadID) { m_Crest::ShapeCombineBase(id); }
|
||||
[numthreads(THREAD_GROUP_SIZE_X, THREAD_GROUP_SIZE_Y, 1)] void ShapeCombine_FLOW_ON_DYNAMIC_WAVE_SIM_ON_DISABLE_COMBINE(uint3 id : SV_DispatchThreadID) { m_Crest::ShapeCombineBase(id); }
|
||||
[numthreads(THREAD_GROUP_SIZE_X, THREAD_GROUP_SIZE_Y, 1)] void ShapeCombineDynamicWaves(uint3 id : SV_DispatchThreadID) { m_Crest::ShapeCombineDynamicWaves(id); }
|
||||
[numthreads(THREAD_GROUP_SIZE_X, THREAD_GROUP_SIZE_Y, 1)] void ShapeCombineDynamicWaves_DISABLE_COMBINE(uint3 id : SV_DispatchThreadID) { m_Crest::ShapeCombineDynamicWaves(id); }
|
||||
[numthreads(THREAD_GROUP_SIZE_X, THREAD_GROUP_SIZE_Y, 1)] void ShapeCombineCopyDynamicWaves(uint3 id : SV_DispatchThreadID) { m_Crest::ShapeCombineCopyDynamicWaves(id); }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#pragma kernel CrestShorelineColor
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Solves 2D wave equation
|
||||
@@ -40,10 +40,11 @@ void UpdateDynamicWaves(uint3 id)
|
||||
const float sliceIndexSource = id.z + _Crest_LodChange;
|
||||
const Cascade cascadeSource = Cascade::MakeDynamicWavesSource(sliceIndexSource);
|
||||
|
||||
// Off either end of the cascade - not useful to sample anything from previous frame. Always initialise
|
||||
// with 0 values.
|
||||
if (sliceIndexSource < 0.0 || sliceIndexSource >= cascadeSource._Count - 1.0)
|
||||
// Off either end of the cascade. Not useful to sample anything from previous
|
||||
// frame, as we do not produce any new data from sources of waves.
|
||||
if (sliceIndexSource < 0.0 || sliceIndexSource >= cascadeSource._Count)
|
||||
{
|
||||
// Always initialise with 0 values.
|
||||
_Crest_Target[id] = (float2)0;
|
||||
return;
|
||||
}
|
||||
@@ -91,21 +92,14 @@ void UpdateDynamicWaves(uint3 id)
|
||||
const float3 X = float3(1.0, 0.0, 0.0);
|
||||
const float3 Y = float3(-X.y, X.x, 0.0);
|
||||
|
||||
// no border wrap mode for RTs in unity it seems,
|
||||
// so make any off-array reads 0 manually
|
||||
const bool insideTarget = sliceIndexSource <= cascadeSource._Count && sliceIndexSource >= 0;
|
||||
|
||||
float fxm, fym, fxp, fyp; float2 ft_v;
|
||||
ft_v = fxm = fym = fxp = fyp = 0.0;
|
||||
|
||||
if (insideTarget)
|
||||
{
|
||||
fxm = cascadeSource.SampleDynamicWaves(uv_source - e * X).x; // x minus
|
||||
fym = cascadeSource.SampleDynamicWaves(uv_source - e * Y).x; // y minus
|
||||
fxp = cascadeSource.SampleDynamicWaves(uv_source + e * X).x; // x plus
|
||||
fyp = cascadeSource.SampleDynamicWaves(uv_source + e * Y).x; // y plus
|
||||
ft_v = cascadeSource.SampleDynamicWaves(uv_source);
|
||||
}
|
||||
fxm = cascadeSource.SampleDynamicWaves(uv_source - e * X).x; // x minus
|
||||
fym = cascadeSource.SampleDynamicWaves(uv_source - e * Y).x; // y minus
|
||||
fxp = cascadeSource.SampleDynamicWaves(uv_source + e * X).x; // x plus
|
||||
fyp = cascadeSource.SampleDynamicWaves(uv_source + e * Y).x; // y plus
|
||||
ft_v = cascadeSource.SampleDynamicWaves(uv_source);
|
||||
|
||||
// wave propagation
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#pragma kernel CrestUpdateFoam
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Soft shadow term is red, hard shadow term is green.
|
||||
|
||||
#pragma kernel CrestUpdateShadowsBRP _BRP
|
||||
#pragma kernel CrestUpdateShadowsHRP _HRP
|
||||
#pragma kernel CrestUpdateShadowsURP _URP
|
||||
|
||||
// Both BIRP.
|
||||
#pragma multi_compile __ SHADOWS_SPLIT_SPHERES
|
||||
#pragma multi_compile __ SHADOWS_SINGLE_CASCADE
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/RP/Compute.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/RP/Shadows.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"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/InputsDriven.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Cascade.hlsl"
|
||||
|
||||
// Noise functions used for jitter.
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Noise/Noise.hlsl"
|
||||
|
||||
|
||||
// JitterDiameterSoft, JitterDiameterHard, CurrentFrameWeightSoft, CurrentFrameWeightHard
|
||||
float4 _Crest_JitterDiameters_CurrentFrameWeights;
|
||||
float _Crest_SimDeltaTime;
|
||||
float4x4 _Crest_MainCameraProjectionMatrix;
|
||||
|
||||
bool _Crest_SampleColorMap;
|
||||
float3 _Crest_Absorption;
|
||||
float3 _Crest_Scattering;
|
||||
|
||||
RWTexture2DArray<float2> _Crest_Target;
|
||||
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
half ComputeShadow(const float4 i_positionWS, const float i_jitterDiameter, const half i_terrainHeight, const uint i_LodIndex)
|
||||
{
|
||||
float4 positionWS = i_positionWS;
|
||||
bool noShadows = false;
|
||||
|
||||
if (i_jitterDiameter > 0.0)
|
||||
{
|
||||
// Add jitter.
|
||||
positionWS.xz += i_jitterDiameter * (hash33(uint3(abs(positionWS.xz * 10.0), _Time.y * 120.0)) - 0.5).xy;
|
||||
|
||||
// Shadow Bleeding.
|
||||
// If we are not within a terrain, then check for shadow bleeding.
|
||||
if (i_positionWS.y > i_terrainHeight)
|
||||
{
|
||||
// WorldToSafeUV
|
||||
half terrainHeight = Cascade::MakeDepth(i_LodIndex).SampleSceneHeight(positionWS.xz);
|
||||
|
||||
// If our current position is below the jittered terrain height, then we have landed within a terrain and
|
||||
// we do not want to sample those shadows.
|
||||
if (i_positionWS.y < terrainHeight)
|
||||
{
|
||||
// Return no shadows.
|
||||
noShadows = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return noShadows ? 1.0 : Utility::SampleShadows(positionWS);
|
||||
}
|
||||
|
||||
void UpdateShadows(const uint3 id)
|
||||
{
|
||||
const uint slice0 = id.z;
|
||||
const Cascade cascade = Cascade::MakeShadow(slice0);
|
||||
const float2 worldPosXZ = cascade.IDToWorld(id.xy);
|
||||
|
||||
float4 positionWS = 1.0;
|
||||
positionWS.xz = worldPosXZ;
|
||||
positionWS.y = g_Crest_WaterCenter.y;
|
||||
|
||||
// Shadow from last frame. Manually implement black border.
|
||||
const float sliceIndexSource = clamp((int)slice0 + g_Crest_LodChange, 0.0, g_Crest_LodCount - 1.0);
|
||||
half2 shadow = Cascade::MakeShadowSource(sliceIndexSource).SampleShadowOverflow(positionWS.xz, 1.0);
|
||||
|
||||
// Add displacement so shorelines do not receive shadows incorrectly.
|
||||
positionWS.xyz += Cascade::MakeAnimatedWaves(slice0).SampleDisplacement(positionWS.xz);
|
||||
|
||||
// This was calculated in vertex but we have to sample sea level offset in fragment.
|
||||
float4 mainCameraCoordinates = mul(_Crest_MainCameraProjectionMatrix, positionWS);
|
||||
|
||||
// Check if the current sample is visible in the main camera (and therefore the shadow map can be sampled). This is
|
||||
// required as the shadow buffer is world aligned and surrounds viewer.
|
||||
float3 projected = mainCameraCoordinates.xyz / mainCameraCoordinates.w;
|
||||
if (projected.z < 1.0 && projected.z > 0.0 && abs(projected.x) < 1.0 && abs(projected.y) < 1.0)
|
||||
{
|
||||
half2 shadowThisFrame = 1.0;
|
||||
|
||||
#if (SHADEROPTIONS_CAMERA_RELATIVE_RENDERING != 0)
|
||||
positionWS.xyz -= _WorldSpaceCameraPos.xyz;
|
||||
#endif
|
||||
|
||||
half terrainHeight = Cascade::MakeDepth(slice0).SampleSceneHeight(positionWS.xz);
|
||||
|
||||
half softJitter = _Crest_JitterDiameters_CurrentFrameWeights[CREST_SHADOW_INDEX_SOFT];
|
||||
|
||||
if (_Crest_SampleColorMap)
|
||||
{
|
||||
half3 absorption = _Crest_Absorption;
|
||||
half3 scattering = _Crest_Scattering;
|
||||
|
||||
if (g_Crest_SampleAbsorptionSimulation)
|
||||
{
|
||||
absorption = Cascade::MakeAbsorption(slice0).SampleAbsorption(positionWS.xz);
|
||||
}
|
||||
|
||||
if (g_Crest_SampleScatteringSimulation)
|
||||
{
|
||||
scattering = Cascade::MakeScattering(slice0).SampleScattering(positionWS.xz);
|
||||
}
|
||||
|
||||
half3 extinction = absorption + scattering;
|
||||
half factor = saturate(min(min(extinction.x, extinction.y), extinction.z) * g_Crest_DynamicSoftShadowsFactor);
|
||||
softJitter = (1.0 - factor) * k_Crest_MaximumShadowJitter;
|
||||
}
|
||||
|
||||
// Add soft shadowing data.
|
||||
shadowThisFrame[CREST_SHADOW_INDEX_SOFT] = ComputeShadow
|
||||
(
|
||||
positionWS,
|
||||
softJitter,
|
||||
terrainHeight,
|
||||
slice0
|
||||
);
|
||||
|
||||
// Add hard shadowing data.
|
||||
shadowThisFrame[CREST_SHADOW_INDEX_HARD] = ComputeShadow
|
||||
(
|
||||
positionWS,
|
||||
_Crest_JitterDiameters_CurrentFrameWeights[CREST_SHADOW_INDEX_HARD],
|
||||
terrainHeight,
|
||||
slice0
|
||||
);
|
||||
|
||||
shadowThisFrame = (half2)1.0 - saturate(shadowThisFrame + Utility::ComputeShadowFade(positionWS));
|
||||
|
||||
shadow = lerp(shadow, shadowThisFrame, _Crest_JitterDiameters_CurrentFrameWeights.zw * _Crest_SimDeltaTime * 60.0);
|
||||
}
|
||||
|
||||
_Crest_Target[id] = shadow;
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
m_CrestKernelXRP(UpdateShadows)
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c47c6200534474da18e1134965c102f3
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -100,7 +100,8 @@ half2 Fragment(Varyings input)
|
||||
float4 positionWS = float4(input.positionWS.xyz, 1.0);
|
||||
|
||||
// Shadow from last frame. Manually implement black border.
|
||||
half2 shadow = Cascade::MakeShadowSource(_Crest_LodIndex + g_Crest_LodChange).SampleShadowOverflow(positionWS.xz, 1.0);
|
||||
const float sliceIndexSource = clamp((int)_Crest_LodIndex + g_Crest_LodChange, 0.0, g_Crest_LodCount - 1.0);
|
||||
half2 shadow = Cascade::MakeShadowSource(sliceIndexSource).SampleShadowOverflow(positionWS.xz, 1.0);
|
||||
|
||||
// Add displacement so shorelines do not receive shadows incorrectly.
|
||||
positionWS.xyz += Cascade::MakeAnimatedWaves(_Crest_LodIndex).SampleDisplacement(positionWS.xz);
|
||||
|
||||
@@ -1,170 +1,7 @@
|
||||
// Crest Water System
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Soft shadow term is red, hard shadow term is green.
|
||||
|
||||
Shader "Hidden/Crest/Simulation/Update Shadow"
|
||||
Shader "Hidden/Crest/Obsolete/Simulation/Update Shadow"
|
||||
{
|
||||
SubShader
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.unity.render-pipelines.high-definition"
|
||||
}
|
||||
|
||||
Tags { "RenderPipeline"="HDRenderPipeline" }
|
||||
|
||||
Pass
|
||||
{
|
||||
HLSLPROGRAM
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
|
||||
// #pragma enable_d3d11_debug_symbols
|
||||
|
||||
// SHADOW_ULTRA_LOW uses Gather which is 4.5. HDRP minimum is 5.0 so this is fine.
|
||||
#pragma target 4.5
|
||||
|
||||
// TODO: We might be able to expose this to give developers the option.
|
||||
// #pragma multi_compile SHADOW_ULTRA_LOW SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH
|
||||
|
||||
// Ultra low uses Gather to filter which should be same cost as not filtering. See algorithms per keyword:
|
||||
// Runtime/Lighting/Shadow/HDShadowAlgorithms.hlsl
|
||||
#define SHADOW_ULTRA_LOW
|
||||
#define AREA_SHADOW_LOW
|
||||
#define PUNCTUAL_SHADOW_ULTRA_LOW
|
||||
#define DIRECTIONAL_SHADOW_ULTRA_LOW
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/Lighting/LightLoop/HDShadow.hlsl"
|
||||
|
||||
float4x4 _Crest_ViewProjectionMatrix;
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Data/UpdateShadow.hlsl"
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
half SampleShadows(const float4 i_positionWS)
|
||||
{
|
||||
// Get directional light data. By definition we only have one directional light casting shadow.
|
||||
DirectionalLightData light = _DirectionalLightDatas[_DirectionalShadowIndex];
|
||||
HDShadowContext context = InitShadowContext();
|
||||
|
||||
// Zeros are for screen space position and world space normal which are for filtering and normal bias
|
||||
// respectively. They did not appear to have an impact.
|
||||
half shadows = GetDirectionalShadowAttenuation(context, 0, i_positionWS.xyz, 0, _DirectionalShadowIndex, -light.forward);
|
||||
// Apply shadow strength from main light.
|
||||
shadows = LerpWhiteTo(shadows, light.shadowDimmer);
|
||||
|
||||
return shadows;
|
||||
}
|
||||
|
||||
half ComputeShadowFade(const float4 i_positionWS)
|
||||
{
|
||||
// TODO: Work out shadow fade.
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
PackageRequirements
|
||||
{
|
||||
"com.unity.render-pipelines.universal"
|
||||
}
|
||||
|
||||
Tags { "RenderPipeline"="UniversalPipeline" }
|
||||
|
||||
Pass
|
||||
{
|
||||
HLSLPROGRAM
|
||||
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
// #pragma enable_d3d11_debug_symbols
|
||||
|
||||
// Maybe this is the equivalent of the SHADOW_COLLECTOR_PASS define? Inspired from com.unity.render-pipelines.universal/Shaders/Utils/ScreenSpaceShadows.shader
|
||||
#define _MAIN_LIGHT_SHADOWS_CASCADE
|
||||
#define MAIN_LIGHT_CALCULATE_SHADOWS
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
|
||||
|
||||
#define CREST_SAMPLE_SHADOW_HARD
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Data/UpdateShadow.hlsl"
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
half SampleShadows(const float4 i_positionWS)
|
||||
{
|
||||
// Includes soft shadows if _SHADOWS_SOFT is defined (requires multi-compile pragma).
|
||||
return MainLightRealtimeShadow(TransformWorldToShadowCoord(i_positionWS.xyz));
|
||||
}
|
||||
|
||||
half ComputeShadowFade(const float4 i_positionWS)
|
||||
{
|
||||
return GetShadowFade(i_positionWS.xyz);
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
HLSLPROGRAM
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
|
||||
#pragma multi_compile_shadowcollector
|
||||
|
||||
// #pragma enable_d3d11_debug_symbols
|
||||
|
||||
#define CREST_SAMPLE_SHADOW_HARD
|
||||
#define d_Crest_ReceiveShadowsTransparent 1
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Core.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Legacy/Shadows.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Data/UpdateShadow.hlsl"
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
half SampleShadows(const float4 i_positionWS)
|
||||
{
|
||||
// NOTE: "Shadow Projection > Close Fit" can still produce artefacts when away from caster, but this
|
||||
// appears to be an improvement over the compute shader.
|
||||
float4 shadowCoord = GET_SHADOW_COORDINATES(i_positionWS);
|
||||
half shadows = UNITY_SAMPLE_SHADOW(_ShadowMapTexture, shadowCoord);
|
||||
if (_Crest_ClearShadows) shadows = 1.0;
|
||||
shadows = lerp(_LightShadowData.r, 1.0, shadows);
|
||||
|
||||
return shadows;
|
||||
}
|
||||
|
||||
half ComputeShadowFade(const float4 i_positionWS)
|
||||
{
|
||||
float z = dot(i_positionWS.xyz - _WorldSpaceCameraPos.xyz, unity_CameraToWorld._m02_m12_m22);
|
||||
float fadeDistance = UnityComputeShadowFadeDistance(i_positionWS.xyz, z);
|
||||
float fade = UnityComputeShadowFade(fadeDistance);
|
||||
return fade;
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
// Replaced with UpdateShadow.compute.
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user