For devs who's come to this old repo, sadly it's no longer working.
but good news, I've convert the shader to support latest URP. just copy paste code below to Stylized Water.shader
hope it help someone in the future
Shader "Stylized/Water"
{
Properties
{
[Header(Densities)]
_DepthDensity ("Depth", Range(0.0, 1.0)) = 0.5
_DistanceDensity ("Distance", Range(0.0, 1.0)) = 0.1
[Header(Waves)]
[NoScaleOffset] _WaveNormalMap ("Normal Map", 2D) = "bump"{}
_WaveNormalScale ("Scale", float) = 10.0
_WaveNormalSpeed ("Speed", float) = 1.0
[Header(Base Color)]
[HDR] _ShallowColor ("Shallow", Color) = (0.44, 0.95, 0.36, 1.0)
[HDR] _DeepColor ("Deep", Color) = (0.0, 0.05, 0.19, 1.0)
[HDR] _FarColor ("Far", Color) = (0.04, 0.27, 0.75, 1.0)
[Header(Reflections)]
_ReflectionContribution ("Contribution", Range(0.0, 1.0)) = 1.0
[Header(Subsurface Scattering)]
[HDR] _SSSColor ("Color", Color) = (1, 1, 1, 1)
[Header(Foam)]
_FoamContribution ("Contribution", Range(0.0, 1.0)) = 1.0
[NoScaleOffset] _FoamTexture ("Texture", 2D) = "black"{}
_FoamScale ("Scale", float) = 1.0
_FoamSpeed ("Speed", float) = 1.0
_FoamNoiseScale ("Noise Contribution", Range(0.0, 1.0)) = 0.5
[Header(Sun Specular)]
[HDR] _SunSpecularColor ("Color", Color) = (1, 1, 1, 1)
_SunSpecularExponent ("Exponent", float) = 1000
[Header(Sparkle)]
[NoScaleOffset] _SparklesNormalMap ("Normal Map", 2D) = "bump"{}
_SparkleScale ("Scale", float) = 10
_SparkleSpeed ("Speed", float) = 0.75
[HDR] _SparkleColor ("Color", Color) = (1, 1, 1, 1)
_SparkleExponent ("Exponent", float) = 10000
[Header(Edge Foam)]
[HDR] _EdgeFoamColor ("Color", Color) = (1, 1, 1, 1)
_EdgeFoamDepth ("Scale", float) = 10.0
[Header(Shadow Mapping)]
[Toggle(SHADOWS)] _FancyShadows("Enabled", int) = 0
_MaxShadowDistance("Maximum Sample Distance", float) = 50.0
_ShadowColor ("Color", Color) = (0.5, 0.5, 0.5, 1.0)
[Header(Vertex Waves #1)]
_Wave1Direction ("Direction", Range(0, 1)) = 0
_Wave1Amplitude ("Amplitude", float) = 1
_Wave1Wavelength ("Wavelength", float) = 1
_Wave1Speed ("Speed", float) = 1
[Header(Vertex Waves #2)]
_Wave2Direction ("Direction", Range(0, 1)) = 0
_Wave2Amplitude ("Amplitude", float) = 1
_Wave2Wavelength ("Wavelength", float) = 1
_Wave2Speed ("Speed", float) = 1
}
SubShader
{
LOD 100
Tags { "Queue"="Transparent" "RenderType"="Transparent" "RenderPipeline"="UniversalPipeline" }
Pass
{
Tags { "LightMode" = "UniversalForward" }
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
#pragma shader_feature SHADOWS
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
TEXTURE2D(_WaveNormalMap); SAMPLER(sampler_WaveNormalMap);
TEXTURE2D(_FoamTexture); SAMPLER(sampler_FoamTexture);
TEXTURE2D(_SparklesNormalMap); SAMPLER(sampler_SparklesNormalMap);
TEXTURE2D(_CameraOpaqueTexture); SAMPLER(sampler_CameraOpaqueTexture);
TEXTURE2D(_CameraDepthTexture); SAMPLER(sampler_CameraDepthTexture);
CBUFFER_START(UnityPerMaterial)
float _DepthDensity, _DistanceDensity;
float _WaveNormalScale, _WaveNormalSpeed;
float4 _ShallowColor, _DeepColor, _FarColor;
float _ReflectionContribution;
float4 _SSSColor;
float _FoamContribution, _FoamScale, _FoamSpeed, _FoamNoiseScale;
float4 _SunSpecularColor;
float _SunSpecularExponent;
float _SparkleScale, _SparkleSpeed, _SparkleExponent;
float4 _SparkleColor, _EdgeFoamColor;
float _EdgeFoamDepth;
uint _FancyShadows;
float _MaxShadowDistance;
float4 _ShadowColor;
float _Wave1Direction, _Wave1Amplitude, _Wave1Wavelength, _Wave1Speed;
float _Wave2Direction, _Wave2Amplitude, _Wave2Wavelength, _Wave2Speed;
CBUFFER_END
#define WATER_PI 3.1415926536
float2 Panner(float2 uv, float2 dir, float spd)
{
return uv + normalize(dir) * spd * _Time.y;
}
float SimpleWave(float2 pos, float2 dir, float wl, float amp, float spd)
{
return amp * sin(WATER_PI * dot(pos, dir) / wl + spd * _Time.y);
}
float GetWaveHeight(float2 wp)
{
float2 d1 = float2(cos(WATER_PI * _Wave1Direction), sin(WATER_PI * _Wave1Direction));
float2 d2 = float2(cos(WATER_PI * _Wave2Direction), sin(WATER_PI * _Wave2Direction));
return SimpleWave(wp, d1, _Wave1Wavelength, _Wave1Amplitude, _Wave1Speed)
+ SimpleWave(wp, d2, _Wave2Wavelength, _Wave2Amplitude, _Wave2Speed);
}
float3x3 GetWaveTBN(float2 wp, float d)
{
float h = GetWaveHeight(wp);
float hx = GetWaveHeight(wp - float2(d, 0));
float hz = GetWaveHeight(wp - float2(0, d));
float3 t = normalize(float3(0, h - hz, d));
float3 b = normalize(float3(d, h - hx, 0));
return transpose(float3x3(t, b, normalize(cross(b, t))));
}
struct Attributes { float4 positionOS : POSITION; float2 uv : TEXCOORD0; };
struct Varyings
{
float4 positionCS : SV_POSITION;
float2 uv : TEXCOORD0;
float3 positionWS : TEXCOORD1;
float4 screenPos : TEXCOORD2;
half fogFactor : TEXCOORD3;
};
Varyings vert(Attributes i)
{
Varyings o;
float3 w = TransformObjectToWorld(i.positionOS.xyz);
w.y += GetWaveHeight(w.xz);
o.positionCS = TransformWorldToHClip(w);
o.screenPos = ComputeScreenPos(o.positionCS);
o.uv = i.uv;
o.positionWS = w;
o.fogFactor = ComputeFogFactor(o.positionCS.z);
return o;
}
float4 frag(Varyings i) : SV_Target
{
float3 vd = normalize(GetCameraPositionWS() - i.positionWS);
float3x3 t2w = GetWaveTBN(i.positionWS.xz, 0.01);
float2 pn = i.positionWS.xz / _WaveNormalScale;
float spd = _WaveNormalSpeed;
float2 n1 = Panner(pn + float2(0.000, 0.000), float2(0.1, 0.1), spd);
float2 n2 = Panner(pn + float2(0.418, 0.355), float2(-0.1, -0.1), spd);
float2 n3 = Panner(pn + float2(0.865, 0.148), float2(-0.1, 0.1), spd);
float2 n4 = Panner(pn + float2(0.651, 0.752), float2(0.1, -0.1), spd);
float3 nt = normalize(
UnpackNormal(SAMPLE_TEXTURE2D(_WaveNormalMap, sampler_WaveNormalMap, n1)).rgb +
UnpackNormal(SAMPLE_TEXTURE2D(_WaveNormalMap, sampler_WaveNormalMap, n2)).rgb +
UnpackNormal(SAMPLE_TEXTURE2D(_WaveNormalMap, sampler_WaveNormalMap, n3)).rgb +
UnpackNormal(SAMPLE_TEXTURE2D(_WaveNormalMap, sampler_WaveNormalMap, n4)).rgb);
float3 nw = normalize(mul(t2w, nt));
float2 suv = i.screenPos.xy / i.screenPos.w;
float3 sc = SAMPLE_TEXTURE2D(_CameraOpaqueTexture, sampler_CameraOpaqueTexture, suv).rgb;
float sd = SAMPLE_TEXTURE2D(_CameraDepthTexture, sampler_CameraDepthTexture, suv).r;
float od = abs(LinearEyeDepth(sd, _ZBufferParams) - LinearEyeDepth(i.positionCS.z, _ZBufferParams));
float tt = exp(-_DepthDensity * od);
float dm = exp(-_DistanceDensity * length(i.positionWS - GetCameraPositionWS()));
float sm = 1.0;
#ifdef SHADOWS
float dc = length(i.positionWS - GetCameraPositionWS());
if (dc <= _MaxShadowDistance)
{
float4 sh = TransformWorldToShadowCoord(i.positionWS);
sm = GetMainLight(sh).shadowAttenuation;
}
#endif
float3 bc = lerp(_DeepColor.rgb, sc * _ShallowColor.rgb, tt * max(0.5, sm));
bc = lerp(_FarColor.rgb, bc, dm);
float fr = pow(1.0 - saturate(dot(nw, vd)), 5.0);
float3 rc = GlossyEnvironmentReflection(reflect(-vd, nw), 0.0, 1.0) * fr * dm * sm * _ReflectionContribution;
Light ml = GetMainLight();
float3 sss = _SSSColor.rgb * saturate(GetWaveHeight(i.positionWS.xz)) * saturate(dot(vd, ml.direction));
float2 fu = (i.positionWS.xz / _FoamScale) + _FoamNoiseScale * nt.xz;
float2 f1 = Panner(fu + float2(0.000, 0.000), float2(0.1, 0.1), _FoamSpeed);
float2 f2 = Panner(fu + float2(0.418, 0.355), float2(-0.1, -0.1), _FoamSpeed);
float2 f3 = Panner(fu + float2(0.865, 0.148), float2(-0.1, 0.1), _FoamSpeed);
float2 f4 = Panner(fu + float2(0.651, 0.752), float2(0.1, -0.1), _FoamSpeed);
float3 fc = (SAMPLE_TEXTURE2D(_FoamTexture, sampler_FoamTexture, f1).rgb +
SAMPLE_TEXTURE2D(_FoamTexture, sampler_FoamTexture, f2).rgb +
SAMPLE_TEXTURE2D(_FoamTexture, sampler_FoamTexture, f3).rgb +
SAMPLE_TEXTURE2D(_FoamTexture, sampler_FoamTexture, f4).rgb) * 0.25;
fc *= dm * sm * _FoamContribution;
float3 vr = reflect(-vd, nw);
float sum = round(saturate(pow(saturate(dot(vr, ml.direction)), _SunSpecularExponent))) * sm;
float3 suc = lerp(0, _SunSpecularColor.rgb, sum);
float sk = _SparkleScale;
float4 cs1 = float4(1,2,3,4);
float4 cs2 = float4(1,0.5,2.5,2);
float2 su1a = Panner(i.positionWS.xz / sk * cs1.x, float2(0.1, 0.1), _SparkleSpeed);
float2 su1b = Panner(i.positionWS.xz / sk * cs1.y, float2(-0.1, -0.1), _SparkleSpeed);
float2 su1c = Panner(i.positionWS.xz / sk * cs1.z, float2(-0.1, 0.1), _SparkleSpeed);
float2 su1d = Panner(i.positionWS.xz / sk * cs1.w, float2(0.1, -0.1), _SparkleSpeed);
float3 sk1a = UnpackNormal(SAMPLE_TEXTURE2D(_SparklesNormalMap, sampler_SparklesNormalMap, su1a)).rgb;
float3 sk1b = UnpackNormal(SAMPLE_TEXTURE2D(_SparklesNormalMap, sampler_SparklesNormalMap, su1b)).rgb;
float3 sk1c = UnpackNormal(SAMPLE_TEXTURE2D(_SparklesNormalMap, sampler_SparklesNormalMap, su1c)).rgb;
float3 sk1d = UnpackNormal(SAMPLE_TEXTURE2D(_SparklesNormalMap, sampler_SparklesNormalMap, su1d)).rgb;
float3 na1 = float3(sk1a.x, sk1b.y, 1);
float3 nb1 = float3(sk1c.x, sk1d.y, 1);
float3 sp1 = normalize(float3((na1 + nb1).xy, (na1 * nb1).z));
float2 su2a = Panner(i.positionWS.xz / sk * cs2.x, float2(0.1, 0.1), _SparkleSpeed);
float2 su2b = Panner(i.positionWS.xz / sk * cs2.y, float2(-0.1, -0.1), _SparkleSpeed);
float2 su2c = Panner(i.positionWS.xz / sk * cs2.z, float2(-0.1, 0.1), _SparkleSpeed);
float2 su2d = Panner(i.positionWS.xz / sk * cs2.w, float2(0.1, -0.1), _SparkleSpeed);
float3 sk2a = UnpackNormal(SAMPLE_TEXTURE2D(_SparklesNormalMap, sampler_SparklesNormalMap, su2a)).rgb;
float3 sk2b = UnpackNormal(SAMPLE_TEXTURE2D(_SparklesNormalMap, sampler_SparklesNormalMap, su2b)).rgb;
float3 sk2c = UnpackNormal(SAMPLE_TEXTURE2D(_SparklesNormalMap, sampler_SparklesNormalMap, su2c)).rgb;
float3 sk2d = UnpackNormal(SAMPLE_TEXTURE2D(_SparklesNormalMap, sampler_SparklesNormalMap, su2d)).rgb;
float3 na2 = float3(sk2a.x, sk2b.y, 1);
float3 nb2 = float3(sk2c.x, sk2d.y, 1);
float3 sp2 = normalize(float3((na2 + nb2).xy, (na2 * nb2).z));
float skm = ceil(saturate(pow(dot(sp1, sp2) * saturate(3.0 * sqrt(saturate(dot(sp1.x, sp2.x)))), _SparkleExponent))) * sm * dm;
float3 skc = lerp(0, _SparkleColor.rgb, skm);
float efm = round(exp(-od / _EdgeFoamDepth));
float3 efc = lerp(0, _EdgeFoamColor.rgb, efm) * lerp(_ShadowColor.rgb, 1.0, sm);
float3 c = (bc + rc + sss + fc + suc + skc + efc);
c = MixFog(c, i.fogFactor);
return float4(c, 1);
}
ENDHLSL
}
}
}
For devs who's come to this old repo, sadly it's no longer working.
but good news, I've convert the shader to support latest URP. just copy paste code below to
Stylized Water.shaderhope it help someone in the future