@holtjs/stage 0.8.0 → 0.10.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/CHANGELOG.md +31 -0
- package/README.md +12 -11
- package/dist/{anims-ClNi6zZQ.d.ts → anims-xOSYNG79.d.ts} +23 -4
- package/dist/anims.d.ts +1 -1
- package/dist/anims.js +49 -5
- package/dist/display-CZb3yen0.js +2162 -0
- package/dist/{game-CEa0m4eX.d.ts → game-BbgtwqyW.d.ts} +80 -14
- package/dist/{game-D46nY-B2.js → game-CUZbJLbR.js} +107 -21
- package/dist/headless.d.ts +1 -1
- package/dist/headless.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -2
- package/dist/joystick.d.ts +1 -1
- package/dist/kernel.d.ts +1 -1
- package/dist/lighting.d.ts +99 -15
- package/dist/lighting.js +602 -98
- package/dist/projection.d.ts +47 -14
- package/dist/projection.js +206 -4
- package/dist/{renderer-webgpu-BXU-ZDIp.js → renderer-webgpu-BZ3J971y.js} +43 -1925
- package/dist/renderer-webgpu.d.ts +1 -1
- package/dist/renderer-webgpu.js +1 -1
- package/dist/rig2d.d.ts +2 -2
- package/dist/tilemap.d.ts +1 -1
- package/dist/trace.d.ts +1 -1
- package/llms.txt +12 -11
- package/package.json +1 -1
- package/skills/stage/SKILL.md +17 -11
- package/skills/stage/references/subpaths.md +13 -13
package/dist/lighting.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { It as SceneHostLike, Tt as ImageObject, bt as DisplayObject, gt as CustomPassObject, pt as Container } from "./game-BbgtwqyW.js";
|
|
2
2
|
export type DayPhase = 'day' | 'dusk' | 'night';
|
|
3
3
|
export interface DayNightConfig {
|
|
4
4
|
dayLengthMs?: number;
|
|
@@ -11,7 +11,7 @@ export interface DayNightState {
|
|
|
11
11
|
dayCount: number;
|
|
12
12
|
phase: DayPhase;
|
|
13
13
|
ambientRgb: number;
|
|
14
|
-
/** 0.0 at bright noon -> up to ~0.
|
|
14
|
+
/** 0.0 at bright noon -> up to ~0.88 in pitch-black night. */
|
|
15
15
|
darkness: number;
|
|
16
16
|
sunAzimuthRad: number;
|
|
17
17
|
sunElevationRad: number;
|
|
@@ -55,16 +55,53 @@ export interface PointLight2D {
|
|
|
55
55
|
/** Torch flame organic flicker amplitude in `[0, 0.5]` (`default = 0`). */
|
|
56
56
|
flicker?: number;
|
|
57
57
|
enabled?: boolean;
|
|
58
|
+
/** Coordinate space of `(x, y)` (`'world'` default; `'screen'` when driven directly by `bindEmissive` screen projection). */
|
|
59
|
+
space?: 'world' | 'screen';
|
|
60
|
+
/** Effective scale multiplier when `space === 'screen'` (`default = 1`). */
|
|
61
|
+
screenScale?: number;
|
|
62
|
+
}
|
|
63
|
+
export interface ScreenLightSample2D {
|
|
64
|
+
screenX: number;
|
|
65
|
+
screenY: number;
|
|
66
|
+
z: number;
|
|
67
|
+
radius: number;
|
|
68
|
+
color: number;
|
|
69
|
+
intensity: number;
|
|
58
70
|
}
|
|
59
71
|
/**
|
|
60
72
|
* Evaluate exact 2D normal-mapped Lambertian + specular lighting at pixel `(px, py)` for unit-testing & CPU reference parity.
|
|
61
73
|
*/
|
|
62
74
|
export declare function evaluateNormalLitPixel(baseRgb: number, normalX: number, normalY: number, normalZ: number, px: number, py: number, ambientRgb: number, lights: ReadonlyArray<PointLight2D>): number;
|
|
75
|
+
export interface EmissiveBindOptions {
|
|
76
|
+
/** Optional point-light RGB color (`default = 0xff9a2e` warm flame). */
|
|
77
|
+
color?: number;
|
|
78
|
+
/** Optional point-light radius in pixels (`0` = self-lit emissive overlay only, `default = 0`). */
|
|
79
|
+
radius?: number;
|
|
80
|
+
/** Point-light intensity (`default = 1.0`, multiplied by `frame.emissivePower` when present). */
|
|
81
|
+
intensity?: number;
|
|
82
|
+
/** Light Z height above sprite plane (`default = 36`). */
|
|
83
|
+
z?: number;
|
|
84
|
+
/** Organic flame flicker amplitude in `[0, 0.5]` (`default = 0.1`). */
|
|
85
|
+
flicker?: number;
|
|
86
|
+
/** Explicit emissive atlas texture key (`default = "${sprite.texture.key}_emissive"` if registered on `scene.textures`). */
|
|
87
|
+
emissiveKey?: string;
|
|
88
|
+
/** Self-lit `ADD` overlay opacity (`default = 0.95`). */
|
|
89
|
+
emissiveAlpha?: number;
|
|
90
|
+
/** Optional tint on the self-lit `ADD` overlay (`default = 0xffffff`). */
|
|
91
|
+
emissiveTint?: number;
|
|
92
|
+
}
|
|
93
|
+
export interface EmissiveBinding {
|
|
94
|
+
readonly id: string;
|
|
95
|
+
readonly sprite: ImageObject;
|
|
96
|
+
readonly light: PointLight2D | null;
|
|
97
|
+
readonly glowSprite: ImageObject | null;
|
|
98
|
+
destroy(): void;
|
|
99
|
+
}
|
|
63
100
|
export interface Lighting2DSystemOptions {
|
|
64
101
|
key?: string;
|
|
65
102
|
width: number;
|
|
66
103
|
height: number;
|
|
67
|
-
/** Downscale factor for the offscreen lightmap FBO (`
|
|
104
|
+
/** Downscale factor for the offscreen lightmap FBO (`0.5` = half-res soft butter-smooth light falloff at 1/4 fillrate!). */
|
|
68
105
|
resolutionScale?: number;
|
|
69
106
|
depth?: number;
|
|
70
107
|
cycle?: DayNightCycle;
|
|
@@ -73,23 +110,52 @@ export declare class Lighting2DSystem {
|
|
|
73
110
|
readonly scene: SceneHostLike;
|
|
74
111
|
readonly cycle: DayNightCycle;
|
|
75
112
|
readonly overlayImage: ImageObject;
|
|
113
|
+
/** Screen-space `BlendModes.ADD` container right above `overlayImage` so emissive flames/eyes shine crisp in pitch-black night! */
|
|
114
|
+
readonly emissiveLayer: Container;
|
|
76
115
|
private renderTarget;
|
|
77
116
|
private readonly lightGraphics;
|
|
117
|
+
private glowBatch;
|
|
118
|
+
private glowCap;
|
|
119
|
+
private glowX;
|
|
120
|
+
private glowY;
|
|
121
|
+
private glowScale;
|
|
122
|
+
private glowAlpha;
|
|
123
|
+
private glowTint;
|
|
78
124
|
private readonly lights;
|
|
125
|
+
private readonly emissives;
|
|
126
|
+
private readonly activeScreenLights;
|
|
79
127
|
private resScale;
|
|
80
128
|
private viewportW;
|
|
81
129
|
private viewportH;
|
|
82
130
|
private elapsedSec;
|
|
83
131
|
private manualAmbientRgb;
|
|
132
|
+
private lastAmbientRgb;
|
|
133
|
+
private nextEmissiveSeq;
|
|
134
|
+
private readonly matScratch;
|
|
135
|
+
private readonly decompScratch;
|
|
84
136
|
constructor(scene: SceneHostLike, opts: Lighting2DSystemOptions);
|
|
137
|
+
private ensureGlowCapacity;
|
|
85
138
|
addLight(light: PointLight2D): PointLight2D;
|
|
86
139
|
getLight(id: string): PointLight2D | undefined;
|
|
87
140
|
removeLight(id: string): boolean;
|
|
88
141
|
get lightCount(): number;
|
|
142
|
+
/** Latest ambient RGB evaluated during `update()` (handy for `createSceneNormalLitPass`). */
|
|
143
|
+
get currentAmbientRgb(): number;
|
|
144
|
+
/** Live flickering screen-space point lights from the latest `update()` pass. */
|
|
145
|
+
get screenLights(): ReadonlyArray<ScreenLightSample2D>;
|
|
146
|
+
/**
|
|
147
|
+
* Bind a sprite (`ImageObject` / `SpriteObject`) whose atlas carries `@holtjs/craft` `Frame.emissiveCenter`
|
|
148
|
+
* and/or a sibling `${key}_emissive` self-lit texture:
|
|
149
|
+
* - Automatically tracks `emissiveCenter` in screen space across animations, `flipX`, `rotation`, and `Camera25D` spins!
|
|
150
|
+
* - Optionally drives a flickering `PointLight2D` (`opts.radius > 0`)
|
|
151
|
+
* - Renders `${key}_emissive` in `emissiveLayer` (`BlendModes.ADD` above night darkness) so flames/embers/eyes never dim at night!
|
|
152
|
+
*/
|
|
153
|
+
bindEmissive(sprite: ImageObject, opts?: EmissiveBindOptions): EmissiveBinding;
|
|
89
154
|
setAmbientOverride(rgb: number | null): void;
|
|
90
155
|
resize(width: number, height: number): void;
|
|
156
|
+
private syncEmissiveBindings;
|
|
91
157
|
/**
|
|
92
|
-
* Step the day/night cycle + torch flicker and render the `MULTIPLY` lightmap FBO!
|
|
158
|
+
* Step the day/night cycle + torch flicker, sync bound emissive sprites, and render the `MULTIPLY` lightmap FBO!
|
|
93
159
|
* Pass `projectToScreen` when using `Camera25D`; otherwise defaults to `scene.cameras.main.worldToScreen`.
|
|
94
160
|
*/
|
|
95
161
|
update(deltaMs: number, projectToScreen?: (wx: number, wy: number, wz: number, out: {
|
|
@@ -110,20 +176,38 @@ export interface NormalLitQuad {
|
|
|
110
176
|
v1?: number;
|
|
111
177
|
originX?: number;
|
|
112
178
|
originY?: number;
|
|
179
|
+
rotation?: number;
|
|
180
|
+
flipX?: boolean;
|
|
181
|
+
flipY?: boolean;
|
|
113
182
|
}
|
|
114
183
|
/**
|
|
115
|
-
* Create a state-isolated WebGL2 `CustomPass` that renders normal-mapped 2D props/characters with per-pixel
|
|
116
|
-
* 3D tangent-space point lighting (`uDiffuse` + `uNormal`), gracefully no-oping on Canvas2D!
|
|
184
|
+
* Create a state-isolated, single-draw batched WebGL2 `CustomPass` that renders normal-mapped 2D props/characters with per-pixel
|
|
185
|
+
* 3D tangent-space point lighting (`uDiffuse` + `uNormal`, supporting `rotation`, `flipX`, and `flipY`), gracefully no-oping on Canvas2D!
|
|
117
186
|
*/
|
|
118
187
|
export declare function createNormalLitSpritePass(scene: SceneHostLike, diffuseKey: string, normalKey: string, getQuadsAndLights: () => {
|
|
119
188
|
ambientRgb: number;
|
|
120
189
|
quads: ReadonlyArray<NormalLitQuad>;
|
|
121
|
-
lights: ReadonlyArray<
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
190
|
+
lights: ReadonlyArray<ScreenLightSample2D>;
|
|
191
|
+
}): CustomPassObject;
|
|
192
|
+
export interface SceneNormalLitPassOptions {
|
|
193
|
+
/** `Container` (e.g. `stage25d.billboardLayer`) or array of `DisplayObject`s traversed in painter's order. */
|
|
194
|
+
source: Container | ReadonlyArray<DisplayObject>;
|
|
195
|
+
/** `Lighting2DSystem` supplying live ambient color & flickering screen-space point lights. */
|
|
196
|
+
lighting: Lighting2DSystem;
|
|
197
|
+
/**
|
|
198
|
+
* `'rim'` (default): additive directional 3D normal-map rim & Blinn-Phong specular relief that pairs seamlessly with
|
|
199
|
+
* `Lighting2DSystem` without double-darkening shadows or occluding interleaved non-normal-mapped sprites!
|
|
200
|
+
* `'replace'`: full `base * (ambient + lights)` opaque draw in painter's order.
|
|
201
|
+
*/
|
|
202
|
+
mode?: 'rim' | 'replace';
|
|
203
|
+
/** Directional rim/specular intensity multiplier in `'rim'` mode (`default = 0.6`). */
|
|
204
|
+
rimStrength?: number;
|
|
205
|
+
/** Scene depth of this pass (`default = lighting.overlayImage.depth - 1` so `'rim'` sits right beneath darkness cutout or above sprites). */
|
|
206
|
+
depth?: number;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Scene-graph native 2D Normal-Map lighting pass: automatically traverses `source` (`stage25d.billboardLayer` or nested `Container`s),
|
|
210
|
+
* discovers matching `${texture.key}_normal` atlases registered by `@holtjs/craft`, transforms `customPivot` (`ax/ay`), `flipX`, `flipY`,
|
|
211
|
+
* `rotation`, and `skew` into tangent-space screen basis vectors, and batches consecutive same-atlas sprites into a single WebGL draw call!
|
|
212
|
+
*/
|
|
213
|
+
export declare function createSceneNormalLitPass(scene: SceneHostLike, opts: SceneNormalLitPassOptions): CustomPassObject;
|