移除水
This commit is contained in:
@@ -1,85 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Crest/Inputs/Absorption/Color"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Crest_AbsorptionColor("Absorption", Color) = (0.3416268229484558, 0.6954545974731445, 0.8500000238418579, 0.10196078568696976)
|
||||
|
||||
[HideInInspector]
|
||||
_Crest_Absorption("Absorption", Vector) = (0.0, 0.09803921729326248, 0.20000000298023225, 0.0)
|
||||
|
||||
[Toggle(d_Feather)]
|
||||
_Crest_Feather("Feather At UV Extents", Float) = 0
|
||||
_Crest_FeatherWidth("Feather Width", Range(0.001, 0.5)) = 0.1
|
||||
|
||||
[HideInInspector]
|
||||
_Crest_Version("Version", Integer) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ZWrite Off
|
||||
ColorMask RGB
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
|
||||
#pragma shader_feature_local d_Feather
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Helpers.hlsl"
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float3 vertex : POSITION;
|
||||
#if d_Feather
|
||||
float2 uv : TEXCOORD0;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
#if d_Feather
|
||||
float2 uv : TEXCOORD0;
|
||||
#endif
|
||||
};
|
||||
|
||||
CBUFFER_START(CrestPerWaterInput)
|
||||
half4 _Crest_Absorption;
|
||||
half _Crest_FeatherWidth;
|
||||
CBUFFER_END
|
||||
|
||||
Varyings Vertex(Attributes input)
|
||||
{
|
||||
Varyings output;
|
||||
float3 positionWS = mul(unity_ObjectToWorld, float4(input.vertex, 1.0)).xyz;
|
||||
output.vertex = mul(UNITY_MATRIX_VP, float4(positionWS, 1.0));
|
||||
#if d_Feather
|
||||
output.uv = input.uv;
|
||||
#endif
|
||||
return output;
|
||||
}
|
||||
|
||||
float4 Fragment(Varyings input) : SV_Target
|
||||
{
|
||||
half4 color = _Crest_Absorption;
|
||||
color.a = 1.0;
|
||||
#if d_Feather
|
||||
color.a *= WaveHarmonic::Crest::FeatherWeightFromUV(input.uv, _Crest_FeatherWidth);
|
||||
#endif
|
||||
|
||||
return color;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
CustomEditor "WaveHarmonic.Crest.Editor.CustomShaderGUI"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a866ef153cd246c58ef554043275848
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,80 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Crest/Inputs/Albedo/Color"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[MainTexture] _Crest_Texture("Albedo", 2D) = "white" {}
|
||||
_Crest_Color("Color", Color) = (1.0, 1.0, 1.0, 1.0)
|
||||
_Crest_Cutoff("Alpha Cutoff", Range(0.0, 1.0)) = 0.5
|
||||
|
||||
[Enum(UnityEngine.Rendering.BlendMode)]
|
||||
_Crest_BlendModeSource("Source Blend Mode", Int) = 5
|
||||
[Enum(UnityEngine.Rendering.BlendMode)]
|
||||
_Crest_BlendModeTarget("Target Blend Mode", Int) = 10
|
||||
|
||||
[HideInInspector]
|
||||
_Crest_Version("Version", Integer) = 0
|
||||
}
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
Blend [_Crest_BlendModeSource] [_Crest_BlendModeTarget]
|
||||
|
||||
ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float3 vertex : POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
fixed4 color : COLOR;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
CBUFFER_START(CrestPerWaterInput)
|
||||
float3 _Crest_DisplacementAtInputPosition;
|
||||
CBUFFER_END
|
||||
|
||||
Texture2D _Crest_Texture;
|
||||
SamplerState sampler_Crest_Texture;
|
||||
float4 _Crest_Texture_ST;
|
||||
|
||||
half4 _Crest_Color;
|
||||
half _Crest_Cutoff;
|
||||
|
||||
Varyings Vertex(Attributes input)
|
||||
{
|
||||
Varyings output;
|
||||
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.color = input.color;
|
||||
return output;
|
||||
}
|
||||
|
||||
fixed4 Fragment(Varyings i) : SV_Target
|
||||
{
|
||||
fixed4 color = _Crest_Texture.Sample(sampler_Crest_Texture, i.uv) * _Crest_Color;
|
||||
clip(color.a - _Crest_Cutoff + 0.0001);
|
||||
return color * i.color;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
CustomEditor "WaveHarmonic.Crest.Editor.CustomShaderGUI"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa7b1bc481cf34f229ffd793be4a01c3
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,85 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Crest/Inputs/Animated Waves/Add From Texture"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[MainTexture] _Crest_Texture("Texture", 2D) = "black" {}
|
||||
_Crest_Strength( "Strength", float ) = 1
|
||||
|
||||
[Toggle(d_HeightsOnly)]
|
||||
_Crest_HeightsOnly("Heights Only", Float) = 1
|
||||
|
||||
[HideInInspector]
|
||||
_Crest_Version("Version", Integer) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Blend One One
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex Vert
|
||||
#pragma fragment Frag
|
||||
|
||||
#pragma shader_feature_local d_HeightsOnly
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
Texture2D _Crest_Texture;
|
||||
SamplerState sampler_Crest_Texture;
|
||||
|
||||
CBUFFER_START(CrestPerWaterInput)
|
||||
float4 _Crest_Texture_ST;
|
||||
float _Crest_Strength;
|
||||
float _Crest_Weight;
|
||||
float3 _Crest_DisplacementAtInputPosition;
|
||||
CBUFFER_END
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float3 positionOS : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
Varyings Vert(Attributes input)
|
||||
{
|
||||
Varyings o;
|
||||
|
||||
float3 worldPos = mul(unity_ObjectToWorld, float4(input.positionOS, 1.0)).xyz;
|
||||
// Correct for displacement
|
||||
worldPos.xz -= _Crest_DisplacementAtInputPosition.xz;
|
||||
o.positionCS = mul(UNITY_MATRIX_VP, float4(worldPos, 1.0));
|
||||
|
||||
o.uv = TRANSFORM_TEX(input.uv, _Crest_Texture);
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 Frag(Varyings input) : SV_Target
|
||||
{
|
||||
half3 texSample = _Crest_Texture.Sample(sampler_Crest_Texture, input.uv).xyz;
|
||||
|
||||
half3 displacement = (half3)0.0;
|
||||
#if d_HeightsOnly
|
||||
displacement.y = texSample.x * _Crest_Strength;
|
||||
#else
|
||||
displacement.xyz = texSample * _Crest_Strength;
|
||||
#endif
|
||||
|
||||
return _Crest_Weight * half4(displacement, 0.0);
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
CustomEditor "WaveHarmonic.Crest.Editor.CustomShaderGUI"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62ff65b047d684524b06152100f725bb
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,80 +0,0 @@
|
||||
// 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.
|
||||
|
||||
Shader "Crest/Inputs/Animated Waves/Push Water Under Convex Hull"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[HideInInspector]
|
||||
_Crest_Version("Version", Integer) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
BlendOp Min
|
||||
Cull Front
|
||||
ColorMask G
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.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"
|
||||
|
||||
CBUFFER_START(CrestPerWaterInput)
|
||||
float _Crest_Weight;
|
||||
float3 _Crest_DisplacementAtInputPosition;
|
||||
CBUFFER_END
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float3 positionOS : POSITION;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float3 worldPos : TEXCOORD0;
|
||||
};
|
||||
|
||||
Varyings Vertex(Attributes input)
|
||||
{
|
||||
Varyings o;
|
||||
|
||||
o.worldPos = mul(unity_ObjectToWorld, float4(input.positionOS, 1.0)).xyz;
|
||||
// Correct for displacement
|
||||
o.worldPos.xz -= _Crest_DisplacementAtInputPosition.xz;
|
||||
|
||||
o.positionCS = mul(UNITY_MATRIX_VP, float4(o.worldPos, 1.0));
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 Fragment(Varyings input)
|
||||
{
|
||||
// Write displacement to get from sea level of water to the y value of this geometry.
|
||||
half seaLevelOffset = Cascade::MakeLevel(_Crest_LodIndex).SampleLevel(input.worldPos.xz);
|
||||
return half4(0.0, _Crest_Weight * (input.worldPos.y - g_Crest_WaterCenter.y - seaLevelOffset), 0.0, 0.0);
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
m_CrestVertex
|
||||
m_CrestFragment(half4)
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
CustomEditor "WaveHarmonic.Crest.Editor.CustomShaderGUI"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 170672f06b4574545ba8305cb7d11091
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,84 +0,0 @@
|
||||
// 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.
|
||||
|
||||
Shader "Crest/Inputs/Animated Waves/Set Water Height Using Geometry"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[Enum(ColorWriteMask)]
|
||||
_Crest_ColorMask("Color Mask", Int) = 15
|
||||
|
||||
[HideInInspector]
|
||||
_Crest_Version("Version", Integer) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
Blend Off
|
||||
ColorMask [_Crest_ColorMask]
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.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"
|
||||
|
||||
CBUFFER_START(CrestPerWaterInput)
|
||||
float _Crest_Weight;
|
||||
float3 _Crest_DisplacementAtInputPosition;
|
||||
CBUFFER_END
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float3 positionOS : POSITION;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float3 worldPos : TEXCOORD0;
|
||||
};
|
||||
|
||||
Varyings Vertex(Attributes input)
|
||||
{
|
||||
Varyings o;
|
||||
|
||||
o.worldPos = mul(unity_ObjectToWorld, float4(input.positionOS, 1.0)).xyz;
|
||||
// Correct for displacement
|
||||
o.worldPos.xz -= _Crest_DisplacementAtInputPosition.xz;
|
||||
|
||||
o.positionCS = mul(UNITY_MATRIX_VP, float4(o.worldPos, 1.0));
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 Fragment(Varyings input)
|
||||
{
|
||||
half seaLevelOffset = Cascade::MakeLevel(_Crest_LodIndex).SampleLevel(input.worldPos.xz);
|
||||
|
||||
// Write displacement to get from sea level of water to the y value of this geometry
|
||||
float height = input.worldPos.y - g_Crest_WaterCenter.y - seaLevelOffset;
|
||||
return half4(0.0, _Crest_Weight * height, 0.0, 0.0);
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
m_CrestVertex
|
||||
m_CrestFragment(half4)
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
CustomEditor "WaveHarmonic.Crest.Editor.CustomShaderGUI"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3acaa68c12f5e435290dbeebd2684241
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,87 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Crest/Inputs/Animated Waves/Wave Particle"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Crest_Amplitude( "Amplitude", float ) = 1
|
||||
_Crest_Radius( "Radius", float) = 3
|
||||
|
||||
[HideInInspector]
|
||||
_Crest_Version("Version", Integer) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags { "DisableBatching" = "True" }
|
||||
|
||||
Pass
|
||||
{
|
||||
Blend One One
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex Vert
|
||||
#pragma fragment Frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
CBUFFER_START(CrestPerWaterInput)
|
||||
float _Crest_Radius;
|
||||
float _Crest_Amplitude;
|
||||
float _Crest_Weight;
|
||||
float3 _Crest_DisplacementAtInputPosition;
|
||||
CBUFFER_END
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float3 positionOS : POSITION;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float2 worldOffsetScaledXZ : TEXCOORD0;
|
||||
};
|
||||
|
||||
Varyings Vert(Attributes input)
|
||||
{
|
||||
Varyings o;
|
||||
|
||||
float3 worldPos = mul(unity_ObjectToWorld, float4(input.positionOS, 1.0)).xyz;
|
||||
float3 centerPos = unity_ObjectToWorld._m03_m13_m23;
|
||||
o.worldOffsetScaledXZ = worldPos.xz - centerPos.xz;
|
||||
|
||||
// shape is symmetric around center with known radius - fix the vert positions to perfectly wrap the shape.
|
||||
o.worldOffsetScaledXZ = sign(o.worldOffsetScaledXZ);
|
||||
float4 newWorldPos = float4(centerPos, 1.0);
|
||||
newWorldPos.xz += o.worldOffsetScaledXZ * _Crest_Radius;
|
||||
|
||||
// Correct for displacement
|
||||
newWorldPos.xz -= _Crest_DisplacementAtInputPosition.xz;
|
||||
|
||||
o.positionCS = mul(UNITY_MATRIX_VP, newWorldPos);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 Frag(Varyings input) : SV_Target
|
||||
{
|
||||
// power 4 smoothstep - no normalize needed
|
||||
// credit goes to stubbe's shadertoy: https://www.shadertoy.com/view/4ldSD2
|
||||
float r2 = dot( input.worldOffsetScaledXZ, input.worldOffsetScaledXZ);
|
||||
if( r2 > 1.0 )
|
||||
return (float4)0.0;
|
||||
|
||||
r2 = 1.0 - r2;
|
||||
|
||||
float y = r2 * r2 * _Crest_Amplitude;
|
||||
|
||||
return float4(0.0, y * _Crest_Weight, 0.0, 0.0);
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
CustomEditor "WaveHarmonic.Crest.Editor.CustomShaderGUI"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1519a4fd6d8a4a62b59870be79b3857
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,107 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Crest/Inputs/Dynamic Waves/Add Bump"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Crest_Amplitude( "Amplitude", float ) = 1
|
||||
_Crest_Radius( "Radius", float) = 3
|
||||
|
||||
[HideInInspector]
|
||||
_Crest_Version("Version", Integer) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
Blend One One
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Cascade.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Helpers.hlsl"
|
||||
|
||||
CBUFFER_START(CrestPerWaterInput)
|
||||
float _Crest_Radius;
|
||||
float _Crest_SimDeltaTime;
|
||||
float _Crest_Amplitude;
|
||||
float3 _Crest_DisplacementAtInputPosition;
|
||||
CBUFFER_END
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float3 positionOS : POSITION;
|
||||
float2 texcoord : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float2 worldOffsetScaled : TEXCOORD0;
|
||||
float2 uv : TEXCOORD1;
|
||||
};
|
||||
|
||||
Varyings Vertex(Attributes input)
|
||||
{
|
||||
Varyings o;
|
||||
o.positionCS = UnityObjectToClipPos(input.positionOS);
|
||||
|
||||
float3 worldPos = mul(unity_ObjectToWorld, float4(input.positionOS, 1.0));
|
||||
float3 centerPos = unity_ObjectToWorld._m03_m13_m23;
|
||||
o.worldOffsetScaled.xy = worldPos.xz - centerPos.xz;
|
||||
|
||||
// shape is symmetric around center with known radius - fix the vert positions to perfectly wrap the shape.
|
||||
o.worldOffsetScaled.xy = sign(o.worldOffsetScaled.xy);
|
||||
float4 newWorldPos = float4(centerPos, 1.0);
|
||||
newWorldPos.xz += o.worldOffsetScaled.xy * _Crest_Radius;
|
||||
|
||||
// Correct for displacement
|
||||
newWorldPos.xz -= _Crest_DisplacementAtInputPosition.xz;
|
||||
|
||||
o.positionCS = mul(UNITY_MATRIX_VP, newWorldPos);
|
||||
o.uv = Cascade::MakeDynamicWaves(_Crest_LodIndex).WorldToUV(newWorldPos.xz);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 Fragment(Varyings input)
|
||||
{
|
||||
// power 4 smoothstep - no normalize needed
|
||||
// credit goes to stubbe's shadertoy: https://www.shadertoy.com/view/4ldSD2
|
||||
float r2 = dot(input.worldOffsetScaled.xy, input.worldOffsetScaled.xy);
|
||||
if (r2 > 1.0)
|
||||
return (float4)0.0;
|
||||
|
||||
r2 = 1.0 - r2;
|
||||
|
||||
float y = r2 * r2;
|
||||
y = pow(y, 0.05);
|
||||
y *= _Crest_Amplitude;
|
||||
|
||||
y /= g_Crest_LodCount;
|
||||
|
||||
// Feather edges to reduce streaking without introducing reflections.
|
||||
y *= FeatherWeightFromUV(input.uv, 0.1);
|
||||
|
||||
// accelerate velocities
|
||||
return float4(0.0, _Crest_SimDeltaTime * y, 0.0, 0.0);
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
m_CrestVertex
|
||||
m_CrestFragment(float4)
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e8ca175bc339b74880584aa1544100e
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,84 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Crest/Inputs/Dynamic Waves/Dampen Circle"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Crest_Radius("Radius", float) = 3
|
||||
_Crest_Strength("Strength", Range(0, 100)) = 10
|
||||
|
||||
[HideInInspector]
|
||||
_Crest_Version("Version", Integer) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex Vert
|
||||
#pragma fragment Frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
CBUFFER_START(CrestPerWaterInput)
|
||||
float _Crest_SimDeltaTime;
|
||||
float _Crest_Radius;
|
||||
float _Crest_Strength;
|
||||
float _Crest_Weight;
|
||||
float3 _Crest_DisplacementAtInputPosition;
|
||||
CBUFFER_END
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float3 positionOS : POSITION;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float2 worldOffsetScaled : TEXCOORD0;
|
||||
};
|
||||
|
||||
Varyings Vert(Attributes input)
|
||||
{
|
||||
Varyings o;
|
||||
o.positionCS = UnityObjectToClipPos(input.positionOS);
|
||||
|
||||
float3 worldPos = mul(unity_ObjectToWorld, float4(input.positionOS, 1.0)).xyz;
|
||||
float3 centerPos = unity_ObjectToWorld._m03_m13_m23;
|
||||
o.worldOffsetScaled.xy = worldPos.xz - centerPos.xz;
|
||||
|
||||
// shape is symmetric around center with known radius - fix the vert positions to perfectly wrap the shape.
|
||||
o.worldOffsetScaled.xy = sign(o.worldOffsetScaled.xy);
|
||||
float4 newWorldPos = float4(centerPos, 1.0);
|
||||
newWorldPos.xz += o.worldOffsetScaled.xy * _Crest_Radius;
|
||||
|
||||
// Correct for displacement
|
||||
newWorldPos.xz -= _Crest_DisplacementAtInputPosition.xz;
|
||||
|
||||
o.positionCS = mul(UNITY_MATRIX_VP, newWorldPos);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 Frag(Varyings input) : SV_Target
|
||||
{
|
||||
// power 4 smoothstep - no normalize needed
|
||||
// credit goes to stubbe's shadertoy: https://www.shadertoy.com/view/4ldSD2
|
||||
float r2 = dot(input.worldOffsetScaled.xy, input.worldOffsetScaled.xy);
|
||||
if (r2 > 1.0) return (float4)0.0;
|
||||
r2 = 1.0 - r2;
|
||||
float val = r2 * r2;
|
||||
|
||||
float weight = val * _Crest_Strength * _Crest_SimDeltaTime * _Crest_Weight;
|
||||
return float4(0.0, 0.0, 0.0, weight);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
CustomEditor "WaveHarmonic.Crest.Editor.CustomShaderGUI"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7ab71b44865e403cb0a074713fb3ff7
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,110 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Crest/Inputs/Flow/Add From Texture"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[MainTexture] _Crest_Texture("Flow Map", 2D) = "white" {}
|
||||
_Crest_Strength( "Strength", float ) = 1
|
||||
|
||||
[Toggle(d_FlipX)]
|
||||
_Crest_FlipX("Flip X", Float) = 0
|
||||
[Toggle(d_FlipZ)]
|
||||
_Crest_FlipZ("Flip Z", Float) = 0
|
||||
[Toggle(d_NegativeValues)]
|
||||
_Crest_NegativeValues("Has Negative Values", Float) = 0
|
||||
|
||||
[Toggle(d_Feather)]
|
||||
_Crest_Feather("Feather At UV Extents", Float) = 0
|
||||
_Crest_FeatherWidth("Feather Width", Range(0.001, 0.5)) = 0.1
|
||||
|
||||
[HideInInspector]
|
||||
_Crest_Version("Version", Integer) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Blend One One
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#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
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
#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/Helpers.hlsl"
|
||||
|
||||
Texture2D _Crest_Texture;
|
||||
SamplerState sampler_Crest_Texture;
|
||||
|
||||
CBUFFER_START(CrestPerWaterInput)
|
||||
float4 _Crest_Texture_ST;
|
||||
float _Crest_Strength;
|
||||
float _Crest_Weight;
|
||||
float3 _Crest_DisplacementAtInputPosition;
|
||||
half _Crest_FeatherWidth;
|
||||
CBUFFER_END
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float3 positionOS : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
Varyings Vert(Attributes input)
|
||||
{
|
||||
Varyings o;
|
||||
|
||||
float3 worldPos = mul(unity_ObjectToWorld, float4(input.positionOS, 1.0)).xyz;
|
||||
// Correct for displacement
|
||||
worldPos.xz -= _Crest_DisplacementAtInputPosition.xz;
|
||||
o.positionCS = mul(UNITY_MATRIX_VP, float4(worldPos, 1.0));
|
||||
|
||||
o.uv = TRANSFORM_TEX(input.uv, _Crest_Texture);
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 Frag(Varyings input) : SV_Target
|
||||
{
|
||||
float2 flow = _Crest_Texture.Sample(sampler_Crest_Texture, input.uv).xy;
|
||||
|
||||
#if !d_NegativeValues
|
||||
// From 0..1 to -1..1.
|
||||
flow = flow * 2.0 - 1.0;
|
||||
#endif
|
||||
|
||||
#if d_Feather
|
||||
flow *= WaveHarmonic::Crest::FeatherWeightFromUV(input.uv, _Crest_FeatherWidth);
|
||||
#endif
|
||||
|
||||
#if d_FlipX
|
||||
flow.x *= -1.0;
|
||||
#endif
|
||||
#if d_FlipZ
|
||||
flow.y *= -1.0;
|
||||
#endif
|
||||
|
||||
return float4(flow * _Crest_Strength * _Crest_Weight, 0.0, 0.0);
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
CustomEditor "WaveHarmonic.Crest.Editor.CustomShaderGUI"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8958e526a8d9b403e878e13b80405796
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,101 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Crest/Inputs/Flow/Fixed Direction"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Crest_Speed("Speed", Range(0.0, 30.0)) = 1.0
|
||||
_Crest_Direction("Direction", Range(0.0, 1.0)) = 0.0
|
||||
|
||||
[Toggle(d_Feather)]
|
||||
_Crest_Feather("Feather At UV Extents", Float) = 0
|
||||
_Crest_FeatherWidth("Feather Width", Range(0.001, 0.5)) = 0.1
|
||||
|
||||
[Toggle(d_ApplyRotation)]
|
||||
_Crest_ApplyRotation("Apply Transform XZ Rotation", Float) = 0
|
||||
|
||||
[HideInInspector]
|
||||
_Crest_Version("Version", Integer) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex Vert
|
||||
#pragma fragment Frag
|
||||
|
||||
#pragma shader_feature_local d_Feather
|
||||
#pragma shader_feature_local d_ApplyRotation
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
#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/Helpers.hlsl"
|
||||
|
||||
CBUFFER_START(CrestPerWaterInput)
|
||||
float _Crest_Speed;
|
||||
float _Crest_Direction;
|
||||
float3 _Crest_DisplacementAtInputPosition;
|
||||
half _Crest_FeatherWidth;
|
||||
half _Crest_Weight;
|
||||
CBUFFER_END
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float3 positionOS : POSITION;
|
||||
#if d_Feather
|
||||
float2 uv : TEXCOORD0;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float2 vel : TEXCOORD0;
|
||||
#if d_Feather
|
||||
float2 uv : TEXCOORD1;
|
||||
#endif
|
||||
};
|
||||
|
||||
Varyings Vert(Attributes input)
|
||||
{
|
||||
Varyings o;
|
||||
|
||||
float3 worldPos = mul(unity_ObjectToWorld, float4(input.positionOS, 1.0)).xyz;
|
||||
// Correct for displacement
|
||||
worldPos.xz -= _Crest_DisplacementAtInputPosition.xz;
|
||||
o.positionCS = mul(UNITY_MATRIX_VP, float4(worldPos, 1.0));
|
||||
|
||||
o.vel = _Crest_Speed * float2(cos(_Crest_Direction * 6.283185), sin(_Crest_Direction * 6.283185));
|
||||
|
||||
#if d_Feather
|
||||
o.uv = input.uv;
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 Frag(Varyings input) : SV_Target
|
||||
{
|
||||
float2 flow = input.vel;
|
||||
|
||||
#if d_Feather
|
||||
flow *= WaveHarmonic::Crest::FeatherWeightFromUV(input.uv, _Crest_FeatherWidth);
|
||||
#endif
|
||||
|
||||
#if d_ApplyRotation
|
||||
const float2 rotation = normalize(unity_ObjectToWorld._m00_m20.xy);
|
||||
flow = flow.x * rotation + flow.y * float2(-rotation.y, rotation.x);
|
||||
#endif
|
||||
|
||||
return float4(flow * _Crest_Weight, 0.0, 0.0);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
CustomEditor "WaveHarmonic.Crest.Editor.CustomShaderGUI"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5198aecab500144dbb5ee73bad91640a
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,72 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Crest/Inputs/Foam/Add From Texture"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[MainTexture] _Crest_Texture("Texture", 2D) = "white" {}
|
||||
_Crest_Strength( "Strength", float ) = 1
|
||||
|
||||
[HideInInspector]
|
||||
_Crest_Version("Version", Integer) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Blend One One
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex Vert
|
||||
#pragma fragment Frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
Texture2D _Crest_Texture;
|
||||
SamplerState sampler_Crest_Texture;
|
||||
float _Crest_Strength;
|
||||
|
||||
CBUFFER_START(CrestPerWaterInput)
|
||||
float _Crest_SimDeltaTime;
|
||||
float4 _Crest_Texture_ST;
|
||||
float3 _Crest_DisplacementAtInputPosition;
|
||||
half _Crest_Weight;
|
||||
CBUFFER_END
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float3 positionOS : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
Varyings Vert(Attributes input)
|
||||
{
|
||||
Varyings o;
|
||||
|
||||
float3 worldPos = mul(unity_ObjectToWorld, float4(input.positionOS, 1.0)).xyz;
|
||||
// Correct for displacement
|
||||
worldPos.xz -= _Crest_DisplacementAtInputPosition.xz;
|
||||
o.positionCS = mul(UNITY_MATRIX_VP, float4(worldPos, 1.0));
|
||||
|
||||
o.uv = TRANSFORM_TEX(input.uv, _Crest_Texture);
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 Frag(Varyings input) : SV_Target
|
||||
{
|
||||
return _Crest_Texture.Sample(sampler_Crest_Texture, input.uv) * _Crest_Weight * _Crest_Strength * _Crest_SimDeltaTime;
|
||||
}
|
||||
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
CustomEditor "WaveHarmonic.Crest.Editor.CustomShaderGUI"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 955fe6ade516e42e0ab0b0bbb116170a
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,67 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Crest/Inputs/Foam/Add From Vertex Colors"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Crest_Strength("Strength", float) = 1
|
||||
|
||||
[HideInInspector]
|
||||
_Crest_Version("Version", Integer) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Blend One One
|
||||
|
||||
Pass
|
||||
{
|
||||
CGPROGRAM
|
||||
#pragma vertex Vert
|
||||
#pragma fragment Frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
CBUFFER_START(CrestPerWaterInput)
|
||||
float _Crest_SimDeltaTime;
|
||||
float _Crest_Strength;
|
||||
float _Crest_Weight;
|
||||
float3 _Crest_DisplacementAtInputPosition;
|
||||
CBUFFER_END
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float3 positionOS : POSITION;
|
||||
float4 col : COLOR0;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float4 col : COLOR0;
|
||||
};
|
||||
|
||||
Varyings Vert(Attributes input)
|
||||
{
|
||||
Varyings o;
|
||||
|
||||
float3 worldPos = mul(unity_ObjectToWorld, float4(input.positionOS, 1.0)).xyz;
|
||||
// Correct for displacement
|
||||
worldPos.xz -= _Crest_DisplacementAtInputPosition.xz;
|
||||
o.positionCS = mul(UNITY_MATRIX_VP, float4(worldPos, 1.0));
|
||||
|
||||
o.col = input.col;
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 Frag(Varyings input) : SV_Target
|
||||
{
|
||||
return _Crest_Strength * input.col.x * _Crest_SimDeltaTime * _Crest_Weight;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
CustomEditor "WaveHarmonic.Crest.Editor.CustomShaderGUI"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f51a8e7d464dd4fb0a51d0c61b8ca417
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a69be96a1d36c4f8b9f29717e0a95d94
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,54 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#pragma kernel CrestExecute
|
||||
|
||||
#include "HLSLSupport.cginc"
|
||||
|
||||
#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/Helpers.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/InputsDriven.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Cascade.hlsl"
|
||||
|
||||
Texture2D _Crest_Texture;
|
||||
RWTexture2DArray<float3> _Crest_Target;
|
||||
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
int _Crest_Blend;
|
||||
float _Crest_Weight;
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
float _Crest_FeatherWidth;
|
||||
CBUFFER_END
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
void Execute(uint3 id)
|
||||
{
|
||||
const Cascade cascade = Cascade::MakeAbsorption(id.z);
|
||||
const float2 uv = DataIDToInputUV(id.xy, cascade, _Crest_TexturePosition, _Crest_TextureRotation, _Crest_TextureSize);
|
||||
|
||||
half weight = _Crest_Weight;
|
||||
|
||||
// Feather boundaries.
|
||||
weight *= FeatherWeightFromUV(uv, _Crest_FeatherWidth);
|
||||
|
||||
// Check we are within bounds.
|
||||
if (weight <= 0.0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const half4 source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0);
|
||||
const half3 target = _Crest_Target[id];
|
||||
weight *= source.a;
|
||||
|
||||
_Crest_Target[id] = Blend(_Crest_Blend, weight, 1.0, source.xyz, target);
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
m_CrestInputKernelDefault(Execute)
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82d4c3f5aac084c2bad20d0a31f1168a
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,248 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#pragma kernel CrestTransferWaves
|
||||
|
||||
#pragma multi_compile_local __ d_Texture d_TextureBlend
|
||||
|
||||
#if defined(d_TextureBlend)
|
||||
#define d_Texture 1
|
||||
#endif
|
||||
|
||||
#include "HLSLSupport.cginc"
|
||||
|
||||
#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/Helpers.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/InputsDriven.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Cascade.hlsl"
|
||||
|
||||
Texture2D _Crest_Texture;
|
||||
Texture2DArray _Crest_WaveBuffer;
|
||||
RWTexture2DArray<float4> _Crest_Target;
|
||||
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
float4 _Crest_WaveBufferParameters[MAX_LOD_COUNT];
|
||||
float2 _Crest_AxisX;
|
||||
float _Crest_Weight;
|
||||
float _Crest_FeatherWidth;
|
||||
float _Crest_AttenuationInShallows;
|
||||
float _Crest_RespectShallowWaterAttenuation;
|
||||
float _Crest_MaximumAttenuationDepth;
|
||||
float _Crest_WaveResolutionMultiplier;
|
||||
float _Crest_TransitionalWavelengthThreshold;
|
||||
|
||||
// Texture
|
||||
#if d_Texture
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
bool _Crest_NegativeValues;
|
||||
int _Crest_Blend;
|
||||
#endif
|
||||
CBUFFER_END
|
||||
|
||||
#if d_Texture
|
||||
#define m_None 0
|
||||
#define m_FromZero 4
|
||||
#define m_FromZeroNormalized 5
|
||||
#endif // d_Texture
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
void TransferWaves(uint3 id)
|
||||
{
|
||||
const uint slice0 = id.z;
|
||||
|
||||
const float4 parameters = _Crest_WaveBufferParameters[slice0];
|
||||
const uint first = parameters.x;
|
||||
const uint last = parameters.y;
|
||||
const half transition = parameters.w;
|
||||
|
||||
#if !d_TextureBlend
|
||||
// Additive only. All wavelengths filtered out for this LOD so nothing to do.
|
||||
if (parameters.x < 0 || parameters.y < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
const Cascade cascade = Cascade::MakeAnimatedWaves(slice0);
|
||||
const float2 positionWS = cascade.IDToWorld(id.xy);
|
||||
|
||||
half _weight = _Crest_Weight;
|
||||
half alpha = 0.0;
|
||||
|
||||
#if d_Texture
|
||||
float2 uvPainted = (positionWS - _Crest_TexturePosition) / _Crest_TextureSize;
|
||||
// Clockwise transform rotation.
|
||||
uvPainted = uvPainted.x * float2(_Crest_TextureRotation.y, -_Crest_TextureRotation.x) + uvPainted.y * _Crest_TextureRotation;
|
||||
uvPainted += 0.5;
|
||||
|
||||
// Feather boundaries.
|
||||
_weight *= FeatherWeightFromUV(uvPainted, _Crest_FeatherWidth);
|
||||
|
||||
// Check we are within bounds.
|
||||
if (_weight <= 0.0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
alpha = _weight;
|
||||
|
||||
// Initialize or "use of potentially uninitialized variable" due to early return.
|
||||
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;
|
||||
|
||||
if (!_Crest_NegativeValues)
|
||||
{
|
||||
// -1.0 to 1.0
|
||||
axis = axis * 2.0 - 1.0;
|
||||
}
|
||||
|
||||
float axisLength2 = dot(axis, axis);
|
||||
|
||||
// Zero data so exit early and apply blending if needed.
|
||||
if (!(axisLength2 > 0.00001))
|
||||
{
|
||||
#if d_TextureBlend
|
||||
if (_Crest_Blend > m_None)
|
||||
{
|
||||
// If zero affects blend weight, then reduce alpha by axis length so that it
|
||||
// accounts for zero data.
|
||||
alpha = 0.0;
|
||||
}
|
||||
|
||||
_Crest_Target[id] *= 1.0 - alpha;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
axisLength = sqrt(axisLength2);
|
||||
|
||||
// Alpha blending based on data.
|
||||
if (_Crest_Blend == m_FromZeroNormalized)
|
||||
{
|
||||
// Normalize so even small amounts fully removes existing waves.
|
||||
alpha *= length(normalize(axis));
|
||||
}
|
||||
else if (_Crest_Blend == m_FromZero)
|
||||
{
|
||||
alpha *= axisLength;
|
||||
}
|
||||
|
||||
// Rotate axis with transform rotation to keep axis in local space.
|
||||
axis = axis.x * _Crest_TextureRotation.yx + axis.y * float2(-_Crest_TextureRotation.x, _Crest_TextureRotation.y);
|
||||
|
||||
// Add wind (counterclockwise).
|
||||
axis = axis.x * _Crest_AxisX + axis.y * float2(-_Crest_AxisX.y, _Crest_AxisX.x);
|
||||
|
||||
// Quantize wave direction.
|
||||
const float axisHeading = atan2(axis.y, axis.x) + 2.0 * 3.141592654;
|
||||
const float dTheta = 0.5 * 0.314159265;
|
||||
const float rem = fmod(axisHeading, dTheta);
|
||||
const float angle0 = axisHeading - rem;
|
||||
const float angle1 = angle0 + dTheta;
|
||||
t = rem / dTheta;
|
||||
|
||||
sincos(angle0, axisX0.y, axisX0.x);
|
||||
sincos(angle1, axisX1.y, axisX1.x);
|
||||
axisZ0.x = -axisX0.y; axisZ0.y = axisX0.x;
|
||||
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);
|
||||
|
||||
half3 _displacement = 0.0;
|
||||
|
||||
// Loop through wave buffer slices.
|
||||
for (uint i = first; i <= last; i++)
|
||||
{
|
||||
const uint waveBufferIndex = i;
|
||||
const float waveBufferSize = 0.5f * (1 << waveBufferIndex);
|
||||
|
||||
half weight = _weight;
|
||||
|
||||
uint WAVE_SAMPLE_FACTOR = 8;
|
||||
half minimumWL = waveBufferSize / WAVE_SAMPLE_FACTOR / _Crest_WaveResolutionMultiplier;
|
||||
half averageWL = minimumWL * 1.5f * _Crest_WaveResolutionMultiplier;
|
||||
|
||||
// If approaching end of lod chain, start smoothly transitioning any large
|
||||
// wavelengths across last two LODs.
|
||||
if (minimumWL >= _Crest_TransitionalWavelengthThreshold)
|
||||
{
|
||||
// The transition weight must not be applied to the alpha otherwise popping.
|
||||
weight *= transition;
|
||||
}
|
||||
|
||||
// Attenuation.
|
||||
float attenuation;
|
||||
{
|
||||
// Attenuate waves based on water depth. If depth is greater than half the
|
||||
// wavelength, water is considered deep and wave is unaffected. If depth is less
|
||||
// than this, wave velocity decreases. Waves will then bunch up and grow in
|
||||
// amplitude and eventually break. Deep water model is approximated by simply
|
||||
// ramping down waves in non-deep water with a linear multiplier.
|
||||
// http://hyperphysics.phy-astr.gsu.edu/hbase/Waves/watwav2.html
|
||||
// http://hyperphysics.phy-astr.gsu.edu/hbase/watwav.html#c1
|
||||
half weight = saturate(2.0 * depth / averageWL);
|
||||
if (_Crest_MaximumAttenuationDepth < k_Crest_MaximumWaveAttenuationDepth)
|
||||
{
|
||||
weight = lerp(weight, 1.0, saturate(depth / _Crest_MaximumAttenuationDepth));
|
||||
}
|
||||
|
||||
|
||||
const float attenuationAmount = _Crest_AttenuationInShallows * _Crest_RespectShallowWaterAttenuation;
|
||||
attenuation = attenuationAmount * weight + (1.0 - attenuationAmount);
|
||||
}
|
||||
|
||||
// NOTE: Could not get attenuation applied to alpha to work. Incurred popping.
|
||||
weight *= attenuation;
|
||||
|
||||
// Sample Wave Buffers.
|
||||
if (weight > 0.0)
|
||||
{
|
||||
#if d_Texture
|
||||
// Interpolate waves.
|
||||
float2 positionScaledWS = positionWS / waveBufferSize;
|
||||
|
||||
const float2 uv0 = float2(dot(positionScaledWS, axisX0), dot(positionScaledWS, axisZ0));
|
||||
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;
|
||||
|
||||
float3 displacement = lerp(displacement0, displacement1, t);
|
||||
displacement.xz = displacement.x * axis + displacement.z * float2(-axis.y, axis.x);
|
||||
displacement.y *= axisLength;
|
||||
_displacement += displacement * weight;
|
||||
|
||||
#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;
|
||||
displacement.xz = displacement.x * _Crest_AxisX + displacement.z * float2(-_Crest_AxisX.y, _Crest_AxisX.x);
|
||||
_displacement += displacement * weight;
|
||||
#endif // d_Texture
|
||||
}
|
||||
}
|
||||
|
||||
#if d_TextureBlend
|
||||
// Global waves are always additive.
|
||||
_Crest_Target[id] *= 1.0 - saturate(alpha);
|
||||
#endif
|
||||
|
||||
// Always write full alpha so textures show up in previews.
|
||||
_Crest_Target[id] += float4(_displacement, 1.0);
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
m_CrestInputKernelDefault(TransferWaves)
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a487d04e47a14907809657d5ccf1917
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,92 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Renders convex hull to the clip surface texture.
|
||||
|
||||
Shader "Hidden/Crest/Inputs/Clip/Convex Hull"
|
||||
{
|
||||
CGINCLUDE
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
|
||||
// For SV_IsFrontFace.
|
||||
#pragma target 3.0
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#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"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Surface/Geometry.hlsl"
|
||||
|
||||
CBUFFER_START(CrestPerWaterInput)
|
||||
bool _Crest_Inverted;
|
||||
CBUFFER_END
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float3 positionOS : POSITION;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float3 positionWS : TEXCOORD0;
|
||||
};
|
||||
|
||||
Varyings Vertex(Attributes input)
|
||||
{
|
||||
Varyings o;
|
||||
o.positionCS = UnityObjectToClipPos(input.positionOS);
|
||||
o.positionWS = mul(unity_ObjectToWorld, float4(input.positionOS, 1.0));
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 Fragment(Varyings input, const bool isFrontFace)
|
||||
{
|
||||
float3 surfacePositionWS = Cascade::MakeAnimatedWaves(_Crest_LodIndex)
|
||||
.SampleDisplacementFromUndisplaced(input.positionWS.xz);
|
||||
|
||||
// Move to sea level.
|
||||
surfacePositionWS.y += g_Crest_WaterCenter.y;
|
||||
|
||||
// Clip if above water.
|
||||
if (input.positionWS.y > surfacePositionWS.y)
|
||||
{
|
||||
clip(-1.0);
|
||||
}
|
||||
|
||||
// To add clipping, back face must write one and front face must write zero.
|
||||
return float4(isFrontFace == _Crest_Inverted ? 1.0 : 0.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
m_CrestVertex
|
||||
m_CrestFragmentWithFrontFace(float4)
|
||||
|
||||
ENDCG
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZWrite Off
|
||||
ColorMask R
|
||||
|
||||
Pass
|
||||
{
|
||||
Cull Front
|
||||
// Here so CGINCLUDE works.
|
||||
CGPROGRAM
|
||||
ENDCG
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Cull Back
|
||||
// Here so CGINCLUDE works.
|
||||
CGPROGRAM
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f5d1e029c7564da8855bf97e3b9247a
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,97 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#pragma kernel CrestExecute
|
||||
|
||||
#pragma multi_compile_local d_Sphere d_Cube d_Rectangle
|
||||
#pragma multi_compile_local __ d_Inverted
|
||||
|
||||
#include "HLSLSupport.cginc"
|
||||
|
||||
#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/Cascade.hlsl"
|
||||
|
||||
RWTexture2DArray<float1> _Crest_Target;
|
||||
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
float3 _Crest_Position;
|
||||
float _Crest_Diameter;
|
||||
float4x4 _Crest_Matrix;
|
||||
CBUFFER_END
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
// Also covers elipsoids etc.
|
||||
float SphereSDF(float3 position)
|
||||
{
|
||||
// Distance from center.
|
||||
return length(position);
|
||||
}
|
||||
|
||||
// Also covers rectangular prisms etc.
|
||||
float CubeSDF(float3 position)
|
||||
{
|
||||
// Restrict to one quadrant of a box.
|
||||
position = abs(position);
|
||||
// Get furthest distance from center.
|
||||
return max(position.x, max(position.y, position.z));
|
||||
}
|
||||
|
||||
float RectangleSDF(float2 position)
|
||||
{
|
||||
// Restrict to one quadrant of a box.
|
||||
position = abs(position);
|
||||
// Get furthest distance from center.
|
||||
return max(position.x, position.y);
|
||||
}
|
||||
|
||||
void Execute(uint3 id)
|
||||
{
|
||||
const Cascade cascade = Cascade::MakeClip(id.z);
|
||||
const float2 positionXZ = cascade.IDToWorld(id.xy);
|
||||
|
||||
// TODO: Optimize with something better than spherical culling.
|
||||
// Spherical culling. Check diameter for buffered area.
|
||||
if (length(positionXZ - _Crest_Position.xz) > _Crest_Diameter)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float3 position = 0.0;
|
||||
position.xz = positionXZ;
|
||||
|
||||
#if !d_Rectangle
|
||||
// Only need height as clip surface is sampled at the displaced position.
|
||||
const float3 surface = Cascade::MakeAnimatedWaves(id.z).SampleDisplacementFromUndisplaced(positionXZ);
|
||||
position.y = g_Crest_WaterCenter.y + surface.y;
|
||||
#endif
|
||||
|
||||
// SDF operate in local space.
|
||||
position = mul(_Crest_Matrix, float4(position, 1.0)).xyz;
|
||||
|
||||
float sdf = 0;
|
||||
|
||||
#if d_Sphere
|
||||
sdf = SphereSDF(position);
|
||||
#endif
|
||||
|
||||
#if d_Cube
|
||||
sdf = CubeSDF(position);
|
||||
#endif
|
||||
|
||||
#if d_Rectangle
|
||||
sdf = RectangleSDF(position.xz);
|
||||
#endif
|
||||
|
||||
#if d_Inverted
|
||||
_Crest_Target[id.xyz] = min(_Crest_Target[id.xyz], sdf);
|
||||
#else
|
||||
sdf = 1.0 - sdf;
|
||||
_Crest_Target[id.xyz] = max(_Crest_Target[id.xyz], sdf);
|
||||
#endif
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
m_CrestInputKernelDefault(Execute)
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad943abdbda794e98b8decce3329fcd8
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,47 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Adds clipping from a provided texture. Used by Painted and Texture input modes.
|
||||
|
||||
#pragma kernel CrestExecute
|
||||
|
||||
#include "HLSLSupport.cginc"
|
||||
|
||||
#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/Helpers.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/InputsDriven.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Cascade.hlsl"
|
||||
|
||||
Texture2D _Crest_Texture;
|
||||
RWTexture2DArray<float> _Crest_Target;
|
||||
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
CBUFFER_END
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
void Execute(uint3 id)
|
||||
{
|
||||
const Cascade cascade = Cascade::MakeClip(id.z);
|
||||
const float2 uv = DataIDToInputUV(id.xy, cascade, _Crest_TexturePosition, _Crest_TextureRotation, _Crest_TextureSize);
|
||||
|
||||
// Check we are within bounds.
|
||||
if (!WithinUV(uv))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const float result = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0).x;
|
||||
|
||||
// Painted clip defines a minimum value of the clip.
|
||||
_Crest_Target[id] = max(_Crest_Target[id], result);
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
m_CrestInputKernelDefault(Execute)
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb559b0e067b5464792b8e434189347c
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,4 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Hidden/Crest" { }
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cdf2728920d024e9fb0e708e1dc364bb
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,128 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Copies the depth buffer into the cache as object-space height. Object-space is
|
||||
// used instead of world-space to allow relative movement of baked depth caches
|
||||
// afterwards. It is converted to world-space in another shader before writing into
|
||||
// the LOD data.
|
||||
|
||||
#pragma kernel CrestCopy
|
||||
#pragma kernel CrestFill
|
||||
|
||||
#pragma multi_compile_local __ d_Crest_BackFaceInclusion
|
||||
|
||||
#include "HLSLSupport.cginc"
|
||||
#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/Globals.hlsl"
|
||||
|
||||
Texture2D<float> _CamDepthBuffer;
|
||||
RWTexture2D<float2> _Crest_Target;
|
||||
|
||||
#if d_Crest_BackFaceInclusion
|
||||
Texture2D<float> _Crest_CameraDepthBufferBackfaces;
|
||||
#endif
|
||||
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
float4 _HeightNearHeightFar;
|
||||
float4 _CustomZBufferParams;
|
||||
float _HeightOffset;
|
||||
float _Crest_PreviousPlane;
|
||||
CBUFFER_END
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
float CustomLinear01Depth(const float z)
|
||||
{
|
||||
return (1.0 - z * _CustomZBufferParams.x) / _CustomZBufferParams.y;
|
||||
}
|
||||
|
||||
void Copy(const uint3 id)
|
||||
{
|
||||
const float deviceDepth = _CamDepthBuffer[id.xy].x;
|
||||
|
||||
// If geometry has been clipped by far plane, set the maximum depth.
|
||||
if (deviceDepth <= 0.0)
|
||||
{
|
||||
_Crest_Target[id.xy] = -CREST_WATER_DEPTH_BASELINE;
|
||||
return;
|
||||
}
|
||||
|
||||
const float linear01Z = CustomLinear01Depth(deviceDepth);
|
||||
|
||||
const float altitude =
|
||||
#if UNITY_REVERSED_Z
|
||||
lerp(_HeightNearHeightFar.y, _HeightNearHeightFar.x, linear01Z);
|
||||
#else
|
||||
lerp(_HeightNearHeightFar.x, _HeightNearHeightFar.y, linear01Z);
|
||||
#endif
|
||||
|
||||
_Crest_Target[id.xy] = altitude - _HeightOffset;
|
||||
}
|
||||
|
||||
void Fill(const uint3 id)
|
||||
{
|
||||
const float deviceDepth = _CamDepthBuffer[id.xy].x;
|
||||
|
||||
#if d_Crest_BackFaceInclusion
|
||||
const float deviceBackFaceDepth = _Crest_CameraDepthBufferBackfaces[id.xy].x;
|
||||
#endif
|
||||
|
||||
// If geometry has been clipped by far plane, set the maximum depth.
|
||||
if (deviceDepth <= 0.0)
|
||||
{
|
||||
#if d_Crest_BackFaceInclusion
|
||||
if (deviceBackFaceDepth <= 0.0)
|
||||
#endif
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If not a hole, do not proceed.
|
||||
// We must be limiteed by precision on trying to represent depth baseline
|
||||
if (_Crest_Target[id.xy].x > -CREST_WATER_DEPTH_BASELINE)
|
||||
{
|
||||
#if d_Crest_BackFaceInclusion
|
||||
if (deviceBackFaceDepth <= 0.0)
|
||||
#endif
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const float linear01Z = CustomLinear01Depth(deviceDepth);
|
||||
|
||||
const float altitude =
|
||||
#if UNITY_REVERSED_Z
|
||||
lerp(_HeightNearHeightFar.y, _HeightNearHeightFar.x, linear01Z);
|
||||
#else
|
||||
lerp(_HeightNearHeightFar.x, _HeightNearHeightFar.y, linear01Z);
|
||||
#endif
|
||||
|
||||
|
||||
#if d_Crest_BackFaceInclusion
|
||||
{
|
||||
const float linear01Z = CustomLinear01Depth(deviceBackFaceDepth);
|
||||
const float altitude =
|
||||
#if UNITY_REVERSED_Z
|
||||
lerp(_HeightNearHeightFar.y, _HeightNearHeightFar.x, linear01Z);
|
||||
#else
|
||||
lerp(_HeightNearHeightFar.x, _HeightNearHeightFar.y, linear01Z);
|
||||
#endif
|
||||
|
||||
// Check backfaces.
|
||||
if (altitude > (_Crest_PreviousPlane + 0.00001))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
_Crest_Target[id.xy] = altitude - _HeightOffset;
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
m_CrestKernelDefault(Copy)
|
||||
m_CrestKernelDefault(Fill)
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6bb3e13f5a77e489584dd6fe9dd28a4f
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,69 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Draw cached world-space heights into current frame data. If heights are coming
|
||||
// from an ODC, then they are in object-space and are converted to world-space as
|
||||
// the LOD data stores world-space height.
|
||||
|
||||
#pragma kernel CrestExecute
|
||||
|
||||
#pragma multi_compile_local __ d_CrestSDF
|
||||
|
||||
#include "HLSLSupport.cginc"
|
||||
|
||||
#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/Helpers.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/InputsDriven.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Cascade.hlsl"
|
||||
|
||||
#define m_CrestType float
|
||||
|
||||
#if d_CrestSDF
|
||||
#undef m_CrestType
|
||||
#define m_CrestType float2
|
||||
#endif
|
||||
|
||||
Texture2D<m_CrestType> _Crest_Texture;
|
||||
RWTexture2DArray<m_CrestType> _Crest_Target;
|
||||
|
||||
CBUFFER_START(CrestInputTexture)
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
float _Crest_HeightOffset;
|
||||
bool _Crest_SDF;
|
||||
CBUFFER_END
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
void Execute(uint3 id)
|
||||
{
|
||||
const Cascade cascade = Cascade::MakeDepth(id.z);
|
||||
const float2 uv = DataIDToInputUV(id.xy, cascade, _Crest_TexturePosition, _Crest_TextureRotation, _Crest_TextureSize);
|
||||
|
||||
// Check we are within bounds.
|
||||
if (!WithinUV(uv))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
m_CrestType current = _Crest_Target[id];
|
||||
m_CrestType result = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0);
|
||||
result.x += _Crest_HeightOffset;
|
||||
|
||||
// Take highest terrain height.
|
||||
result.x = max(current.x, result.x);
|
||||
|
||||
#if d_CrestSDF
|
||||
// Take shortest distance.
|
||||
result.y = _Crest_SDF ? min(current.y, result.y) : current.y;
|
||||
#endif
|
||||
|
||||
_Crest_Target[id] = result;
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
m_CrestInputKernelDefault(Execute)
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 025c29236eb8341f0a2078d93379be6a
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,67 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Adds flow from a provided texture. Used by Painted and Texture input modes.
|
||||
|
||||
#pragma kernel CrestExecute
|
||||
|
||||
#include "HLSLSupport.cginc"
|
||||
|
||||
#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/Helpers.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/InputsDriven.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Cascade.hlsl"
|
||||
|
||||
Texture2D _Crest_Texture;
|
||||
RWTexture2DArray<float2> _Crest_Target;
|
||||
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
int _Crest_Blend;
|
||||
float _Crest_Weight;
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
float _Crest_FeatherWidth;
|
||||
bool _Crest_NegativeValues;
|
||||
CBUFFER_END
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
void Execute(uint3 id)
|
||||
{
|
||||
const Cascade cascade = Cascade::MakeFlow(id.z);
|
||||
const float2 uv = DataIDToInputUV(id.xy, cascade, _Crest_TexturePosition, _Crest_TextureRotation, _Crest_TextureSize);
|
||||
|
||||
half weight = _Crest_Weight;
|
||||
|
||||
// Feather boundaries.
|
||||
weight *= FeatherWeightFromUV(uv, _Crest_FeatherWidth);
|
||||
|
||||
// Check we are within bounds.
|
||||
if (weight <= 0.0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float2 source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0).xy;
|
||||
|
||||
if (!_Crest_NegativeValues)
|
||||
{
|
||||
// From 0..1 to -1..1.
|
||||
source = source * 2.0 - 1.0;
|
||||
}
|
||||
|
||||
if (_Crest_Blend == m_CrestBlendAlpha)
|
||||
{
|
||||
weight *= saturate(length(source));
|
||||
}
|
||||
|
||||
const float2 target = _Crest_Target[id];
|
||||
_Crest_Target[id] = Blend(_Crest_Blend, weight, 1.0, source, target);
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
m_CrestInputKernelDefault(Execute)
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67ee915fe51504dd894c5cbf6f1a7868
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,56 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Adds foam from a provided texture. Used by Painted and Texture input modes.
|
||||
|
||||
#pragma kernel CrestExecute
|
||||
|
||||
#include "HLSLSupport.cginc"
|
||||
|
||||
#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/Helpers.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/InputsDriven.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Cascade.hlsl"
|
||||
|
||||
Texture2D _Crest_Texture;
|
||||
RWTexture2DArray<float> _Crest_Target;
|
||||
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
int _Crest_Blend;
|
||||
float _Crest_Weight;
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
float _Crest_FeatherWidth;
|
||||
float _Crest_SimDeltaTime;
|
||||
CBUFFER_END
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
void Execute(uint3 id)
|
||||
{
|
||||
const Cascade cascade = Cascade::MakeFoam(id.z);
|
||||
const float2 uv = DataIDToInputUV(id.xy, cascade, _Crest_TexturePosition, _Crest_TextureRotation, _Crest_TextureSize);
|
||||
|
||||
half weight = _Crest_Weight;
|
||||
|
||||
// Boundary check with feathering.
|
||||
weight *= FeatherWeightFromUV(uv, _Crest_FeatherWidth);
|
||||
|
||||
// Check we are within bounds.
|
||||
if (weight <= 0.0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const float source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0).x;
|
||||
const float target = _Crest_Target[id];
|
||||
|
||||
_Crest_Target[id] = Blend(_Crest_Blend, weight, _Crest_SimDeltaTime, source, target);
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
m_CrestInputKernelDefault(Execute)
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 69307e5986e134adc90ee257e7dba1ea
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,154 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// An implementation of the Jump Flood algorithm by Rong and Tan
|
||||
// Source: https://www.comp.nus.edu.sg/~tants/jfa.html
|
||||
|
||||
#pragma kernel CrestInitialize
|
||||
#pragma kernel CrestExecute
|
||||
#pragma kernel CrestApply
|
||||
|
||||
#pragma multi_compile_local __ d_Crest_Inverted
|
||||
#pragma multi_compile_local __ d_Crest_Standalone
|
||||
|
||||
#include "HLSLSupport.cginc"
|
||||
#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/Globals.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Helpers.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Cascade.hlsl"
|
||||
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
uint _Crest_JumpSize;
|
||||
uint _Crest_TextureSize;
|
||||
float4x4 _Crest_ProjectionToWorld;
|
||||
float _Crest_HeightOffset;
|
||||
float _Crest_WaterLevel;
|
||||
CBUFFER_END
|
||||
|
||||
// Holds scene depth for initialization.
|
||||
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 float2(m_Crest_PositiveInfinity, m_Crest_PositiveInfinity)
|
||||
|
||||
#if d_Crest_Inverted
|
||||
#define m_DepthCheck depth > 0.0
|
||||
#else
|
||||
#define m_DepthCheck depth <= 0.0
|
||||
#endif
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
bool IsUninitializedPosition(const float2 position)
|
||||
{
|
||||
return isinf(position.x);
|
||||
}
|
||||
|
||||
float2 IDtoWorld(const uint2 id, const float resolution, const float4x4 projectionToWorld)
|
||||
{
|
||||
float2 uv = (((id + 0.5) / resolution) - 0.5) * 2.0;
|
||||
return mul(projectionToWorld, float4(uv, 0.0, 1.0)).xz;
|
||||
}
|
||||
|
||||
void Initialize(const uint3 id)
|
||||
{
|
||||
float2 position = IDtoWorld(id.xy, _Crest_TextureSize, _Crest_ProjectionToWorld);
|
||||
float depth = _Crest_WaterLevel - (_Crest_Source[id.xy].x + _Crest_HeightOffset);
|
||||
|
||||
#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);
|
||||
depth += lerp(Cascade::MakeLevel(slice0).SampleLevel(position), Cascade::MakeLevel(slice1).SampleLevel(position), alpha);
|
||||
#endif
|
||||
|
||||
_Crest_Target[id.xy] = m_DepthCheck ? position : m_CrestUninitializedPosition;
|
||||
}
|
||||
|
||||
void Execute(const uint3 id)
|
||||
{
|
||||
float2 nearest = _Crest_Source[id.xy];
|
||||
|
||||
const uint3 jump = uint3(_Crest_JumpSize, -(int)_Crest_JumpSize, 0);
|
||||
const bool xBounds = _Crest_TextureSize - _Crest_JumpSize > id.x;
|
||||
const bool yBounds = _Crest_TextureSize - _Crest_JumpSize > id.y;
|
||||
const bool zBounds = id.x >= _Crest_JumpSize;
|
||||
const bool wBounds = id.y >= _Crest_JumpSize;
|
||||
|
||||
float2 candidates[8];
|
||||
candidates[0] = yBounds ? _Crest_Source[id.xy + jump.zx] : nearest;
|
||||
candidates[1] = yBounds && xBounds ? _Crest_Source[id.xy + jump.xx] : nearest;
|
||||
candidates[2] = xBounds ? _Crest_Source[id.xy + jump.xz] : nearest;
|
||||
candidates[3] = xBounds && wBounds ? _Crest_Source[id.xy + jump.xy] : nearest;
|
||||
candidates[4] = wBounds ? _Crest_Source[id.xy + jump.zy] : nearest;
|
||||
candidates[5] = wBounds && zBounds ? _Crest_Source[id.xy + jump.yy] : nearest;
|
||||
candidates[6] = zBounds ? _Crest_Source[id.xy + jump.yz] : nearest;
|
||||
candidates[7] = zBounds && yBounds ? _Crest_Source[id.xy + jump.yx] : nearest;
|
||||
|
||||
const float2 position = IDtoWorld(id.xy, _Crest_TextureSize, _Crest_ProjectionToWorld);
|
||||
const float2 displacement = nearest - position;
|
||||
float distance2 = dot(displacement, displacement);
|
||||
|
||||
for (uint i = 0; i < 8; i++)
|
||||
{
|
||||
if (IsUninitializedPosition(nearest))
|
||||
{
|
||||
nearest = candidates[i];
|
||||
continue;
|
||||
}
|
||||
|
||||
const float2 candidateDisplacement = candidates[i] - position;
|
||||
const float candidateDistance2 = dot(candidateDisplacement, candidateDisplacement);
|
||||
|
||||
if (candidateDistance2 < distance2)
|
||||
{
|
||||
nearest = candidates[i];
|
||||
distance2 = candidateDistance2;
|
||||
}
|
||||
}
|
||||
|
||||
_Crest_Target[id.xy] = nearest;
|
||||
}
|
||||
|
||||
void Apply(const uint3 id)
|
||||
{
|
||||
float2 result = _Crest_Target[id.xy];
|
||||
float2 position = IDtoWorld(id.xy, _Crest_TextureSize, _Crest_ProjectionToWorld);
|
||||
|
||||
#if d_Crest_Inverted
|
||||
float depth = _Crest_WaterLevel - (result.x + _Crest_HeightOffset);
|
||||
|
||||
#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);
|
||||
depth += lerp(Cascade::MakeLevel(slice0).SampleLevel(position), Cascade::MakeLevel(slice1).SampleLevel(position), alpha);
|
||||
#endif
|
||||
|
||||
// Do not overwrite positive SDF.
|
||||
if (depth > 0) return;
|
||||
#endif
|
||||
|
||||
float2 nearest = _Crest_Source[id.xy];
|
||||
float2 displacement = nearest - position;
|
||||
|
||||
float distance = length(displacement);
|
||||
|
||||
#if d_Crest_Inverted
|
||||
distance = -distance;
|
||||
#endif
|
||||
|
||||
result.y = distance;
|
||||
|
||||
_Crest_Target[id.xy] = result;
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
m_CrestKernelDefault(Initialize)
|
||||
m_CrestKernelDefault(Execute)
|
||||
m_CrestKernelDefault(Apply)
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 55a9b76c48b7343b2b66ed91a0619c29
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,63 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Adds height from a provided texture. Used by Painted and Texture input modes.
|
||||
|
||||
#pragma kernel CrestExecute
|
||||
|
||||
#pragma multi_compile_local __ d_CatmullRom
|
||||
|
||||
#include "HLSLSupport.cginc"
|
||||
|
||||
#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/Helpers.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/InputsDriven.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Cascade.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Utility/Filtering.hlsl"
|
||||
|
||||
m_DisplacementTexture(Texture2D, 4) _Crest_Texture;
|
||||
RWTexture2DArray<float> _Crest_Target;
|
||||
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
int _Crest_Blend;
|
||||
float _Crest_Weight;
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
float2 _Crest_Resolution;
|
||||
CBUFFER_END
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
void Execute(uint3 id)
|
||||
{
|
||||
const Cascade cascade = Cascade::MakeLevel(id.z);
|
||||
const float2 uv = DataIDToInputUV(id.xy, cascade, _Crest_TexturePosition, _Crest_TextureRotation, _Crest_TextureSize);
|
||||
|
||||
half weight = _Crest_Weight;
|
||||
|
||||
// Feather boundaries.
|
||||
weight *= FeatherWeightFromUV(uv, 0.0);
|
||||
|
||||
// Check we are within bounds.
|
||||
if (weight <= 0.0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#if d_CatmullRom
|
||||
const float source = Utility::SampleTextureCatmullRom(_Crest_Texture, LODData_linear_clamp_sampler, uv, _Crest_Resolution).x;
|
||||
#else
|
||||
const float source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0.0).x;
|
||||
#endif
|
||||
|
||||
const float target = _Crest_Target[id];
|
||||
|
||||
_Crest_Target[id] = Blend(_Crest_Blend, weight, 1.0, source, target);
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
m_CrestInputKernelDefault(Execute)
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6bccbd92220dc418cacd3f17096c6b97
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,54 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#pragma kernel CrestExecute
|
||||
|
||||
#include "HLSLSupport.cginc"
|
||||
|
||||
#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/Helpers.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/InputsDriven.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Cascade.hlsl"
|
||||
|
||||
Texture2D _Crest_Texture;
|
||||
RWTexture2DArray<float3> _Crest_Target;
|
||||
|
||||
CBUFFER_START(CrestPerMaterial)
|
||||
int _Crest_Blend;
|
||||
float _Crest_Weight;
|
||||
float2 _Crest_TextureSize;
|
||||
float2 _Crest_TexturePosition;
|
||||
float2 _Crest_TextureRotation;
|
||||
float _Crest_FeatherWidth;
|
||||
CBUFFER_END
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
void Execute(uint3 id)
|
||||
{
|
||||
const Cascade cascade = Cascade::MakeScattering(id.z);
|
||||
const float2 uv = DataIDToInputUV(id.xy, cascade, _Crest_TexturePosition, _Crest_TextureRotation, _Crest_TextureSize);
|
||||
|
||||
half weight = _Crest_Weight;
|
||||
|
||||
// Feather boundaries.
|
||||
weight *= FeatherWeightFromUV(uv, _Crest_FeatherWidth);
|
||||
|
||||
// Check we are within bounds.
|
||||
if (weight <= 0.0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const half4 source = _Crest_Texture.SampleLevel(LODData_linear_clamp_sampler, uv, 0);
|
||||
const half3 target = _Crest_Target[id];
|
||||
weight *= source.a;
|
||||
|
||||
_Crest_Target[id] = Blend(_Crest_Blend, weight, 1.0, source.xyz, target);
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
m_CrestInputKernelDefault(Execute)
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78d6b75ecfb664f0cbb70001b1446627
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,124 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
#pragma kernel CrestExecute
|
||||
|
||||
#include "HLSLSupport.cginc"
|
||||
|
||||
#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/Helpers.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/InputsDriven.hlsl"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Cascade.hlsl"
|
||||
|
||||
RWTexture2DArray<float2> _Crest_Target;
|
||||
|
||||
CBUFFER_START(CrestPerWaterInput)
|
||||
float3 _Crest_Position;
|
||||
float3 _Crest_Velocity;
|
||||
float _Crest_SimDeltaTime;
|
||||
float _Crest_Weight;
|
||||
float _Crest_Radius;
|
||||
float _Crest_InnerSphereOffset;
|
||||
float _Crest_InnerSphereMultiplier;
|
||||
float _Crest_LargeWaveMultiplier;
|
||||
CBUFFER_END
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
// Resolution-aware interaction falloff function, inspired by "bandfiltered step"
|
||||
// from Ottosson. Basically adding together this falloff function at different
|
||||
// scales generates a consistent result that doesn't grow into an ugly uintended
|
||||
// shape. Shadertoy with more details: https://www.shadertoy.com/view/WltBWM
|
||||
float InteractionFalloff(float a, float x)
|
||||
{
|
||||
float ax = a * x;
|
||||
float ax2 = ax * ax;
|
||||
float ax4 = ax2 * ax2;
|
||||
|
||||
return ax / (1.0 + ax2 * ax4);
|
||||
}
|
||||
|
||||
void SphereSDF(float2 offsetXZ, out float sdf, out float2 normal)
|
||||
{
|
||||
float distance = length(offsetXZ);
|
||||
sdf = distance - _Crest_Radius;
|
||||
normal = distance > 0.0001 ? offsetXZ / distance : float2(1.0, 0.0);
|
||||
}
|
||||
|
||||
void Execute(uint3 id)
|
||||
{
|
||||
const Cascade cascade = Cascade::MakeDynamicWaves(id.z);
|
||||
|
||||
if (_Crest_LargeWaveMultiplier * _Crest_Radius < cascade._Texel)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float2 positionXZ = cascade.IDToWorld(id.xy);
|
||||
float2 offsetXZ = positionXZ - _Crest_Position.xz;
|
||||
|
||||
// Spherical culling. Check diameter for buffered area.
|
||||
if (length(offsetXZ) > _Crest_Radius * 4.0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Feather at edges of LOD to reduce streaking without reflections.
|
||||
half weight = _Crest_Weight * FeatherWeightFromUV(cascade.WorldToUV(positionXZ).xy, 0.1);
|
||||
|
||||
// Check we are within bounds.
|
||||
if (weight <= 0.0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float minimumWavelength = Cascade::Make(id.z)._MaximumWavelength * 0.5;
|
||||
|
||||
float sdf;
|
||||
float2 sdfNormal;
|
||||
SphereSDF(offsetXZ, sdf, sdfNormal);
|
||||
|
||||
// Push in same direction as velocity inside sphere, and opposite direction outside.
|
||||
float verticalForce = 0.0;
|
||||
{
|
||||
verticalForce = -_Crest_Velocity.y;
|
||||
|
||||
// Range / radius of interaction force
|
||||
const float a = 1.67 / minimumWavelength;
|
||||
verticalForce *= InteractionFalloff( a, sdf );
|
||||
}
|
||||
|
||||
// Push water up in direction of motion, pull down behind.
|
||||
float horizontalForce = 0.0;
|
||||
if (sdf > 0.0 || sdf < -_Crest_Radius * _Crest_InnerSphereOffset)
|
||||
{
|
||||
// Range / radius of interaction force.
|
||||
const float a = 1.43 / minimumWavelength;
|
||||
|
||||
// Invert within sphere, to balance / negate forces applied outside of sphere.
|
||||
float forceSign = sign(sdf);
|
||||
|
||||
horizontalForce = forceSign * dot(sdfNormal, _Crest_Velocity.xz) * InteractionFalloff(a, abs(sdf));
|
||||
|
||||
// If inside sphere, add an additional weight.
|
||||
if (sdf < 0.0)
|
||||
{
|
||||
horizontalForce *= _Crest_InnerSphereMultiplier;
|
||||
}
|
||||
}
|
||||
|
||||
// Add to velocity (y-channel) to accelerate water. Magic number was the default
|
||||
// value for _Strength which has been removed.
|
||||
float acceleration = weight * (verticalForce + horizontalForce) * 0.2;
|
||||
|
||||
// Helps interaction to work at different scales
|
||||
acceleration /= minimumWavelength;
|
||||
|
||||
_Crest_Target[id] = float2(_Crest_Target[id].x, _Crest_Target[id].y + acceleration * _Crest_SimDeltaTime);
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
m_CrestInputKernelDefault(Execute)
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98fb0af5d79724a2c945809b974524eb
|
||||
ComputeShaderImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,52 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Crest/Inputs/All/Override"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[Enum(ColorWriteMask)]
|
||||
_Crest_ColorMask("Color Mask", Int) = 15
|
||||
_Crest_Value("Value", Vector) = (1, 1, 1, 1)
|
||||
|
||||
[HideInInspector]
|
||||
_Crest_Version("Version", Integer) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
Blend Off
|
||||
ColorMask [_Crest_ColorMask]
|
||||
ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
CBUFFER_START(CrestPerWaterInput)
|
||||
float3 _Crest_DisplacementAtInputPosition;
|
||||
half4 _Crest_Value;
|
||||
half _Crest_Weight;
|
||||
CBUFFER_END
|
||||
|
||||
float4 Vertex(float3 positionOS : POSITION) : SV_POSITION
|
||||
{
|
||||
float3 positionWS = mul(unity_ObjectToWorld, float4(positionOS, 1.0)).xyz;
|
||||
// Correct for displacement.
|
||||
positionWS.xz -= _Crest_DisplacementAtInputPosition.xz;
|
||||
return mul(UNITY_MATRIX_VP, float4(positionWS, 1.0));
|
||||
}
|
||||
|
||||
half4 Fragment() : SV_Target
|
||||
{
|
||||
return _Crest_Value * _Crest_Weight;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
CustomEditor "WaveHarmonic.Crest.Editor.CustomShaderGUI"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 288a089f90e714983b8a760dd49e5a5c
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,129 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// 0-1 scaling of existing water data using multiplicative blending.
|
||||
|
||||
Shader "Crest/Inputs/All/Scale"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
// Scale the water data. Zero is no data and one leaves data untouched.
|
||||
_Crest_Scale("Scale", Range(0, 1)) = 0.35
|
||||
|
||||
// Use the texture instead of the scale value.
|
||||
[Toggle(d_Texture)]
|
||||
_Crest_ApplyTexture("Apply Texture", Float) = 0
|
||||
[MainTexture] _Crest_Texture("Texture", 2D) = "black" {}
|
||||
|
||||
// Inverts the scale value.
|
||||
[Toggle(d_Invert)]
|
||||
_Crest_Invert("Invert", Float) = 0
|
||||
|
||||
[Header(Feather)]
|
||||
// Feather the edges of the mesh using the texture coordinates. Easiest to understand with a plane.
|
||||
[Toggle(d_Feather)]
|
||||
_Crest_Feather("Feather At UV Extents", Float) = 0
|
||||
// How far from edge to feather.
|
||||
_Crest_FeatherWidth("Feather Width", Range(0.001, 0.5)) = 0.1
|
||||
|
||||
[HideInInspector]
|
||||
_Crest_Version("Version", Integer) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
// Multiply
|
||||
Blend Zero SrcColor
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex Vert
|
||||
#pragma fragment Frag
|
||||
|
||||
#pragma shader_feature_local d_Texture
|
||||
#pragma shader_feature_local d_Invert
|
||||
#pragma shader_feature_local d_Feather
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
#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/Helpers.hlsl"
|
||||
|
||||
#if defined(d_Texture) || defined(d_Feather)
|
||||
#define _NEED_UVS
|
||||
#endif
|
||||
|
||||
#if d_Texture
|
||||
Texture2D _Crest_Texture;
|
||||
SamplerState sampler_Crest_Texture;
|
||||
#endif
|
||||
|
||||
CBUFFER_START(CrestPerWaterInput)
|
||||
float _Crest_Weight;
|
||||
float3 _Crest_DisplacementAtInputPosition;
|
||||
float _Crest_Scale;
|
||||
#if d_Feather
|
||||
half _Crest_FeatherWidth;
|
||||
#endif
|
||||
#if d_Texture
|
||||
float4 _Crest_Texture_ST;
|
||||
#endif
|
||||
CBUFFER_END
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float3 positionOS : POSITION;
|
||||
#ifdef _NEED_UVS
|
||||
float2 uv : TEXCOORD0;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
#ifdef _NEED_UVS
|
||||
float2 uv : TEXCOORD0;
|
||||
#endif
|
||||
};
|
||||
|
||||
Varyings Vert(Attributes input)
|
||||
{
|
||||
Varyings o;
|
||||
|
||||
float3 positionWS = mul(unity_ObjectToWorld, float4(input.positionOS, 1.0)).xyz;
|
||||
// Correct for displacement.
|
||||
positionWS.xz -= _Crest_DisplacementAtInputPosition.xz;
|
||||
o.positionCS = mul(UNITY_MATRIX_VP, float4(positionWS, 1.0));
|
||||
|
||||
#ifdef _NEED_UVS
|
||||
o.uv = input.uv;
|
||||
#endif
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 Frag(Varyings input) : SV_Target
|
||||
{
|
||||
#if d_Texture
|
||||
float scale = _Crest_Texture.Sample(sampler_Crest_Texture, input.uv).r;
|
||||
#else
|
||||
float scale = _Crest_Scale;
|
||||
#endif
|
||||
|
||||
#if d_Invert
|
||||
scale = 1.0 - scale;
|
||||
#endif
|
||||
|
||||
#if d_Feather
|
||||
scale = lerp(1.0, scale, WaveHarmonic::Crest::FeatherWeightFromUV(input.uv, _Crest_FeatherWidth));
|
||||
#endif
|
||||
|
||||
return scale * _Crest_Weight;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
CustomEditor "WaveHarmonic.Crest.Editor.CustomShaderGUI"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cbf67e7cbdc0a4cc09a539707e0007b9
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,82 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Crest/Inputs/Scattering/Color"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Crest_Scattering("Scattering", Color) = (0.0, 0.09803921729326248, 0.20000000298023225, 0.0)
|
||||
|
||||
[Toggle(d_Feather)]
|
||||
_Crest_Feather("Feather At UV Extents", Float) = 0
|
||||
_Crest_FeatherWidth("Feather Width", Range(0.001, 0.5)) = 0.1
|
||||
|
||||
[HideInInspector]
|
||||
_Crest_Version("Version", Integer) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
Blend SrcAlpha OneMinusSrcAlpha
|
||||
ZWrite Off
|
||||
ColorMask RGB
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
|
||||
#pragma shader_feature_local d_Feather
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Helpers.hlsl"
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float3 vertex : POSITION;
|
||||
#if d_Feather
|
||||
float2 uv : TEXCOORD0;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
#if d_Feather
|
||||
float2 uv : TEXCOORD0;
|
||||
#endif
|
||||
};
|
||||
|
||||
CBUFFER_START(CrestPerWaterInput)
|
||||
half4 _Crest_Scattering;
|
||||
half _Crest_FeatherWidth;
|
||||
CBUFFER_END
|
||||
|
||||
Varyings Vertex(Attributes input)
|
||||
{
|
||||
Varyings output;
|
||||
float3 positionWS = mul(unity_ObjectToWorld, float4(input.vertex, 1.0)).xyz;
|
||||
output.vertex = mul(UNITY_MATRIX_VP, float4(positionWS, 1.0));
|
||||
#if d_Feather
|
||||
output.uv = input.uv;
|
||||
#endif
|
||||
return output;
|
||||
}
|
||||
|
||||
float4 Fragment(Varyings input) : SV_Target
|
||||
{
|
||||
half4 color = _Crest_Scattering;
|
||||
color.a = 1.0;
|
||||
#if d_Feather
|
||||
color.a *= WaveHarmonic::Crest::FeatherWeightFromUV(input.uv, _Crest_FeatherWidth);
|
||||
#endif
|
||||
|
||||
return color;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
CustomEditor "WaveHarmonic.Crest.Editor.CustomShaderGUI"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ea69fc35da7574631aea97812ee8652b
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,192 +0,0 @@
|
||||
// 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
|
||||
// following data on verts:
|
||||
// - POSITION: Vert positions as normal.
|
||||
// - TEXCOORD0: Axis - direction for waves to travel. "Forward vector" for waves.
|
||||
// - TEXCOORD1: X - 0 at start of waves, 1 at end of waves
|
||||
//
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ uv1.x = 0 |
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | | uv0 - wave direction vector
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | \|/
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ uv1.x = 1
|
||||
// ------------------- shoreline --------------------
|
||||
//
|
||||
|
||||
Shader "Crest/Inputs/Shape Waves/Add From Geometry"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[Enum(UnityEngine.Rendering.BlendMode)]
|
||||
_Crest_BlendModeSource("Source Blend Mode", Int) = 1
|
||||
[Enum(UnityEngine.Rendering.BlendMode)]
|
||||
_Crest_BlendModeTarget("Target Blend Mode", Int) = 1
|
||||
|
||||
// Controls ramp distance over which waves grow/fade as they move forwards
|
||||
_Crest_FeatherWaveStart( "Feather wave start (0-1)", Range( 0.0, 10 ) ) = 0.1
|
||||
|
||||
[Toggle(d_Feather)]
|
||||
_Crest_Feather("Feather At UV Extents", Float) = 0
|
||||
_Crest_FeatherWidth("Feather Width", Range(0.001, 1)) = 0.1
|
||||
|
||||
[HideInInspector]
|
||||
_Crest_Version("Version", Integer) = 0
|
||||
}
|
||||
|
||||
CGINCLUDE
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
// #pragma enable_d3d11_debug_symbols
|
||||
|
||||
#pragma shader_feature_local d_Feather
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Macros.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"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Helpers.hlsl"
|
||||
|
||||
Texture2DArray _Crest_WaveBuffer;
|
||||
|
||||
CBUFFER_START(CrestPerWaterInput)
|
||||
float _Crest_RespectShallowWaterAttenuation;
|
||||
int _Crest_WaveBufferSliceIndex;
|
||||
float _Crest_AverageWavelength;
|
||||
float _Crest_AttenuationInShallows;
|
||||
float _Crest_Weight;
|
||||
float2 _Crest_AxisX;
|
||||
half _Crest_MaximumAttenuationDepth;
|
||||
half _Crest_FeatherWidth;
|
||||
half _Crest_FeatherWaveStart;
|
||||
CBUFFER_END
|
||||
|
||||
m_CrestNameSpace
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float4 vertex : POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 vertex : SV_POSITION;
|
||||
float2 uv : TEXCOORD0;
|
||||
float3 uv_slice : TEXCOORD1;
|
||||
float2 axis : TEXCOORD2;
|
||||
float3 worldPosScaled : TEXCOORD3;
|
||||
float2 worldPosXZ : TEXCOORD5;
|
||||
};
|
||||
|
||||
Varyings Vertex(Attributes v)
|
||||
{
|
||||
Varyings o;
|
||||
|
||||
const float3 positionOS = v.vertex.xyz;
|
||||
o.vertex = UnityObjectToClipPos(positionOS);
|
||||
const float3 worldPos = mul( unity_ObjectToWorld, float4(positionOS, 1.0) ).xyz;
|
||||
|
||||
// UV coordinate into the cascade we are rendering into
|
||||
o.uv_slice = Cascade::MakeAnimatedWaves(_Crest_LodIndex).WorldToUV(worldPos.xz);
|
||||
|
||||
o.worldPosXZ = worldPos.xz;
|
||||
|
||||
o.uv = v.uv;
|
||||
|
||||
// World pos prescaled by wave buffer size, suitable for using as UVs in fragment shader
|
||||
const float waveBufferSize = 0.5f * (1 << _Crest_WaveBufferSliceIndex);
|
||||
o.worldPosScaled = worldPos / waveBufferSize;
|
||||
|
||||
// Rotate forward axis around y-axis into world space
|
||||
o.axis = unity_ObjectToWorld._m00_m20.xy;
|
||||
o.axis = _Crest_AxisX.x * o.axis + _Crest_AxisX.y * float2(-o.axis.y, o.axis.x);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 Fragment(Varyings input)
|
||||
{
|
||||
float wt = _Crest_Weight;
|
||||
|
||||
// Feature at away from shore.
|
||||
wt *= saturate(input.uv.x / _Crest_FeatherWaveStart);
|
||||
|
||||
#if d_Feather
|
||||
wt *= FeatherWeightFromUV(input.uv, _Crest_FeatherWidth);
|
||||
#endif
|
||||
|
||||
float alpha = wt;
|
||||
|
||||
// Attenuate if depth is less than half of the average wavelength
|
||||
const half depth = Cascade::MakeDepth(_Crest_LodIndex).SampleSignedDepthFromSeaLevel(input.worldPosXZ) +
|
||||
Cascade::MakeLevel(_Crest_LodIndex).SampleLevel(input.worldPosXZ);
|
||||
half depth_wt = saturate(2.0 * depth / _Crest_AverageWavelength);
|
||||
if (_Crest_MaximumAttenuationDepth < k_Crest_MaximumWaveAttenuationDepth)
|
||||
{
|
||||
depth_wt = lerp(depth_wt, 1.0, saturate(depth / _Crest_MaximumAttenuationDepth));
|
||||
}
|
||||
const float attenuationAmount = _Crest_AttenuationInShallows * _Crest_RespectShallowWaterAttenuation;
|
||||
wt *= attenuationAmount * depth_wt + (1.0 - attenuationAmount);
|
||||
|
||||
// Quantize wave direction and interpolate waves
|
||||
float axisHeading = atan2( input.axis.y, input.axis.x ) + 2.0 * 3.141592654;
|
||||
const float dTheta = 0.5*0.314159265;
|
||||
float angle0 = axisHeading;
|
||||
const float rem = fmod( angle0, dTheta );
|
||||
angle0 -= rem;
|
||||
const float angle1 = angle0 + dTheta;
|
||||
|
||||
float2 axisX0; sincos( angle0, axisX0.y, axisX0.x );
|
||||
float2 axisX1; sincos( angle1, axisX1.y, axisX1.x );
|
||||
float2 axisZ0; axisZ0.x = -axisX0.y; axisZ0.y = axisX0.x;
|
||||
float2 axisZ1; axisZ1.x = -axisX1.y; axisZ1.y = axisX1.x;
|
||||
|
||||
const float2 uv0 = float2(dot( input.worldPosScaled.xz, axisX0 ), dot( input.worldPosScaled.xz, axisZ0 ));
|
||||
const float2 uv1 = float2(dot( input.worldPosScaled.xz, axisX1 ), dot( input.worldPosScaled.xz, axisZ1 ));
|
||||
|
||||
// Sample displacement, rotate into frame
|
||||
float3 disp0 = _Crest_WaveBuffer.SampleLevel( sampler_Crest_linear_repeat, float3(uv0, _Crest_WaveBufferSliceIndex), 0 ).xyz;
|
||||
float3 disp1 = _Crest_WaveBuffer.SampleLevel( sampler_Crest_linear_repeat, float3(uv1, _Crest_WaveBufferSliceIndex), 0 ).xyz;
|
||||
disp0.xz = disp0.x * axisX0 + disp0.z * axisZ0;
|
||||
disp1.xz = disp1.x * axisX1 + disp1.z * axisZ1;
|
||||
float3 disp = lerp( disp0, disp1, rem / dTheta );
|
||||
|
||||
disp *= wt;
|
||||
|
||||
return float4(disp, alpha);
|
||||
}
|
||||
|
||||
m_CrestNameSpaceEnd
|
||||
|
||||
m_CrestVertex
|
||||
m_CrestFragment(float4)
|
||||
ENDCG
|
||||
|
||||
SubShader
|
||||
{
|
||||
ZWrite Off
|
||||
ZTest Always
|
||||
Cull Off
|
||||
|
||||
Pass
|
||||
{
|
||||
// Either additive or alpha blend for geometry waves.
|
||||
Blend [_Crest_BlendModeSource] [_Crest_BlendModeTarget]
|
||||
CGPROGRAM
|
||||
ENDCG
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
// Subsequent draws need to be additive. We cannot change render state with command
|
||||
// buffer and changing on material is not aligned with command buffer usage.
|
||||
Blend One One
|
||||
CGPROGRAM
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
CustomEditor "WaveHarmonic.Crest.Editor.CustomShaderGUI"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95ec6475fc33247d4b80d07df23f2748
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,55 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
Shader "Crest/Inputs/All/Utility"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[Enum(UnityEngine.Rendering.BlendMode)] _Crest_BlendModeSource("Source Blend Mode", Int) = 1
|
||||
[Enum(UnityEngine.Rendering.BlendMode)] _Crest_BlendModeTarget("Target Blend Mode", Int) = 1
|
||||
[Enum(UnityEngine.Rendering.BlendOp)] _Crest_BlendOperation("Blend Operation", Int) = 0
|
||||
[Enum(UnityEngine.Rendering.ColorWriteMask)] _Crest_ColorMask("Color Mask", Int) = 15
|
||||
_Crest_Value("Value", Vector) = (1, 1, 1, 1)
|
||||
|
||||
[HideInInspector]
|
||||
_Crest_Version("Version", Integer) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
Blend [_Crest_BlendModeSource] [_Crest_BlendModeTarget]
|
||||
BlendOp [_Crest_BlendOperation]
|
||||
ColorMask [_Crest_ColorMask]
|
||||
ZWrite Off
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex Vertex
|
||||
#pragma fragment Fragment
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
|
||||
CBUFFER_START(CrestPerWaterInput)
|
||||
float3 _Crest_DisplacementAtInputPosition;
|
||||
half4 _Crest_Value;
|
||||
half _Crest_Weight;
|
||||
CBUFFER_END
|
||||
|
||||
float4 Vertex(float3 positionOS : POSITION) : SV_POSITION
|
||||
{
|
||||
float3 positionWS = mul(unity_ObjectToWorld, float4(positionOS, 1.0)).xyz;
|
||||
// Correct for displacement.
|
||||
positionWS.xz -= _Crest_DisplacementAtInputPosition.xz;
|
||||
return mul(UNITY_MATRIX_VP, float4(positionWS, 1.0));
|
||||
}
|
||||
|
||||
half4 Fragment() : SV_Target
|
||||
{
|
||||
return _Crest_Value * _Crest_Weight;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
CustomEditor "WaveHarmonic.Crest.Editor.CustomShaderGUI"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 27b6f889dcd1b4d20919255e69078a08
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,54 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// Renders water depth - signed distance from sea level to sea floor
|
||||
Shader "Crest/Inputs/Depth/Water Depth From Geometry"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[HideInInspector]
|
||||
_Crest_Version("Version", Integer) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
BlendOp Max
|
||||
ColorMask R
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex Vert
|
||||
#pragma fragment Frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Constants.hlsl"
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float3 positionOS : POSITION;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float terrainHeight : TEXCOORD0;
|
||||
};
|
||||
|
||||
Varyings Vert(Attributes input)
|
||||
{
|
||||
Varyings o;
|
||||
o.positionCS = UnityObjectToClipPos(input.positionOS);
|
||||
o.terrainHeight = mul(unity_ObjectToWorld, float4(input.positionOS, 1.0)).y;
|
||||
return o;
|
||||
}
|
||||
|
||||
float4 Frag(Varyings input) : SV_Target
|
||||
{
|
||||
return float4(input.terrainHeight, 0.0, 0.0, 0.0);
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
CustomEditor "WaveHarmonic.Crest.Editor.CustomShaderGUI"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a8aeab41790ee4cb1b72e19aa4a7a1ad
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,71 +0,0 @@
|
||||
// Crest Water System
|
||||
// Copyright © 2024 Wave Harmonic. All rights reserved.
|
||||
|
||||
// This sets base water height to Y value of geometry.
|
||||
|
||||
Shader "Crest/Inputs/Level/Water Level From Geometry"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
[Enum(UnityEngine.Rendering.BlendMode)] _Crest_BlendSource("Source Blend Mode", Int) = 1
|
||||
[Enum(UnityEngine.Rendering.BlendMode)] _Crest_BlendTarget("Target Blend Mode", Int) = 0
|
||||
[Enum(UnityEngine.Rendering.BlendOp)] _Crest_BlendOperation("Blend Operation", Int) = 0
|
||||
|
||||
[HideInInspector]
|
||||
_Crest_Version("Version", Integer) = 0
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Pass
|
||||
{
|
||||
Blend [_Crest_BlendSource] [_Crest_BlendTarget]
|
||||
BlendOp [_Crest_BlendOperation]
|
||||
|
||||
CGPROGRAM
|
||||
#pragma vertex Vert
|
||||
#pragma fragment Frag
|
||||
|
||||
#include "UnityCG.cginc"
|
||||
#include "Packages/com.waveharmonic.crest/Runtime/Shaders/Library/Globals.hlsl"
|
||||
|
||||
CBUFFER_START(CrestPerWaterInput)
|
||||
float3 _Crest_DisplacementAtInputPosition;
|
||||
half _Crest_Weight;
|
||||
CBUFFER_END
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float3 positionOS : POSITION;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
float3 worldPos : TEXCOORD0;
|
||||
};
|
||||
|
||||
Varyings Vert(Attributes input)
|
||||
{
|
||||
Varyings o;
|
||||
|
||||
o.worldPos = mul(unity_ObjectToWorld, float4(input.positionOS, 1.0)).xyz;
|
||||
// Correct for displacement
|
||||
o.worldPos.xz -= _Crest_DisplacementAtInputPosition.xz;
|
||||
|
||||
o.positionCS = mul(UNITY_MATRIX_VP, float4(o.worldPos, 1.0));
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
half4 Frag(Varyings input) : SV_Target
|
||||
{
|
||||
// Write displacement to get from sea level of water to the y value of this geometry
|
||||
const float heightOffset = input.worldPos.y - g_Crest_WaterCenter.y;
|
||||
return heightOffset * _Crest_Weight;
|
||||
}
|
||||
ENDCG
|
||||
}
|
||||
}
|
||||
CustomEditor "WaveHarmonic.Crest.Editor.CustomShaderGUI"
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 06402bee7075b4b9fafef2b1ddf3b5cc
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user