Replace painted-blue water with a real URP water material

- Add TravelersQuest/BowlValleyWater shader: depth-based colour and
  transparency, refraction, Fresnel sky reflection, sun glint,
  distance-faded wave normals and shoreline foam
- Ocean plane uses Ocean.mat; rivers and lakes get per-tile surface
  meshes ("Rivers & Lakes") with Freshwater.mat
- Lakes sit at flat levels from their shorelines with beds carved below;
  rivers sit at least 5 m above their beds out to the sea
- Underwater terrain is painted riverbed mud or sand/silt; the blue
  Water terrain layer is removed
- Store generated water meshes in Git LFS alongside the terrain tiles

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Netherwarlord
2026-11-24 15:03:09 -05:00
co-authored by Claude Opus 5.5
parent 5ea8cafbe8
commit 75c196cc00
197 changed files with 9726 additions and 4130 deletions
+8570 -3988
View File
File diff suppressed because it is too large Load Diff
@@ -62,6 +62,8 @@ namespace TravelersQuest.World.Editor
public float[] extBase, extDist; public int extW, extH; public float extX0, extZ0; // extDist: km outside the outline
public bool[] insideMask; public float[] watMask; // crop-resolution masks kept for river-mouth detection
public float[] edgeDepth; // smoothed distance inside the outline (crop pixels)
public float[] waterLevel; // river/lake surface level (true m) around core water, crop res
public float[] lakeLevel, lakeW; // per-lake flat level (spread outward) and lake membership
}
static Fields fields;
@@ -200,6 +202,17 @@ namespace TravelersQuest.World.Editor
float bed = floorH - 18 - 45 * Mathf.Clamp01(waterWide * 1.6f - 0.25f);
float carve = Mathf.SmoothStep(0, 1, Mathf.InverseLerp(0.12f, 0.55f, water));
h = Mathf.Lerp((float)h, Mathf.Min((float)h, bed), carve);
// lakes: bed carved down from the lake's own (flat) water level, so the whole lake holds water
if (fields.lakeW != null)
{
float lw = SampleField(fields.lakeW, (float)wx, (float)wz);
if (lw > 0.02f)
{
float ll = SampleField(fields.lakeLevel, (float)wx, (float)wz);
float lakeBed = ll - 6 - 30 * Mathf.Clamp01(waterWide * 1.8f - 0.6f);
h = Mathf.Lerp((float)h, Mathf.Min((float)h, lakeBed), Mathf.SmoothStep(0, 1, Mathf.InverseLerp(0.12f, 0.55f, lw)));
}
}
return (float)h;
}
@@ -256,6 +269,7 @@ namespace TravelersQuest.World.Editor
BuildCoast(fields);
TraceRivers();
PlaceIslands();
BuildWaterLevels();
}
else { rivers = new List<RiverPath>(); islands = new List<Island>(); riverBuckets = null; }
SolveSpotOffsets();
@@ -507,6 +521,183 @@ namespace TravelersQuest.World.Editor
return h;
}
// ---------- river & lake surfaces ----------
// Water level from the real banks: for every lake, the low part (10th percentile) of the ground just outside its
// shore; for rivers, the lowest nearby bank, smoothed along the channel. Both sit 2 m under that bank height.
static void BuildWaterLevels()
{
var f = fields; int N = CW * CH;
var wetM = new bool[N]; for (int i = 0; i < N; i++) wetM[i] = f.watMask[i] > 0;
var near = Dilate(wetM, 4);
var bank = new float[N];
Parallel.For(0, CH, y =>
{
for (int x = 0; x < CW; x++)
{
int i = y * CW + x;
if (near[i] && !wetM[i]) { var w = CropToWorld(x, y); bank[i] = RawHeight(w.x, w.y); }
}
});
var level = new float[N]; var has = new bool[N];
// lakes
var lake = new bool[N];
for (int i = 0; i < N; i++) lake[i] = wetM[i] && f.waterWide[i] > 0.55f; // narrow channels between lakes stay rivers
var lab = new int[N]; var q = new Queue<int>(); var members = new List<int>(); int nl = 0;
for (int st = 0; st < N; st++)
{
if (!lake[st] || lab[st] != 0) continue;
nl++; lab[st] = nl; q.Enqueue(st); members.Clear();
var shore = new List<float>(); var seen = new HashSet<int>();
while (q.Count > 0)
{
int i = q.Dequeue(); members.Add(i); int x = i % CW, y = i / CW;
for (int dy = -3; dy <= 3; dy++) for (int dx = -3; dx <= 3; dx++)
{
int xx = x + dx, yy = y + dy; if (xx < 0 || yy < 0 || xx >= CW || yy >= CH) continue;
int j = yy * CW + xx;
if (!wetM[j] && near[j] && seen.Add(j)) shore.Add(bank[j]);
}
void T(int j) { if (lake[j] && lab[j] == 0) { lab[j] = nl; q.Enqueue(j); } }
if (x > 0) T(i - 1); if (x < CW - 1) T(i + 1); if (y > 0) T(i - CW); if (y < CH - 1) T(i + CW);
}
if (shore.Count == 0) continue;
shore.Sort();
float lv = shore[(int)(shore.Count * 0.1f)] - 2;
// never below most of the lake's own bed (the surface mesh is limited to the lake's footprint anyway)
lv = Mathf.Min(lv, shore[shore.Count / 2] - 1); // never above the typical shoreline
foreach (var i in members) { level[i] = lv; has[i] = true; }
}
// rivers
var rv = new float[N]; var rw = new float[N]; var rmin = new float[N];
for (int y = 0; y < CH; y++) for (int x = 0; x < CW; x++)
{
int i = y * CW + x; if (!wetM[i] || lake[i]) continue;
float mn = float.MaxValue;
for (int dy = -4; dy <= 4; dy++) for (int dx = -4; dx <= 4; dx++)
{
int xx = x + dx, yy = y + dy; if (xx < 0 || yy < 0 || xx >= CW || yy >= CH) continue;
int j = yy * CW + xx; if (!wetM[j] && near[j]) mn = Mathf.Min(mn, bank[j]);
}
if (mn == float.MaxValue) continue;
var wp = CropToWorld(x, y); float bedH = RawHeight(wp.x, wp.y);
float lv = Mathf.Max(mn - 2, bedH + 5); // perched channels still hold water
rmin[i] = Mathf.Max(lv, bedH + 3); rv[i] = lv; rw[i] = 1;
}
var rvB = Blur(rv, CW, CH, 2f); var rwB = Blur(rw, CW, CH, 2f);
for (int i = 0; i < N; i++) if (rw[i] > 0 && rwB[i] > 1e-3f) { level[i] = Mathf.Max(rvB[i] / rwB[i], rmin[i]); has[i] = true; }
// spread levels a few pixels outward so the surface mesh can tuck under the banks
for (int pass = 0; pass < 8; pass++)
{
var nlv = (float[])level.Clone(); var nh = (bool[])has.Clone();
for (int y = 1; y < CH - 1; y++) for (int x = 1; x < CW - 1; x++)
{
int i = y * CW + x; if (has[i]) continue;
float acc = 0; int c = 0;
for (int dy = -1; dy <= 1; dy++) for (int dx = -1; dx <= 1; dx++) { int j = i + dy * CW + dx; if (has[j]) { acc += level[j]; c++; } }
if (c > 0) { nlv[i] = acc / c; nh[i] = true; }
}
level = nlv; has = nh;
}
for (int i = 0; i < N; i++) if (!has[i]) level[i] = -10000;
f.waterLevel = level;
// lake level field (spread a few px past the shore) + soft membership, used to carve the lakebeds
var ll = new float[N]; var lh = new bool[N]; var lm = new float[N];
for (int i = 0; i < N; i++) if (lake[i]) { ll[i] = level[i]; lh[i] = true; lm[i] = 1; }
for (int pass = 0; pass < 6; pass++)
{
var nll = (float[])ll.Clone(); var nlh = (bool[])lh.Clone();
for (int y = 1; y < CH - 1; y++) for (int x = 1; x < CW - 1; x++)
{
int i = y * CW + x; if (lh[i]) continue;
float acc = 0; int c = 0;
for (int dy = -1; dy <= 1; dy++) for (int dx = -1; dx <= 1; dx++) { int j = i + dy * CW + dx; if (lh[j]) { acc += ll[j]; c++; } }
if (c > 0) { nll[i] = acc / c; nlh[i] = true; }
}
ll = nll; lh = nlh;
}
f.lakeLevel = ll; f.lakeW = Blur(lm, CW, CH, 1.0f);
}
// extended river channels: surface 3 m above the bed; c = how strongly this point is in the channel
static void ExtWater(double wx, double wz, out float level, out float c)
{
level = -10000; c = 0;
if (!QueryRiver(wx, wz, out float r, out float sAt, out float bed, out var rp)) return;
float hw = rp.HalfWidth(sAt, bed);
float fadeIn = Mathf.SmoothStep(0, 1, sAt / 1500f);
c = Mathf.SmoothStep(0, 1, Mathf.InverseLerp(hw * 1.15f, hw * 0.6f, r)) * fadeIn;
level = bed + 3;
}
static Material WaterMaterial(string path, Color shallow, Color deep, float absorption, float waveLength, float foamDepth, float fadeDist)
{
var mat = AssetDatabase.LoadAssetAtPath<Material>(path);
var shader = Shader.Find("TravelersQuest/BowlValleyWater");
if (!mat) { mat = new Material(shader); AssetDatabase.CreateAsset(mat, path); }
mat.shader = shader;
mat.SetColor("_ShallowColor", shallow); mat.SetColor("_DeepColor", deep);
mat.SetFloat("_Absorption", absorption); mat.SetFloat("_WaveLength", waveLength);
mat.SetFloat("_FoamDepth", foamDepth); mat.SetFloat("_NormalFadeDistance", fadeDist);
EditorUtility.SetDirty(mat);
return mat;
}
static Material FreshwaterMaterial() => WaterMaterial(OutputFolder + "/Freshwater.mat",
new Color(0.16f, 0.44f, 0.40f), new Color(0.03f, 0.15f, 0.17f), 0.035f, 9f, 4f, 4000f);
static Material OceanMaterial() => WaterMaterial(OutputFolder + "/Ocean.mat",
new Color(0.10f, 0.50f, 0.56f), new Color(0.02f, 0.09f, 0.22f), 0.012f, 30f, 8f, 9000f);
// Surface mesh over the rivers and lakes of one tile (every 2nd heightmap sample, ~122 m).
static Mesh BuildWaterMesh(float[] hm, int res, double ox, double oz, float tileW, float tileD)
{
const int step = 2; int g = (res - 1) / step + 1;
var lvl = new float[g * g]; var wet = new bool[g * g]; var terr = new float[g * g];
Parallel.For(0, g, j =>
{
for (int i = 0; i < g; i++)
{
int k = j * g + i;
double wx = ox + (double)i / (g - 1) * tileW, wz = oz + (double)j / (g - 1) * tileD;
terr[k] = hm[(j * step) * res + i * step];
float coreW = SampleField(fields.water, (float)wx, (float)wz);
float coreL = SampleField(fields.waterLevel, (float)wx, (float)wz);
ExtWater(wx, wz, out float extL, out float extC);
lvl[k] = extC > 0.05f ? (coreL > -5000 && coreW > 0.05f ? Mathf.Min(extL, coreL) : extL) : coreL;
wet[k] = (coreW > 0.2f && coreL > -5000) || extC > 0.3f;
}
});
var verts = new List<Vector3>(); var tris = new List<int>(); var map = new Dictionary<int, int>();
int V(int i, int j)
{
int k = j * g + i;
if (!map.TryGetValue(k, out int idx))
{
idx = verts.Count; map[k] = idx;
verts.Add(new Vector3((float)i / (g - 1) * tileW, lvl[k] * VerticalExaggeration, (float)j / (g - 1) * tileD));
}
return idx;
}
for (int j = 0; j < g - 1; j++)
for (int i = 0; i < g - 1; i++)
{
int a = j * g + i, b = a + 1, c = a + g, d = c + 1;
if (!(wet[a] || wet[b] || wet[c] || wet[d])) continue;
float lmax = Mathf.Max(Mathf.Max(lvl[a], lvl[b]), Mathf.Max(lvl[c], lvl[d]));
float lmin = Mathf.Min(Mathf.Min(lvl[a], lvl[b]), Mathf.Min(lvl[c], lvl[d]));
float tmin = Mathf.Min(Mathf.Min(terr[a], terr[b]), Mathf.Min(terr[c], terr[d]));
if (lmin < -5000 || lmax < 0.5f || lmax < tmin + 0.3f) continue; // undefined, at/below sea level, or no water showing
int va = V(i, j), vb = V(i + 1, j), vc = V(i, j + 1), vd = V(i + 1, j + 1);
tris.Add(va); tris.Add(vc); tris.Add(vb);
tris.Add(vb); tris.Add(vc); tris.Add(vd);
}
if (tris.Count == 0) return null;
var mesh = new Mesh { indexFormat = UnityEngine.Rendering.IndexFormat.UInt32 };
mesh.SetVertices(verts); mesh.SetTriangles(tris, 0);
var normals = new Vector3[verts.Count]; for (int n = 0; n < normals.Length; n++) normals[n] = Vector3.up;
mesh.normals = normals; mesh.RecalculateBounds();
return mesh;
}
// ---------- bay islands ----------
public struct Island { public float cx, cz, rx, rz, rot, top; public bool settlement; public int seed; }
static List<Island> islands = new List<Island>();
@@ -758,6 +949,9 @@ namespace TravelersQuest.World.Editor
new GameObject(RootName);
foreach (var guid in AssetDatabase.FindAssets("t:TerrainData", new[] { OutputFolder }))
AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(guid)); // regenerated below; layout may have changed
if (AssetDatabase.IsValidFolder(OutputFolder + "/Water"))
foreach (var guid in AssetDatabase.FindAssets("t:Mesh", new[] { OutputFolder + "/Water" }))
AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(guid));
EnsureFolder(OutputFolder); EnsureFolder(OutputFolder + "/Layers");
CreateLayers();
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(scene);
@@ -778,7 +972,7 @@ namespace TravelersQuest.World.Editor
("Lowland", new Color32(160, 199, 86, 255), 0.05f), ("Plains", new Color32(128, 174, 66, 255), 0.05f),
("Foothills", new Color32(84, 128, 48, 255), 0.05f), ("Mountains", new Color32(168, 152, 120, 255), 0.08f),
("HighMountains", new Color32(176, 174, 182, 255), 0.1f), ("AlpineSnow", new Color32(244, 246, 250, 255), 0.35f),
("Water", new Color32(52, 116, 226, 255), 0.85f), ("Rock", new Color32(112, 100, 88, 255), 0.1f),
("Riverbed", new Color32(86, 78, 60, 255), 0.2f), ("Rock", new Color32(112, 100, 88, 255), 0.1f),
};
static TerrainLayer[] CreateLayers()
@@ -899,7 +1093,13 @@ namespace TravelersQuest.World.Editor
{
ApplyRiver(h, wx, wz, out float riverWet);
wet = Mathf.Max(wet, riverWet);
if (h < 0) wet = 1; // seafloor
if (h < 0)
{
// seafloor under the ocean surface: sand in the shallows, dark silt deeper
float sand = Mathf.InverseLerp(-45, -4, h);
for (int k = 0; k < L; k++) wts[k] = 0;
wts[3] = sand; wts[6] = 1 - sand; wet = 0;
}
}
for (int k = 0; k < L; k++) wts[k] *= 1 - wet;
wts[6] += wet;
@@ -937,6 +1137,27 @@ namespace TravelersQuest.World.Editor
terrain.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.TwoSided;
if (!anySolid) go.SetActive(false); // tile lies wholly outside the outline
sb.Append(go.name).Append(anySolid ? " " : "(empty) ");
if (!CutOutsideOutline)
{
var wm = BuildWaterMesh(hm, res, ox, oz, tileW, tileD);
if (wm != null)
{
EnsureFolder(OutputFolder + "/Water");
string mp = $"{OutputFolder}/Water/Water_{tx:D2}_{tz:D2}.asset";
AssetDatabase.CreateAsset(wm, mp);
var waterRoot = root.transform.Find("Rivers & Lakes") ?? new GameObject("Rivers & Lakes").transform;
waterRoot.SetParent(root.transform, false);
var w = new GameObject($"Water {tx:D2}-{tz:D2}", typeof(MeshFilter), typeof(MeshRenderer));
w.transform.SetParent(waterRoot, false);
w.transform.position = new Vector3((float)ox, 0, (float)oz);
w.GetComponent<MeshFilter>().sharedMesh = wm;
var mr = w.GetComponent<MeshRenderer>();
mr.sharedMaterial = FreshwaterMaterial();
mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
mr.receiveShadows = false;
}
}
}
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(root.scene);
AssetDatabase.SaveAssets();
@@ -982,6 +1203,7 @@ namespace TravelersQuest.World.Editor
float aspect = Mathf.Max(cam.aspect, 1f);
float y = Mathf.Max(WorldSizeZ * 0.52f / half, WorldSizeX * 0.52f / (half * aspect));
cam.transform.position = new Vector3(0, y, 0);
cam.nearClipPlane = y * 0.05f; // depth precision for the water shader at this distance
}
}
var sv = SceneView.lastActiveSceneView;
@@ -1000,17 +1222,7 @@ namespace TravelersQuest.World.Editor
static void CreateOceanPlane(Transform parent)
{
string matPath = OutputFolder + "/Ocean.mat";
var mat = AssetDatabase.LoadAssetAtPath<Material>(matPath);
if (!mat)
{
mat = new Material(Shader.Find("Universal Render Pipeline/Lit"));
AssetDatabase.CreateAsset(mat, matPath);
}
mat.SetColor("_BaseColor", new Color32(38, 92, 168, 255));
mat.SetFloat("_Smoothness", 0.88f);
mat.SetFloat("_Metallic", 0f);
EditorUtility.SetDirty(mat);
var mat = OceanMaterial();
var sea = GameObject.CreatePrimitive(PrimitiveType.Plane);
sea.name = "Ocean (sea level)";
UnityEngine.Object.DestroyImmediate(sea.GetComponent<Collider>());
@@ -1020,6 +1232,7 @@ namespace TravelersQuest.World.Editor
var r = sea.GetComponent<MeshRenderer>();
r.sharedMaterial = mat;
r.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
r.receiveShadows = false;
}
// 16-bit little-endian RAW at half resolution + PNG preview, written outside Assets/.
@@ -1058,6 +1271,15 @@ namespace TravelersQuest.World.Editor
}
// ---------- debug ----------
// debug: water numbers at a reference-map pixel (crop coordinates)
public static string ProbeWater(int px, int py)
{
if (fields == null) Prepare();
var w = CropToWorld(px, py); int i = py * CW + px;
return $"px({px},{py}) world({w.x / 1000:F1},{w.y / 1000:F1})km wat={fields.watMask[i]} waterWide={fields.waterWide[i]:F2} " +
$"raw={RawHeight(w.x, w.y):F1} h={Height(w.x, w.y):F1} level={fields.waterLevel[i]:F1} field={SampleField(fields.water, w.x, w.y):F2}";
}
public static string RiverSummary()
{
Prepare();
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e916f31c882a8f2af864b5c0bd6887c2
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,150 @@
// URP water for the Bowl Valley world: depth-tinted body with refraction, Fresnel sky reflection,
// sun glint, distance-faded wind-wave normals and shoreline foam. Requires the URP depth + opaque textures.
Shader "TravelersQuest/BowlValleyWater"
{
Properties
{
_ShallowColor ("Shallow Color", Color) = (0.12, 0.46, 0.50, 1)
_DeepColor ("Deep Color", Color) = (0.02, 0.10, 0.22, 1)
_Absorption ("Absorption (per world unit of depth)", Float) = 0.02
_RefractionTint ("Refraction Visibility", Range(0, 1)) = 0.8
_Refraction ("Refraction Distortion", Float) = 0.025
_FoamColor ("Foam Color", Color) = (0.92, 0.96, 1, 1)
_FoamDepth ("Shore Foam Depth (world units)", Float) = 5
_EdgeSoftness ("Shore Edge Softness (world units)", Float) = 1.5
_WaveLength ("Longest Wave Length (m)", Float) = 24
_WaveSpeed ("Wave Speed", Float) = 1
_WaveDirection ("Wind Direction (degrees)", Float) = 35
_NormalStrength ("Wave Normal Strength", Range(0, 2)) = 0.7
_NormalFadeDistance ("Wave Fade Distance", Float) = 6000
_Smoothness ("Smoothness", Range(0, 1)) = 0.94
_SunGlint ("Sun Glint", Float) = 3
}
SubShader
{
Tags { "RenderPipeline" = "UniversalPipeline" "RenderType" = "Transparent" "Queue" = "Transparent-50" "IgnoreProjector" = "True" }
Pass
{
Name "Water"
Tags { "LightMode" = "UniversalForward" }
Blend SrcAlpha OneMinusSrcAlpha
ZWrite Off
Cull Back
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#pragma target 3.5
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl"
CBUFFER_START(UnityPerMaterial)
half4 _ShallowColor, _DeepColor, _FoamColor;
float _Absorption, _RefractionTint, _Refraction, _FoamDepth, _EdgeSoftness;
float _WaveLength, _WaveSpeed, _WaveDirection, _NormalStrength, _NormalFadeDistance;
half _Smoothness, _SunGlint;
CBUFFER_END
struct Attributes { float4 positionOS : POSITION; };
struct Varyings
{
float4 positionCS : SV_POSITION;
float3 positionWS : TEXCOORD0;
float4 screenPos : TEXCOORD1;
half fog : TEXCOORD2;
};
Varyings vert(Attributes v)
{
Varyings o;
o.positionWS = TransformObjectToWorld(v.positionOS.xyz);
o.positionCS = TransformWorldToHClip(o.positionWS);
o.screenPos = ComputeScreenPos(o.positionCS);
o.fog = ComputeFogFactor(o.positionCS.z);
return o;
}
// Sum of directional waves spread around the wind direction -> surface slope (dh/dx, dh/dz).
// Each wave fades out once it is smaller than a few pixels (footprint), so distant water doesn't alias.
float2 WaveSlope(float2 p, float t, float footprint)
{
// break up the regular interference pattern with a slow warp of the sample position
p += 4.0 * float2(sin(p.y * 0.0213 + 1.3) + sin(p.x * 0.0071), sin(p.x * 0.0187 - 0.7) + sin(p.y * 0.0063));
float2 slope = 0;
float wl = _WaveLength, steep = 0.2;
float baseAngle = radians(_WaveDirection);
[unroll] for (int i = 0; i < 10; i++)
{
float a = baseAngle + sin(i * 2.399963) * 1.1; // golden-angle spread around the wind
float2 d = float2(cos(a), sin(a));
float k = 6.2831853 / wl;
float phase = dot(d, p) * k + t * sqrt(9.81 * k) * _WaveSpeed + i * 2.3;
float aa = saturate(wl / (footprint * 6.0) - 0.5);
slope += d * steep * aa * cos(phase);
wl *= 0.72; steep *= 0.86;
}
return slope;
}
half4 frag(Varyings i) : SV_Target
{
float3 camPos = GetCameraPositionWS();
float3 toCam = camPos - i.positionWS;
float dist = length(toCam);
float3 V = toCam / dist;
float fade = saturate(1 - dist / _NormalFadeDistance);
float footprint = max(length(ddx(i.positionWS.xz)), length(ddy(i.positionWS.xz))) + 1e-4;
float2 s = WaveSlope(i.positionWS.xz, _Time.y, footprint) * _NormalStrength * fade;
float3 N = normalize(float3(-s.x, 1, -s.y));
// water thickness along the view ray from the depth buffer
float2 uv = i.screenPos.xy / i.screenPos.w;
float surfaceEye = i.screenPos.w;
float sceneEye = LinearEyeDepth(SampleSceneDepth(uv), _ZBufferParams);
float thickness = max(0, sceneEye - surfaceEye);
// refracted view of the bed (ignore samples that land on geometry in front of the water)
float2 ruv = uv + N.xz * _Refraction * saturate(thickness * 0.1);
float rEye = LinearEyeDepth(SampleSceneDepth(ruv), _ZBufferParams);
if (rEye < surfaceEye) { ruv = uv; rEye = sceneEye; }
float rThick = max(0, rEye - surfaceEye);
half3 behind = SampleSceneColor(ruv);
Light sun = GetMainLight();
half3 ambient = SampleSH(half3(0, 1, 0));
half3 lit = ambient + sun.color * saturate(sun.direction.y) * 0.85;
float trans = exp(-rThick * _Absorption);
half3 waterColor = lerp(_DeepColor.rgb, _ShallowColor.rgb, trans) * lit;
half3 body = lerp(waterColor, behind * lerp(1, _ShallowColor.rgb * 1.4, 0.35), trans * _RefractionTint);
// reflection + sun glint
float NdotV = saturate(dot(N, V));
float fresnel = 0.02 + 0.98 * pow(1 - NdotV, 5);
half3 R = reflect(-V, N);
half3 refl = GlossyEnvironmentReflection(R, 1 - _Smoothness, 1);
half3 H = normalize(sun.direction + V);
half spec = pow(saturate(dot(N, H)), 900) * _SunGlint;
half3 color = lerp(body, refl, fresnel) + spec * sun.color;
// shoreline foam (broken up by the wave pattern)
float foamBand = saturate(1 - thickness / _FoamDepth);
float foamNoise = saturate(0.5 + 2.5 * (s.x + s.y) + 0.5 * sin(dot(i.positionWS.xz, float2(0.11, 0.07)) + _Time.y));
color = lerp(color, _FoamColor.rgb * lit, foamBand * foamBand * foamNoise * 0.85);
half alpha = saturate(thickness / max(_EdgeSoftness, 1e-3));
color = MixFog(color, i.fog);
return half4(color, alpha);
}
ENDHLSL
}
}
FallBack Off
}
@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: e6a40dc93388798f8bd7c8af7f9c1285
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,45 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!21 &2100000
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Freshwater
m_Shader: {fileID: 4800000, guid: e6a40dc93388798f8bd7c8af7f9c1285, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap: {}
disabledShaderPasses: []
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs: []
m_Ints: []
m_Floats:
- _Absorption: 0.035
- _EdgeSoftness: 1.5
- _FoamDepth: 4
- _NormalFadeDistance: 4000
- _NormalStrength: 0.7
- _Refraction: 0.025
- _RefractionTint: 0.8
- _Smoothness: 0.94
- _SunGlint: 3
- _WaveDirection: 35
- _WaveLength: 9
- _WaveSpeed: 1
m_Colors:
- _DeepColor: {r: 0.03, g: 0.15, b: 0.17, a: 1}
- _FoamColor: {r: 0.92, g: 0.96, b: 1, a: 1}
- _ShallowColor: {r: 0.16, g: 0.44, b: 0.4, a: 1}
m_BuildTextureStacks: []
m_AllowLocking: 1
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 197611251a7bec4df86d7d0c90f83284
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 2100000
userData:
assetBundleName:
assetBundleVariant:
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: b7d0aefcfa8c4b660870d0f7ca122ea4
guid: fe2d750478c54c112ab086dea0735f1d
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
@@ -6,15 +6,15 @@ TerrainLayer:
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Water
m_DiffuseTexture: {fileID: 2800000, guid: b7d0aefcfa8c4b660870d0f7ca122ea4, type: 3}
m_Name: Riverbed
m_DiffuseTexture: {fileID: 2800000, guid: fe2d750478c54c112ab086dea0735f1d, type: 3}
m_NormalMapTexture: {fileID: 0}
m_MaskMapTexture: {fileID: 0}
m_TileSize: {x: 400, y: 400}
m_TileOffset: {x: 0, y: 0}
m_Specular: {r: 0, g: 0, b: 0, a: 0}
m_Metallic: 0
m_Smoothness: 0.85
m_Smoothness: 0.2
m_NormalScale: 1
m_DiffuseRemapMin: {x: 0, y: 0, z: 0, w: 0}
m_DiffuseRemapMax: {x: 1, y: 1, z: 1, w: 1}
@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 444b71326748d68d89d08afee169c9ca
guid: af0d853c314467c598554fa180673bc4
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 8574412962073106934
@@ -8,7 +8,7 @@ Material:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Ocean
m_Shader: {fileID: 4800000, guid: 933532a4fcc9baf4fa0491de14d08ed7, type: 3}
m_Shader: {fileID: 4800000, guid: e6a40dc93388798f8bd7c8af7f9c1285, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
@@ -17,8 +17,7 @@ Material:
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: -1
stringTagMap:
RenderType: Opaque
stringTagMap: {}
disabledShaderPasses:
- MOTIONVECTORS
m_LockedProperties:
@@ -83,6 +82,7 @@ Material:
m_Offset: {x: 0, y: 0}
m_Ints: []
m_Floats:
- _Absorption: 0.012
- _AddPrecomputedVelocity: 0
- _AlphaClip: 0
- _AlphaToMask: 0
@@ -97,28 +97,41 @@ Material:
- _DetailNormalMapScale: 1
- _DstBlend: 0
- _DstBlendAlpha: 0
- _EdgeSoftness: 1.5
- _EnvironmentReflections: 1
- _FoamDepth: 8
- _GlossMapScale: 0
- _Glossiness: 0
- _GlossyReflections: 0
- _Metallic: 0
- _NormalFadeDistance: 9000
- _NormalStrength: 0.7
- _OcclusionStrength: 1
- _Parallax: 0.005
- _QueueOffset: 0
- _ReceiveShadows: 1
- _Refraction: 0.025
- _RefractionTint: 0.8
- _Smoothness: 0.88
- _SmoothnessTextureChannel: 0
- _SpecularHighlights: 1
- _SrcBlend: 1
- _SrcBlendAlpha: 1
- _SunGlint: 3
- _Surface: 0
- _WaveDirection: 35
- _WaveLength: 30
- _WaveSpeed: 1
- _WorkflowMode: 1
- _XRMotionVectorsPass: 1
- _ZWrite: 1
m_Colors:
- _BaseColor: {r: 0.14901961, g: 0.36078432, b: 0.65882355, a: 1}
- _Color: {r: 0.14901957, g: 0.3607843, b: 0.65882355, a: 1}
- _DeepColor: {r: 0.02, g: 0.09, b: 0.22, a: 1}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
- _FoamColor: {r: 0.92, g: 0.96, b: 1, a: 1}
- _ShallowColor: {r: 0.1, g: 0.5, b: 0.56, a: 1}
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
m_BuildTextureStacks: []
m_AllowLocking: 1
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 27fd825d3a967889995aecf2181f2900
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 96e7ee7c811c7ce669d4004b0001b80c
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 4300000
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6c563c039925d8f3fa856eab11a7d5da
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 4300000
userData:
assetBundleName:
assetBundleVariant:

Some files were not shown because too many files have changed in this diff Show More