create-threenative 0.2.7 → 0.2.8
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 +3 -1
- package/agent-docs/references/capability-reference.md +177 -7
- package/capabilities.json +247 -4
- package/dist/index.js +6 -1
- package/dist/threenative.js +3 -2
- package/package.json +4 -4
- package/templates/action-rpg/package.json +1 -1
- package/templates/minimal/package.json +1 -1
- package/templates/platformer/package.json +1 -1
- package/templates/puzzle/package.json +1 -1
- package/templates/racing/package.json +1 -1
- package/templates/rain/.codex/config.toml +19 -0
- package/templates/rain/.cursor/mcp.json +32 -0
- package/templates/rain/.gemini/settings.json +32 -0
- package/templates/rain/.mcp.json +32 -0
- package/templates/rain/.vscode/mcp.json +36 -0
- package/templates/rain/.zed/settings.json +36 -0
- package/templates/rain/AGENTS.md +96 -0
- package/templates/rain/CLAUDE.md +98 -0
- package/templates/rain/assets/rain-loop.wav +0 -0
- package/templates/rain/assets/thunder.wav +0 -0
- package/templates/rain/assets/wind-loop.wav +0 -0
- package/templates/rain/index.html +18 -0
- package/templates/rain/kit.json +7 -0
- package/templates/rain/native-playtests/boot.playtest.json +13 -0
- package/templates/rain/native-playtests/lightning.playtest.json +173 -0
- package/templates/rain/opencode.json +41 -0
- package/templates/rain/package.json +56 -0
- package/templates/rain/playtests/auto-lightning-clear.playtest.json +66 -0
- package/templates/rain/playtests/auto-lightning.playtest.json +26 -0
- package/templates/rain/playtests/automation.playtest.json +133 -0
- package/templates/rain/playtests/cinematic.playtest.json +59 -0
- package/templates/rain/playtests/flash.playtest.json +27 -0
- package/templates/rain/playtests/fly.playtest.json +54 -0
- package/templates/rain/playtests/lightning.playtest.json +220 -0
- package/templates/rain/playtests/loading.playtest.json +57 -0
- package/templates/rain/playtests/paused.playtest.json +59 -0
- package/templates/rain/playtests/performance.playtest.json +22 -0
- package/templates/rain/playtests/reduced-motion.playtest.json +87 -0
- package/templates/rain/playtests/simulation.playtest.json +20 -0
- package/templates/rain/playtests/storm.playtest.json +150 -0
- package/templates/rain/playtests/survives.playtest.json +58 -0
- package/templates/rain/playtests/tiers.playtest.json +179 -0
- package/templates/rain/playtests/weather.playtest.json +77 -0
- package/templates/rain/public/favicon.svg +5 -0
- package/templates/rain/src/audio/storm.ts +314 -0
- package/templates/rain/src/game.ts +114 -0
- package/templates/rain/src/main.ts +15 -0
- package/templates/rain/src/render/bloom-shader.ts +65 -0
- package/templates/rain/src/render/camera.ts +160 -0
- package/templates/rain/src/render/clouds-shader.ts +242 -0
- package/templates/rain/src/render/clouds.ts +142 -0
- package/templates/rain/src/render/lighting.ts +39 -0
- package/templates/rain/src/render/lightning.ts +360 -0
- package/templates/rain/src/render/loading.ts +327 -0
- package/templates/rain/src/render/materials.ts +19 -0
- package/templates/rain/src/render/noise-volume.ts +159 -0
- package/templates/rain/src/render/palette.ts +18 -0
- package/templates/rain/src/render/post-shader.ts +178 -0
- package/templates/rain/src/render/postprocessing.ts +226 -0
- package/templates/rain/src/render/quality.ts +135 -0
- package/templates/rain/src/render/rain.ts +299 -0
- package/templates/rain/src/render/sky.ts +28 -0
- package/templates/rain/src/render/world-shader.ts +680 -0
- package/templates/rain/src/render/world.ts +146 -0
- package/templates/rain/src/render/worldEnvironment.ts +809 -0
- package/templates/rain/src/scenes/Boot.ts +334 -0
- package/templates/rain/src/state.ts +257 -0
- package/templates/rain/src/style.css +1160 -0
- package/templates/rain/src/ui/App.tsx +29 -0
- package/templates/rain/src/ui/GameUi.tsx +187 -0
- package/templates/rain/src/ui/Hud.tsx +327 -0
- package/templates/rain/src/ui/LoadingOverlay.tsx +46 -0
- package/templates/rain/src/ui/Menu.tsx +370 -0
- package/templates/rain/src/ui/automation.ts +60 -0
- package/templates/rain/src/ui/main.tsx +7 -0
- package/templates/rain/src/ui/tempest.ts +149 -0
- package/templates/rain/tailwind.config.ts +2 -0
- package/templates/rain/threenative.config.ts +66 -0
- package/templates/rain/tools/generate-shaders.mjs +656 -0
- package/templates/rain/tools/make-storm-audio.mjs +387 -0
- package/templates/rain/tools/storm-dsp.mjs +177 -0
- package/templates/rain/tools/tempest-bloom.frag +10 -0
- package/templates/rain/tools/tempest-clouds.frag +86 -0
- package/templates/rain/tools/tempest-post.frag +47 -0
- package/templates/rain/tools/tempest-world.frag +210 -0
- package/templates/rain/tools/verify-noise-volume.mjs +61 -0
- package/templates/rain/tsconfig.json +17 -0
- package/templates/rain/vite.config.ts +37 -0
- package/templates/rts/package.json +1 -1
- package/templates/runner/package.json +1 -1
- package/templates/sailing/package.json +1 -1
- package/templates/shooter/package.json +1 -1
- package/templates/snow/.codex/config.toml +19 -0
- package/templates/snow/.cursor/mcp.json +32 -0
- package/templates/snow/.gemini/settings.json +32 -0
- package/templates/snow/.mcp.json +32 -0
- package/templates/snow/.vscode/mcp.json +36 -0
- package/templates/snow/.zed/settings.json +36 -0
- package/templates/snow/AGENTS.md +88 -0
- package/templates/snow/CLAUDE.md +90 -0
- package/templates/snow/README.md +26 -0
- package/templates/snow/assets/crunch.wav +0 -0
- package/templates/snow/assets/wind.wav +0 -0
- package/templates/snow/index.html +12 -0
- package/templates/snow/kit.json +7 -0
- package/templates/snow/native-playtests/snow-physics.playtest.json +150 -0
- package/templates/snow/native-playtests/survives.playtest.json +47 -0
- package/templates/snow/opencode.json +41 -0
- package/templates/snow/package.json +58 -0
- package/templates/snow/playtests/footsteps.playtest.json +95 -0
- package/templates/snow/playtests/performance.playtest.json +36 -0
- package/templates/snow/playtests/snow-physics.playtest.json +154 -0
- package/templates/snow/playtests/survives.playtest.json +56 -0
- package/templates/snow/playtests/touch-controls.playtest.json +71 -0
- package/templates/snow/playtests/weather.playtest.json +119 -0
- package/templates/snow/public/favicon.svg +5 -0
- package/templates/snow/src/audio.ts +58 -0
- package/templates/snow/src/commands.ts +8 -0
- package/templates/snow/src/entities/Explorer.ts +279 -0
- package/templates/snow/src/game.ts +69 -0
- package/templates/snow/src/main.ts +15 -0
- package/templates/snow/src/render/bootPrint.ts +50 -0
- package/templates/snow/src/render/camera.ts +84 -0
- package/templates/snow/src/render/explorer.ts +321 -0
- package/templates/snow/src/render/lighting.ts +50 -0
- package/templates/snow/src/render/loading.ts +325 -0
- package/templates/snow/src/render/materials.ts +36 -0
- package/templates/snow/src/render/palette.ts +17 -0
- package/templates/snow/src/render/postprocessing.ts +44 -0
- package/templates/snow/src/render/props.ts +42 -0
- package/templates/snow/src/render/quality.ts +135 -0
- package/templates/snow/src/render/scenery.ts +244 -0
- package/templates/snow/src/render/sky.ts +57 -0
- package/templates/snow/src/render/snowSurface.ts +259 -0
- package/templates/snow/src/render/touch-controls.ts +143 -0
- package/templates/snow/src/render/weather.ts +279 -0
- package/templates/snow/src/render/worldEnvironment.ts +809 -0
- package/templates/snow/src/scenes/Boot.ts +12 -0
- package/templates/snow/src/scenes/Snow.ts +635 -0
- package/templates/snow/src/state.ts +46 -0
- package/templates/snow/src/style.css +143 -0
- package/templates/snow/src/terrain.ts +64 -0
- package/templates/snow/src/ui/App.tsx +15 -0
- package/templates/snow/src/ui/Controls.tsx +322 -0
- package/templates/snow/src/ui/GameUi.tsx +354 -0
- package/templates/snow/src/ui/icons.tsx +54 -0
- package/templates/snow/src/ui/main.tsx +7 -0
- package/templates/snow/tailwind.config.ts +2 -0
- package/templates/snow/threenative.config.ts +51 -0
- package/templates/snow/tsconfig.json +17 -0
- package/templates/snow/vite.config.ts +37 -0
- package/templates/starter/package.json +1 -1
- package/templates/tower-defense/package.json +1 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { acceptHotUpdate } from "@threenative/core/hot";
|
|
2
|
+
import { createElement } from "react";
|
|
3
|
+
import { createRoot } from "react-dom/client";
|
|
4
|
+
import game from "./game.js";
|
|
5
|
+
import { App } from "./ui/App.js";
|
|
6
|
+
import "./style.css";
|
|
7
|
+
|
|
8
|
+
import.meta.hot?.accept();
|
|
9
|
+
acceptHotUpdate(game, import.meta.hot);
|
|
10
|
+
const root = document.getElementById("root");
|
|
11
|
+
if (root === null) throw new Error("Missing #root element.");
|
|
12
|
+
const appRoot = root as typeof root & { __threenativeRoot?: ReturnType<typeof createRoot> };
|
|
13
|
+
const reactRoot = appRoot.__threenativeRoot ?? createRoot(appRoot);
|
|
14
|
+
appRoot.__threenativeRoot = reactRoot;
|
|
15
|
+
reactRoot.render(createElement(App, { game }));
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// Transcribed once by Three.js's own GLSL to TSL transpiler from tools/tempest-bloom.frag, and maintained
|
|
2
|
+
// here by hand since: `tools/generate-shaders.mjs` regenerates only the coast and cloud shaders.
|
|
3
|
+
// Keep the .frag in step when you change this file.
|
|
4
|
+
//
|
|
5
|
+
// The demo's exact bloom: a 5x5 gaussian at twice the input texel size, masked by a soft-knee
|
|
6
|
+
// luminance threshold and normalised by the weight it actually accumulated — not by 25, so the
|
|
7
|
+
// frame's corners, where the kernel hangs off the target, cannot dim. Rendered at quarter
|
|
8
|
+
// resolution: see src/render/postprocessing.ts.
|
|
9
|
+
import { DataTexture, Vector2, Vector3, Vector4 } from "three";
|
|
10
|
+
import {
|
|
11
|
+
Fn,
|
|
12
|
+
Loop,
|
|
13
|
+
exp,
|
|
14
|
+
float,
|
|
15
|
+
frameGroup,
|
|
16
|
+
int,
|
|
17
|
+
max,
|
|
18
|
+
smoothstep,
|
|
19
|
+
texture,
|
|
20
|
+
uniform,
|
|
21
|
+
vec2,
|
|
22
|
+
vec3,
|
|
23
|
+
vec4,
|
|
24
|
+
} from "three/tsl";
|
|
25
|
+
import type { Node, TextureNode } from "three/webgpu";
|
|
26
|
+
|
|
27
|
+
// Uniforms the shader reads. Values are assigned by src/render/world.ts and src/render/clouds.ts,
|
|
28
|
+
// which own the camera basis and the weather; the generated module only holds the nodes.
|
|
29
|
+
const uScenePlaceholder = new DataTexture(new Uint8Array([0, 0, 0, 255]), 1, 1);
|
|
30
|
+
uScenePlaceholder.needsUpdate = true;
|
|
31
|
+
export let uScene: TextureNode = texture(uScenePlaceholder).setGroup(frameGroup);
|
|
32
|
+
export function setScene(value: TextureNode): void {
|
|
33
|
+
uScene = value;
|
|
34
|
+
}
|
|
35
|
+
export const uRes = uniform(new Vector2(), "vec2").setGroup(frameGroup);
|
|
36
|
+
|
|
37
|
+
// Three.js Transpiler r185
|
|
38
|
+
|
|
39
|
+
export const tempestBloom = /*@__PURE__*/ Fn(([vUv]: [Node<"vec2">]) => {
|
|
40
|
+
const c = vec3(0).toVar();
|
|
41
|
+
const w = float(0).toVar();
|
|
42
|
+
|
|
43
|
+
Loop(
|
|
44
|
+
{ start: int(-2), end: int(2), condition: "<=" },
|
|
45
|
+
{ start: int(-2), end: int(2), condition: "<=" },
|
|
46
|
+
({ i, j }) => {
|
|
47
|
+
const wt = exp(
|
|
48
|
+
float(j.mul(j).add(i.mul(i)))
|
|
49
|
+
.negate()
|
|
50
|
+
.mul(0.32),
|
|
51
|
+
).toVar();
|
|
52
|
+
// `vUv` is the bloom quad's own geometry uv, bottom-up; the scene it reads is a render target
|
|
53
|
+
// whose first row is the top of the frame. Unflipped, every highlight blooms mirrored about
|
|
54
|
+
// the horizon — the lamp's glow hung in the sky above it.
|
|
55
|
+
const s = uScene
|
|
56
|
+
.sample(vec2(vUv.x, vUv.y.oneMinus()).add(vec2(float(j), float(i)).div(uRes).mul(2)))
|
|
57
|
+
.rgb.toVar();
|
|
58
|
+
const l = max(s.r, max(s.g, s.b)).toVar();
|
|
59
|
+
c.addAssign(s.mul(smoothstep(0.7, 1.6, l)).mul(wt));
|
|
60
|
+
w.addAssign(wt);
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
return vec4(c.div(w), 1);
|
|
65
|
+
});
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
// Generated for you. Framing is a game-owned decision.
|
|
2
|
+
//
|
|
3
|
+
// The rig, not the scene: everything that decides where the camera stands and what it looks at
|
|
4
|
+
// lives here, so the scene is left wiring lifecycle and publishing state.
|
|
5
|
+
import { Euler, MathUtils, type PerspectiveCamera, Vector3 } from "three";
|
|
6
|
+
|
|
7
|
+
/** The view the game opens on, and the one `resetCamera` returns to. */
|
|
8
|
+
export interface IHomeView {
|
|
9
|
+
readonly pitch: number;
|
|
10
|
+
readonly position: Vector3;
|
|
11
|
+
readonly yaw: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const HOME: IHomeView = {
|
|
15
|
+
pitch: 0.21,
|
|
16
|
+
position: new Vector3(1.8, 2.85, 18),
|
|
17
|
+
yaw: -0.085,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const PITCH_RANGE: readonly [number, number] = [-0.7, 1.25];
|
|
21
|
+
const WALK_SPEED = 6;
|
|
22
|
+
const RUN_SPEED = 23;
|
|
23
|
+
const LOOK_SENSITIVITY = 0.0023;
|
|
24
|
+
|
|
25
|
+
/** How far the free camera may roam: the coast runs along -z, the sea is at +x. */
|
|
26
|
+
const BOUNDS = {
|
|
27
|
+
maxX: 220,
|
|
28
|
+
maxY: 110,
|
|
29
|
+
maxZ: 90,
|
|
30
|
+
minX: -100,
|
|
31
|
+
minY: 1.65,
|
|
32
|
+
minZ: -350,
|
|
33
|
+
} as const;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* What the rig needs from the engine's input. Structural on purpose: `src/render/` is ordinary
|
|
37
|
+
* Three.js and must not import a package.
|
|
38
|
+
*/
|
|
39
|
+
export interface ICameraInput {
|
|
40
|
+
pressed(name: string): boolean;
|
|
41
|
+
raw: {
|
|
42
|
+
readonly pointer: {
|
|
43
|
+
readonly buttons: number;
|
|
44
|
+
readonly down: boolean;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* `move` is the key vector; `look` is the drag's motion since the last tick, in pixels — the
|
|
49
|
+
* engine samples it at the tick, so the raw pointer's own counter is already spent.
|
|
50
|
+
*/
|
|
51
|
+
vector(name: string): { x: number; y: number };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface ICameraRig {
|
|
55
|
+
/** Camera-space forward, flat on the ground: what WASD walks along. */
|
|
56
|
+
readonly forward: Vector3;
|
|
57
|
+
readonly heading: number;
|
|
58
|
+
readonly position: Vector3;
|
|
59
|
+
readonly right: Vector3;
|
|
60
|
+
readonly up: Vector3;
|
|
61
|
+
/** True while a key or a drag is asking for the camera, which cancels the cinematic orbit. */
|
|
62
|
+
readonly manual: boolean;
|
|
63
|
+
reset(): void;
|
|
64
|
+
update(dt: number, elapsed: number, input: ICameraInput, cinematic: boolean): void;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function setupCamera(camera: PerspectiveCamera): void {
|
|
68
|
+
camera.fov = 55;
|
|
69
|
+
// Match the source projection/depth coefficients: 1.00012*d - 0.300018.
|
|
70
|
+
camera.near = 0.15;
|
|
71
|
+
camera.far = 2500;
|
|
72
|
+
camera.position.copy(HOME.position);
|
|
73
|
+
camera.updateProjectionMatrix();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const LEFT_MOUSE = 1;
|
|
77
|
+
|
|
78
|
+
export function createCameraRig(camera: PerspectiveCamera): ICameraRig {
|
|
79
|
+
const position = HOME.position.clone();
|
|
80
|
+
const rotation = new Euler(0, 0, 0, "YXZ");
|
|
81
|
+
const forward = new Vector3();
|
|
82
|
+
const right = new Vector3();
|
|
83
|
+
const up = new Vector3();
|
|
84
|
+
const worldUp = new Vector3(0, 1, 0);
|
|
85
|
+
let yaw = HOME.yaw;
|
|
86
|
+
let pitch = HOME.pitch;
|
|
87
|
+
let manual = false;
|
|
88
|
+
|
|
89
|
+
const orient = (): void => {
|
|
90
|
+
// The rig stores yaw as the compass heading it publishes, so a reset and a drag agree on
|
|
91
|
+
// sign instead of each carrying their own.
|
|
92
|
+
rotation.set(pitch, -yaw, 0, "YXZ");
|
|
93
|
+
camera.quaternion.setFromEuler(rotation);
|
|
94
|
+
forward.set(Math.sin(yaw) * Math.cos(pitch), Math.sin(pitch), -Math.cos(yaw) * Math.cos(pitch));
|
|
95
|
+
right.crossVectors(forward, worldUp).normalize();
|
|
96
|
+
up.crossVectors(right, forward);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const reset = (): void => {
|
|
100
|
+
position.copy(HOME.position);
|
|
101
|
+
yaw = HOME.yaw;
|
|
102
|
+
pitch = HOME.pitch;
|
|
103
|
+
orient();
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
reset();
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
forward,
|
|
110
|
+
get heading() {
|
|
111
|
+
return Math.round(((yaw * 180) / Math.PI + 360) % 360);
|
|
112
|
+
},
|
|
113
|
+
get manual() {
|
|
114
|
+
return manual;
|
|
115
|
+
},
|
|
116
|
+
position,
|
|
117
|
+
reset,
|
|
118
|
+
right,
|
|
119
|
+
up,
|
|
120
|
+
update(dt, elapsed, input, cinematic) {
|
|
121
|
+
const move = input.vector("move");
|
|
122
|
+
const altitude = Number(input.pressed("ascend")) - Number(input.pressed("descend"));
|
|
123
|
+
const boost = input.pressed("boost");
|
|
124
|
+
const dragging = input.raw.pointer.down && (input.raw.pointer.buttons & LEFT_MOUSE) !== 0;
|
|
125
|
+
manual = move.x !== 0 || move.y !== 0 || altitude !== 0 || boost || dragging;
|
|
126
|
+
if (cinematic && !manual) {
|
|
127
|
+
// A slow orbit of the opening view: the coast stays in frame while the weather plays out.
|
|
128
|
+
position.set(
|
|
129
|
+
HOME.position.x + Math.sin(elapsed * 0.08) * 1.6,
|
|
130
|
+
HOME.position.y + Math.sin(elapsed * 0.06) * 0.16,
|
|
131
|
+
HOME.position.z + Math.cos(elapsed * 0.07) * 1.8,
|
|
132
|
+
);
|
|
133
|
+
yaw = HOME.yaw + Math.sin(elapsed * 0.045) * 0.12;
|
|
134
|
+
pitch = HOME.pitch + Math.sin(elapsed * 0.06) * 0.027;
|
|
135
|
+
orient();
|
|
136
|
+
camera.position.copy(position);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (dragging) {
|
|
140
|
+
const look = input.vector("look");
|
|
141
|
+
yaw += look.x * LOOK_SENSITIVITY;
|
|
142
|
+
pitch = MathUtils.clamp(pitch - look.y * LOOK_SENSITIVITY, PITCH_RANGE[0], PITCH_RANGE[1]);
|
|
143
|
+
}
|
|
144
|
+
// Yaw only, so walking never climbs the hill the camera is standing on.
|
|
145
|
+
const flatForward = new Vector3(Math.sin(yaw), 0, -Math.cos(yaw));
|
|
146
|
+
const flatRight = new Vector3(Math.cos(yaw), 0, Math.sin(yaw));
|
|
147
|
+
const speed = dt * (boost ? RUN_SPEED : WALK_SPEED);
|
|
148
|
+
position.addScaledVector(flatForward, speed * move.y);
|
|
149
|
+
position.addScaledVector(flatRight, speed * move.x);
|
|
150
|
+
position.y += speed * altitude;
|
|
151
|
+
position.set(
|
|
152
|
+
MathUtils.clamp(position.x, BOUNDS.minX, BOUNDS.maxX),
|
|
153
|
+
MathUtils.clamp(position.y, BOUNDS.minY, BOUNDS.maxY),
|
|
154
|
+
MathUtils.clamp(position.z, BOUNDS.minZ, BOUNDS.maxZ),
|
|
155
|
+
);
|
|
156
|
+
orient();
|
|
157
|
+
camera.position.copy(position);
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
// GENERATED FILE — do not edit it. Every line below is the output of Three.js's own GLSL to
|
|
2
|
+
// TSL transpiler, run over tools/tempest-clouds.frag. That .frag file
|
|
3
|
+
// is the source of truth; change it and the generator, never this file.
|
|
4
|
+
//
|
|
5
|
+
// node tools/generate-shaders.mjs
|
|
6
|
+
//
|
|
7
|
+
// The shader is the storm ceiling: a raymarched volume between 145 and 815 metres, lit by a
|
|
8
|
+
// five-tap march toward the sun and filled from a procedural 64³ noise volume. It is one full-screen
|
|
9
|
+
// pass into a render target the coast samples — see src/render/clouds.ts.
|
|
10
|
+
import { Data3DTexture, Vector2, Vector3, Vector4 } from "three";
|
|
11
|
+
import {
|
|
12
|
+
Break,
|
|
13
|
+
Fn,
|
|
14
|
+
If,
|
|
15
|
+
Loop,
|
|
16
|
+
abs,
|
|
17
|
+
add,
|
|
18
|
+
clamp,
|
|
19
|
+
depth,
|
|
20
|
+
dot,
|
|
21
|
+
exp,
|
|
22
|
+
float,
|
|
23
|
+
floor,
|
|
24
|
+
fract,
|
|
25
|
+
frameGroup,
|
|
26
|
+
int,
|
|
27
|
+
length,
|
|
28
|
+
mat2,
|
|
29
|
+
max,
|
|
30
|
+
min,
|
|
31
|
+
mix,
|
|
32
|
+
mul,
|
|
33
|
+
normalize,
|
|
34
|
+
pow,
|
|
35
|
+
screenCoordinate,
|
|
36
|
+
smoothstep,
|
|
37
|
+
sub,
|
|
38
|
+
texture3D,
|
|
39
|
+
uniform,
|
|
40
|
+
vec2,
|
|
41
|
+
vec3,
|
|
42
|
+
vec4,
|
|
43
|
+
} from "three/tsl";
|
|
44
|
+
import type { Node, TextureNode } from "three/webgpu";
|
|
45
|
+
|
|
46
|
+
// Uniforms the shader reads. Values are assigned by src/render/world.ts and src/render/clouds.ts,
|
|
47
|
+
// which own the camera basis and the weather; the generated module only holds the nodes.
|
|
48
|
+
export const uTime = uniform(0, "float").setGroup(frameGroup);
|
|
49
|
+
export const uCloud = uniform(0, "float").setGroup(frameGroup);
|
|
50
|
+
export const uWind = uniform(0, "float").setGroup(frameGroup);
|
|
51
|
+
export const uFlash = uniform(0, "float").setGroup(frameGroup);
|
|
52
|
+
export const uAspect = uniform(0, "float").setGroup(frameGroup);
|
|
53
|
+
export const uTan = uniform(0, "float").setGroup(frameGroup);
|
|
54
|
+
export const uCam = uniform(new Vector3(), "vec3").setGroup(frameGroup);
|
|
55
|
+
export const uForward = uniform(new Vector3(), "vec3").setGroup(frameGroup);
|
|
56
|
+
export const uRight = uniform(new Vector3(), "vec3").setGroup(frameGroup);
|
|
57
|
+
export const uUp = uniform(new Vector3(), "vec3").setGroup(frameGroup);
|
|
58
|
+
export const uStrike = uniform(new Vector3(), "vec3").setGroup(frameGroup);
|
|
59
|
+
export const uSunDir = uniform(new Vector3(), "vec3").setGroup(frameGroup);
|
|
60
|
+
export const uSkyLow = uniform(new Vector3(), "vec3").setGroup(frameGroup);
|
|
61
|
+
export const uSkyHigh = uniform(new Vector3(), "vec3").setGroup(frameGroup);
|
|
62
|
+
const uNoisePlaceholder = new Data3DTexture(new Uint8Array([0, 0, 0, 255]), 1, 1, 1);
|
|
63
|
+
uNoisePlaceholder.needsUpdate = true;
|
|
64
|
+
export let uNoise: TextureNode = texture3D(uNoisePlaceholder).setGroup(frameGroup);
|
|
65
|
+
export function setNoise(value: TextureNode): void {
|
|
66
|
+
uNoise = value;
|
|
67
|
+
}
|
|
68
|
+
export const uSteps = uniform(0, "int").setGroup(frameGroup);
|
|
69
|
+
|
|
70
|
+
// Three.js Transpiler r185
|
|
71
|
+
|
|
72
|
+
// Polyfills
|
|
73
|
+
|
|
74
|
+
const gl_FragCoord = vec3(screenCoordinate.x, screenCoordinate.y.oneMinus(), depth);
|
|
75
|
+
|
|
76
|
+
// The look, owned by src/render/{sky,lighting}.ts and set from there every run.
|
|
77
|
+
|
|
78
|
+
export const hash12 = /*@__PURE__*/ Fn(([p]: [Node<"vec2">]) => {
|
|
79
|
+
const p3 = fract(vec3(p.xyx).mul(0.1031)).toVar();
|
|
80
|
+
p3.addAssign(dot(p3, p3.yzx.add(33.33)));
|
|
81
|
+
|
|
82
|
+
return fract(p3.x.add(p3.y).mul(p3.z));
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
export const hash13 = /*@__PURE__*/ Fn(([p_immutable]: [Node<"vec3">]) => {
|
|
86
|
+
const p = p_immutable.toVar();
|
|
87
|
+
p.assign(fract(p.mul(0.1031)));
|
|
88
|
+
p.addAssign(dot(p, p.zyx.add(31.32)));
|
|
89
|
+
|
|
90
|
+
return fract(p.x.add(p.y).mul(p.z));
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
export const noise2 = /*@__PURE__*/ Fn(([p]: [Node<"vec2">]) => {
|
|
94
|
+
const i = floor(p).toVar();
|
|
95
|
+
const f = fract(p).toVar();
|
|
96
|
+
f.assign(f.mul(f).mul(sub(3, mul(2, f))));
|
|
97
|
+
|
|
98
|
+
return mix(
|
|
99
|
+
mix(hash12(i), hash12(i.add(vec2(1, 0))), f.x),
|
|
100
|
+
mix(hash12(i.add(vec2(0, 1))), hash12(i.add(1)), f.x),
|
|
101
|
+
f.y,
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
export const fbm2 = /*@__PURE__*/ Fn(([p_immutable]: [Node<"vec2">]) => {
|
|
106
|
+
const p = p_immutable.toVar();
|
|
107
|
+
const v = mul(0.5, noise2(p)).toVar();
|
|
108
|
+
p.assign(mat2(0.8, 0.6, -0.6, 0.8).mul(p).mul(2.03).add(19.1));
|
|
109
|
+
v.addAssign(mul(0.25, noise2(p)));
|
|
110
|
+
p.assign(p.mul(2.02).add(9.3));
|
|
111
|
+
v.addAssign(mul(0.125, noise2(p)));
|
|
112
|
+
|
|
113
|
+
return v.add(mul(0.0625, noise2(p.mul(2.01).add(17))));
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
export const ray = /*@__PURE__*/ Fn(([uv]: [Node<"vec2">]) => {
|
|
117
|
+
const q = uv.mul(2).sub(1).toVar();
|
|
118
|
+
|
|
119
|
+
return normalize(
|
|
120
|
+
uForward.add(uRight.mul(q.x).mul(uAspect).mul(uTan)).add(uUp.mul(q.y).mul(uTan)),
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
export const project = /*@__PURE__*/ Fn(([p]: [Node<"vec3">]) => {
|
|
125
|
+
const v = p.sub(uCam).toVar();
|
|
126
|
+
const d = dot(v, uForward).toVar();
|
|
127
|
+
|
|
128
|
+
return vec4(
|
|
129
|
+
dot(v, uRight).div(uAspect.mul(uTan)),
|
|
130
|
+
dot(v, uUp).div(uTan),
|
|
131
|
+
mul(1.00012, d).sub(0.300018),
|
|
132
|
+
d,
|
|
133
|
+
);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
export const density = /*@__PURE__*/ Fn(([p]: [Node<"vec3">]) => {
|
|
137
|
+
// One value, one return, for the reason given in the coast's `baseColor`: the transpiler turns a
|
|
138
|
+
// GLSL early return into a JavaScript return that only leaves the `If` callback the node graph is
|
|
139
|
+
// being built inside, so the branch would never be assigned. The guard is kept as a guard, so a
|
|
140
|
+
// clear sky still costs one comparison and no noise fetches.
|
|
141
|
+
|
|
142
|
+
const res = float(0).toVar();
|
|
143
|
+
|
|
144
|
+
If(uCloud.greaterThanEqual(0.005), () => {
|
|
145
|
+
const drift = vec3(uTime.mul(add(2, uWind.mul(13))), 0, uTime.mul(1.2)).toVar();
|
|
146
|
+
const q = p.add(drift).mul(0.00105).toVar();
|
|
147
|
+
q.y.mulAssign(1.4);
|
|
148
|
+
const n = uNoise.sample(q).toVar();
|
|
149
|
+
const broad = n.r
|
|
150
|
+
.mul(0.76)
|
|
151
|
+
.add(uNoise.sample(q.mul(2.07).add(vec3(0.1, 0.3, 0.7))).r.mul(0.24))
|
|
152
|
+
.toVar();
|
|
153
|
+
|
|
154
|
+
// Flattened condensation base with turbulent billows above it.
|
|
155
|
+
|
|
156
|
+
const h = p.y.sub(145).div(670).toVar();
|
|
157
|
+
const base = smoothstep(0, 0.09, h)
|
|
158
|
+
.mul(sub(1, smoothstep(0.68, 1, h)))
|
|
159
|
+
.toVar();
|
|
160
|
+
const shape = broad.add(uCloud.mul(0.3)).sub(0.72).toVar();
|
|
161
|
+
const edge = uNoise.sample(q.mul(3.81)).b.sub(0.5).mul(0.12).toVar();
|
|
162
|
+
res.assign(clamp(shape.sub(edge).mul(5.1), 0, 1).mul(base));
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
return res;
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
export const lightAt = /*@__PURE__*/ Fn(([p_immutable, l]: [Node<"vec3">, Node<"vec3">]) => {
|
|
169
|
+
const p = p_immutable.toVar();
|
|
170
|
+
const sum = float(0).toVar();
|
|
171
|
+
const stepLen = float(28).toVar();
|
|
172
|
+
|
|
173
|
+
Loop({ start: int(0), end: 5 }, ({ i }) => {
|
|
174
|
+
p.addAssign(l.mul(stepLen));
|
|
175
|
+
sum.addAssign(density(p).mul(stepLen));
|
|
176
|
+
stepLen.mulAssign(1.7);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
return exp(sum.negate().mul(0.015));
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
export const tempestClouds = /*@__PURE__*/ Fn(([vUv]: [Node<"vec2">]) => {
|
|
183
|
+
const rd = ray(vUv).toVar();
|
|
184
|
+
rd.y.assign(abs(rd.y));
|
|
185
|
+
rd.assign(normalize(rd));
|
|
186
|
+
const sunDir = uSunDir.toVar();
|
|
187
|
+
const mu = dot(rd, sunDir).toVar();
|
|
188
|
+
const sky = mix(uSkyLow, uSkyHigh, pow(clamp(rd.y, 0, 1), 0.62)).toVar();
|
|
189
|
+
sky.addAssign(vec3(0.31, 0.27, 0.205).mul(pow(max(mu, 0), 14)));
|
|
190
|
+
sky.addAssign(vec3(0.7, 0.57, 0.37).mul(pow(max(mu, 0), 140)));
|
|
191
|
+
sky.addAssign(uFlash.mul(vec3(0.14, 0.22, 0.36)));
|
|
192
|
+
const t0 = max(0, sub(145, uCam.y).div(max(rd.y, 0.008))).toVar();
|
|
193
|
+
const t1 = min(10500, sub(815, uCam.y).div(max(rd.y, 0.008))).toVar();
|
|
194
|
+
const col = vec4(sky, 1).toVar();
|
|
195
|
+
|
|
196
|
+
If(t0.lessThan(t1), () => {
|
|
197
|
+
const dt = t1.sub(t0).div(float(uSteps)).toVar();
|
|
198
|
+
const jitter = hash12(gl_FragCoord.xy).mul(0.75).add(0.12).toVar();
|
|
199
|
+
const light = vec3(0).toVar();
|
|
200
|
+
const trans = float(1).toVar();
|
|
201
|
+
const phase = add(0.45, mul(0.65, pow(max(mu, 0), 5))).toVar();
|
|
202
|
+
|
|
203
|
+
Loop({ start: int(0), end: 96 }, ({ i }) => {
|
|
204
|
+
If(i.greaterThanEqual(uSteps).or(trans.lessThan(0.008)), () => {
|
|
205
|
+
Break();
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
const t = t0.add(float(i).add(jitter).mul(dt)).toVar();
|
|
209
|
+
const p = uCam.add(rd.mul(t)).toVar();
|
|
210
|
+
const d = density(p).toVar();
|
|
211
|
+
|
|
212
|
+
If(d.greaterThan(0.002), () => {
|
|
213
|
+
const sun = lightAt(p, sunDir).toVar();
|
|
214
|
+
const height = clamp(p.y.sub(145).div(670), 0, 1).toVar();
|
|
215
|
+
const ambient = mix(vec3(0.035, 0.061, 0.079), vec3(0.19, 0.25, 0.28), height).toVar();
|
|
216
|
+
|
|
217
|
+
// A small multiple-scattering/powder approximation prevents crushed cloud cores.
|
|
218
|
+
|
|
219
|
+
const c = ambient
|
|
220
|
+
.mul(add(0.7, mul(0.45, sub(1, exp(d.negate().mul(3))))))
|
|
221
|
+
.add(vec3(0.97, 0.94, 0.85).mul(sun).mul(phase).mul(0.7))
|
|
222
|
+
.toVar();
|
|
223
|
+
const glow = exp(
|
|
224
|
+
length(p.sub(uStrike).mul(vec3(1, 0.5, 1)))
|
|
225
|
+
.negate()
|
|
226
|
+
.mul(0.0022),
|
|
227
|
+
).toVar();
|
|
228
|
+
c.addAssign(vec3(0.85, 1.18, 1.9).mul(uFlash).mul(glow).mul(1.2));
|
|
229
|
+
const absorb = sub(1, exp(d.negate().mul(dt).mul(0.02))).toVar();
|
|
230
|
+
light.addAssign(trans.mul(absorb).mul(c));
|
|
231
|
+
trans.mulAssign(sub(1, absorb));
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const marched = light.add(trans.mul(sky)).toVar();
|
|
236
|
+
const atmospheric = sub(1, exp(t0.negate().mul(0.000075))).toVar();
|
|
237
|
+
marched.assign(mix(marched, sky, atmospheric.mul(0.66)));
|
|
238
|
+
col.assign(vec4(marched, sub(1, trans)));
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
return col;
|
|
242
|
+
});
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Generated for you. Ordinary Three.js, and the whole storm ceiling lives in this file.
|
|
2
|
+
//
|
|
3
|
+
// The clouds are not part of the coast's raymarch: the source rendered them into a screen-sized
|
|
4
|
+
// target first and handed that target to the world shader as its sky and its wet reflections, which
|
|
5
|
+
// is what makes the reflections carry the same cloud shapes the sky does. This is that pass. The
|
|
6
|
+
// shader itself is `clouds-shader.ts`, transpiled from `tools/tempest-clouds.frag`; the maths of the
|
|
7
|
+
// volume is there and the only decision here is where the march happens.
|
|
8
|
+
//
|
|
9
|
+
// The pass is a `PassNode` over a scene holding one screen quad, so the engine's own renderer owns
|
|
10
|
+
// the render target, its size and its per-frame update — there is no second render loop here, and
|
|
11
|
+
// nothing about the target is copied out by hand.
|
|
12
|
+
import {
|
|
13
|
+
DoubleSide,
|
|
14
|
+
Mesh,
|
|
15
|
+
OrthographicCamera,
|
|
16
|
+
type PerspectiveCamera,
|
|
17
|
+
PlaneGeometry,
|
|
18
|
+
Scene,
|
|
19
|
+
Vector3,
|
|
20
|
+
} from "three";
|
|
21
|
+
import { positionGeometry, texture3D, uv, vec4 } from "three/tsl";
|
|
22
|
+
import { MeshBasicNodeMaterial, PassNode } from "three/webgpu";
|
|
23
|
+
import type { QualityName, Weather } from "../state.js";
|
|
24
|
+
import {
|
|
25
|
+
setNoise,
|
|
26
|
+
tempestClouds,
|
|
27
|
+
uAspect,
|
|
28
|
+
uCam,
|
|
29
|
+
uCloud,
|
|
30
|
+
uFlash,
|
|
31
|
+
uForward,
|
|
32
|
+
uRight,
|
|
33
|
+
uSteps,
|
|
34
|
+
uStrike,
|
|
35
|
+
uTan,
|
|
36
|
+
uTime,
|
|
37
|
+
uUp,
|
|
38
|
+
uWind,
|
|
39
|
+
} from "./clouds-shader.js";
|
|
40
|
+
import { createNoiseVolume } from "./noise-volume.js";
|
|
41
|
+
import { studyTier } from "./quality.js";
|
|
42
|
+
import { setSky } from "./world-shader.js";
|
|
43
|
+
|
|
44
|
+
export interface ICloudPassOptions {
|
|
45
|
+
readonly camera: PerspectiveCamera;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ICloudPass {
|
|
49
|
+
/** The node the world shader samples for its sky and its reflections. */
|
|
50
|
+
readonly sky: ReturnType<PassNode["getTextureNode"]>;
|
|
51
|
+
/** The cloud target as the renderer last sized it, and the march steps it ran: read, not asked. */
|
|
52
|
+
measured(): { readonly height: number; readonly steps: number; readonly width: number };
|
|
53
|
+
dispose(): void;
|
|
54
|
+
update(options: {
|
|
55
|
+
readonly elapsed: number;
|
|
56
|
+
readonly flash: number;
|
|
57
|
+
readonly quality: QualityName;
|
|
58
|
+
readonly strike: Vector3;
|
|
59
|
+
readonly weather: Weather;
|
|
60
|
+
}): void;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function createCloudPass({ camera }: ICloudPassOptions): ICloudPass {
|
|
64
|
+
const volume = createNoiseVolume();
|
|
65
|
+
setNoise(texture3D(volume.texture));
|
|
66
|
+
|
|
67
|
+
// The source's cloud quad filled the frame from clip-space corners, so the camera on this pass is
|
|
68
|
+
// a formality: the vertex stage writes the corners and nothing reads the projection.
|
|
69
|
+
const cloudScene = new Scene();
|
|
70
|
+
const cloudCamera = new OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
|
71
|
+
const geometry = new PlaneGeometry(2, 2);
|
|
72
|
+
const material = new MeshBasicNodeMaterial();
|
|
73
|
+
material.side = DoubleSide;
|
|
74
|
+
material.vertexNode = vec4(positionGeometry.xy, 0, 1);
|
|
75
|
+
material.fragmentNode = tempestClouds(uv());
|
|
76
|
+
const quad = new Mesh(geometry, material);
|
|
77
|
+
// Same as the coast quad: its own bounds are two metres wide at the origin, and the projection it
|
|
78
|
+
// is drawn with has no use for them.
|
|
79
|
+
quad.frustumCulled = false;
|
|
80
|
+
cloudScene.add(quad);
|
|
81
|
+
|
|
82
|
+
const pass = new PassNode(PassNode.COLOR, cloudScene, cloudCamera);
|
|
83
|
+
// The world's shader has to reach the pass through the node graph, not through a copied texture:
|
|
84
|
+
// a pass that is not in the graph the renderer walks is never asked for a frame.
|
|
85
|
+
const sky = pass.getTextureNode();
|
|
86
|
+
setSky(sky);
|
|
87
|
+
|
|
88
|
+
const forward = new Vector3();
|
|
89
|
+
const right = new Vector3();
|
|
90
|
+
const up = new Vector3();
|
|
91
|
+
let steps = 0;
|
|
92
|
+
let scale = 0;
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
sky,
|
|
96
|
+
measured: () => ({
|
|
97
|
+
height: pass.renderTarget.height,
|
|
98
|
+
steps: uSteps.value,
|
|
99
|
+
width: pass.renderTarget.width,
|
|
100
|
+
}),
|
|
101
|
+
dispose(): void {
|
|
102
|
+
pass.dispose();
|
|
103
|
+
geometry.dispose();
|
|
104
|
+
material.dispose();
|
|
105
|
+
volume.texture.dispose();
|
|
106
|
+
},
|
|
107
|
+
update({ elapsed, flash, quality, strike, weather }): void {
|
|
108
|
+
// The same basis the world marches from, and the same field of view, so the clouds and the
|
|
109
|
+
// coast agree on where the horizon is.
|
|
110
|
+
camera.getWorldDirection(forward);
|
|
111
|
+
right.set(1, 0, 0).applyQuaternion(camera.quaternion);
|
|
112
|
+
up.set(0, 1, 0).applyQuaternion(camera.quaternion);
|
|
113
|
+
uCam.value.copy(camera.position);
|
|
114
|
+
uForward.value.copy(forward);
|
|
115
|
+
uRight.value.copy(right);
|
|
116
|
+
uUp.value.copy(up);
|
|
117
|
+
uAspect.value = camera.aspect;
|
|
118
|
+
uTan.value = Math.tan((camera.fov * Math.PI) / 360);
|
|
119
|
+
|
|
120
|
+
uTime.value = elapsed;
|
|
121
|
+
uCloud.value = weather.cloud;
|
|
122
|
+
uWind.value = weather.wind;
|
|
123
|
+
uFlash.value = flash;
|
|
124
|
+
uStrike.value.copy(strike);
|
|
125
|
+
|
|
126
|
+
const tier = studyTier(quality);
|
|
127
|
+
const next = tier.cloudSteps;
|
|
128
|
+
if (next !== steps) {
|
|
129
|
+
steps = next;
|
|
130
|
+
uSteps.value = next;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// The pass renders at this share of the frame's resolution: the cloud march is smooth and
|
|
134
|
+
// low-frequency next to the coast it backs, so a lower tier costs it little and buys a lot.
|
|
135
|
+
const nextScale = tier.cloudScale;
|
|
136
|
+
if (nextScale !== scale) {
|
|
137
|
+
scale = nextScale;
|
|
138
|
+
pass.setResolutionScale(nextScale);
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Generated for you. This is ordinary Three.js; tune the storm's light here.
|
|
2
|
+
//
|
|
3
|
+
// The coast is ray-marched, so nothing here is added to the scene: these are Three's own light
|
|
4
|
+
// objects used as the place the storm's lighting is decided, and `setupLighting` hands their
|
|
5
|
+
// direction and colour × intensity to the two shaders. No shadow map is involved — the march
|
|
6
|
+
// computes its own occlusion — so there is nothing to tune for one.
|
|
7
|
+
import { Color, DirectionalLight, HemisphereLight, LinearSRGBColorSpace } from "three";
|
|
8
|
+
import * as clouds from "./clouds-shader.js";
|
|
9
|
+
import * as world from "./world-shader.js";
|
|
10
|
+
|
|
11
|
+
/** The study's colours are linear RGB; these keep them exact instead of converting from sRGB. */
|
|
12
|
+
const linear = (r: number, g: number, b: number): Color =>
|
|
13
|
+
new Color().setRGB(r, g, b, LinearSRGBColorSpace);
|
|
14
|
+
|
|
15
|
+
export interface IStormLighting {
|
|
16
|
+
/** The low storm sun behind the deck: its direction lights the clouds and the coast. */
|
|
17
|
+
readonly key: DirectionalLight;
|
|
18
|
+
/** The lightning's own light. Its intensity is scaled by the flash every frame in the shader. */
|
|
19
|
+
readonly rim: DirectionalLight;
|
|
20
|
+
/** The overcast sky light; the shader weights it `0.45 + 0.55 · n.y`, like a hemisphere. */
|
|
21
|
+
readonly fill: HemisphereLight;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function setupLighting(): IStormLighting {
|
|
25
|
+
const key = new DirectionalLight(linear(0.56, 0.61, 0.67), 0.35);
|
|
26
|
+
key.position.set(-0.62, 0.34, -0.71).normalize();
|
|
27
|
+
const rim = new DirectionalLight(linear(0.8 / 1.4, 1.04 / 1.4, 1), 1.4);
|
|
28
|
+
const fill = new HemisphereLight(linear(0.64, 0.86, 1.03), linear(0.29, 0.39, 0.46), 0.65);
|
|
29
|
+
|
|
30
|
+
world.uSunDir.value.copy(key.position);
|
|
31
|
+
clouds.uSunDir.value.copy(key.position);
|
|
32
|
+
const sun = key.color.clone().multiplyScalar(key.intensity);
|
|
33
|
+
world.uSunColor.value.set(sun.r, sun.g, sun.b);
|
|
34
|
+
const flash = rim.color.clone().multiplyScalar(rim.intensity);
|
|
35
|
+
world.uFlashLight.value.set(flash.r, flash.g, flash.b);
|
|
36
|
+
const sky = fill.color.clone().multiplyScalar(fill.intensity);
|
|
37
|
+
world.uFill.value.set(sky.r, sky.g, sky.b);
|
|
38
|
+
return { fill, key, rim };
|
|
39
|
+
}
|