portals and dash. Also a bit of terrain building and level design

This commit is contained in:
2022-03-13 00:26:35 +02:00
parent 813cd0c451
commit e82799c36a
6242 changed files with 2160679 additions and 188245 deletions

View File

@@ -0,0 +1,31 @@
#ifndef CAUSTIC_INCLUDED
#define CAUSTIC_INCLUDED
#include "PCommon.cginc"
#include "PDepth.cginc"
void SampleCausticTexture(float sceneDepth, float surfaceDepth, float3 fragWorldPos, float3 worldNormal, out half4 causticColor)
{
fragWorldPos -= worldNormal * _CausticDistortionStrength;
float fragToCamSqrDistance = SqrDistance(fragWorldPos, _WorldSpaceCameraPos.xyz);
float refWorldPosToCamSqrDistance = (sceneDepth * sceneDepth * fragToCamSqrDistance) / (surfaceDepth * surfaceDepth);
float3 fragWorldDir = normalize(fragWorldPos - _WorldSpaceCameraPos.xyz);
float3 refWorldPos = fragWorldDir * sqrt(refWorldPosToCamSqrDistance) + _WorldSpaceCameraPos.xyz;
float2 uv = refWorldPos.xz / (_CausticSize + 0.0000001);
causticColor = tex2D(_CausticTex, uv + _PoseidonTime * 0.0125).r;
causticColor *= _CausticStrength;
float fade = lerp(0.25, 1, NoiseTexFrag(uv * 0.05 - _PoseidonTime * 0.0125));
//#if LIGHT_ABSORPTION
// float waterDepth = sceneDepth - surfaceDepth;
// float depthFade = 1 - saturate(InverseLerpUnclamped(0, _MaxDepth, waterDepth));
// fade *= depthFade;
//#endif
causticColor *= fade;
causticColor = saturate(causticColor);
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 3613dfff1c2e94e40b700e2c5277eb55
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,166 @@
#ifndef PCOMMON_INCLUDED
#define PCOMMON_INCLUDED
sampler2D _NoiseTex;
float NoiseTexFrag(float2 uv)
{
return tex2D(_NoiseTex, uv).r*2 - 1;
}
float NoiseTexVert(float2 uv)
{
return tex2Dlod(_NoiseTex, float4(uv.xy, 0, 0)).r*2 - 1;
}
float2 GradientNoise_dir(float2 p)
{
p = p % 289;
float x = (34 * p.x + 1) * p.x % 289 + p.y;
x = (34 * x + 1) * x % 289;
x = frac(x / 41) * 2 - 1;
return normalize(float2(x - floor(x + 0.5), abs(x) - 0.5));
}
float GradientNoise(float2 p)
{
float2 ip = floor(p);
float2 fp = frac(p);
float d00 = dot(GradientNoise_dir(ip), fp);
float d01 = dot(GradientNoise_dir(ip + float2(0, 1)), fp - float2(0, 1));
float d10 = dot(GradientNoise_dir(ip + float2(1, 0)), fp - float2(1, 0));
float d11 = dot(GradientNoise_dir(ip + float2(1, 1)), fp - float2(1, 1));
fp = fp * fp * fp * (fp * (fp * 6 - 15) + 10);
return lerp(lerp(d00, d01, fp.y), lerp(d10, d11, fp.y), fp.x);
}
float InverseLerpUnclamped(float a, float b, float value)
{
//adding a==b check if needed
return (value - a) / (b - a + 0.00000001);
}
float RandomValue(float seed)
{
return frac(sin(dot(float2(seed, seed+1), float2(12.9898, 78.233)))*43758.5453);
}
float RandomValue(float x, float y)
{
return frac(sin(dot(float2(x, y), float2(12.9898, 78.233)))*43758.5453);
}
float2 VoronoiRandomVector (float2 UV, float offset)
{
float2x2 m = float2x2(15.27, 47.63, 99.41, 89.98);
UV = frac(sin(mul(UV, m)) * 46839.32);
return float2(sin(UV.y*+offset)*0.5+0.5, cos(UV.x*offset)*0.5+0.5);
}
float Voronoi(float2 UV, float AngleOffset, float CellDensity)
{
float2 g = floor(UV * CellDensity);
float2 f = frac(UV * CellDensity);
float t = 8.0;
float3 res = float3(8.0, 0.0, 0.0);
float noiseValue = 0;
for(int y=-1; y<=1; y++)
{
for(int x=-1; x<=1; x++)
{
float2 lattice = float2(x,y);
float2 offset = VoronoiRandomVector(lattice + g, AngleOffset);
float d = distance(lattice + offset, f);
if(d < res.x)
{
res = float3(d, offset.x, offset.y);
noiseValue = res.x;
}
}
}
return noiseValue;
}
float2 PanUV(float2 uv, float2 speed)
{
return uv + _Time.y*speed;
}
half IsOrtho()
{
return unity_OrthoParams.w;
}
half GetNearPlane()
{
return _ProjectionParams.y;
}
half GetFarPlane()
{
return _ProjectionParams.z;
}
float SqrDistance(float3 pt1, float3 pt2)
{
float3 v = pt2 - pt1;
return dot(v,v);
}
half TriangleWave(half In)
{
return 2.0 * abs(2 * (In - floor(0.5 + In))) - 1.0;
}
half RandomValueHalf(half x, half y)
{
return frac(sin(dot(half2(x, y), half2(12.9898, 78.233))) * 43758.5453);
}
half ValueNoiseInterpolate(half a, half b, half t)
{
return (1.0 - t) * a + (t * b);
}
half ValueNoise(half2 uv)
{
half2 i = floor(uv);
half2 f = frac(uv);
f = f * f * (3.0 - 2.0 * f);
uv = abs(frac(uv) - 0.5);
half2 c0 = i + half2(0.0, 0.0);
half2 c1 = i + half2(1.0, 0.0);
half2 c2 = i + half2(0.0, 1.0);
half2 c3 = i + half2(1.0, 1.0);
half r0 = RandomValueHalf(c0.x, c0.y);
half r1 = RandomValueHalf(c1.x, c1.y);
half r2 = RandomValueHalf(c2.x, c2.y);
half r3 = RandomValueHalf(c3.x, c3.y);
half bottomOfGrid = ValueNoiseInterpolate(r0, r1, f.x);
half topOfGrid = ValueNoiseInterpolate(r2, r3, f.x);
half t = ValueNoiseInterpolate(bottomOfGrid, topOfGrid, f.y);
return t;
}
float SampleVertexNoise(float2 uv)
{
return NoiseTexVert(uv);
}
float SampleFragmentNoise(float2 uv)
{
return NoiseTexFrag(uv);
}
void CalculateNormal(float4 v0, float4 v1, float4 v2, inout float3 normal)
{
float4 dir0 = v1 - v0;
float4 dir1 = v2 - v0;
normal = normalize(cross(dir0.xyz, dir1.xyz));
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 3786d410294f5eb40b432f6758c993a7
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,39 @@
#ifndef PCORE_INCLUDED
#define PCORE_INCLUDED
#include "PUniforms.cginc"
#include "PWave.cginc"
struct Input
{
float4 vertexPos;
float3 worldPos;
float4 screenPos;
float3 normal;
float fogCoord;
float crestMask;
};
void vertexFunction(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input, o);
o.vertexPos = v.vertex;
#if MESH_NOISE
ApplyMeshNoise(v.vertex, v.texcoord, v.color);
#endif
#if WAVE
ApplyWaveHQ(v.vertex, v.texcoord, v.color, o.crestMask);
#endif
ApplyRipple(v.vertex, v.texcoord, v.color);
CalculateNormal(v.vertex, v.texcoord, v.color, v.normal);
o.normal = v.normal;
UNITY_TRANSFER_FOG(o, UnityObjectToClipPos(v.vertex));
}
void finalColorFunction(Input i, SurfaceOutputStandardSpecular o, inout fixed4 color)
{
UNITY_APPLY_FOG(i.fogCoord, color);
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 8118462c6b45ae54288814f50e5e749f
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,46 @@
#ifndef PDEPTH_INCLUDED
#define PDEPTH_INCLUDED
#include "PCommon.cginc"
#if !defined(POSEIDON_SRP)
UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
float4 _CameraDepthTexture_TexelSize;
#endif
float GetSceneDepth(float4 screenPos)
{
#if !defined(POSEIDON_SRP)
screenPos = float4(screenPos.xyz, screenPos.w + 0.00000000001);
float depth01 = SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(screenPos));
float perpsDepth = LinearEyeDepth(depth01);
#else
float2 uv = float2(screenPos.xy / screenPos.w);
uv = UnityStereoTransformScreenSpaceTex(uv);
float depth01 = SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv);
float perpsDepth = LinearEyeDepth(depth01, _ZBufferParams);
#endif
#if defined(UNITY_REVERSED_Z)
depth01 = 1 - depth01;
#endif
float orthoDepth = lerp(GetNearPlane(), GetFarPlane(), depth01);
float depth = lerp(perpsDepth, orthoDepth, IsOrtho());
return depth;
}
float GetSurfaceDepth(float4 worldPos)
{
float4 viewPos = mul(UNITY_MATRIX_V, worldPos);
return - viewPos.z;
}
float GetDepthFade(float sceneDepth, float surfaceDepth, float maxDepth)
{
float waterDepth = sceneDepth - surfaceDepth;
float depthFade = 1 - saturate(InverseLerpUnclamped(0, maxDepth, waterDepth));
return depthFade;
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: d3b131db2c4e97d42843e167ecac7bb3
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,86 @@
#ifndef PFOAM_INCLUDED
#define PFOAM_INCLUDED
#include "PUniforms.cginc"
#include "PCommon.cginc"
#include "PDepth.cginc"
void CalculateFoamColor(float sceneDepth, float surfaceDepth, float3 worldPos, float3 normal, float crestMask, out half4 foamColor)
{
float waterDepth = sceneDepth - surfaceDepth;
float depthClip = waterDepth <= _ShorelineFoamStrength * _FoamDistance;
foamColor = depthClip * _FoamColor * (_ShorelineFoamStrength > 0);
#if WAVE && FOAM_CREST
float dt = waterDepth / (_WaveHeight + _CrestMaxDepth);
float crestDepthFade = 1 - dt * dt * dt * dt * dt * dt * dt * dt; //1-x^8
float crestFade = saturate(InverseLerpUnclamped(0, 1 - _CrestFoamStrength, crestMask));
crestFade = crestFade * 1.2 * crestDepthFade;
float crestClip = crestFade >= 0.5;
float crestDepthClip = waterDepth <= (_WaveHeight + _CrestMaxDepth);
float4 crestColor = _FoamColor * crestClip * (_CrestFoamStrength > 0);
foamColor = max(foamColor, crestColor);
#endif
#if defined(POSEIDON_RIVER)
#if FOAM_SLOPE
half normalDotUp = (1 - normal.y * normal.y);
half slopeFade = 1 - frac((worldPos.y + _PoseidonTime * _SlopeFoamFlowSpeed) / _SlopeFoamDistance);
slopeFade *= _SlopeFoamStrength;
slopeFade *= normalDotUp;
half slopeClip = slopeFade >= 0.1;
half4 slopeColor = _FoamColor * slopeClip;
foamColor = max(foamColor, slopeColor);
#endif
#endif
}
void CalculateFoamColorHQ(float sceneDepth, float surfaceDepth, float3 worldPos, float3 normal, float crestMask, out half4 foamColor)
{
float waterDepth = sceneDepth - surfaceDepth;
float depthClip = waterDepth <= _FoamDistance;
half noiseScale = _FoamNoiseScaleHQ;
half noiseSpeed = _FoamNoiseSpeedHQ;
noiseScale *= 0.1;
noiseSpeed *= 0.01;
half noiseBase = SampleFragmentNoise(worldPos.xz * noiseScale - noiseSpeed.xx * _PoseidonTime * 0.2) * 0.5 + 0.5;
half noiseFade = SampleFragmentNoise(worldPos.xz * noiseScale + noiseSpeed.xx * _PoseidonTime) * 0.5 + 0.5;
half noise = noiseBase * noiseFade;
half depthFade = saturate(InverseLerpUnclamped(0, _ShorelineFoamStrength * _FoamDistance * (1 + noise), waterDepth));
half noiseClip = noise >= depthFade;
foamColor = depthClip * noiseClip * _FoamColor * (_ShorelineFoamStrength > 0);
#if WAVE && FOAM_CREST
float dt = waterDepth / (_WaveHeight + _CrestMaxDepth);
float crestDepthFade = 1 - dt * dt * dt * dt * dt * dt * dt * dt; //1-x^8
float crestFade = saturate(InverseLerpUnclamped(0, 1 - _CrestFoamStrength, crestMask));
crestFade = crestFade * (1 + noise) * crestDepthFade;
float crestClip = crestFade >= 0.5;
float crestDepthClip = waterDepth <= (_WaveHeight + _CrestMaxDepth);
float4 crestColor = _FoamColor * crestClip * (_CrestFoamStrength > 0);
foamColor = max(foamColor, crestColor);
#endif
#if defined(POSEIDON_RIVER)
#if FOAM_SLOPE
half normalDotUp = (1 - normal.y * normal.y);
half slopeFade = 1 - frac((worldPos.y + _PoseidonTime * _SlopeFoamFlowSpeed) / _SlopeFoamDistance);
half midPoint = 0.9;
slopeFade = (slopeFade < midPoint) * (slopeFade / midPoint) + (slopeFade >= midPoint) * (lerp(1, 0, InverseLerpUnclamped(midPoint, 1, slopeFade)));
slopeFade *= _SlopeFoamStrength;
slopeFade -= noise;
slopeFade *= normalDotUp;
half slopeClip = slopeFade >= 0.1;
half4 slopeColor = _FoamColor * slopeClip;
foamColor = max(foamColor, slopeColor);
#endif
#endif
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: e5962f627cb08f14598147e1bcf6e691
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,13 @@
#ifndef PFRESNEL_INCLUDED
#define PFRESNEL_INCLUDED
#include "PUniforms.cginc"
void CalculateFresnelFactor(float3 worldPos, float3 worldNormal, out half fresnel)
{
float3 worldViewDir = normalize(_WorldSpaceCameraPos.xyz - worldPos);
half vDotN = dot(worldViewDir, worldNormal);
fresnel = saturate(pow(max(0, 1 - vDotN), _FresnelStrength)) - _FresnelBias;
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 32c01768e62420447a6d0461ac8a8a25
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,15 @@
#ifndef PLIGHTABSORPTION_INCLUDED
#define PLIGHTABSORPTION_INCLUDED
#include "PUniforms.cginc"
#include "PCommon.cginc"
#include "PDepth.cginc"
void CalculateDeepWaterColor(float sceneDepth, float surfaceDepth, out half4 waterColor)
{
float waterDepth = sceneDepth - surfaceDepth;
float depthFade = saturate(InverseLerpUnclamped(0, _MaxDepth, waterDepth));
waterColor = lerp(_Color, _DepthColor, depthFade);
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: bfa298dfdd0823b478218243358f6f6a
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
#ifndef PMESHNOISE_INCLUDED
#define PMESHNOISE_INCLUDED
#include "PUniforms.cginc"
#include "PCommon.cginc"
void ApplyMeshNoise(half amount, half noiseFrequency, inout float4 localPos)
{
float4 worldPos = mul(unity_ObjectToWorld, localPos);
half offsetX = NoiseTexVert(worldPos.xz/noiseFrequency)*amount* _PoseidonSineTime;
half offsetZ = NoiseTexVert(-worldPos.xz/noiseFrequency)*amount* _PoseidonSineTime;
worldPos += float4(offsetX, 0, offsetZ, 0);
localPos = mul(unity_WorldToObject, worldPos);
}
void ApplyMeshNoise(inout float4 v0, inout float4 v1, inout float4 v2)
{
ApplyMeshNoise(_MeshNoise, 100, v0);
ApplyMeshNoise(_MeshNoise, 100, v1);
ApplyMeshNoise(_MeshNoise, 100, v2);
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: ecf649469cdd7c640ba01bc894b9eff1
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
#ifndef PPOSTPROCESSING_COMMON_INCLUDED
#define PPOSTPROCESSING_COMMON_INCLUDED
#if defined (POSEIDON_SRP)
#define PDECLARE_TEXTURE2D(textureName) TEXTURE2D_X(textureName)
#define PSAMPLE_TEXTURE2D(textureName, uv) SAMPLE_TEXTURE2D_X(textureName, sampler_LinearRepeat, uv)
#define PDECLARE_DEPTH_TEXTURE PDECLARE_TEXTURE2D(_CameraDepthTexture)
#define PLINEAR_EYE_DEPTH(uv) LinearEyeDepth(PSAMPLE_TEXTURE2D(_CameraDepthTexture, uv).r, _ZBufferParams)
#else //Builtin RP
#define PDECLARE_TEXTURE2D(textureName) TEXTURE2D_SAMPLER2D(textureName, sampler##textureName)
#define PSAMPLE_TEXTURE2D(textureName, uv) SAMPLE_TEXTURE2D(textureName, sampler##textureName, uv)
#define PDECLARE_DEPTH_TEXTURE PDECLARE_TEXTURE2D(_CameraDepthTexture)
#define PLINEAR_EYE_DEPTH(uv) LinearEyeDepth(PSAMPLE_TEXTURE2D(_CameraDepthTexture, uv).r)
#endif
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: e2bc570e5a6c95540b6125ef1ed52d3a
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,16 @@
#ifndef PREFLECTION_INCLUDED
#define PREFLECTION_INCLUDED
#include "PUniforms.cginc"
void SampleReflectionTexture(float4 screenPos, float3 worldNormal, out half4 color)
{
float4 n = float4(worldNormal.x, worldNormal.z, 1, 1);
half4 offset = half4(n.xy * _ReflectionTex_TexelSize.xy * _ReflectionDistortionStrength, 0, 0);
float2 uv = float2(screenPos.xy / screenPos.w);
//uv = UnityStereoTransformScreenSpaceTex(uv);
uv += offset.xy;
color = tex2D(_ReflectionTex, uv.xy);
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 07e8bd8cb6d801b4bb2ffdc8d611e231
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,25 @@
#ifndef PREFRACTION_INCLUDED
#define PREFRACTION_INCLUDED
void SampleRefractionTexture(float4 screenPos, float3 worldNormal, out half4 color)
{
float2 texel = _RefractionTex_TexelSize.xy;
//#if defined(POSEIDON_SRP)
texel = 1/_ScreenParams.xy;
//#endif
float4 n = float4(worldNormal.x, worldNormal.z, 1, 1);
half4 offset = half4(n.xy*texel*_RefractionDistortionStrength, 0, 0);
float2 uv = float2(screenPos.xy / screenPos.w);
uv = UnityStereoTransformScreenSpaceTex(uv);
uv -= offset.xy;
#if defined(POSEIDON_SRP)
color = float4(SHADERGRAPH_SAMPLE_SCENE_COLOR(uv.xy), 1);
#else
color = tex2D(_RefractionTex, uv.xy);
#endif
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 8e6d6f769fe5d4c44873a50964a1f65a
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,43 @@
#ifndef PRIPPLE_INCLUDED
#define PRIPPLE_INCLUDED
#include "PUniforms.cginc"
#include "PCommon.cginc"
float4 CalculateRippleVertexOffset(float4 localPos, float rippleHeight, float rippleSpeed, float rippleScale, float3 flowDir)
{
float4 worldPos = mul(unity_ObjectToWorld, float4(localPos.xyz, 1));
float2 noisePos = float2(worldPos.x, worldPos.z);
rippleScale *= 0.01;
rippleSpeed *= 0.1;
float noiseBase = SampleVertexNoise((noisePos - flowDir.xz * _PoseidonTime * rippleSpeed) * rippleScale) * 0.5 + 0.5;
float noiseFade = lerp(0.5, 1, SampleVertexNoise((noisePos + flowDir.xz * _PoseidonTime * rippleSpeed * 3) * rippleScale) * 0.5 + 0.5);
float noise = abs(noiseBase - noiseFade);
float4 offset = float4(0, noise * rippleHeight, 0, 0);
return offset;
}
void ApplyRipple(inout float4 v0, inout float4 v1, inout float4 v2)
{
float3 flowDir = float3(1, 1, 1);
v0 += CalculateRippleVertexOffset(v0, _RippleHeight, _RippleSpeed, _RippleNoiseScale, flowDir);
v1 += CalculateRippleVertexOffset(v1, _RippleHeight, _RippleSpeed, _RippleNoiseScale, flowDir);
v2 += CalculateRippleVertexOffset(v2, _RippleHeight, _RippleSpeed, _RippleNoiseScale, flowDir);
}
void ApplyRipple(inout float4 vertex,inout float4 texcoord, inout float4 color, float4 texcoord1)
{
float3 flow0 = float3(texcoord.w, 0, color.w);
float3 flow1 = float3(texcoord1.x, 0, texcoord1.y);
float3 flow2 = float3(texcoord1.z, 0, texcoord1.w);
vertex += CalculateRippleVertexOffset(vertex, _RippleHeight, _RippleSpeed, _RippleNoiseScale, flow0);
texcoord += CalculateRippleVertexOffset(texcoord, _RippleHeight, _RippleSpeed, _RippleNoiseScale, flow1);
color += CalculateRippleVertexOffset(color, _RippleHeight, _RippleSpeed, _RippleNoiseScale, flow2);
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 98588b8c335309a479e819d398ee9526
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,145 @@
#ifndef PUNDERWATER_COMMON_INCLUDED
#define PUNDERWATER_COMMON_INCLUDED
PDECLARE_TEXTURE2D(_MainTex);
PDECLARE_DEPTH_TEXTURE;
float _WaterLevel;
float _MaxDepth;
float _SurfaceColorBoost;
float4 _ShallowFogColor;
float4 _DeepFogColor;
float _ViewDistance;
#if CAUSTIC
PDECLARE_TEXTURE2D(_CausticTex);
float _CausticSize;
float _CausticStrength;
#endif
#if DISTORTION
PDECLARE_TEXTURE2D(_DistortionTex);
float _DistortionStrength;
float _WaterFlowSpeed;
#endif
float3 _CameraViewDir;
float _CameraFov;
float4x4 _CameraToWorldMatrix;
float _Intensity;
PDECLARE_TEXTURE2D(_NoiseTex);
float NoiseTexFrag(float2 uv)
{
return PSAMPLE_TEXTURE2D(_NoiseTex, uv).r * 2 - 1;
}
float InverseLerpUnclamped(float a, float b, float value)
{
return (value - a) / (b - a + 0.00000001);
}
float3 LinearDepthToWorldPosition(float depth, float2 uv)
{
float viewPlaneHeight = 2 * depth * tan(radians(_CameraFov * 0.5));
float viewPlaneWidth = viewPlaneHeight * (_ScreenParams.x / _ScreenParams.y);
float x = viewPlaneWidth * (uv.x - 0.5);
float y = viewPlaneHeight * (uv.y - 0.5);
float3 pos = float3(x, y, -depth);
float3 worldPos = mul(_CameraToWorldMatrix, float4(pos.xyz, 1)).xyz;
return worldPos;
}
float3 GetWaterPlaneIntersection(float3 camPos, float3 dir)
{
float3 planeOrigin = float3(0, _WaterLevel - camPos.y, 0);
float3 planeNormal = float3(0, 1, 0);
float rayLength = dot(planeOrigin, planeNormal) / (dot(dir, planeNormal) + 0.000001);
float3 localIntersect = dir * rayLength;
float3 worldIntersect = localIntersect + camPos;
return worldIntersect;
}
#if CAUSTIC
float4 SampleCaustic(float3 worldPos)
{
float2 uv = worldPos.xz / (_CausticSize + 0.0000001);
float4 causticColor = PSAMPLE_TEXTURE2D(_CausticTex, uv + _Time.y * 0.0125).rrrr * _CausticStrength;
float fade = lerp(0.25, 1, NoiseTexFrag(uv * 0.05 - _Time.y * 0.0125));
causticColor *= fade;
causticColor = saturate(causticColor);
return causticColor;
}
#endif
#if DISTORTION
float2 DistorUV(float2 uv)
{
float depth = _WaterLevel - _WorldSpaceCameraPos.y;
float fDepth = saturate(depth / _MaxDepth);
float flow = _WaterFlowSpeed * lerp(1, 0.25, fDepth);
flow = _WaterFlowSpeed;
float3 n0 = PSAMPLE_TEXTURE2D(_DistortionTex, uv + flow * _Time.y * 0.025).xyz;
float3 n1 = PSAMPLE_TEXTURE2D(_DistortionTex, uv * 2 - flow * _Time.y * 2 * 0.025).xyz;
float3 n = (n0 + n1) * 0.5;
n = n * 2 - 1;
n = normalize(n) * _DistortionStrength * 0.025;
//fade function y=1-x^8, x[-1,1]
float2 uvRemap = uv * 2 - 1; //remap to [-1, 1]
float x = uvRemap.x;
float fadeX = 1 - x * x * x * x * x * x * x * x;
float y = uvRemap.y;
float fadeY = 1 - y * y * y * y * y * y * y * y;
float fade = fadeX * fadeY;
n *= fade;
uv += float2(n.x, n.y);
return uv;
}
#endif
float4 ApplyUnderwater(float2 uv)
{
#if DISTORTION
uv = DistorUV(uv);
#endif
float4 color = PSAMPLE_TEXTURE2D(_MainTex, uv);
float sceneDepth = PLINEAR_EYE_DEPTH(uv);
float3 worldPos = LinearDepthToWorldPosition(sceneDepth, uv);
float aboveWaterSurface = worldPos.y >= _WaterLevel;
float3 direction = normalize(worldPos - _WorldSpaceCameraPos);
float3 waterIntersection = GetWaterPlaneIntersection(_WorldSpaceCameraPos, direction);
worldPos = lerp(worldPos, waterIntersection, aboveWaterSurface);
float depth = _WaterLevel - min(_WorldSpaceCameraPos.y, worldPos.y);
float fDepth = saturate(depth / _MaxDepth);
float isCameraBelowWater = _WorldSpaceCameraPos.y <= _WaterLevel;
#if CAUSTIC
float4 causticColor = SampleCaustic(worldPos);
color += causticColor * (1 - fDepth) * (1 - aboveWaterSurface) * isCameraBelowWater;
#endif
float4 fogColor = lerp(_ShallowFogColor, _DeepFogColor, fDepth);
float d = distance(worldPos, _WorldSpaceCameraPos);
float fDistance = saturate(InverseLerpUnclamped(-_ViewDistance, _ViewDistance, d));
float fColor = fDistance * fogColor.a;
float f = fColor * _Intensity * isCameraBelowWater;
color *= lerp(1, _SurfaceColorBoost, aboveWaterSurface);
float4 result = lerp(color, fogColor, f);
return result;
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 2f68fd794d3c01643be7f26c3f472625
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,65 @@
#ifndef PUNIFORMS_INCLUDED
#define PUNIFORMS_INCLUDED
uniform float _PoseidonTime;
uniform float _PoseidonSineTime;
uniform half _MeshNoise;
uniform half4 _Color;
uniform half4 _Specular;
uniform half _Smoothness;
uniform half4 _DepthColor;
uniform half _MaxDepth;
uniform half4 _FoamColor;
uniform half _FoamDistance;
uniform half _FoamNoiseScaleHQ;
uniform half _FoamNoiseSpeedHQ;
uniform half _ShorelineFoamStrength;
uniform half _CrestFoamStrength;
uniform half _CrestMaxDepth;
#if defined(POSEIDON_RIVER)
uniform half _SlopeFoamStrength;
uniform half _SlopeFoamFlowSpeed;
uniform half _SlopeFoamDistance;
#endif
uniform float _RippleHeight;
uniform float _RippleNoiseScale;
uniform float _RippleSpeed;
uniform float2 _WaveDirection;
uniform half _WaveSpeed;
uniform half _WaveHeight;
uniform half _WaveLength;
uniform half _WaveSteepness;
uniform half _WaveDeform;
#if WAVE_MASK
uniform sampler2D _WaveMask;
uniform float4 _WaveMaskBounds;
#endif
uniform half _FresnelStrength;
uniform half _FresnelBias;
#if defined(POSEIDON_WATER_ADVANCED)
uniform sampler2D _ReflectionTex;
uniform half4 _ReflectionTex_TexelSize;
uniform half _ReflectionDistortionStrength;
#endif
#if defined(POSEIDON_WATER_ADVANCED) || defined(POSEIDON_RIVER)
uniform sampler2D _RefractionTex;
uniform half4 _RefractionTex_TexelSize;
uniform half _RefractionDistortionStrength;
uniform sampler2D _CausticTex;
uniform half _CausticSize;
uniform half _CausticStrength;
uniform half _CausticDistortionStrength;
#endif
uniform half _AuraLightingFactor;
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 607378e9727cb7945a7586517c266730
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,88 @@
#ifndef PWAVE_INCLUDED
#define PWAVE_INCLUDED
#include "PUniforms.cginc"
#include "PCommon.cginc"
float2 SampleSpline(float t, float2 anchor0, float2 anchor1, float2 tangent0, float2 tangent1)
{
float oneMinusT = 1 - t;
float2 p = oneMinusT * oneMinusT * oneMinusT * anchor0 +
3 * oneMinusT * oneMinusT * t * tangent0 +
3 * oneMinusT * t * t * tangent1 +
t * t * t * anchor1;
return p;
}
half2 SampleWaveCurve(float t, half waveSteepness)
{
half2 left = half2(0, 0);
half2 right = half2(1, 0);
half2 middle = half2(lerp(0.5, 0.95, waveSteepness), 1);
half2 anchor0 = left * (t < middle.x) + middle * (t >= middle.x);
half2 anchor1 = middle * (t < middle.x) + right * (t >= middle.x);
half tangentLength = 0.5;
half2 tangent0 = float2(tangentLength, 0) * (t < middle.x) + float2(middle.x + tangentLength, middle.y) * (t >= middle.x);
half2 tangent1 = float2(middle.x - tangentLength, middle.y) * (t < middle.x) + float2(1 - tangentLength, 0) * (t >= middle.x);
half splineT = InverseLerpUnclamped(anchor0.x, anchor1.x, t);
half2 p = SampleSpline(splineT, anchor0, anchor1, tangent0, tangent1);
return p;
}
float4 CalculateWaveOffsetHQ(float4 vertex, float2 waveDirection, inout float crestMask)
{
float4 worldPos = mul(unity_ObjectToWorld, float4(vertex.xyz, 1));
#if WAVE_MASK
float maskU = InverseLerpUnclamped(_WaveMaskBounds.x, _WaveMaskBounds.z, worldPos.x);
float maskV = InverseLerpUnclamped(_WaveMaskBounds.y, _WaveMaskBounds.w, worldPos.z);
float4 mask = tex2Dlod(_WaveMask, float4(maskU, maskV, 0, 0));
float inbounds = (maskU >= 0) * (maskU <= 1) * (maskV >= 0) * (maskV <= 1);
//waveDirection = lerp(waveDirection, float2(mask.r * 2 - 1, mask.g * 2 - 1), inbounds);
#endif
half2 noisePos = worldPos.xz - 2 * _WaveSpeed * waveDirection * _PoseidonTime;
half noise = SampleVertexNoise(noisePos * 0.001) * _WaveDeform;
half dotValue = dot(worldPos.xz, waveDirection);
half t = frac((dotValue - _WaveSpeed * _PoseidonTime) / _WaveLength - noise * _WaveDeform * 0.25);
half2 p = SampleWaveCurve(t, _WaveSteepness);
p.y -= lerp(0.5, 1, noise * 0.5 + 0.5);
crestMask = saturate(p.y / _WaveHeight);
float4 offset = float4(0, _WaveHeight * p.y, 0, 0);
#if WAVE_MASK
float heightMask = lerp(1, mask.a, inbounds);
offset.y *= heightMask;
float crestMaskMask = lerp(1, mask.b, inbounds);
crestMask *= crestMaskMask;
#endif
return offset;
}
void ApplyWaveHQ(inout float4 v0, inout float4 v1, inout float4 v2, inout float crestMask)
{
float4 offset0 = CalculateWaveOffsetHQ(v0, _WaveDirection, crestMask);
v0 += offset0;
float tmp;
v1 += CalculateWaveOffsetHQ(v1, _WaveDirection, tmp);
v2 += CalculateWaveOffsetHQ(v2, _WaveDirection, tmp);
}
void ApplyWaveHQ(inout float4 vertex, inout float4 texcoord, inout float4 color, float4 texcoord1, inout float crestMask)
{
float2 flow0 = mul(unity_ObjectToWorld, float4(texcoord.w, 0, color.w, 0)).xz;
float2 flow1 = mul(unity_ObjectToWorld, float4(texcoord1.x, 0, texcoord1.y, 0)).xz;
float2 flow2 = mul(unity_ObjectToWorld, float4(texcoord1.z, 0, texcoord1.w, 0)).xz;
float4 offset0 = CalculateWaveOffsetHQ(vertex, flow0, crestMask);
vertex += offset0;
float tmp;
texcoord += CalculateWaveOffsetHQ(texcoord, flow1, tmp);
color += CalculateWaveOffsetHQ(color, flow2, tmp);
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: fa461cb0cc467c14fac622a5ed1e0a26
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,35 @@
#ifndef PWETLENS_COMMON_INCLUDED
#define PWETLENS_COMMON_INCLUDED
PDECLARE_TEXTURE2D(_MainTex);
PDECLARE_TEXTURE2D(_WetLensTex);
float _Strength;
float2 DistorUV(float2 uv)
{
float3 n = PSAMPLE_TEXTURE2D(_WetLensTex, uv).xyz;
n = lerp(float3(0.5, 0.5, 0), n, _Strength);
n = n * 2 - 1;
n = normalize(n) * 0.1;
//fade function y=1-x^8, x[-1,1]
float2 uvRemap = uv * 2 - 1; //remap to [-1, 1]
float x = uvRemap.x;
float fadeX = 1 - x * x * x * x * x * x * x * x;
float y = uvRemap.y;
float fadeY = 1 - y * y * y * y * y * y * y * y;
float fade = fadeX * fadeY;
n *= fade;
uv += float2(-n.x, -n.y);
return uv;
}
float4 ApplyWetLens(float2 uv)
{
uv = DistorUV(uv);
float4 color = PSAMPLE_TEXTURE2D(_MainTex, uv);
return color;
}
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 843f79a9c7d6673439f500f134d25f54
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,5 @@
#ifndef FILE_INCLUDED
#define FILE_INCLUDED
#endif

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 68dc23bc5921fde4f9522770d2549659
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant: