oda-engine 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +151 -2
- package/bin/nowhere.mjs +352 -0
- package/lib/account.mjs +57 -0
- package/lib/agentModules.mjs +57 -0
- package/lib/devServer.mjs +351 -0
- package/lib/headless.mjs +231 -0
- package/lib/headlessPreview.mjs +212 -0
- package/lib/keys.mjs +517 -0
- package/lib/make.mjs +855 -0
- package/lib/mcp.mjs +537 -0
- package/lib/open.mjs +22 -0
- package/lib/preview.mjs +87 -0
- package/lib/previewRpc.mjs +134 -0
- package/lib/project.mjs +359 -0
- package/lib/publishFlow.mjs +90 -0
- package/lib/resources.mjs +50 -0
- package/lib/rules.mjs +60 -0
- package/lib/scaffold.mjs +42 -0
- package/lib/setup.mjs +59 -0
- package/lib/tools.mjs +668 -0
- package/package.json +51 -4
- package/template/game.config.json +9 -0
- package/template/scene.json +4 -0
- package/template/src/main.ts +11 -0
- package/vendor/DOCS.md +447 -0
- package/vendor/agent/appRun.mjs +520 -0
- package/vendor/agent/assets/brief.mjs +242 -0
- package/vendor/agent/assets/collider.mjs +531 -0
- package/vendor/agent/assets/environments/index.mjs +12 -0
- package/vendor/agent/assets/environments/worldlabs.mjs +161 -0
- package/vendor/agent/assets/fetch.mjs +168 -0
- package/vendor/agent/assets/footprint.mjs +13 -0
- package/vendor/agent/assets/gltf.mjs +547 -0
- package/vendor/agent/assets/hdr.mjs +269 -0
- package/vendor/agent/assets/imageOps.mjs +171 -0
- package/vendor/agent/assets/images/codex.mjs +307 -0
- package/vendor/agent/assets/images/fal.mjs +75 -0
- package/vendor/agent/assets/images/gemini.mjs +84 -0
- package/vendor/agent/assets/images/index.mjs +25 -0
- package/vendor/agent/assets/images/openai.mjs +75 -0
- package/vendor/agent/assets/images/stability.mjs +71 -0
- package/vendor/agent/assets/images/views.mjs +31 -0
- package/vendor/agent/assets/import.mjs +1352 -0
- package/vendor/agent/assets/inspect.mjs +465 -0
- package/vendor/agent/assets/jobs.mjs +196 -0
- package/vendor/agent/assets/ktx2.mjs +290 -0
- package/vendor/agent/assets/ledger.mjs +466 -0
- package/vendor/agent/assets/net.mjs +254 -0
- package/vendor/agent/assets/prices.json +39 -0
- package/vendor/agent/assets/providers/fal.mjs +115 -0
- package/vendor/agent/assets/providers/index.mjs +22 -0
- package/vendor/agent/assets/providers/meshy.mjs +119 -0
- package/vendor/agent/assets/providers/tripo.mjs +188 -0
- package/vendor/agent/assets/sources/ambientcg.mjs +129 -0
- package/vendor/agent/assets/sources/index.mjs +23 -0
- package/vendor/agent/assets/sources/polyhaven.mjs +237 -0
- package/vendor/agent/assets/sources/polypizza.mjs +121 -0
- package/vendor/agent/assets/splat.mjs +631 -0
- package/vendor/agent/assets/targets.mjs +122 -0
- package/vendor/agent/assets/tile.mjs +261 -0
- package/vendor/agent/assets/unzip.mjs +180 -0
- package/vendor/agent/blender/cleanup.py +360 -0
- package/vendor/agent/blender/convert.py +167 -0
- package/vendor/agent/blender/find.mjs +192 -0
- package/vendor/agent/blender/nw_export.py +104 -0
- package/vendor/agent/blender/nw_rubric.py +426 -0
- package/vendor/agent/blender/run.mjs +193 -0
- package/vendor/agent/blender/runner.py +252 -0
- package/vendor/agent/blender/sheet.py +743 -0
- package/vendor/agent/depth.mjs +134 -0
- package/vendor/agent/director/board.mjs +451 -0
- package/vendor/agent/director/contracts.mjs +663 -0
- package/vendor/agent/director/director.mjs +2365 -0
- package/vendor/agent/director/estimate.mjs +200 -0
- package/vendor/agent/director/gate.mjs +802 -0
- package/vendor/agent/director/limits.json +16 -0
- package/vendor/agent/director/methods.mjs +457 -0
- package/vendor/agent/director/policy.json +33 -0
- package/vendor/agent/director/prompts.mjs +244 -0
- package/vendor/agent/director/reading.mjs +341 -0
- package/vendor/agent/director/router.mjs +184 -0
- package/vendor/agent/director/seams.mjs +243 -0
- package/vendor/agent/director/session.mjs +643 -0
- package/vendor/agent/director/store.mjs +119 -0
- package/vendor/agent/director/taskGate.mjs +110 -0
- package/vendor/agent/director/teamLedger.mjs +118 -0
- package/vendor/agent/director/triage.mjs +63 -0
- package/vendor/agent/downloads.cjs +363 -0
- package/vendor/agent/flow.mjs +78 -0
- package/vendor/agent/guard.mjs +613 -0
- package/vendor/agent/host.mjs +1736 -0
- package/vendor/agent/language.mjs +58 -0
- package/vendor/agent/ledger.mjs +360 -0
- package/vendor/agent/locale.cjs +186 -0
- package/vendor/agent/loop/capacity.mjs +74 -0
- package/vendor/agent/loop/compose.mjs +127 -0
- package/vendor/agent/loop/gate.mjs +205 -0
- package/vendor/agent/loop/judge.mjs +189 -0
- package/vendor/agent/loop/levels.mjs +273 -0
- package/vendor/agent/loop/state.mjs +358 -0
- package/vendor/agent/notes.cjs +278 -0
- package/vendor/agent/pace.mjs +258 -0
- package/vendor/agent/panels.mjs +431 -0
- package/vendor/agent/prompt.mjs +342 -0
- package/vendor/agent/reference/board.mjs +410 -0
- package/vendor/agent/reference/compose.mjs +364 -0
- package/vendor/agent/reference/decode.mjs +56 -0
- package/vendor/agent/reference/facts.mjs +1874 -0
- package/vendor/agent/reference/png.mjs +107 -0
- package/vendor/agent/reference/records.mjs +63 -0
- package/vendor/agent/reference/web.mjs +252 -0
- package/vendor/agent/roles/artist.mjs +69 -0
- package/vendor/agent/roles/builder.mjs +79 -0
- package/vendor/agent/roles/checks.mjs +223 -0
- package/vendor/agent/roles/common.mjs +188 -0
- package/vendor/agent/roles/critic.mjs +171 -0
- package/vendor/agent/roles/index.mjs +39 -0
- package/vendor/agent/roles/modeller.mjs +142 -0
- package/vendor/agent/roles/qa.mjs +58 -0
- package/vendor/agent/roles/rubrics.mjs +79 -0
- package/vendor/agent/roles/sound.mjs +69 -0
- package/vendor/agent/rounds.cjs +333 -0
- package/vendor/agent/shared.mjs +284 -0
- package/vendor/agent/stopGate.mjs +574 -0
- package/vendor/agent/subagents.mjs +129 -0
- package/vendor/agent/tools/assets.mjs +499 -0
- package/vendor/agent/tools/blender.mjs +754 -0
- package/vendor/agent/tools/cards.mjs +479 -0
- package/vendor/agent/tools/choices.mjs +479 -0
- package/vendor/agent/tools/compose.mjs +74 -0
- package/vendor/agent/tools/environment.mjs +488 -0
- package/vendor/agent/tools/eyes.mjs +733 -0
- package/vendor/agent/tools/generate.mjs +338 -0
- package/vendor/agent/tools/guide.mjs +46 -0
- package/vendor/agent/tools/harness.mjs +193 -0
- package/vendor/agent/tools/image.mjs +643 -0
- package/vendor/agent/tools/index.mjs +162 -0
- package/vendor/agent/tools/look.mjs +578 -0
- package/vendor/agent/tools/loop.mjs +858 -0
- package/vendor/agent/tools/others.mjs +123 -0
- package/vendor/agent/tools/pictures.mjs +535 -0
- package/vendor/agent/tools/reference.mjs +366 -0
- package/vendor/agent/transcripts.mjs +118 -0
- package/vendor/agent-loop.mjs +602 -0
- package/vendor/agent-plugin/.claude-plugin/plugin.json +5 -0
- package/vendor/agent-plugin/skills/art-direction/SKILL.md +82 -0
- package/vendor/agent-plugin/skills/asset-legality/SKILL.md +101 -0
- package/vendor/agent-plugin/skills/asset-sources/SKILL.md +111 -0
- package/vendor/agent-plugin/skills/blender-modeling/SKILL.md +97 -0
- package/vendor/agent-plugin/skills/look-dev/SKILL.md +104 -0
- package/vendor/agent-plugin/skills/playtesting/SKILL.md +74 -0
- package/vendor/agent-plugin/skills/reference-loop/SKILL.md +102 -0
- package/vendor/agent-plugin/skills/sound-design/SKILL.md +60 -0
- package/vendor/agent-plugin/skills/style/SKILL.md +35 -0
- package/vendor/agent-plugin/skills/tsl-r185/SKILL.md +107 -0
- package/vendor/auth.cjs +570 -0
- package/vendor/build.cjs +953 -0
- package/vendor/catalog.json +455 -0
- package/vendor/connectors.cjs +688 -0
- package/vendor/eyes.mjs +733 -0
- package/vendor/gameExports.json +1390 -0
- package/vendor/git.cjs +222 -0
- package/vendor/models.json +57 -0
- package/vendor/publish.cjs +1018 -0
- package/vendor/refBoard.cjs +301 -0
- package/vendor/schema/dist/assets.d.ts +335 -0
- package/vendor/schema/dist/assets.js +439 -0
- package/vendor/schema/dist/brief.d.ts +357 -0
- package/vendor/schema/dist/brief.js +302 -0
- package/vendor/schema/dist/common.d.ts +9 -0
- package/vendor/schema/dist/common.js +13 -0
- package/vendor/schema/dist/config.d.ts +406 -0
- package/vendor/schema/dist/config.js +355 -0
- package/vendor/schema/dist/contract.d.ts +599 -0
- package/vendor/schema/dist/contract.js +1146 -0
- package/vendor/schema/dist/index.d.ts +14 -0
- package/vendor/schema/dist/index.js +21 -0
- package/vendor/schema/dist/look.d.ts +463 -0
- package/vendor/schema/dist/look.js +681 -0
- package/vendor/schema/dist/lookStats.d.ts +230 -0
- package/vendor/schema/dist/lookStats.js +768 -0
- package/vendor/schema/dist/pilot.d.ts +32 -0
- package/vendor/schema/dist/pilot.js +44 -0
- package/vendor/schema/dist/publish.d.ts +214 -0
- package/vendor/schema/dist/publish.js +291 -0
- package/vendor/schema/dist/scene.d.ts +75 -0
- package/vendor/schema/dist/scene.js +120 -0
- package/vendor/schema/dist/skyLight.d.ts +141 -0
- package/vendor/schema/dist/skyLight.js +436 -0
- package/vendor/schema/dist/style.d.ts +131 -0
- package/vendor/schema/dist/style.js +155 -0
- package/vendor/schema/package.json +1 -0
- package/vendor/selectionPrompt.mjs +51 -0
- package/vendor/useTools.mjs +195 -0
- package/vendor/userMessage.mjs +26 -0
- package/web-dist/assets/GaussianSplatUtils-CB77cP9U.js +1 -0
- package/web-dist/assets/KTX2Loader-6OIWUF7s.js +2 -0
- package/web-dist/assets/SPZLoader-zYj0Alfv.js +1 -0
- package/web-dist/assets/gaussianSplat-CJTI1sEh.js +1 -0
- package/web-dist/assets/index-CcjyyQco.css +1 -0
- package/web-dist/assets/index-DMyJcoZJ.js +693 -0
- package/web-dist/assets/meshopt_decoder.module-BvwdjiD3.js +1 -0
- package/web-dist/assets/zstddec.module-CfFeQW7d.js +1 -0
- package/web-dist/index.html +34 -0
|
@@ -0,0 +1,681 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
// The look: how a planet's picture is finished once the world is lit. Tone
|
|
3
|
+
// mapping, exposure, a grade, ambient occlusion, the sun's shadow, vignette and
|
|
4
|
+
// grain, all in game.config.json beside the sky and the fog, so a person can
|
|
5
|
+
// turn them by hand and every host reads the same numbers.
|
|
6
|
+
//
|
|
7
|
+
// There are no presets: every value of a look comes from the game's own
|
|
8
|
+
// brief (the request and its reference), so no two games start from the same
|
|
9
|
+
// stock mood. A config from before, whose look block names a preset, still
|
|
10
|
+
// parses (the key is dropped) and draws its own values.
|
|
11
|
+
//
|
|
12
|
+
// Every host draws it through one function (the SDK's createLook): the studio,
|
|
13
|
+
// the CLI's preview and the planet's player page. A look tuned in the studio is
|
|
14
|
+
// therefore the look a visitor sees. resolveLook below is the single place the
|
|
15
|
+
// defaults, the config and the device's tier are merged, so no host and no
|
|
16
|
+
// tool can disagree about what a config means.
|
|
17
|
+
//
|
|
18
|
+
// Only types come from config.ts: it imports LookSpec from here at run time,
|
|
19
|
+
// and a cycle the other way would leave one of them half made.
|
|
20
|
+
export const TONE_MAPPINGS = ['agx', 'neutral', 'aces', 'none'];
|
|
21
|
+
export const QUALITY_TIERS = ['low', 'medium', 'high'];
|
|
22
|
+
/** How edges are smoothed. traa: temporal (three's TRAANode), which also
|
|
23
|
+
* smooths what MSAA never reaches (a shader's own edges, alpha-tested
|
|
24
|
+
* leaves, the shadow's dither); smaa and fxaa: one frame, on the finished
|
|
25
|
+
* picture; msaa: four samples in the scene pass; none. */
|
|
26
|
+
export const AA_METHODS = ['traa', 'smaa', 'fxaa', 'msaa', 'none'];
|
|
27
|
+
const Gain = z.tuple([z.number().min(0).max(4), z.number().min(0).max(4), z.number().min(0).max(4)]);
|
|
28
|
+
const Lift = z.tuple([z.number().min(-0.5).max(0.5), z.number().min(-0.5).max(0.5), z.number().min(-0.5).max(0.5)]);
|
|
29
|
+
/** The grade, applied in scene-linear light before the tone curve (the LUT and
|
|
30
|
+
* posterize after it, on the display picture). Every field is optional and
|
|
31
|
+
* its absence is the identity. */
|
|
32
|
+
export const Grade = z.object({
|
|
33
|
+
/** White balance: -1 cold, +1 warm. */
|
|
34
|
+
temperature: z.number().min(-1).max(1).optional(),
|
|
35
|
+
/** -1 green, +1 magenta. */
|
|
36
|
+
tint: z.number().min(-1).max(1).optional(),
|
|
37
|
+
saturation: z.number().min(0).max(2).optional(),
|
|
38
|
+
/** Around middle grey (0.18, scene linear): above 1 the darks go darker and the lights lighter. */
|
|
39
|
+
contrast: z.number().min(0.5).max(1.5).optional(),
|
|
40
|
+
/** ASC CDL, per channel: out = (in * slope + offset) ^ power. */
|
|
41
|
+
cdl: z.object({ slope: Gain.optional(), offset: Lift.optional(), power: Gain.optional() }).optional(),
|
|
42
|
+
/** A 3D LUT (.cube under assets/) over the display picture; null takes one off. */
|
|
43
|
+
lut: z
|
|
44
|
+
.object({ asset: z.string().regex(/^assets\/[^/]+\.cube$/, 'must be a .cube file directly inside assets/'), intensity: z.number().min(0).max(1).optional() })
|
|
45
|
+
.nullable()
|
|
46
|
+
.optional(),
|
|
47
|
+
/** Steps per channel on the display picture; 0 is off. */
|
|
48
|
+
posterize: z.number().int().min(0).max(64).optional(),
|
|
49
|
+
});
|
|
50
|
+
const LookTier = z.object({
|
|
51
|
+
ao: z.boolean().optional(),
|
|
52
|
+
bloom: z.boolean().optional(),
|
|
53
|
+
grain: z.boolean().optional(),
|
|
54
|
+
/** The edge smoothing on this tier, in place of the one it would get. */
|
|
55
|
+
aa: z.enum(AA_METHODS).optional(),
|
|
56
|
+
/** true keeps the sun's cascades on this tier (low has none by default). */
|
|
57
|
+
cascades: z.boolean().optional(),
|
|
58
|
+
/** true keeps the reflections on this tier (only high has them by default). */
|
|
59
|
+
ssr: z.boolean().optional(),
|
|
60
|
+
/** Probe GI on this tier: true keeps it on low past a small grid (spaced
|
|
61
|
+
* wider to fit a phone's few probes), false leaves it off. */
|
|
62
|
+
gi: z.boolean().optional(),
|
|
63
|
+
});
|
|
64
|
+
const StyleHex = z.string().regex(/^#[0-9a-fA-F]{6}$/, 'must be a colour like #1a2b3c');
|
|
65
|
+
const Angle = z.number().min(-180).max(180);
|
|
66
|
+
/**
|
|
67
|
+
* How the picture is drawn, when the space's style is not a photograph: the
|
|
68
|
+
* marks a drawing makes, laid over the lit and graded picture. Each block is
|
|
69
|
+
* one technique and is off when absent; what it needs to mean anything is
|
|
70
|
+
* required, so no technique arrives with the engine's taste in it. Sizes in
|
|
71
|
+
* px are measured on a picture 1080 pixels high and scale with the real
|
|
72
|
+
* one, so a still at 2560 wide draws the same marks the viewport does.
|
|
73
|
+
*
|
|
74
|
+
* These are techniques, not styles: which of them a space uses, and with
|
|
75
|
+
* what numbers, comes from its own style.json (analysed from the creator's
|
|
76
|
+
* pictures, or the direction they chose), never from a list of looks.
|
|
77
|
+
*/
|
|
78
|
+
export const LookStyle = z.object({
|
|
79
|
+
/** Lines along silhouettes and creases, found in the depth and the normals. */
|
|
80
|
+
outline: z
|
|
81
|
+
.object({
|
|
82
|
+
/** Line width, px. */
|
|
83
|
+
width: z.number().min(0.5).max(8),
|
|
84
|
+
color: StyleHex,
|
|
85
|
+
/** How small a jump in depth draws a line: 0 only the largest, 1 the smallest. */
|
|
86
|
+
depth: z.number().min(0).max(1).optional(),
|
|
87
|
+
/** How small a bend in the surface draws a line: 0 none, 1 the gentlest. */
|
|
88
|
+
crease: z.number().min(0).max(1).optional(),
|
|
89
|
+
})
|
|
90
|
+
.nullable()
|
|
91
|
+
.optional(),
|
|
92
|
+
/** Shading in flat steps of brightness (cel shading), hue kept. */
|
|
93
|
+
bands: z
|
|
94
|
+
.object({
|
|
95
|
+
/** Steps from dark to light. */
|
|
96
|
+
count: z.number().int().min(2).max(8),
|
|
97
|
+
/** 0 a hard step, 1 a soft ramp between steps. */
|
|
98
|
+
softness: z.number().min(0).max(1).optional(),
|
|
99
|
+
})
|
|
100
|
+
.nullable()
|
|
101
|
+
.optional(),
|
|
102
|
+
/** Pen strokes that build the dark: one direction in the half-light, crossed in the shade. */
|
|
103
|
+
hatch: z
|
|
104
|
+
.object({
|
|
105
|
+
amount: z.number().min(0).max(1),
|
|
106
|
+
/** Distance between strokes, px. */
|
|
107
|
+
spacing: z.number().min(2).max(48),
|
|
108
|
+
color: StyleHex,
|
|
109
|
+
angle: Angle.optional(),
|
|
110
|
+
})
|
|
111
|
+
.nullable()
|
|
112
|
+
.optional(),
|
|
113
|
+
/** Printed dots that grow with the dark (comics, old print). */
|
|
114
|
+
halftone: z
|
|
115
|
+
.object({
|
|
116
|
+
amount: z.number().min(0).max(1),
|
|
117
|
+
/** Distance between dot centres, px. */
|
|
118
|
+
spacing: z.number().min(3).max(48),
|
|
119
|
+
color: StyleHex,
|
|
120
|
+
angle: Angle.optional(),
|
|
121
|
+
})
|
|
122
|
+
.nullable()
|
|
123
|
+
.optional(),
|
|
124
|
+
/** Paint: each pixel takes the calmest patch around it (Kuwahara), so
|
|
125
|
+
* surfaces turn to strokes and edges stay. */
|
|
126
|
+
paint: z.object({ radius: z.number().int().min(1).max(6) }).nullable().optional(),
|
|
127
|
+
/** The surface it is drawn on: its colour under the light, and its grain. */
|
|
128
|
+
paper: z
|
|
129
|
+
.object({
|
|
130
|
+
amount: z.number().min(0).max(1),
|
|
131
|
+
color: StyleHex,
|
|
132
|
+
/** Size of the grain, px. */
|
|
133
|
+
grain: z.number().min(0.5).max(16),
|
|
134
|
+
})
|
|
135
|
+
.nullable()
|
|
136
|
+
.optional(),
|
|
137
|
+
/** Big square pixels, px a side. */
|
|
138
|
+
pixel: z.object({ size: z.number().int().min(2).max(16) }).nullable().optional(),
|
|
139
|
+
});
|
|
140
|
+
/** Every field optional: resolveLook fills the rest, so a config stays short.
|
|
141
|
+
* A key it does not know (the old `preset`) is dropped by this lenient parse
|
|
142
|
+
* and refused by LookSpecStrict. */
|
|
143
|
+
export const LookSpec = z.object({
|
|
144
|
+
toneMapping: z.enum(TONE_MAPPINGS).optional(),
|
|
145
|
+
/** A multiplier on the light before the tone curve: 2 is one stop brighter. */
|
|
146
|
+
exposure: z.number().min(0.05).max(8).optional(),
|
|
147
|
+
grade: Grade.optional(),
|
|
148
|
+
/** Ambient occlusion: the dark where things meet. radius in metres. */
|
|
149
|
+
ao: z.object({ enabled: z.boolean().optional(), radius: z.number().min(0.05).max(4).optional(), strength: z.number().min(0).max(1).optional() }).optional(),
|
|
150
|
+
/** How edges are smoothed. Technical, not a look: absent is TRAA on a high
|
|
151
|
+
* and a medium device and FXAA on a low one (resolveLook). */
|
|
152
|
+
aa: z.enum(AA_METHODS).optional(),
|
|
153
|
+
/** The sun's shadow: quality is the most texels it gets (the device may give
|
|
154
|
+
* fewer), softness the width of its edge in metres. cascades splits it
|
|
155
|
+
* into that many maps along the view (0 is one map), each finer near the
|
|
156
|
+
* eye, so a wall 200 m away still takes the sun's shadow; distance is how
|
|
157
|
+
* far they reach, metres. Absent, both follow the map's size and the tier. */
|
|
158
|
+
shadows: z
|
|
159
|
+
.object({
|
|
160
|
+
quality: z.enum(QUALITY_TIERS).optional(),
|
|
161
|
+
softness: z.number().min(0).max(0.5).optional(),
|
|
162
|
+
cascades: z.number().int().min(0).max(4).optional(),
|
|
163
|
+
distance: z.number().min(10).max(10000).optional(),
|
|
164
|
+
})
|
|
165
|
+
.optional(),
|
|
166
|
+
/** Screen-space reflections, on the high tier: what a polished or wet
|
|
167
|
+
* surface shows of the world around it, where the sky map alone shows
|
|
168
|
+
* only the sky. distance is how far a reflection reaches and thickness how
|
|
169
|
+
* deep a thing seen in it is taken to be, both metres; intensity scales
|
|
170
|
+
* the reflection (1 is as the surface's own reflectance has it). */
|
|
171
|
+
ssr: z
|
|
172
|
+
.object({
|
|
173
|
+
enabled: z.boolean().optional(),
|
|
174
|
+
distance: z.number().min(0.5).max(500).optional(),
|
|
175
|
+
thickness: z.number().min(0.01).max(5).optional(),
|
|
176
|
+
intensity: z.number().min(0).max(1).optional(),
|
|
177
|
+
})
|
|
178
|
+
.optional(),
|
|
179
|
+
/** Indirect light. probes: a grid of light probes baked when the planet
|
|
180
|
+
* loads (three's LightProbeGrid), spacing metres apart, over the box
|
|
181
|
+
* (centre and size, metres) or, without one, over what stands on the map.
|
|
182
|
+
* The probes see the sky and what the sun lights, so shade takes the
|
|
183
|
+
* colour of what is round it (a white floor by a red wall goes pink) and
|
|
184
|
+
* a room is darker than the open; they then give the sky's diffuse light
|
|
185
|
+
* in place of the sky map. intensity scales what they give (1 is as
|
|
186
|
+
* baked). Low bakes them only for a small grid (tiers.low.gi). */
|
|
187
|
+
gi: z
|
|
188
|
+
.object({
|
|
189
|
+
kind: z.literal('probes'),
|
|
190
|
+
spacing: z.number().min(0.5).max(50).optional(),
|
|
191
|
+
intensity: z.number().min(0).max(4).optional(),
|
|
192
|
+
box: z
|
|
193
|
+
.object({
|
|
194
|
+
center: z.tuple([z.number(), z.number(), z.number()]),
|
|
195
|
+
size: z.tuple([z.number().min(0.5).max(10000), z.number().min(0.5).max(10000), z.number().min(0.5).max(10000)]),
|
|
196
|
+
})
|
|
197
|
+
.optional(),
|
|
198
|
+
})
|
|
199
|
+
.optional(),
|
|
200
|
+
vignette: z.object({ amount: z.number().min(0).max(1).optional(), smoothness: z.number().min(0.05).max(1).optional() }).optional(),
|
|
201
|
+
/** Film grain, as a share of full brightness; 0 is off. */
|
|
202
|
+
grain: z.number().min(0).max(0.3).optional(),
|
|
203
|
+
/** How strongly the sky lights the world through what it reflects. Absent:
|
|
204
|
+
* 1 under an HDRI or a physical sky, whose light is measured (the picture's
|
|
205
|
+
* own strength), and 0.4 under the painted kinds, whose dome is made of
|
|
206
|
+
* display colours over the game's own fill. */
|
|
207
|
+
environment: z.object({ intensity: z.number().min(0).max(4).optional() }).optional(),
|
|
208
|
+
/** How the picture is drawn when it is not a photograph (LookStyle). */
|
|
209
|
+
style: LookStyle.optional(),
|
|
210
|
+
/** What a lesser device keeps: low drops AO and grain unless these say true;
|
|
211
|
+
* either may drop bloom with false, and choose its own edge smoothing,
|
|
212
|
+
* cascades and reflections. */
|
|
213
|
+
tiers: z.object({ low: LookTier.optional(), medium: LookTier.optional() }).optional(),
|
|
214
|
+
});
|
|
215
|
+
/** The same schema, rebuilt with every object refusing keys it does not know. */
|
|
216
|
+
function strictly(schema) {
|
|
217
|
+
if (schema instanceof z.ZodOptional)
|
|
218
|
+
return strictly(schema.unwrap()).optional();
|
|
219
|
+
if (schema instanceof z.ZodNullable)
|
|
220
|
+
return strictly(schema.unwrap()).nullable();
|
|
221
|
+
if (schema instanceof z.ZodObject) {
|
|
222
|
+
const shape = {};
|
|
223
|
+
for (const [key, value] of Object.entries(schema.shape))
|
|
224
|
+
shape[key] = strictly(value);
|
|
225
|
+
return z.strictObject(shape);
|
|
226
|
+
}
|
|
227
|
+
return schema;
|
|
228
|
+
}
|
|
229
|
+
/** The same, refusing unknown keys at every depth: what look_apply validates with, so a typo is a finding
|
|
230
|
+
* rather than silently ignored. The config itself stays lenient so an older studio can open a newer project. */
|
|
231
|
+
export const LookSpecStrict = strictly(LookSpec);
|
|
232
|
+
/** No technique: the picture as lit and graded. */
|
|
233
|
+
export const NO_STYLE = Object.freeze({ outline: null, bands: null, hatch: null, halftone: null, paint: null, paper: null, pixel: null });
|
|
234
|
+
/** Whether a look draws with any technique of LookStyle. */
|
|
235
|
+
export const hasStyle = (style) => !!style && Object.values(style).some((t) => t !== null);
|
|
236
|
+
/** A map's side in metres: config.ts's mapSide (UNITS_PER_TILE 100 a tile),
|
|
237
|
+
* which this file cannot import at run time (see above). */
|
|
238
|
+
const sideOf = (tiles) => 100 * Math.sqrt(tiles);
|
|
239
|
+
/** The size a world with no `tiles` is taken to be where something needs a
|
|
240
|
+
* number (how far the sun's shadows reach, how far a camera stands back). It
|
|
241
|
+
* is not an edge: such a world has none. */
|
|
242
|
+
export const OPEN_WORLD_SIDE = 400;
|
|
243
|
+
/** What every tier but low may draw, at most, in the sun's cascades. */
|
|
244
|
+
const CASCADES = { low: 0, medium: 3, high: 4 };
|
|
245
|
+
/** The fewest texels a side the SDK sun's one map gets where the device
|
|
246
|
+
* allows it: below this a wide penumbra still hides the texels, but a
|
|
247
|
+
* surface the sun grazes starts to shadow itself in bands. */
|
|
248
|
+
const SUN_MAP_MIN = 2048;
|
|
249
|
+
/** The square a single map follows the player over, past SHADOW_WHOLE_MAP:
|
|
250
|
+
* half its side, metres (world.ts). */
|
|
251
|
+
export const SHADOW_FOLLOW = 40;
|
|
252
|
+
/** Probe GI on each tier: the most probes, the bounces after the first
|
|
253
|
+
* pass, and each probe's cube. */
|
|
254
|
+
const GI_TIERS = {
|
|
255
|
+
high: { maxProbes: 2048, bounces: 1, cubeSize: 32 },
|
|
256
|
+
medium: { maxProbes: 1024, bounces: 1, cubeSize: 32 },
|
|
257
|
+
low: { maxProbes: 256, bounces: 0, cubeSize: 16 },
|
|
258
|
+
};
|
|
259
|
+
/** A low device that keeps its cascades (tiers.low.cascades) gets this many at most. */
|
|
260
|
+
const LOW_CASCADES = 2;
|
|
261
|
+
/** The largest half-side of planet one shadow map covers whole (world.ts
|
|
262
|
+
* fits it to the map up to here and makes it follow the player past it).
|
|
263
|
+
* Past it the cascades are on by default. */
|
|
264
|
+
export const SHADOW_WHOLE_MAP = 60;
|
|
265
|
+
/** A phone's drawing buffer, about 1.5 million pixels: sharper than one
|
|
266
|
+
* pixel per CSS pixel (0.33 MP on a 390 x 844 phone) and well short of
|
|
267
|
+
* its panel (3 MP at a pixel ratio of 3). */
|
|
268
|
+
export const PHONE_PIXEL_BUDGET = 1_500_000;
|
|
269
|
+
/** The light a measured sky gives (an HDRI, a physical sky): its own strength. */
|
|
270
|
+
const OWN_LIGHT = 1;
|
|
271
|
+
/** Reflections' reach and depth when the brief gives only that it has them. */
|
|
272
|
+
const SSR_DISTANCE = 30;
|
|
273
|
+
const SSR_THICKNESS = 0.25;
|
|
274
|
+
/** Probes this far apart when the brief asks for them without a spacing. */
|
|
275
|
+
const GI_SPACING = 4;
|
|
276
|
+
/** The most hemisphere fill lookAdvice lets pass under a measured sky. */
|
|
277
|
+
const FILL_UNDER_SKY = 0.1;
|
|
278
|
+
/** The look a config with a look block starts from. */
|
|
279
|
+
export const LOOK_DEFAULTS = Object.freeze({
|
|
280
|
+
toneMapping: 'agx',
|
|
281
|
+
exposure: 1,
|
|
282
|
+
grade: {
|
|
283
|
+
temperature: 0,
|
|
284
|
+
tint: 0,
|
|
285
|
+
saturation: 1,
|
|
286
|
+
contrast: 1,
|
|
287
|
+
cdl: { slope: [1, 1, 1], offset: [0, 0, 0], power: [1, 1, 1] },
|
|
288
|
+
lut: null,
|
|
289
|
+
posterize: 0,
|
|
290
|
+
},
|
|
291
|
+
// What the studio has always drawn: GTAO 0.6 m at 0.85, the sky lighting at
|
|
292
|
+
// 0.4 over the game's own fill, a 4096 shadow map with a 7 cm penumbra.
|
|
293
|
+
ao: { enabled: true, radius: 0.6, strength: 0.85 },
|
|
294
|
+
// Cascades, their reach and the sun's own map sizes follow the map's
|
|
295
|
+
// size: resolveLook fills them.
|
|
296
|
+
shadows: { mapSize: 4096, sunMapSize: 4096, cascadeMapSize: 2048, softness: 0.07, cascades: 0, distance: 0 },
|
|
297
|
+
vignette: { amount: 0, smoothness: 0.5 },
|
|
298
|
+
grain: 0,
|
|
299
|
+
environment: { intensity: 0.4 },
|
|
300
|
+
aa: 'traa',
|
|
301
|
+
ssr: null,
|
|
302
|
+
gi: null,
|
|
303
|
+
pixelRatioMax: 2,
|
|
304
|
+
pixelBudget: null,
|
|
305
|
+
msaa: 0,
|
|
306
|
+
style: NO_STYLE,
|
|
307
|
+
});
|
|
308
|
+
/** LOOK_DEFAULTS with toneMapping 'neutral': what the studio drew before
|
|
309
|
+
* there was a look block, so a config without one looks as it always did. */
|
|
310
|
+
export const LEGACY_LOOK = Object.freeze({ ...LOOK_DEFAULTS, toneMapping: 'neutral' });
|
|
311
|
+
const SHADOW_SIZES = { low: 1024, medium: 2048, high: 4096 };
|
|
312
|
+
/** fog.heightDensity when a height fog gives none. The ground fog's factor is
|
|
313
|
+
* 1 - exp(-(heightDensity x metres below fog.height x distance)^2): depth
|
|
314
|
+
* and distance multiply, so for ground 2.3 m under the top, at 5, 10, 20,
|
|
315
|
+
* 40 and 80 m, 0.005 gives 0.00, 0.01, 0.05, 0.19, 0.57; 0.01 gives 0.01,
|
|
316
|
+
* 0.05, 0.19, 0.57, 0.97; 0.08 gives 0.57 at 5 m and 0.97 by 10 m. */
|
|
317
|
+
export const FOG_HEIGHT_DENSITY = 0.01;
|
|
318
|
+
/** Above this a height fog turns everything under its top to fog colour
|
|
319
|
+
* within a few metres; look_apply says so. */
|
|
320
|
+
export const FOG_HEIGHT_DENSITY_THICK = 0.04;
|
|
321
|
+
// ---- reading what may be anything ----
|
|
322
|
+
//
|
|
323
|
+
// resolveLook runs on configs no schema has seen in this process: the world's
|
|
324
|
+
// player page reads one published by whatever verifier was deployed then, and
|
|
325
|
+
// a hand-edited file reaches the studio before it validates. So every field
|
|
326
|
+
// is read for what it is, with its default when it is not.
|
|
327
|
+
const isObj = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
328
|
+
const num = (v, fallback, lo = -Infinity, hi = Infinity) => typeof v === 'number' && Number.isFinite(v) ? Math.min(hi, Math.max(lo, v)) : fallback;
|
|
329
|
+
const bool = (v, fallback) => (typeof v === 'boolean' ? v : fallback);
|
|
330
|
+
const triple = (v, fallback, lo, hi) => Array.isArray(v) && v.length === 3 && v.every((x) => typeof x === 'number' && Number.isFinite(x))
|
|
331
|
+
? [num(v[0], 0, lo, hi), num(v[1], 0, lo, hi), num(v[2], 0, lo, hi)]
|
|
332
|
+
: fallback;
|
|
333
|
+
const HEX = /^#[0-9a-fA-F]{6}$/;
|
|
334
|
+
const hex = (v, fallback) => (typeof v === 'string' && HEX.test(v) ? v : fallback);
|
|
335
|
+
const oneOf = (v, list, fallback) => typeof v === 'string' && list.includes(v) ? v : fallback;
|
|
336
|
+
const copyBase = (b) => ({
|
|
337
|
+
toneMapping: b.toneMapping,
|
|
338
|
+
exposure: b.exposure,
|
|
339
|
+
grade: {
|
|
340
|
+
...b.grade,
|
|
341
|
+
cdl: { slope: [...b.grade.cdl.slope], offset: [...b.grade.cdl.offset], power: [...b.grade.cdl.power] },
|
|
342
|
+
lut: b.grade.lut ? { ...b.grade.lut } : null,
|
|
343
|
+
},
|
|
344
|
+
ao: { ...b.ao },
|
|
345
|
+
shadows: { ...b.shadows },
|
|
346
|
+
vignette: { ...b.vignette },
|
|
347
|
+
grain: b.grain,
|
|
348
|
+
environment: { ...b.environment },
|
|
349
|
+
aa: b.aa,
|
|
350
|
+
ssr: b.ssr ? { ...b.ssr } : null,
|
|
351
|
+
gi: b.gi ? { ...b.gi, box: b.gi.box ? { center: [...b.gi.box.center], size: [...b.gi.box.size] } : null } : null,
|
|
352
|
+
pixelRatioMax: b.pixelRatioMax,
|
|
353
|
+
pixelBudget: b.pixelBudget,
|
|
354
|
+
msaa: b.msaa,
|
|
355
|
+
style: {
|
|
356
|
+
outline: b.style.outline ? { ...b.style.outline } : null,
|
|
357
|
+
bands: b.style.bands ? { ...b.style.bands } : null,
|
|
358
|
+
hatch: b.style.hatch ? { ...b.style.hatch } : null,
|
|
359
|
+
halftone: b.style.halftone ? { ...b.style.halftone } : null,
|
|
360
|
+
paint: b.style.paint ? { ...b.style.paint } : null,
|
|
361
|
+
paper: b.style.paper ? { ...b.style.paper } : null,
|
|
362
|
+
pixel: b.style.pixel ? { ...b.style.pixel } : null,
|
|
363
|
+
},
|
|
364
|
+
});
|
|
365
|
+
/** Lays the fields a look block sets over `into`, leaving the rest. */
|
|
366
|
+
function layer(into, spec) {
|
|
367
|
+
if (!isObj(spec))
|
|
368
|
+
return;
|
|
369
|
+
into.toneMapping = oneOf(spec.toneMapping, TONE_MAPPINGS, into.toneMapping);
|
|
370
|
+
into.exposure = num(spec.exposure, into.exposure, 0.05, 8);
|
|
371
|
+
const g = spec.grade;
|
|
372
|
+
if (isObj(g)) {
|
|
373
|
+
const grade = into.grade;
|
|
374
|
+
grade.temperature = num(g.temperature, grade.temperature, -1, 1);
|
|
375
|
+
grade.tint = num(g.tint, grade.tint, -1, 1);
|
|
376
|
+
grade.saturation = num(g.saturation, grade.saturation, 0, 2);
|
|
377
|
+
grade.contrast = num(g.contrast, grade.contrast, 0.5, 1.5);
|
|
378
|
+
if (isObj(g.cdl)) {
|
|
379
|
+
grade.cdl.slope = triple(g.cdl.slope, grade.cdl.slope, 0, 4);
|
|
380
|
+
grade.cdl.offset = triple(g.cdl.offset, grade.cdl.offset, -0.5, 0.5);
|
|
381
|
+
grade.cdl.power = triple(g.cdl.power, grade.cdl.power, 0, 4);
|
|
382
|
+
}
|
|
383
|
+
if (g.lut === null)
|
|
384
|
+
grade.lut = null;
|
|
385
|
+
else if (isObj(g.lut) && typeof g.lut.asset === 'string' && /^assets\/[^/]+\.cube$/.test(g.lut.asset)) {
|
|
386
|
+
grade.lut = { asset: g.lut.asset, intensity: num(g.lut.intensity, 1, 0, 1) };
|
|
387
|
+
}
|
|
388
|
+
if (typeof g.posterize === 'number')
|
|
389
|
+
grade.posterize = Math.round(num(g.posterize, grade.posterize, 0, 64));
|
|
390
|
+
}
|
|
391
|
+
if (isObj(spec.ao)) {
|
|
392
|
+
into.ao.enabled = bool(spec.ao.enabled, into.ao.enabled);
|
|
393
|
+
into.ao.radius = num(spec.ao.radius, into.ao.radius, 0.05, 4);
|
|
394
|
+
into.ao.strength = num(spec.ao.strength, into.ao.strength, 0, 1);
|
|
395
|
+
}
|
|
396
|
+
if (isObj(spec.shadows)) {
|
|
397
|
+
if (typeof spec.shadows.quality === 'string')
|
|
398
|
+
into.shadows.mapSize = SHADOW_SIZES[oneOf(spec.shadows.quality, QUALITY_TIERS, 'high')];
|
|
399
|
+
into.shadows.softness = num(spec.shadows.softness, into.shadows.softness, 0, 0.5);
|
|
400
|
+
}
|
|
401
|
+
into.aa = oneOf(spec.aa, AA_METHODS, into.aa);
|
|
402
|
+
if (isObj(spec.ssr) && spec.ssr.enabled !== false) {
|
|
403
|
+
into.ssr = {
|
|
404
|
+
distance: num(spec.ssr.distance, SSR_DISTANCE, 0.5, 500),
|
|
405
|
+
thickness: num(spec.ssr.thickness, SSR_THICKNESS, 0.01, 5),
|
|
406
|
+
intensity: num(spec.ssr.intensity, 1, 0, 1),
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
if (isObj(spec.gi) && spec.gi.kind === 'probes') {
|
|
410
|
+
const box = isObj(spec.gi.box) ? spec.gi.box : null;
|
|
411
|
+
into.gi = {
|
|
412
|
+
kind: 'probes',
|
|
413
|
+
spacing: num(spec.gi.spacing, GI_SPACING, 0.5, 50),
|
|
414
|
+
intensity: num(spec.gi.intensity, 1, 0, 4),
|
|
415
|
+
box: box ? { center: triple(box.center, [0, 0, 0], -1e5, 1e5), size: triple(box.size, [1, 1, 1], 0.5, 10000) } : null,
|
|
416
|
+
...GI_TIERS.high,
|
|
417
|
+
fit: 'space',
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
if (isObj(spec.vignette)) {
|
|
421
|
+
into.vignette.amount = num(spec.vignette.amount, into.vignette.amount, 0, 1);
|
|
422
|
+
into.vignette.smoothness = num(spec.vignette.smoothness, into.vignette.smoothness, 0.05, 1);
|
|
423
|
+
}
|
|
424
|
+
into.grain = num(spec.grain, into.grain, 0, 0.3);
|
|
425
|
+
if (isObj(spec.environment))
|
|
426
|
+
into.environment.intensity = num(spec.environment.intensity, into.environment.intensity, 0, 4);
|
|
427
|
+
if (isObj(spec.style))
|
|
428
|
+
layerStyle(into.style, spec.style);
|
|
429
|
+
}
|
|
430
|
+
const isNum = (v) => typeof v === 'number' && Number.isFinite(v);
|
|
431
|
+
const isHex = (v) => typeof v === 'string' && HEX.test(v);
|
|
432
|
+
/** A technique is on only when what it needs is there (LookStyle's required
|
|
433
|
+
* fields): a block missing its colour or its size is off, not filled in. */
|
|
434
|
+
function layerStyle(into, spec) {
|
|
435
|
+
const o = spec.outline;
|
|
436
|
+
if (o === null)
|
|
437
|
+
into.outline = null;
|
|
438
|
+
else if (isObj(o) && isNum(o.width) && isHex(o.color)) {
|
|
439
|
+
into.outline = { width: num(o.width, 1, 0.5, 8), color: o.color, depth: num(o.depth, 0.5, 0, 1), crease: num(o.crease, 0.5, 0, 1) };
|
|
440
|
+
}
|
|
441
|
+
const b = spec.bands;
|
|
442
|
+
if (b === null)
|
|
443
|
+
into.bands = null;
|
|
444
|
+
else if (isObj(b) && isNum(b.count))
|
|
445
|
+
into.bands = { count: Math.round(num(b.count, 3, 2, 8)), softness: num(b.softness, 0.1, 0, 1) };
|
|
446
|
+
for (const key of ['hatch', 'halftone']) {
|
|
447
|
+
const t = spec[key];
|
|
448
|
+
if (t === null)
|
|
449
|
+
into[key] = null;
|
|
450
|
+
else if (isObj(t) && isNum(t.amount) && isNum(t.spacing) && isHex(t.color)) {
|
|
451
|
+
into[key] = { amount: num(t.amount, 0, 0, 1), spacing: num(t.spacing, 8, key === 'hatch' ? 2 : 3, 48), color: t.color, angle: num(t.angle, 45, -180, 180) };
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
const paint = spec.paint;
|
|
455
|
+
if (paint === null)
|
|
456
|
+
into.paint = null;
|
|
457
|
+
else if (isObj(paint) && isNum(paint.radius))
|
|
458
|
+
into.paint = { radius: Math.round(num(paint.radius, 2, 1, 6)) };
|
|
459
|
+
const paper = spec.paper;
|
|
460
|
+
if (paper === null)
|
|
461
|
+
into.paper = null;
|
|
462
|
+
else if (isObj(paper) && isNum(paper.amount) && isHex(paper.color) && isNum(paper.grain)) {
|
|
463
|
+
into.paper = { amount: num(paper.amount, 0, 0, 1), color: paper.color, grain: num(paper.grain, 2, 0.5, 16) };
|
|
464
|
+
}
|
|
465
|
+
const pixel = spec.pixel;
|
|
466
|
+
if (pixel === null)
|
|
467
|
+
into.pixel = null;
|
|
468
|
+
else if (isObj(pixel) && isNum(pixel.size))
|
|
469
|
+
into.pixel = { size: Math.round(num(pixel.size, 4, 2, 16)) };
|
|
470
|
+
}
|
|
471
|
+
const tierFlags = (spec, tier) => {
|
|
472
|
+
const tiers = isObj(spec) ? spec.tiers : undefined;
|
|
473
|
+
const flags = isObj(tiers) ? tiers[tier] : undefined;
|
|
474
|
+
return isObj(flags) ? flags : {};
|
|
475
|
+
};
|
|
476
|
+
/**
|
|
477
|
+
* The look a config asks for, on a device of `tier` (default high: the studio
|
|
478
|
+
* and the CLI always draw high). In order, each over the last: LOOK_DEFAULTS
|
|
479
|
+
* (LEGACY_LOOK when the config has no look block), the config's look fields,
|
|
480
|
+
* then the tier, which only ever takes things away: low draws without AO and
|
|
481
|
+
* grain (unless look.tiers.low gives them back), FXAA where TRAA or MSAA was
|
|
482
|
+
* asked, no cascades and no reflections, a 1024 shadow map and a phone's
|
|
483
|
+
* pixel budget; medium a 2048 map, 1.5 pixels, three cascades at most and no
|
|
484
|
+
* reflections. Either tier's flags may also drop bloom, and choose their own
|
|
485
|
+
* edge smoothing, cascades and reflections. Bloom and fog are config.bloom
|
|
486
|
+
* and config.fog, filled in.
|
|
487
|
+
*
|
|
488
|
+
* Two defaults follow the config rather than a constant. The sun's cascades
|
|
489
|
+
* are on where one map cannot hold the planet (a half-side past
|
|
490
|
+
* SHADOW_WHOLE_MAP), reaching the map's diagonal. The sky lights at its own
|
|
491
|
+
* strength (1) when it is measured light, an HDRI or a physical sky: 0.4
|
|
492
|
+
* there dimmed a photographed sky to 40% of what it was shot at.
|
|
493
|
+
*/
|
|
494
|
+
export function resolveLook(config, tier = 'high') {
|
|
495
|
+
const cfg = isObj(config) ? config : {};
|
|
496
|
+
const spec = isObj(cfg.look) ? cfg.look : null;
|
|
497
|
+
const base = copyBase(spec ? LOOK_DEFAULTS : LEGACY_LOOK);
|
|
498
|
+
layer(base, spec);
|
|
499
|
+
const b = isObj(cfg.bloom) ? cfg.bloom : {};
|
|
500
|
+
const bloom = {
|
|
501
|
+
enabled: bool(b.enabled, true),
|
|
502
|
+
strength: num(b.strength, 0.9, 0, 3),
|
|
503
|
+
radius: num(b.radius, 0.4, 0, 1),
|
|
504
|
+
threshold: num(b.threshold, 0, 0, 2),
|
|
505
|
+
};
|
|
506
|
+
let fog = null;
|
|
507
|
+
if (isObj(cfg.fog)) {
|
|
508
|
+
const f = cfg.fog;
|
|
509
|
+
const far = num(f.far, 100, 1e-3);
|
|
510
|
+
fog = {
|
|
511
|
+
mode: oneOf(f.mode, ['range', 'exp2', 'height'], 'range'),
|
|
512
|
+
color: hex(f.color, '#ffffff'),
|
|
513
|
+
near: num(f.near, 0, 0),
|
|
514
|
+
far,
|
|
515
|
+
density: num(f.density, 1.978 / far, 0, 1),
|
|
516
|
+
height: num(f.height, 0),
|
|
517
|
+
heightDensity: num(f.heightDensity, FOG_HEIGHT_DENSITY, 0, 1),
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
// The sky's own light, unless the look says how strong it is.
|
|
521
|
+
const skyKind = isObj(cfg.sky) ? cfg.sky.kind : undefined;
|
|
522
|
+
const envSet = isObj(spec) && isObj(spec.environment) && typeof spec.environment.intensity === 'number';
|
|
523
|
+
if (!envSet && (skyKind === 'hdri' || skyKind === 'physical'))
|
|
524
|
+
base.environment.intensity = OWN_LIGHT;
|
|
525
|
+
// The sun's cascades: the look's count and reach, or as many as the tier
|
|
526
|
+
// draws wherever one map cannot hold the planet, reaching its far corner.
|
|
527
|
+
const side = cfg.tiles === undefined || cfg.tiles === null ? OPEN_WORLD_SIDE : sideOf(num(cfg.tiles, 1, 1));
|
|
528
|
+
const shadowSpec = isObj(spec) && isObj(spec.shadows) ? spec.shadows : {};
|
|
529
|
+
const asked = typeof shadowSpec.cascades === 'number' ? Math.round(num(shadowSpec.cascades, 0, 0, 4)) : side / 2 > SHADOW_WHOLE_MAP ? CASCADES.high : 0;
|
|
530
|
+
base.shadows.cascades = asked;
|
|
531
|
+
base.shadows.distance = num(shadowSpec.distance, Math.min(10000, Math.max(10, side * Math.SQRT2)), 10, 10000);
|
|
532
|
+
const t = oneOf(tier, QUALITY_TIERS, 'high');
|
|
533
|
+
if (t !== 'high') {
|
|
534
|
+
const flags = tierFlags(spec, t);
|
|
535
|
+
const keep = (flag, byDefault) => flag ?? byDefault;
|
|
536
|
+
base.ao.enabled = base.ao.enabled && keep(flags.ao, t !== 'low');
|
|
537
|
+
if (!keep(flags.grain, t !== 'low'))
|
|
538
|
+
base.grain = 0;
|
|
539
|
+
bloom.enabled = bloom.enabled && keep(flags.bloom, true);
|
|
540
|
+
base.shadows.mapSize = Math.min(base.shadows.mapSize, SHADOW_SIZES[t]);
|
|
541
|
+
// A phone: FXAA where the look asked for what a phone cannot carry (TRAA's
|
|
542
|
+
// history and velocity targets, MSAA's four samples).
|
|
543
|
+
const stepped = t === 'low' && (base.aa === 'traa' || base.aa === 'msaa') ? 'fxaa' : base.aa;
|
|
544
|
+
base.aa = oneOf(flags.aa, AA_METHODS, stepped);
|
|
545
|
+
base.shadows.cascades = Math.min(base.shadows.cascades, t === 'low' ? (flags.cascades === true ? LOW_CASCADES : 0) : flags.cascades === false ? 0 : CASCADES[t]);
|
|
546
|
+
if (!keep(flags.ssr, false))
|
|
547
|
+
base.ssr = null;
|
|
548
|
+
base.pixelRatioMax = t === 'low' ? 2 : 1.5;
|
|
549
|
+
base.pixelBudget = t === 'low' ? PHONE_PIXEL_BUDGET : null;
|
|
550
|
+
// Probe GI: medium bakes fewer probes; a phone only a small grid (a
|
|
551
|
+
// room at the brief's spacing) unless the look keeps it there, and then
|
|
552
|
+
// spaced to fit its few. false on either tier leaves it off.
|
|
553
|
+
if (base.gi)
|
|
554
|
+
base.gi = flags.gi === false ? null : { ...base.gi, ...GI_TIERS[t], fit: t === 'low' && flags.gi !== true ? 'skip' : 'space' };
|
|
555
|
+
}
|
|
556
|
+
base.msaa = base.aa === 'msaa' ? 4 : 0;
|
|
557
|
+
const sizes = shadowMapSizes({ half: side / 2, softness: base.shadows.softness, cap: base.shadows.mapSize });
|
|
558
|
+
base.shadows.sunMapSize = sizes.sun;
|
|
559
|
+
base.shadows.cascadeMapSize = sizes.cascade;
|
|
560
|
+
return { legacy: spec === null, preset: null, tier: t, ...base, bloom, fog };
|
|
561
|
+
}
|
|
562
|
+
const pow2Above = (x) => Math.pow(2, Math.ceil(Math.log2(Math.max(1, x))));
|
|
563
|
+
/**
|
|
564
|
+
* The SDK sun's map sizes, texels a side, within the device's cap.
|
|
565
|
+
*
|
|
566
|
+
* sun one map over what it covers (the whole map up to
|
|
567
|
+
* SHADOW_WHOLE_MAP, the square that follows the player past
|
|
568
|
+
* it): as fine as its penumbra can show and no finer, at least
|
|
569
|
+
* SUN_MAP_MIN. Texels finer than half the penumbra are blurred
|
|
570
|
+
* away by the soft filter (light.ts spreads its taps over the
|
|
571
|
+
* penumbra's width), so they cost GPU memory (5 bytes a texel:
|
|
572
|
+
* depth and the lean colour target) and show nothing. A 7 cm
|
|
573
|
+
* penumbra keeps the cap on a one-tile map; a 35 cm one there
|
|
574
|
+
* would need 1024 and gets SUN_MAP_MIN.
|
|
575
|
+
* cascade half the cap, so four cascades cost what one full map does.
|
|
576
|
+
* Not sized by the penumbra: only the nearest cascade's texels
|
|
577
|
+
* are finer than a penumbra, the far ones' are already coarser
|
|
578
|
+
* (a 300 m cascade's 2048 texels are 15 cm), and halving them
|
|
579
|
+
* moved the shadows inside laputa-v2's window arches at its
|
|
580
|
+
* hero view, 216 m out.
|
|
581
|
+
*/
|
|
582
|
+
export function shadowMapSizes(o) {
|
|
583
|
+
const texel = Math.max(o.softness, 0.005) / 2;
|
|
584
|
+
const covered = o.half > SHADOW_WHOLE_MAP ? SHADOW_FOLLOW : o.half + 1;
|
|
585
|
+
const sun = Math.min(o.cap, Math.max(Math.min(SUN_MAP_MIN, o.cap), pow2Above((covered * 2 * Math.SQRT2) / texel)));
|
|
586
|
+
return { sun, cascade: Math.max(256, o.cap / 2) };
|
|
587
|
+
}
|
|
588
|
+
/** The parts of a resolved look that change the shader graph (tone mapping, ao on, bloom on, lut on,
|
|
589
|
+
* posterize on, vignette on, grain on, msaa, fog mode). Equal keys: only uniforms changed. */
|
|
590
|
+
export function lookStructureKey(look) {
|
|
591
|
+
return [
|
|
592
|
+
look.toneMapping,
|
|
593
|
+
`ao:${look.ao.enabled ? 1 : 0}`,
|
|
594
|
+
`bloom:${look.bloom.enabled ? 1 : 0}`,
|
|
595
|
+
`lut:${look.grade.lut ? 1 : 0}`,
|
|
596
|
+
`posterize:${look.grade.posterize > 0 ? 1 : 0}`,
|
|
597
|
+
`vignette:${look.vignette.amount > 0 ? 1 : 0}`,
|
|
598
|
+
`grain:${look.grain > 0 ? 1 : 0}`,
|
|
599
|
+
`msaa:${look.msaa}`,
|
|
600
|
+
`aa:${look.aa}`,
|
|
601
|
+
`ssr:${look.ssr ? 1 : 0}`,
|
|
602
|
+
`fog:${look.fog ? look.fog.mode : 'none'}`,
|
|
603
|
+
`style:${Object.entries(look.style ?? NO_STYLE)
|
|
604
|
+
.filter(([, t]) => t !== null)
|
|
605
|
+
.map(([k]) => k)
|
|
606
|
+
.join('+')}`,
|
|
607
|
+
].join('|');
|
|
608
|
+
}
|
|
609
|
+
export * from './lookStats.js';
|
|
610
|
+
export * from './skyLight.js';
|
|
611
|
+
// ---------------------------------------------------------------------------
|
|
612
|
+
// what a config leaves to the engine
|
|
613
|
+
// ---------------------------------------------------------------------------
|
|
614
|
+
const hasKey = (o, key) => isObj(o) && o[key] !== undefined;
|
|
615
|
+
/**
|
|
616
|
+
* The look values a config leaves to the engine's own numbers, and a sky of
|
|
617
|
+
* kind none, as sentences for nw_check: each one is a value every space that
|
|
618
|
+
* leaves it out shares, so it reads as a stock look rather than as this
|
|
619
|
+
* space's. Read from the raw document, before the schema fills its defaults.
|
|
620
|
+
* Technical values (edge smoothing, cascades, tiers) are never named: their
|
|
621
|
+
* defaults are not a look. Identity values (a grade, vignette and grain
|
|
622
|
+
* left out are none of them) are not named either.
|
|
623
|
+
*/
|
|
624
|
+
export function lookAdvice(raw) {
|
|
625
|
+
const cfg = isObj(raw) ? raw : {};
|
|
626
|
+
const out = [];
|
|
627
|
+
const sky = isObj(cfg.sky) ? cfg.sky : null;
|
|
628
|
+
if (!sky || sky.kind === 'none') {
|
|
629
|
+
out.push("sky is none: the planet is drawn on the host's plain backdrop (white on a planet), with no horizon and a stock daylight dome lighting it. Set sky from the brief: an HDRI of the reference's sky (asset_search), a physical sky with the reference's sun, or its gradient or colour.");
|
|
630
|
+
}
|
|
631
|
+
const look = isObj(cfg.look) ? cfg.look : null;
|
|
632
|
+
if (!look) {
|
|
633
|
+
out.push("game.config.json has no look block, so the planet is drawn with the studio's look from before (Neutral, AO 0.6 m at 0.85, the sky light at 0.4, a 7 cm shadow edge). Add one with values from the brief (look_apply).");
|
|
634
|
+
}
|
|
635
|
+
else {
|
|
636
|
+
const left = [];
|
|
637
|
+
if (!hasKey(look, 'toneMapping'))
|
|
638
|
+
left.push(`look.toneMapping (${LOOK_DEFAULTS.toneMapping})`);
|
|
639
|
+
if (!hasKey(look, 'exposure'))
|
|
640
|
+
left.push(`look.exposure (${LOOK_DEFAULTS.exposure})`);
|
|
641
|
+
const ao = isObj(look.ao) ? look.ao : {};
|
|
642
|
+
if (ao.enabled !== false) {
|
|
643
|
+
if (!hasKey(ao, 'radius'))
|
|
644
|
+
left.push(`look.ao.radius (${LOOK_DEFAULTS.ao.radius} m)`);
|
|
645
|
+
if (!hasKey(ao, 'strength'))
|
|
646
|
+
left.push(`look.ao.strength (${LOOK_DEFAULTS.ao.strength})`);
|
|
647
|
+
}
|
|
648
|
+
if (!hasKey(look.shadows, 'softness'))
|
|
649
|
+
left.push(`look.shadows.softness (${LOOK_DEFAULTS.shadows.softness} m)`);
|
|
650
|
+
// A measured sky lights at its own strength, which is the picture's and not a stock value.
|
|
651
|
+
const measured = sky?.kind === 'hdri' || sky?.kind === 'physical';
|
|
652
|
+
if (!measured && !hasKey(look.environment, 'intensity'))
|
|
653
|
+
left.push(`look.environment.intensity (${LOOK_DEFAULTS.environment.intensity})`);
|
|
654
|
+
if (left.length > 0) {
|
|
655
|
+
out.push(`Look values left to the engine's defaults: ${left.join(', ')}. Set each from the brief (the reference's light, contrast and tone), or this space starts from the same numbers as every other.`);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
const left = [];
|
|
659
|
+
const lighting = isObj(cfg.lighting) ? cfg.lighting : {};
|
|
660
|
+
if (!hasKey(lighting.ambient, 'color'))
|
|
661
|
+
left.push('lighting.ambient.color');
|
|
662
|
+
if (!hasKey(lighting.ambient, 'intensity'))
|
|
663
|
+
left.push('lighting.ambient.intensity');
|
|
664
|
+
if (lighting.sun !== null) {
|
|
665
|
+
for (const key of ['color', 'intensity', 'direction'])
|
|
666
|
+
if (!hasKey(lighting.sun, key))
|
|
667
|
+
left.push(`lighting.sun.${key}`);
|
|
668
|
+
}
|
|
669
|
+
if (!isObj(cfg.bloom))
|
|
670
|
+
left.push('bloom');
|
|
671
|
+
if (left.length > 0) {
|
|
672
|
+
out.push(`Light and glow left to the schema's defaults: ${left.join(', ')}. Set them from the brief (the reference's sun: its direction, colour and strength; the shade's colour and depth; what glows and how much).`);
|
|
673
|
+
}
|
|
674
|
+
// A measured sky lights the shade itself, at its own strength; the
|
|
675
|
+
// hemisphere fill (lighting.ambient) is then a second sky on top of it.
|
|
676
|
+
const fill = isObj(lighting.ambient) && typeof lighting.ambient.intensity === 'number' ? lighting.ambient.intensity : null;
|
|
677
|
+
if ((sky?.kind === 'hdri' || sky?.kind === 'physical') && fill !== null && fill > FILL_UNDER_SKY) {
|
|
678
|
+
out.push(`lighting.ambient.intensity is ${fill} under ${sky.kind === 'hdri' ? 'an HDRI' : 'a physical sky'}, which already lights the shade at its own strength (look.environment.intensity): the fill adds a second sky on top. Set it near 0 unless the reference's shade is lighter than the sky alone makes it.`);
|
|
679
|
+
}
|
|
680
|
+
return out;
|
|
681
|
+
}
|