@woosh/meep-engine 2.108.0 → 2.108.2
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/build/meep.cjs +178 -127
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +178 -127
- package/editor/tools/paint/TerrainHeightPaintTool.js +5 -5
- package/package.json +1 -1
- package/src/core/binary/float_to_uint8.d.ts +7 -0
- package/src/core/binary/float_to_uint8.d.ts.map +1 -0
- package/src/core/binary/{float2uint8.js → float_to_uint8.js} +1 -1
- package/src/core/binary/uint8_to_float.d.ts +7 -0
- package/src/core/binary/uint8_to_float.d.ts.map +1 -0
- package/src/core/binary/{uint82float.js → uint8_to_float.js} +1 -1
- package/src/core/binary/uint8_to_float.spec.d.ts +2 -0
- package/src/core/binary/uint8_to_float.spec.d.ts.map +1 -0
- package/src/core/binary/uint8_to_float.spec.js +7 -0
- package/src/core/codegen/codeToBlob.d.ts +8 -0
- package/src/core/codegen/codeToBlob.d.ts.map +1 -0
- package/src/core/codegen/codeToBlob.js +36 -0
- package/src/core/codegen/codeToURL.d.ts +8 -0
- package/src/core/codegen/codeToURL.d.ts.map +1 -0
- package/src/core/codegen/codeToURL.js +22 -0
- package/src/core/collection/array/array_shuffle.d.ts +8 -0
- package/src/core/collection/array/array_shuffle.d.ts.map +1 -0
- package/src/core/collection/array/array_shuffle.js +22 -0
- package/src/core/collection/array/array_shuffle.spec.d.ts +2 -0
- package/src/core/collection/array/array_shuffle.spec.d.ts.map +1 -0
- package/src/core/collection/array/{randomizeArrayElementOrder.spec.js → array_shuffle.spec.js} +4 -4
- package/src/core/collection/array/iterator/ArrayIteratorRandom.js +2 -2
- package/src/core/collection/array/randomMultipleFromArray.js +2 -2
- package/src/core/color/Color.js +9 -9
- package/src/core/color/hsv/hsv2rgb.js +4 -4
- package/src/core/color/rgb2uint24.js +4 -4
- package/src/core/color/sRGB/linear_to_sRGB.d.ts +1 -0
- package/src/core/color/sRGB/linear_to_sRGB.d.ts.map +1 -1
- package/src/core/color/sRGB/linear_to_sRGB.js +4 -4
- package/src/core/geom/3d/aabb/AABB3.d.ts.map +1 -1
- package/src/core/geom/3d/aabb/AABB3.js +4 -1
- package/src/core/geom/3d/aabb/aabb3_intersects_ray.js +3 -3
- package/src/core/geom/3d/shape/UnitSphereShape3D.d.ts.map +1 -1
- package/src/core/geom/3d/shape/UnitSphereShape3D.js +14 -14
- package/src/core/geom/3d/sphere/harmonics/SH3_COEFFICIENTS.d.ts.map +1 -1
- package/src/core/geom/3d/sphere/harmonics/SH3_COEFFICIENTS.js +2 -0
- package/src/core/geom/Vector3.js +3 -3
- package/src/core/geom/random/randomPointInSphere.d.ts +1 -1
- package/src/core/geom/random/randomPointInSphere.js +2 -2
- package/src/core/geom/random/randomPointOnSphere.d.ts +3 -3
- package/src/core/geom/random/randomPointOnSphere.d.ts.map +1 -1
- package/src/core/geom/random/randomPointOnSphere.js +5 -9
- package/src/core/process/task/util/randomCountTask.js +3 -3
- package/src/core/process/worker/WorkerBuilder.d.ts.map +1 -1
- package/src/core/process/worker/WorkerBuilder.js +5 -35
- package/src/engine/EngineHarness.d.ts.map +1 -1
- package/src/engine/EngineHarness.js +7 -1
- package/src/engine/asset/loaders/ArrayBufferLoader.d.ts.map +1 -1
- package/src/engine/asset/loaders/ArrayBufferLoader.js +17 -10
- package/src/engine/asset/loaders/material/TextureAttachmensByMaterialType.d.ts.map +1 -1
- package/src/engine/asset/loaders/material/TextureAttachmensByMaterialType.js +3 -0
- package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +4 -4
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.d.ts.map +1 -1
- package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.js +4 -0
- package/src/engine/graphics/ecs/sprite/SpriteSystemPE.d.ts.map +1 -1
- package/src/engine/graphics/ecs/sprite/SpriteSystemPE.js +7 -7
- package/src/engine/graphics/impostors/octahedral/bake/prepare_bake_material.js +3 -3
- package/src/engine/graphics/sh3/SH3VisualisationMaterial.d.ts.map +1 -1
- package/src/engine/graphics/sh3/SH3VisualisationMaterial.js +9 -6
- package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.d.ts.map +1 -1
- package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js +4 -5
- package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +14 -6
- package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples.d.ts +10 -0
- package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples.js +20 -0
- package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples_2d.d.ts +10 -0
- package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples_2d.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples_2d.js +31 -0
- package/src/engine/graphics/sh3/path_tracer/sampling/make_stratified_sample.d.ts +9 -0
- package/src/engine/graphics/sh3/path_tracer/sampling/make_stratified_sample.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/sampling/make_stratified_sample.js +21 -0
- package/src/engine/graphics/sh3/path_tracer/texture/sample_material.js +1 -1
- package/src/engine/graphics/sh3/path_tracer/texture/sample_texture.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/texture/sample_texture.js +2 -3
- package/src/engine/graphics/sh3/path_tracer/vec3_uint8_to_float.js +4 -4
- package/src/engine/graphics/sh3/prototypeSH3Probe.js +74 -6
- package/src/engine/graphics/texture/sampler/Sampler2D.d.ts.map +1 -1
- package/src/engine/graphics/texture/sampler/Sampler2D.js +2 -2
- package/src/engine/network/convertPathToURL.d.ts +3 -1
- package/src/engine/network/convertPathToURL.d.ts.map +1 -1
- package/src/engine/network/convertPathToURL.js +68 -51
- package/src/engine/physics/fluid/SliceVisualiser.d.ts.map +1 -1
- package/src/engine/physics/fluid/SliceVisualiser.js +4 -4
- package/src/generation/filtering/numeric/CellFilterCache.d.ts.map +1 -1
- package/src/generation/filtering/numeric/CellFilterCache.js +1 -0
- package/src/core/binary/float2uint8.d.ts +0 -7
- package/src/core/binary/float2uint8.d.ts.map +0 -1
- package/src/core/binary/uint82float.d.ts +0 -7
- package/src/core/binary/uint82float.d.ts.map +0 -1
- package/src/core/binary/uint82float.spec.d.ts +0 -2
- package/src/core/binary/uint82float.spec.d.ts.map +0 -1
- package/src/core/binary/uint82float.spec.js +0 -7
- package/src/core/collection/array/randomizeArrayElementOrder.d.ts +0 -8
- package/src/core/collection/array/randomizeArrayElementOrder.d.ts.map +0 -1
- package/src/core/collection/array/randomizeArrayElementOrder.js +0 -24
- package/src/core/collection/array/randomizeArrayElementOrder.spec.d.ts +0 -2
- package/src/core/collection/array/randomizeArrayElementOrder.spec.d.ts.map +0 -1
|
@@ -53,6 +53,12 @@ function setLocale(engine) {
|
|
|
53
53
|
return engine.localization.loadLocale(locale);
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Equal to ~ 5500 K light color
|
|
58
|
+
* @type {Readonly<Color>}
|
|
59
|
+
*/
|
|
60
|
+
const DEFAULT_SUNLIGHT_COLOR = Object.freeze(new Color(1, 0.93, 0.87));
|
|
61
|
+
|
|
56
62
|
export class EngineHarness {
|
|
57
63
|
constructor() {
|
|
58
64
|
/**
|
|
@@ -333,7 +339,7 @@ export class EngineHarness {
|
|
|
333
339
|
ecd = engine.entityManager.dataset,
|
|
334
340
|
shadowmapResolution = 1024,
|
|
335
341
|
castShadow = true,
|
|
336
|
-
sun =
|
|
342
|
+
sun = DEFAULT_SUNLIGHT_COLOR,
|
|
337
343
|
sunIntensity = 0.9,
|
|
338
344
|
sunDirection = new Vector3(0.1, -1, 0.1),
|
|
339
345
|
ambient = Color.white,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ArrayBufferLoader.d.ts","sourceRoot":"","sources":["../../../../../src/engine/asset/loaders/ArrayBufferLoader.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ArrayBufferLoader.d.ts","sourceRoot":"","sources":["../../../../../src/engine/asset/loaders/ArrayBufferLoader.js"],"names":[],"mappings":"AAyFA;IACI;;;OAGG;IACH,iCAFW,MAAM,GAAC,KAAK,GAAC,MAAM,EAa7B;IANG;;;;OAIG;IACH,yBAAsC;IAG1C;;;oDA0DC;CACJ;4BAlK2B,kBAAkB;qBAJzB,gCAAgC;sBAC/B,aAAa"}
|
|
@@ -13,20 +13,19 @@ import { AssetLoader } from "./AssetLoader.js";
|
|
|
13
13
|
function observeResponseProgress(input, progress) {
|
|
14
14
|
let response = input
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
if (typeof ReadableStream === 'undefined' || response.body.getReader === undefined) {
|
|
16
|
+
// Workaround: Checking if response.body === undefined for Alipay browser
|
|
17
|
+
if (typeof ReadableStream === 'undefined' || response.body === undefined || response.body.getReader === undefined) {
|
|
18
18
|
|
|
19
19
|
return response;
|
|
20
20
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const reader = response.body.getReader();
|
|
23
|
+
// Nginx needs X-File-Size check
|
|
24
|
+
// https://serverfault.com/questions/482875/why-does-nginx-remove-content-length-header-for-chunked-content
|
|
25
|
+
const contentLength = response.headers.get('Content-Length') || response.headers.get('X-File-Size');
|
|
27
26
|
|
|
28
|
-
const contentLength = response.headers.get('Content-Length');
|
|
29
27
|
const total = contentLength ? parseInt(contentLength) : 0;
|
|
28
|
+
|
|
30
29
|
let loaded = 0;
|
|
31
30
|
|
|
32
31
|
// periodically read data into the new stream tracking while download progress
|
|
@@ -34,6 +33,11 @@ function observeResponseProgress(input, progress) {
|
|
|
34
33
|
type: "bytes",
|
|
35
34
|
start(controller) {
|
|
36
35
|
|
|
36
|
+
/**
|
|
37
|
+
* @type {ReadableStreamDefaultReader<Uint8Array>}
|
|
38
|
+
*/
|
|
39
|
+
const reader = response.body.getReader();
|
|
40
|
+
|
|
37
41
|
pump();
|
|
38
42
|
|
|
39
43
|
function pump() {
|
|
@@ -51,6 +55,7 @@ function observeResponseProgress(input, progress) {
|
|
|
51
55
|
progress(loaded, total);
|
|
52
56
|
|
|
53
57
|
controller.enqueue(value);
|
|
58
|
+
|
|
54
59
|
pump();
|
|
55
60
|
|
|
56
61
|
});
|
|
@@ -123,16 +128,18 @@ export class ArrayBufferLoader extends AssetLoader {
|
|
|
123
128
|
|
|
124
129
|
let response = await fetch(request);
|
|
125
130
|
|
|
126
|
-
|
|
131
|
+
const response_status = response.status;
|
|
132
|
+
|
|
133
|
+
if (response_status !== 200 && response_status !== 0) {
|
|
127
134
|
|
|
128
|
-
throw Error(`fetch for "${response.url}" responded with ${
|
|
135
|
+
throw Error(`fetch for "${response.url}" responded with ${response_status}: ${response.statusText}`);
|
|
129
136
|
|
|
130
137
|
}
|
|
131
138
|
|
|
132
139
|
// Some browsers return HTTP Status 0 when using non-http protocol
|
|
133
140
|
// e.g. 'file://' or 'data://'. Handle as success.
|
|
134
141
|
|
|
135
|
-
if (
|
|
142
|
+
if (response_status === 0) {
|
|
136
143
|
|
|
137
144
|
console.warn('HTTP Status 0 received.');
|
|
138
145
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextureAttachmensByMaterialType.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/asset/loaders/material/TextureAttachmensByMaterialType.js"],"names":[],"mappings":"AAmCA;;;GAGG;AACH,
|
|
1
|
+
{"version":3,"file":"TextureAttachmensByMaterialType.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/asset/loaders/material/TextureAttachmensByMaterialType.js"],"names":[],"mappings":"AAmCA;;;GAGG;AACH,mDA8FE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ClampToEdgeWrapping, DataTexture, NearestFilter } from "three";
|
|
2
2
|
import { assert } from "../../../../core/assert.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { float_to_uint8 } from "../../../../core/binary/float_to_uint8.js";
|
|
4
|
+
import { uint8_to_float } from "../../../../core/binary/uint8_to_float.js";
|
|
5
5
|
import { array_copy } from "../../../../core/collection/array/array_copy.js";
|
|
6
6
|
import { isTypedArray } from "../../../../core/collection/array/typed/isTypedArray.js";
|
|
7
7
|
import Vector1 from "../../../../core/geom/Vector1.js";
|
|
@@ -203,7 +203,7 @@ export class TerrainOverlay {
|
|
|
203
203
|
for (let i = 0; i < 4; i++) {
|
|
204
204
|
const v = this.sampler.readChannel(x, y, i);
|
|
205
205
|
|
|
206
|
-
result[i] =
|
|
206
|
+
result[i] = uint8_to_float(v);
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
|
|
@@ -250,7 +250,7 @@ export class TerrainOverlay {
|
|
|
250
250
|
paintPoint(x, y, vec4) {
|
|
251
251
|
for (let i = 0; i < 4; i++) {
|
|
252
252
|
|
|
253
|
-
this.sampler.writeChannel(x, y, i,
|
|
253
|
+
this.sampler.writeChannel(x, y, i, float_to_uint8(vec4[i]));
|
|
254
254
|
|
|
255
255
|
}
|
|
256
256
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TopDownCameraController.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/ecs/camera/topdown/TopDownCameraController.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TopDownCameraController.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/ecs/camera/topdown/TopDownCameraController.js"],"names":[],"mappings":"AAcA;;;;;;GAMG;AACH,iDALW,MAAM,kBACN,MAAM,SACN,uBAAuB,UACvB,uBAAuB,QAejC;;AAiED;IAmJI,iDAMC;IAxJD,0BAeC;IAdG,gBAA2B;IAE3B,cAAc;IACd,YAAY;IACZ,aAAa;IAEb,iBAAiB;IACjB,oBAAoB;IACpB,oBAAsB;IAQ1B;;;;;OAKG;IACH,yBAJW,OAAO,UACP,OAAO,OACP,OAAO,QAsBjB;IAED;;;;OAIG;IACH,cAHW,uBAAuB,GACrB,OAAO,CAWnB;IAED;;;OAGG;IACH,YAFW,uBAAuB,QAYjC;IAED;;;OAGG;IACH,SAFa,uBAAuB,CAQnC;IAED;;;;;OAKG;IACH,QAJW,uBAAuB,KACvB,uBAAuB,KACvB,MAAM,QAahB;IAED;;;;;;;;MAYC;IAED;;;;;;;;aAsBC;CASJ;;;;;;oBAzPmB,qCAAqC;AAuEzD;;;;;;;;;GASG;AACH,gEANW,OAAO,kBACP,MAAM,OACN,MAAM,UACN,OAAO,eACP,OAAO,QAajB"}
|
|
@@ -4,6 +4,7 @@ import { eulerAnglesFromMatrix } from "../../../../../core/geom/3d/eulerAnglesFr
|
|
|
4
4
|
import { normalize_angle_rad } from "../../../../../core/geom/normalize_angle_rad.js";
|
|
5
5
|
import Vector3 from '../../../../../core/geom/Vector3.js';
|
|
6
6
|
import { lerp } from "../../../../../core/math/lerp.js";
|
|
7
|
+
import { max2 } from "../../../../../core/math/max2.js";
|
|
7
8
|
|
|
8
9
|
const m4 = new Matrix4();
|
|
9
10
|
const angles = [];
|
|
@@ -136,6 +137,9 @@ class TopDownCameraController {
|
|
|
136
137
|
|
|
137
138
|
this.distance = eye.distanceTo(target);
|
|
138
139
|
|
|
140
|
+
// ensure we can maintain this distance
|
|
141
|
+
this.distanceMax = max2(this.distance, this.distanceMax);
|
|
142
|
+
|
|
139
143
|
this.target.copy(target);
|
|
140
144
|
}
|
|
141
145
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpriteSystemPE.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/ecs/sprite/SpriteSystemPE.js"],"names":[],"mappings":"AA6HA;IACI,cAKC;IADG,mDAAuC;CAE9C;
|
|
1
|
+
{"version":3,"file":"SpriteSystemPE.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/ecs/sprite/SpriteSystemPE.js"],"names":[],"mappings":"AA6HA;IACI,cAKC;IADG,mDAAuC;CAE9C;sCAjIqC,8CAA8C;0BAE1D,qCAAqC;uBAQxC,aAAa"}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ParticleLayer } from "../../particles/particular/engine/emitter/ParticleLayer.js";
|
|
3
|
-
import Entity from "../../../ecs/Entity.js";
|
|
4
|
-
import { Transform } from "../../../ecs/transform/Transform.js";
|
|
1
|
+
import { float_to_uint8 } from "../../../../core/binary/float_to_uint8.js";
|
|
5
2
|
import { SerializationMetadata } from "../../../ecs/components/SerializationMetadata.js";
|
|
3
|
+
import Entity from "../../../ecs/Entity.js";
|
|
6
4
|
import { AbstractContextSystem } from "../../../ecs/system/AbstractContextSystem.js";
|
|
7
5
|
import { SystemEntityContext } from "../../../ecs/system/SystemEntityContext.js";
|
|
8
|
-
import {
|
|
6
|
+
import { Transform } from "../../../ecs/transform/Transform.js";
|
|
9
7
|
import {
|
|
10
8
|
PARTICLE_ATTRIBUTE_COLOR,
|
|
11
9
|
PARTICLE_ATTRIBUTE_POSITION
|
|
12
10
|
} from "../../particles/particular/engine/emitter/PARTICLE_ATTRIBUTES.js";
|
|
11
|
+
import { ParticleEmitter } from "../../particles/particular/engine/emitter/ParticleEmitter.js";
|
|
13
12
|
import { ParticleEmitterFlag } from "../../particles/particular/engine/emitter/ParticleEmitterFlag.js";
|
|
14
|
-
import {
|
|
13
|
+
import { ParticleLayer } from "../../particles/particular/engine/emitter/ParticleLayer.js";
|
|
14
|
+
import { Sprite } from "./Sprite.js";
|
|
15
15
|
|
|
16
16
|
class Context extends SystemEntityContext {
|
|
17
17
|
constructor() {
|
|
@@ -92,7 +92,7 @@ class Context extends SystemEntityContext {
|
|
|
92
92
|
|
|
93
93
|
emitter.particles?.writeAttributeVector4(
|
|
94
94
|
0, PARTICLE_ATTRIBUTE_COLOR,
|
|
95
|
-
|
|
95
|
+
float_to_uint8(sprite.color.r), float_to_uint8(sprite.color.g), float_to_uint8(sprite.color.b), float_to_uint8(sprite.opacity.getValue())
|
|
96
96
|
);
|
|
97
97
|
|
|
98
98
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { float_to_uint8 } from "../../../../../core/binary/float_to_uint8.js";
|
|
2
2
|
import { clamp01 } from "../../../../../core/math/clamp01.js";
|
|
3
3
|
import { makeOnePixelTexture } from "../../../texture/makeOnePixelTexture.js";
|
|
4
4
|
|
|
@@ -38,12 +38,12 @@ export function prepare_bake_material({
|
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
if (texture_metalness === null) {
|
|
41
|
-
const m =
|
|
41
|
+
const m = float_to_uint8(clamp01(source_material.metalness));
|
|
42
42
|
texture_metalness = makeOnePixelTexture([m, m, m, 255], cleanup_signal);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
if (texture_roughness === null) {
|
|
46
|
-
const r =
|
|
46
|
+
const r = float_to_uint8(clamp01(source_material.roughness));
|
|
47
47
|
|
|
48
48
|
texture_roughness = makeOnePixelTexture([r, r, r, 255], cleanup_signal);
|
|
49
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SH3VisualisationMaterial.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/sh3/SH3VisualisationMaterial.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SH3VisualisationMaterial.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/sh3/SH3VisualisationMaterial.js"],"names":[],"mappings":"AA0DA;IAEI,cAoBC;CAEJ;+BAlFuC,OAAO"}
|
|
@@ -24,17 +24,20 @@ vec3 inverseTransformDirection( in vec3 normal, in mat4 matrix ) {
|
|
|
24
24
|
vec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {
|
|
25
25
|
// normal is assumed to have unit length
|
|
26
26
|
float x = normal.x, y = normal.y, z = normal.z;
|
|
27
|
+
|
|
27
28
|
// band 0
|
|
28
29
|
vec3 result = shCoefficients[ 0 ] * 0.886227;
|
|
30
|
+
|
|
29
31
|
// band 1
|
|
30
|
-
result
|
|
32
|
+
result -= shCoefficients[ 1 ] * 2.0 * 0.511664 * y;
|
|
31
33
|
result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;
|
|
32
|
-
result
|
|
34
|
+
result -= shCoefficients[ 3 ] * 2.0 * 0.511664 * x;
|
|
35
|
+
|
|
33
36
|
// band 2
|
|
34
37
|
result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;
|
|
35
|
-
result
|
|
38
|
+
result -= shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;
|
|
36
39
|
result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );
|
|
37
|
-
result
|
|
40
|
+
result -= shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;
|
|
38
41
|
result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );
|
|
39
42
|
|
|
40
43
|
return result;
|
|
@@ -46,9 +49,9 @@ varying vec3 vNormal;
|
|
|
46
49
|
|
|
47
50
|
void main() {
|
|
48
51
|
vec3 normal = normalize( vNormal );
|
|
49
|
-
vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );
|
|
52
|
+
vec3 worldNormal = normalize(inverseTransformDirection( normal, viewMatrix ));
|
|
50
53
|
vec3 irradiance = shGetIrradianceAt( worldNormal, sh );
|
|
51
|
-
vec3 outgoingLight =
|
|
54
|
+
vec3 outgoingLight = 1.0 * irradiance * intensity;
|
|
52
55
|
gl_FragColor = linearToOutputTexel( vec4( outgoingLight, 1.0 ) );
|
|
53
56
|
}
|
|
54
57
|
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PathTracerProbeRenderer.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PathTracerProbeRenderer.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js"],"names":[],"mappings":"AAuBA;IACI,mBAA0B;IAC1B,qBAAmB;IACnB,qBAAyB;IAEzB,uBAA6B;IAE7B,iFA2CC;IASD,4BAsCC;CACJ;8BA3G6B,oBAAoB;2BADvB,8BAA8B;gCADzB,mCAAmC"}
|
|
@@ -18,9 +18,12 @@ const __shared_buffer = new ArrayBuffer((27 + 9) * 8);
|
|
|
18
18
|
const sh_basis = new Float64Array(__shared_buffer, 0, 9);
|
|
19
19
|
const coefficients = new Float64Array(__shared_buffer, 9 * 8, 27);
|
|
20
20
|
|
|
21
|
+
const ray = new Float32Array(6);
|
|
22
|
+
const sampled_irradiance = new Float32Array(3);
|
|
23
|
+
|
|
21
24
|
export class PathTracerProbeRenderer extends ProbeRenderer {
|
|
22
25
|
tracer = new PathTracer();
|
|
23
|
-
sample_count =
|
|
26
|
+
sample_count = 256;
|
|
24
27
|
random = seededRandom(0);
|
|
25
28
|
|
|
26
29
|
scene = new PathTracedScene()
|
|
@@ -29,13 +32,9 @@ export class PathTracerProbeRenderer extends ProbeRenderer {
|
|
|
29
32
|
|
|
30
33
|
const tracer = this.tracer;
|
|
31
34
|
|
|
32
|
-
const ray = [];
|
|
33
|
-
|
|
34
|
-
const direct_light = [];
|
|
35
35
|
|
|
36
36
|
array_copy(position, position_offset, ray, 0, 3);
|
|
37
37
|
|
|
38
|
-
const sampled_irradiance = [];
|
|
39
38
|
|
|
40
39
|
coefficients.fill(0);
|
|
41
40
|
|
|
@@ -11,9 +11,10 @@ import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
|
11
11
|
import { PLYLoader } from "three/examples/jsm/loaders/PLYLoader.js";
|
|
12
12
|
|
|
13
13
|
import '../../../../../../../../css/game.scss';
|
|
14
|
-
import {
|
|
14
|
+
import { float_to_uint8 } from "../../../../core/binary/float_to_uint8.js";
|
|
15
15
|
import { Color } from "../../../../core/color/Color.js";
|
|
16
16
|
import { kelvin_to_rgb } from "../../../../core/color/kelvin/kelvin_to_rgb.js";
|
|
17
|
+
import { linear_to_sRGB } from "../../../../core/color/sRGB/linear_to_sRGB.js";
|
|
17
18
|
|
|
18
19
|
import { noop } from "../../../../core/function/noop.js";
|
|
19
20
|
import { ray3_array_compose } from "../../../../core/geom/3d/ray/ray3_array_compose.js";
|
|
@@ -72,7 +73,7 @@ vCanvas.css({
|
|
|
72
73
|
* How many rays to use per-pixel
|
|
73
74
|
* @type {number}
|
|
74
75
|
*/
|
|
75
|
-
const PIXEL_SAMPLE_COUNT =
|
|
76
|
+
const PIXEL_SAMPLE_COUNT = 64;
|
|
76
77
|
|
|
77
78
|
const scene = new PathTracedScene();
|
|
78
79
|
const pt = new PathTracer();
|
|
@@ -428,7 +429,8 @@ function* render(target, pt, camera, scene, progress = { current: 0, total: 0 })
|
|
|
428
429
|
|
|
429
430
|
const pixel_address = ((max_y - y) * width + x) * 4;
|
|
430
431
|
|
|
431
|
-
|
|
432
|
+
const output_data = target.data;
|
|
433
|
+
output_data[pixel_address + 3] = 255;
|
|
432
434
|
|
|
433
435
|
for (let i = 0; i < pixel_sample_count; i++) {
|
|
434
436
|
|
|
@@ -454,9 +456,15 @@ function* render(target, pt, camera, scene, progress = { current: 0, total: 0 })
|
|
|
454
456
|
sample_count++;
|
|
455
457
|
}
|
|
456
458
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
459
|
+
pixel_accummulation[0] /= pixel_sample_count
|
|
460
|
+
pixel_accummulation[1] /= pixel_sample_count
|
|
461
|
+
pixel_accummulation[2] /= pixel_sample_count
|
|
462
|
+
|
|
463
|
+
linear_to_sRGB(pixel_accummulation, 0, pixel_accummulation, 0);
|
|
464
|
+
|
|
465
|
+
output_data[pixel_address] = float_to_uint8(pixel_accummulation[0]);
|
|
466
|
+
output_data[pixel_address + 1] = float_to_uint8(pixel_accummulation[1]);
|
|
467
|
+
output_data[pixel_address + 2] = float_to_uint8(pixel_accummulation[2]);
|
|
460
468
|
|
|
461
469
|
|
|
462
470
|
progress.current++;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {number[]} result
|
|
4
|
+
* @param {number} result_offset
|
|
5
|
+
* @param {number} result_stride
|
|
6
|
+
* @param {number} num_samples
|
|
7
|
+
* @param {function():number} random
|
|
8
|
+
*/
|
|
9
|
+
export function generate_stratified_samples(result: number[], result_offset: number, result_stride: number, num_samples: number, random: () => number): void;
|
|
10
|
+
//# sourceMappingURL=generate_stratified_samples.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate_stratified_samples.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples.js"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,oDANW,MAAM,EAAE,iBACR,MAAM,iBACN,MAAM,eACN,MAAM,gBACK,MAAM,QAW3B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { make_stratified_sample } from "./make_stratified_sample.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {number[]} result
|
|
6
|
+
* @param {number} result_offset
|
|
7
|
+
* @param {number} result_stride
|
|
8
|
+
* @param {number} num_samples
|
|
9
|
+
* @param {function():number} random
|
|
10
|
+
*/
|
|
11
|
+
export function generate_stratified_samples(result, result_offset, result_stride, num_samples, random) {
|
|
12
|
+
|
|
13
|
+
const delta = 1 / num_samples;
|
|
14
|
+
|
|
15
|
+
for (let i = 0; i < num_samples; ++i) {
|
|
16
|
+
|
|
17
|
+
result[result_offset + i * result_stride] = make_stratified_sample(i, delta, random);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Based on https://github.com/TheRealMJP/DXRPathTracer/blob/e01b893c76ad629fa6e715d35b98901f5195d000/SampleFramework12/v1.02/Graphics/Sampling.cpp#L440
|
|
3
|
+
* @param {number[]} result
|
|
4
|
+
* @param {number} result_offset
|
|
5
|
+
* @param {number} num_samples_x
|
|
6
|
+
* @param {number} num_samples_y
|
|
7
|
+
* @param {function():number} random
|
|
8
|
+
*/
|
|
9
|
+
export function generate_stratified_samples_2d(result: number[], result_offset: number, num_samples_x: number, num_samples_y: number, random: () => number): number;
|
|
10
|
+
//# sourceMappingURL=generate_stratified_samples_2d.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate_stratified_samples_2d.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples_2d.js"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,uDANW,MAAM,EAAE,iBACR,MAAM,iBACN,MAAM,iBACN,MAAM,gBACK,MAAM,UAqB3B"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { make_stratified_sample } from "./make_stratified_sample.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Based on https://github.com/TheRealMJP/DXRPathTracer/blob/e01b893c76ad629fa6e715d35b98901f5195d000/SampleFramework12/v1.02/Graphics/Sampling.cpp#L440
|
|
5
|
+
* @param {number[]} result
|
|
6
|
+
* @param {number} result_offset
|
|
7
|
+
* @param {number} num_samples_x
|
|
8
|
+
* @param {number} num_samples_y
|
|
9
|
+
* @param {function():number} random
|
|
10
|
+
*/
|
|
11
|
+
export function generate_stratified_samples_2d(result, result_offset, num_samples_x, num_samples_y, random) {
|
|
12
|
+
|
|
13
|
+
const delta_x = 1 / num_samples_x;
|
|
14
|
+
const delta_y = 1 / num_samples_y;
|
|
15
|
+
|
|
16
|
+
let sample_index = 0;
|
|
17
|
+
for (let y = 0; y < num_samples_y; y++) {
|
|
18
|
+
for (let x = 0; x < num_samples_x; x++) {
|
|
19
|
+
|
|
20
|
+
const address = result_offset + sample_index * 2;
|
|
21
|
+
|
|
22
|
+
result[address] = make_stratified_sample(x, delta_x, random);
|
|
23
|
+
result[address + 1] = make_stratified_sample(y, delta_y, random);
|
|
24
|
+
|
|
25
|
+
++sample_index;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return sample_index;
|
|
30
|
+
}
|
|
31
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {number} index
|
|
4
|
+
* @param {number} delta
|
|
5
|
+
* @param {function} random
|
|
6
|
+
* @return {number}
|
|
7
|
+
*/
|
|
8
|
+
export function make_stratified_sample(index: number, delta: number, random: Function): number;
|
|
9
|
+
//# sourceMappingURL=make_stratified_sample.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make_stratified_sample.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/sampling/make_stratified_sample.js"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,8CALW,MAAM,SACN,MAAM,qBAEL,MAAM,CAWjB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { clamp } from "../../../../../core/math/clamp.js";
|
|
2
|
+
|
|
3
|
+
const ONE_MINUS_EPSILON = 0.999999;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {number} index
|
|
8
|
+
* @param {number} delta
|
|
9
|
+
* @param {function} random
|
|
10
|
+
* @return {number}
|
|
11
|
+
*/
|
|
12
|
+
export function make_stratified_sample(index, delta, random) {
|
|
13
|
+
|
|
14
|
+
let sample = index + random();
|
|
15
|
+
|
|
16
|
+
sample *= delta;
|
|
17
|
+
|
|
18
|
+
sample = clamp(sample, 0, ONE_MINUS_EPSILON);
|
|
19
|
+
|
|
20
|
+
return sample;
|
|
21
|
+
}
|
|
@@ -64,7 +64,7 @@ export function sample_material(
|
|
|
64
64
|
|
|
65
65
|
const material = mesh.material;
|
|
66
66
|
|
|
67
|
-
if (material.isMeshStandardMaterial) {
|
|
67
|
+
if (material.isMeshStandardMaterial || material.isMeshBasicMaterial) {
|
|
68
68
|
const material_color = material.color;
|
|
69
69
|
|
|
70
70
|
out[0] *= material_color.r;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sample_texture.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/texture/sample_texture.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sample_texture.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/texture/sample_texture.js"],"names":[],"mappings":"AAYA;;;;;;;GAOG;AACH,oCANW,MAAM,EAAE,GAAC,YAAY,2CAGrB,MAAM,KACN,MAAM,QAoChB"}
|
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
sRGBEncoding,
|
|
8
8
|
UnsignedByteType
|
|
9
9
|
} from "three";
|
|
10
|
-
import { linear_to_sRGB } from "../../../../../core/color/sRGB/linear_to_sRGB.js";
|
|
11
10
|
import { vec3_uint8_to_float } from "../vec3_uint8_to_float.js";
|
|
12
11
|
import { apply_texture_clamping_to_coordinate } from "./apply_texture_clamping_to_coordinate.js";
|
|
13
12
|
|
|
@@ -50,7 +49,7 @@ export function sample_texture(out, sampler, texture, u, v) {
|
|
|
50
49
|
if (texture_encoding === LinearEncoding) {
|
|
51
50
|
// nothing
|
|
52
51
|
} else if (texture_encoding === sRGBEncoding) {
|
|
53
|
-
// convert value to
|
|
54
|
-
|
|
52
|
+
// convert value to linear space
|
|
53
|
+
// sRGB_to_linear(out, 0, out, 0);
|
|
55
54
|
}
|
|
56
55
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { uint8_to_float } from "../../../../core/binary/uint8_to_float.js";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
*
|
|
@@ -6,7 +6,7 @@ import { uint82float } from "../../../../core/binary/uint82float.js";
|
|
|
6
6
|
* @param {number[]} input
|
|
7
7
|
*/
|
|
8
8
|
export function vec3_uint8_to_float(out, input) {
|
|
9
|
-
out[0] =
|
|
10
|
-
out[1] =
|
|
11
|
-
out[2] =
|
|
9
|
+
out[0] = uint8_to_float(input[0]);
|
|
10
|
+
out[1] = uint8_to_float(input[1]);
|
|
11
|
+
out[2] = uint8_to_float(input[2]);
|
|
12
12
|
}
|