@needle-tools/engine 4.13.1-next.9fc3e64 → 4.14.0-next.31f837e
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/dist/generateMeshBVH.worker-DFcS3P04.js +21 -0
- package/dist/{gltf-progressive-Dbi_Tfhb.js → gltf-progressive-8voIgNp_.js} +4 -4
- package/dist/{gltf-progressive-CaUGGjVL.umd.cjs → gltf-progressive-BRRBj-nY.umd.cjs} +1 -1
- package/dist/{gltf-progressive-DuAR0MQR.min.js → gltf-progressive-Dkh3tG4-.min.js} +1 -1
- package/dist/loader.worker-C6cXDgR1.js +23 -0
- package/dist/{materialx-BF23AVE8.umd.cjs → materialx-CxlgposR.umd.cjs} +1 -1
- package/dist/{materialx-fkoFuRh3.js → materialx-D66rYPqe.js} +2 -2
- package/dist/{materialx-B9ddsHcF.min.js → materialx-Dx8st96L.min.js} +1 -1
- package/dist/{needle-engine.bundle-Dqrh7aWw.umd.cjs → needle-engine.bundle-BQXG5qbQ.umd.cjs} +136 -143
- package/dist/{needle-engine.bundle-BZRE5G6O.js → needle-engine.bundle-Byl5i6zJ.js} +6120 -5904
- package/dist/{needle-engine.bundle-DwybonUg.min.js → needle-engine.bundle-D7w0XD7M.min.js} +147 -154
- package/dist/needle-engine.d.ts +61 -9
- package/dist/needle-engine.js +416 -415
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/dist/{postprocessing-DdM-tz1j.js → postprocessing-BkSpxpYB.js} +2 -2
- package/dist/{postprocessing-BVNrgYZK.min.js → postprocessing-Ce5-UWiA.min.js} +1 -1
- package/dist/{postprocessing-CI2TjWpu.umd.cjs → postprocessing-DFVElmAh.umd.cjs} +1 -1
- package/dist/{three-BW2s1Yl-.umd.cjs → three-Bad8p1pf.umd.cjs} +46 -46
- package/dist/{three-I__hSXzr.min.js → three-CWn13_u1.min.js} +33 -33
- package/dist/{three-VvRoMeIN.js → three-DFV1-P9z.js} +4209 -4209
- package/dist/{three-examples-BhfOE7NG.js → three-examples-43yqn3mL.js} +1 -1
- package/dist/{three-examples-Bpfu6ke_.umd.cjs → three-examples-CO-tx3Sp.umd.cjs} +1 -1
- package/dist/{three-examples-D8zAE_7t.min.js → three-examples-DKuJVGT4.min.js} +1 -1
- package/dist/{three-mesh-ui-BU55xDxJ.umd.cjs → three-mesh-ui-ChzVOraf.umd.cjs} +1 -1
- package/dist/{three-mesh-ui-C3QbemOV.min.js → three-mesh-ui-DyEA5HQF.min.js} +1 -1
- package/dist/{three-mesh-ui-CcMp-FQm.js → three-mesh-ui-fSAQJxdI.js} +1 -1
- package/dist/{vendor-COVQl0b8.umd.cjs → vendor-B51YffMU.umd.cjs} +1 -1
- package/dist/{vendor-BiyIZ61v.js → vendor-CgpZ5ivC.js} +1 -1
- package/dist/{vendor-DW7zqjuT.min.js → vendor-pe19S9r5.min.js} +1 -1
- package/lib/engine/api.d.ts +1 -0
- package/lib/engine/api.js +1 -0
- package/lib/engine/api.js.map +1 -1
- package/lib/engine/engine_lightdata.js +8 -6
- package/lib/engine/engine_lightdata.js.map +1 -1
- package/lib/engine/engine_materialpropertyblock.d.ts +47 -0
- package/lib/engine/engine_materialpropertyblock.js +412 -0
- package/lib/engine/engine_materialpropertyblock.js.map +1 -0
- package/lib/engine-components/ReflectionProbe.d.ts +0 -1
- package/lib/engine-components/ReflectionProbe.js +15 -76
- package/lib/engine-components/ReflectionProbe.js.map +1 -1
- package/lib/engine-components/RendererLightmap.d.ts +13 -9
- package/lib/engine-components/RendererLightmap.js +68 -81
- package/lib/engine-components/RendererLightmap.js.map +1 -1
- package/package.json +2 -2
- package/src/engine/api.ts +1 -0
- package/src/engine/engine_lightdata.ts +8 -6
- package/src/engine/engine_materialpropertyblock.ts +500 -0
- package/src/engine-components/ReflectionProbe.ts +17 -89
- package/src/engine-components/RendererLightmap.ts +76 -87
- package/dist/generateMeshBVH.worker-iyfPIK6R.js +0 -21
- package/dist/loader.worker-C1GG9A7C.js +0 -23
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Texture, Vector4 } from "three";
|
|
2
2
|
import { type Renderer } from "./Renderer.js";
|
|
3
3
|
/**
|
|
4
4
|
* This component is automatically added by the {@link Renderer} component if the object has lightmap uvs AND we have a lightmap.
|
|
@@ -12,22 +12,26 @@ export declare class RendererLightmap {
|
|
|
12
12
|
private lightmapIndex;
|
|
13
13
|
private lightmapScaleOffset;
|
|
14
14
|
private readonly renderer;
|
|
15
|
-
private
|
|
15
|
+
private _isApplied;
|
|
16
16
|
private get context();
|
|
17
17
|
private get gameObject();
|
|
18
18
|
private lightmapTexture;
|
|
19
|
-
private lightmapScaleOffsetUniform;
|
|
20
|
-
private lightmapUniform;
|
|
21
19
|
constructor(renderer: Renderer);
|
|
22
20
|
init(lightmapIndex: number, lightmapScaleOffset: Vector4, lightmapTexture: Texture): void;
|
|
23
|
-
updateLightmapUniforms(
|
|
21
|
+
updateLightmapUniforms(_material: any): void;
|
|
24
22
|
/**
|
|
25
|
-
* Apply the lightmap to the object
|
|
23
|
+
* Apply the lightmap to the object using MaterialPropertyBlock instead of cloning materials.
|
|
24
|
+
* The lightmap texture and its per-object UV transform are set as overrides via PropertyBlock.
|
|
25
|
+
* Three.js reads material.lightMap to determine shader defines and upload uniforms,
|
|
26
|
+
* and uses texture.offset/repeat to compute lightMapTransform in the vertex shader.
|
|
26
27
|
*/
|
|
27
28
|
applyLightmap(): void;
|
|
29
|
+
/** Update the lightMap override on all property blocks (e.g. after LOD swap) */
|
|
30
|
+
private updatePropertyBlockTexture;
|
|
31
|
+
/**
|
|
32
|
+
* Remove the lightmap from the object
|
|
33
|
+
*/
|
|
34
|
+
onUnset(): void;
|
|
28
35
|
private ensureLightmapUvs;
|
|
29
|
-
private ensureLightmapMaterial;
|
|
30
|
-
private assignLightmapTexture;
|
|
31
|
-
private onBeforeCompile;
|
|
32
36
|
private setLightmapDebugMaterial;
|
|
33
37
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { NEEDLE_progressive } from "@needle-tools/gltf-progressive";
|
|
2
|
-
import { Group, Mesh,
|
|
2
|
+
import { Group, Mesh, ShaderMaterial, Vector2, Vector4 } from "three";
|
|
3
3
|
import { getParam } from "../engine/engine_utils.js";
|
|
4
|
+
import { MaterialPropertyBlock } from "../engine/engine_materialpropertyblock.js";
|
|
4
5
|
const debug = getParam("debuglightmaps");
|
|
5
|
-
|
|
6
|
-
const $lightmapVersion = Symbol("lightmap-material-version");
|
|
6
|
+
const $lightmapKey = Symbol("lightmapKey");
|
|
7
7
|
/**
|
|
8
8
|
* This component is automatically added by the {@link Renderer} component if the object has lightmap uvs AND we have a lightmap.
|
|
9
9
|
*
|
|
@@ -18,10 +18,13 @@ export class RendererLightmap {
|
|
|
18
18
|
if (tex !== this.lightmapTexture) {
|
|
19
19
|
this.lightmapTexture = tex;
|
|
20
20
|
this.applyLightmap();
|
|
21
|
+
this.updatePropertyBlockTexture();
|
|
21
22
|
if (this.lightmapTexture) {
|
|
22
23
|
NEEDLE_progressive.assignTextureLOD(this.lightmapTexture, 0).then(res => {
|
|
23
|
-
if (res?.isTexture)
|
|
24
|
+
if (res?.isTexture) {
|
|
24
25
|
this.lightmapTexture = res;
|
|
26
|
+
this.updatePropertyBlockTexture();
|
|
27
|
+
}
|
|
25
28
|
});
|
|
26
29
|
}
|
|
27
30
|
}
|
|
@@ -29,12 +32,10 @@ export class RendererLightmap {
|
|
|
29
32
|
lightmapIndex = -1;
|
|
30
33
|
lightmapScaleOffset = new Vector4(1, 1, 0, 0);
|
|
31
34
|
renderer;
|
|
32
|
-
|
|
35
|
+
_isApplied = false;
|
|
33
36
|
get context() { return this.renderer.context; }
|
|
34
37
|
get gameObject() { return this.renderer.gameObject; }
|
|
35
38
|
lightmapTexture = null;
|
|
36
|
-
lightmapScaleOffsetUniform = { value: new Vector4(1, 1, 0, 0) };
|
|
37
|
-
lightmapUniform = { value: null };
|
|
38
39
|
constructor(renderer) {
|
|
39
40
|
this.renderer = renderer;
|
|
40
41
|
}
|
|
@@ -46,8 +47,10 @@ export class RendererLightmap {
|
|
|
46
47
|
this.lightmapScaleOffset = lightmapScaleOffset;
|
|
47
48
|
this.lightmapTexture = lightmapTexture;
|
|
48
49
|
NEEDLE_progressive.assignTextureLOD(lightmapTexture, 0).then(res => {
|
|
49
|
-
if (res?.isTexture)
|
|
50
|
+
if (res?.isTexture) {
|
|
50
51
|
this.lightmapTexture = res;
|
|
52
|
+
this.updatePropertyBlockTexture();
|
|
53
|
+
}
|
|
51
54
|
});
|
|
52
55
|
if (debug == "show") {
|
|
53
56
|
console.log("Lightmap:", this.gameObject.name, lightmapIndex, "\nScaleOffset:", lightmapScaleOffset, "\nTexture:", lightmapTexture);
|
|
@@ -57,17 +60,17 @@ export class RendererLightmap {
|
|
|
57
60
|
console.log("Use debuglightmaps=show to render lightmaps only in the scene.");
|
|
58
61
|
this.applyLightmap();
|
|
59
62
|
}
|
|
60
|
-
updateLightmapUniforms(
|
|
61
|
-
const uniforms = material["uniforms"];
|
|
62
|
-
if (uniforms && uniforms.lightmap) {
|
|
63
|
-
this.lightmapScaleOffsetUniform.value = this.lightmapScaleOffset;
|
|
64
|
-
uniforms.lightmapScaleOffset = this.lightmapScaleOffsetUniform;
|
|
65
|
-
}
|
|
63
|
+
updateLightmapUniforms(_material) {
|
|
66
64
|
}
|
|
67
65
|
/**
|
|
68
|
-
* Apply the lightmap to the object
|
|
66
|
+
* Apply the lightmap to the object using MaterialPropertyBlock instead of cloning materials.
|
|
67
|
+
* The lightmap texture and its per-object UV transform are set as overrides via PropertyBlock.
|
|
68
|
+
* Three.js reads material.lightMap to determine shader defines and upload uniforms,
|
|
69
|
+
* and uses texture.offset/repeat to compute lightMapTransform in the vertex shader.
|
|
69
70
|
*/
|
|
70
71
|
applyLightmap() {
|
|
72
|
+
if (this._isApplied)
|
|
73
|
+
return;
|
|
71
74
|
if (this.gameObject.type === "Object3D") {
|
|
72
75
|
if (debug)
|
|
73
76
|
console.warn("Can not add lightmap. Is this object missing a renderer?", this.gameObject.name);
|
|
@@ -75,22 +78,57 @@ export class RendererLightmap {
|
|
|
75
78
|
}
|
|
76
79
|
const mesh = this.gameObject;
|
|
77
80
|
this.ensureLightmapUvs(mesh);
|
|
81
|
+
if (this.lightmapIndex >= 0 && this.lightmapTexture) {
|
|
82
|
+
this.lightmapTexture.channel = 1;
|
|
83
|
+
const so = this.lightmapScaleOffset;
|
|
84
|
+
for (let i = 0; i < this.renderer.sharedMaterials.length; i++) {
|
|
85
|
+
const mat = this.renderer.sharedMaterials[i];
|
|
86
|
+
if (!mat)
|
|
87
|
+
continue;
|
|
88
|
+
// If the material doesn't support lightmaps, skip it
|
|
89
|
+
if (mat["lightMap"] === undefined)
|
|
90
|
+
continue;
|
|
91
|
+
if (debug)
|
|
92
|
+
console.log("Setting lightmap on material", mat.name, "for renderer", this.renderer.name);
|
|
93
|
+
// Use property block to set lightMap with per-object UV transform.
|
|
94
|
+
// The texture transform differentiates cache keys per object and
|
|
95
|
+
// PropertyBlock handles save/restore of the shared texture's offset/repeat.
|
|
96
|
+
const propertyBlock = MaterialPropertyBlock.get(this.gameObject);
|
|
97
|
+
propertyBlock.setOverride("lightMap", this.lightmapTexture, {
|
|
98
|
+
offset: new Vector2(so.z, 1 - so.y - so.w),
|
|
99
|
+
repeat: new Vector2(so.x, so.y)
|
|
100
|
+
});
|
|
101
|
+
mat[$lightmapKey] = true;
|
|
102
|
+
}
|
|
103
|
+
this._isApplied = true;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** Update the lightMap override on all property blocks (e.g. after LOD swap) */
|
|
107
|
+
updatePropertyBlockTexture() {
|
|
108
|
+
if (!this._isApplied || !this.lightmapTexture)
|
|
109
|
+
return;
|
|
110
|
+
this.lightmapTexture.channel = 1;
|
|
111
|
+
const so = this.lightmapScaleOffset;
|
|
112
|
+
const propertyBlock = MaterialPropertyBlock.get(this.gameObject);
|
|
113
|
+
propertyBlock.setOverride("lightMap", this.lightmapTexture, {
|
|
114
|
+
offset: new Vector2(so.z, 1 - so.y - so.w),
|
|
115
|
+
repeat: new Vector2(so.x, so.y)
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Remove the lightmap from the object
|
|
120
|
+
*/
|
|
121
|
+
onUnset() {
|
|
78
122
|
for (let i = 0; i < this.renderer.sharedMaterials.length; i++) {
|
|
79
123
|
const mat = this.renderer.sharedMaterials[i];
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
const newMat = this.ensureLightmapMaterial(mat, i);
|
|
83
|
-
if (mat !== newMat) {
|
|
84
|
-
this.renderer.sharedMaterials[i] = newMat;
|
|
124
|
+
if (mat) {
|
|
125
|
+
delete mat[$lightmapKey];
|
|
85
126
|
}
|
|
86
127
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (mat)
|
|
92
|
-
this.assignLightmapTexture(mat);
|
|
93
|
-
}
|
|
128
|
+
const block = MaterialPropertyBlock.get(this.gameObject);
|
|
129
|
+
if (block) {
|
|
130
|
+
block.clearOverride("lightMap");
|
|
131
|
+
block.clearOverride("lightMapIntensity");
|
|
94
132
|
}
|
|
95
133
|
}
|
|
96
134
|
ensureLightmapUvs(object) {
|
|
@@ -105,58 +143,8 @@ export class RendererLightmap {
|
|
|
105
143
|
}
|
|
106
144
|
}
|
|
107
145
|
}
|
|
108
|
-
ensureLightmapMaterial(material, index) {
|
|
109
|
-
if (!material.userData)
|
|
110
|
-
material.userData = {};
|
|
111
|
-
// if (material instanceof MeshPhysicalMaterial) {
|
|
112
|
-
// return material;
|
|
113
|
-
// }
|
|
114
|
-
// check if the material version has changed and only then clone the material
|
|
115
|
-
if (this.clonedMaterials[index] !== material) {
|
|
116
|
-
if (debug) {
|
|
117
|
-
++cloningCounter;
|
|
118
|
-
if (cloningCounter++ < 1000) {
|
|
119
|
-
console.warn(`Cloning material for lightmap ${this.renderer.name}: '${material.name}'`);
|
|
120
|
-
}
|
|
121
|
-
else if (cloningCounter === 1000) {
|
|
122
|
-
console.warn(`Further material cloning for lightmaps suppressed to avoid flooding the console.`);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
const mat = material.clone();
|
|
126
|
-
if (!mat.name?.includes("(lightmap)"))
|
|
127
|
-
mat.name = material.name + " (lightmap)";
|
|
128
|
-
material = mat;
|
|
129
|
-
material.onBeforeCompile = this.onBeforeCompile;
|
|
130
|
-
this.clonedMaterials[index] = material;
|
|
131
|
-
}
|
|
132
|
-
return material;
|
|
133
|
-
}
|
|
134
|
-
assignLightmapTexture(material) {
|
|
135
|
-
if (!material)
|
|
136
|
-
return;
|
|
137
|
-
if (material instanceof MeshPhysicalMaterial && material.transmission > 0) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
const hasChanged = material.lightMap !== this.lightmapTexture || material[$lightmapVersion] !== material.version;
|
|
141
|
-
if (!hasChanged) {
|
|
142
|
-
return;
|
|
143
|
-
}
|
|
144
|
-
if (debug)
|
|
145
|
-
console.log(`Assigning lightmap texture ${this.renderer.name}: '${material.name}' (${material.version} ${material[$lightmapVersion]})`);
|
|
146
|
-
// assign the lightmap
|
|
147
|
-
material.lightMap = this.lightmapTexture;
|
|
148
|
-
material.needsUpdate = true;
|
|
149
|
-
// store the version of the material
|
|
150
|
-
material[$lightmapVersion] = material.version;
|
|
151
|
-
}
|
|
152
|
-
onBeforeCompile = (shader, _) => {
|
|
153
|
-
if (debug === "verbose")
|
|
154
|
-
console.log("Lightmaps, before compile\n", shader);
|
|
155
|
-
this.lightmapScaleOffsetUniform.value = this.lightmapScaleOffset;
|
|
156
|
-
this.lightmapUniform.value = this.lightmapTexture;
|
|
157
|
-
shader.uniforms.lightmapScaleOffset = this.lightmapScaleOffsetUniform;
|
|
158
|
-
};
|
|
159
146
|
setLightmapDebugMaterial() {
|
|
147
|
+
const so = this.lightmapScaleOffset;
|
|
160
148
|
// debug lightmaps
|
|
161
149
|
this.gameObject["material"] = new ShaderMaterial({
|
|
162
150
|
vertexShader: `
|
|
@@ -170,7 +158,6 @@ export class RendererLightmap {
|
|
|
170
158
|
fragmentShader: `
|
|
171
159
|
uniform sampler2D lightMap;
|
|
172
160
|
uniform float lightMapIntensity;
|
|
173
|
-
uniform vec4 lightmapScaleOffset;
|
|
174
161
|
varying vec2 vUv1;
|
|
175
162
|
|
|
176
163
|
// took from threejs 05fc79cd52b79e8c3e8dec1e7dca72c5c39983a4
|
|
@@ -179,8 +166,8 @@ export class RendererLightmap {
|
|
|
179
166
|
}
|
|
180
167
|
|
|
181
168
|
void main() {
|
|
182
|
-
vec2 lUv = vUv1.xy *
|
|
183
|
-
|
|
169
|
+
vec2 lUv = vUv1.xy * vec2(${so.x.toFixed(6)}, ${so.y.toFixed(6)}) + vec2(${so.z.toFixed(6)}, ${(1 - so.y - so.w).toFixed(6)});
|
|
170
|
+
|
|
184
171
|
vec4 lightMapTexel = texture2D( lightMap, lUv);
|
|
185
172
|
gl_FragColor = lightMapTexel;
|
|
186
173
|
gl_FragColor.a = 1.;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RendererLightmap.js","sourceRoot":"","sources":["../../src/engine-components/RendererLightmap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"RendererLightmap.js","sourceRoot":"","sources":["../../src/engine-components/RendererLightmap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAY,cAAc,EAAW,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAGzF,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,MAAM,2CAA2C,CAAC;AAGlF,MAAM,KAAK,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Q,CAAC,YAAY,CAAC,KAAK,CAAC,EAAE;gBACtC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC;aAC3E;SACJ;aACI,IAAI,MAAM,YAAY,KAAK,EAAE;YAC9B,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,QAAQ,EAAE;gBACjC,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;aACjC;SACJ;IACL,CAAC;IAEO,wBAAwB;QAC5B,MAAM,EAAE,GAAG,IAAI,CAAC,mBAAmB,CAAC;QAEpC,kBAAkB;QAClB,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,GAAG,IAAI,cAAc,CAAC;YAC7C,YAAY,EAAE;;;;;;;iBAOT;YACL,cAAc,EAAE;;;;;;;;;;;gDAWoB,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC;;;;;;iBAM9H;YACL,OAAO,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE;SAChC,CAAC,CAAC;IACP,CAAC;CACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/engine",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.14.0-next.31f837e",
|
|
4
4
|
"description": "Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.",
|
|
5
5
|
"main": "dist/needle-engine.min.js",
|
|
6
6
|
"exports": {
|
|
@@ -111,7 +111,7 @@
|
|
|
111
111
|
"scroll-timeline-polyfill": "^1.1.0",
|
|
112
112
|
"simplex-noise": "^4.0.1",
|
|
113
113
|
"stats.js": "^0.17.0",
|
|
114
|
-
"three": "npm:@needle-tools/three@0.169.
|
|
114
|
+
"three": "npm:@needle-tools/three@0.169.17",
|
|
115
115
|
"three-mesh-bvh": "0.9.7",
|
|
116
116
|
"three-mesh-ui": "npm:@needle-tools/three-mesh-ui@^7.1.5-alpha.5",
|
|
117
117
|
"three.quarks": "0.15.6",
|
package/src/engine/api.ts
CHANGED
|
@@ -56,6 +56,7 @@ export * from "./engine_networking_peer.js";
|
|
|
56
56
|
export * from "./engine_networking_streams.js";
|
|
57
57
|
export * from "./engine_networking_types.js";
|
|
58
58
|
export * from "./engine_networking_utils.js";
|
|
59
|
+
export { MaterialPropertyBlock } from "./engine_materialpropertyblock.js"
|
|
59
60
|
export * from "./engine_patcher.js";
|
|
60
61
|
export * from "./engine_physics.js";
|
|
61
62
|
export * from "./engine_physics.types.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ShaderChunk, Texture
|
|
1
|
+
import { ShaderChunk, Texture } from "three";
|
|
2
2
|
|
|
3
3
|
import { setDisposable } from "./engine_assetdatabase.js";
|
|
4
4
|
import type { Context } from "./engine_setup.js";
|
|
@@ -91,9 +91,10 @@ export class LightDataRegistry implements ILightDataRegistry {
|
|
|
91
91
|
// all the chunks we can patch
|
|
92
92
|
// console.log(ShaderChunk);
|
|
93
93
|
// Unity: ambientOrLightmapUV.xy = v.uv1.xy * unity_LightmapST.xy + unity_LightmapST.zw; ambientOrLightmapUV.zw = 0;
|
|
94
|
+
// Replace standard lightmap sampling with RGBM decode.
|
|
95
|
+
// UV transform (scale/offset) is handled natively by three.js via texture.offset/repeat → lightMapTransform.
|
|
94
96
|
ShaderChunk.lights_fragment_maps = ShaderChunk.lights_fragment_maps.replace("vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );", `
|
|
95
|
-
|
|
96
|
-
vec4 lightMapTexel = texture2D( lightMap, lUv);
|
|
97
|
+
vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );
|
|
97
98
|
// The range of RGBM lightmaps goes from 0 to 34.49 (5^2.2) in linear space, and from 0 to 5 in gamma space.
|
|
98
99
|
lightMapTexel.rgb *= lightMapTexel.a * 8.; // no idea where that "8" comes from... heuristically derived
|
|
99
100
|
lightMapTexel.a = 1.;
|
|
@@ -104,8 +105,7 @@ ShaderChunk.lightmap_pars_fragment = `
|
|
|
104
105
|
#ifdef USE_LIGHTMAP
|
|
105
106
|
uniform sampler2D lightMap;
|
|
106
107
|
uniform float lightMapIntensity;
|
|
107
|
-
|
|
108
|
-
|
|
108
|
+
|
|
109
109
|
// took from threejs 05fc79cd52b79e8c3e8dec1e7dca72c5c39983a4
|
|
110
110
|
vec4 conv_sRGBToLinear( in vec4 value ) {
|
|
111
111
|
return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );
|
|
@@ -125,4 +125,6 @@ irradiance += 0.;
|
|
|
125
125
|
irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );
|
|
126
126
|
#endif`);
|
|
127
127
|
|
|
128
|
-
|
|
128
|
+
// lightmapScaleOffset is no longer needed as a uniform -
|
|
129
|
+
// UV transform is encoded in the lightMap texture's offset/repeat properties
|
|
130
|
+
// and applied natively by three.js via lightMapTransform in the vertex shader.
|