dewdrop-sdk 0.12.0 → 0.14.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/package.json +1 -1
- package/src/three.d.ts +83 -25
- package/src/wgsl.d.ts +43 -28
- package/src/wgsl.js +4 -3
- package/src/wgsl.wasm +0 -0
package/package.json
CHANGED
package/src/three.d.ts
CHANGED
|
@@ -2,35 +2,46 @@
|
|
|
2
2
|
// types three.js with @types/three. Add `/// <reference types="dewdrop-sdk/three" />` to a file, or
|
|
3
3
|
// "dewdrop-sdk/three" to the "types" of its tsconfig.json or jsconfig.json.
|
|
4
4
|
/// <reference path="./wgsl.d.ts" />
|
|
5
|
-
import type { Color, ColorRepresentation, Material, MaterialParameters } from 'three';
|
|
5
|
+
import type { Color, ColorRepresentation, Material, MaterialParameters, Object3D, Texture } from 'three';
|
|
6
6
|
|
|
7
7
|
/** One point of `ExposureSettings.compensationCurve`: a scene's brightness in EV100, and how many stops
|
|
8
8
|
* brighter (positive) or darker (negative) than middle grey an adapting exposure shows it. */
|
|
9
9
|
export type CompensationPoint = readonly [ev100: number, stops: number];
|
|
10
10
|
|
|
11
|
-
/** How Dewdrop exposes the lit scene. Settings left out keep their defaults. */
|
|
11
|
+
/** How Dewdrop exposes and tones the lit scene. Settings left out keep their defaults. */
|
|
12
12
|
export interface ExposureSettings {
|
|
13
13
|
/** A fixed exposure in EV100, where each step up halves the brightness; `null` (the default) adapts to the
|
|
14
14
|
* scene. */
|
|
15
15
|
ev?: number | null;
|
|
16
|
+
/** How many stops brighter (positive) or darker (negative) an adapting exposure shows every scene, from −6
|
|
17
|
+
* to 6 (default 0). */
|
|
18
|
+
compensation?: number;
|
|
16
19
|
/** How much brighter or darker than middle grey an adapting exposure keeps a scene, by how bright the scene
|
|
17
|
-
* is: 1 to 8 points, straight lines between them. Default `[[-2, -2.5], [7, 0]]`. */
|
|
20
|
+
* is: 1 to 8 points, straight lines between them. Default `[[-8, -7], [-2, -2.5], [7, 0]]`. */
|
|
18
21
|
compensationCurve?: readonly CompensationPoint[];
|
|
19
22
|
/** How fast the exposure brightens (default 4). */
|
|
20
23
|
up?: number;
|
|
21
24
|
/** How fast the exposure darkens (default 10). */
|
|
22
25
|
down?: number;
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
|
|
29
|
-
/** How
|
|
30
|
-
|
|
31
|
-
/** Not a setting since dewdrop-sdk 0.
|
|
26
|
+
/** How much the bright areas of a picture are brought down, from 0, not at all, to 1 (default 0.7). */
|
|
27
|
+
highlightCompression?: number;
|
|
28
|
+
/** How much the dark areas of a picture are lifted, from 0, not at all, to 1 (default 0.6). */
|
|
29
|
+
shadowLift?: number;
|
|
30
|
+
/** Contrast around middle grey, from 0.5 to 2 (default 1). */
|
|
31
|
+
contrast?: number;
|
|
32
|
+
/** How strong the colors are, from 0, grey, to 2 (default 1). */
|
|
33
|
+
saturation?: number;
|
|
34
|
+
/** Not a setting since dewdrop-sdk 0.13.0: use `contrast`. */
|
|
35
|
+
shadowContrast?: never;
|
|
36
|
+
/** Not a setting since dewdrop-sdk 0.13.0: use `contrast`. */
|
|
37
|
+
highlightContrast?: never;
|
|
38
|
+
/** Not a setting since dewdrop-sdk 0.13.0: use `shadowLift`, from 0 to 1. */
|
|
39
|
+
localShadowsEv?: never;
|
|
40
|
+
/** Not a setting since dewdrop-sdk 0.13.0: use `highlightCompression`, from 0 to 1. */
|
|
41
|
+
localHighlightsEv?: never;
|
|
42
|
+
/** Not a setting since dewdrop-sdk 0.10.1: use `shadowLift`. */
|
|
32
43
|
localShadows?: never;
|
|
33
|
-
/** Not a setting since dewdrop-sdk 0.10.1: use `
|
|
44
|
+
/** Not a setting since dewdrop-sdk 0.10.1: use `highlightCompression`. */
|
|
34
45
|
localHighlights?: never;
|
|
35
46
|
/** Not a setting since dewdrop-sdk 0.10.1: an adapting exposure is shaped by `compensationCurve`. */
|
|
36
47
|
strength?: never;
|
|
@@ -41,13 +52,14 @@ export interface ExposureSettings {
|
|
|
41
52
|
/** The exposure as reading `renderer.exposure` gives it: every setting filled in. */
|
|
42
53
|
export interface ResolvedExposureSettings {
|
|
43
54
|
ev: number | null;
|
|
55
|
+
compensation: number;
|
|
44
56
|
compensationCurve: readonly CompensationPoint[];
|
|
45
57
|
up: number;
|
|
46
58
|
down: number;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
59
|
+
highlightCompression: number;
|
|
60
|
+
shadowLift: number;
|
|
61
|
+
contrast: number;
|
|
62
|
+
saturation: number;
|
|
51
63
|
}
|
|
52
64
|
|
|
53
65
|
declare module 'three' {
|
|
@@ -61,28 +73,38 @@ declare module 'three' {
|
|
|
61
73
|
* setting filled in. */
|
|
62
74
|
get exposure(): ResolvedExposureSettings | null;
|
|
63
75
|
set exposure(settings: ExposureSettings | null);
|
|
64
|
-
/**
|
|
65
|
-
*
|
|
76
|
+
/** Whether lights, glows and the sky's color are in real units: a sun in lux, a lamp in candela, a glow or
|
|
77
|
+
* the sky in nits. `false` (the default) reads them as three.js's own, where an intensity of 1 is an
|
|
78
|
+
* ordinary light. */
|
|
79
|
+
physicalLights: boolean;
|
|
80
|
+
/** The time in seconds a program reads as `time()`; it stays as set, so set it from the game's clock every
|
|
81
|
+
* frame. */
|
|
66
82
|
programTime: number;
|
|
67
83
|
}
|
|
68
84
|
|
|
69
85
|
interface DewMaterialParameters extends MaterialParameters {
|
|
70
|
-
/** The
|
|
86
|
+
/** The program, from `import sway from './sway.wgsl'`: a file with `fn vertex`, `fn fragment` or both. */
|
|
71
87
|
module?: Uint32Array | null;
|
|
72
88
|
/** The program's numbers: `param(0)`, `param(1)` and on. */
|
|
73
89
|
params?: Float32Array | null;
|
|
74
|
-
/** How far, in object units,
|
|
90
|
+
/** How far, in object units, `vertex` may move any vertex; a vertex is held within it. 0 unless set. */
|
|
75
91
|
maxDisplacement?: number;
|
|
76
|
-
/** What the mesh is drawn in
|
|
92
|
+
/** What the mesh is drawn in when the program has no `fragment`. */
|
|
77
93
|
color?: ColorRepresentation;
|
|
94
|
+
/** Up to four textures the program reads: `texture0(uv)` reads the first, and so on. */
|
|
95
|
+
textures?: (Texture | null)[];
|
|
96
|
+
/** How the surface takes light: `'diffuse'` (the default), matte, or `'standard'`, which reads the
|
|
97
|
+
* roughness and metalness `fragment` returns. */
|
|
98
|
+
shade?: 'diffuse' | 'standard';
|
|
78
99
|
/** Whether what it draws casts shadows; true unless set. */
|
|
79
100
|
castShadow?: boolean;
|
|
80
101
|
}
|
|
81
102
|
|
|
82
103
|
/**
|
|
83
|
-
* A material
|
|
84
|
-
* `
|
|
85
|
-
*
|
|
104
|
+
* A material drawn by a WGSL program: its `vertex` moves the mesh's vertices every frame, and its
|
|
105
|
+
* `fragment` colors each pixel of its surface. Without a `fragment` it is drawn in its `color` and lit as a
|
|
106
|
+
* `MeshLambertMaterial` is. A change to `module`, `maxDisplacement`, `color`, `textures` or `shade` shows
|
|
107
|
+
* once `needsUpdate` is set; a change to `params`, as often as every frame, once `paramsNeedUpdate` is.
|
|
86
108
|
*/
|
|
87
109
|
class DewMaterial extends Material {
|
|
88
110
|
constructor(parameters?: DewMaterialParameters);
|
|
@@ -91,8 +113,44 @@ declare module 'three' {
|
|
|
91
113
|
params: Float32Array | null;
|
|
92
114
|
maxDisplacement: number;
|
|
93
115
|
color: Color;
|
|
116
|
+
textures: (Texture | null)[];
|
|
117
|
+
shade: 'diffuse' | 'standard';
|
|
94
118
|
castShadow: boolean;
|
|
95
119
|
/** Set true after writing `params`, to send them. */
|
|
96
120
|
set paramsNeedUpdate(value: boolean);
|
|
97
121
|
}
|
|
122
|
+
|
|
123
|
+
interface ScreenProgramParameters {
|
|
124
|
+
/** The program, from `import grade from './grade.wgsl'`: a file with `fn output`. */
|
|
125
|
+
module?: Uint32Array | null;
|
|
126
|
+
/** The program's numbers: `param(0)`, `param(1)` and on. */
|
|
127
|
+
params?: Float32Array | null;
|
|
128
|
+
/** Which picture the program edits: `'output'`, the final one. Set it: it is not the default. */
|
|
129
|
+
stage?: 'output';
|
|
130
|
+
/** The pixels it runs at: `'full'` (the default), every one; or `'box'` or `'sphere'`, those showing a
|
|
131
|
+
* surface inside a box or ball round the object, 1 unit out from its centre each way at a scale of 1,
|
|
132
|
+
* placed and scaled in the scene as any object is. */
|
|
133
|
+
domain?: 'full' | 'box' | 'sphere';
|
|
134
|
+
/** When several are in the scene, the lowest `priority` runs first; 0 unless set. */
|
|
135
|
+
priority?: number;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* A WGSL program run over the final picture, as a post-processing pass is: add it to the scene and it
|
|
140
|
+
* runs every frame while it is visible. A change to `module`, `domain` or `priority` shows once `needsUpdate`
|
|
141
|
+
* is set; a change to `params`, as often as every frame, once `paramsNeedUpdate` is.
|
|
142
|
+
*/
|
|
143
|
+
class ScreenProgram extends Object3D {
|
|
144
|
+
constructor(parameters?: ScreenProgramParameters);
|
|
145
|
+
readonly isScreenProgram: true;
|
|
146
|
+
module: Uint32Array | null;
|
|
147
|
+
params: Float32Array | null;
|
|
148
|
+
stage: 'output';
|
|
149
|
+
domain: 'full' | 'box' | 'sphere';
|
|
150
|
+
priority: number;
|
|
151
|
+
/** Set true after changing anything but `params`, to register the program again. */
|
|
152
|
+
set needsUpdate(value: boolean);
|
|
153
|
+
/** Set true after writing `params`, to send them. */
|
|
154
|
+
set paramsNeedUpdate(value: boolean);
|
|
155
|
+
}
|
|
98
156
|
}
|
package/src/wgsl.d.ts
CHANGED
|
@@ -2,36 +2,51 @@
|
|
|
2
2
|
|
|
3
3
|
declare module '*.wgsl' {
|
|
4
4
|
/**
|
|
5
|
-
* The compiled
|
|
6
|
-
*
|
|
7
|
-
* runs for every vertex every frame and may use:
|
|
5
|
+
* The compiled program the file holds, which `vite build` makes with the game. What the file defines
|
|
6
|
+
* says what it is for:
|
|
8
7
|
*
|
|
9
|
-
* - `
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* - `param(i: u32) -> f32`, the material's number `i` (0 past the last);
|
|
15
|
-
* - `camera() -> vec3f`, the camera's position in the world;
|
|
16
|
-
* - `world(p: vec3f) -> vec3f`, object-space `p` in the world, each
|
|
17
|
-
* instance's own for an `InstancedMesh` (`world(vec3f(0.0))` is where
|
|
18
|
-
* the instance stands).
|
|
8
|
+
* - `fn vertex(v: Vertex) -> Moved` moves each vertex of a mesh, every frame, and
|
|
9
|
+
* `fn fragment(p: Point) -> Surface` colors each pixel of its surface. A file may hold either or both,
|
|
10
|
+
* and is the `module` of a `DewMaterial`.
|
|
11
|
+
* - `fn output(p: Pixel) -> vec3f` gives each pixel of the final picture its color, as a post-processing
|
|
12
|
+
* pass does. It is alone in its file, the `module` of a `ScreenProgram` whose `stage` is `'output'`.
|
|
19
13
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* `
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
14
|
+
* A material's functions use:
|
|
15
|
+
*
|
|
16
|
+
* - `struct Vertex { position: vec3f, normal: vec3f, uv: vec2f, color: vec4f, index: u32 }`, the vertex
|
|
17
|
+
* in object space, after skinning and morphs, and `struct Moved { position: vec3f, normal: vec3f }`,
|
|
18
|
+
* where it goes and its normal there;
|
|
19
|
+
* - `struct Point { position: vec3f, normal: vec3f, uv: vec2f, color: vec4f, front: bool }`, the point
|
|
20
|
+
* of the surface a pixel shows, in object space, with the geometry's texture coordinates and color;
|
|
21
|
+
* - `struct Surface { color: vec3f, opacity: f32, normal: vec3f, glow: vec3f, roughness: f32,
|
|
22
|
+
* metalness: f32 }`, what the point looks like; `plain(p)` is a white, opaque, matte one to start from.
|
|
23
|
+
* `glow` is in nits; `opacity` counts on a transparent material, and `roughness` and `metalness` on one
|
|
24
|
+
* whose `shade` is `'standard'`;
|
|
25
|
+
* - `texture0(uv)` to `texture3(uv)`, the material's `textures`, in `fragment`; and
|
|
26
|
+
* `texture0_level(uv, level)` to `texture3_level(uv, level)` anywhere;
|
|
27
|
+
* - `tint() -> vec3f`, the instance's color for an `InstancedMesh` or `BatchedMesh`, white otherwise;
|
|
28
|
+
* - `camera() -> vec3f`, the camera's position in the world, and `world(p: vec3f) -> vec3f`, object-space
|
|
29
|
+
* `p` in the world, each instance's own.
|
|
30
|
+
*
|
|
31
|
+
* The screen's function uses `struct Pixel { color: vec3f, at: vec2i, uv: vec2f }`, the pixel's color from
|
|
32
|
+
* 0 to 1, its column and row from the top left, and the same from 0 to 1; `size() -> vec2i`, the picture's
|
|
33
|
+
* size in pixels; and `color_at(at: vec2i) -> vec3f`, another pixel's color as it was before the program.
|
|
34
|
+
*
|
|
35
|
+
* Every function may use `time() -> f32`, `renderer.programTime` in seconds; `delta() -> f32`, the seconds
|
|
36
|
+
* since the last frame; and `param(i: u32) -> f32`, number `i` of the material's or the screen program's
|
|
37
|
+
* `params` (0 past the last).
|
|
38
|
+
*
|
|
39
|
+
* Programs use 32-bit types, declare no bindings or entry points, and leave out `discard` and a few
|
|
40
|
+
* built-in functions (`asinh`, `acosh`, `atanh`, `modf`, `frexp`, `ldexp`, the `pack` and `unpack`
|
|
41
|
+
* families, `firstLeadingBit`, `firstTrailingBit`, `countLeadingZeros`, `countTrailingZeros`,
|
|
42
|
+
* `extractBits`, `insertBits`, `reverseBits`, `quantizeToF16`, `determinant`, `dot4I8Packed`,
|
|
43
|
+
* `dot4U8Packed`); `dpdx`, `dpdy` and `fwidth` are `fragment`'s alone. A file is at most 64 KiB; its
|
|
44
|
+
* brackets nest at most 32 deep, a statement holds at most 512 operators, and an `if` chains at most 32
|
|
45
|
+
* `else if`. A program's variables hold at most 1,024 values in all, and its size and complexity are
|
|
46
|
+
* held to limits far past a sway, a painted cloth or a grade; one that reads textures in `fragment` has
|
|
47
|
+
* less room. Each vertex and pixel runs for a limited time each frame: a loop with a constant count that
|
|
48
|
+
* would run past it is refused, and one whose count the game sets (`param(i)`) is the program's own to
|
|
49
|
+
* keep to a few thousand passes. `vite build` says where a file goes outside any of these.
|
|
35
50
|
*/
|
|
36
51
|
const module: Uint32Array;
|
|
37
52
|
export default module;
|
package/src/wgsl.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
// Compiles a
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// Compiles a program from its WGSL file with `wgsl.wasm` — a material's,
|
|
2
|
+
// which defines `vertex`, `fragment` or both, or the screen's, which
|
|
3
|
+
// defines `output`: the program's code, or an error at a 1-based line and
|
|
4
|
+
// column of the file (0 and 0 for none) with its message.
|
|
4
5
|
import { readFileSync } from 'node:fs';
|
|
5
6
|
|
|
6
7
|
let compiled = null;
|
package/src/wgsl.wasm
CHANGED
|
Binary file
|