melonjs 19.2.0 → 19.3.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 +12 -10
- package/build/camera/camera2d.d.ts.map +1 -1
- package/build/index.js +1623 -529
- package/build/index.js.map +4 -4
- package/build/physics/bounds.d.ts +5 -2
- package/build/physics/bounds.d.ts.map +1 -1
- package/build/renderable/container.d.ts +1 -1
- package/build/renderable/container.d.ts.map +1 -1
- package/build/renderable/light2d.d.ts +128 -18
- package/build/renderable/light2d.d.ts.map +1 -1
- package/build/renderable/sprite.d.ts +38 -6
- package/build/renderable/sprite.d.ts.map +1 -1
- package/build/state/stage.d.ts +65 -9
- package/build/state/stage.d.ts.map +1 -1
- package/build/video/buffer/vertex.d.ts +2 -1
- package/build/video/buffer/vertex.d.ts.map +1 -1
- package/build/video/canvas/canvas_renderer.d.ts +2 -0
- package/build/video/canvas/canvas_renderer.d.ts.map +1 -1
- package/build/video/renderer.d.ts +62 -0
- package/build/video/renderer.d.ts.map +1 -1
- package/build/video/renderstate.d.ts +20 -0
- package/build/video/renderstate.d.ts.map +1 -1
- package/build/video/texture/atlas.d.ts +26 -2
- package/build/video/texture/atlas.d.ts.map +1 -1
- package/build/video/webgl/batchers/batcher.d.ts +6 -0
- package/build/video/webgl/batchers/batcher.d.ts.map +1 -1
- package/build/video/webgl/batchers/lit_quad_batcher.d.ts +109 -0
- package/build/video/webgl/batchers/lit_quad_batcher.d.ts.map +1 -0
- package/build/video/webgl/batchers/quad_batcher.d.ts +19 -1
- package/build/video/webgl/batchers/quad_batcher.d.ts.map +1 -1
- package/build/video/webgl/effects/radialGradient.d.ts +105 -0
- package/build/video/webgl/effects/radialGradient.d.ts.map +1 -0
- package/build/video/webgl/glshader.d.ts.map +1 -1
- package/build/video/webgl/lighting/constants.d.ts +13 -0
- package/build/video/webgl/lighting/constants.d.ts.map +1 -0
- package/build/video/webgl/lighting/pack.d.ts +76 -0
- package/build/video/webgl/lighting/pack.d.ts.map +1 -0
- package/build/video/webgl/shaders/multitexture-lit.d.ts +23 -0
- package/build/video/webgl/shaders/multitexture-lit.d.ts.map +1 -0
- package/build/video/webgl/webgl_renderer.d.ts +17 -0
- package/build/video/webgl/webgl_renderer.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -82,6 +82,26 @@ export default class RenderState {
|
|
|
82
82
|
* @param {boolean} [scissorTestActive=false] - whether scissor/clip is currently enabled
|
|
83
83
|
*/
|
|
84
84
|
save(scissorTestActive?: boolean): void;
|
|
85
|
+
/**
|
|
86
|
+
* Inspect the scissor box that the next `restore()` would install,
|
|
87
|
+
* without mutating any state. Lets renderers detect whether a
|
|
88
|
+
* pending `restore()` will actually change the scissor (and
|
|
89
|
+
* decide, e.g., whether to flush GPU work first).
|
|
90
|
+
*
|
|
91
|
+
* Returns:
|
|
92
|
+
* - `Int32Array` (length 4) — `[x, y, width, height]` of the
|
|
93
|
+
* saved scissor when scissor was active at the matching `save()`
|
|
94
|
+
* call.
|
|
95
|
+
* - `null` — when the saved state had scissor disabled, or the
|
|
96
|
+
* stack is empty. Treat this as "next scissor will be inactive".
|
|
97
|
+
*
|
|
98
|
+
* The returned array is a **live reference into the internal
|
|
99
|
+
* stack** — zero allocation on a hot path. Callers MUST treat it
|
|
100
|
+
* as read-only; mutating it corrupts subsequent `restore()` calls.
|
|
101
|
+
* @ignore
|
|
102
|
+
* @returns {Int32Array | null}
|
|
103
|
+
*/
|
|
104
|
+
peekScissor(): Int32Array | null;
|
|
85
105
|
/**
|
|
86
106
|
* Restore state from the stack.
|
|
87
107
|
* Color, tint, transform, and scissor are restored in place.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderstate.d.ts","sourceRoot":"","sources":["../../src/video/renderstate.js"],"names":[],"mappings":"AAGA;;GAEG;AAEH;;;;;;;GAOG;AACH;IAEE;;;OAGG;IACH,cAFU,KAAK,CAE4B;IAE3C;;;OAGG;IACH,aAFU,KAAK,CAEiC;IAEhD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AE9B;;;OAGG;IACH,eAFU,YAAY,GAAC,SAAS,CAEF;IAI9B;;OAEG;IACH,uBAAwB;IAExB;;;OAGG;IACH,oBAAoB;IAEpB,cAAc;IACd,qBAEE;IAEF,cAAc;IACd,oBAEE;IAEF,cAAc;IACd,yBAEE;IAEF,cAAc;IACd,yCAEE;IAEF,cAAc;IACd,sBAAoD;IAEpD,cAAc;IACd,wCAAyD;IAEzD,cAAc;IACd,sBAAoD;IAEpD,cAAc;IACd,mBAAiD;IAEjD,cAAc;IACd,oBAAkD;IAGnD;;;OAGG;IACH,yBAFW,OAAO,QAyBjB;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,eAFa,UAAU,GAAG,IAAI,CAQ7B;IAED;;;;;;;;OAQG;IACH,qBAJW,MAAM,gBACN,MAAM,GACJ;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAyBhE;IAED;;;;OAIG;IACH,aAHW,MAAM,UACN,MAAM,QAUhB;IAED,sDAAsD;IACtD,oBAiBC;CACD;sBA9OqB,oBAAoB;yBACjB,qBAAqB;8BAGnB,eAAe"}
|
|
@@ -46,7 +46,7 @@ export class TextureAtlas {
|
|
|
46
46
|
/**
|
|
47
47
|
* @param {object|object[]} atlases - atlas information. See {@link loader.getJSON}
|
|
48
48
|
* @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|CompressedImage|string|OffscreenCanvas[]|HTMLImageElement[]|HTMLCanvasElement[]|string[]} [src=atlas.meta.image] - Image source
|
|
49
|
-
* @param {boolean} [cache
|
|
49
|
+
* @param {boolean|object} [options] - either a boolean (legacy `cache` flag — `false` disables `TextureCache` registration; default behavior is to cache) or an options object `{ cache?: boolean, normalMap?: HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|ImageBitmap|string }`. When `normalMap` is provided, the atlas exposes a paired normal-map texture sharing the same UVs as the color texture (used by the WebGL renderer's lit pipeline). `HTMLVideoElement` is intentionally not supported as a normal map (would freeze on frame 0 due to per-image GL texture caching).
|
|
50
50
|
* @example
|
|
51
51
|
* // create a texture atlas from a JSON Object
|
|
52
52
|
* game.texture = new me.TextureAtlas(
|
|
@@ -68,8 +68,16 @@ export class TextureAtlas {
|
|
|
68
68
|
* anchorPoint : new me.Vector2d(0.5, 0.5)
|
|
69
69
|
* },
|
|
70
70
|
* me.loader.getImage("spritesheet")
|
|
71
|
+
* );
|
|
72
|
+
*
|
|
73
|
+
* // SpriteIlluminator workflow: pair the color atlas with its normal map
|
|
74
|
+
* game.texture = new me.TextureAtlas(
|
|
75
|
+
* me.loader.getJSON("scene"),
|
|
76
|
+
* me.loader.getImage("scene"),
|
|
77
|
+
* { normalMap: me.loader.getImage("scene_n") }
|
|
78
|
+
* );
|
|
71
79
|
*/
|
|
72
|
-
constructor(atlases: object | object[], src?: HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | CompressedImage | string | OffscreenCanvas[] | HTMLImageElement[] | HTMLCanvasElement[] | string[],
|
|
80
|
+
constructor(atlases: object | object[], src?: HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | CompressedImage | string | OffscreenCanvas[] | HTMLImageElement[] | HTMLCanvasElement[] | string[], options?: boolean | object);
|
|
73
81
|
/**
|
|
74
82
|
* to identify the atlas format (e.g. texture packer)
|
|
75
83
|
* @ignore
|
|
@@ -81,6 +89,14 @@ export class TextureAtlas {
|
|
|
81
89
|
* @ignore
|
|
82
90
|
*/
|
|
83
91
|
sources: Map<any, any>;
|
|
92
|
+
/**
|
|
93
|
+
* paired normal-map source(s), keyed identically to `sources`.
|
|
94
|
+
* Populated from the constructor's `options.normalMap`. Used by
|
|
95
|
+
* the WebGL renderer's lit pipeline for per-pixel lighting.
|
|
96
|
+
* @type {Map}
|
|
97
|
+
* @ignore
|
|
98
|
+
*/
|
|
99
|
+
normalSources: Map<any, any>;
|
|
84
100
|
/**
|
|
85
101
|
* the atlas dictionnaries
|
|
86
102
|
* @type {Map}
|
|
@@ -122,6 +138,14 @@ export class TextureAtlas {
|
|
|
122
138
|
* @returns {HTMLImageElement|HTMLCanvasElement}
|
|
123
139
|
*/
|
|
124
140
|
getTexture(region?: object): HTMLImageElement | HTMLCanvasElement;
|
|
141
|
+
/**
|
|
142
|
+
* Return the paired normal-map texture for the given region, or `null`
|
|
143
|
+
* if no normal map was provided to this atlas. The normal map shares
|
|
144
|
+
* the same UV layout as the color texture returned by {@link TextureAtlas#getTexture}.
|
|
145
|
+
* @param {object} [region] - region name in case of multipack textures
|
|
146
|
+
* @returns {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|ImageBitmap|null}
|
|
147
|
+
*/
|
|
148
|
+
getNormalTexture(region?: object): HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | ImageBitmap | null;
|
|
125
149
|
/**
|
|
126
150
|
* add a region to the atlas
|
|
127
151
|
* @param {string} name - region mame
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"atlas.d.ts","sourceRoot":"","sources":["../../../src/video/texture/atlas.js"],"names":[],"mappings":"AASA;;;GAGG;AAEH;;;GAGG;AACH;;;;;;;;;;;;;;;;;;;EAoBC;AAED;;;GAGG;AACH,+FAYC;AAED;;;;;;;;;;GAUG;AACH;IACC
|
|
1
|
+
{"version":3,"file":"atlas.d.ts","sourceRoot":"","sources":["../../../src/video/texture/atlas.js"],"names":[],"mappings":"AASA;;;GAGG;AAEH;;;GAGG;AACH;;;;;;;;;;;;;;;;;;;EAoBC;AAED;;;GAGG;AACH,+FAYC;AAED;;;;;;;;;;GAUG;AACH;IACC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;IACH,qBAjCW,MAAM,GAAC,MAAM,EAAE,QACf,gBAAgB,GAAC,iBAAiB,GAAC,eAAe,GAAC,eAAe,GAAC,MAAM,GAAC,eAAe,EAAE,GAAC,gBAAgB,EAAE,GAAC,iBAAiB,EAAE,GAAC,MAAM,EAAE,YAC3I,OAAO,GAAC,MAAM,EAsOxB;IAjMA;;;OAGG;IACH,sBAAkB;IAElB;;;;OAIG;IACH,uBAAwB;IAExB;;;;;;OAMG;IACH,6BAA8B;IAE9B;;;;OAIG;IACH,uBAAwB;IAExB;;;;OAIG;IACH,2BAA4B;IAE5B;;;OAGG;IACH;;;;;;MAA6D;IAW1D,YAA8C;IAgJlD;;;;OAIG;IACH,gBAHW,MAAM,GACJ,MAAM,CAQlB;IAED;;;OAGG;IACH,aAFa,MAAM,CAIlB;IAED;;;;OAIG;IACH,oBAHW,MAAM,GACJ,gBAAgB,GAAC,iBAAiB,CAQ9C;IAED;;;;;;OAMG;IACH,0BAHW,MAAM,GACJ,gBAAgB,GAAC,iBAAiB,GAAC,eAAe,GAAC,WAAW,GAAC,IAAI,CAU/E;IAED;;;;;;;;OAQG;IACH,gBAPW,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,GACJ,MAAM,CAmBlB;IAED;;;;;OAKG;IACH,gBAJW,MAAM,UACN,MAAM,GACJ,MAAM,CAiBlB;IAED;;;;;;;OAOG;IACH,aANW,MAAM,GAAC,MAAM,OACb,MAAM,OACN,MAAM,OACN,MAAM,GACJ,YAAY,CAsCxB;IAED;;;;;;;OAOG;IACH,cANW,MAAM,QACN,MAAM,KACN,MAAM,KACN,MAAM,GACJ,YAAY,CAoBxB;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,2BA1BW,MAAM,aACN,MAAM,cACN,OAAO,GACL,MAAM,GAAC,eAAe,CAqClC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,6BAnBW,MAAM,EAAE,GAAC,MAAM,EAAE,GAGf,MAAM,CAyElB;IAED,2DA2CC;CACD;mBAtqBkB,8BAA8B;iCAQjB,uCAAuC"}
|
|
@@ -116,6 +116,12 @@ export class Batcher {
|
|
|
116
116
|
* called by the WebGL renderer when a batcher becomes the current one
|
|
117
117
|
*/
|
|
118
118
|
bind(): void;
|
|
119
|
+
/**
|
|
120
|
+
* called by the WebGL renderer when this batcher is being replaced by another.
|
|
121
|
+
* Disables this batcher's vertex attribute locations so they don't leak across
|
|
122
|
+
* (otherwise stale stride/offset state can cause INVALID_OPERATION on the next draw).
|
|
123
|
+
*/
|
|
124
|
+
unbind(): void;
|
|
119
125
|
/**
|
|
120
126
|
* Select the shader to use for compositing
|
|
121
127
|
* @see GLShader
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batcher.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/batchers/batcher.js"],"names":[],"mappings":"AAmBA;;;;GAIG;AACH;IACC;;;;;;;;;;;;;;;OAeG;IACH,sBAfW,aAAa,YAErB;QAA2B,UAAU,EACrC;YAAoC,IAAI,EAAhC,MAAM;YACsB,IAAI,EAAhC,MAAM;YACsB,IAAI,EAAhC,MAAM;YACuB,UAAU,EAAvC,OAAO;YACqB,MAAM,EAAlC,MAAM;SACd;QAAyB,MAAM,EAC/B;YAAgC,MAAM,EAA9B,MAAM;YACkB,QAAQ,EAAhC,MAAM;SACd;QAA0B,WAAW;QACV,OAAO;QACR,iBAAiB;KAC7C,EAGA;IAED;;;OAGG;IACH,yCA6HC;IA3HA,cAAwB;IAGxB,QAAqB;IAGrB,gBAA2C;IAE3C;;;OAGG;IACH,oCAA8B;IAE9B;;;OAGG;IACH,oCAA8B;IAE9B;;;;OAIG;IACH,yBAA6B;IAE7B;;;;OAIG;IACH,iCAAoB;IAEpB;;;;;OAKG;IACH,2BAAe;IAEf;;;;;OAKG;IACH,+BAAmB;IAEnB;;;OAGG;IACH,0CAAsB;IAqCtB;;;OAGG;IACH,sCAA0E;IAE1E;;;OAGG;IACH,oCAA+C;IAE/C;;;;OAIG;IACH,+CAA0B;IAE1B;;;;OAIG;IACH,iDAAuB;IAUxB;;;OAGG;IACH,cAUC;IAED;;OAEG;IACH,aAYC;IAED;;;;OAIG;IACH,kBAFW,QAAQ,
|
|
1
|
+
{"version":3,"file":"bat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;+BADxB,wBAAwB"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* additional import for TypeScript
|
|
3
|
+
* @import {TextureAtlas} from "./../../texture/atlas.js";
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Lit-aware variant of `QuadBatcher` for the SpriteIlluminator workflow.
|
|
7
|
+
*
|
|
8
|
+
* Adds a 5th vertex attribute (`aNormalTextureId`) so each quad knows
|
|
9
|
+
* which paired normal-map sampler to read, and bundles the per-frame
|
|
10
|
+
* light uniforms (`uLightPos`, `uLightColor`, `uLightHeight`, `uAmbient`)
|
|
11
|
+
* that the lit fragment shader iterates.
|
|
12
|
+
*
|
|
13
|
+
* Texture-slot capacity is halved relative to `QuadBatcher` because each
|
|
14
|
+
* sprite may need a paired (color, normal) sampler — color goes to unit
|
|
15
|
+
* `n`, normal to unit `maxBatchTextures + n`. The `WebGLRenderer` only
|
|
16
|
+
* dispatches sprites here when the scene actually needs lighting (active
|
|
17
|
+
* `Light2d` AND the sprite has a `normalMap`); unlit sprites stay on
|
|
18
|
+
* `QuadBatcher` and pay nothing.
|
|
19
|
+
* @category Rendering
|
|
20
|
+
*/
|
|
21
|
+
export default class LitQuadBatcher extends QuadBatcher {
|
|
22
|
+
/**
|
|
23
|
+
* normal-map texture per color slot — keyed by the same unit index as
|
|
24
|
+
* `boundTextures`. Used by `addQuad` to detect when a normal-map slot
|
|
25
|
+
* needs (re-)uploading, mirroring the color-texture cache.
|
|
26
|
+
* @type {Array<HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|ImageBitmap|null>}
|
|
27
|
+
* @ignore
|
|
28
|
+
*/
|
|
29
|
+
boundNormalMaps: (ImageBitmap | HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | null)[] | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Map from a normal-map source image to its GL texture object.
|
|
32
|
+
* @type {Map<HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|ImageBitmap, WebGLTexture>}
|
|
33
|
+
* @ignore
|
|
34
|
+
*/
|
|
35
|
+
normalMapTextures: Map<ImageBitmap | HTMLImageElement | HTMLCanvasElement | OffscreenCanvas, WebGLTexture> | undefined;
|
|
36
|
+
_lightCount: number | undefined;
|
|
37
|
+
_maxLights: number | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Bind the paired normal sampler uniforms (`uNormalSampler0..N-1`)
|
|
40
|
+
* to texture units `maxBatchTextures..2*maxBatchTextures-1`. Called
|
|
41
|
+
* from `init` and `reset`.
|
|
42
|
+
* @ignore
|
|
43
|
+
*/
|
|
44
|
+
bindNormalSamplers(): void;
|
|
45
|
+
/**
|
|
46
|
+
* Upload per-frame Light2d uniforms used by the lit fragment path.
|
|
47
|
+
* Called once per camera per frame (before the world tree walk).
|
|
48
|
+
* Lights past `MAX_LIGHTS` are silently ignored.
|
|
49
|
+
*
|
|
50
|
+
* Coordinates must be supplied in the same space as the renderer's
|
|
51
|
+
* pre-projection vertex coords (i.e. camera-local / FBO-local),
|
|
52
|
+
* matching `Stage.drawLighting`'s convention.
|
|
53
|
+
* @param {object} uniforms
|
|
54
|
+
* @param {Float32Array} uniforms.positions - flat array of `[x, y, radius, intensity]` per light, length = 4 * count
|
|
55
|
+
* @param {Float32Array} uniforms.colors - flat array of `[r, g, b]` per light, length = 3 * count
|
|
56
|
+
* @param {Float32Array} [uniforms.heights] - flat array of per-light height, length = MAX_LIGHTS
|
|
57
|
+
* @param {number} uniforms.count - number of lights to render (clamped to MAX_LIGHTS)
|
|
58
|
+
* @param {number[]} [uniforms.ambient] - `[r, g, b]` ambient floor (0..1 each)
|
|
59
|
+
*/
|
|
60
|
+
setLightUniforms(uniforms: {
|
|
61
|
+
positions: Float32Array;
|
|
62
|
+
colors: Float32Array;
|
|
63
|
+
heights?: Float32Array<ArrayBufferLike> | undefined;
|
|
64
|
+
count: number;
|
|
65
|
+
ambient?: number[] | undefined;
|
|
66
|
+
}): void;
|
|
67
|
+
/**
|
|
68
|
+
* Bind a normal-map image to the given GL texture unit. Uploads on
|
|
69
|
+
* first use (via `uploadNormalMap`) and rebinds the cached
|
|
70
|
+
* `WebGLTexture` on subsequent calls. Mirrors the
|
|
71
|
+
* `bindTexture2D` / `createTexture2D` split used by `MaterialBatcher`,
|
|
72
|
+
* but for normal-map textures which live outside the color
|
|
73
|
+
* `TextureCache` (cached per-image in `normalMapTextures`).
|
|
74
|
+
* @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|ImageBitmap} image - normal-map source
|
|
75
|
+
* @param {number} unit - GL texture unit (already offset by `maxBatchTextures`)
|
|
76
|
+
*/
|
|
77
|
+
bindNormalMap(image: HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | ImageBitmap, unit: number): void;
|
|
78
|
+
/**
|
|
79
|
+
* Upload a normal-map image to GL and cache the resulting `WebGLTexture`
|
|
80
|
+
* for future `bindNormalMap` calls. Not meant to be called directly —
|
|
81
|
+
* `bindNormalMap` invokes this on the first use of a given image.
|
|
82
|
+
*
|
|
83
|
+
* `premultipliedAlpha = false` — normal maps store linear-encoded
|
|
84
|
+
* surface normals; multiplying through alpha would corrupt the
|
|
85
|
+
* encoding for any non-opaque texel.
|
|
86
|
+
* @param {HTMLImageElement|HTMLCanvasElement|OffscreenCanvas|ImageBitmap} image - normal-map source
|
|
87
|
+
* @param {number} unit - GL texture unit (already offset by `maxBatchTextures`)
|
|
88
|
+
*/
|
|
89
|
+
uploadNormalMap(image: HTMLImageElement | HTMLCanvasElement | OffscreenCanvas | ImageBitmap, unit: number): void;
|
|
90
|
+
/**
|
|
91
|
+
* Add a textured quad with optional paired normal map.
|
|
92
|
+
* @param {TextureAtlas} texture - Source texture atlas
|
|
93
|
+
* @param {number} x - Destination x-coordinate
|
|
94
|
+
* @param {number} y - Destination y-coordinate
|
|
95
|
+
* @param {number} w - Destination width
|
|
96
|
+
* @param {number} h - Destination height
|
|
97
|
+
* @param {number} u0 - Texture UV (u0) value
|
|
98
|
+
* @param {number} v0 - Texture UV (v0) value
|
|
99
|
+
* @param {number} u1 - Texture UV (u1) value
|
|
100
|
+
* @param {number} v1 - Texture UV (v1) value
|
|
101
|
+
* @param {number} tint - tint color (UINT32 argb)
|
|
102
|
+
* @param {boolean} [reupload=false] - Force the texture to be reuploaded
|
|
103
|
+
* @param {HTMLImageElement|HTMLCanvasElement|null} [normalMap=null] - paired normal-map (SpriteIlluminator workflow)
|
|
104
|
+
*/
|
|
105
|
+
addQuad(texture: TextureAtlas, x: number, y: number, w: number, h: number, u0: number, v0: number, u1: number, v1: number, tint: number, reupload?: boolean, normalMap?: HTMLImageElement | HTMLCanvasElement | null): void;
|
|
106
|
+
}
|
|
107
|
+
import QuadBatcher from "./quad_batcher.js";
|
|
108
|
+
import type { TextureAtlas } from "./../../texture/atlas.js";
|
|
109
|
+
//# sourceMappingURL=lit_quad_batcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lit_quad_batcher.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/batchers/lit_quad_batcher.js"],"names":[],"mappings":"AAKA;;;GAGG;AAEH;;;;;;;;;;;;;;;GAeG;AACH;IAoEE;;;;;;OAMG;IACH,6GAAmD;IAEnD;;;;OAIG;IACH,uHAAkC;IAElC,gCAAoB;IACpB,+BAA4B;IAK7B;;;;;OAKG;IACH,2BAOC;IAsBD;;;;;;;;;;;;;;OAcG;IACH,2BANG;QAA+B,SAAS,EAAhC,YAAY;QACW,MAAM,EAA7B,YAAY;QACY,OAAO;QACd,KAAK,EAAtB,MAAM;QACc,OAAO;KACrC,QAgBA;IAED;;;;;;;;;OASG;IACH,qBAHW,gBAAgB,GAAC,iBAAiB,GAAC,eAAe,GAAC,WAAW,QAC9D,MAAM,QAahB;IAED;;;;;;;;;;OAUG;IACH,uBAHW,gBAAgB,GAAC,iBAAiB,GAAC,eAAe,GAAC,WAAW,QAC9D,MAAM,QAiBhB;IAED;;;;;;;;;;;;;;OAcG;IACH,iBAbW,YAAY,KACZ,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,QACN,MAAM,aACN,OAAO,cACP,gBAAgB,GAAC,iBAAiB,GAAC,IAAI,QA0EjD;CAwDD;wBAtXoC,mBAAmB;kCAIzB,0BAA0B"}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* additional import for TypeScript
|
|
3
|
+
* @import {TextureAtlas} from "./../../texture/atlas.js";
|
|
4
|
+
*/
|
|
5
|
+
export const V_ARRAY: Vector2d[];
|
|
1
6
|
/**
|
|
2
7
|
* A WebGL Compositor object. This class handles all of the WebGL state<br>
|
|
3
8
|
* Pushes texture regions or shape geometry into WebGL buffers, automatically flushes to GPU
|
|
@@ -22,6 +27,18 @@ export default class QuadBatcher extends MaterialBatcher {
|
|
|
22
27
|
* @ignore
|
|
23
28
|
*/
|
|
24
29
|
useMultiTexture: boolean | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* (Re-)create the index buffer for quad batching (4 verts + 6 indices per quad).
|
|
32
|
+
* Called from `init` and `reset` (after context loss).
|
|
33
|
+
* @ignore
|
|
34
|
+
*/
|
|
35
|
+
createIndexBuffer(): void;
|
|
36
|
+
/**
|
|
37
|
+
* Bind the color sampler uniforms (`uSampler0..uSamplerN-1`) to their
|
|
38
|
+
* respective texture units. Called from `init` and `reset`.
|
|
39
|
+
* @ignore
|
|
40
|
+
*/
|
|
41
|
+
bindColorSamplers(): void;
|
|
25
42
|
/**
|
|
26
43
|
* Select the shader to use for compositing.
|
|
27
44
|
* Multi-texture batching is automatically enabled when the default
|
|
@@ -55,10 +72,11 @@ export default class QuadBatcher extends MaterialBatcher {
|
|
|
55
72
|
* @param {number} u1 - Texture UV (u1) value.
|
|
56
73
|
* @param {number} v1 - Texture UV (v1) value.
|
|
57
74
|
* @param {number} tint - tint color to be applied to the texture in UINT32 (argb) format
|
|
58
|
-
* @param {boolean} reupload - Force the texture to be reuploaded even if already bound
|
|
75
|
+
* @param {boolean} [reupload=false] - Force the texture to be reuploaded even if already bound
|
|
59
76
|
*/
|
|
60
77
|
addQuad(texture: TextureAtlas, x: number, y: number, w: number, h: number, u0: number, v0: number, u1: number, v1: number, tint: number, reupload?: boolean): void;
|
|
61
78
|
}
|
|
79
|
+
import { Vector2d } from "../../../math/vector2d.ts";
|
|
62
80
|
import { MaterialBatcher } from "./material_batcher.js";
|
|
63
81
|
import type { TextureAtlas } from "./../../texture/atlas.js";
|
|
64
82
|
//# sourceMappingURL=quad_batcher.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quad_batcher.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/batchers/quad_batcher.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"quad_batcher.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/batchers/quad_batcher.js"],"names":[],"mappings":"AAMA;;;GAGG;AAMH,iCAKE;AAEF;;;;GAIG;AACH;IACC;;;OAGG;IACH,0BAwDC;IAvDA;;;;OAIG;IACH,qCAA0D;IAyC1D;;;;;OAKG;IACH,qCAA2B;IAK5B;;;;OAIG;IACH,0BAQC;IAED;;;;OAIG;IACH,0BAIC;IAED;;;;;;;OAOG;IACH,kBAFW,QAAQ,GAAC,YAAY,QAK/B;IAoDD;;;;;;;;;;OAUG;IACH,oBAPW,YAAY,KACZ,MAAM,KACN,MAAM,SACN,MAAM,UACN,MAAM,UACN,QAAQ,GAAC,YAAY,QAoD/B;IAED;;;;;;;;;;;;;OAaG;IACH,iBAZW,YAAY,KACZ,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,QACN,MAAM,aACN,OAAO,QAqDjB;CACD;yBApTwB,2BAA2B;gCAIpB,uBAAuB;kCAIxB,0BAA0B"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* additional import for TypeScript
|
|
3
|
+
* @import { Color } from "../../../math/color.ts";
|
|
4
|
+
* @import { default as WebGLRenderer } from "../webgl_renderer.js";
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* A procedural radial-gradient shader effect: solid color at the center
|
|
8
|
+
* fading linearly to fully transparent at the edge of the host quad.
|
|
9
|
+
* The falloff is naturally elliptical for non-square quads.
|
|
10
|
+
*
|
|
11
|
+
* **UV-space caveat.** The `apply(color, uv)` function receives
|
|
12
|
+
* `vRegion` — the atlas UVs of the host quad. The falloff math
|
|
13
|
+
* (`length(uv * 2 - 1)`) assumes those UVs span `[0, 1] × [0, 1]`,
|
|
14
|
+
* which is true when the quad samples a full-rect texture (a
|
|
15
|
+
* dedicated 1×1 white pixel, a non-atlased Sprite, an FBO blit, or
|
|
16
|
+
* the engine-provided light atlas used by `WebGLRenderer.drawLight`).
|
|
17
|
+
* If you attach this effect to a Sprite that uses a *sub-region* of a
|
|
18
|
+
* larger atlas, `uv` will be in `[u0..u1] × [v0..v1]` and the radial
|
|
19
|
+
* center will be misplaced. For atlas-based renderables, set the
|
|
20
|
+
* effect's `uColor`/`uIntensity` and pair it with a Sprite whose
|
|
21
|
+
* texture covers a full atlas, or use a Sprite created from a
|
|
22
|
+
* standalone image.
|
|
23
|
+
*
|
|
24
|
+
* The falloff curve is **linear** (`f = clamp(1 - d, 0, 1)`) to match
|
|
25
|
+
* the Canvas 2D `createRadialGradient` two-stop output exactly. Output
|
|
26
|
+
* is premultiplied so the result composes correctly under additive
|
|
27
|
+
* (`"lighter"`) blending across overlapping quads.
|
|
28
|
+
*
|
|
29
|
+
* Color & intensity come from **two stacked sources**, multiplied
|
|
30
|
+
* together: the `uColor`/`uIntensity` uniforms (set per-effect via
|
|
31
|
+
* `setColor` / `setIntensity` — the natural API for a single-instance
|
|
32
|
+
* shader attached to a renderable) AND the per-vertex tint coming
|
|
33
|
+
* through `aColor` (used by `WebGLRenderer.drawLight` to encode each
|
|
34
|
+
* light's color + intensity in the vertex stream so multiple lights
|
|
35
|
+
* sharing this shader can batch into a single draw call). For typical
|
|
36
|
+
* standalone usage the per-vertex tint is `(1,1,1,1)` and the uniforms
|
|
37
|
+
* drive the look; for the Light2d batching path the uniforms stay at
|
|
38
|
+
* defaults and the tint carries everything.
|
|
39
|
+
* @category Effects
|
|
40
|
+
* @example
|
|
41
|
+
* // Soft white spot, 50% peak alpha at center
|
|
42
|
+
* const spot = new RadialGradientEffect(renderer, { intensity: 0.5 });
|
|
43
|
+
* @example
|
|
44
|
+
* // Tinted hotspot — orange center, full brightness, sized via the
|
|
45
|
+
* // host quad's bounds
|
|
46
|
+
* const hot = new RadialGradientEffect(renderer, {
|
|
47
|
+
* color: new Color(255, 128, 64),
|
|
48
|
+
* intensity: 1.0,
|
|
49
|
+
* });
|
|
50
|
+
* hot.setIntensity(2.0); // pulse brighter at runtime
|
|
51
|
+
* @example
|
|
52
|
+
* // Pickup highlight — attach to any Renderable so it renders inside
|
|
53
|
+
* // the renderable's bounding rect (anchorPoint applies). Combine with
|
|
54
|
+
* // `blendMode = "lighter"` for the additive glow look.
|
|
55
|
+
* pickup.shader = new RadialGradientEffect(renderer, {
|
|
56
|
+
* color: new Color(120, 255, 200), // mint green
|
|
57
|
+
* intensity: 0.8,
|
|
58
|
+
* });
|
|
59
|
+
* pickup.blendMode = "lighter";
|
|
60
|
+
* @example
|
|
61
|
+
* // Damage / impact indicator — short-lived elliptical flash on hit.
|
|
62
|
+
* // The quad's width/height drive the falloff aspect for free.
|
|
63
|
+
* const flash = new RadialGradientEffect(renderer, {
|
|
64
|
+
* color: new Color(255, 32, 32),
|
|
65
|
+
* intensity: 1.5,
|
|
66
|
+
* });
|
|
67
|
+
* // animate intensity to fade out
|
|
68
|
+
* tween.to({ intensity: 0 }, 200).onUpdate((s) => flash.setIntensity(s.intensity));
|
|
69
|
+
* @example
|
|
70
|
+
* // Debug overlay — draw a soft circle wherever the player is to mark
|
|
71
|
+
* // a trigger zone, without baking a texture per zone.
|
|
72
|
+
* const zoneMarker = new RadialGradientEffect(renderer, {
|
|
73
|
+
* color: new Color(80, 160, 255),
|
|
74
|
+
* intensity: 0.4,
|
|
75
|
+
* });
|
|
76
|
+
*/
|
|
77
|
+
export default class RadialGradientEffect extends ShaderEffect {
|
|
78
|
+
/**
|
|
79
|
+
* @param {WebGLRenderer} renderer - the current renderer instance
|
|
80
|
+
* @param {object} [options] - initial uniform values
|
|
81
|
+
* @param {Color} [options.color] - center color (0..255 RGB); defaults to white
|
|
82
|
+
* @param {number} [options.intensity=1] - peak alpha at the center (0..1+)
|
|
83
|
+
*/
|
|
84
|
+
constructor(renderer: WebGLRenderer, options?: {
|
|
85
|
+
color?: Color | undefined;
|
|
86
|
+
intensity?: number | undefined;
|
|
87
|
+
});
|
|
88
|
+
_colorBuf: Float32Array<ArrayBuffer>;
|
|
89
|
+
/**
|
|
90
|
+
* Set the center color. RGB only — alpha is ignored (the radial
|
|
91
|
+
* falloff supplies the per-pixel alpha).
|
|
92
|
+
* @param {Color} color - 0..255 RGB color
|
|
93
|
+
*/
|
|
94
|
+
setColor(color: Color): void;
|
|
95
|
+
/**
|
|
96
|
+
* Set the peak intensity. Acts as a brightness multiplier on the
|
|
97
|
+
* falloff curve; values above 1 over-saturate the center of the gradient.
|
|
98
|
+
* @param {number} intensity - 0..1+ multiplier
|
|
99
|
+
*/
|
|
100
|
+
setIntensity(intensity: number): void;
|
|
101
|
+
}
|
|
102
|
+
import ShaderEffect from "../shadereffect.js";
|
|
103
|
+
import type { Color } from "../../../math/color.ts";
|
|
104
|
+
import type { default as WebGLRenderer } from "../webgl_renderer.js";
|
|
105
|
+
//# sourceMappingURL=radialGradient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"radialGradient.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/effects/radialGradient.js"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsEG;AACH;IACC;;;;;OAKG;IACH,sBALW,aAAa,YAErB;QAAwB,KAAK;QACJ,SAAS;KACpC,EA0CA;IAZA,qCAAoC;IAcrC;;;;OAIG;IACH,gBAFW,KAAK,QAOf;IAED;;;;OAIG;IACH,wBAFW,MAAM,QAIhB;CACD;yBArJwB,oBAAoB;2BAInB,wBAAwB;8CACL,sBAAsB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"glshader.d.ts","sourceRoot":"","sources":["../../../src/video/webgl/glshader.js"],"names":[],"mappings":"AAOA;;;GAGG;AACH;IACC;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,gBA1BW,qBAAqB,UACrB,MAAM,YACN,MAAM,cACN,MAAM,EAyEhB;IAjDA;;;OAGG;IACH,IAFU,qBAAqB,CAEnB;IAEZ;;;OAGG;IACH,QAFU,MAAM,CAKf;IAED;;;OAGG;IACH,UAFU,MAAM,CAKf;IAED;;;OAGG;IACH,YAFU,KAAK,EAAE,CAEiC;IAElD;;;OAGG;IACH,SAFU,YAAY,CAOrB;IAED;;;OAGG;IACH,UAFU,MAAM,CAE8B;IAM/C;;OAEG;IACH,aAEC;IAED;;;;OAIG;IACH,wBAHW,MAAM,GACJ,KAAK,CASjB;IAED;;;;;;OAMG;IACH,iBALW,MAAM,SACN,MAAM,GAAC,YAAY,QAiB7B;IAED;;;;;OAKG;IACH,wBAJW,qBAAqB,cACrB,MAAM,EAAE,UACR,MAAM,
|
|
1
|
+
{"version":3,"file":"glshader.d.ts","sourceRoot":"","sources":["../../../src/video/webgl/glshader.js"],"names":[],"mappings":"AAOA;;;GAGG;AACH;IACC;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,gBA1BW,qBAAqB,UACrB,MAAM,YACN,MAAM,cACN,MAAM,EAyEhB;IAjDA;;;OAGG;IACH,IAFU,qBAAqB,CAEnB;IAEZ;;;OAGG;IACH,QAFU,MAAM,CAKf;IAED;;;OAGG;IACH,UAFU,MAAM,CAKf;IAED;;;OAGG;IACH,YAFU,KAAK,EAAE,CAEiC;IAElD;;;OAGG;IACH,SAFU,YAAY,CAOrB;IAED;;;OAGG;IACH,UAFU,MAAM,CAE8B;IAM/C;;OAEG;IACH,aAEC;IAED;;;;OAIG;IACH,wBAHW,MAAM,GACJ,KAAK,CASjB;IAED;;;;;;OAMG;IACH,iBALW,MAAM,SACN,MAAM,GAAC,YAAY,QAiB7B;IAED;;;;;OAKG;IACH,wBAJW,qBAAqB,cACrB,MAAM,EAAE,UACR,MAAM,QAmBhB;IAED;;OAEG;IACH,gBAQC;CACD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constants shared between the lit fragment shader (`multitexture-lit.js`),
|
|
3
|
+
* the lit batcher (`LitQuadBatcher`), and the uniform packer (`pack.ts`).
|
|
4
|
+
* Kept in a tiny standalone module so the three consumers don't depend on
|
|
5
|
+
* each other transitively for a single integer.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Maximum number of `Light2d` instances the lit fragment shader supports
|
|
9
|
+
* concurrently per draw call. Lights past this index are ignored. Sized
|
|
10
|
+
* to keep the GLSL uniform arrays comfortably within WebGL1 limits.
|
|
11
|
+
*/
|
|
12
|
+
export declare const MAX_LIGHTS = 8;
|
|
13
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/lighting/constants.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;GAIG;AACH,eAAO,MAAM,UAAU,IAAI,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-frame scratch buffer for `packLights()`. Pre-allocates one entry
|
|
3
|
+
* per light slot so the per-camera-per-frame upload doesn't allocate.
|
|
4
|
+
*/
|
|
5
|
+
export interface LightUniformScratch {
|
|
6
|
+
positions: Float32Array;
|
|
7
|
+
colors: Float32Array;
|
|
8
|
+
heights: Float32Array;
|
|
9
|
+
ambient: number[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Result of `packLights()` — typed-array views into the scratch plus the
|
|
13
|
+
* actual count. `WebGLRenderer.setLightUniforms` forwards this to
|
|
14
|
+
* `LitQuadBatcher.setLightUniforms` for upload.
|
|
15
|
+
*/
|
|
16
|
+
export interface LightUniforms extends LightUniformScratch {
|
|
17
|
+
count: number;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Allocate a fresh scratch buffer sized for `MAX_LIGHTS` slots. One per
|
|
21
|
+
* renderer is enough; reuse across frames.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createLightUniformScratch(): LightUniformScratch;
|
|
24
|
+
/**
|
|
25
|
+
* Light2d-shaped duck-type — anything `packLights()` reads from. Avoids
|
|
26
|
+
* importing `Light2d` directly (keeps this module renderer-agnostic).
|
|
27
|
+
*/
|
|
28
|
+
interface LightLike {
|
|
29
|
+
getBounds(): {
|
|
30
|
+
centerX: number;
|
|
31
|
+
centerY: number;
|
|
32
|
+
width: number;
|
|
33
|
+
height: number;
|
|
34
|
+
};
|
|
35
|
+
intensity: number;
|
|
36
|
+
color: {
|
|
37
|
+
r: number;
|
|
38
|
+
g: number;
|
|
39
|
+
b: number;
|
|
40
|
+
};
|
|
41
|
+
lightHeight: number;
|
|
42
|
+
}
|
|
43
|
+
/** Color-shaped duck-type for the ambient floor. */
|
|
44
|
+
interface ColorLike {
|
|
45
|
+
r: number;
|
|
46
|
+
g: number;
|
|
47
|
+
b: number;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Pack the active scene lights into the scratch buffer in a shape the
|
|
51
|
+
* lit fragment shader uploads directly.
|
|
52
|
+
*
|
|
53
|
+
* Light positions are translated from world-space (where
|
|
54
|
+
* `light.getBounds().centerX/Y` lives) into the renderer's
|
|
55
|
+
* pre-projection coords by subtracting `(translateX, translateY)` —
|
|
56
|
+
* the same translate `Camera2d.draw()` applies to the world container.
|
|
57
|
+
* This matches what `Stage.drawLighting` does for the cutout pass, so
|
|
58
|
+
* the lit fragment's `lightPos - vWorldPos` math lines up with the
|
|
59
|
+
* camera's view.
|
|
60
|
+
*
|
|
61
|
+
* Lights past `MAX_LIGHTS` (8) are silently dropped. Unused slots are
|
|
62
|
+
* zero-filled so stale data from a previous frame can't leak into the
|
|
63
|
+
* shader.
|
|
64
|
+
*
|
|
65
|
+
* Pure function: deterministic given the same inputs, no I/O, scratch
|
|
66
|
+
* is the only mutable target.
|
|
67
|
+
* @param lights - active lights iterable (e.g. `Stage._activeLights`); falsy treated as empty
|
|
68
|
+
* @param ambient - ambient floor color (0..255 RGB); falsy treated as black
|
|
69
|
+
* @param translateX - world-to-screen X translate (matches `Camera2d.draw()`)
|
|
70
|
+
* @param translateY - world-to-screen Y translate
|
|
71
|
+
* @param scratch - pre-allocated scratch (see `createLightUniformScratch`)
|
|
72
|
+
* @returns the scratch with `count` filled in
|
|
73
|
+
*/
|
|
74
|
+
export declare function packLights(lights: Iterable<LightLike> | null | undefined, ambient: ColorLike | null | undefined, translateX: number, translateY: number, scratch: LightUniformScratch): LightUniforms;
|
|
75
|
+
export {};
|
|
76
|
+
//# sourceMappingURL=pack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pack.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/lighting/pack.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IACnC,SAAS,EAAE,YAAY,CAAC;IACxB,MAAM,EAAE,YAAY,CAAC;IACrB,OAAO,EAAE,YAAY,CAAC;IACtB,OAAO,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAc,SAAQ,mBAAmB;IACzD,KAAK,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,IAAI,mBAAmB,CAO/D;AAED;;;GAGG;AACH,UAAU,SAAS;IAClB,SAAS,IAAI;QACZ,OAAO,EAAE,MAAM,CAAC;QAChB,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE,MAAM,CAAC;KACf,CAAC;IACF,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3C,WAAW,EAAE,MAAM,CAAC;CACpB;AAED,oDAAoD;AACpD,UAAU,SAAS;IAClB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACV;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,UAAU,CACzB,MAAM,EAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,IAAI,GAAG,SAAS,EAC9C,OAAO,EAAE,SAAS,GAAG,IAAI,GAAG,SAAS,EACrC,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,mBAAmB,GAC1B,aAAa,CA4Cf"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate the fragment shader for `LitQuadBatcher` — the SpriteIlluminator
|
|
3
|
+
* path that supports per-pixel normal-map lighting from up to `MAX_LIGHTS`
|
|
4
|
+
* point lights.
|
|
5
|
+
*
|
|
6
|
+
* Sprites without a `normalMap` push `aNormalTextureId = -1` and take the
|
|
7
|
+
* unlit fast path inside this same shader (sample color, multiply by
|
|
8
|
+
* vertex color, return) so lit and unlit sprites can share the lit batch
|
|
9
|
+
* when they coexist with active lights. The cost vs the truly-unlit
|
|
10
|
+
* `QuadBatcher` shader is one varying read + one comparison per fragment.
|
|
11
|
+
*
|
|
12
|
+
* The light's "height above the sprite plane" is encoded as a small
|
|
13
|
+
* fraction of the light's radius (default `0.075`) so that lights
|
|
14
|
+
* exactly at a fragment's screen position don't produce degenerate
|
|
15
|
+
* flat shading.
|
|
16
|
+
* @param {number} maxTextures - the number of color/normal texture units to support
|
|
17
|
+
* @returns {string} GLSL fragment shader source
|
|
18
|
+
* @ignore
|
|
19
|
+
*/
|
|
20
|
+
export function buildLitMultiTextureFragment(maxTextures: number): string;
|
|
21
|
+
export { MAX_LIGHTS };
|
|
22
|
+
import { MAX_LIGHTS } from "../lighting/constants.ts";
|
|
23
|
+
//# sourceMappingURL=multitexture-lit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multitexture-lit.d.ts","sourceRoot":"","sources":["../../../../src/video/webgl/shaders/multitexture-lit.js"],"names":[],"mappings":"AAgCA;;;;;;;;;;;;;;;;;;GAkBG;AACH,0DAJW,MAAM,GACJ,MAAM,CAiFlB;;2BAjI0B,0BAA0B"}
|
|
@@ -60,6 +60,7 @@ export default class WebGLRenderer extends Renderer {
|
|
|
60
60
|
x: number;
|
|
61
61
|
y: number;
|
|
62
62
|
}[];
|
|
63
|
+
_clipAABB: Bounds;
|
|
63
64
|
_polyVerts: any[];
|
|
64
65
|
_currentGradient: any;
|
|
65
66
|
/**
|
|
@@ -91,6 +92,8 @@ export default class WebGLRenderer extends Renderer {
|
|
|
91
92
|
* @default 1
|
|
92
93
|
*/
|
|
93
94
|
get WebGLVersion(): number;
|
|
95
|
+
_lightShader: RadialGradientEffect | undefined;
|
|
96
|
+
_lightAtlas: TextureAtlas | undefined;
|
|
94
97
|
/**
|
|
95
98
|
* add a new batcher to this renderer
|
|
96
99
|
* @param {Batcher} batcher - a batcher instance
|
|
@@ -122,6 +125,18 @@ export default class WebGLRenderer extends Renderer {
|
|
|
122
125
|
* let basic = renderer.createPattern(image, "no-repeat");
|
|
123
126
|
*/
|
|
124
127
|
createPattern(image: HTMLImageElement | SVGImageElement | HTMLVideoElement | HTMLCanvasElement | ImageBitmap | OffscreenCanvas | VideoFrame, repeat: string): TextureAtlas;
|
|
128
|
+
_lightUniformsScratch: import("./lighting/pack.ts").LightUniformScratch | undefined;
|
|
129
|
+
/**
|
|
130
|
+
* Lazy-init a shared 1×1 white `TextureAtlas` used as the source
|
|
131
|
+
* texture for `drawLight`'s procedural shader. The shader ignores
|
|
132
|
+
* the sampled color, but `addQuad`'s vertex format includes a
|
|
133
|
+
* texture-unit attribute so we still need a real texture; sharing
|
|
134
|
+
* one across every light keeps them on the same multi-texture slot
|
|
135
|
+
* (no flush on light switch).
|
|
136
|
+
* @returns {TextureAtlas}
|
|
137
|
+
* @ignore
|
|
138
|
+
*/
|
|
139
|
+
_getLightAtlas(): TextureAtlas;
|
|
125
140
|
/** @ignore */
|
|
126
141
|
endPostEffect(renderable: any): void;
|
|
127
142
|
/**
|
|
@@ -512,8 +527,10 @@ export default class WebGLRenderer extends Renderer {
|
|
|
512
527
|
}
|
|
513
528
|
import Renderer from "./../renderer.js";
|
|
514
529
|
import { Matrix3d } from "../../math/matrix3d.ts";
|
|
530
|
+
import { Bounds } from "../../physics/bounds.ts";
|
|
515
531
|
import type { Batcher } from "./batchers/batcher.js";
|
|
516
532
|
import TextureCache from "./../texture/cache.js";
|
|
533
|
+
import RadialGradientEffect from "./effects/radialGradient.js";
|
|
517
534
|
import { TextureAtlas } from "./../texture/atlas.js";
|
|
518
535
|
import { Color } from "./../../math/color.ts";
|
|
519
536
|
import type { Rect } from "./../../geometries/rectangle.ts";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webgl_renderer.d.ts","sourceRoot":"","sources":["../../../src/video/webgl/webgl_renderer.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"webgl_renderer.d.ts","sourceRoot":"","sources":["../../../src/video/webgl/webgl_renderer.js"],"names":[],"mappings":"AAqDA;;;GAGG;AACH;IAQE;;;;;OAKG;IACH,oBAJU,MAAM,CAIU;IAU1B;;;;OAIG;IACH,IAFU,qBAAqB,CAEI;IAYnC;;;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