@luma.gl/gltf 9.1.0-alpha.1 → 9.1.0-alpha.12
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/dist.dev.js +303 -648
- package/dist/dist.min.js +48 -361
- package/dist/gltf/create-gltf-model.d.ts.map +1 -1
- package/dist/gltf/create-gltf-model.js +47 -34
- package/dist/index.cjs +54 -35
- package/dist/index.cjs.map +2 -2
- package/package.json +7 -6
- package/src/gltf/create-gltf-model.ts +3 -3
package/dist/dist.dev.js
CHANGED
|
@@ -51,6 +51,13 @@ var __exports__ = (() => {
|
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
+
// external-global-plugin:@luma.gl/shadertools
|
|
55
|
+
var require_shadertools = __commonJS({
|
|
56
|
+
"external-global-plugin:@luma.gl/shadertools"(exports, module) {
|
|
57
|
+
module.exports = globalThis.luma;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
54
61
|
// bundle.ts
|
|
55
62
|
var bundle_exports = {};
|
|
56
63
|
__export(bundle_exports, {
|
|
@@ -264,7 +271,7 @@ var __exports__ = (() => {
|
|
|
264
271
|
}
|
|
265
272
|
|
|
266
273
|
// ../../node_modules/@loaders.gl/images/dist/lib/utils/version.js
|
|
267
|
-
var VERSION = true ? "4.2.
|
|
274
|
+
var VERSION = true ? "4.2.1" : "latest";
|
|
268
275
|
|
|
269
276
|
// ../../node_modules/@loaders.gl/images/dist/lib/category-api/image-type.js
|
|
270
277
|
var parseImageNode = globalThis.loaders?.parseImageNode;
|
|
@@ -837,17 +844,11 @@ var __exports__ = (() => {
|
|
|
837
844
|
printRowMajor: true,
|
|
838
845
|
_cartographicRadians: false
|
|
839
846
|
};
|
|
840
|
-
globalThis.mathgl = globalThis.mathgl || {
|
|
841
|
-
config: {
|
|
842
|
-
...DEFAULT_CONFIG
|
|
843
|
-
}
|
|
844
|
-
};
|
|
847
|
+
globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
|
|
845
848
|
var config = globalThis.mathgl.config;
|
|
846
|
-
function formatValue(value, {
|
|
847
|
-
precision = config.precision
|
|
848
|
-
} = {}) {
|
|
849
|
+
function formatValue(value, { precision = config.precision } = {}) {
|
|
849
850
|
value = round(value);
|
|
850
|
-
return
|
|
851
|
+
return `${parseFloat(value.toPrecision(precision))}`;
|
|
851
852
|
}
|
|
852
853
|
function isArray(value) {
|
|
853
854
|
return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
|
|
@@ -891,28 +892,12 @@ var __exports__ = (() => {
|
|
|
891
892
|
}
|
|
892
893
|
|
|
893
894
|
// ../../node_modules/@math.gl/core/dist/classes/base/math-array.js
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
ExtendableBuiltin.prototype = Object.create(cls.prototype, {
|
|
901
|
-
constructor: {
|
|
902
|
-
value: cls,
|
|
903
|
-
enumerable: false,
|
|
904
|
-
writable: true,
|
|
905
|
-
configurable: true
|
|
906
|
-
}
|
|
907
|
-
});
|
|
908
|
-
if (Object.setPrototypeOf) {
|
|
909
|
-
Object.setPrototypeOf(ExtendableBuiltin, cls);
|
|
910
|
-
} else {
|
|
911
|
-
ExtendableBuiltin.__proto__ = cls;
|
|
912
|
-
}
|
|
913
|
-
return ExtendableBuiltin;
|
|
914
|
-
}
|
|
915
|
-
var MathArray = class extends _extendableBuiltin(Array) {
|
|
895
|
+
var MathArray = class extends Array {
|
|
896
|
+
// Common methods
|
|
897
|
+
/**
|
|
898
|
+
* Clone the current object
|
|
899
|
+
* @returns a new copy of this object
|
|
900
|
+
*/
|
|
916
901
|
clone() {
|
|
917
902
|
return new this.constructor().copy(this);
|
|
918
903
|
}
|
|
@@ -932,7 +917,10 @@ var __exports__ = (() => {
|
|
|
932
917
|
return targetObject;
|
|
933
918
|
}
|
|
934
919
|
from(arrayOrObject) {
|
|
935
|
-
return Array.isArray(arrayOrObject) ? this.copy(arrayOrObject) :
|
|
920
|
+
return Array.isArray(arrayOrObject) ? this.copy(arrayOrObject) : (
|
|
921
|
+
// @ts-ignore
|
|
922
|
+
this.fromObject(arrayOrObject)
|
|
923
|
+
);
|
|
936
924
|
}
|
|
937
925
|
to(arrayOrObject) {
|
|
938
926
|
if (arrayOrObject === this) {
|
|
@@ -943,18 +931,20 @@ var __exports__ = (() => {
|
|
|
943
931
|
toTarget(target) {
|
|
944
932
|
return target ? this.to(target) : this;
|
|
945
933
|
}
|
|
934
|
+
/** @deprecated */
|
|
946
935
|
toFloat32Array() {
|
|
947
936
|
return new Float32Array(this);
|
|
948
937
|
}
|
|
949
938
|
toString() {
|
|
950
939
|
return this.formatString(config);
|
|
951
940
|
}
|
|
941
|
+
/** Formats string according to options */
|
|
952
942
|
formatString(opts) {
|
|
953
943
|
let string = "";
|
|
954
944
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
955
945
|
string += (i > 0 ? ", " : "") + formatValue(this[i], opts);
|
|
956
946
|
}
|
|
957
|
-
return
|
|
947
|
+
return `${opts.printTypes ? this.constructor.name : ""}[${string}]`;
|
|
958
948
|
}
|
|
959
949
|
equals(array) {
|
|
960
950
|
if (!array || this.length !== array.length) {
|
|
@@ -978,6 +968,8 @@ var __exports__ = (() => {
|
|
|
978
968
|
}
|
|
979
969
|
return true;
|
|
980
970
|
}
|
|
971
|
+
// Modifiers
|
|
972
|
+
/** Negates all values in this object */
|
|
981
973
|
negate() {
|
|
982
974
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
983
975
|
this[i] = -this[i];
|
|
@@ -995,12 +987,14 @@ var __exports__ = (() => {
|
|
|
995
987
|
}
|
|
996
988
|
return this.check();
|
|
997
989
|
}
|
|
990
|
+
/** Minimal */
|
|
998
991
|
min(vector) {
|
|
999
992
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
1000
993
|
this[i] = Math.min(vector[i], this[i]);
|
|
1001
994
|
}
|
|
1002
995
|
return this.check();
|
|
1003
996
|
}
|
|
997
|
+
/** Maximal */
|
|
1004
998
|
max(vector) {
|
|
1005
999
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
1006
1000
|
this[i] = Math.max(vector[i], this[i]);
|
|
@@ -1041,18 +1035,25 @@ var __exports__ = (() => {
|
|
|
1041
1035
|
}
|
|
1042
1036
|
return this.check();
|
|
1043
1037
|
}
|
|
1038
|
+
/**
|
|
1039
|
+
* Multiplies all elements by `scale`
|
|
1040
|
+
* Note: `Matrix4.multiplyByScalar` only scales its 3x3 "minor"
|
|
1041
|
+
*/
|
|
1044
1042
|
multiplyByScalar(scalar) {
|
|
1045
1043
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
1046
1044
|
this[i] *= scalar;
|
|
1047
1045
|
}
|
|
1048
1046
|
return this.check();
|
|
1049
1047
|
}
|
|
1048
|
+
// Debug checks
|
|
1049
|
+
/** Throws an error if array length is incorrect or contains illegal values */
|
|
1050
1050
|
check() {
|
|
1051
1051
|
if (config.debug && !this.validate()) {
|
|
1052
|
-
throw new Error(
|
|
1052
|
+
throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);
|
|
1053
1053
|
}
|
|
1054
1054
|
return this;
|
|
1055
1055
|
}
|
|
1056
|
+
/** Returns false if the array length is incorrect or contains illegal values */
|
|
1056
1057
|
validate() {
|
|
1057
1058
|
let valid = this.length === this.ELEMENTS;
|
|
1058
1059
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
@@ -1060,39 +1061,48 @@ var __exports__ = (() => {
|
|
|
1060
1061
|
}
|
|
1061
1062
|
return valid;
|
|
1062
1063
|
}
|
|
1064
|
+
// three.js compatibility
|
|
1065
|
+
/** @deprecated */
|
|
1063
1066
|
sub(a) {
|
|
1064
1067
|
return this.subtract(a);
|
|
1065
1068
|
}
|
|
1069
|
+
/** @deprecated */
|
|
1066
1070
|
setScalar(a) {
|
|
1067
1071
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
1068
1072
|
this[i] = a;
|
|
1069
1073
|
}
|
|
1070
1074
|
return this.check();
|
|
1071
1075
|
}
|
|
1076
|
+
/** @deprecated */
|
|
1072
1077
|
addScalar(a) {
|
|
1073
1078
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
1074
1079
|
this[i] += a;
|
|
1075
1080
|
}
|
|
1076
1081
|
return this.check();
|
|
1077
1082
|
}
|
|
1083
|
+
/** @deprecated */
|
|
1078
1084
|
subScalar(a) {
|
|
1079
1085
|
return this.addScalar(-a);
|
|
1080
1086
|
}
|
|
1087
|
+
/** @deprecated */
|
|
1081
1088
|
multiplyScalar(scalar) {
|
|
1082
1089
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
1083
1090
|
this[i] *= scalar;
|
|
1084
1091
|
}
|
|
1085
1092
|
return this.check();
|
|
1086
1093
|
}
|
|
1094
|
+
/** @deprecated */
|
|
1087
1095
|
divideScalar(a) {
|
|
1088
1096
|
return this.multiplyByScalar(1 / a);
|
|
1089
1097
|
}
|
|
1098
|
+
/** @deprecated */
|
|
1090
1099
|
clampScalar(min, max) {
|
|
1091
1100
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
1092
1101
|
this[i] = Math.min(Math.max(this[i], min), max);
|
|
1093
1102
|
}
|
|
1094
1103
|
return this.check();
|
|
1095
1104
|
}
|
|
1105
|
+
/** @deprecated */
|
|
1096
1106
|
get elements() {
|
|
1097
1107
|
return this;
|
|
1098
1108
|
}
|
|
@@ -1112,13 +1122,13 @@ var __exports__ = (() => {
|
|
|
1112
1122
|
}
|
|
1113
1123
|
function checkNumber(value) {
|
|
1114
1124
|
if (!Number.isFinite(value)) {
|
|
1115
|
-
throw new Error(
|
|
1125
|
+
throw new Error(`Invalid number ${JSON.stringify(value)}`);
|
|
1116
1126
|
}
|
|
1117
1127
|
return value;
|
|
1118
1128
|
}
|
|
1119
1129
|
function checkVector(v, length4, callerName = "") {
|
|
1120
1130
|
if (config.debug && !validateVector(v, length4)) {
|
|
1121
|
-
throw new Error(
|
|
1131
|
+
throw new Error(`math.gl: ${callerName} some fields set to invalid numbers'`);
|
|
1122
1132
|
}
|
|
1123
1133
|
return v;
|
|
1124
1134
|
}
|
|
@@ -1126,12 +1136,13 @@ var __exports__ = (() => {
|
|
|
1126
1136
|
// ../../node_modules/@math.gl/core/dist/lib/assert.js
|
|
1127
1137
|
function assert2(condition, message) {
|
|
1128
1138
|
if (!condition) {
|
|
1129
|
-
throw new Error(
|
|
1139
|
+
throw new Error(`math.gl assertion ${message}`);
|
|
1130
1140
|
}
|
|
1131
1141
|
}
|
|
1132
1142
|
|
|
1133
1143
|
// ../../node_modules/@math.gl/core/dist/classes/base/vector.js
|
|
1134
1144
|
var Vector = class extends MathArray {
|
|
1145
|
+
// ACCESSORS
|
|
1135
1146
|
get x() {
|
|
1136
1147
|
return this[0];
|
|
1137
1148
|
}
|
|
@@ -1144,12 +1155,24 @@ var __exports__ = (() => {
|
|
|
1144
1155
|
set y(value) {
|
|
1145
1156
|
this[1] = checkNumber(value);
|
|
1146
1157
|
}
|
|
1158
|
+
/**
|
|
1159
|
+
* Returns the length of the vector from the origin to the point described by this vector
|
|
1160
|
+
*
|
|
1161
|
+
* @note `length` is a reserved word for Arrays, so `v.length()` will return number of elements
|
|
1162
|
+
* Instead we provide `len` and `magnitude`
|
|
1163
|
+
*/
|
|
1147
1164
|
len() {
|
|
1148
1165
|
return Math.sqrt(this.lengthSquared());
|
|
1149
1166
|
}
|
|
1167
|
+
/**
|
|
1168
|
+
* Returns the length of the vector from the origin to the point described by this vector
|
|
1169
|
+
*/
|
|
1150
1170
|
magnitude() {
|
|
1151
1171
|
return this.len();
|
|
1152
1172
|
}
|
|
1173
|
+
/**
|
|
1174
|
+
* Returns the squared length of the vector from the origin to the point described by this vector
|
|
1175
|
+
*/
|
|
1153
1176
|
lengthSquared() {
|
|
1154
1177
|
let length4 = 0;
|
|
1155
1178
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
@@ -1157,6 +1180,9 @@ var __exports__ = (() => {
|
|
|
1157
1180
|
}
|
|
1158
1181
|
return length4;
|
|
1159
1182
|
}
|
|
1183
|
+
/**
|
|
1184
|
+
* Returns the squared length of the vector from the origin to the point described by this vector
|
|
1185
|
+
*/
|
|
1160
1186
|
magnitudeSquared() {
|
|
1161
1187
|
return this.lengthSquared();
|
|
1162
1188
|
}
|
|
@@ -1178,6 +1204,7 @@ var __exports__ = (() => {
|
|
|
1178
1204
|
}
|
|
1179
1205
|
return checkNumber(product);
|
|
1180
1206
|
}
|
|
1207
|
+
// MODIFIERS
|
|
1181
1208
|
normalize() {
|
|
1182
1209
|
const length4 = this.magnitude();
|
|
1183
1210
|
if (length4 !== 0) {
|
|
@@ -1203,6 +1230,7 @@ var __exports__ = (() => {
|
|
|
1203
1230
|
}
|
|
1204
1231
|
return this.check();
|
|
1205
1232
|
}
|
|
1233
|
+
// THREE.js compatibility
|
|
1206
1234
|
lengthSq() {
|
|
1207
1235
|
return this.lengthSquared();
|
|
1208
1236
|
}
|
|
@@ -1501,6 +1529,8 @@ var __exports__ = (() => {
|
|
|
1501
1529
|
object.w = this[3];
|
|
1502
1530
|
return object;
|
|
1503
1531
|
}
|
|
1532
|
+
// Getters/setters
|
|
1533
|
+
/* eslint-disable no-multi-spaces, brace-style, no-return-assign */
|
|
1504
1534
|
get ELEMENTS() {
|
|
1505
1535
|
return 4;
|
|
1506
1536
|
}
|
|
@@ -1532,6 +1562,7 @@ var __exports__ = (() => {
|
|
|
1532
1562
|
transformQuat(this, this, quaternion2);
|
|
1533
1563
|
return this.check();
|
|
1534
1564
|
}
|
|
1565
|
+
// three.js compatibility
|
|
1535
1566
|
applyMatrix4(m) {
|
|
1536
1567
|
m.transform(this, this);
|
|
1537
1568
|
return this;
|
|
@@ -1540,19 +1571,29 @@ var __exports__ = (() => {
|
|
|
1540
1571
|
|
|
1541
1572
|
// ../../node_modules/@math.gl/core/dist/classes/base/matrix.js
|
|
1542
1573
|
var Matrix = class extends MathArray {
|
|
1574
|
+
// fromObject(object) {
|
|
1575
|
+
// const array = object.elements;
|
|
1576
|
+
// return this.fromRowMajor(array);
|
|
1577
|
+
// }
|
|
1578
|
+
// toObject(object) {
|
|
1579
|
+
// const array = object.elements;
|
|
1580
|
+
// this.toRowMajor(array);
|
|
1581
|
+
// return object;
|
|
1582
|
+
// }
|
|
1583
|
+
// TODO better override formatString?
|
|
1543
1584
|
toString() {
|
|
1544
1585
|
let string = "[";
|
|
1545
1586
|
if (config.printRowMajor) {
|
|
1546
1587
|
string += "row-major:";
|
|
1547
1588
|
for (let row = 0; row < this.RANK; ++row) {
|
|
1548
1589
|
for (let col = 0; col < this.RANK; ++col) {
|
|
1549
|
-
string +=
|
|
1590
|
+
string += ` ${this[col * this.RANK + row]}`;
|
|
1550
1591
|
}
|
|
1551
1592
|
}
|
|
1552
1593
|
} else {
|
|
1553
1594
|
string += "column-major:";
|
|
1554
1595
|
for (let i = 0; i < this.ELEMENTS; ++i) {
|
|
1555
|
-
string +=
|
|
1596
|
+
string += ` ${this[i]}`;
|
|
1556
1597
|
}
|
|
1557
1598
|
}
|
|
1558
1599
|
string += "]";
|
|
@@ -1561,9 +1602,11 @@ var __exports__ = (() => {
|
|
|
1561
1602
|
getElementIndex(row, col) {
|
|
1562
1603
|
return col * this.RANK + row;
|
|
1563
1604
|
}
|
|
1605
|
+
// By default assumes row major indices
|
|
1564
1606
|
getElement(row, col) {
|
|
1565
1607
|
return this[col * this.RANK + row];
|
|
1566
1608
|
}
|
|
1609
|
+
// By default assumes row major indices
|
|
1567
1610
|
setElement(row, col, value) {
|
|
1568
1611
|
this[col * this.RANK + row] = checkNumber(value);
|
|
1569
1612
|
return this;
|
|
@@ -2421,6 +2464,7 @@ var __exports__ = (() => {
|
|
|
2421
2464
|
this[15] = array[15];
|
|
2422
2465
|
return this.check();
|
|
2423
2466
|
}
|
|
2467
|
+
// eslint-disable-next-line max-params
|
|
2424
2468
|
set(m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33) {
|
|
2425
2469
|
this[0] = m00;
|
|
2426
2470
|
this[1] = m10;
|
|
@@ -2440,6 +2484,8 @@ var __exports__ = (() => {
|
|
|
2440
2484
|
this[15] = m33;
|
|
2441
2485
|
return this.check();
|
|
2442
2486
|
}
|
|
2487
|
+
// accepts row major order, stores as column major
|
|
2488
|
+
// eslint-disable-next-line max-params
|
|
2443
2489
|
setRowMajor(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
|
|
2444
2490
|
this[0] = m00;
|
|
2445
2491
|
this[1] = m10;
|
|
@@ -2478,25 +2524,41 @@ var __exports__ = (() => {
|
|
|
2478
2524
|
result[15] = this[15];
|
|
2479
2525
|
return result;
|
|
2480
2526
|
}
|
|
2527
|
+
// Constructors
|
|
2528
|
+
/** Set to identity matrix */
|
|
2481
2529
|
identity() {
|
|
2482
2530
|
return this.copy(IDENTITY_MATRIX);
|
|
2483
2531
|
}
|
|
2532
|
+
/**
|
|
2533
|
+
*
|
|
2534
|
+
* @param object
|
|
2535
|
+
* @returns self
|
|
2536
|
+
*/
|
|
2537
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2484
2538
|
fromObject(object) {
|
|
2485
2539
|
return this.check();
|
|
2486
2540
|
}
|
|
2541
|
+
/**
|
|
2542
|
+
* Calculates a 4x4 matrix from the given quaternion
|
|
2543
|
+
* @param quaternion Quaternion to create matrix from
|
|
2544
|
+
* @returns self
|
|
2545
|
+
*/
|
|
2487
2546
|
fromQuaternion(quaternion2) {
|
|
2488
2547
|
fromQuat(this, quaternion2);
|
|
2489
2548
|
return this.check();
|
|
2490
2549
|
}
|
|
2550
|
+
/**
|
|
2551
|
+
* Generates a frustum matrix with the given bounds
|
|
2552
|
+
* @param view.left - Left bound of the frustum
|
|
2553
|
+
* @param view.right - Right bound of the frustum
|
|
2554
|
+
* @param view.bottom - Bottom bound of the frustum
|
|
2555
|
+
* @param view.top - Top bound of the frustum
|
|
2556
|
+
* @param view.near - Near bound of the frustum
|
|
2557
|
+
* @param view.far - Far bound of the frustum. Can be set to Infinity.
|
|
2558
|
+
* @returns self
|
|
2559
|
+
*/
|
|
2491
2560
|
frustum(view) {
|
|
2492
|
-
const {
|
|
2493
|
-
left,
|
|
2494
|
-
right,
|
|
2495
|
-
bottom,
|
|
2496
|
-
top,
|
|
2497
|
-
near = DEFAULT_NEAR,
|
|
2498
|
-
far = DEFAULT_FAR
|
|
2499
|
-
} = view;
|
|
2561
|
+
const { left, right, bottom, top, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
|
|
2500
2562
|
if (far === Infinity) {
|
|
2501
2563
|
computeInfinitePerspectiveOffCenter(this, left, right, bottom, top, near);
|
|
2502
2564
|
} else {
|
|
@@ -2504,35 +2566,47 @@ var __exports__ = (() => {
|
|
|
2504
2566
|
}
|
|
2505
2567
|
return this.check();
|
|
2506
2568
|
}
|
|
2569
|
+
/**
|
|
2570
|
+
* Generates a look-at matrix with the given eye position, focal point,
|
|
2571
|
+
* and up axis
|
|
2572
|
+
* @param view.eye - (vector) Position of the viewer
|
|
2573
|
+
* @param view.center - (vector) Point the viewer is looking at
|
|
2574
|
+
* @param view.up - (vector) Up axis
|
|
2575
|
+
* @returns self
|
|
2576
|
+
*/
|
|
2507
2577
|
lookAt(view) {
|
|
2508
|
-
const {
|
|
2509
|
-
eye,
|
|
2510
|
-
center = [0, 0, 0],
|
|
2511
|
-
up = [0, 1, 0]
|
|
2512
|
-
} = view;
|
|
2578
|
+
const { eye, center = [0, 0, 0], up = [0, 1, 0] } = view;
|
|
2513
2579
|
lookAt(this, eye, center, up);
|
|
2514
2580
|
return this.check();
|
|
2515
2581
|
}
|
|
2582
|
+
/**
|
|
2583
|
+
* Generates a orthogonal projection matrix with the given bounds
|
|
2584
|
+
* from "traditional" view space parameters
|
|
2585
|
+
* @param view.left - Left bound of the frustum
|
|
2586
|
+
* @param view.right number Right bound of the frustum
|
|
2587
|
+
* @param view.bottom - Bottom bound of the frustum
|
|
2588
|
+
* @param view.top number Top bound of the frustum
|
|
2589
|
+
* @param view.near - Near bound of the frustum
|
|
2590
|
+
* @param view.far number Far bound of the frustum
|
|
2591
|
+
* @returns self
|
|
2592
|
+
*/
|
|
2516
2593
|
ortho(view) {
|
|
2517
|
-
const {
|
|
2518
|
-
left,
|
|
2519
|
-
right,
|
|
2520
|
-
bottom,
|
|
2521
|
-
top,
|
|
2522
|
-
near = DEFAULT_NEAR,
|
|
2523
|
-
far = DEFAULT_FAR
|
|
2524
|
-
} = view;
|
|
2594
|
+
const { left, right, bottom, top, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
|
|
2525
2595
|
ortho(this, left, right, bottom, top, near, far);
|
|
2526
2596
|
return this.check();
|
|
2527
2597
|
}
|
|
2598
|
+
/**
|
|
2599
|
+
* Generates an orthogonal projection matrix with the same parameters
|
|
2600
|
+
* as a perspective matrix (plus focalDistance)
|
|
2601
|
+
* @param view.fovy Vertical field of view in radians
|
|
2602
|
+
* @param view.aspect Aspect ratio. Typically viewport width / viewport height
|
|
2603
|
+
* @param view.focalDistance Distance in the view frustum used for extent calculations
|
|
2604
|
+
* @param view.near Near bound of the frustum
|
|
2605
|
+
* @param view.far Far bound of the frustum
|
|
2606
|
+
* @returns self
|
|
2607
|
+
*/
|
|
2528
2608
|
orthographic(view) {
|
|
2529
|
-
const {
|
|
2530
|
-
fovy = DEFAULT_FOVY,
|
|
2531
|
-
aspect = DEFAULT_ASPECT,
|
|
2532
|
-
focalDistance = 1,
|
|
2533
|
-
near = DEFAULT_NEAR,
|
|
2534
|
-
far = DEFAULT_FAR
|
|
2535
|
-
} = view;
|
|
2609
|
+
const { fovy = DEFAULT_FOVY, aspect = DEFAULT_ASPECT, focalDistance = 1, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
|
|
2536
2610
|
checkRadians(fovy);
|
|
2537
2611
|
const halfY = fovy / 2;
|
|
2538
2612
|
const top = focalDistance * Math.tan(halfY);
|
|
@@ -2546,32 +2620,53 @@ var __exports__ = (() => {
|
|
|
2546
2620
|
far
|
|
2547
2621
|
});
|
|
2548
2622
|
}
|
|
2623
|
+
/**
|
|
2624
|
+
* Generates a perspective projection matrix with the given bounds
|
|
2625
|
+
* @param view.fovy Vertical field of view in radians
|
|
2626
|
+
* @param view.aspect Aspect ratio. typically viewport width/height
|
|
2627
|
+
* @param view.near Near bound of the frustum
|
|
2628
|
+
* @param view.far Far bound of the frustum
|
|
2629
|
+
* @returns self
|
|
2630
|
+
*/
|
|
2549
2631
|
perspective(view) {
|
|
2550
|
-
const {
|
|
2551
|
-
fovy = 45 * Math.PI / 180,
|
|
2552
|
-
aspect = 1,
|
|
2553
|
-
near = 0.1,
|
|
2554
|
-
far = 500
|
|
2555
|
-
} = view;
|
|
2632
|
+
const { fovy = 45 * Math.PI / 180, aspect = 1, near = 0.1, far = 500 } = view;
|
|
2556
2633
|
checkRadians(fovy);
|
|
2557
2634
|
perspective(this, fovy, aspect, near, far);
|
|
2558
2635
|
return this.check();
|
|
2559
2636
|
}
|
|
2637
|
+
// Accessors
|
|
2560
2638
|
determinant() {
|
|
2561
2639
|
return determinant(this);
|
|
2562
2640
|
}
|
|
2641
|
+
/**
|
|
2642
|
+
* Extracts the non-uniform scale assuming the matrix is an affine transformation.
|
|
2643
|
+
* The scales are the "lengths" of the column vectors in the upper-left 3x3 matrix.
|
|
2644
|
+
* @param result
|
|
2645
|
+
* @returns self
|
|
2646
|
+
*/
|
|
2563
2647
|
getScale(result = [-0, -0, -0]) {
|
|
2564
2648
|
result[0] = Math.sqrt(this[0] * this[0] + this[1] * this[1] + this[2] * this[2]);
|
|
2565
2649
|
result[1] = Math.sqrt(this[4] * this[4] + this[5] * this[5] + this[6] * this[6]);
|
|
2566
2650
|
result[2] = Math.sqrt(this[8] * this[8] + this[9] * this[9] + this[10] * this[10]);
|
|
2567
2651
|
return result;
|
|
2568
2652
|
}
|
|
2653
|
+
/**
|
|
2654
|
+
* Gets the translation portion, assuming the matrix is a affine transformation matrix.
|
|
2655
|
+
* @param result
|
|
2656
|
+
* @returns self
|
|
2657
|
+
*/
|
|
2569
2658
|
getTranslation(result = [-0, -0, -0]) {
|
|
2570
2659
|
result[0] = this[12];
|
|
2571
2660
|
result[1] = this[13];
|
|
2572
2661
|
result[2] = this[14];
|
|
2573
2662
|
return result;
|
|
2574
2663
|
}
|
|
2664
|
+
/**
|
|
2665
|
+
* Gets upper left 3x3 pure rotation matrix (non-scaling), assume affine transformation matrix
|
|
2666
|
+
* @param result
|
|
2667
|
+
* @param scaleResult
|
|
2668
|
+
* @returns self
|
|
2669
|
+
*/
|
|
2575
2670
|
getRotation(result, scaleResult) {
|
|
2576
2671
|
result = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
|
|
2577
2672
|
scaleResult = scaleResult || [-0, -0, -0];
|
|
@@ -2597,6 +2692,12 @@ var __exports__ = (() => {
|
|
|
2597
2692
|
result[15] = 1;
|
|
2598
2693
|
return result;
|
|
2599
2694
|
}
|
|
2695
|
+
/**
|
|
2696
|
+
*
|
|
2697
|
+
* @param result
|
|
2698
|
+
* @param scaleResult
|
|
2699
|
+
* @returns self
|
|
2700
|
+
*/
|
|
2600
2701
|
getRotationMatrix3(result, scaleResult) {
|
|
2601
2702
|
result = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0];
|
|
2602
2703
|
scaleResult = scaleResult || [-0, -0, -0];
|
|
@@ -2615,6 +2716,7 @@ var __exports__ = (() => {
|
|
|
2615
2716
|
result[8] = this[10] * inverseScale2;
|
|
2616
2717
|
return result;
|
|
2617
2718
|
}
|
|
2719
|
+
// Modifiers
|
|
2618
2720
|
transpose() {
|
|
2619
2721
|
transpose(this, this);
|
|
2620
2722
|
return this.check();
|
|
@@ -2623,6 +2725,7 @@ var __exports__ = (() => {
|
|
|
2623
2725
|
invert(this, this);
|
|
2624
2726
|
return this.check();
|
|
2625
2727
|
}
|
|
2728
|
+
// Operations
|
|
2626
2729
|
multiplyLeft(a) {
|
|
2627
2730
|
multiply(this, a, this);
|
|
2628
2731
|
return this.check();
|
|
@@ -2631,33 +2734,68 @@ var __exports__ = (() => {
|
|
|
2631
2734
|
multiply(this, this, a);
|
|
2632
2735
|
return this.check();
|
|
2633
2736
|
}
|
|
2737
|
+
// Rotates a matrix by the given angle around the X axis
|
|
2634
2738
|
rotateX(radians) {
|
|
2635
2739
|
rotateX(this, this, radians);
|
|
2636
2740
|
return this.check();
|
|
2637
2741
|
}
|
|
2742
|
+
// Rotates a matrix by the given angle around the Y axis.
|
|
2638
2743
|
rotateY(radians) {
|
|
2639
2744
|
rotateY(this, this, radians);
|
|
2640
2745
|
return this.check();
|
|
2641
2746
|
}
|
|
2747
|
+
/**
|
|
2748
|
+
* Rotates a matrix by the given angle around the Z axis.
|
|
2749
|
+
* @param radians
|
|
2750
|
+
* @returns self
|
|
2751
|
+
*/
|
|
2642
2752
|
rotateZ(radians) {
|
|
2643
2753
|
rotateZ(this, this, radians);
|
|
2644
2754
|
return this.check();
|
|
2645
2755
|
}
|
|
2756
|
+
/**
|
|
2757
|
+
*
|
|
2758
|
+
* @param param0
|
|
2759
|
+
* @returns self
|
|
2760
|
+
*/
|
|
2646
2761
|
rotateXYZ(angleXYZ) {
|
|
2647
2762
|
return this.rotateX(angleXYZ[0]).rotateY(angleXYZ[1]).rotateZ(angleXYZ[2]);
|
|
2648
2763
|
}
|
|
2764
|
+
/**
|
|
2765
|
+
*
|
|
2766
|
+
* @param radians
|
|
2767
|
+
* @param axis
|
|
2768
|
+
* @returns self
|
|
2769
|
+
*/
|
|
2649
2770
|
rotateAxis(radians, axis) {
|
|
2650
2771
|
rotate(this, this, radians, axis);
|
|
2651
2772
|
return this.check();
|
|
2652
2773
|
}
|
|
2774
|
+
/**
|
|
2775
|
+
*
|
|
2776
|
+
* @param factor
|
|
2777
|
+
* @returns self
|
|
2778
|
+
*/
|
|
2653
2779
|
scale(factor) {
|
|
2654
2780
|
scale(this, this, Array.isArray(factor) ? factor : [factor, factor, factor]);
|
|
2655
2781
|
return this.check();
|
|
2656
2782
|
}
|
|
2783
|
+
/**
|
|
2784
|
+
*
|
|
2785
|
+
* @param vec
|
|
2786
|
+
* @returns self
|
|
2787
|
+
*/
|
|
2657
2788
|
translate(vector) {
|
|
2658
2789
|
translate(this, this, vector);
|
|
2659
2790
|
return this.check();
|
|
2660
2791
|
}
|
|
2792
|
+
// Transforms
|
|
2793
|
+
/**
|
|
2794
|
+
* Transforms any 2, 3 or 4 element vector. 2 and 3 elements are treated as points
|
|
2795
|
+
* @param vector
|
|
2796
|
+
* @param result
|
|
2797
|
+
* @returns self
|
|
2798
|
+
*/
|
|
2661
2799
|
transform(vector, result) {
|
|
2662
2800
|
if (vector.length === 4) {
|
|
2663
2801
|
result = transformMat43(result || [-0, -0, -0, -0], vector, this);
|
|
@@ -2666,10 +2804,14 @@ var __exports__ = (() => {
|
|
|
2666
2804
|
}
|
|
2667
2805
|
return this.transformAsPoint(vector, result);
|
|
2668
2806
|
}
|
|
2807
|
+
/**
|
|
2808
|
+
* Transforms any 2 or 3 element array as point (w implicitly 1)
|
|
2809
|
+
* @param vector
|
|
2810
|
+
* @param result
|
|
2811
|
+
* @returns self
|
|
2812
|
+
*/
|
|
2669
2813
|
transformAsPoint(vector, result) {
|
|
2670
|
-
const {
|
|
2671
|
-
length: length4
|
|
2672
|
-
} = vector;
|
|
2814
|
+
const { length: length4 } = vector;
|
|
2673
2815
|
let out;
|
|
2674
2816
|
switch (length4) {
|
|
2675
2817
|
case 2:
|
|
@@ -2684,6 +2826,12 @@ var __exports__ = (() => {
|
|
|
2684
2826
|
checkVector(out, vector.length);
|
|
2685
2827
|
return out;
|
|
2686
2828
|
}
|
|
2829
|
+
/**
|
|
2830
|
+
* Transforms any 2 or 3 element array as vector (w implicitly 0)
|
|
2831
|
+
* @param vector
|
|
2832
|
+
* @param result
|
|
2833
|
+
* @returns self
|
|
2834
|
+
*/
|
|
2687
2835
|
transformAsVector(vector, result) {
|
|
2688
2836
|
let out;
|
|
2689
2837
|
switch (vector.length) {
|
|
@@ -2699,15 +2847,19 @@ var __exports__ = (() => {
|
|
|
2699
2847
|
checkVector(out, vector.length);
|
|
2700
2848
|
return out;
|
|
2701
2849
|
}
|
|
2850
|
+
/** @deprecated */
|
|
2702
2851
|
transformPoint(vector, result) {
|
|
2703
2852
|
return this.transformAsPoint(vector, result);
|
|
2704
2853
|
}
|
|
2854
|
+
/** @deprecated */
|
|
2705
2855
|
transformVector(vector, result) {
|
|
2706
2856
|
return this.transformAsPoint(vector, result);
|
|
2707
2857
|
}
|
|
2858
|
+
/** @deprecated */
|
|
2708
2859
|
transformDirection(vector, result) {
|
|
2709
2860
|
return this.transformAsVector(vector, result);
|
|
2710
2861
|
}
|
|
2862
|
+
// three.js math API compatibility
|
|
2711
2863
|
makeRotationX(radians) {
|
|
2712
2864
|
return this.identity().rotateX(radians);
|
|
2713
2865
|
}
|
|
@@ -3034,6 +3186,13 @@ var __exports__ = (() => {
|
|
|
3034
3186
|
this[3] = object.w;
|
|
3035
3187
|
return this.check();
|
|
3036
3188
|
}
|
|
3189
|
+
/**
|
|
3190
|
+
* Creates a quaternion from the given 3x3 rotation matrix.
|
|
3191
|
+
* NOTE: The resultant quaternion is not normalized, so you should
|
|
3192
|
+
* be sure to renormalize the quaternion yourself where necessary.
|
|
3193
|
+
* @param m
|
|
3194
|
+
* @returns
|
|
3195
|
+
*/
|
|
3037
3196
|
fromMatrix3(m) {
|
|
3038
3197
|
fromMat3(this, m);
|
|
3039
3198
|
return this.check();
|
|
@@ -3042,13 +3201,21 @@ var __exports__ = (() => {
|
|
|
3042
3201
|
setAxisAngle(this, axis, rad);
|
|
3043
3202
|
return this.check();
|
|
3044
3203
|
}
|
|
3204
|
+
/** Set a quat to the identity quaternion */
|
|
3045
3205
|
identity() {
|
|
3046
3206
|
identity2(this);
|
|
3047
3207
|
return this.check();
|
|
3048
3208
|
}
|
|
3209
|
+
// Set the components of a quat to the given values
|
|
3210
|
+
// set(i, j, k, l) {
|
|
3211
|
+
// quat_set(this, i, j, k, l);
|
|
3212
|
+
// return this.check();
|
|
3213
|
+
// }
|
|
3214
|
+
// Sets a quat from the given angle and rotation axis, then returns it.
|
|
3049
3215
|
setAxisAngle(axis, rad) {
|
|
3050
3216
|
return this.fromAxisRotation(axis, rad);
|
|
3051
3217
|
}
|
|
3218
|
+
// Getters/setters
|
|
3052
3219
|
get ELEMENTS() {
|
|
3053
3220
|
return 4;
|
|
3054
3221
|
}
|
|
@@ -3076,35 +3243,72 @@ var __exports__ = (() => {
|
|
|
3076
3243
|
set w(value) {
|
|
3077
3244
|
this[3] = checkNumber(value);
|
|
3078
3245
|
}
|
|
3246
|
+
// Calculates the length of a quat
|
|
3079
3247
|
len() {
|
|
3080
3248
|
return length3(this);
|
|
3081
3249
|
}
|
|
3250
|
+
// Calculates the squared length of a quat
|
|
3082
3251
|
lengthSquared() {
|
|
3083
3252
|
return squaredLength2(this);
|
|
3084
3253
|
}
|
|
3254
|
+
// Calculates the dot product of two quat's
|
|
3255
|
+
// @return {Number}
|
|
3085
3256
|
dot(a) {
|
|
3086
3257
|
return dot3(this, a);
|
|
3087
3258
|
}
|
|
3259
|
+
// Gets the rotation axis and angle for a given quaternion.
|
|
3260
|
+
// If a quaternion is created with setAxisAngle, this method will
|
|
3261
|
+
// return the same values as providied in the original parameter
|
|
3262
|
+
// list OR functionally equivalent values.
|
|
3263
|
+
// Example: The quaternion formed by axis [0, 0, 1] and angle -90
|
|
3264
|
+
// is the same as the quaternion formed by [0, 0, 1] and 270.
|
|
3265
|
+
// This method favors the latter.
|
|
3266
|
+
// @return {{[x,y,z], Number}}
|
|
3267
|
+
// getAxisAngle() {
|
|
3268
|
+
// const axis = [];
|
|
3269
|
+
// // const angle = quat_getAxisAngle(axis, this);
|
|
3270
|
+
// return {axis, angle};
|
|
3271
|
+
// }
|
|
3272
|
+
// MODIFIERS
|
|
3273
|
+
// Sets a quaternion to represent the shortest rotation from one vector
|
|
3274
|
+
// to another. Both vectors are assumed to be unit length.
|
|
3088
3275
|
rotationTo(vectorA, vectorB) {
|
|
3089
3276
|
rotationTo(this, vectorA, vectorB);
|
|
3090
3277
|
return this.check();
|
|
3091
3278
|
}
|
|
3279
|
+
// Sets the specified quaternion with values corresponding to the given axes.
|
|
3280
|
+
// Each axis is a vec3 and is expected to be unit length and perpendicular
|
|
3281
|
+
// to all other specified axes.
|
|
3282
|
+
// setAxes() {
|
|
3283
|
+
// Number
|
|
3284
|
+
// }
|
|
3285
|
+
// Performs a spherical linear interpolation with two control points
|
|
3286
|
+
// sqlerp() {
|
|
3287
|
+
// Number;
|
|
3288
|
+
// }
|
|
3289
|
+
// Adds two quat's
|
|
3092
3290
|
add(a) {
|
|
3093
3291
|
add2(this, this, a);
|
|
3094
3292
|
return this.check();
|
|
3095
3293
|
}
|
|
3294
|
+
// Calculates the W component of a quat from the X, Y, and Z components.
|
|
3295
|
+
// Any existing W component will be ignored.
|
|
3096
3296
|
calculateW() {
|
|
3097
3297
|
calculateW(this, this);
|
|
3098
3298
|
return this.check();
|
|
3099
3299
|
}
|
|
3300
|
+
// Calculates the conjugate of a quat If the quaternion is normalized,
|
|
3301
|
+
// this function is faster than quat_invert and produces the same result.
|
|
3100
3302
|
conjugate() {
|
|
3101
3303
|
conjugate(this, this);
|
|
3102
3304
|
return this.check();
|
|
3103
3305
|
}
|
|
3306
|
+
// Calculates the inverse of a quat
|
|
3104
3307
|
invert() {
|
|
3105
3308
|
invert2(this, this);
|
|
3106
3309
|
return this.check();
|
|
3107
3310
|
}
|
|
3311
|
+
// Performs a linear interpolation between two quat's
|
|
3108
3312
|
lerp(a, b, t) {
|
|
3109
3313
|
if (t === void 0) {
|
|
3110
3314
|
return this.lerp(this, a, b);
|
|
@@ -3112,6 +3316,7 @@ var __exports__ = (() => {
|
|
|
3112
3316
|
lerp2(this, a, b, t);
|
|
3113
3317
|
return this.check();
|
|
3114
3318
|
}
|
|
3319
|
+
// Multiplies two quat's
|
|
3115
3320
|
multiplyRight(a) {
|
|
3116
3321
|
multiply2(this, this, a);
|
|
3117
3322
|
return this.check();
|
|
@@ -3120,6 +3325,7 @@ var __exports__ = (() => {
|
|
|
3120
3325
|
multiply2(this, a, this);
|
|
3121
3326
|
return this.check();
|
|
3122
3327
|
}
|
|
3328
|
+
// Normalize a quat
|
|
3123
3329
|
normalize() {
|
|
3124
3330
|
const length4 = this.len();
|
|
3125
3331
|
const l = length4 > 0 ? 1 / length4 : 0;
|
|
@@ -3132,22 +3338,27 @@ var __exports__ = (() => {
|
|
|
3132
3338
|
}
|
|
3133
3339
|
return this.check();
|
|
3134
3340
|
}
|
|
3341
|
+
// Rotates a quaternion by the given angle about the X axis
|
|
3135
3342
|
rotateX(rad) {
|
|
3136
3343
|
rotateX2(this, this, rad);
|
|
3137
3344
|
return this.check();
|
|
3138
3345
|
}
|
|
3346
|
+
// Rotates a quaternion by the given angle about the Y axis
|
|
3139
3347
|
rotateY(rad) {
|
|
3140
3348
|
rotateY2(this, this, rad);
|
|
3141
3349
|
return this.check();
|
|
3142
3350
|
}
|
|
3351
|
+
// Rotates a quaternion by the given angle about the Z axis
|
|
3143
3352
|
rotateZ(rad) {
|
|
3144
3353
|
rotateZ2(this, this, rad);
|
|
3145
3354
|
return this.check();
|
|
3146
3355
|
}
|
|
3356
|
+
// Scales a quat by a scalar number
|
|
3147
3357
|
scale(b) {
|
|
3148
3358
|
scale3(this, this, b);
|
|
3149
3359
|
return this.check();
|
|
3150
3360
|
}
|
|
3361
|
+
// Performs a spherical linear interpolation between two quat
|
|
3151
3362
|
slerp(arg0, arg1, arg2) {
|
|
3152
3363
|
let start;
|
|
3153
3364
|
let target;
|
|
@@ -3177,6 +3388,7 @@ var __exports__ = (() => {
|
|
|
3177
3388
|
transformQuat2(result, vector, this);
|
|
3178
3389
|
return checkVector(result, 4);
|
|
3179
3390
|
}
|
|
3391
|
+
// THREE.js Math API compatibility
|
|
3180
3392
|
lengthSq() {
|
|
3181
3393
|
return this.lengthSquared();
|
|
3182
3394
|
}
|
|
@@ -3369,568 +3581,7 @@ var __exports__ = (() => {
|
|
|
3369
3581
|
|
|
3370
3582
|
// src/gltf/create-gltf-model.ts
|
|
3371
3583
|
var import_core4 = __toESM(require_core(), 1);
|
|
3372
|
-
|
|
3373
|
-
// ../shadertools/src/lib/glsl-utils/highlight.ts
|
|
3374
|
-
var glsl = (x) => `${x}`;
|
|
3375
|
-
|
|
3376
|
-
// ../shadertools/src/modules-webgl1/lighting/lights/lights-glsl.ts
|
|
3377
|
-
var lightingShader = glsl`\
|
|
3378
|
-
#if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
3379
|
-
|
|
3380
|
-
struct AmbientLight {
|
|
3381
|
-
vec3 color;
|
|
3382
|
-
};
|
|
3383
|
-
|
|
3384
|
-
struct PointLight {
|
|
3385
|
-
vec3 color;
|
|
3386
|
-
vec3 position;
|
|
3387
|
-
|
|
3388
|
-
// Constant-Linear-Exponential
|
|
3389
|
-
vec3 attenuation;
|
|
3390
|
-
};
|
|
3391
|
-
|
|
3392
|
-
struct DirectionalLight {
|
|
3393
|
-
vec3 color;
|
|
3394
|
-
vec3 direction;
|
|
3395
|
-
};
|
|
3396
|
-
|
|
3397
|
-
uniform AmbientLight lighting_uAmbientLight;
|
|
3398
|
-
uniform PointLight lighting_uPointLight[MAX_LIGHTS];
|
|
3399
|
-
uniform DirectionalLight lighting_uDirectionalLight[MAX_LIGHTS];
|
|
3400
|
-
uniform int lighting_uPointLightCount;
|
|
3401
|
-
uniform int lighting_uDirectionalLightCount;
|
|
3402
|
-
|
|
3403
|
-
uniform bool lighting_uEnabled;
|
|
3404
|
-
|
|
3405
|
-
float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
3406
|
-
return pointLight.attenuation.x
|
|
3407
|
-
+ pointLight.attenuation.y * distance
|
|
3408
|
-
+ pointLight.attenuation.z * distance * distance;
|
|
3409
|
-
}
|
|
3410
|
-
|
|
3411
|
-
#endif
|
|
3412
|
-
`;
|
|
3413
|
-
|
|
3414
|
-
// ../shadertools/src/modules-webgl1/lighting/lights/lights.ts
|
|
3415
|
-
var INITIAL_MODULE_OPTIONS = {
|
|
3416
|
-
lightSources: {}
|
|
3417
|
-
};
|
|
3418
|
-
function convertColor(colorDef = {}) {
|
|
3419
|
-
const { color = [0, 0, 0], intensity = 1 } = colorDef;
|
|
3420
|
-
return color.map((component) => component * intensity / 255);
|
|
3421
|
-
}
|
|
3422
|
-
function getLightSourceUniforms({
|
|
3423
|
-
ambientLight,
|
|
3424
|
-
pointLights = [],
|
|
3425
|
-
directionalLights = []
|
|
3426
|
-
}) {
|
|
3427
|
-
const lightSourceUniforms = {};
|
|
3428
|
-
if (ambientLight) {
|
|
3429
|
-
lightSourceUniforms["lighting_uAmbientLight.color"] = convertColor(ambientLight);
|
|
3430
|
-
} else {
|
|
3431
|
-
lightSourceUniforms["lighting_uAmbientLight.color"] = [0, 0, 0];
|
|
3432
|
-
}
|
|
3433
|
-
pointLights.forEach((pointLight, index) => {
|
|
3434
|
-
lightSourceUniforms[`lighting_uPointLight[${index}].color`] = convertColor(pointLight);
|
|
3435
|
-
lightSourceUniforms[`lighting_uPointLight[${index}].position`] = pointLight.position;
|
|
3436
|
-
lightSourceUniforms[`lighting_uPointLight[${index}].attenuation`] = pointLight.attenuation || [
|
|
3437
|
-
1,
|
|
3438
|
-
0,
|
|
3439
|
-
0
|
|
3440
|
-
];
|
|
3441
|
-
});
|
|
3442
|
-
lightSourceUniforms.lighting_uPointLightCount = pointLights.length;
|
|
3443
|
-
directionalLights.forEach((directionalLight, index) => {
|
|
3444
|
-
lightSourceUniforms[`lighting_uDirectionalLight[${index}].color`] = convertColor(directionalLight);
|
|
3445
|
-
lightSourceUniforms[`lighting_uDirectionalLight[${index}].direction`] = directionalLight.direction;
|
|
3446
|
-
});
|
|
3447
|
-
lightSourceUniforms.lighting_uDirectionalLightCount = directionalLights.length;
|
|
3448
|
-
return lightSourceUniforms;
|
|
3449
|
-
}
|
|
3450
|
-
function getUniforms(opts = INITIAL_MODULE_OPTIONS) {
|
|
3451
|
-
if ("lightSources" in opts) {
|
|
3452
|
-
const { ambientLight, pointLights, directionalLights } = opts.lightSources || {};
|
|
3453
|
-
const hasLights = ambientLight || pointLights && pointLights.length > 0 || directionalLights && directionalLights.length > 0;
|
|
3454
|
-
if (!hasLights) {
|
|
3455
|
-
return { lighting_uEnabled: false };
|
|
3456
|
-
}
|
|
3457
|
-
return Object.assign(
|
|
3458
|
-
{},
|
|
3459
|
-
getLightSourceUniforms({ ambientLight, pointLights, directionalLights }),
|
|
3460
|
-
{
|
|
3461
|
-
lighting_uEnabled: true
|
|
3462
|
-
}
|
|
3463
|
-
);
|
|
3464
|
-
}
|
|
3465
|
-
if ("lights" in opts) {
|
|
3466
|
-
const lightSources = { pointLights: [], directionalLights: [] };
|
|
3467
|
-
for (const light of opts.lights || []) {
|
|
3468
|
-
switch (light.type) {
|
|
3469
|
-
case "ambient":
|
|
3470
|
-
lightSources.ambientLight = light;
|
|
3471
|
-
break;
|
|
3472
|
-
case "directional":
|
|
3473
|
-
lightSources.directionalLights?.push(light);
|
|
3474
|
-
break;
|
|
3475
|
-
case "point":
|
|
3476
|
-
lightSources.pointLights?.push(light);
|
|
3477
|
-
break;
|
|
3478
|
-
default:
|
|
3479
|
-
}
|
|
3480
|
-
}
|
|
3481
|
-
return getUniforms({ lightSources });
|
|
3482
|
-
}
|
|
3483
|
-
return {};
|
|
3484
|
-
}
|
|
3485
|
-
var lights = {
|
|
3486
|
-
name: "lights",
|
|
3487
|
-
vs: lightingShader,
|
|
3488
|
-
fs: lightingShader,
|
|
3489
|
-
getUniforms,
|
|
3490
|
-
defines: {
|
|
3491
|
-
MAX_LIGHTS: 3
|
|
3492
|
-
}
|
|
3493
|
-
};
|
|
3494
|
-
|
|
3495
|
-
// ../shadertools/src/modules-webgl1/lighting/pbr/pbr-vertex-glsl.ts
|
|
3496
|
-
var vs = glsl`\
|
|
3497
|
-
uniform mat4 u_MVPMatrix;
|
|
3498
|
-
uniform mat4 u_ModelMatrix;
|
|
3499
|
-
uniform mat4 u_NormalMatrix;
|
|
3500
|
-
|
|
3501
|
-
out vec3 pbr_vPosition;
|
|
3502
|
-
out vec2 pbr_vUV;
|
|
3503
|
-
|
|
3504
|
-
#ifdef HAS_NORMALS
|
|
3505
|
-
# ifdef HAS_TANGENTS
|
|
3506
|
-
out mat3 pbr_vTBN;
|
|
3507
|
-
# else
|
|
3508
|
-
out vec3 pbr_vNormal;
|
|
3509
|
-
# endif
|
|
3510
|
-
#endif
|
|
3511
|
-
|
|
3512
|
-
void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, vec2 uv)
|
|
3513
|
-
{
|
|
3514
|
-
vec4 pos = u_ModelMatrix * position;
|
|
3515
|
-
pbr_vPosition = vec3(pos.xyz) / pos.w;
|
|
3516
|
-
|
|
3517
|
-
#ifdef HAS_NORMALS
|
|
3518
|
-
#ifdef HAS_TANGENTS
|
|
3519
|
-
vec3 normalW = normalize(vec3(u_NormalMatrix * vec4(normal.xyz, 0.0)));
|
|
3520
|
-
vec3 tangentW = normalize(vec3(u_ModelMatrix * vec4(tangent.xyz, 0.0)));
|
|
3521
|
-
vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
|
|
3522
|
-
pbr_vTBN = mat3(tangentW, bitangentW, normalW);
|
|
3523
|
-
#else // HAS_TANGENTS != 1
|
|
3524
|
-
pbr_vNormal = normalize(vec3(u_ModelMatrix * vec4(normal.xyz, 0.0)));
|
|
3525
|
-
#endif
|
|
3526
|
-
#endif
|
|
3527
|
-
|
|
3528
|
-
#ifdef HAS_UV
|
|
3529
|
-
pbr_vUV = uv;
|
|
3530
|
-
#else
|
|
3531
|
-
pbr_vUV = vec2(0.,0.);
|
|
3532
|
-
#endif
|
|
3533
|
-
}
|
|
3534
|
-
`;
|
|
3535
|
-
|
|
3536
|
-
// ../shadertools/src/modules-webgl1/lighting/pbr/pbr-fragment-glsl.ts
|
|
3537
|
-
var fs = glsl`\
|
|
3538
|
-
precision highp float;
|
|
3539
|
-
|
|
3540
|
-
uniform bool pbr_uUnlit;
|
|
3541
|
-
|
|
3542
|
-
#ifdef USE_IBL
|
|
3543
|
-
uniform samplerCube u_DiffuseEnvSampler;
|
|
3544
|
-
uniform samplerCube u_SpecularEnvSampler;
|
|
3545
|
-
uniform sampler2D u_brdfLUT;
|
|
3546
|
-
uniform vec2 u_ScaleIBLAmbient;
|
|
3547
|
-
#endif
|
|
3548
|
-
|
|
3549
|
-
#ifdef HAS_BASECOLORMAP
|
|
3550
|
-
uniform sampler2D u_BaseColorSampler;
|
|
3551
|
-
#endif
|
|
3552
|
-
#ifdef HAS_NORMALMAP
|
|
3553
|
-
uniform sampler2D u_NormalSampler;
|
|
3554
|
-
uniform float u_NormalScale;
|
|
3555
|
-
#endif
|
|
3556
|
-
#ifdef HAS_EMISSIVEMAP
|
|
3557
|
-
uniform sampler2D u_EmissiveSampler;
|
|
3558
|
-
uniform vec3 u_EmissiveFactor;
|
|
3559
|
-
#endif
|
|
3560
|
-
#ifdef HAS_METALROUGHNESSMAP
|
|
3561
|
-
uniform sampler2D u_MetallicRoughnessSampler;
|
|
3562
|
-
#endif
|
|
3563
|
-
#ifdef HAS_OCCLUSIONMAP
|
|
3564
|
-
uniform sampler2D u_OcclusionSampler;
|
|
3565
|
-
uniform float u_OcclusionStrength;
|
|
3566
|
-
#endif
|
|
3567
|
-
|
|
3568
|
-
#ifdef ALPHA_CUTOFF
|
|
3569
|
-
uniform float u_AlphaCutoff;
|
|
3570
|
-
#endif
|
|
3571
|
-
|
|
3572
|
-
uniform vec2 u_MetallicRoughnessValues;
|
|
3573
|
-
uniform vec4 u_BaseColorFactor;
|
|
3574
|
-
|
|
3575
|
-
uniform vec3 u_Camera;
|
|
3576
|
-
|
|
3577
|
-
// debugging flags used for shader output of intermediate PBR variables
|
|
3578
|
-
#ifdef PBR_DEBUG
|
|
3579
|
-
uniform vec4 u_ScaleDiffBaseMR;
|
|
3580
|
-
uniform vec4 u_ScaleFGDSpec;
|
|
3581
|
-
#endif
|
|
3582
|
-
|
|
3583
|
-
in vec3 pbr_vPosition;
|
|
3584
|
-
|
|
3585
|
-
in vec2 pbr_vUV;
|
|
3586
|
-
|
|
3587
|
-
#ifdef HAS_NORMALS
|
|
3588
|
-
#ifdef HAS_TANGENTS
|
|
3589
|
-
in mat3 pbr_vTBN;
|
|
3590
|
-
#else
|
|
3591
|
-
in vec3 pbr_vNormal;
|
|
3592
|
-
#endif
|
|
3593
|
-
#endif
|
|
3594
|
-
|
|
3595
|
-
// Encapsulate the various inputs used by the various functions in the shading equation
|
|
3596
|
-
// We store values in this struct to simplify the integration of alternative implementations
|
|
3597
|
-
// of the shading terms, outlined in the Readme.MD Appendix.
|
|
3598
|
-
struct PBRInfo
|
|
3599
|
-
{
|
|
3600
|
-
float NdotL; // cos angle between normal and light direction
|
|
3601
|
-
float NdotV; // cos angle between normal and view direction
|
|
3602
|
-
float NdotH; // cos angle between normal and half vector
|
|
3603
|
-
float LdotH; // cos angle between light direction and half vector
|
|
3604
|
-
float VdotH; // cos angle between view direction and half vector
|
|
3605
|
-
float perceptualRoughness; // roughness value, as authored by the model creator (input to shader)
|
|
3606
|
-
float metalness; // metallic value at the surface
|
|
3607
|
-
vec3 reflectance0; // full reflectance color (normal incidence angle)
|
|
3608
|
-
vec3 reflectance90; // reflectance color at grazing angle
|
|
3609
|
-
float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2])
|
|
3610
|
-
vec3 diffuseColor; // color contribution from diffuse lighting
|
|
3611
|
-
vec3 specularColor; // color contribution from specular lighting
|
|
3612
|
-
vec3 n; // normal at surface point
|
|
3613
|
-
vec3 v; // vector from surface point to camera
|
|
3614
|
-
};
|
|
3615
|
-
|
|
3616
|
-
const float M_PI = 3.141592653589793;
|
|
3617
|
-
const float c_MinRoughness = 0.04;
|
|
3618
|
-
|
|
3619
|
-
vec4 SRGBtoLINEAR(vec4 srgbIn)
|
|
3620
|
-
{
|
|
3621
|
-
#ifdef MANUAL_SRGB
|
|
3622
|
-
#ifdef SRGB_FAST_APPROXIMATION
|
|
3623
|
-
vec3 linOut = pow(srgbIn.xyz,vec3(2.2));
|
|
3624
|
-
#else //SRGB_FAST_APPROXIMATION
|
|
3625
|
-
vec3 bLess = step(vec3(0.04045),srgbIn.xyz);
|
|
3626
|
-
vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );
|
|
3627
|
-
#endif //SRGB_FAST_APPROXIMATION
|
|
3628
|
-
return vec4(linOut,srgbIn.w);;
|
|
3629
|
-
#else //MANUAL_SRGB
|
|
3630
|
-
return srgbIn;
|
|
3631
|
-
#endif //MANUAL_SRGB
|
|
3632
|
-
}
|
|
3633
|
-
|
|
3634
|
-
// Find the normal for this fragment, pulling either from a predefined normal map
|
|
3635
|
-
// or from the interpolated mesh normal and tangent attributes.
|
|
3636
|
-
vec3 getNormal()
|
|
3637
|
-
{
|
|
3638
|
-
// Retrieve the tangent space matrix
|
|
3639
|
-
#ifndef HAS_TANGENTS
|
|
3640
|
-
vec3 pos_dx = dFdx(pbr_vPosition);
|
|
3641
|
-
vec3 pos_dy = dFdy(pbr_vPosition);
|
|
3642
|
-
vec3 tex_dx = dFdx(vec3(pbr_vUV, 0.0));
|
|
3643
|
-
vec3 tex_dy = dFdy(vec3(pbr_vUV, 0.0));
|
|
3644
|
-
vec3 t = (tex_dy.t * pos_dx - tex_dx.t * pos_dy) / (tex_dx.s * tex_dy.t - tex_dy.s * tex_dx.t);
|
|
3645
|
-
|
|
3646
|
-
#ifdef HAS_NORMALS
|
|
3647
|
-
vec3 ng = normalize(pbr_vNormal);
|
|
3648
|
-
#else
|
|
3649
|
-
vec3 ng = cross(pos_dx, pos_dy);
|
|
3650
|
-
#endif
|
|
3651
|
-
|
|
3652
|
-
t = normalize(t - ng * dot(ng, t));
|
|
3653
|
-
vec3 b = normalize(cross(ng, t));
|
|
3654
|
-
mat3 tbn = mat3(t, b, ng);
|
|
3655
|
-
#else // HAS_TANGENTS
|
|
3656
|
-
mat3 tbn = pbr_vTBN;
|
|
3657
|
-
#endif
|
|
3658
|
-
|
|
3659
|
-
#ifdef HAS_NORMALMAP
|
|
3660
|
-
vec3 n = texture(u_NormalSampler, pbr_vUV).rgb;
|
|
3661
|
-
n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_NormalScale, u_NormalScale, 1.0)));
|
|
3662
|
-
#else
|
|
3663
|
-
// The tbn matrix is linearly interpolated, so we need to re-normalize
|
|
3664
|
-
vec3 n = normalize(tbn[2].xyz);
|
|
3665
|
-
#endif
|
|
3666
|
-
|
|
3667
|
-
return n;
|
|
3668
|
-
}
|
|
3669
|
-
|
|
3670
|
-
// Calculation of the lighting contribution from an optional Image Based Light source.
|
|
3671
|
-
// Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].
|
|
3672
|
-
// See our README.md on Environment Maps [3] for additional discussion.
|
|
3673
|
-
#ifdef USE_IBL
|
|
3674
|
-
vec3 getIBLContribution(PBRInfo pbrInputs, vec3 n, vec3 reflection)
|
|
3675
|
-
{
|
|
3676
|
-
float mipCount = 9.0; // resolution of 512x512
|
|
3677
|
-
float lod = (pbrInputs.perceptualRoughness * mipCount);
|
|
3678
|
-
// retrieve a scale and bias to F0. See [1], Figure 3
|
|
3679
|
-
vec3 brdf = SRGBtoLINEAR(texture(u_brdfLUT,
|
|
3680
|
-
vec2(pbrInputs.NdotV, 1.0 - pbrInputs.perceptualRoughness))).rgb;
|
|
3681
|
-
vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;
|
|
3682
|
-
|
|
3683
|
-
#ifdef USE_TEX_LOD
|
|
3684
|
-
vec3 specularLight = SRGBtoLINEAR(textureCubeLod(u_SpecularEnvSampler, reflection, lod)).rgb;
|
|
3685
|
-
#else
|
|
3686
|
-
vec3 specularLight = SRGBtoLINEAR(textureCube(u_SpecularEnvSampler, reflection)).rgb;
|
|
3687
|
-
#endif
|
|
3688
|
-
|
|
3689
|
-
vec3 diffuse = diffuseLight * pbrInputs.diffuseColor;
|
|
3690
|
-
vec3 specular = specularLight * (pbrInputs.specularColor * brdf.x + brdf.y);
|
|
3691
|
-
|
|
3692
|
-
// For presentation, this allows us to disable IBL terms
|
|
3693
|
-
diffuse *= u_ScaleIBLAmbient.x;
|
|
3694
|
-
specular *= u_ScaleIBLAmbient.y;
|
|
3695
|
-
|
|
3696
|
-
return diffuse + specular;
|
|
3697
|
-
}
|
|
3698
|
-
#endif
|
|
3699
|
-
|
|
3700
|
-
// Basic Lambertian diffuse
|
|
3701
|
-
// Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog
|
|
3702
|
-
// See also [1], Equation 1
|
|
3703
|
-
vec3 diffuse(PBRInfo pbrInputs)
|
|
3704
|
-
{
|
|
3705
|
-
return pbrInputs.diffuseColor / M_PI;
|
|
3706
|
-
}
|
|
3707
|
-
|
|
3708
|
-
// The following equation models the Fresnel reflectance term of the spec equation (aka F())
|
|
3709
|
-
// Implementation of fresnel from [4], Equation 15
|
|
3710
|
-
vec3 specularReflection(PBRInfo pbrInputs)
|
|
3711
|
-
{
|
|
3712
|
-
return pbrInputs.reflectance0 +
|
|
3713
|
-
(pbrInputs.reflectance90 - pbrInputs.reflectance0) *
|
|
3714
|
-
pow(clamp(1.0 - pbrInputs.VdotH, 0.0, 1.0), 5.0);
|
|
3715
|
-
}
|
|
3716
|
-
|
|
3717
|
-
// This calculates the specular geometric attenuation (aka G()),
|
|
3718
|
-
// where rougher material will reflect less light back to the viewer.
|
|
3719
|
-
// This implementation is based on [1] Equation 4, and we adopt their modifications to
|
|
3720
|
-
// alphaRoughness as input as originally proposed in [2].
|
|
3721
|
-
float geometricOcclusion(PBRInfo pbrInputs)
|
|
3722
|
-
{
|
|
3723
|
-
float NdotL = pbrInputs.NdotL;
|
|
3724
|
-
float NdotV = pbrInputs.NdotV;
|
|
3725
|
-
float r = pbrInputs.alphaRoughness;
|
|
3726
|
-
|
|
3727
|
-
float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));
|
|
3728
|
-
float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));
|
|
3729
|
-
return attenuationL * attenuationV;
|
|
3730
|
-
}
|
|
3731
|
-
|
|
3732
|
-
// The following equation(s) model the distribution of microfacet normals across
|
|
3733
|
-
// the area being drawn (aka D())
|
|
3734
|
-
// Implementation from "Average Irregularity Representation of a Roughened Surface
|
|
3735
|
-
// for Ray Reflection" by T. S. Trowbridge, and K. P. Reitz
|
|
3736
|
-
// Follows the distribution function recommended in the SIGGRAPH 2013 course notes
|
|
3737
|
-
// from EPIC Games [1], Equation 3.
|
|
3738
|
-
float microfacetDistribution(PBRInfo pbrInputs)
|
|
3739
|
-
{
|
|
3740
|
-
float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness;
|
|
3741
|
-
float f = (pbrInputs.NdotH * roughnessSq - pbrInputs.NdotH) * pbrInputs.NdotH + 1.0;
|
|
3742
|
-
return roughnessSq / (M_PI * f * f);
|
|
3743
|
-
}
|
|
3744
|
-
|
|
3745
|
-
void PBRInfo_setAmbientLight(inout PBRInfo pbrInputs) {
|
|
3746
|
-
pbrInputs.NdotL = 1.0;
|
|
3747
|
-
pbrInputs.NdotH = 0.0;
|
|
3748
|
-
pbrInputs.LdotH = 0.0;
|
|
3749
|
-
pbrInputs.VdotH = 1.0;
|
|
3750
|
-
}
|
|
3751
|
-
|
|
3752
|
-
void PBRInfo_setDirectionalLight(inout PBRInfo pbrInputs, vec3 lightDirection) {
|
|
3753
|
-
vec3 n = pbrInputs.n;
|
|
3754
|
-
vec3 v = pbrInputs.v;
|
|
3755
|
-
vec3 l = normalize(lightDirection); // Vector from surface point to light
|
|
3756
|
-
vec3 h = normalize(l+v); // Half vector between both l and v
|
|
3757
|
-
|
|
3758
|
-
pbrInputs.NdotL = clamp(dot(n, l), 0.001, 1.0);
|
|
3759
|
-
pbrInputs.NdotH = clamp(dot(n, h), 0.0, 1.0);
|
|
3760
|
-
pbrInputs.LdotH = clamp(dot(l, h), 0.0, 1.0);
|
|
3761
|
-
pbrInputs.VdotH = clamp(dot(v, h), 0.0, 1.0);
|
|
3762
|
-
}
|
|
3763
|
-
|
|
3764
|
-
void PBRInfo_setPointLight(inout PBRInfo pbrInputs, PointLight pointLight) {
|
|
3765
|
-
vec3 light_direction = normalize(pointLight.position - pbr_vPosition);
|
|
3766
|
-
PBRInfo_setDirectionalLight(pbrInputs, light_direction);
|
|
3767
|
-
}
|
|
3768
|
-
|
|
3769
|
-
vec3 calculateFinalColor(PBRInfo pbrInputs, vec3 lightColor) {
|
|
3770
|
-
// Calculate the shading terms for the microfacet specular shading model
|
|
3771
|
-
vec3 F = specularReflection(pbrInputs);
|
|
3772
|
-
float G = geometricOcclusion(pbrInputs);
|
|
3773
|
-
float D = microfacetDistribution(pbrInputs);
|
|
3774
|
-
|
|
3775
|
-
// Calculation of analytical lighting contribution
|
|
3776
|
-
vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInputs);
|
|
3777
|
-
vec3 specContrib = F * G * D / (4.0 * pbrInputs.NdotL * pbrInputs.NdotV);
|
|
3778
|
-
// Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)
|
|
3779
|
-
return pbrInputs.NdotL * lightColor * (diffuseContrib + specContrib);
|
|
3780
|
-
}
|
|
3781
|
-
|
|
3782
|
-
vec4 pbr_filterColor(vec4 colorUnused)
|
|
3783
|
-
{
|
|
3784
|
-
// The albedo may be defined from a base texture or a flat color
|
|
3785
|
-
#ifdef HAS_BASECOLORMAP
|
|
3786
|
-
vec4 baseColor = SRGBtoLINEAR(texture(u_BaseColorSampler, pbr_vUV)) * u_BaseColorFactor;
|
|
3787
|
-
#else
|
|
3788
|
-
vec4 baseColor = u_BaseColorFactor;
|
|
3789
|
-
#endif
|
|
3790
|
-
|
|
3791
|
-
#ifdef ALPHA_CUTOFF
|
|
3792
|
-
if (baseColor.a < u_AlphaCutoff) {
|
|
3793
|
-
discard;
|
|
3794
|
-
}
|
|
3795
|
-
#endif
|
|
3796
|
-
|
|
3797
|
-
vec3 color = vec3(0, 0, 0);
|
|
3798
|
-
|
|
3799
|
-
if(pbr_uUnlit){
|
|
3800
|
-
color.rgb = baseColor.rgb;
|
|
3801
|
-
}
|
|
3802
|
-
else{
|
|
3803
|
-
// Metallic and Roughness material properties are packed together
|
|
3804
|
-
// In glTF, these factors can be specified by fixed scalar values
|
|
3805
|
-
// or from a metallic-roughness map
|
|
3806
|
-
float perceptualRoughness = u_MetallicRoughnessValues.y;
|
|
3807
|
-
float metallic = u_MetallicRoughnessValues.x;
|
|
3808
|
-
#ifdef HAS_METALROUGHNESSMAP
|
|
3809
|
-
// Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
|
|
3810
|
-
// This layout intentionally reserves the 'r' channel for (optional) occlusion map data
|
|
3811
|
-
vec4 mrSample = texture(u_MetallicRoughnessSampler, pbr_vUV);
|
|
3812
|
-
perceptualRoughness = mrSample.g * perceptualRoughness;
|
|
3813
|
-
metallic = mrSample.b * metallic;
|
|
3814
|
-
#endif
|
|
3815
|
-
perceptualRoughness = clamp(perceptualRoughness, c_MinRoughness, 1.0);
|
|
3816
|
-
metallic = clamp(metallic, 0.0, 1.0);
|
|
3817
|
-
// Roughness is authored as perceptual roughness; as is convention,
|
|
3818
|
-
// convert to material roughness by squaring the perceptual roughness [2].
|
|
3819
|
-
float alphaRoughness = perceptualRoughness * perceptualRoughness;
|
|
3820
|
-
|
|
3821
|
-
vec3 f0 = vec3(0.04);
|
|
3822
|
-
vec3 diffuseColor = baseColor.rgb * (vec3(1.0) - f0);
|
|
3823
|
-
diffuseColor *= 1.0 - metallic;
|
|
3824
|
-
vec3 specularColor = mix(f0, baseColor.rgb, metallic);
|
|
3825
|
-
|
|
3826
|
-
// Compute reflectance.
|
|
3827
|
-
float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
|
|
3828
|
-
|
|
3829
|
-
// For typical incident reflectance range (between 4% to 100%) set the grazing
|
|
3830
|
-
// reflectance to 100% for typical fresnel effect.
|
|
3831
|
-
// For very low reflectance range on highly diffuse objects (below 4%),
|
|
3832
|
-
// incrementally reduce grazing reflecance to 0%.
|
|
3833
|
-
float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
|
|
3834
|
-
vec3 specularEnvironmentR0 = specularColor.rgb;
|
|
3835
|
-
vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
|
|
3836
|
-
|
|
3837
|
-
vec3 n = getNormal(); // normal at surface point
|
|
3838
|
-
vec3 v = normalize(u_Camera - pbr_vPosition); // Vector from surface point to camera
|
|
3839
|
-
|
|
3840
|
-
float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
|
|
3841
|
-
vec3 reflection = -normalize(reflect(v, n));
|
|
3842
|
-
|
|
3843
|
-
PBRInfo pbrInputs = PBRInfo(
|
|
3844
|
-
0.0, // NdotL
|
|
3845
|
-
NdotV,
|
|
3846
|
-
0.0, // NdotH
|
|
3847
|
-
0.0, // LdotH
|
|
3848
|
-
0.0, // VdotH
|
|
3849
|
-
perceptualRoughness,
|
|
3850
|
-
metallic,
|
|
3851
|
-
specularEnvironmentR0,
|
|
3852
|
-
specularEnvironmentR90,
|
|
3853
|
-
alphaRoughness,
|
|
3854
|
-
diffuseColor,
|
|
3855
|
-
specularColor,
|
|
3856
|
-
n,
|
|
3857
|
-
v
|
|
3858
|
-
);
|
|
3859
|
-
|
|
3860
|
-
#ifdef USE_LIGHTS
|
|
3861
|
-
// Apply ambient light
|
|
3862
|
-
PBRInfo_setAmbientLight(pbrInputs);
|
|
3863
|
-
color += calculateFinalColor(pbrInputs, lighting_uAmbientLight.color);
|
|
3864
|
-
|
|
3865
|
-
// Apply directional light
|
|
3866
|
-
for(int i = 0; i < lighting_uDirectionalLightCount; i++) {
|
|
3867
|
-
if (i < lighting_uDirectionalLightCount) {
|
|
3868
|
-
PBRInfo_setDirectionalLight(pbrInputs, lighting_uDirectionalLight[i].direction);
|
|
3869
|
-
color += calculateFinalColor(pbrInputs, lighting_uDirectionalLight[i].color);
|
|
3870
|
-
}
|
|
3871
|
-
}
|
|
3872
|
-
|
|
3873
|
-
// Apply point light
|
|
3874
|
-
for(int i = 0; i < lighting_uPointLightCount; i++) {
|
|
3875
|
-
if (i < lighting_uPointLightCount) {
|
|
3876
|
-
PBRInfo_setPointLight(pbrInputs, lighting_uPointLight[i]);
|
|
3877
|
-
float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition));
|
|
3878
|
-
color += calculateFinalColor(pbrInputs, lighting_uPointLight[i].color / attenuation);
|
|
3879
|
-
}
|
|
3880
|
-
}
|
|
3881
|
-
#endif
|
|
3882
|
-
|
|
3883
|
-
// Calculate lighting contribution from image based lighting source (IBL)
|
|
3884
|
-
#ifdef USE_IBL
|
|
3885
|
-
color += getIBLContribution(pbrInputs, n, reflection);
|
|
3886
|
-
#endif
|
|
3887
|
-
|
|
3888
|
-
// Apply optional PBR terms for additional (optional) shading
|
|
3889
|
-
#ifdef HAS_OCCLUSIONMAP
|
|
3890
|
-
float ao = texture(u_OcclusionSampler, pbr_vUV).r;
|
|
3891
|
-
color = mix(color, color * ao, u_OcclusionStrength);
|
|
3892
|
-
#endif
|
|
3893
|
-
|
|
3894
|
-
#ifdef HAS_EMISSIVEMAP
|
|
3895
|
-
vec3 emissive = SRGBtoLINEAR(texture(u_EmissiveSampler, pbr_vUV)).rgb * u_EmissiveFactor;
|
|
3896
|
-
color += emissive;
|
|
3897
|
-
#endif
|
|
3898
|
-
|
|
3899
|
-
// This section uses mix to override final color for reference app visualization
|
|
3900
|
-
// of various parameters in the lighting equation.
|
|
3901
|
-
#ifdef PBR_DEBUG
|
|
3902
|
-
// TODO: Figure out how to debug multiple lights
|
|
3903
|
-
|
|
3904
|
-
// color = mix(color, F, u_ScaleFGDSpec.x);
|
|
3905
|
-
// color = mix(color, vec3(G), u_ScaleFGDSpec.y);
|
|
3906
|
-
// color = mix(color, vec3(D), u_ScaleFGDSpec.z);
|
|
3907
|
-
// color = mix(color, specContrib, u_ScaleFGDSpec.w);
|
|
3908
|
-
|
|
3909
|
-
// color = mix(color, diffuseContrib, u_ScaleDiffBaseMR.x);
|
|
3910
|
-
color = mix(color, baseColor.rgb, u_ScaleDiffBaseMR.y);
|
|
3911
|
-
color = mix(color, vec3(metallic), u_ScaleDiffBaseMR.z);
|
|
3912
|
-
color = mix(color, vec3(perceptualRoughness), u_ScaleDiffBaseMR.w);
|
|
3913
|
-
#endif
|
|
3914
|
-
|
|
3915
|
-
}
|
|
3916
|
-
|
|
3917
|
-
return vec4(pow(color,vec3(1.0/2.2)), baseColor.a);
|
|
3918
|
-
}
|
|
3919
|
-
`;
|
|
3920
|
-
|
|
3921
|
-
// ../shadertools/src/modules-webgl1/lighting/pbr/pbr.ts
|
|
3922
|
-
var pbr = {
|
|
3923
|
-
name: "pbr",
|
|
3924
|
-
vs,
|
|
3925
|
-
fs,
|
|
3926
|
-
defines: {
|
|
3927
|
-
LIGHTING_FRAGMENT: 1
|
|
3928
|
-
},
|
|
3929
|
-
dependencies: [lights],
|
|
3930
|
-
getUniforms: (props) => props
|
|
3931
|
-
};
|
|
3932
|
-
|
|
3933
|
-
// src/gltf/create-gltf-model.ts
|
|
3584
|
+
var import_shadertools = __toESM(require_shadertools(), 1);
|
|
3934
3585
|
var import_engine2 = __toESM(require_engine(), 1);
|
|
3935
3586
|
var SHADER = (
|
|
3936
3587
|
/* WGSL */
|
|
@@ -3981,8 +3632,9 @@ layout(0) positions: vec4; // in vec4 POSITION;
|
|
|
3981
3632
|
}
|
|
3982
3633
|
`
|
|
3983
3634
|
);
|
|
3984
|
-
var
|
|
3985
|
-
|
|
3635
|
+
var vs = (
|
|
3636
|
+
/* glsl */
|
|
3637
|
+
`#version 300 es
|
|
3986
3638
|
|
|
3987
3639
|
// in vec4 POSITION;
|
|
3988
3640
|
in vec4 positions;
|
|
@@ -4021,16 +3673,19 @@ layout(0) positions: vec4; // in vec4 POSITION;
|
|
|
4021
3673
|
pbr_setPositionNormalTangentUV(positions, _NORMAL, _TANGENT, _TEXCOORD_0);
|
|
4022
3674
|
gl_Position = u_MVPMatrix * positions;
|
|
4023
3675
|
}
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
3676
|
+
`
|
|
3677
|
+
);
|
|
3678
|
+
var fs = (
|
|
3679
|
+
/* glsl */
|
|
3680
|
+
`#version 300 es
|
|
4027
3681
|
out vec4 fragmentColor;
|
|
4028
3682
|
|
|
4029
3683
|
void main(void) {
|
|
4030
3684
|
vec3 pos = pbr_vPosition;
|
|
4031
3685
|
fragmentColor = pbr_filterColor(vec4(1.0));
|
|
4032
3686
|
}
|
|
4033
|
-
|
|
3687
|
+
`
|
|
3688
|
+
);
|
|
4034
3689
|
function createGLTFModel(device, options) {
|
|
4035
3690
|
const { id, geometry, material, vertexCount, materialOptions, modelOptions } = options;
|
|
4036
3691
|
const parsedMaterial = parsePBRMaterial(device, material, geometry.attributes, materialOptions);
|
|
@@ -4045,12 +3700,12 @@ layout(0) positions: vec4; // in vec4 POSITION;
|
|
|
4045
3700
|
const modelProps = {
|
|
4046
3701
|
id,
|
|
4047
3702
|
source: SHADER,
|
|
4048
|
-
vs
|
|
4049
|
-
fs
|
|
3703
|
+
vs,
|
|
3704
|
+
fs,
|
|
4050
3705
|
geometry,
|
|
4051
3706
|
topology: geometry.topology,
|
|
4052
3707
|
vertexCount,
|
|
4053
|
-
modules: [pbr],
|
|
3708
|
+
modules: [import_shadertools.pbr],
|
|
4054
3709
|
...modelOptions,
|
|
4055
3710
|
bindings: { ...parsedMaterial.bindings, ...modelOptions.bindings },
|
|
4056
3711
|
defines: { ...parsedMaterial.defines, ...modelOptions.defines },
|