@driftengine/core 4.8.4 → 4.8.6
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.json +4332 -4250
- package/dist/build/shaderComments.js +0 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.js +11 -1
- package/dist/render/ambientHarmonics.d.ts +46 -0
- package/dist/render/ambientHarmonics.js +80 -0
- package/dist/render/areaLights.d.ts +19 -0
- package/dist/render/areaLights.js +20 -0
- package/dist/render/backend/api.d.ts +13 -2
- package/dist/render/backend/webgl2/instanced.d.ts +2 -0
- package/dist/render/backend/webgl2/instanced.js +11 -2
- package/dist/render/backend/webgl2/renderer.d.ts +74 -1
- package/dist/render/backend/webgl2/renderer.js +229 -37
- package/dist/render/backend/webgl2/skinScatter.d.ts +14 -0
- package/dist/render/backend/webgl2/skinScatter.js +88 -26
- package/dist/render/backend/webgpu/buffers.js +2 -1
- package/dist/render/backend/webgpu/clusterBinner.js +3 -2
- package/dist/render/backend/webgpu/flatPass.d.ts +7 -5
- package/dist/render/backend/webgpu/flatPass.js +15 -13
- package/dist/render/backend/webgpu/particlePass.d.ts +37 -4
- package/dist/render/backend/webgpu/particlePass.js +80 -12
- package/dist/render/backend/webgpu/postPass.d.ts +6 -1
- package/dist/render/backend/webgpu/postPass.js +7 -2
- package/dist/render/backend/webgpu/renderer.d.ts +58 -7
- package/dist/render/backend/webgpu/renderer.js +329 -78
- package/dist/render/backend/webgpu/shaders/clusterBin.wgsl.d.ts +1 -1
- package/dist/render/backend/webgpu/shaders/clusterBin.wgsl.js +41 -1
- package/dist/render/backend/webgpu/skinPaletteRing.d.ts +40 -28
- package/dist/render/backend/webgpu/skinPaletteRing.js +69 -32
- package/dist/render/backend/webgpu/skinScatterPass.d.ts +10 -2
- package/dist/render/backend/webgpu/skinScatterPass.js +59 -9
- package/dist/render/backend/webgpu/surfaceTexturePass.d.ts +2 -1
- package/dist/render/backend/webgpu/surfaceTexturePass.js +18 -4
- package/dist/render/bloomChain.d.ts +44 -0
- package/dist/render/bloomChain.js +28 -0
- package/dist/render/bloomPass.d.ts +3 -1
- package/dist/render/bloomPass.js +16 -2
- package/dist/render/clusteredLights.d.ts +55 -1
- package/dist/render/clusteredLights.js +182 -8
- package/dist/render/fixtureAtlas.js +1 -1
- package/dist/render/instanceCull.js +7 -0
- package/dist/render/instances.d.ts +32 -10
- package/dist/render/instances.js +17 -8
- package/dist/render/lightBudget.d.ts +26 -1
- package/dist/render/lightBudget.js +26 -3
- package/dist/render/lightmap.d.ts +102 -0
- package/dist/render/lightmap.js +118 -0
- package/dist/render/mesh.js +2 -1
- package/dist/render/particleBatch.d.ts +59 -3
- package/dist/render/particleBatch.js +53 -2
- package/dist/render/particleMaterial.d.ts +6 -1
- package/dist/render/particleMaterial.js +10 -2
- package/dist/render/particlePool.d.ts +11 -0
- package/dist/render/particlePool.js +2 -0
- package/dist/render/particleSort.d.ts +34 -0
- package/dist/render/particleSort.js +96 -0
- package/dist/render/sceneTarget.d.ts +5 -0
- package/dist/render/sceneTarget.js +8 -1
- package/dist/render/shaders/bloom.d.ts +8 -4
- package/dist/render/shaders/bloom.js +20 -3
- package/dist/render/shaders/flat/areaLight.d.ts +10 -0
- package/dist/render/shaders/flat/areaLight.js +96 -0
- package/dist/render/shaders/flat/index.js +30 -4
- package/dist/render/shaders/flat/main.d.ts +1 -1
- package/dist/render/shaders/flat/main.js +107 -105
- package/dist/render/shaders/flat/models.d.ts +16 -4
- package/dist/render/shaders/flat/models.js +64 -4
- package/dist/render/shaders/flat/normalMap.d.ts +10 -0
- package/dist/render/shaders/flat/normalMap.js +25 -0
- package/dist/render/shaders/flat/preamble.js +74 -37
- package/dist/render/shaders/flat/skin.js +6 -5
- package/dist/render/shaders/generated/bloom.wgsl.d.ts +13 -3
- package/dist/render/shaders/generated/bloom.wgsl.js +13 -3
- package/dist/render/shaders/generated/flat.wgsl.d.ts +1631 -2044
- package/dist/render/shaders/generated/flat.wgsl.js +1669 -2082
- package/dist/render/shaders/generated/particle.wgsl.d.ts +115 -1
- package/dist/render/shaders/generated/particle.wgsl.js +115 -1
- package/dist/render/shaders/generated/skinBlur.wgsl.d.ts +12 -2
- package/dist/render/shaders/generated/skinBlur.wgsl.js +12 -2
- package/dist/render/shaders/particle.d.ts +17 -1
- package/dist/render/shaders/particle.js +133 -1
- package/dist/render/shaders/skinBlur.js +25 -3
- package/dist/render/skinBlur.d.ts +8 -5
- package/dist/render/skinBlur.js +8 -5
- package/dist/render/surfaceModel.d.ts +21 -1
- package/dist/render/surfaceModel.js +22 -0
- package/dist/render/surfaceTexture.d.ts +14 -1
- package/dist/render/surfaceTexture.js +15 -2
- package/package.json +6 -6
- package/src/build/shaderComments.ts +0 -0
- package/src/index.ts +20 -1
- package/src/render/ambientHarmonics.ts +92 -0
- package/src/render/areaLights.ts +39 -0
- package/src/render/backend/api.ts +14 -1
- package/src/render/backend/webgl2/instanced.ts +12 -2
- package/src/render/backend/webgl2/renderer.ts +292 -35
- package/src/render/backend/webgl2/skinScatter.ts +120 -43
- package/src/render/backend/webgpu/buffers.ts +2 -1
- package/src/render/backend/webgpu/clusterBinner.ts +3 -1
- package/src/render/backend/webgpu/flatPass.ts +18 -13
- package/src/render/backend/webgpu/particlePass.ts +118 -12
- package/src/render/backend/webgpu/postPass.ts +7 -2
- package/src/render/backend/webgpu/renderer.ts +396 -95
- package/src/render/backend/webgpu/shaders/clusterBin.wgsl.ts +41 -1
- package/src/render/backend/webgpu/skinPaletteRing.ts +65 -33
- package/src/render/backend/webgpu/skinScatterPass.ts +59 -9
- package/src/render/backend/webgpu/surfaceTexturePass.ts +26 -5
- package/src/render/bloomChain.ts +69 -0
- package/src/render/bloomPass.ts +26 -2
- package/src/render/clusteredLights.ts +221 -7
- package/src/render/fixtureAtlas.ts +1 -1
- package/src/render/instanceCull.ts +5 -0
- package/src/render/instances.ts +40 -11
- package/src/render/lightBudget.ts +48 -2
- package/src/render/lightmap.ts +202 -0
- package/src/render/mesh.ts +2 -1
- package/src/render/particleBatch.ts +95 -4
- package/src/render/particleMaterial.ts +11 -1
- package/src/render/particlePool.ts +13 -0
- package/src/render/particleSort.ts +133 -0
- package/src/render/sceneTarget.ts +18 -1
- package/src/render/shaders/bloom.ts +20 -3
- package/src/render/shaders/flat/areaLight.ts +96 -0
- package/src/render/shaders/flat/index.ts +30 -4
- package/src/render/shaders/flat/main.ts +107 -105
- package/src/render/shaders/flat/models.ts +73 -8
- package/src/render/shaders/flat/normalMap.ts +25 -0
- package/src/render/shaders/flat/preamble.ts +74 -37
- package/src/render/shaders/flat/skin.ts +6 -5
- package/src/render/shaders/generated/bloom.wgsl.ts +13 -3
- package/src/render/shaders/generated/flat.wgsl.ts +1669 -2082
- package/src/render/shaders/generated/particle.wgsl.ts +116 -1
- package/src/render/shaders/generated/skinBlur.wgsl.ts +12 -2
- package/src/render/shaders/particle.ts +134 -1
- package/src/render/shaders/skinBlur.ts +25 -3
- package/src/render/skinBlur.ts +8 -5
- package/src/render/surfaceModel.ts +36 -1
- package/src/render/surfaceTexture.ts +41 -3
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
* the draw's model matrix and the eye's joint each draw, with `eyeAxisInWorld`.
|
|
19
19
|
*/
|
|
20
20
|
import type { Vec3 } from '../math/color.ts';
|
|
21
|
+
import { lightmapRegionOf } from './lightmap.ts';
|
|
22
|
+
import type { LightmapRegion } from './lightmap.ts';
|
|
21
23
|
|
|
22
24
|
/** Strands of brushed metal, satin or hair-like fibre: a highlight stretched across them. */
|
|
23
25
|
export interface AnisotropicModel {
|
|
@@ -77,8 +79,19 @@ export interface EyeModel {
|
|
|
77
79
|
readonly joint: number;
|
|
78
80
|
}
|
|
79
81
|
|
|
82
|
+
/**
|
|
83
|
+
* A surface whose static light was baked: the standard model, plus a lightmap page's light read at
|
|
84
|
+
* the mesh's second coordinates (`MeshData.lightmapUvs`). The material's `modelMap` is the page,
|
|
85
|
+
* from `createLightmap`; see `lightmap.ts` for what it adds and what it gives up.
|
|
86
|
+
*/
|
|
87
|
+
export interface LightmapModel {
|
|
88
|
+
readonly kind: 'lightmap';
|
|
89
|
+
/** Where this material's surfaces are on the page: `uv2 * scale + bias`. See `LightmapRegion`. */
|
|
90
|
+
readonly region: LightmapRegion;
|
|
91
|
+
}
|
|
92
|
+
|
|
80
93
|
/** Every model a material can name, by its `kind`: see `SurfaceMaterial.model`. */
|
|
81
|
-
export type SurfaceModel = AnisotropicModel | HairModel | SkinModel | EyeModel;
|
|
94
|
+
export type SurfaceModel = AnisotropicModel | HairModel | SkinModel | EyeModel | LightmapModel;
|
|
82
95
|
/** A model's name, which also picks its pipeline switch: `SURFACE_MODEL_SWITCH`. */
|
|
83
96
|
export type SurfaceModelKind = SurfaceModel['kind'];
|
|
84
97
|
|
|
@@ -88,6 +101,7 @@ export const SURFACE_MODEL_KINDS: readonly SurfaceModelKind[] = [
|
|
|
88
101
|
'hair',
|
|
89
102
|
'skin',
|
|
90
103
|
'eye',
|
|
104
|
+
'lightmap',
|
|
91
105
|
];
|
|
92
106
|
|
|
93
107
|
/** The lit stage's switch for each kind. */
|
|
@@ -96,6 +110,7 @@ export const SURFACE_MODEL_SWITCH: Readonly<Record<SurfaceModelKind, string>> =
|
|
|
96
110
|
hair: 'MODEL_HAIR',
|
|
97
111
|
skin: 'MODEL_SKIN',
|
|
98
112
|
eye: 'MODEL_EYE',
|
|
113
|
+
lightmap: 'MODEL_LIGHTMAP',
|
|
99
114
|
};
|
|
100
115
|
|
|
101
116
|
/** Floats a material's model takes: `uModelParams[2]`. */
|
|
@@ -188,6 +203,19 @@ export function eyeModel(
|
|
|
188
203
|
});
|
|
189
204
|
}
|
|
190
205
|
|
|
206
|
+
/**
|
|
207
|
+
* A baked surface, reading its region of a lightmap page: the whole page where none is named. An
|
|
208
|
+
* instanced batch's regions compose with this one, each instance's applied first: see
|
|
209
|
+
* `MeshInstances.lightmapRegions`.
|
|
210
|
+
*/
|
|
211
|
+
export function lightmapModel(options: { region?: LightmapRegion } = {}): LightmapModel {
|
|
212
|
+
const region = lightmapRegionOf(options.region);
|
|
213
|
+
return Object.freeze({
|
|
214
|
+
kind: 'lightmap',
|
|
215
|
+
region: Object.freeze([region[0], region[1], region[2], region[3]]) as LightmapRegion,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
191
219
|
/**
|
|
192
220
|
* A model's numbers into `out` — eight floats, `uModelParams[0]` then `[1]` — and whether a model
|
|
193
221
|
* map is bound into the last. Zeros for the standard model. An eye's axis goes in with the
|
|
@@ -197,6 +225,7 @@ export function eyeModel(
|
|
|
197
225
|
* - hair: shift, scatter, backlit, − · −, −, −, map
|
|
198
226
|
* - skin: the scatter colour, radius · transmission, profile, −, map
|
|
199
227
|
* - eye: iris radius, iris depth, ior, cornea roughness · the axis, map
|
|
228
|
+
* - lightmap: the region's scale and bias · −, −, −, map
|
|
200
229
|
*/
|
|
201
230
|
export function packModel(model: SurfaceModel | null, mapped: boolean, out: Float32Array): void {
|
|
202
231
|
out.fill(0);
|
|
@@ -230,6 +259,12 @@ export function packModel(model: SurfaceModel | null, mapped: boolean, out: Floa
|
|
|
230
259
|
out[5] = model.axis[1];
|
|
231
260
|
out[6] = model.axis[2];
|
|
232
261
|
return;
|
|
262
|
+
case 'lightmap':
|
|
263
|
+
out[0] = model.region[0];
|
|
264
|
+
out[1] = model.region[1];
|
|
265
|
+
out[2] = model.region[2];
|
|
266
|
+
out[3] = model.region[3];
|
|
267
|
+
return;
|
|
233
268
|
}
|
|
234
269
|
}
|
|
235
270
|
|
|
@@ -21,6 +21,8 @@ import { uploadCompressedArray } from './glCompressed.ts';
|
|
|
21
21
|
import { SURFACE_EFFECT_TEXELS, packSurfaceEffects } from './surfaceEffects.ts';
|
|
22
22
|
import type { SurfaceLayerEffect } from './surfaceEffects.ts';
|
|
23
23
|
import type { CutoutMode } from './cutoutDither.ts';
|
|
24
|
+
import { isLightmapTexels } from './lightmap.ts';
|
|
25
|
+
import type { LightmapTexels } from './lightmap.ts';
|
|
24
26
|
|
|
25
27
|
/**
|
|
26
28
|
* How a texture behaves past its edges and between its texels.
|
|
@@ -110,6 +112,18 @@ export interface SurfaceMaterial<Texture = SurfaceTexture> {
|
|
|
110
112
|
* without culling, and a back face is lit as its front, with the normal turned to the viewer.
|
|
111
113
|
*/
|
|
112
114
|
doubleSided?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* The lighting channels this surface takes light from, a mask: 1, 2, 3 … 255. **1 by default**,
|
|
117
|
+
* which is every light's default too, so a scene that names no channel is lit as it always was.
|
|
118
|
+
*
|
|
119
|
+
* A point or spot light shades this surface only where its `PointLightSet.lightChannels` and this
|
|
120
|
+
* share a bit — Unreal's lighting channels. A character's own key and rim lights on channel 2,
|
|
121
|
+
* and the character's materials on 3, light the character and leave the floor around it as the
|
|
122
|
+
* stage's lights alone have it. **What it does not reach**: the sun, the sky and the probes, area
|
|
123
|
+
* lights, DriftLight's volume and the GPU-driven pipeline light every surface whatever its mask.
|
|
124
|
+
* A number that is not a whole mask from 1 to 255 is channel 1.
|
|
125
|
+
*/
|
|
126
|
+
lightChannels?: number;
|
|
113
127
|
/**
|
|
114
128
|
* How hard the normal map turns the shading normal.
|
|
115
129
|
*
|
|
@@ -267,11 +281,15 @@ export class SurfaceTexture {
|
|
|
267
281
|
*/
|
|
268
282
|
constructor(
|
|
269
283
|
gl: WebGL2RenderingContext,
|
|
270
|
-
source: SurfaceSource | readonly SurfaceSource[],
|
|
284
|
+
source: SurfaceSource | readonly SurfaceSource[] | LightmapTexels,
|
|
271
285
|
options: SurfaceTextureOptions = {},
|
|
272
286
|
compressed: readonly CompressedTextureFormat[] = [],
|
|
273
287
|
) {
|
|
274
|
-
|
|
288
|
+
/* A lightmap's page: half floats, uploaded as they are. See `lightmap.ts`. */
|
|
289
|
+
const baked = isLightmapTexels(source) ? source : null;
|
|
290
|
+
const listed = (
|
|
291
|
+
baked !== null ? [] : Array.isArray(source) ? source : [source]
|
|
292
|
+
) as readonly SurfaceSource[];
|
|
275
293
|
const blocks = compressedLayers(listed);
|
|
276
294
|
this.srgb = (options.colorSpace ?? 'linear') === 'srgb';
|
|
277
295
|
/* Refused before anything is allocated, so a refusal leaves no texture behind. */
|
|
@@ -282,7 +300,27 @@ export class SurfaceTexture {
|
|
|
282
300
|
const wrap = (options.wrap ?? 'repeat') === 'repeat' ? gl.REPEAT : gl.CLAMP_TO_EDGE;
|
|
283
301
|
gl.bindTexture(gl.TEXTURE_2D_ARRAY, texture);
|
|
284
302
|
|
|
285
|
-
if (
|
|
303
|
+
if (baked !== null) {
|
|
304
|
+
/* No chain: a page is read at its own resolution, and a level of it would blend regions. */
|
|
305
|
+
this.layers = baked.layers;
|
|
306
|
+
this.blockFormat = null;
|
|
307
|
+
this.mipmapped = false;
|
|
308
|
+
/* A typed array refuses either flag set, so both are put down here rather than assumed. */
|
|
309
|
+
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
310
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
|
|
311
|
+
gl.texImage3D(
|
|
312
|
+
gl.TEXTURE_2D_ARRAY,
|
|
313
|
+
0,
|
|
314
|
+
gl.RGBA16F,
|
|
315
|
+
baked.width,
|
|
316
|
+
baked.height,
|
|
317
|
+
baked.layers,
|
|
318
|
+
0,
|
|
319
|
+
gl.RGBA,
|
|
320
|
+
gl.HALF_FLOAT,
|
|
321
|
+
baked.texels,
|
|
322
|
+
);
|
|
323
|
+
} else if (blocks !== null && plan !== null) {
|
|
286
324
|
/* The stored chain, or level 0 alone where no chain was asked for. Nothing is generated:
|
|
287
325
|
`generateMipmap` cannot write a compressed format. */
|
|
288
326
|
this.layers = blocks.length;
|