Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f0fc3b6e9b | ||
|
|
cf6b4827ef | ||
|
|
8fb6b97010 | ||
|
|
a11d3cab87 | ||
|
|
d0a0b02323 |
10 changed files with 1504 additions and 186 deletions
|
|
@ -16,5 +16,5 @@ Public site for [Rust to Dust](https://rtd.gamecult.org), built as a `GameCult-Q
|
|||
|
||||
## Status
|
||||
|
||||
- **Live in this repo:** `GameCult-Quartz` Imperial Chrome overlay, self-hosted Monaspace Krypton font, progressive-enhancement Sion Lobby status bar (`/api/directory/servers`), and Yggdrasil release deploy script.
|
||||
- **Live in this repo:** `GameCult-Quartz` vector-only military HUD overlay, self-hosted Monaspace Krypton font, progressive-enhancement Sion Lobby status bar (`/api/directory/servers`), and Yggdrasil release deploy script.
|
||||
- **Scaffolded:** `content/Architecture/index.md` (six subsystem teardown slots) and `content/Lore/index.md` (stub for Weksa).
|
||||
|
|
|
|||
|
|
@ -95,3 +95,15 @@ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
|
|||
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE FONT SOFTWARE OR FROM
|
||||
OTHER DEALINGS IN THE FONT SOFTWARE.
|
||||
|
||||
|
||||
Sion Terrain & Building Data (`site/quartz/static/sion-dem.png`)
|
||||
================================================================
|
||||
|
||||
Source: Federal Office of Topography swisstopo - ch.swisstopo.swissalti3d & ch.swisstopo.swissbuildings3d_3_0
|
||||
|
||||
Provided under swisstopo Open Government Data (OGD) terms of use:
|
||||
https://www.swisstopo.admin.ch/en/terms-of-use-free-geodata-and-geoservices
|
||||
|
||||
Elevation, urban building footprints, and hydrological masks derived from
|
||||
swisstopo datasets are packed into `site/quartz/static/sion-dem.png`.
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
---
|
||||
title: Lore
|
||||
description: Setting notes and world documentation for Rust to Dust.
|
||||
description: Setting notes and operational theater dossiers for Rust to Dust.
|
||||
---
|
||||
|
||||
Setting notes and world documentation authored by Weksa.
|
||||
|
||||
This section is currently a scaffold awaiting prose-council-reviewed lore pages.
|
||||
Field dossiers, faction briefs, and Sion valley setting documentation are incoming.
|
||||
|
|
|
|||
|
|
@ -4,15 +4,46 @@ description: Salvage-grid vehicular and mech combat in a 3 km Swiss Alpine valle
|
|||
---
|
||||
|
||||
<section class="rtd-hero">
|
||||
<p class="rtd-kicker">GameCult // Vehicle & Mech Arena</p>
|
||||
<h1>RUST TO DUST</h1>
|
||||
<p>Salvage-grid vehicular and mech combat across a 3 km Swiss Alpine valley around Sion. Twelve contenders drop in by orbital pod inside a shrinking ring, fighting rival pilots and gilded Imperial spectators while bolting salvaged weapons onto live thermal chassis mid-match.</p>
|
||||
<div class="rtd-hero-rail">
|
||||
<span>SION SECTOR // 46.2331N 7.3606E</span>
|
||||
</div>
|
||||
<div class="rtd-hero-copy">
|
||||
<h1>RUST TO DUST</h1>
|
||||
<p>Salvage-grid vehicular and mech combat across a 3 km Swiss Alpine valley around Sion. Twelve contenders drop in by orbital pod inside a shrinking ring, fighting rival pilots and gilded Imperial spectators while bolting salvaged weapons onto live thermal chassis mid-match.</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<div class="rtd-telemetry" data-rtd-lobby-status>Sion Lobby · <code>rtd.gamecult.org:3076</code></div>
|
||||
<div class="rtd-telemetry" data-rtd-lobby-status>
|
||||
<div class="rtd-telemetry-cell rtd-telemetry-link">
|
||||
<span class="rtd-telemetry-label">LINK</span>
|
||||
<span class="rtd-telemetry-value"><span class="rtd-telemetry-pip" aria-hidden="true"></span>STANDBY</span>
|
||||
</div>
|
||||
<div class="rtd-telemetry-cell">
|
||||
<span class="rtd-telemetry-label">NODE</span>
|
||||
<span class="rtd-telemetry-value">SION LOBBY</span>
|
||||
</div>
|
||||
<div class="rtd-telemetry-cell">
|
||||
<span class="rtd-telemetry-label">CREW</span>
|
||||
<span class="rtd-telemetry-value">--/--</span>
|
||||
</div>
|
||||
<div class="rtd-telemetry-cell">
|
||||
<span class="rtd-telemetry-label">SECTOR</span>
|
||||
<span class="rtd-telemetry-value">SION</span>
|
||||
</div>
|
||||
<div class="rtd-telemetry-cell">
|
||||
<span class="rtd-telemetry-label">STATE</span>
|
||||
<span class="rtd-telemetry-value">DIRECT</span>
|
||||
</div>
|
||||
<div class="rtd-telemetry-cell rtd-telemetry-endpoint">
|
||||
<span class="rtd-telemetry-label">ENDPOINT</span>
|
||||
<span class="rtd-telemetry-value"><code>rtd.gamecult.org:3076</code></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||

|
||||
|
||||
<section class="rtd-panel">
|
||||
|
||||
## What the Game Is
|
||||
|
||||
*Rust to Dust* drops 12 contenders—solo or in squads—into a live arena ring. The last contender or squad left standing after final-ring orbital redeployments close wins the match. On the ground, you pilot one of 15 chassis spanning wheeled buggies, tracked tanks, VTOL craft, four-legged walkers, and tall bipedal mechs. Around the perimeter orbit three tiers of Imperial spectators—heavy gilded Tourist walkers, agile Patron hunters, and stealthy Exemplar escorts—who stay neutral until provoked. Opening fire near them triggers a lethal hunt under live Imperial Broadcast commentary, while bringing one down drops high-tier Imperial weapons and multi-stage ordnance onto the field.
|
||||
|
|
@ -25,11 +56,25 @@ Every vehicle and mech is simulated as a physical 2D thermal grid:
|
|||
|
||||
That combat plays out over a `3,072 m × 3,072 m` Swiss Alpine valley centered on Sion alongside a `1,536 m × 1,536 m` desert testbed. Artillery craters, blast scorches, and tire tracks stamp straight into the shared `192 m` terrain grid, altering physics collision and surviving from match to match in a persistent scar cache.
|
||||
|
||||
</section>
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
## Sections
|
||||
|
||||
- [Architecture](/Architecture/) — Six engineering teardowns covering the single-draw-call Vulkan HUD, `0.5 m` swisstopo terrain and tiled physics, lighting and volumetric plumes, thermal-grid netcode, upright mech walkers (work in progress), and planned destructible Sion buildings and valley foliage.
|
||||
- [Lore](/Lore/) — Setting notes and world documentation authored by Weksa.
|
||||
<div class="rtd-index-grid">
|
||||
<a class="rtd-index-card" href="/Architecture/">
|
||||
<span class="rtd-index-kicker">01 // ARCHITECTURE</span>
|
||||
<span class="rtd-index-title">Subsystem Teardowns</span>
|
||||
<span class="rtd-index-desc">Six engineering teardowns: single-draw-call Vulkan HUD, 0.5 m swisstopo terrain and tiled physics, lighting and volumetric plumes, thermal-grid netcode, upright mech walkers, and destructible Sion buildings.</span>
|
||||
<span class="rtd-index-cue">ACCESS CHANNEL -></span>
|
||||
</a>
|
||||
<a class="rtd-index-card" href="/Lore/">
|
||||
<span class="rtd-index-kicker">02 // LORE</span>
|
||||
<span class="rtd-index-title">Setting & World Notes</span>
|
||||
<span class="rtd-index-desc">Sion valley theater history, factions, and operational field dossiers.</span>
|
||||
<span class="rtd-index-cue">ACCESS CHANNEL -></span>
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -23,10 +23,12 @@ node "${WORK}/GameCult-Quartz/scripts/build-site.mjs" build \
|
|||
--siteRoot "${WORK}/rtd-site" \
|
||||
--contentDir content \
|
||||
--overlayDir site \
|
||||
--outputDir "${RELEASE_DIR}"
|
||||
--outputDir "${WORK}/public"
|
||||
|
||||
test -s "${RELEASE_DIR}/index.html"
|
||||
test -s "${RELEASE_DIR}/index.css"
|
||||
test -s "${WORK}/public/index.html"
|
||||
test -s "${WORK}/public/index.css"
|
||||
|
||||
mv "${WORK}/public" "${RELEASE_DIR}"
|
||||
|
||||
ln -sfn "${RELEASE_DIR}" "${CURRENT_LINK}"
|
||||
ACTIVE_TARGET="$(readlink -f "${CURRENT_LINK}")"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { Fragment, h } from "preact"
|
||||
import { h } from "preact"
|
||||
import { QuartzConfig } from "./quartz/cfg"
|
||||
import * as Plugin from "./quartz/plugins"
|
||||
import { QuartzEmitterPlugin } from "./quartz/plugins/types"
|
||||
|
|
@ -9,11 +9,8 @@ const RtdMeta: QuartzEmitterPlugin = () => ({
|
|||
async *partialEmit() {},
|
||||
externalResources: () => ({
|
||||
additionalHead: [
|
||||
() =>
|
||||
h(Fragment, {}, [
|
||||
h("meta", { name: "theme-color", content: "#0E1114" }),
|
||||
h("meta", { name: "twitter:card", content: "summary_large_image" }),
|
||||
]),
|
||||
() => h("meta", { name: "theme-color", content: "#0D100D" }),
|
||||
() => h("script", { src: "/static/sion-hud.js", defer: true }),
|
||||
],
|
||||
}),
|
||||
})
|
||||
|
|
@ -35,31 +32,31 @@ const config: QuartzConfig = {
|
|||
typography: {
|
||||
title: "JetBrains Mono",
|
||||
header: "JetBrains Mono",
|
||||
body: "Inter",
|
||||
body: "JetBrains Mono",
|
||||
code: "Monaspace Krypton",
|
||||
},
|
||||
colors: {
|
||||
lightMode: {
|
||||
light: "#0E1114",
|
||||
lightgray: "#1D252E",
|
||||
gray: "#6E7D8C",
|
||||
darkgray: "#C9D3DC",
|
||||
dark: "#EBF0F5",
|
||||
secondary: "#E09838",
|
||||
tertiary: "#38C4D4",
|
||||
highlight: "rgba(56, 196, 212, 0.12)",
|
||||
textHighlight: "#E0983844",
|
||||
light: "#0d100d",
|
||||
lightgray: "#3e4638",
|
||||
gray: "#989487",
|
||||
darkgray: "#e4dfd2",
|
||||
dark: "#e4dfd2",
|
||||
secondary: "#9bb06a",
|
||||
tertiary: "#44d9e8",
|
||||
highlight: "rgba(155, 176, 106, 0.12)",
|
||||
textHighlight: "#e08a4a44",
|
||||
},
|
||||
darkMode: {
|
||||
light: "#0E1114",
|
||||
lightgray: "#1D252E",
|
||||
gray: "#6E7D8C",
|
||||
darkgray: "#C9D3DC",
|
||||
dark: "#EBF0F5",
|
||||
secondary: "#E09838",
|
||||
tertiary: "#38C4D4",
|
||||
highlight: "rgba(56, 196, 212, 0.12)",
|
||||
textHighlight: "#E0983844",
|
||||
light: "#0d100d",
|
||||
lightgray: "#3e4638",
|
||||
gray: "#989487",
|
||||
darkgray: "#e4dfd2",
|
||||
dark: "#e4dfd2",
|
||||
secondary: "#9bb06a",
|
||||
tertiary: "#44d9e8",
|
||||
highlight: "rgba(155, 176, 106, 0.12)",
|
||||
textHighlight: "#e08a4a44",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
|
|
|||
|
|
@ -2,11 +2,13 @@ import { QuartzComponent, QuartzComponentConstructor, QuartzComponentProps } fro
|
|||
import { FullSlug, resolveRelative } from "../util/path"
|
||||
|
||||
const routes = [
|
||||
{ label: "Overview", slug: "index" as FullSlug, prefix: "index" },
|
||||
{ label: "Architecture", slug: "Architecture/index" as FullSlug, prefix: "Architecture" },
|
||||
{ label: "Lore", slug: "Lore/index" as FullSlug, prefix: "Lore" },
|
||||
{ code: "01", label: "OVERVIEW", slug: "index" as FullSlug, prefix: "index" },
|
||||
{ code: "02", label: "ARCHITECTURE", slug: "Architecture/index" as FullSlug, prefix: "Architecture" },
|
||||
{ code: "03", label: "LORE", slug: "Lore/index" as FullSlug, prefix: "Lore" },
|
||||
]
|
||||
|
||||
const compassDegrees = Array.from({ length: 73 }, (_, i) => i * 5)
|
||||
|
||||
function isActive(currentSlug: string, prefix: string) {
|
||||
return prefix === "index"
|
||||
? currentSlug === "index"
|
||||
|
|
@ -21,6 +23,36 @@ const lobbyStatusScript = `
|
|||
const controller = typeof AbortController === "function" ? new AbortController() : null;
|
||||
const timer = controller ? window.setTimeout(() => controller.abort(), 4000) : null;
|
||||
|
||||
function makeCell(label, value, extraClass, withPip, asCode) {
|
||||
const cell = document.createElement("div");
|
||||
cell.className = extraClass ? "rtd-telemetry-cell " + extraClass : "rtd-telemetry-cell";
|
||||
|
||||
const lbl = document.createElement("span");
|
||||
lbl.className = "rtd-telemetry-label";
|
||||
lbl.textContent = label;
|
||||
|
||||
const val = document.createElement("span");
|
||||
val.className = "rtd-telemetry-value";
|
||||
|
||||
if (withPip) {
|
||||
const pip = document.createElement("span");
|
||||
pip.className = "rtd-telemetry-pip";
|
||||
pip.setAttribute("aria-hidden", "true");
|
||||
val.appendChild(pip);
|
||||
val.appendChild(document.createTextNode(value));
|
||||
} else if (asCode) {
|
||||
const code = document.createElement("code");
|
||||
code.textContent = value;
|
||||
val.appendChild(code);
|
||||
} else {
|
||||
val.textContent = value;
|
||||
}
|
||||
|
||||
cell.appendChild(lbl);
|
||||
cell.appendChild(val);
|
||||
return cell;
|
||||
}
|
||||
|
||||
fetch("/api/directory/servers", {
|
||||
headers: { Accept: "application/json" },
|
||||
signal: controller ? controller.signal : undefined,
|
||||
|
|
@ -31,29 +63,25 @@ const lobbyStatusScript = `
|
|||
const srv = servers[0];
|
||||
if (!srv || typeof srv !== "object") return;
|
||||
|
||||
const name = typeof srv.name === "string" && srv.name.trim() ? srv.name.trim() : "Sion Lobby";
|
||||
const humans = Number.isFinite(srv.humans) ? String(srv.humans) : "?";
|
||||
const maxHumans = Number.isFinite(srv.maxHumans) ? String(srv.maxHumans) : "?";
|
||||
const map = typeof srv.map === "string" && srv.map.trim() ? srv.map.trim() : "unknown";
|
||||
const phase = typeof srv.phase === "string" && srv.phase.trim() ? srv.phase.trim() : "unknown";
|
||||
const name = typeof srv.name === "string" && srv.name.trim() ? srv.name.trim() : "SION LOBBY";
|
||||
const humans = Number.isFinite(srv.humans) ? String(srv.humans) : "--";
|
||||
const maxHumans = Number.isFinite(srv.maxHumans) ? String(srv.maxHumans) : "--";
|
||||
const map = typeof srv.map === "string" && srv.map.trim() ? srv.map.trim().toUpperCase() : "SION";
|
||||
const phase = typeof srv.phase === "string" && srv.phase.trim() ? srv.phase.trim().toUpperCase() : "DIRECT";
|
||||
const endpoint =
|
||||
typeof srv.publicHost === "string" && srv.publicHost.trim() && Number.isFinite(srv.udpPort)
|
||||
? srv.publicHost.trim() + ":" + String(srv.udpPort)
|
||||
: "rtd.gamecult.org:3076";
|
||||
|
||||
for (const el of targets) {
|
||||
const dot = document.createElement("span");
|
||||
dot.className = "rtd-telemetry-dot";
|
||||
dot.setAttribute("aria-hidden", "true");
|
||||
|
||||
const summary = document.createElement("span");
|
||||
summary.textContent =
|
||||
name + " · " + humans + "/" + maxHumans + " · " + map + " · " + phase + " · ";
|
||||
|
||||
const code = document.createElement("code");
|
||||
code.textContent = endpoint;
|
||||
|
||||
el.replaceChildren(dot, summary, code);
|
||||
el.replaceChildren(
|
||||
makeCell("LINK", "LIVE", "rtd-telemetry-link", true, false),
|
||||
makeCell("NODE", name, "", false, false),
|
||||
makeCell("CREW", humans + "/" + maxHumans, "", false, false),
|
||||
makeCell("SECTOR", map, "", false, false),
|
||||
makeCell("STATE", phase, "", false, false),
|
||||
makeCell("ENDPOINT", endpoint, "rtd-telemetry-endpoint", false, true)
|
||||
);
|
||||
el.setAttribute("data-rtd-lobby-live", "true");
|
||||
}
|
||||
})
|
||||
|
|
@ -70,30 +98,94 @@ export default (() => {
|
|||
|
||||
return (
|
||||
<section class="rtd-masthead">
|
||||
<a
|
||||
class="rtd-wordmark"
|
||||
href={resolveRelative(currentSlug, "index" as FullSlug)}
|
||||
aria-label="Rust to Dust home"
|
||||
>
|
||||
RUST TO DUST
|
||||
</a>
|
||||
<nav class="rtd-nav" aria-label="Rust to Dust sections">
|
||||
{routes.map((route) => {
|
||||
const active = isActive(currentSlug, route.prefix)
|
||||
return (
|
||||
<a
|
||||
href={resolveRelative(currentSlug, route.slug)}
|
||||
class={active ? "active" : undefined}
|
||||
aria-current={active ? "page" : undefined}
|
||||
<div class="rtd-masthead-top">
|
||||
<div class="rtd-brand">
|
||||
<a
|
||||
class="rtd-wordmark"
|
||||
href={resolveRelative(currentSlug, "index" as FullSlug)}
|
||||
aria-label="Rust to Dust home"
|
||||
>
|
||||
<svg
|
||||
class="rtd-emblem"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
aria-hidden="true"
|
||||
>
|
||||
{route.label}
|
||||
</a>
|
||||
)
|
||||
})}
|
||||
<a class="rtd-nav-quiet" href="https://gamecult.org">
|
||||
GameCult
|
||||
</a>
|
||||
</nav>
|
||||
<path
|
||||
d="M2 5.5V2H5.5M18.5 2H22V5.5M2 18.5V22H5.5M18.5 22H22V18.5"
|
||||
stroke="#3e4638"
|
||||
stroke-width="1"
|
||||
/>
|
||||
<circle cx="12" cy="12" r="7.5" stroke="#9bb06a" stroke-width="1" />
|
||||
<path
|
||||
d="M12 1V6.5M12 17.5V23M1 12H6.5M17.5 12H23"
|
||||
stroke="#9bb06a"
|
||||
stroke-width="1"
|
||||
/>
|
||||
<rect x="10.5" y="10.5" width="3" height="3" fill="#e08a4a" />
|
||||
</svg>
|
||||
<span>RUST TO DUST</span>
|
||||
</a>
|
||||
<span class="rtd-sys-tag">SYS // RTD-01</span>
|
||||
</div>
|
||||
|
||||
<nav class="rtd-nav" aria-label="Rust to Dust sections">
|
||||
{routes.map((route) => {
|
||||
const active = isActive(currentSlug, route.prefix)
|
||||
return (
|
||||
<a
|
||||
href={resolveRelative(currentSlug, route.slug)}
|
||||
class={active ? "active" : undefined}
|
||||
aria-current={active ? "page" : undefined}
|
||||
>
|
||||
<span class="rtd-nav-idx">{route.code}</span>
|
||||
<span class="rtd-nav-label">{route.label}</span>
|
||||
</a>
|
||||
)
|
||||
})}
|
||||
<a class="rtd-nav-quiet" href="https://gamecult.org">
|
||||
<span class="rtd-nav-idx">00</span>
|
||||
<span class="rtd-nav-label">GAMECULT</span>
|
||||
</a>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<div class="rtd-compass" aria-hidden="true">
|
||||
<svg
|
||||
class="rtd-compass-svg"
|
||||
viewBox="0 0 960 22"
|
||||
preserveAspectRatio="xMidYMid meet"
|
||||
fill="none"
|
||||
>
|
||||
<line x1="0" y1="0.5" x2="960" y2="0.5" stroke="#3e4638" stroke-width="1" />
|
||||
{compassDegrees.map((deg) => {
|
||||
const x = 30 + (deg / 5) * 12.5
|
||||
const isMajor = deg % 45 === 0
|
||||
const isMedium = !isMajor && deg % 15 === 0
|
||||
const y2 = isMajor ? 10 : isMedium ? 7 : 4
|
||||
const stroke = isMajor ? "#9bb06a" : isMedium ? "#5c6852" : "#3e4638"
|
||||
const label = String(deg).padStart(3, "0")
|
||||
return (
|
||||
<g key={deg}>
|
||||
<line x1={x} y1="1" x2={x} y2={y2} stroke={stroke} stroke-width="1" />
|
||||
{isMajor && (
|
||||
<text
|
||||
x={x}
|
||||
y="20"
|
||||
text-anchor="middle"
|
||||
class={deg === 180 ? "rtd-compass-center-label" : "rtd-compass-label"}
|
||||
>
|
||||
{label}
|
||||
</text>
|
||||
)}
|
||||
</g>
|
||||
)
|
||||
})}
|
||||
<polygon points="476,1 484,1 480,6.5" fill="#e08a4a" />
|
||||
</svg>
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
BIN
site/quartz/static/sion-dem.png
Normal file
BIN
site/quartz/static/sion-dem.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 177 KiB |
471
site/quartz/static/sion-hud.js
Normal file
471
site/quartz/static/sion-hud.js
Normal file
|
|
@ -0,0 +1,471 @@
|
|||
(() => {
|
||||
"use strict";
|
||||
if (typeof window === "undefined" || typeof document === "undefined") return;
|
||||
if (document.getElementById("rtd-terrain-canvas")) return;
|
||||
|
||||
const GRID = 224, WORLD_SIZE = 10.0, HEIGHT_SCALE = 2.65, RT_SCALE = 0.8, MAX_DPR = 1.75;
|
||||
const TARGET = [0.05, 0.34, -0.15];
|
||||
const BASE_YAW = -0.78, BASE_PITCH = 0.49, BASE_DIST = 6.15, FOV_Y = (38 * Math.PI) / 180;
|
||||
|
||||
const DEM_GLSL = `
|
||||
vec3 decodeTexel(ivec2 p, ivec2 maxC) {
|
||||
vec4 t = texelFetch(uDem, clamp(p, ivec2(0), maxC), 0);
|
||||
return vec3((t.r * 256.0 + t.g) / 257.0, t.b, t.a);
|
||||
}
|
||||
vec3 sampleDem(vec2 uv) {
|
||||
vec2 maxF = uDemSize - 1.0;
|
||||
ivec2 maxC = ivec2(maxF);
|
||||
vec2 fc = clamp(uv, 0.0, 1.0) * maxF;
|
||||
ivec2 p0 = ivec2(floor(fc));
|
||||
vec2 f = fract(fc);
|
||||
vec3 d00 = decodeTexel(p0, maxC);
|
||||
vec3 d10 = decodeTexel(p0 + ivec2(1, 0), maxC);
|
||||
vec3 d01 = decodeTexel(p0 + ivec2(0, 1), maxC);
|
||||
vec3 d11 = decodeTexel(p0 + ivec2(1, 1), maxC);
|
||||
return mix(mix(d00, d10, f.x), mix(d01, d11, f.x), f.y);
|
||||
}`;
|
||||
|
||||
const PASS1_VS = `#version 300 es
|
||||
precision highp float;
|
||||
precision highp int;
|
||||
layout(location = 0) in vec2 aUv;
|
||||
uniform sampler2D uDem;
|
||||
uniform vec2 uDemSize;
|
||||
uniform mat4 uViewProj;
|
||||
uniform float uWorldSize, uHeightScale;
|
||||
out vec2 vUv;
|
||||
out vec3 vWorldPos;
|
||||
${DEM_GLSL}
|
||||
void main() {
|
||||
vec3 dem = sampleDem(aUv);
|
||||
vec3 wp = vec3((aUv.x - 0.5) * uWorldSize, dem.x * uHeightScale, (aUv.y - 0.5) * uWorldSize);
|
||||
vUv = aUv;
|
||||
vWorldPos = wp;
|
||||
gl_Position = uViewProj * vec4(wp, 1.0);
|
||||
}`;
|
||||
|
||||
const PASS1_FS = `#version 300 es
|
||||
precision highp float;
|
||||
precision highp int;
|
||||
in vec2 vUv;
|
||||
in vec3 vWorldPos;
|
||||
uniform sampler2D uDem;
|
||||
uniform vec2 uDemSize, uCursorXZ;
|
||||
uniform vec3 uCamPos;
|
||||
uniform float uWorldSize, uHeightScale, uTime, uFocusDist, uCursorAlpha;
|
||||
out vec4 fragColor;
|
||||
const float TAU = 6.28318530718;
|
||||
const vec3 GROUND = vec3(0.051, 0.063, 0.051);
|
||||
const vec3 C_MINOR = vec3(0.180, 0.228, 0.165);
|
||||
const vec3 C_MAJOR = vec3(0.416, 0.502, 0.314);
|
||||
const vec3 C_OLIVE = vec3(0.608, 0.690, 0.416);
|
||||
const vec3 C_BONE = vec3(0.847, 0.824, 0.745);
|
||||
const vec3 C_CYAN = vec3(0.267, 0.851, 0.910);
|
||||
const vec3 C_AMBER = vec3(0.878, 0.541, 0.290);
|
||||
${DEM_GLSL}
|
||||
float pxLine(float val, float spacing, float pxWidth) {
|
||||
float s = val / spacing;
|
||||
float fw = max(fwidth(s), 1e-5);
|
||||
float d = abs(fract(s + 0.5) - 0.5) / fw;
|
||||
return (1.0 - smoothstep(pxWidth * 0.5, pxWidth * 0.5 + 1.0, d)) * smoothstep(0.60, 0.20, fw);
|
||||
}
|
||||
float pxRing(float dist, float radius, float pxWidth) {
|
||||
float d = abs(dist - radius) / max(fwidth(dist), 1e-4);
|
||||
return 1.0 - smoothstep(pxWidth * 0.5, pxWidth * 0.5 + 1.0, d);
|
||||
}
|
||||
void main() {
|
||||
vec3 dem = sampleDem(vUv);
|
||||
float h = dem.x, urban = dem.y, water = dem.z;
|
||||
vec2 texel = 1.0 / uDemSize;
|
||||
float hL = sampleDem(vUv - vec2(texel.x, 0.0)).x;
|
||||
float hR = sampleDem(vUv + vec2(texel.x, 0.0)).x;
|
||||
float hD = sampleDem(vUv - vec2(0.0, texel.y)).x;
|
||||
float hU = sampleDem(vUv + vec2(0.0, texel.y)).x;
|
||||
vec3 N = normalize(vec3((hL - hR) * uHeightScale, 2.0 * uWorldSize * texel.x, (hD - hU) * uHeightScale));
|
||||
|
||||
vec3 viewVec = uCamPos - vWorldPos;
|
||||
float viewDepth = length(viewVec);
|
||||
vec3 V = viewVec / max(viewDepth, 1e-4);
|
||||
vec3 L = normalize(vec3(-0.62, 0.66, 0.42));
|
||||
float ndl = max(dot(N, L), 0.0);
|
||||
float rim = pow(1.0 - max(dot(N, V), 0.0), 2.6) * (0.35 + 0.65 * smoothstep(0.06, 0.72, h));
|
||||
float slope = 1.0 - clamp(N.y, 0.0, 1.0);
|
||||
|
||||
vec3 col = GROUND;
|
||||
col += vec3(0.050, 0.068, 0.044) * (0.28 + 0.72 * ndl) * (0.45 + 0.55 * h);
|
||||
col += vec3(0.085, 0.112, 0.070) * rim * (0.45 + 0.55 * slope);
|
||||
|
||||
float dryMask = 1.0 - smoothstep(0.18, 0.62, water);
|
||||
float minorC = pxLine(h, 0.018, 0.85) * dryMask;
|
||||
float majorC = pxLine(h, 0.090, 1.20) * dryMask;
|
||||
col = mix(col, C_MINOR, minorC * (0.55 + 0.25 * ndl));
|
||||
col = mix(col, mix(C_MAJOR, C_OLIVE, clamp(0.25 + 0.55 * ndl + 0.35 * h, 0.0, 1.0)), majorC * 0.78);
|
||||
|
||||
// Rhone river fill and shoreline highlight
|
||||
float waterFill = smoothstep(0.18, 0.68, water);
|
||||
float shore = 1.0 - smoothstep(0.6, 1.8, abs(water - 0.36) / max(fwidth(water), 1e-4));
|
||||
col = mix(col, mix(GROUND, C_CYAN, 0.26), waterFill * 0.85);
|
||||
col += C_CYAN * shore * 0.52 * smoothstep(0.06, 0.30, water);
|
||||
|
||||
// Sion building clusters
|
||||
float urbMask = smoothstep(0.06, 0.75, urban);
|
||||
float urbEdge = clamp(fwidth(urban) * 1.4, 0.0, 1.0) * step(0.05, urban);
|
||||
col = mix(col, mix(C_OLIVE, C_BONE, smoothstep(0.15, 0.88, urban)) * 0.64, urbMask * 0.85);
|
||||
col += C_BONE * urbEdge * 0.22;
|
||||
|
||||
// Projected tactical safe-circle, outer range ring, and slow bearing sweep
|
||||
vec2 relSion = vWorldPos.xz - vec2(-0.55, 0.35);
|
||||
float rSion = length(relSion), ang = atan(relSion.y, relSion.x);
|
||||
float safeRing = pxRing(rSion, 1.62, 1.25) * smoothstep(0.32, 0.38, fract(ang * 28.0 / TAU));
|
||||
float outerRing = pxRing(rSion, 2.85, 0.90) * smoothstep(0.50, 0.56, fract(ang * 48.0 / TAU));
|
||||
float behind = mod(mod(uTime * 0.20, TAU) - 3.14159265 - ang + TAU, TAU);
|
||||
float sweep = exp(-behind * 4.8) * smoothstep(2.90, 2.78, rSion) * smoothstep(0.18, 0.55, rSion);
|
||||
float ray = smoothstep(0.022, 0.0, behind) * smoothstep(2.88, 2.82, rSion);
|
||||
col += C_AMBER * safeRing * 0.68 + C_OLIVE * outerRing * 0.22 + mix(C_OLIVE, C_AMBER, 0.38) * (sweep * 0.075 + ray * 0.18);
|
||||
|
||||
// Cursor target reticle on valley floor
|
||||
if (uCursorAlpha > 0.005) {
|
||||
vec2 relCur = vWorldPos.xz - uCursorXZ;
|
||||
float cRing = pxRing(length(relCur), 0.22, 1.15);
|
||||
float tX = (1.0 - smoothstep(0.012, 0.024, abs(relCur.y))) * step(0.11, abs(relCur.x)) * step(abs(relCur.x), 0.31);
|
||||
float tZ = (1.0 - smoothstep(0.012, 0.024, abs(relCur.x))) * step(0.11, abs(relCur.y)) * step(abs(relCur.y), 0.31);
|
||||
col += mix(C_AMBER, C_CYAN, 0.25) * (cRing * 0.52 + max(tX, tZ) * 0.32) * uCursorAlpha;
|
||||
}
|
||||
|
||||
float edgeFade = smoothstep(0.0, 0.08, min(min(vUv.x, 1.0 - vUv.x), min(vUv.y, 1.0 - vUv.y)));
|
||||
col = mix(GROUND, col, edgeFade * (1.0 - smoothstep(8.2, 13.5, viewDepth)));
|
||||
|
||||
float diff = viewDepth - uFocusDist;
|
||||
float coc = clamp(max(abs(diff) - 0.58, 0.0) * sign(diff) / 3.35, -1.0, 1.0);
|
||||
fragColor = vec4(clamp(col, 0.0, 1.0), clamp(0.5 + 0.5 * coc, 0.0, 1.0));
|
||||
}`;
|
||||
|
||||
const PASS2_VS = `#version 300 es
|
||||
precision highp float;
|
||||
out vec2 vUv;
|
||||
void main() {
|
||||
vec2 pos = vec2(float((gl_VertexID & 1) << 2) - 1.0, float((gl_VertexID & 2) << 1) - 1.0);
|
||||
vUv = pos * 0.5 + 0.5;
|
||||
gl_Position = vec4(pos, 0.0, 1.0);
|
||||
}`;
|
||||
|
||||
const PASS2_FS = `#version 300 es
|
||||
precision highp float;
|
||||
in vec2 vUv;
|
||||
uniform sampler2D uScene;
|
||||
uniform vec2 uSceneRes;
|
||||
uniform float uAspect, uGrainSeed;
|
||||
out vec4 fragColor;
|
||||
const float GOLDEN_ANGLE = 2.39996323;
|
||||
const vec3 GROUND = vec3(0.051, 0.063, 0.051);
|
||||
const vec3 HALATION = vec3(1.0, 0.44, 0.16);
|
||||
void main() {
|
||||
vec2 invRes = 1.0 / uSceneRes;
|
||||
vec4 c0 = texture(uScene, vUv);
|
||||
float blur = abs(c0.a * 2.0 - 1.0);
|
||||
vec3 acc = c0.rgb;
|
||||
float wSum = 1.0;
|
||||
if (blur > 0.012) {
|
||||
for (int i = 0; i < 24; i++) {
|
||||
float r = sqrt((float(i) + 0.5) / 24.0);
|
||||
float a = float(i) * GOLDEN_ANGLE;
|
||||
vec2 off = vec2(cos(a), sin(a)) * (r * blur * 8.5) * invRes;
|
||||
vec4 s = texture(uScene, clamp(vUv + off, 0.001, 0.999));
|
||||
float sCoc = s.a * 2.0 - 1.0;
|
||||
float w = ((sCoc < 0.0) ? 1.0 : smoothstep(0.0, 0.24, abs(sCoc) + blur * 0.65))
|
||||
* (1.0 + 0.35 * dot(s.rgb, vec3(0.30, 0.58, 0.12)));
|
||||
acc += s.rgb * w;
|
||||
wSum += w;
|
||||
}
|
||||
}
|
||||
vec3 col = acc / wSum;
|
||||
|
||||
// Radial lateral chromatic aberration + warm amber halation
|
||||
vec2 fromC = vUv - 0.5;
|
||||
vec2 caOff = fromC * (0.0018 + 0.0038 * blur) * (0.35 + 2.1 * dot(fromC, fromC));
|
||||
col.r = mix(col.r, texture(uScene, clamp(vUv + caOff, 0.001, 0.999)).r, 0.42);
|
||||
col.b = mix(col.b, texture(uScene, clamp(vUv - caOff, 0.001, 0.999)).b, 0.42);
|
||||
|
||||
vec2 hs = invRes * 5.5;
|
||||
vec3 glow = (
|
||||
texture(uScene, clamp(vUv + hs, 0.001, 0.999)).rgb +
|
||||
texture(uScene, clamp(vUv - hs, 0.001, 0.999)).rgb +
|
||||
texture(uScene, clamp(vUv + vec2(-hs.x, hs.y), 0.001, 0.999)).rgb +
|
||||
texture(uScene, clamp(vUv + vec2(hs.x, -hs.y), 0.001, 0.999)).rgb
|
||||
) * 0.25;
|
||||
col += HALATION * max(max(glow.r, max(glow.g, glow.b)) - 0.24, 0.0) * 0.26;
|
||||
|
||||
// Low-luminance grade + cos^4 vignette + deterministic 1/255 grain
|
||||
col = mix(GROUND, col, 0.86);
|
||||
col = col / (1.0 + col * 0.42);
|
||||
vec2 vPos = fromC * vec2(uAspect * 0.52, 0.72);
|
||||
float vig = pow(inversesqrt(1.0 + dot(vPos, vPos)), 4.0);
|
||||
col = mix(vec3(0.036, 0.044, 0.036), col, mix(0.44, 1.0, vig));
|
||||
float ign = fract(52.9829189 * fract(dot(gl_FragCoord.xy + uGrainSeed, vec2(0.06711056, 0.00583715))));
|
||||
col += (ign - 0.5) / 255.0 * 1.4;
|
||||
fragColor = vec4(clamp(col, 0.0, 1.0), 1.0);
|
||||
}`;
|
||||
|
||||
function compile(gl, type, src) {
|
||||
const sh = gl.createShader(type);
|
||||
if (!sh) return null;
|
||||
gl.shaderSource(sh, src);
|
||||
gl.compileShader(sh);
|
||||
if (!gl.getShaderParameter(sh, gl.COMPILE_STATUS)) { gl.deleteShader(sh); return null; }
|
||||
return sh;
|
||||
}
|
||||
|
||||
function link(gl, vsSrc, fsSrc) {
|
||||
const vs = compile(gl, gl.VERTEX_SHADER, vsSrc), fs = compile(gl, gl.FRAGMENT_SHADER, fsSrc);
|
||||
if (!vs || !fs) return null;
|
||||
const p = gl.createProgram();
|
||||
gl.attachShader(p, vs); gl.attachShader(p, fs); gl.linkProgram(p);
|
||||
gl.deleteShader(vs); gl.deleteShader(fs);
|
||||
if (!gl.getProgramParameter(p, gl.LINK_STATUS)) { gl.deleteProgram(p); return null; }
|
||||
return p;
|
||||
}
|
||||
|
||||
function uniforms(gl, p, names) {
|
||||
const out = {};
|
||||
for (const n of names) out[n] = gl.getUniformLocation(p, n);
|
||||
return out;
|
||||
}
|
||||
|
||||
function buildCamera(eye, target, aspect) {
|
||||
let zx = eye[0] - target[0], zy = eye[1] - target[1], zz = eye[2] - target[2];
|
||||
let len = Math.hypot(zx, zy, zz) || 1;
|
||||
zx /= len; zy /= len; zz /= len;
|
||||
let xx = zz, xz = -zx;
|
||||
len = Math.hypot(xx, xz) || 1;
|
||||
xx /= len; xz /= len;
|
||||
const yx = zy * xz, yy = zz * xx - zx * xz, yz = -zy * xx;
|
||||
const tx = -(xx * eye[0] + xz * eye[2]);
|
||||
const ty = -(yx * eye[0] + yy * eye[1] + yz * eye[2]);
|
||||
const tz = -(zx * eye[0] + zy * eye[1] + zz * eye[2]);
|
||||
const f = 1 / Math.tan(FOV_Y * 0.5), near = 0.25, far = 26.0, nf = 1 / (near - far);
|
||||
const pa = f / aspect, pc = (far + near) * nf, pd = 2 * far * near * nf;
|
||||
const vp = new Float32Array([
|
||||
pa * xx, f * yx, pc * zx, -zx,
|
||||
0, f * yy, pc * zy, -zy,
|
||||
pa * xz, f * yz, pc * zz, -zz,
|
||||
pa * tx, f * ty, pc * tz + pd, -tz,
|
||||
]);
|
||||
return { vp, right: [xx, 0, xz], up: [yx, yy, yz], fwd: [-zx, -zy, -zz] };
|
||||
}
|
||||
|
||||
function init() {
|
||||
if (!document.body) return;
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.id = "rtd-terrain-canvas";
|
||||
canvas.setAttribute("aria-hidden", "true");
|
||||
canvas.style.cssText = "position:fixed;inset:0;width:100vw;height:100vh;z-index:0;pointer-events:none;display:block;";
|
||||
|
||||
const gl = canvas.getContext("webgl2", {
|
||||
alpha: false, antialias: false, depth: false, stencil: false,
|
||||
powerPreference: "low-power", preserveDrawingBuffer: false,
|
||||
});
|
||||
if (!gl) return;
|
||||
|
||||
const p1 = link(gl, PASS1_VS, PASS1_FS), p2 = link(gl, PASS2_VS, PASS2_FS);
|
||||
if (!p1 || !p2) return;
|
||||
|
||||
const verts = new Float32Array((GRID + 1) * (GRID + 1) * 2);
|
||||
for (let j = 0, vi = 0; j <= GRID; j++) {
|
||||
for (let i = 0; i <= GRID; i++) { verts[vi++] = i / GRID; verts[vi++] = j / GRID; }
|
||||
}
|
||||
const indices = new Uint16Array(GRID * GRID * 6);
|
||||
for (let j = 0, ii = 0, row = GRID + 1; j < GRID; j++) {
|
||||
for (let i = 0; i < GRID; i++) {
|
||||
const a = j * row + i;
|
||||
indices[ii++] = a; indices[ii++] = a + row; indices[ii++] = a + 1;
|
||||
indices[ii++] = a + 1; indices[ii++] = a + row; indices[ii++] = a + row + 1;
|
||||
}
|
||||
}
|
||||
|
||||
const meshVao = gl.createVertexArray(), quadVao = gl.createVertexArray();
|
||||
gl.bindVertexArray(meshVao);
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
|
||||
gl.bufferData(gl.ARRAY_BUFFER, verts, gl.STATIC_DRAW);
|
||||
gl.enableVertexAttribArray(0);
|
||||
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
|
||||
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, gl.createBuffer());
|
||||
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices, gl.STATIC_DRAW);
|
||||
gl.bindVertexArray(null);
|
||||
|
||||
const demTex = gl.createTexture(), sceneFbo = gl.createFramebuffer();
|
||||
const sceneTex = gl.createTexture(), sceneDepth = gl.createRenderbuffer();
|
||||
const u1 = uniforms(gl, p1, [
|
||||
"uDem", "uDemSize", "uViewProj", "uWorldSize", "uHeightScale",
|
||||
"uCamPos", "uTime", "uFocusDist", "uCursorXZ", "uCursorAlpha",
|
||||
]);
|
||||
const u2 = uniforms(gl, p2, ["uScene", "uSceneRes", "uAspect", "uGrainSeed"]);
|
||||
|
||||
let width = 1, height = 1, rtW = 1, rtH = 1, demW = 320, demH = 320;
|
||||
let mounted = false, contextLost = false, rafId = 0;
|
||||
|
||||
function resize() {
|
||||
const dpr = Math.min(window.devicePixelRatio || 1, MAX_DPR);
|
||||
const w = Math.max(1, Math.round(window.innerWidth * dpr));
|
||||
const h = Math.max(1, Math.round(window.innerHeight * dpr));
|
||||
if (w === width && h === height && mounted) return true;
|
||||
width = w; height = h; canvas.width = w; canvas.height = h;
|
||||
rtW = Math.max(1, Math.round(w * RT_SCALE));
|
||||
rtH = Math.max(1, Math.round(h * RT_SCALE));
|
||||
|
||||
gl.bindTexture(gl.TEXTURE_2D, sceneTex);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, rtW, rtH, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
||||
|
||||
gl.bindRenderbuffer(gl.RENDERBUFFER, sceneDepth);
|
||||
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, rtW, rtH);
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, sceneFbo);
|
||||
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, sceneTex, 0);
|
||||
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, sceneDepth);
|
||||
const ok = gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE;
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
return ok;
|
||||
}
|
||||
|
||||
const mql = window.matchMedia ? window.matchMedia("(prefers-reduced-motion: reduce)") : null;
|
||||
let reduced = Boolean(mql && mql.matches);
|
||||
let ptrX = 0, ptrY = 0, ptrActive = false, lastTs = 0, elapsed = 0;
|
||||
let smX = 0, smY = 0, smFocus = BASE_DIST, smCurX = -0.55, smCurZ = 0.35, smCurA = 0;
|
||||
|
||||
function render(dt) {
|
||||
if (contextLost) return;
|
||||
const damp = reduced ? 1 : 1 - Math.exp(-dt * 4.5);
|
||||
const afDamp = reduced ? 1 : 1 - Math.exp(-dt * 3.4);
|
||||
smX += ((ptrActive && !reduced ? ptrX : 0) - smX) * damp;
|
||||
smY += ((ptrActive && !reduced ? ptrY : 0) - smY) * damp;
|
||||
smCurA += ((ptrActive && !reduced ? 1 : 0) - smCurA) * damp;
|
||||
|
||||
const yaw = BASE_YAW + (reduced ? 0 : Math.sin(elapsed * 0.065) * 0.055) + smX * 0.061;
|
||||
const pitch = BASE_PITCH - smY * 0.031, cp = Math.cos(pitch);
|
||||
const eye = [
|
||||
TARGET[0] + cp * Math.sin(yaw) * BASE_DIST,
|
||||
TARGET[1] + Math.sin(pitch) * BASE_DIST,
|
||||
TARGET[2] + cp * Math.cos(yaw) * BASE_DIST,
|
||||
];
|
||||
const aspect = width / height, cam = buildCamera(eye, TARGET, aspect);
|
||||
|
||||
let targetFocus = BASE_DIST;
|
||||
if (ptrActive && !reduced) {
|
||||
const thf = Math.tan(FOV_Y * 0.5);
|
||||
const rx = cam.fwd[0] + cam.right[0] * (smX * thf * aspect) + cam.up[0] * (-smY * thf);
|
||||
const ry = cam.fwd[1] + cam.up[1] * (-smY * thf);
|
||||
const rz = cam.fwd[2] + cam.right[2] * (smX * thf * aspect) + cam.up[2] * (-smY * thf);
|
||||
if (ry < -0.05) {
|
||||
const tHit = (0.14 - eye[1]) / ry;
|
||||
const hx = Math.max(-4.4, Math.min(4.4, eye[0] + rx * tHit));
|
||||
const hz = Math.max(-4.4, Math.min(4.4, eye[2] + rz * tHit));
|
||||
smCurX += (hx - smCurX) * damp;
|
||||
smCurZ += (hz - smCurZ) * damp;
|
||||
targetFocus = Math.max(3.3, Math.min(9.5, Math.hypot(hx - eye[0], 0.14 - eye[1], hz - eye[2])));
|
||||
}
|
||||
}
|
||||
smFocus += (targetFocus - smFocus) * afDamp;
|
||||
|
||||
// Pass 1: 3D Sion terrain + CoC to 0.8x FBO
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, sceneFbo);
|
||||
gl.viewport(0, 0, rtW, rtH);
|
||||
gl.enable(gl.DEPTH_TEST);
|
||||
gl.depthFunc(gl.LESS);
|
||||
gl.clearColor(0.051, 0.063, 0.051, 0.92);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||
gl.useProgram(p1);
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.bindTexture(gl.TEXTURE_2D, demTex);
|
||||
gl.uniform1i(u1.uDem, 0);
|
||||
gl.uniform2f(u1.uDemSize, demW, demH);
|
||||
gl.uniformMatrix4fv(u1.uViewProj, false, cam.vp);
|
||||
gl.uniform1f(u1.uWorldSize, WORLD_SIZE);
|
||||
gl.uniform1f(u1.uHeightScale, HEIGHT_SCALE);
|
||||
gl.uniform3f(u1.uCamPos, eye[0], eye[1], eye[2]);
|
||||
gl.uniform1f(u1.uTime, elapsed);
|
||||
gl.uniform1f(u1.uFocusDist, smFocus);
|
||||
gl.uniform2f(u1.uCursorXZ, smCurX, smCurZ);
|
||||
gl.uniform1f(u1.uCursorAlpha, smCurA);
|
||||
gl.bindVertexArray(meshVao);
|
||||
gl.drawElements(gl.TRIANGLES, indices.length, gl.UNSIGNED_SHORT, 0);
|
||||
|
||||
// Pass 2: Fullscreen optical bokeh DoF + CA + halation + vignette + grain
|
||||
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
||||
gl.viewport(0, 0, width, height);
|
||||
gl.disable(gl.DEPTH_TEST);
|
||||
gl.useProgram(p2);
|
||||
gl.activeTexture(gl.TEXTURE0);
|
||||
gl.bindTexture(gl.TEXTURE_2D, sceneTex);
|
||||
gl.uniform1i(u2.uScene, 0);
|
||||
gl.uniform2f(u2.uSceneRes, rtW, rtH);
|
||||
gl.uniform1f(u2.uAspect, aspect);
|
||||
gl.uniform1f(u2.uGrainSeed, reduced ? 0.0 : (elapsed * 23.0) % 100.0);
|
||||
gl.bindVertexArray(quadVao);
|
||||
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
||||
gl.bindVertexArray(null);
|
||||
}
|
||||
|
||||
function tick(ts) {
|
||||
rafId = 0;
|
||||
if (reduced || document.hidden || contextLost) return;
|
||||
const dt = lastTs ? Math.min((ts - lastTs) * 0.001, 0.05) : 0.016;
|
||||
lastTs = ts;
|
||||
elapsed += dt;
|
||||
render(dt);
|
||||
rafId = window.requestAnimationFrame(tick);
|
||||
}
|
||||
const startLoop = () => { if (!reduced && !document.hidden && !contextLost && !rafId) { lastTs = 0; rafId = window.requestAnimationFrame(tick); } };
|
||||
const stopLoop = () => { if (rafId) { window.cancelAnimationFrame(rafId); rafId = 0; } };
|
||||
|
||||
const img = new Image();
|
||||
img.decoding = "async";
|
||||
img.onload = () => {
|
||||
if (!img.naturalWidth || !img.naturalHeight || contextLost) return;
|
||||
demW = img.naturalWidth; demH = img.naturalHeight;
|
||||
gl.bindTexture(gl.TEXTURE_2D, demTex);
|
||||
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
||||
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
|
||||
gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
||||
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
||||
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, gl.RGBA, gl.UNSIGNED_BYTE, img);
|
||||
if (!resize()) return;
|
||||
|
||||
document.body.insertBefore(canvas, document.body.firstChild);
|
||||
document.body.classList.add("rtd-webgl-active");
|
||||
mounted = true;
|
||||
render(0);
|
||||
if (!reduced) startLoop();
|
||||
|
||||
window.addEventListener("resize", () => { if (resize() && (reduced || !rafId)) render(0); }, { passive: true });
|
||||
window.addEventListener("pointermove", (e) => {
|
||||
if (!window.innerWidth || !window.innerHeight) return;
|
||||
ptrX = (e.clientX / window.innerWidth) * 2 - 1;
|
||||
ptrY = (e.clientY / window.innerHeight) * 2 - 1;
|
||||
ptrActive = true;
|
||||
}, { passive: true });
|
||||
window.addEventListener("pointerleave", () => { ptrActive = false; }, { passive: true });
|
||||
window.addEventListener("blur", () => { ptrActive = false; }, { passive: true });
|
||||
document.addEventListener("visibilitychange", () => { if (document.hidden) stopLoop(); else if (!reduced) startLoop(); });
|
||||
if (mql && typeof mql.addEventListener === "function") {
|
||||
mql.addEventListener("change", (ev) => {
|
||||
reduced = ev.matches;
|
||||
if (reduced) { stopLoop(); render(0); } else startLoop();
|
||||
});
|
||||
}
|
||||
canvas.addEventListener("webglcontextlost", (ev) => {
|
||||
ev.preventDefault(); contextLost = true; stopLoop();
|
||||
document.body.classList.remove("rtd-webgl-active");
|
||||
});
|
||||
};
|
||||
img.onerror = () => {};
|
||||
img.src = "/static/sion-dem.png";
|
||||
}
|
||||
|
||||
if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", init, { once: true });
|
||||
else init();
|
||||
})();
|
||||
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue