@margoengine/lighting2d 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.
@@ -0,0 +1,104 @@
1
+ /// <reference lib="esnext.disposable" preserve="true" />
2
+ import type { EngineKernel } from '@margoengine/core';
3
+ import { type Engine, type EnginePlugin } from '@margoengine/core/extension';
4
+ import { Light2D, type Light2DOptions, type Lighting2DOptions, type Occluder2D } from './index.js';
5
+ /** How coordinates outside [0, 1] behave when projecting a light cookie. */
6
+ export type CookieWrapMode = 'zero' | 'clamp' | 'repeat' | 'mirror';
7
+ /** How the cookie texture combines with the light color. */
8
+ export type CookieBlendMode = 'multiply' | 'alpha' | 'color';
9
+ /** Size and pixels of a cookie texture: width by height RGBA texels. */
10
+ export interface CookieTextureOptions {
11
+ width: number;
12
+ height: number;
13
+ /** RGBA byte data (0..255) or Float32Array (0..1). Length must be width * height * 4. */
14
+ data: ArrayLike<number>;
15
+ }
16
+ /** A 2D cookie / gobo texture for shaping 2D lights. */
17
+ export declare class CookieTexture2D {
18
+ readonly width: number;
19
+ readonly height: number;
20
+ readonly data: Float32Array;
21
+ constructor(options: CookieTextureOptions);
22
+ }
23
+ /** Creates a CookieTexture2D from raw RGBA data. */
24
+ export declare function createCookieTexture(width: number, height: number, data: ArrayLike<number>): CookieTexture2D;
25
+ /** Creates a window blinds cookie pattern with horizontal or vertical slats. */
26
+ export declare function createWindowCookie(width: number, height: number, slats?: number, vertical?: boolean): CookieTexture2D;
27
+ /** Creates a flashlight gobo pattern with a bright center and falloff rings. */
28
+ export declare function createSpotCookie(size: number, innerRatio?: number, outerRatio?: number): CookieTexture2D;
29
+ /** Samples a cookie texture at normalized coordinate (u, v) with wrapping. */
30
+ export declare function cookieSample(cookie: CookieTexture2D, u: number, v: number, wrap?: CookieWrapMode): [number, number, number, number];
31
+ /** Options for creating a CookieLight2D. */
32
+ export interface CookieLight2DOptions extends Light2DOptions {
33
+ /** Cookie texture to shape the light footprint. */
34
+ cookie?: CookieTexture2D;
35
+ /** Width and height of the cookie footprint in world units. Default is radius * 2 or 64. */
36
+ cookieScale?: number | readonly [number, number];
37
+ /** World offset of the cookie relative to the light position. Default [0, 0]. */
38
+ cookieOffset?: readonly [number, number];
39
+ /** Rotation angle of the cookie in radians. Default 0 (or light angle for spot). */
40
+ cookieRotation?: number;
41
+ /** Wrap mode outside [0, 1]: 'zero' (default), 'clamp', 'repeat', 'mirror'. */
42
+ cookieWrap?: CookieWrapMode;
43
+ /** Blend mode: 'multiply' (default), 'alpha', or 'color'. */
44
+ cookieMode?: CookieBlendMode;
45
+ }
46
+ /** One 2D light shaped by a cookie texture. */
47
+ export declare class CookieLight2D extends Light2D {
48
+ cookie?: CookieTexture2D;
49
+ cookieScale: [number, number];
50
+ cookieOffset: [number, number];
51
+ cookieRotation: number;
52
+ cookieWrap: CookieWrapMode;
53
+ cookieMode: CookieBlendMode;
54
+ constructor(options?: CookieLight2DOptions);
55
+ }
56
+ /**
57
+ * CPU evaluation of CookieLight2D at world coordinate (x, y) with normal.
58
+ * Computes base light attenuation and modulates by the sampled cookie texture.
59
+ */
60
+ export declare function cookieLightAt(light: CookieLight2D, x: number, y: number, normal?: readonly number[]): number[];
61
+ /** Options for CookieLighting2D: the plain lighting options plus the default cookie scale, wrap and blend for its lights. */
62
+ export interface CookieLighting2DOptions extends Lighting2DOptions {
63
+ /** Default cookie scale in world units if not set per light. Default 64. */
64
+ cookieScale?: number | readonly [number, number];
65
+ /** Default cookie wrap mode if not set per light. Default 'zero'. */
66
+ cookieWrap?: CookieWrapMode;
67
+ /** Default cookie blend mode if not set per light. Default 'multiply'. */
68
+ cookieMode?: CookieBlendMode;
69
+ }
70
+ /**
71
+ * 2D Lighting plugin with cookie / gobo texture support.
72
+ * WebGPU only.
73
+ */
74
+ export declare class CookieLighting2D implements EnginePlugin {
75
+ #private;
76
+ readonly name: string;
77
+ ambient: string;
78
+ camera: {
79
+ readonly x: number;
80
+ readonly y: number;
81
+ readonly zoom: number;
82
+ };
83
+ cookieScale: [number, number];
84
+ cookieWrap: CookieWrapMode;
85
+ cookieMode: CookieBlendMode;
86
+ readonly lights: CookieLight2D[];
87
+ layer: number;
88
+ constructor(options: CookieLighting2DOptions);
89
+ static attach(instance: EngineKernel, options: CookieLighting2DOptions): CookieLighting2D;
90
+ addLight(options?: CookieLight2DOptions): CookieLight2D;
91
+ removeLight(light: CookieLight2D): void;
92
+ setOccluders(occluders: readonly Occluder2D[]): void;
93
+ /**
94
+ * Replaces where the light goes, from the next frame: a texture, or a function read each frame. After a device
95
+ * restore, hand in a texture made on `engine.gpu` here.
96
+ */
97
+ setTarget(target: GPUTexture | (() => GPUTexture)): void;
98
+ /** Replaces the surface directions, from the next frame; undefined draws flat. After a device restore, hand in new ones here. */
99
+ setNormals(normals: GPUTexture | (() => GPUTexture) | undefined): void;
100
+ setup(engine: Engine): void;
101
+ onDeviceRestored(): void;
102
+ dispose(): void;
103
+ [Symbol.dispose]: () => void;
104
+ }