matrix-engine-wgpu 1.4.2 → 1.4.4
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/examples/load-obj-file.js +6 -1
- package/index.js +17 -10
- package/package.json +1 -1
- package/public/css/style.css +1 -1
- package/public/examples.js +97 -44
- package/readme.md +88 -64
- package/src/engine/behavior.js +35 -0
- package/src/engine/lights.js +9 -1
- package/src/engine/mesh-obj.js +18 -9
- package/src/engine/utils.js +1 -9
- package/src/shaders/fragment.wgsl.js +6 -4
- package/src/world.js +2 -5
|
@@ -81,8 +81,13 @@ export var loadObjFile = function() {
|
|
|
81
81
|
|
|
82
82
|
var TEST = loadObjFile.getSceneObjectByName('cube2');
|
|
83
83
|
console.log(`%c Test access scene ${TEST} object.`, LOG_MATRIX);
|
|
84
|
+
|
|
84
85
|
loadObjFile.addLight();
|
|
85
|
-
|
|
86
|
+
loadObjFile.lightContainer[0].behavior.setOsc0(-1,1,0.1)
|
|
87
|
+
loadObjFile.lightContainer[0].behavior.value_ = -1;
|
|
88
|
+
loadObjFile.lightContainer[0].updater.push((light) => {
|
|
89
|
+
light.position[0] = light.behavior.setPath0()
|
|
90
|
+
})
|
|
86
91
|
|
|
87
92
|
}
|
|
88
93
|
})
|
package/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This file created by:
|
|
3
|
-
* Nikola Lukic
|
|
4
|
-
*
|
|
3
|
+
* @author Nikola Lukic
|
|
4
|
+
* @email zlatnaspirala@gmail.com mart 2024
|
|
5
|
+
* @description npm import/export
|
|
5
6
|
*/
|
|
6
7
|
// import {degToRad, radToDeg} from "./utils";
|
|
7
8
|
import {downloadMeshes, makeObjSeqArg} from "./src/engine/loader-obj.js";
|
|
@@ -13,16 +14,20 @@ import {
|
|
|
13
14
|
computeWorldVertsAndAABB, rayIntersectsAABB,
|
|
14
15
|
computeAABB
|
|
15
16
|
} from "./src/engine/raycast.js";
|
|
17
|
+
import {OSCILLATOR, SWITCHER} from "./src/engine/utils.js";
|
|
16
18
|
|
|
17
19
|
var about = () => {
|
|
18
|
-
console.
|
|
19
|
-
console.
|
|
20
|
-
console.
|
|
21
|
-
console.
|
|
22
|
-
console.
|
|
23
|
-
console.
|
|
24
|
-
console.
|
|
25
|
-
console.
|
|
20
|
+
console.info("Hi npm. matrix-engine for webgpu is ready...")
|
|
21
|
+
console.info("--------------------------------------------")
|
|
22
|
+
console.info("List of features: ")
|
|
23
|
+
console.info(" - Loading obj files with uvs")
|
|
24
|
+
console.info(" - Scene camera use -z front")
|
|
25
|
+
console.info(" - position, rotation - same like matrix-engine")
|
|
26
|
+
console.info(" - Physics used Ammo.js build")
|
|
27
|
+
console.info(" - Raycaster HIT/CLICK on object scene")
|
|
28
|
+
console.info(" - Light cast shadow multi lights")
|
|
29
|
+
console.info("--------------------------------------------")
|
|
30
|
+
|
|
26
31
|
}
|
|
27
32
|
|
|
28
33
|
export {
|
|
@@ -37,5 +42,7 @@ export {
|
|
|
37
42
|
computeAABB,
|
|
38
43
|
computeWorldVertsAndAABB,
|
|
39
44
|
makeObjSeqArg,
|
|
45
|
+
SWITCHER,
|
|
46
|
+
OSCILLATOR,
|
|
40
47
|
about
|
|
41
48
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "matrix-engine-wgpu",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "Fixed shadows casting vs camera/video texture, webGPU powered pwa application. Crazy fast rendering with AmmoJS physics support. Simple raycaster hit object added.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
package/public/css/style.css
CHANGED
package/public/examples.js
CHANGED
|
@@ -68,7 +68,7 @@ function destroyJambDoms() {
|
|
|
68
68
|
(0, _loadObjsSequence.loadObjsSequence)();
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
-
},{"./examples/camera-texture.js":2,"./examples/load-obj-file.js":3,"./examples/load-objs-sequence.js":4,"./examples/unlit-textures.js":5,"./examples/video-texture.js":6,"./src/engine/utils.js":
|
|
71
|
+
},{"./examples/camera-texture.js":2,"./examples/load-obj-file.js":3,"./examples/load-objs-sequence.js":4,"./examples/unlit-textures.js":5,"./examples/video-texture.js":6,"./src/engine/utils.js":18}],2:[function(require,module,exports){
|
|
72
72
|
"use strict";
|
|
73
73
|
|
|
74
74
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -149,7 +149,7 @@ var loadCameraTexture = function () {
|
|
|
149
149
|
};
|
|
150
150
|
exports.loadCameraTexture = loadCameraTexture;
|
|
151
151
|
|
|
152
|
-
},{"../src/engine/loader-obj.js":
|
|
152
|
+
},{"../src/engine/loader-obj.js":13,"../src/engine/raycast.js":17,"../src/engine/utils.js":18,"../src/world.js":27}],3:[function(require,module,exports){
|
|
153
153
|
"use strict";
|
|
154
154
|
|
|
155
155
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -278,7 +278,11 @@ var loadObjFile = function () {
|
|
|
278
278
|
var TEST = loadObjFile.getSceneObjectByName('cube2');
|
|
279
279
|
console.log(`%c Test access scene ${TEST} object.`, _utils.LOG_MATRIX);
|
|
280
280
|
loadObjFile.addLight();
|
|
281
|
-
|
|
281
|
+
loadObjFile.lightContainer[0].behavior.setOsc0(-1, 1, 0.1);
|
|
282
|
+
loadObjFile.lightContainer[0].behavior.value_ = -1;
|
|
283
|
+
loadObjFile.lightContainer[0].updater.push(light => {
|
|
284
|
+
light.position[0] = light.behavior.setPath0();
|
|
285
|
+
});
|
|
282
286
|
}
|
|
283
287
|
});
|
|
284
288
|
// just for dev
|
|
@@ -286,7 +290,7 @@ var loadObjFile = function () {
|
|
|
286
290
|
};
|
|
287
291
|
exports.loadObjFile = loadObjFile;
|
|
288
292
|
|
|
289
|
-
},{"../src/engine/loader-obj.js":
|
|
293
|
+
},{"../src/engine/loader-obj.js":13,"../src/engine/utils.js":18,"../src/world.js":27}],4:[function(require,module,exports){
|
|
290
294
|
"use strict";
|
|
291
295
|
|
|
292
296
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -376,7 +380,7 @@ var loadObjsSequence = function () {
|
|
|
376
380
|
};
|
|
377
381
|
exports.loadObjsSequence = loadObjsSequence;
|
|
378
382
|
|
|
379
|
-
},{"../src/engine/loader-obj.js":
|
|
383
|
+
},{"../src/engine/loader-obj.js":13,"../src/engine/utils.js":18,"../src/world.js":27}],5:[function(require,module,exports){
|
|
380
384
|
"use strict";
|
|
381
385
|
|
|
382
386
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -437,7 +441,7 @@ var unlitTextures = function () {
|
|
|
437
441
|
};
|
|
438
442
|
exports.unlitTextures = unlitTextures;
|
|
439
443
|
|
|
440
|
-
},{"../src/world.js":
|
|
444
|
+
},{"../src/world.js":27}],6:[function(require,module,exports){
|
|
441
445
|
"use strict";
|
|
442
446
|
|
|
443
447
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -521,7 +525,7 @@ var loadVideoTexture = function () {
|
|
|
521
525
|
};
|
|
522
526
|
exports.loadVideoTexture = loadVideoTexture;
|
|
523
527
|
|
|
524
|
-
},{"../src/engine/loader-obj.js":
|
|
528
|
+
},{"../src/engine/loader-obj.js":13,"../src/engine/raycast.js":17,"../src/engine/utils.js":18,"../src/world.js":27}],7:[function(require,module,exports){
|
|
525
529
|
"use strict";
|
|
526
530
|
|
|
527
531
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -6282,7 +6286,45 @@ class MEBall {
|
|
|
6282
6286
|
}
|
|
6283
6287
|
exports.default = MEBall;
|
|
6284
6288
|
|
|
6285
|
-
},{"../shaders/shaders":
|
|
6289
|
+
},{"../shaders/shaders":23,"./engine":11,"./matrix-class":15,"wgpu-matrix":7}],9:[function(require,module,exports){
|
|
6290
|
+
"use strict";
|
|
6291
|
+
|
|
6292
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6293
|
+
value: true
|
|
6294
|
+
});
|
|
6295
|
+
exports.default = void 0;
|
|
6296
|
+
var _utils = require("./utils");
|
|
6297
|
+
/**
|
|
6298
|
+
* @description
|
|
6299
|
+
* Can be reuse for any other tasks.
|
|
6300
|
+
* @author Nikola Lukic
|
|
6301
|
+
*/
|
|
6302
|
+
|
|
6303
|
+
class Behavior {
|
|
6304
|
+
status = "Only oscillator";
|
|
6305
|
+
constructor() {
|
|
6306
|
+
this.osc0 = new _utils.OSCILLATOR(0, 5, 0.01);
|
|
6307
|
+
}
|
|
6308
|
+
setOsc0(min, max, step) {
|
|
6309
|
+
this.osc0.min = min;
|
|
6310
|
+
this.osc0.max = max;
|
|
6311
|
+
this.osc0.step = step;
|
|
6312
|
+
}
|
|
6313
|
+
|
|
6314
|
+
// apend - keep init origin
|
|
6315
|
+
addPath(NUMBER) {
|
|
6316
|
+
let inc = this.osc0.UPDATE();
|
|
6317
|
+
console.log('test inc', inc);
|
|
6318
|
+
console.log('test inc + number', NUMBER + inc);
|
|
6319
|
+
return inc + NUMBER;
|
|
6320
|
+
}
|
|
6321
|
+
setPath0() {
|
|
6322
|
+
return this.osc0.UPDATE();
|
|
6323
|
+
}
|
|
6324
|
+
}
|
|
6325
|
+
exports.default = Behavior;
|
|
6326
|
+
|
|
6327
|
+
},{"./utils":18}],10:[function(require,module,exports){
|
|
6286
6328
|
"use strict";
|
|
6287
6329
|
|
|
6288
6330
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -6707,7 +6749,7 @@ class MECube {
|
|
|
6707
6749
|
}
|
|
6708
6750
|
exports.default = MECube;
|
|
6709
6751
|
|
|
6710
|
-
},{"../shaders/shaders":
|
|
6752
|
+
},{"../shaders/shaders":23,"./engine":11,"./matrix-class":15,"wgpu-matrix":7}],11:[function(require,module,exports){
|
|
6711
6753
|
"use strict";
|
|
6712
6754
|
|
|
6713
6755
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -7121,7 +7163,7 @@ function createInputHandler(window, canvas) {
|
|
|
7121
7163
|
};
|
|
7122
7164
|
}
|
|
7123
7165
|
|
|
7124
|
-
},{"./utils":
|
|
7166
|
+
},{"./utils":18,"wgpu-matrix":7}],12:[function(require,module,exports){
|
|
7125
7167
|
"use strict";
|
|
7126
7168
|
|
|
7127
7169
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -7130,6 +7172,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7130
7172
|
exports.SpotLight = void 0;
|
|
7131
7173
|
var _wgpuMatrix = require("wgpu-matrix");
|
|
7132
7174
|
var _vertexShadow = require("../shaders/vertexShadow.wgsl");
|
|
7175
|
+
var _behavior = _interopRequireDefault(require("./behavior"));
|
|
7176
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
7133
7177
|
/**
|
|
7134
7178
|
* @description
|
|
7135
7179
|
* Spot light with shodow cast.
|
|
@@ -7302,9 +7346,17 @@ class SpotLight {
|
|
|
7302
7346
|
});
|
|
7303
7347
|
return this.mainPassBindGroupContainer[index];
|
|
7304
7348
|
};
|
|
7349
|
+
|
|
7350
|
+
// Only osc values +-
|
|
7351
|
+
this.behavior = new _behavior.default();
|
|
7352
|
+
|
|
7353
|
+
// put here only func
|
|
7354
|
+
this.updater = [];
|
|
7305
7355
|
}
|
|
7306
7356
|
update() {
|
|
7307
|
-
|
|
7357
|
+
this.updater.forEach(update => {
|
|
7358
|
+
update(this);
|
|
7359
|
+
});
|
|
7308
7360
|
this.direction = _wgpuMatrix.vec3.normalize(_wgpuMatrix.vec3.subtract(this.target, this.position));
|
|
7309
7361
|
const target = _wgpuMatrix.vec3.add(this.position, this.direction);
|
|
7310
7362
|
this.viewMatrix = _wgpuMatrix.mat4.lookAt(this.position, target, this.up);
|
|
@@ -7321,7 +7373,7 @@ class SpotLight {
|
|
|
7321
7373
|
}
|
|
7322
7374
|
exports.SpotLight = SpotLight;
|
|
7323
7375
|
|
|
7324
|
-
},{"../shaders/vertexShadow.wgsl":
|
|
7376
|
+
},{"../shaders/vertexShadow.wgsl":25,"./behavior":9,"wgpu-matrix":7}],13:[function(require,module,exports){
|
|
7325
7377
|
"use strict";
|
|
7326
7378
|
|
|
7327
7379
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -7789,7 +7841,7 @@ function play(nameAni) {
|
|
|
7789
7841
|
this.playing = true;
|
|
7790
7842
|
}
|
|
7791
7843
|
|
|
7792
|
-
},{}],
|
|
7844
|
+
},{}],14:[function(require,module,exports){
|
|
7793
7845
|
"use strict";
|
|
7794
7846
|
|
|
7795
7847
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -8143,7 +8195,7 @@ class Materials {
|
|
|
8143
8195
|
}
|
|
8144
8196
|
exports.default = Materials;
|
|
8145
8197
|
|
|
8146
|
-
},{}],
|
|
8198
|
+
},{}],15:[function(require,module,exports){
|
|
8147
8199
|
"use strict";
|
|
8148
8200
|
|
|
8149
8201
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -8379,7 +8431,7 @@ class Rotation {
|
|
|
8379
8431
|
}
|
|
8380
8432
|
exports.Rotation = Rotation;
|
|
8381
8433
|
|
|
8382
|
-
},{"./utils":
|
|
8434
|
+
},{"./utils":18}],16:[function(require,module,exports){
|
|
8383
8435
|
"use strict";
|
|
8384
8436
|
|
|
8385
8437
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -8396,7 +8448,7 @@ var _materials = _interopRequireDefault(require("./materials"));
|
|
|
8396
8448
|
var _fragmentVideo = require("../shaders/fragment.video.wgsl");
|
|
8397
8449
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8398
8450
|
class MEMeshObj extends _materials.default {
|
|
8399
|
-
constructor(canvas, device, context, o, inputHandler) {
|
|
8451
|
+
constructor(canvas, device, context, o, inputHandler, globalAmbient) {
|
|
8400
8452
|
super(device);
|
|
8401
8453
|
if (typeof o.name === 'undefined') o.name = (0, _utils.genName)(3);
|
|
8402
8454
|
if (typeof o.raycast === 'undefined') {
|
|
@@ -8415,6 +8467,7 @@ class MEMeshObj extends _materials.default {
|
|
|
8415
8467
|
this.clearColor = "red";
|
|
8416
8468
|
this.video = null;
|
|
8417
8469
|
this.FINISH_VIDIO_INIT = false;
|
|
8470
|
+
this.globalAmbient = globalAmbient;
|
|
8418
8471
|
|
|
8419
8472
|
// Mesh stuff - for single mesh or t-posed (fiktive-first in loading order)
|
|
8420
8473
|
this.mesh = o.mesh;
|
|
@@ -8559,7 +8612,7 @@ class MEMeshObj extends _materials.default {
|
|
|
8559
8612
|
});
|
|
8560
8613
|
this.sceneUniformBuffer = this.device.createBuffer({
|
|
8561
8614
|
label: 'sceneUniformBuffer per mesh',
|
|
8562
|
-
size:
|
|
8615
|
+
size: 176,
|
|
8563
8616
|
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
8564
8617
|
});
|
|
8565
8618
|
this.uniformBufferBindGroupLayout = this.device.createBindGroupLayout({
|
|
@@ -8607,10 +8660,9 @@ class MEMeshObj extends _materials.default {
|
|
|
8607
8660
|
camera.update(dt, inputHandler());
|
|
8608
8661
|
const camVP = _wgpuMatrix.mat4.multiply(camera.projectionMatrix, camera.view);
|
|
8609
8662
|
for (const mesh of mainRenderBundle) {
|
|
8610
|
-
|
|
8611
|
-
const sceneData = new Float32Array(16 + 16 + 4 + 4); // 16+16+4+4 = 40 floats
|
|
8663
|
+
const sceneData = new Float32Array(44);
|
|
8612
8664
|
|
|
8613
|
-
// Light
|
|
8665
|
+
// Light VP
|
|
8614
8666
|
sceneData.set(spotLight.viewProjMatrix, 0);
|
|
8615
8667
|
|
|
8616
8668
|
// Camera VP
|
|
@@ -8621,9 +8673,10 @@ class MEMeshObj extends _materials.default {
|
|
|
8621
8673
|
|
|
8622
8674
|
// Light position + padding
|
|
8623
8675
|
sceneData.set([spotLight.position[0], spotLight.position[1], spotLight.position[2], 0.0], 36);
|
|
8624
|
-
|
|
8625
|
-
//
|
|
8626
|
-
0,
|
|
8676
|
+
|
|
8677
|
+
// Global ambient + padding
|
|
8678
|
+
sceneData.set([this.globalAmbient[0], this.globalAmbient[1], this.globalAmbient[2], 0.0], 40);
|
|
8679
|
+
device.queue.writeBuffer(mesh.sceneUniformBuffer, 0, sceneData.buffer, sceneData.byteOffset, sceneData.byteLength);
|
|
8627
8680
|
}
|
|
8628
8681
|
};
|
|
8629
8682
|
this.getModelMatrix = pos => {
|
|
@@ -8816,7 +8869,7 @@ class MEMeshObj extends _materials.default {
|
|
|
8816
8869
|
}
|
|
8817
8870
|
exports.default = MEMeshObj;
|
|
8818
8871
|
|
|
8819
|
-
},{"../shaders/fragment.video.wgsl":
|
|
8872
|
+
},{"../shaders/fragment.video.wgsl":21,"../shaders/fragment.wgsl":22,"../shaders/vertex.wgsl":24,"../shaders/vertexShadow.wgsl":25,"./materials":14,"./matrix-class":15,"./utils":18,"wgpu-matrix":7}],17:[function(require,module,exports){
|
|
8820
8873
|
"use strict";
|
|
8821
8874
|
|
|
8822
8875
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -9031,7 +9084,7 @@ function addRaycastsAABBListener(canvasId = "canvas1") {
|
|
|
9031
9084
|
});
|
|
9032
9085
|
}
|
|
9033
9086
|
|
|
9034
|
-
},{"wgpu-matrix":7}],
|
|
9087
|
+
},{"wgpu-matrix":7}],18:[function(require,module,exports){
|
|
9035
9088
|
"use strict";
|
|
9036
9089
|
|
|
9037
9090
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -9538,7 +9591,7 @@ function OSCILLATOR(min, max, step) {
|
|
|
9538
9591
|
}
|
|
9539
9592
|
};
|
|
9540
9593
|
} else {
|
|
9541
|
-
console.log("
|
|
9594
|
+
console.log("OSCILLATOR ERROR");
|
|
9542
9595
|
}
|
|
9543
9596
|
}
|
|
9544
9597
|
|
|
@@ -9917,7 +9970,7 @@ function setupCanvasFilters(canvasId) {
|
|
|
9917
9970
|
updateFilter(); // Initial
|
|
9918
9971
|
}
|
|
9919
9972
|
|
|
9920
|
-
},{}],
|
|
9973
|
+
},{}],19:[function(require,module,exports){
|
|
9921
9974
|
"use strict";
|
|
9922
9975
|
|
|
9923
9976
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -9957,7 +10010,7 @@ class MultiLang {
|
|
|
9957
10010
|
}
|
|
9958
10011
|
exports.MultiLang = MultiLang;
|
|
9959
10012
|
|
|
9960
|
-
},{"../engine/utils":
|
|
10013
|
+
},{"../engine/utils":18}],20:[function(require,module,exports){
|
|
9961
10014
|
"use strict";
|
|
9962
10015
|
|
|
9963
10016
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -10241,7 +10294,7 @@ class MatrixAmmo {
|
|
|
10241
10294
|
}
|
|
10242
10295
|
exports.default = MatrixAmmo;
|
|
10243
10296
|
|
|
10244
|
-
},{"../engine/utils":
|
|
10297
|
+
},{"../engine/utils":18}],21:[function(require,module,exports){
|
|
10245
10298
|
"use strict";
|
|
10246
10299
|
|
|
10247
10300
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -10333,7 +10386,7 @@ fn main(input : FragmentInput) -> @location(0) vec4f {
|
|
|
10333
10386
|
}
|
|
10334
10387
|
`;
|
|
10335
10388
|
|
|
10336
|
-
},{}],
|
|
10389
|
+
},{}],22:[function(require,module,exports){
|
|
10337
10390
|
"use strict";
|
|
10338
10391
|
|
|
10339
10392
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -10351,6 +10404,8 @@ struct Scene {
|
|
|
10351
10404
|
padding2 : f32, // align to 16 bytes
|
|
10352
10405
|
lightPos : vec3f,
|
|
10353
10406
|
padding : f32, // align to 16 bytes
|
|
10407
|
+
globalAmbient : vec3f, // <--- new
|
|
10408
|
+
padding3 : f32, // keep alignment (16 bytes)
|
|
10354
10409
|
};
|
|
10355
10410
|
|
|
10356
10411
|
struct SpotLight {
|
|
@@ -10456,7 +10511,7 @@ fn main(input: FragmentInput) -> @location(0) vec4f {
|
|
|
10456
10511
|
// let viewDir = normalize(scene.cameraViewProjMatrix[3].xyz - input.fragPos);
|
|
10457
10512
|
|
|
10458
10513
|
var lightContribution = vec3f(0.0);
|
|
10459
|
-
var ambient = vec3f(0.
|
|
10514
|
+
var ambient = vec3f(0.5);
|
|
10460
10515
|
|
|
10461
10516
|
for (var i: u32 = 0u; i < MAX_SPOTLIGHTS; i = i + 1u) {
|
|
10462
10517
|
let sc = spotlights[i].lightViewProj * vec4<f32>(input.fragPos, 1.0);
|
|
@@ -10470,15 +10525,15 @@ fn main(input: FragmentInput) -> @location(0) vec4f {
|
|
|
10470
10525
|
let visibility = sampleShadow(uv, i32(i), depthRef - bias, norm, lightDir);
|
|
10471
10526
|
let contrib = computeSpotLight(spotlights[i], norm, input.fragPos, viewDir);
|
|
10472
10527
|
lightContribution += contrib * visibility;
|
|
10473
|
-
ambient += spotlights[i].ambientFactor * spotlights[i].color;
|
|
10528
|
+
// ambient += spotlights[i].ambientFactor * spotlights[i].color;
|
|
10474
10529
|
}
|
|
10475
|
-
|
|
10530
|
+
// ambient /= f32(MAX_SPOTLIGHTS); PREVENT OVER NEXT FEATURE ON SWICHER
|
|
10476
10531
|
let texColor = textureSample(meshTexture, meshSampler, input.uv);
|
|
10477
|
-
let finalColor = texColor.rgb * (
|
|
10532
|
+
let finalColor = texColor.rgb * (scene.globalAmbient + lightContribution); // * albedo;
|
|
10478
10533
|
return vec4f(finalColor, 1.0);
|
|
10479
10534
|
}`;
|
|
10480
10535
|
|
|
10481
|
-
},{}],
|
|
10536
|
+
},{}],23:[function(require,module,exports){
|
|
10482
10537
|
"use strict";
|
|
10483
10538
|
|
|
10484
10539
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -10536,7 +10591,7 @@ fn fragmentMain(input: VertexOutput) -> @location(0) vec4f {
|
|
|
10536
10591
|
return vec4f(textureColor.rgb * lightColor, textureColor.a);
|
|
10537
10592
|
}`;
|
|
10538
10593
|
|
|
10539
|
-
},{}],
|
|
10594
|
+
},{}],24:[function(require,module,exports){
|
|
10540
10595
|
"use strict";
|
|
10541
10596
|
|
|
10542
10597
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -10584,7 +10639,7 @@ fn main(
|
|
|
10584
10639
|
return output;
|
|
10585
10640
|
}`;
|
|
10586
10641
|
|
|
10587
|
-
},{}],
|
|
10642
|
+
},{}],25:[function(require,module,exports){
|
|
10588
10643
|
"use strict";
|
|
10589
10644
|
|
|
10590
10645
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -10612,7 +10667,7 @@ fn main(
|
|
|
10612
10667
|
}
|
|
10613
10668
|
`;
|
|
10614
10669
|
|
|
10615
|
-
},{}],
|
|
10670
|
+
},{}],26:[function(require,module,exports){
|
|
10616
10671
|
"use strict";
|
|
10617
10672
|
|
|
10618
10673
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -10682,7 +10737,7 @@ class MatrixSounds {
|
|
|
10682
10737
|
}
|
|
10683
10738
|
exports.MatrixSounds = MatrixSounds;
|
|
10684
10739
|
|
|
10685
|
-
},{}],
|
|
10740
|
+
},{}],27:[function(require,module,exports){
|
|
10686
10741
|
"use strict";
|
|
10687
10742
|
|
|
10688
10743
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -10825,6 +10880,7 @@ class MatrixEngineWGPU {
|
|
|
10825
10880
|
} else {
|
|
10826
10881
|
this.frame = this.framePassPerObject;
|
|
10827
10882
|
}
|
|
10883
|
+
this.globalAmbient = _wgpuMatrix.vec3.create(0.5, 0.5, 0.5);
|
|
10828
10884
|
this.MAX_SPOTLIGHTS = 20;
|
|
10829
10885
|
this.inputHandler = (0, _engine.createInputHandler)(window, canvas);
|
|
10830
10886
|
this.createGlobalStuff();
|
|
@@ -11211,7 +11267,7 @@ class MatrixEngineWGPU {
|
|
|
11211
11267
|
}
|
|
11212
11268
|
};
|
|
11213
11269
|
}
|
|
11214
|
-
let myMesh1 = new _meshObj.default(this.canvas, this.device, this.context, o, this.inputHandler);
|
|
11270
|
+
let myMesh1 = new _meshObj.default(this.canvas, this.device, this.context, o, this.inputHandler, this.globalAmbient);
|
|
11215
11271
|
myMesh1.spotlightUniformBuffer = this.spotlightUniformBuffer;
|
|
11216
11272
|
myMesh1.clearColor = clearColor;
|
|
11217
11273
|
if (o.physics.enabled == true) {
|
|
@@ -11276,13 +11332,10 @@ class MatrixEngineWGPU {
|
|
|
11276
11332
|
// 1️⃣ Update light data (position, direction, uniforms)
|
|
11277
11333
|
for (const light of this.lightContainer) {
|
|
11278
11334
|
light.update();
|
|
11279
|
-
// light.updateSceneUniforms(this.mainRenderBundle, this.cameras.WASD);
|
|
11280
11335
|
this.mainRenderBundle.forEach((meItem, index) => {
|
|
11281
11336
|
meItem.position.update();
|
|
11282
11337
|
meItem.updateModelUniformBuffer();
|
|
11283
|
-
// if(meItem.isVideo != true) {
|
|
11284
11338
|
meItem.getTransformationMatrix(this.mainRenderBundle, light);
|
|
11285
|
-
// }
|
|
11286
11339
|
});
|
|
11287
11340
|
}
|
|
11288
11341
|
if (this.matrixAmmo) this.matrixAmmo.updatePhysics();
|
|
@@ -11372,4 +11425,4 @@ class MatrixEngineWGPU {
|
|
|
11372
11425
|
}
|
|
11373
11426
|
exports.default = MatrixEngineWGPU;
|
|
11374
11427
|
|
|
11375
|
-
},{"./engine/ball.js":8,"./engine/cube.js":
|
|
11428
|
+
},{"./engine/ball.js":8,"./engine/cube.js":10,"./engine/engine.js":11,"./engine/lights.js":12,"./engine/loader-obj.js":13,"./engine/mesh-obj.js":16,"./engine/utils.js":18,"./multilang/lang.js":19,"./physics/matrix-ammo.js":20,"./sounds/sounds.js":26,"wgpu-matrix":7}]},{},[1]);
|
package/readme.md
CHANGED
|
@@ -45,7 +45,9 @@ Published on npm as: **`matrix-engine-wgpu`**
|
|
|
45
45
|
```js
|
|
46
46
|
app.mainRenderBundle[0];
|
|
47
47
|
```
|
|
48
|
-
|
|
48
|
+
|
|
49
|
+
or
|
|
50
|
+
|
|
49
51
|
```js
|
|
50
52
|
app.getSceneObjectByName("Sphere1");
|
|
51
53
|
```
|
|
@@ -154,17 +156,36 @@ SpotLight – Emits light in a cone shape with configurable cutoff angles.
|
|
|
154
156
|
|
|
155
157
|
Features
|
|
156
158
|
|
|
157
|
-
✅ Supports multiple lights (4 max),
|
|
159
|
+
✅ Supports multiple lights (4 max), ~20 for next update.
|
|
158
160
|
✅ Shadow-ready (spotlight0 shadows implemented, extendable to others)
|
|
159
161
|
|
|
160
|
-
Required:
|
|
162
|
+
Important Required to be added manual:
|
|
163
|
+
|
|
161
164
|
```js
|
|
162
|
-
engine.addLight()
|
|
165
|
+
engine.addLight();
|
|
163
166
|
```
|
|
164
167
|
|
|
165
168
|
Access lights with array lightContainer:
|
|
169
|
+
|
|
166
170
|
```js
|
|
167
|
-
app.lightContainer[0]
|
|
171
|
+
app.lightContainer[0];
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Small behavior object.
|
|
175
|
+
- For now just one ocs0 object
|
|
176
|
+
Everytime if called than updated (light.position[0] = light.behavior.setPath0())
|
|
177
|
+
behavior.setOsc0(min, max, step);
|
|
178
|
+
app.lightContainer[0].behavior.osc0.on_maximum_value = function() {/* what ever*/};
|
|
179
|
+
app.lightContainer[0].behavior.osc0.on_minimum_value = function() {/* what ever*/};
|
|
180
|
+
|
|
181
|
+
Make light move by x.
|
|
182
|
+
```js
|
|
183
|
+
loadObjFile.addLight();
|
|
184
|
+
loadObjFile.lightContainer[0].behavior.setOsc0(-1, 1, 0.01);
|
|
185
|
+
loadObjFile.lightContainer[0].behavior.value_ = -1;
|
|
186
|
+
loadObjFile.lightContainer[0].updater.push(light => {
|
|
187
|
+
light.position[0] = light.behavior.setPath0();
|
|
188
|
+
});
|
|
168
189
|
```
|
|
169
190
|
|
|
170
191
|
### Object Interaction (Raycasting)
|
|
@@ -292,63 +313,65 @@ This example shows how to load and animate a sequence of .obj files to simulate
|
|
|
292
313
|
|
|
293
314
|
```js
|
|
294
315
|
import MatrixEngineWGPU from "../src/world.js";
|
|
295
|
-
import {
|
|
296
|
-
import {
|
|
316
|
+
import {downloadMeshes, makeObjSeqArg} from "../src/engine/loader-obj.js";
|
|
317
|
+
import {LOG_MATRIX} from "../src/engine/utils.js";
|
|
297
318
|
|
|
298
319
|
export var loadObjsSequence = function () {
|
|
299
|
-
let loadObjFile = new MatrixEngineWGPU(
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
320
|
+
let loadObjFile = new MatrixEngineWGPU(
|
|
321
|
+
{
|
|
322
|
+
useSingleRenderPass: true,
|
|
323
|
+
canvasSize: "fullscreen",
|
|
324
|
+
mainCameraParams: {
|
|
325
|
+
type: "WASD",
|
|
326
|
+
responseCoef: 1000,
|
|
327
|
+
},
|
|
305
328
|
},
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
);
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
function onLoadObj(m) {
|
|
322
|
-
console.log(`%c Loaded objs: ${m} `, LOG_MATRIX);
|
|
323
|
-
var objAnim = {
|
|
324
|
-
id: "swat-walk-pistol",
|
|
325
|
-
meshList: m,
|
|
326
|
-
currentAni: 1,
|
|
327
|
-
animations: {
|
|
328
|
-
active: "walk",
|
|
329
|
-
walk: { from: 1, to: 20, speed: 3 },
|
|
330
|
-
walkPistol: { from: 36, to: 60, speed: 3 },
|
|
331
|
-
},
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
loadObjFile.addMeshObj({
|
|
335
|
-
position: { x: 0, y: 2, z: -10 },
|
|
336
|
-
rotation: { x: 0, y: 0, z: 0 },
|
|
337
|
-
rotationSpeed: { x: 0, y: 0, z: 0 },
|
|
338
|
-
scale: [100, 100, 100],
|
|
339
|
-
texturesPaths: ["./res/meshes/blender/cube.png"],
|
|
340
|
-
name: "swat",
|
|
341
|
-
mesh: m["swat-walk-pistol"],
|
|
342
|
-
physics: {
|
|
343
|
-
enabled: false,
|
|
344
|
-
geometry: "Cube",
|
|
345
|
-
},
|
|
346
|
-
objAnim: objAnim,
|
|
329
|
+
() => {
|
|
330
|
+
addEventListener("AmmoReady", () => {
|
|
331
|
+
downloadMeshes(
|
|
332
|
+
makeObjSeqArg({
|
|
333
|
+
id: "swat-walk-pistol",
|
|
334
|
+
path: "res/meshes/objs-sequence/swat-walk-pistol",
|
|
335
|
+
from: 1,
|
|
336
|
+
to: 20,
|
|
337
|
+
}),
|
|
338
|
+
onLoadObj,
|
|
339
|
+
{scale: [10, 10, 10]}
|
|
340
|
+
);
|
|
347
341
|
});
|
|
348
342
|
|
|
349
|
-
|
|
343
|
+
function onLoadObj(m) {
|
|
344
|
+
console.log(`%c Loaded objs: ${m} `, LOG_MATRIX);
|
|
345
|
+
var objAnim = {
|
|
346
|
+
id: "swat-walk-pistol",
|
|
347
|
+
meshList: m,
|
|
348
|
+
currentAni: 1,
|
|
349
|
+
animations: {
|
|
350
|
+
active: "walk",
|
|
351
|
+
walk: {from: 1, to: 20, speed: 3},
|
|
352
|
+
walkPistol: {from: 36, to: 60, speed: 3},
|
|
353
|
+
},
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
loadObjFile.addMeshObj({
|
|
357
|
+
position: {x: 0, y: 2, z: -10},
|
|
358
|
+
rotation: {x: 0, y: 0, z: 0},
|
|
359
|
+
rotationSpeed: {x: 0, y: 0, z: 0},
|
|
360
|
+
scale: [100, 100, 100],
|
|
361
|
+
texturesPaths: ["./res/meshes/blender/cube.png"],
|
|
362
|
+
name: "swat",
|
|
363
|
+
mesh: m["swat-walk-pistol"],
|
|
364
|
+
physics: {
|
|
365
|
+
enabled: false,
|
|
366
|
+
geometry: "Cube",
|
|
367
|
+
},
|
|
368
|
+
objAnim: objAnim,
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
app.mainRenderBundle[0].objAnim.play("walk");
|
|
372
|
+
}
|
|
350
373
|
}
|
|
351
|
-
|
|
374
|
+
);
|
|
352
375
|
|
|
353
376
|
window.app = loadObjFile;
|
|
354
377
|
};
|
|
@@ -358,23 +381,23 @@ export var loadObjsSequence = function () {
|
|
|
358
381
|
|
|
359
382
|
```js
|
|
360
383
|
TEST.loadVideoTexture({
|
|
361
|
-
type:
|
|
362
|
-
src:
|
|
384
|
+
type: "video", // video , camera //not tested yet canvas2d , canvas2dinline
|
|
385
|
+
src: "res/videos/tunel.mp4",
|
|
363
386
|
});
|
|
364
387
|
```
|
|
365
388
|
|
|
366
389
|
For canvasinline attach this to arg (example for direct draw on canvas2d and passing intro webgpu pipeline):
|
|
390
|
+
|
|
367
391
|
```js
|
|
368
392
|
canvaInlineProgram: (ctx, canvas) => {
|
|
369
|
-
ctx.fillStyle =
|
|
393
|
+
ctx.fillStyle = "black";
|
|
370
394
|
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
|
371
|
-
ctx.fillStyle =
|
|
372
|
-
ctx.font =
|
|
395
|
+
ctx.fillStyle = "white";
|
|
396
|
+
ctx.font = "20px Orbitron";
|
|
373
397
|
ctx.fillText(`FPS: ${Math.round(performance.now() % 60)}`, 10, 30);
|
|
374
|
-
}
|
|
398
|
+
};
|
|
375
399
|
```
|
|
376
400
|
|
|
377
|
-
|
|
378
401
|
<pre>
|
|
379
402
|
| Scenario | Best Approach |
|
|
380
403
|
| ------------------------------ | ---------------------------------- |
|
|
@@ -384,6 +407,7 @@ canvaInlineProgram: (ctx, canvas) => {
|
|
|
384
407
|
</pre>
|
|
385
408
|
|
|
386
409
|
### Note
|
|
410
|
+
|
|
387
411
|
If this happen less then 15 times (Loading procces) then it is ok probably...
|
|
388
412
|
|
|
389
413
|
```json
|
|
@@ -394,11 +418,11 @@ Draw func (err):TypeError: Failed to execute 'beginRenderPass' on 'GPUCommandEnc
|
|
|
394
418
|
|
|
395
419
|
It is possible for 1 or 2 warn in middle time when mesh switch to the videoTexture.
|
|
396
420
|
Will be fixxed in next update.
|
|
421
|
+
|
|
397
422
|
```js
|
|
398
423
|
Dimension (TextureViewDimension::e2DArray) of [TextureView of Texture "shadowTextureArray[GLOBAL] num of light 1"] doesn't match the expected dimension (TextureViewDimension::e2D).
|
|
399
424
|
```
|
|
400
425
|
|
|
401
|
-
|
|
402
426
|
## About URLParams
|
|
403
427
|
|
|
404
428
|
Buildin Url Param check for multiLang.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {OSCILLATOR} from "./utils";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description
|
|
5
|
+
* Can be reuse for any other tasks.
|
|
6
|
+
* @author Nikola Lukic
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export default class Behavior {
|
|
10
|
+
|
|
11
|
+
status = "Only oscillator";
|
|
12
|
+
|
|
13
|
+
constructor() {
|
|
14
|
+
this.osc0 = new OSCILLATOR(0, 5, 0.01);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
setOsc0(min,max, step){
|
|
18
|
+
this.osc0.min =min;
|
|
19
|
+
this.osc0.max =max;
|
|
20
|
+
this.osc0.step =step;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// apend - keep init origin
|
|
24
|
+
addPath(NUMBER) {
|
|
25
|
+
let inc = this.osc0.UPDATE();
|
|
26
|
+
console.log('test inc' ,inc)
|
|
27
|
+
console.log('test inc + number' ,(NUMBER + inc))
|
|
28
|
+
return (inc + NUMBER);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
setPath0() {
|
|
32
|
+
return this.osc0.UPDATE();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
}
|
package/src/engine/lights.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {mat4, vec3} from 'wgpu-matrix';
|
|
2
2
|
import {vertexShadowWGSL} from '../shaders/vertexShadow.wgsl';
|
|
3
|
+
import Behavior from './behavior';
|
|
4
|
+
|
|
3
5
|
/**
|
|
4
6
|
* @description
|
|
5
7
|
* Spot light with shodow cast.
|
|
@@ -209,10 +211,16 @@ export class SpotLight {
|
|
|
209
211
|
});
|
|
210
212
|
return this.mainPassBindGroupContainer[index];
|
|
211
213
|
}
|
|
214
|
+
|
|
215
|
+
// Only osc values +-
|
|
216
|
+
this.behavior = new Behavior();
|
|
217
|
+
|
|
218
|
+
// put here only func
|
|
219
|
+
this.updater = [];
|
|
212
220
|
}
|
|
213
221
|
|
|
214
222
|
update() {
|
|
215
|
-
|
|
223
|
+
this.updater.forEach((update) => {update(this)})
|
|
216
224
|
this.direction = vec3.normalize(vec3.subtract(this.target, this.position));
|
|
217
225
|
const target = vec3.add(this.position, this.direction);
|
|
218
226
|
this.viewMatrix = mat4.lookAt(this.position, target, this.up);
|
package/src/engine/mesh-obj.js
CHANGED
|
@@ -8,7 +8,7 @@ import Materials from './materials';
|
|
|
8
8
|
import {fragmentVideoWGSL} from '../shaders/fragment.video.wgsl';
|
|
9
9
|
|
|
10
10
|
export default class MEMeshObj extends Materials {
|
|
11
|
-
constructor(canvas, device, context, o, inputHandler) {
|
|
11
|
+
constructor(canvas, device, context, o, inputHandler, globalAmbient) {
|
|
12
12
|
super(device);
|
|
13
13
|
if(typeof o.name === 'undefined') o.name = genName(3);
|
|
14
14
|
if(typeof o.raycast === 'undefined') {
|
|
@@ -24,6 +24,7 @@ export default class MEMeshObj extends Materials {
|
|
|
24
24
|
this.clearColor = "red";
|
|
25
25
|
this.video = null;
|
|
26
26
|
this.FINISH_VIDIO_INIT = false;
|
|
27
|
+
this.globalAmbient = globalAmbient;
|
|
27
28
|
|
|
28
29
|
// Mesh stuff - for single mesh or t-posed (fiktive-first in loading order)
|
|
29
30
|
this.mesh = o.mesh;
|
|
@@ -184,7 +185,7 @@ export default class MEMeshObj extends Materials {
|
|
|
184
185
|
|
|
185
186
|
this.sceneUniformBuffer = this.device.createBuffer({
|
|
186
187
|
label: 'sceneUniformBuffer per mesh',
|
|
187
|
-
size:
|
|
188
|
+
size: 176,
|
|
188
189
|
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
|
|
189
190
|
});
|
|
190
191
|
|
|
@@ -222,7 +223,7 @@ export default class MEMeshObj extends Materials {
|
|
|
222
223
|
],
|
|
223
224
|
});
|
|
224
225
|
|
|
225
|
-
|
|
226
|
+
|
|
226
227
|
|
|
227
228
|
// Rotates the camera around the origin based on time.
|
|
228
229
|
this.getTransformationMatrix = (mainRenderBundle, spotLight) => {
|
|
@@ -235,23 +236,31 @@ export default class MEMeshObj extends Materials {
|
|
|
235
236
|
const camVP = mat4.multiply(camera.projectionMatrix, camera.view);
|
|
236
237
|
|
|
237
238
|
for(const mesh of mainRenderBundle) {
|
|
238
|
-
|
|
239
|
-
const sceneData = new Float32Array(16 + 16 + 4 + 4); // 16+16+4+4 = 40 floats
|
|
239
|
+
const sceneData = new Float32Array(44);
|
|
240
240
|
|
|
241
|
-
// Light
|
|
241
|
+
// Light VP
|
|
242
242
|
sceneData.set(spotLight.viewProjMatrix, 0);
|
|
243
243
|
|
|
244
244
|
// Camera VP
|
|
245
245
|
sceneData.set(camVP, 16);
|
|
246
246
|
|
|
247
247
|
// Camera position + padding
|
|
248
|
-
sceneData.set(
|
|
248
|
+
sceneData.set(
|
|
249
|
+
[camera.position.x, camera.position.y, camera.position.z, 0.0],
|
|
250
|
+
32
|
|
251
|
+
);
|
|
249
252
|
|
|
250
253
|
// Light position + padding
|
|
251
|
-
sceneData.set(
|
|
254
|
+
sceneData.set(
|
|
255
|
+
[spotLight.position[0], spotLight.position[1], spotLight.position[2], 0.0],
|
|
256
|
+
36
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
// Global ambient + padding
|
|
260
|
+
sceneData.set([this.globalAmbient[0], this.globalAmbient[1], this.globalAmbient[2], 0.0], 40);
|
|
252
261
|
|
|
253
262
|
device.queue.writeBuffer(
|
|
254
|
-
mesh.sceneUniformBuffer,
|
|
263
|
+
mesh.sceneUniformBuffer,
|
|
255
264
|
0,
|
|
256
265
|
sceneData.buffer,
|
|
257
266
|
sceneData.byteOffset,
|
package/src/engine/utils.js
CHANGED
|
@@ -460,15 +460,7 @@ export function OSCILLATOR(min, max, step) {
|
|
|
460
460
|
}
|
|
461
461
|
};
|
|
462
462
|
} else {
|
|
463
|
-
console.log(
|
|
464
|
-
"SYS : warning for procedure 'SYS.MATH.OSCILLATOR' Desciption : Replace object with string or number, min >> " +
|
|
465
|
-
typeof min +
|
|
466
|
-
' and max >>' +
|
|
467
|
-
typeof max +
|
|
468
|
-
' and step >>' +
|
|
469
|
-
typeof step +
|
|
470
|
-
' << must be string or number.'
|
|
471
|
-
);
|
|
463
|
+
console.log("OSCILLATOR ERROR");
|
|
472
464
|
}
|
|
473
465
|
}
|
|
474
466
|
|
|
@@ -9,6 +9,8 @@ struct Scene {
|
|
|
9
9
|
padding2 : f32, // align to 16 bytes
|
|
10
10
|
lightPos : vec3f,
|
|
11
11
|
padding : f32, // align to 16 bytes
|
|
12
|
+
globalAmbient : vec3f, // <--- new
|
|
13
|
+
padding3 : f32, // keep alignment (16 bytes)
|
|
12
14
|
};
|
|
13
15
|
|
|
14
16
|
struct SpotLight {
|
|
@@ -114,7 +116,7 @@ fn main(input: FragmentInput) -> @location(0) vec4f {
|
|
|
114
116
|
// let viewDir = normalize(scene.cameraViewProjMatrix[3].xyz - input.fragPos);
|
|
115
117
|
|
|
116
118
|
var lightContribution = vec3f(0.0);
|
|
117
|
-
var ambient = vec3f(0.
|
|
119
|
+
var ambient = vec3f(0.5);
|
|
118
120
|
|
|
119
121
|
for (var i: u32 = 0u; i < MAX_SPOTLIGHTS; i = i + 1u) {
|
|
120
122
|
let sc = spotlights[i].lightViewProj * vec4<f32>(input.fragPos, 1.0);
|
|
@@ -128,10 +130,10 @@ fn main(input: FragmentInput) -> @location(0) vec4f {
|
|
|
128
130
|
let visibility = sampleShadow(uv, i32(i), depthRef - bias, norm, lightDir);
|
|
129
131
|
let contrib = computeSpotLight(spotlights[i], norm, input.fragPos, viewDir);
|
|
130
132
|
lightContribution += contrib * visibility;
|
|
131
|
-
ambient += spotlights[i].ambientFactor * spotlights[i].color;
|
|
133
|
+
// ambient += spotlights[i].ambientFactor * spotlights[i].color;
|
|
132
134
|
}
|
|
133
|
-
|
|
135
|
+
// ambient /= f32(MAX_SPOTLIGHTS); PREVENT OVER NEXT FEATURE ON SWICHER
|
|
134
136
|
let texColor = textureSample(meshTexture, meshSampler, input.uv);
|
|
135
|
-
let finalColor = texColor.rgb * (
|
|
137
|
+
let finalColor = texColor.rgb * (scene.globalAmbient + lightContribution); // * albedo;
|
|
136
138
|
return vec4f(finalColor, 1.0);
|
|
137
139
|
}`;
|
package/src/world.js
CHANGED
|
@@ -127,6 +127,7 @@ export default class MatrixEngineWGPU {
|
|
|
127
127
|
this.frame = this.framePassPerObject;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
this.globalAmbient = vec3.create(0.5, 0.5, 0.5);
|
|
130
131
|
this.MAX_SPOTLIGHTS = 20;
|
|
131
132
|
this.inputHandler = createInputHandler(window, canvas);
|
|
132
133
|
this.createGlobalStuff();
|
|
@@ -379,7 +380,7 @@ export default class MatrixEngineWGPU {
|
|
|
379
380
|
}
|
|
380
381
|
}
|
|
381
382
|
}
|
|
382
|
-
let myMesh1 = new MEMeshObj(this.canvas, this.device, this.context, o, this.inputHandler);
|
|
383
|
+
let myMesh1 = new MEMeshObj(this.canvas, this.device, this.context, o, this.inputHandler, this.globalAmbient);
|
|
383
384
|
myMesh1.spotlightUniformBuffer = this.spotlightUniformBuffer;
|
|
384
385
|
myMesh1.clearColor = clearColor;
|
|
385
386
|
if(o.physics.enabled == true) {
|
|
@@ -447,20 +448,16 @@ export default class MatrixEngineWGPU {
|
|
|
447
448
|
// 1️⃣ Update light data (position, direction, uniforms)
|
|
448
449
|
for(const light of this.lightContainer) {
|
|
449
450
|
light.update()
|
|
450
|
-
// light.updateSceneUniforms(this.mainRenderBundle, this.cameras.WASD);
|
|
451
451
|
this.mainRenderBundle.forEach((meItem, index) => {
|
|
452
452
|
meItem.position.update()
|
|
453
453
|
meItem.updateModelUniformBuffer()
|
|
454
|
-
// if(meItem.isVideo != true) {
|
|
455
454
|
meItem.getTransformationMatrix(this.mainRenderBundle, light)
|
|
456
|
-
// }
|
|
457
455
|
})
|
|
458
456
|
}
|
|
459
457
|
if(this.matrixAmmo) this.matrixAmmo.updatePhysics();
|
|
460
458
|
|
|
461
459
|
for(let i = 0;i < this.lightContainer.length;i++) {
|
|
462
460
|
const light = this.lightContainer[i];
|
|
463
|
-
|
|
464
461
|
let ViewPerLightRenderShadowPass = this.shadowTextureArray.createView({
|
|
465
462
|
dimension: '2d',
|
|
466
463
|
baseArrayLayer: i,
|