@tinypoly/gpu-renderer 0.0.0-stage → 0.0.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/ARCHITECTURE.md +334 -0
- package/LICENSE +21 -0
- package/README.md +258 -2
- package/dist/accumulator.d.ts +27 -0
- package/dist/accumulator.d.ts.map +1 -0
- package/dist/accumulator.js +57 -0
- package/dist/accumulator.js.map +1 -0
- package/dist/bvh.d.ts +26 -0
- package/dist/bvh.d.ts.map +1 -0
- package/dist/bvh.js +207 -0
- package/dist/bvh.js.map +1 -0
- package/dist/camera.d.ts +29 -0
- package/dist/camera.d.ts.map +1 -0
- package/dist/camera.js +48 -0
- package/dist/camera.js.map +1 -0
- package/dist/canvas.d.ts +9 -0
- package/dist/canvas.d.ts.map +1 -0
- package/dist/canvas.js +11 -0
- package/dist/canvas.js.map +1 -0
- package/dist/denoise.d.ts +69 -0
- package/dist/denoise.d.ts.map +1 -0
- package/dist/denoise.js +455 -0
- package/dist/denoise.js.map +1 -0
- package/dist/device.d.ts +37 -0
- package/dist/device.d.ts.map +1 -0
- package/dist/device.js +52 -0
- package/dist/device.js.map +1 -0
- package/dist/dispatchScheduler.d.ts +43 -0
- package/dist/dispatchScheduler.d.ts.map +1 -0
- package/dist/dispatchScheduler.js +49 -0
- package/dist/dispatchScheduler.js.map +1 -0
- package/dist/environment.d.ts +39 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/environment.js +168 -0
- package/dist/environment.js.map +1 -0
- package/dist/frameLayout.d.ts +4 -0
- package/dist/frameLayout.d.ts.map +1 -0
- package/dist/frameLayout.js +58 -0
- package/dist/frameLayout.js.map +1 -0
- package/dist/geometry.d.ts +75 -0
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +671 -0
- package/dist/geometry.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/lights.d.ts +64 -0
- package/dist/lights.d.ts.map +1 -0
- package/dist/lights.js +264 -0
- package/dist/lights.js.map +1 -0
- package/dist/materialLayout.d.ts +143 -0
- package/dist/materialLayout.d.ts.map +1 -0
- package/dist/materialLayout.js +297 -0
- package/dist/materialLayout.js.map +1 -0
- package/dist/math.d.ts +10 -0
- package/dist/math.d.ts.map +1 -0
- package/dist/math.js +40 -0
- package/dist/math.js.map +1 -0
- package/dist/pathTracePass.d.ts +27 -0
- package/dist/pathTracePass.d.ts.map +1 -0
- package/dist/pathTracePass.js +83 -0
- package/dist/pathTracePass.js.map +1 -0
- package/dist/planarCapture.d.ts +38 -0
- package/dist/planarCapture.d.ts.map +1 -0
- package/dist/planarCapture.js +163 -0
- package/dist/planarCapture.js.map +1 -0
- package/dist/presentPass.d.ts +31 -0
- package/dist/presentPass.d.ts.map +1 -0
- package/dist/presentPass.js +78 -0
- package/dist/presentPass.js.map +1 -0
- package/dist/renderer.d.ts +196 -0
- package/dist/renderer.d.ts.map +1 -0
- package/dist/renderer.js +839 -0
- package/dist/renderer.js.map +1 -0
- package/dist/sceneAssets.d.ts +24 -0
- package/dist/sceneAssets.d.ts.map +1 -0
- package/dist/sceneAssets.js +77 -0
- package/dist/sceneAssets.js.map +1 -0
- package/dist/sceneUpload.d.ts +61 -0
- package/dist/sceneUpload.d.ts.map +1 -0
- package/dist/sceneUpload.js +98 -0
- package/dist/sceneUpload.js.map +1 -0
- package/dist/shaderModule.d.ts +7 -0
- package/dist/shaderModule.d.ts.map +1 -0
- package/dist/shaderModule.js +19 -0
- package/dist/shaderModule.js.map +1 -0
- package/dist/shaderProgram.d.ts +124 -0
- package/dist/shaderProgram.d.ts.map +1 -0
- package/dist/shaderProgram.js +1030 -0
- package/dist/shaderProgram.js.map +1 -0
- package/dist/structLayout.d.ts +28 -0
- package/dist/structLayout.d.ts.map +1 -0
- package/dist/structLayout.js +58 -0
- package/dist/structLayout.js.map +1 -0
- package/dist/texturePack.d.ts +54 -0
- package/dist/texturePack.d.ts.map +1 -0
- package/dist/texturePack.js +86 -0
- package/dist/texturePack.js.map +1 -0
- package/dist/upstream.d.ts +7 -0
- package/dist/upstream.d.ts.map +1 -0
- package/dist/upstream.js +11 -0
- package/dist/upstream.js.map +1 -0
- package/dist/volumetric.d.ts +10 -0
- package/dist/volumetric.d.ts.map +1 -0
- package/dist/volumetric.js +34 -0
- package/dist/volumetric.js.map +1 -0
- package/dist/wgsl/bsdf.wgsl.d.ts +13 -0
- package/dist/wgsl/bsdf.wgsl.d.ts.map +1 -0
- package/dist/wgsl/bsdf.wgsl.js +619 -0
- package/dist/wgsl/bsdf.wgsl.js.map +1 -0
- package/dist/wgsl/bvh.wgsl.d.ts +3 -0
- package/dist/wgsl/bvh.wgsl.d.ts.map +1 -0
- package/dist/wgsl/bvh.wgsl.js +218 -0
- package/dist/wgsl/bvh.wgsl.js.map +1 -0
- package/dist/wgsl/common.wgsl.d.ts +3 -0
- package/dist/wgsl/common.wgsl.d.ts.map +1 -0
- package/dist/wgsl/common.wgsl.js +193 -0
- package/dist/wgsl/common.wgsl.js.map +1 -0
- package/dist/wgsl/environment.wgsl.d.ts +10 -0
- package/dist/wgsl/environment.wgsl.d.ts.map +1 -0
- package/dist/wgsl/environment.wgsl.js +145 -0
- package/dist/wgsl/environment.wgsl.js.map +1 -0
- package/dist/wgsl/lights.wgsl.d.ts +10 -0
- package/dist/wgsl/lights.wgsl.d.ts.map +1 -0
- package/dist/wgsl/lights.wgsl.js +434 -0
- package/dist/wgsl/lights.wgsl.js.map +1 -0
- package/dist/wgsl/pathTrace.wgsl.d.ts +14 -0
- package/dist/wgsl/pathTrace.wgsl.d.ts.map +1 -0
- package/dist/wgsl/pathTrace.wgsl.js +1020 -0
- package/dist/wgsl/pathTrace.wgsl.js.map +1 -0
- package/dist/wgsl/present.wgsl.d.ts +7 -0
- package/dist/wgsl/present.wgsl.d.ts.map +1 -0
- package/dist/wgsl/present.wgsl.js +154 -0
- package/dist/wgsl/present.wgsl.js.map +1 -0
- package/dist/wgsl/random.wgsl.d.ts +9 -0
- package/dist/wgsl/random.wgsl.d.ts.map +1 -0
- package/dist/wgsl/random.wgsl.js +91 -0
- package/dist/wgsl/random.wgsl.js.map +1 -0
- package/dist/wgsl/sampling.wgsl.d.ts +3 -0
- package/dist/wgsl/sampling.wgsl.d.ts.map +1 -0
- package/dist/wgsl/sampling.wgsl.js +31 -0
- package/dist/wgsl/sampling.wgsl.js.map +1 -0
- package/dist/wgsl/shaderSupport.wgsl.d.ts +6 -0
- package/dist/wgsl/shaderSupport.wgsl.d.ts.map +1 -0
- package/dist/wgsl/shaderSupport.wgsl.js +120 -0
- package/dist/wgsl/shaderSupport.wgsl.js.map +1 -0
- package/dist/wgsl/surface.wgsl.d.ts +10 -0
- package/dist/wgsl/surface.wgsl.d.ts.map +1 -0
- package/dist/wgsl/surface.wgsl.js +794 -0
- package/dist/wgsl/surface.wgsl.js.map +1 -0
- package/dist/wgsl/texture.wgsl.d.ts +11 -0
- package/dist/wgsl/texture.wgsl.d.ts.map +1 -0
- package/dist/wgsl/texture.wgsl.js +132 -0
- package/dist/wgsl/texture.wgsl.js.map +1 -0
- package/package.json +76 -3
- package/src/accumulator.ts +64 -0
- package/src/bvh.ts +272 -0
- package/src/camera.ts +77 -0
- package/src/canvas.ts +13 -0
- package/src/denoise.ts +514 -0
- package/src/device.ts +81 -0
- package/src/dispatchScheduler.ts +71 -0
- package/src/environment.ts +233 -0
- package/src/frameLayout.ts +59 -0
- package/src/geometry.ts +899 -0
- package/src/index.ts +61 -0
- package/src/lights.ts +365 -0
- package/src/materialLayout.ts +408 -0
- package/src/math.ts +48 -0
- package/src/pathTracePass.ts +97 -0
- package/src/planarCapture.ts +225 -0
- package/src/presentPass.ts +99 -0
- package/src/renderer.ts +1117 -0
- package/src/sceneAssets.ts +118 -0
- package/src/sceneUpload.ts +185 -0
- package/src/shaderModule.ts +19 -0
- package/src/shaderProgram.ts +1370 -0
- package/src/structLayout.ts +93 -0
- package/src/texturePack.ts +152 -0
- package/src/upstream.ts +56 -0
- package/src/volumetric.ts +42 -0
- package/src/wgsl/bsdf.wgsl.ts +618 -0
- package/src/wgsl/bvh.wgsl.ts +217 -0
- package/src/wgsl/common.wgsl.ts +193 -0
- package/src/wgsl/environment.wgsl.ts +144 -0
- package/src/wgsl/lights.wgsl.ts +433 -0
- package/src/wgsl/pathTrace.wgsl.ts +1019 -0
- package/src/wgsl/present.wgsl.ts +153 -0
- package/src/wgsl/random.wgsl.ts +90 -0
- package/src/wgsl/sampling.wgsl.ts +30 -0
- package/src/wgsl/shaderSupport.wgsl.ts +119 -0
- package/src/wgsl/surface.wgsl.ts +793 -0
- package/src/wgsl/texture.wgsl.ts +131 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { RenderEnvironment, SerializedTexture } from "./upstream.js";
|
|
2
|
+
/**
|
|
3
|
+
* The light that surrounds the scene. A gradient is three numbers the shader evaluates directly; an equirectangular
|
|
4
|
+
* image is a texture plus the tables that let a shadow ray aim at its bright parts.
|
|
5
|
+
*
|
|
6
|
+
* Without those tables a sun in an image is exactly the problem direct light sampling exists to solve: a tiny, very
|
|
7
|
+
* bright region that a cosine weighted bounce almost never finds. The construction is the one in `environment.js` of
|
|
8
|
+
* the CPU renderer: a cumulative distribution over rows weighted by luminance and the sine of the colatitude, then one
|
|
9
|
+
* over the columns of each row.
|
|
10
|
+
*/
|
|
11
|
+
export interface PackedEnvironment {
|
|
12
|
+
/** The image itself, ready to join the scene's own textures. */
|
|
13
|
+
texture: SerializedTexture;
|
|
14
|
+
/** Rows, then each row's columns, then the luminance of every texel: `2 * width * height + height` floats. */
|
|
15
|
+
distribution: Float32Array;
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
/** The sum of luminance times the sine of the colatitude, which turns a texel's share into a density. */
|
|
19
|
+
total: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Cumulative distributions over the reduced image. A row is weighted by the sine of its colatitude, because a row near
|
|
23
|
+
* a pole covers far less of the sphere than one at the equator.
|
|
24
|
+
*/
|
|
25
|
+
export declare function environmentDistribution(grid: Float32Array, width: number, height: number): {
|
|
26
|
+
distribution: Float32Array<ArrayBuffer>;
|
|
27
|
+
total: number;
|
|
28
|
+
} | null;
|
|
29
|
+
/**
|
|
30
|
+
* Loads an equirectangular image and builds everything the shader needs from it. Returns null for an environment that
|
|
31
|
+
* is not an image, or one whose file could not be read, which leaves the renderer on its gradient.
|
|
32
|
+
*/
|
|
33
|
+
export declare function loadEnvironment(environment: RenderEnvironment): Promise<PackedEnvironment | null>;
|
|
34
|
+
/**
|
|
35
|
+
* An equirectangular image already in memory, linear RGBA floats with the zenith in the first row, made into an
|
|
36
|
+
* environment: a procedural sky baked by the CPU renderer's interpreter arrives this way.
|
|
37
|
+
*/
|
|
38
|
+
export declare function environmentFromImage(data: Float32Array, sourceWidth: number, sourceHeight: number, id?: string): PackedEnvironment | null;
|
|
39
|
+
//# sourceMappingURL=environment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.d.ts","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE1E;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IAChC,gEAAgE;IAChE,OAAO,EAAE,iBAAiB,CAAC;IAC3B,8GAA8G;IAC9G,YAAY,EAAE,YAAY,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,yGAAyG;IACzG,KAAK,EAAE,MAAM,CAAC;CACf;AAsFD;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;SAuCxF;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,WAAW,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAqBvG;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,SAAgB,GAAG,iBAAiB,GAAG,IAAI,CAgD7G"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { HDRLoader } from "three/examples/jsm/loaders/HDRLoader.js";
|
|
2
|
+
/** The grid the distribution is built on, as in the CPU renderer. Finer than this buys nothing but memory. */
|
|
3
|
+
const GRID_WIDTH = 256;
|
|
4
|
+
const GRID_HEIGHT = 128;
|
|
5
|
+
/** How large an image is kept for the sharp lookup. A full resolution sky costs more memory than it adds detail here. */
|
|
6
|
+
const MAX_WIDTH = 1024;
|
|
7
|
+
const luminance = (r, g, b) => 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
8
|
+
/** An area averaged reduction to `width` by `height`, which is what the distribution is built from. */
|
|
9
|
+
function reduce(source, sourceWidth, sourceHeight, width, height) {
|
|
10
|
+
const target = new Float32Array(width * height * 3);
|
|
11
|
+
const scaleX = sourceWidth / width, scaleY = sourceHeight / height;
|
|
12
|
+
for (let y = 0; y < height; y++) {
|
|
13
|
+
for (let x = 0; x < width; x++) {
|
|
14
|
+
const x0 = Math.floor(x * scaleX), x1 = Math.max(x0 + 1, Math.ceil((x + 1) * scaleX));
|
|
15
|
+
const y0 = Math.floor(y * scaleY), y1 = Math.max(y0 + 1, Math.ceil((y + 1) * scaleY));
|
|
16
|
+
let r = 0, g = 0, b = 0, n = 0;
|
|
17
|
+
for (let sy = y0; sy < Math.min(sourceHeight, y1); sy++) {
|
|
18
|
+
for (let sx = x0; sx < Math.min(sourceWidth, x1); sx++) {
|
|
19
|
+
const at = (sy * sourceWidth + sx) * 4;
|
|
20
|
+
r += source[at];
|
|
21
|
+
g += source[at + 1];
|
|
22
|
+
b += source[at + 2];
|
|
23
|
+
n++;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const at = (y * width + x) * 3;
|
|
27
|
+
const weight = n || 1;
|
|
28
|
+
target[at] = r / weight;
|
|
29
|
+
target[at + 1] = g / weight;
|
|
30
|
+
target[at + 2] = b / weight;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return target;
|
|
34
|
+
}
|
|
35
|
+
/** Never picked less often than this share of the average, so no direction is left without a density. */
|
|
36
|
+
const FLOOR = 0.02;
|
|
37
|
+
/**
|
|
38
|
+
* The luminance a direction is picked by. It is the neighbourhood's brightest rather than the texel's own, because the
|
|
39
|
+
* image is read back with a bilinear filter: that filter spreads a sun into the texels around it, and a direction the
|
|
40
|
+
* distribution gave no chance of being picked would arrive through the bounce alone, as a firefly. Taking the maximum
|
|
41
|
+
* over the neighbours keeps the density above what the filter can produce there.
|
|
42
|
+
*/
|
|
43
|
+
function weights(grid, width, height) {
|
|
44
|
+
const raw = new Float32Array(width * height);
|
|
45
|
+
const spread = new Float32Array(width * height);
|
|
46
|
+
let sum = 0;
|
|
47
|
+
for (let index = 0; index < width * height; index++) {
|
|
48
|
+
raw[index] = luminance(grid[index * 3], grid[index * 3 + 1], grid[index * 3 + 2]);
|
|
49
|
+
sum += raw[index];
|
|
50
|
+
}
|
|
51
|
+
const floor = sum / (width * height) * FLOOR;
|
|
52
|
+
for (let y = 0; y < height; y++) {
|
|
53
|
+
for (let x = 0; x < width; x++) {
|
|
54
|
+
let peak = 0;
|
|
55
|
+
for (let dy = -1; dy <= 1; dy++) {
|
|
56
|
+
const row = Math.min(Math.max(y + dy, 0), height - 1);
|
|
57
|
+
for (let dx = -1; dx <= 1; dx++) {
|
|
58
|
+
// Longitude wraps around, so the texel left of the first column is the last one.
|
|
59
|
+
peak = Math.max(peak, raw[row * width + (x + dx + width) % width]);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
spread[y * width + x] = peak + floor;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return spread;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Cumulative distributions over the reduced image. A row is weighted by the sine of its colatitude, because a row near
|
|
69
|
+
* a pole covers far less of the sphere than one at the equator.
|
|
70
|
+
*/
|
|
71
|
+
export function environmentDistribution(grid, width, height) {
|
|
72
|
+
const rows = new Float32Array(height);
|
|
73
|
+
const columns = new Float32Array(width * height);
|
|
74
|
+
const values = weights(grid, width, height);
|
|
75
|
+
let total = 0;
|
|
76
|
+
for (let y = 0; y < height; y++) {
|
|
77
|
+
const sine = Math.sin((y + 0.5) / height * Math.PI);
|
|
78
|
+
let row = 0;
|
|
79
|
+
for (let x = 0; x < width; x++) {
|
|
80
|
+
const index = y * width + x;
|
|
81
|
+
row += values[index] * sine;
|
|
82
|
+
columns[index] = row;
|
|
83
|
+
}
|
|
84
|
+
for (let x = 0; x < width; x++) {
|
|
85
|
+
const index = y * width + x;
|
|
86
|
+
// A row with nothing in it is still chosen uniformly, so a search over it always terminates somewhere.
|
|
87
|
+
columns[index] = row > 0 ? columns[index] / row : (x + 1) / width;
|
|
88
|
+
}
|
|
89
|
+
total += row;
|
|
90
|
+
rows[y] = total;
|
|
91
|
+
}
|
|
92
|
+
if (!(total > 0))
|
|
93
|
+
return null;
|
|
94
|
+
for (let y = 0; y < height; y++)
|
|
95
|
+
rows[y] /= total;
|
|
96
|
+
const distribution = new Float32Array(height + width * height * 2);
|
|
97
|
+
distribution.set(rows, 0);
|
|
98
|
+
distribution.set(columns, height);
|
|
99
|
+
distribution.set(values, height + width * height);
|
|
100
|
+
return { distribution, total };
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Loads an equirectangular image and builds everything the shader needs from it. Returns null for an environment that
|
|
104
|
+
* is not an image, or one whose file could not be read, which leaves the renderer on its gradient.
|
|
105
|
+
*/
|
|
106
|
+
export async function loadEnvironment(environment) {
|
|
107
|
+
if (environment.kind !== "hdri" || !environment.url)
|
|
108
|
+
return null;
|
|
109
|
+
const loaded = await new Promise(resolve => {
|
|
110
|
+
new HDRLoader()
|
|
111
|
+
.setDataType(1015)
|
|
112
|
+
.load(environment.url, texture => {
|
|
113
|
+
const image = texture.image;
|
|
114
|
+
resolve(image?.data instanceof Float32Array ? image : null);
|
|
115
|
+
texture.dispose();
|
|
116
|
+
}, undefined, () => resolve(null));
|
|
117
|
+
});
|
|
118
|
+
if (!loaded || loaded.width < 1 || loaded.height < 1)
|
|
119
|
+
return null;
|
|
120
|
+
return environmentFromImage(loaded.data, loaded.width, loaded.height);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* An equirectangular image already in memory, linear RGBA floats with the zenith in the first row, made into an
|
|
124
|
+
* environment: a procedural sky baked by the CPU renderer's interpreter arrives this way.
|
|
125
|
+
*/
|
|
126
|
+
export function environmentFromImage(data, sourceWidth, sourceHeight, id = "environment") {
|
|
127
|
+
const loaded = { data, width: sourceWidth, height: sourceHeight };
|
|
128
|
+
if (loaded.width < 1 || loaded.height < 1 || data.length < loaded.width * loaded.height * 4)
|
|
129
|
+
return null;
|
|
130
|
+
// The sharp lookup keeps at most MAX_WIDTH across; the distribution is built on a much coarser grid either way.
|
|
131
|
+
const width = Math.min(loaded.width, MAX_WIDTH);
|
|
132
|
+
const height = Math.max(1, Math.round(loaded.height * (width / loaded.width)));
|
|
133
|
+
const scaled = width === loaded.width
|
|
134
|
+
? loaded.data
|
|
135
|
+
: (() => {
|
|
136
|
+
const reduced = reduce(loaded.data, loaded.width, loaded.height, width, height);
|
|
137
|
+
const rgba = new Float32Array(width * height * 4);
|
|
138
|
+
for (let texel = 0; texel < width * height; texel++) {
|
|
139
|
+
rgba[texel * 4] = reduced[texel * 3];
|
|
140
|
+
rgba[texel * 4 + 1] = reduced[texel * 3 + 1];
|
|
141
|
+
rgba[texel * 4 + 2] = reduced[texel * 3 + 2];
|
|
142
|
+
rgba[texel * 4 + 3] = 1;
|
|
143
|
+
}
|
|
144
|
+
return rgba;
|
|
145
|
+
})();
|
|
146
|
+
const gridWidth = Math.min(GRID_WIDTH, width);
|
|
147
|
+
const gridHeight = Math.min(GRID_HEIGHT, height);
|
|
148
|
+
const built = environmentDistribution(reduce(scaled, width, height, gridWidth, gridHeight), gridWidth, gridHeight);
|
|
149
|
+
if (!built)
|
|
150
|
+
return null;
|
|
151
|
+
const texture = {
|
|
152
|
+
id,
|
|
153
|
+
width,
|
|
154
|
+
height,
|
|
155
|
+
data: scaled,
|
|
156
|
+
// An HDR file is linear already, and the loader hands back floats.
|
|
157
|
+
colorSpace: "srgb-linear",
|
|
158
|
+
// Longitude wraps around; latitude stops at the poles.
|
|
159
|
+
wrapS: 1000,
|
|
160
|
+
wrapT: 1001,
|
|
161
|
+
matrix: [1, 0, 0, 0, 1, 0, 0, 0, 1],
|
|
162
|
+
flipY: false,
|
|
163
|
+
channel: 0,
|
|
164
|
+
nearest: false,
|
|
165
|
+
};
|
|
166
|
+
return { texture, distribution: built.distribution, width: gridWidth, height: gridHeight, total: built.total };
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=environment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"environment.js","sourceRoot":"","sources":["../src/environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAuBpE,8GAA8G;AAC9G,MAAM,UAAU,GAAG,GAAG,CAAC;AACvB,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB,yHAAyH;AACzH,MAAM,SAAS,GAAG,IAAI,CAAC;AAEvB,MAAM,SAAS,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS,EAAE,EAAE,CAAC,MAAM,GAAG,CAAC,GAAG,MAAM,GAAG,CAAC,GAAG,MAAM,GAAG,CAAC,CAAC;AAE5F,uGAAuG;AACvG,SAAS,MAAM,CAAC,MAAoB,EAAE,WAAmB,EAAE,YAAoB,EAAE,KAAa,EAAE,MAAc;IAC5G,MAAM,MAAM,GAAG,IAAI,YAAY,CAAC,KAAK,GAAG,MAAM,GAAG,CAAC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,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;AACjH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frameLayout.d.ts","sourceRoot":"","sources":["../src/frameLayout.ts"],"names":[],"mappings":"AAEA,6EAA6E;AAC7E,eAAO,MAAM,YAAY,0CAqDvB,CAAC;AAEH,eAAO,MAAM,WAAW,QAAqB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { layoutStruct } from "./structLayout.js";
|
|
2
|
+
/** The kernel's per dispatch uniform, as both sides of the device see it. */
|
|
3
|
+
export const FRAME_LAYOUT = layoutStruct("Frame", [
|
|
4
|
+
{ name: "cameraToWorld", type: "mat4f" },
|
|
5
|
+
{ name: "worldToCamera", type: "mat4f" },
|
|
6
|
+
{ name: "projection", type: "mat4f" },
|
|
7
|
+
{ name: "inverseProjection", type: "mat4f", doc: "Clip space to view space: every camera ray goes through it." },
|
|
8
|
+
{ name: "environmentTop", type: "vec4f", doc: "rgb is the colour at the top of the gradient, w its exponent." },
|
|
9
|
+
{ name: "environmentBottom", type: "vec4f", doc: "rgb is the colour at the bottom, w the environment's strength." },
|
|
10
|
+
{ name: "ambientSky", type: "vec4f", doc: "An ambient or hemisphere light, as radiance along the axis and against it." },
|
|
11
|
+
{ name: "ambientGround", type: "vec4f" },
|
|
12
|
+
{ name: "ambientAxis", type: "vec4f" },
|
|
13
|
+
...Array.from({ length: 9 }, (_, k) => ({
|
|
14
|
+
name: `probe${k}`,
|
|
15
|
+
type: "vec4f",
|
|
16
|
+
doc: k === 0 ? "Light probes: Three's nine spherical harmonic coefficients of radiance, summed." : undefined,
|
|
17
|
+
})),
|
|
18
|
+
{ name: "fogColor", type: "vec4f", doc: "rgb is the fog colour, w its kind: 0 none, 1 linear, 2 exponential squared." },
|
|
19
|
+
{ name: "fogParams", type: "vec4f", doc: "near, far, density, and 1 when the fog covers every surface." },
|
|
20
|
+
{ name: "background", type: "vec4f", doc: "rgb is the colour, w the mode: 0 environment, 1 colour, 2 transparent." },
|
|
21
|
+
{ name: "lens", type: "vec4f", doc: "Lens radius, focus distance, blade count; a radius of zero is a pinhole." },
|
|
22
|
+
{ name: "resolution", type: "vec2u" },
|
|
23
|
+
{ name: "bandOrigin", type: "vec2u" },
|
|
24
|
+
{ name: "bandSize", type: "vec2u" },
|
|
25
|
+
{ name: "sampleIndex", type: "u32" },
|
|
26
|
+
{ name: "sampleCount", type: "u32" },
|
|
27
|
+
{ name: "cameraKind", type: "u32", doc: "0 perspective, 1 orthographic." },
|
|
28
|
+
{ name: "bounces", type: "u32" },
|
|
29
|
+
{ name: "triangleCount", type: "u32" },
|
|
30
|
+
{ name: "lightCount", type: "u32" },
|
|
31
|
+
{ name: "areaLightCount", type: "u32", doc: "How many leading lights are emissive triangles." },
|
|
32
|
+
{ name: "clampIndirect", type: "f32", doc: "Maximum luminance one indirect contribution may add; zero leaves it." },
|
|
33
|
+
{ name: "shadowSpread", type: "f32", doc: "Tangent of half the angular diameter shadow rays spread over." },
|
|
34
|
+
{ name: "shadowsEnabled", type: "u32" },
|
|
35
|
+
{ name: "uvOffset", type: "u32", doc: "Where the UV sets start inside the attribute buffer." },
|
|
36
|
+
{ name: "orderOffset", type: "u32", doc: "Where the hierarchy's triangle order starts inside the index buffer." },
|
|
37
|
+
{ name: "colorOffset", type: "u32", doc: "Where vertex colours start inside the attribute buffer." },
|
|
38
|
+
{ name: "hasColors", type: "u32" },
|
|
39
|
+
{ name: "varyingOffset", type: "u32", doc: "Where shader varyings start inside the attribute buffer." },
|
|
40
|
+
{ name: "environmentTexture", type: "u32", doc: "The surrounding image, or NO_TEXTURE for the gradient." },
|
|
41
|
+
{ name: "environmentCdf", type: "u32" },
|
|
42
|
+
{ name: "environmentCdfSize", type: "vec2u" },
|
|
43
|
+
{ name: "environmentTotal", type: "f32" },
|
|
44
|
+
{ name: "environmentRotation", type: "f32" },
|
|
45
|
+
{ name: "environmentPick", type: "f32", doc: "How often direct sampling picks the environment over a light." },
|
|
46
|
+
{ name: "skyProgram", type: "u32", doc: "A procedural sky's foreground program, or NO_PROGRAM." },
|
|
47
|
+
{ name: "skyData", type: "u32" },
|
|
48
|
+
{ name: "skyBackground", type: "u32", doc: "Whether a procedural sky paints the background (1) or leaves it black (0)." },
|
|
49
|
+
{ name: "skyIntensity", type: "f32", doc: "The strength a procedural sky lights with, which its background ignores." },
|
|
50
|
+
{ name: "pixelCount", type: "u32", doc: "Where the alpha half of the accumulation buffer starts." },
|
|
51
|
+
{ name: "volumetricCount", type: "u32", doc: "Lights that scatter in the air, and where their records start." },
|
|
52
|
+
{ name: "volumetricData", type: "u32" },
|
|
53
|
+
{ name: "adaptiveMin", type: "u32", doc: "Samples a pixel takes before it may stop as converged; 0 never stops." },
|
|
54
|
+
{ name: "adaptiveThreshold", type: "f32", doc: "The error under which a pixel and its neighbours count as converged." },
|
|
55
|
+
{ name: "clipPlane", type: "vec4f", doc: "A plane the camera ray drops surfaces behind, for planar captures; w = 0 and xyz = 0 is none." },
|
|
56
|
+
]);
|
|
57
|
+
export const FRAME_WORDS = FRAME_LAYOUT.words;
|
|
58
|
+
//# sourceMappingURL=frameLayout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frameLayout.js","sourceRoot":"","sources":["../src/frameLayout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,6EAA6E;AAC7E,MAAM,CAAC,MAAM,YAAY,GAAG,YAAY,CAAC,OAAO,EAAE;IAChD,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,EAAE;IACxC,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,OAAO,EAAE;IACxC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,OAAO,EAAE;IACrC,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,6DAA6D,EAA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
|
+
import { type CameraMatrices } from "./camera.js";
|
|
2
|
+
import { NO_PROGRAM, type MaterialPlacement, type MaterialProperties } from "./materialLayout.js";
|
|
3
|
+
import type { ShaderPrograms } from "./shaderProgram.js";
|
|
4
|
+
import type { SerializedMesh, SerializedScene, SerializedTexture, UniformValue } from "./upstream.js";
|
|
5
|
+
/** The flat, GPU ready form of a scene's triangles. Positions and normals are world space, three vertices per entry. */
|
|
6
|
+
export interface PackedGeometry {
|
|
7
|
+
/** Nine coordinates per triangle. */
|
|
8
|
+
positions: Float32Array;
|
|
9
|
+
/** Nine normal components per triangle, one per vertex. */
|
|
10
|
+
normals: Float32Array;
|
|
11
|
+
/** Twelve per triangle: two UV sets for each of the three vertices, which is what Three's map channels need. */
|
|
12
|
+
uvs: Float32Array;
|
|
13
|
+
/** Twelve per triangle, RGBA per vertex, when any material reads vertex colours; empty otherwise. */
|
|
14
|
+
colors: Float32Array;
|
|
15
|
+
/** Shader varyings, three corners per triangle of a shader material, laid out as each program asks. */
|
|
16
|
+
varyings: Float32Array;
|
|
17
|
+
/** One material index per triangle. */
|
|
18
|
+
materials: Uint32Array;
|
|
19
|
+
triangleCount: number;
|
|
20
|
+
/** Four floats per material: linear rgb and opacity. */
|
|
21
|
+
materialColors: Float32Array;
|
|
22
|
+
/** Four floats per material: linear emissive rgb and its intensity. */
|
|
23
|
+
materialEmissive: Float32Array;
|
|
24
|
+
/** Every material of the scene, resolved, in the order the triangle indices refer to them. */
|
|
25
|
+
materialProperties: MaterialProperties[];
|
|
26
|
+
/** The mesh specific half of each material entry. */
|
|
27
|
+
materialPlacements: MaterialPlacement[];
|
|
28
|
+
materialCount: number;
|
|
29
|
+
/** Words the materials keep in the texture buffer: clipping planes and shader uniforms. */
|
|
30
|
+
extraWords: Uint32Array;
|
|
31
|
+
/**
|
|
32
|
+
* Whether the triangles depend on the camera: points, lines and sprites face it, and a vertex shader projects through
|
|
33
|
+
* it. Such a scene is packed again whenever the camera or the image size changes.
|
|
34
|
+
*/
|
|
35
|
+
cameraDependent: boolean;
|
|
36
|
+
}
|
|
37
|
+
export interface PackOptions {
|
|
38
|
+
/** The index in the texture table of each texture, by id. */
|
|
39
|
+
textures?: ReadonlyMap<string, number>;
|
|
40
|
+
/** The textures themselves, for the work done here on the CPU: displacement maps and vertex shaders. */
|
|
41
|
+
textureData?: ReadonlyMap<string, SerializedTexture>;
|
|
42
|
+
/** The camera and image size points, lines, sprites and vertex shaders are built for. */
|
|
43
|
+
camera?: CameraMatrices;
|
|
44
|
+
width?: number;
|
|
45
|
+
height?: number;
|
|
46
|
+
/** Translated fragment shaders, for the materials that have one. */
|
|
47
|
+
programs?: ShaderPrograms;
|
|
48
|
+
/** Where the extra words will start in the texture buffer, so the materials can point at them absolutely. */
|
|
49
|
+
extraBase?: number;
|
|
50
|
+
/** Scene fog, which a shader's fog uniforms read. */
|
|
51
|
+
fog?: SerializedScene["fog"];
|
|
52
|
+
}
|
|
53
|
+
/** The uniforms Three sets on every shader for this camera and mesh. */
|
|
54
|
+
export declare function builtinUniforms(camera: CameraMatrices | undefined, matrixWorld: readonly number[], fog?: SerializedScene["fog"]): Record<string, UniformValue>;
|
|
55
|
+
/**
|
|
56
|
+
* Flattens the scene into triangles, materials resolved and transforms applied. Every triangle carries its own three
|
|
57
|
+
* vertices: the path tracer reads a hit through its triangle index, and sharing vertices would cost an indirection on
|
|
58
|
+
* the hottest path of the kernel for memory that low poly scenes do not miss.
|
|
59
|
+
*
|
|
60
|
+
* Points, lines and sprites become triangles that face the camera, sized the way Three draws them, so a path has a
|
|
61
|
+
* surface to find; vertex shaders run here, on the CPU renderer's interpreter, and their varyings ride along per corner.
|
|
62
|
+
*/
|
|
63
|
+
export declare function packGeometry(scene: SerializedScene, options?: PackOptions | ReadonlyMap<string, number>): PackedGeometry;
|
|
64
|
+
/**
|
|
65
|
+
* The attributes of an instanced geometry, which the snapshot keeps as plain attributes with one element per instance
|
|
66
|
+
* rather than per vertex, and how many instances there are.
|
|
67
|
+
*/
|
|
68
|
+
export declare function instancedAttributes(mesh: SerializedMesh): {
|
|
69
|
+
names: Set<string>;
|
|
70
|
+
count: number;
|
|
71
|
+
} | null;
|
|
72
|
+
/** Flat shading for geometry that arrives without normals: the three vertices share the face normal. */
|
|
73
|
+
export declare function faceNormal(a: readonly number[], b: readonly number[], c: readonly number[]): number[];
|
|
74
|
+
export { NO_PROGRAM };
|
|
75
|
+
//# sourceMappingURL=geometry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../src/geometry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AACxF,OAAO,EAKL,UAAU,EACV,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,KAAK,EAAsB,cAAc,EAAE,eAAe,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE1H,wHAAwH;AACxH,MAAM,WAAW,cAAc;IAC7B,qCAAqC;IACrC,SAAS,EAAE,YAAY,CAAC;IACxB,2DAA2D;IAC3D,OAAO,EAAE,YAAY,CAAC;IACtB,gHAAgH;IAChH,GAAG,EAAE,YAAY,CAAC;IAClB,qGAAqG;IACrG,MAAM,EAAE,YAAY,CAAC;IACrB,uGAAuG;IACvG,QAAQ,EAAE,YAAY,CAAC;IACvB,uCAAuC;IACvC,SAAS,EAAE,WAAW,CAAC;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,wDAAwD;IACxD,cAAc,EAAE,YAAY,CAAC;IAC7B,uEAAuE;IACvE,gBAAgB,EAAE,YAAY,CAAC;IAC/B,8FAA8F;IAC9F,kBAAkB,EAAE,kBAAkB,EAAE,CAAC;IACzC,qDAAqD;IACrD,kBAAkB,EAAE,iBAAiB,EAAE,CAAC;IACxC,aAAa,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