@galacean/effects-plugin-model 2.0.0-alpha.2 → 2.0.0-alpha.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/dist/index.d.ts +8 -0
- package/dist/index.js +324 -163
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +2 -2
- package/dist/index.mjs +326 -165
- package/dist/index.mjs.map +1 -1
- package/dist/loader.mjs +327 -166
- package/dist/loader.mjs.map +1 -1
- package/dist/plugin/model-item.d.ts +21 -29
- package/dist/plugin/model-plugin.d.ts +3 -2
- package/dist/runtime/camera.d.ts +7 -6
- package/dist/runtime/light.d.ts +6 -5
- package/dist/runtime/material.d.ts +11 -5
- package/dist/runtime/mesh.d.ts +8 -8
- package/dist/runtime/skybox.d.ts +3 -3
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Description: Galacean Effects player model plugin
|
|
4
4
|
* Author: Ant Group CO., Ltd.
|
|
5
5
|
* Contributors: 飂兮
|
|
6
|
-
* Version: v2.0.0-alpha.
|
|
6
|
+
* Version: v2.0.0-alpha.4
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
@@ -1898,8 +1898,8 @@ var PCamera = /** @class */ (function (_super) {
|
|
|
1898
1898
|
* @param height - 画布高度
|
|
1899
1899
|
* @param owner - 所属的相机组件
|
|
1900
1900
|
*/
|
|
1901
|
-
function PCamera(name, width, height,
|
|
1902
|
-
var _a;
|
|
1901
|
+
function PCamera(name, width, height, data, owner) {
|
|
1902
|
+
var _a, _b, _c, _d, _e;
|
|
1903
1903
|
var _this = _super.call(this) || this;
|
|
1904
1904
|
/**
|
|
1905
1905
|
* 画布宽度
|
|
@@ -1920,7 +1920,7 @@ var PCamera = /** @class */ (function (_super) {
|
|
|
1920
1920
|
/**
|
|
1921
1921
|
* Y 轴上视角
|
|
1922
1922
|
*/
|
|
1923
|
-
_this.
|
|
1923
|
+
_this.fov = 45;
|
|
1924
1924
|
/**
|
|
1925
1925
|
* 纵横比
|
|
1926
1926
|
*/
|
|
@@ -1944,11 +1944,11 @@ var PCamera = /** @class */ (function (_super) {
|
|
|
1944
1944
|
_this.name = name;
|
|
1945
1945
|
_this.width = width;
|
|
1946
1946
|
_this.height = height;
|
|
1947
|
-
_this.nearPlane =
|
|
1948
|
-
_this.farPlane =
|
|
1949
|
-
_this.
|
|
1950
|
-
_this.aspect = (
|
|
1951
|
-
_this.clipMode =
|
|
1947
|
+
_this.nearPlane = (_a = data.near) !== null && _a !== void 0 ? _a : 0.001;
|
|
1948
|
+
_this.farPlane = (_b = data.far) !== null && _b !== void 0 ? _b : 1000;
|
|
1949
|
+
_this.fov = (_c = data.fov) !== null && _c !== void 0 ? _c : 45;
|
|
1950
|
+
_this.aspect = (_d = data.aspect) !== null && _d !== void 0 ? _d : (_this.width / _this.height);
|
|
1951
|
+
_this.clipMode = (_e = data.clipMode) !== null && _e !== void 0 ? _e : effects.spec.CameraClipMode.landscape;
|
|
1952
1952
|
_this.update();
|
|
1953
1953
|
return _this;
|
|
1954
1954
|
}
|
|
@@ -1960,7 +1960,7 @@ var PCamera = /** @class */ (function (_super) {
|
|
|
1960
1960
|
this.transform.fromEffectsTransform(this.owner.transform);
|
|
1961
1961
|
}
|
|
1962
1962
|
var reverse = this.clipMode === effects.spec.CameraClipMode.portrait;
|
|
1963
|
-
this.projectionMatrix.perspective(this.
|
|
1963
|
+
this.projectionMatrix.perspective(this.fov * deg2rad, this.aspect, this.nearPlane, this.farPlane, reverse);
|
|
1964
1964
|
this.viewMatrix = this.matrix.invert();
|
|
1965
1965
|
};
|
|
1966
1966
|
/**
|
|
@@ -1978,7 +1978,7 @@ var PCamera = /** @class */ (function (_super) {
|
|
|
1978
1978
|
* @returns 视角中的包围盒
|
|
1979
1979
|
*/
|
|
1980
1980
|
PCamera.prototype.computeViewAABB = function (box) {
|
|
1981
|
-
var tanTheta = Math.tan(this.
|
|
1981
|
+
var tanTheta = Math.tan(this.fov * deg2rad * 0.5);
|
|
1982
1982
|
var aspect = this.aspect;
|
|
1983
1983
|
var yFarCoord = 0;
|
|
1984
1984
|
var yNearCoord = 0;
|
|
@@ -2048,11 +2048,13 @@ var PCameraManager = /** @class */ (function () {
|
|
|
2048
2048
|
this.winHeight = 512;
|
|
2049
2049
|
this.cameraList = [];
|
|
2050
2050
|
this.defaultCamera = new PCamera('camera', 512, 512, {
|
|
2051
|
+
id: '0',
|
|
2052
|
+
dataType: 'camera',
|
|
2051
2053
|
fov: 60,
|
|
2052
2054
|
far: 1000,
|
|
2053
2055
|
near: 0.001,
|
|
2054
|
-
position: [0, 0, -1.5],
|
|
2055
2056
|
clipMode: effects.spec.CameraClipMode.portrait,
|
|
2057
|
+
item: { id: '0' },
|
|
2056
2058
|
});
|
|
2057
2059
|
}
|
|
2058
2060
|
/**
|
|
@@ -2071,12 +2073,13 @@ var PCameraManager = /** @class */ (function () {
|
|
|
2071
2073
|
};
|
|
2072
2074
|
/**
|
|
2073
2075
|
* 插入相机数据,创建新的相机对象
|
|
2074
|
-
* @param
|
|
2075
|
-
* @param
|
|
2076
|
+
* @param name - 相机名称
|
|
2077
|
+
* @param data - 相机相关数据
|
|
2078
|
+
* @param owner - 相机所属组件
|
|
2076
2079
|
* @returns 新的相机对象
|
|
2077
2080
|
*/
|
|
2078
|
-
PCameraManager.prototype.insert = function (name,
|
|
2079
|
-
var camera = new PCamera(name, this.winWidth, this.winHeight,
|
|
2081
|
+
PCameraManager.prototype.insert = function (name, data, owner) {
|
|
2082
|
+
var camera = new PCamera(name, this.winWidth, this.winHeight, data, owner);
|
|
2080
2083
|
this.cameraList.push(camera);
|
|
2081
2084
|
return camera;
|
|
2082
2085
|
};
|
|
@@ -2123,7 +2126,7 @@ var PCameraManager = /** @class */ (function () {
|
|
|
2123
2126
|
* @param clipMode - 剪裁模式
|
|
2124
2127
|
*/
|
|
2125
2128
|
PCameraManager.prototype.updateDefaultCamera = function (fovy, aspect, nearPlane, farPlane, position, rotation, clipMode) {
|
|
2126
|
-
this.defaultCamera.
|
|
2129
|
+
this.defaultCamera.fov = fovy;
|
|
2127
2130
|
this.defaultCamera.aspect = aspect;
|
|
2128
2131
|
this.defaultCamera.nearPlane = nearPlane;
|
|
2129
2132
|
this.defaultCamera.farPlane = farPlane;
|
|
@@ -2178,10 +2181,12 @@ var PLight = /** @class */ (function (_super) {
|
|
|
2178
2181
|
__extends(PLight, _super);
|
|
2179
2182
|
/**
|
|
2180
2183
|
* 创建灯光对象
|
|
2181
|
-
* @param
|
|
2182
|
-
* @param
|
|
2184
|
+
* @param name - 灯光名称
|
|
2185
|
+
* @param data - 灯光相关数据
|
|
2186
|
+
* @param owner - 所属灯光组件
|
|
2183
2187
|
*/
|
|
2184
|
-
function PLight(name,
|
|
2188
|
+
function PLight(name, data, owner) {
|
|
2189
|
+
var _a, _b, _c, _d;
|
|
2185
2190
|
var _this = _super.call(this) || this;
|
|
2186
2191
|
/**
|
|
2187
2192
|
* 方向,仅用于方向光和聚光灯
|
|
@@ -2221,20 +2226,20 @@ var PLight = /** @class */ (function (_super) {
|
|
|
2221
2226
|
_this.outerConeAngle = 0;
|
|
2222
2227
|
_this.innerConeAngle = 0;
|
|
2223
2228
|
//
|
|
2224
|
-
var
|
|
2225
|
-
_this.color = new Vector3(
|
|
2226
|
-
_this.intensity =
|
|
2227
|
-
if (
|
|
2229
|
+
var color = data.color;
|
|
2230
|
+
_this.color = new Vector3(color.r, color.g, color.b);
|
|
2231
|
+
_this.intensity = data.intensity;
|
|
2232
|
+
if (data.lightType === 'point') {
|
|
2228
2233
|
_this.lightType = exports.PLightType.point;
|
|
2229
|
-
_this.range =
|
|
2234
|
+
_this.range = (_a = data.range) !== null && _a !== void 0 ? _a : -1;
|
|
2230
2235
|
}
|
|
2231
|
-
else if (
|
|
2236
|
+
else if (data.lightType === 'spot') {
|
|
2232
2237
|
_this.lightType = exports.PLightType.spot;
|
|
2233
|
-
_this.range =
|
|
2234
|
-
_this.outerConeAngle =
|
|
2235
|
-
_this.innerConeAngle =
|
|
2238
|
+
_this.range = (_b = data.range) !== null && _b !== void 0 ? _b : -1;
|
|
2239
|
+
_this.outerConeAngle = (_c = data.outerConeAngle) !== null && _c !== void 0 ? _c : Math.PI;
|
|
2240
|
+
_this.innerConeAngle = (_d = data.innerConeAngle) !== null && _d !== void 0 ? _d : 0;
|
|
2236
2241
|
}
|
|
2237
|
-
else if (
|
|
2242
|
+
else if (data.lightType === 'directional') {
|
|
2238
2243
|
_this.lightType = exports.PLightType.directional;
|
|
2239
2244
|
}
|
|
2240
2245
|
else {
|
|
@@ -2550,12 +2555,12 @@ var PMesh = /** @class */ (function (_super) {
|
|
|
2550
2555
|
* 构造函数,创建 Mesh 对象,并与所属组件和父元素相关联
|
|
2551
2556
|
* @param engine - 引擎
|
|
2552
2557
|
* @param name - 名称
|
|
2553
|
-
* @param
|
|
2558
|
+
* @param meshData - Mesh 参数
|
|
2554
2559
|
* @param owner - 所属的 Mesh 组件
|
|
2555
2560
|
* @param parentId - 父元素索引
|
|
2556
2561
|
* @param parent - 父元素
|
|
2557
2562
|
*/
|
|
2558
|
-
function PMesh(engine, name,
|
|
2563
|
+
function PMesh(engine, name, meshData, owner, parentId, parent) {
|
|
2559
2564
|
var _a;
|
|
2560
2565
|
var _this = _super.call(this) || this;
|
|
2561
2566
|
_this.engine = engine;
|
|
@@ -2591,7 +2596,7 @@ var PMesh = /** @class */ (function (_super) {
|
|
|
2591
2596
|
* 是否销毁
|
|
2592
2597
|
*/
|
|
2593
2598
|
_this.isDisposed = false;
|
|
2594
|
-
var proxy = new EffectsMeshProxy(
|
|
2599
|
+
var proxy = new EffectsMeshProxy(meshData, parent);
|
|
2595
2600
|
_this.name = name;
|
|
2596
2601
|
_this.type = exports.PObjectType.mesh;
|
|
2597
2602
|
_this.visible = false;
|
|
@@ -2614,7 +2619,7 @@ var PMesh = /** @class */ (function (_super) {
|
|
|
2614
2619
|
if (_this.primitives.length <= 0) {
|
|
2615
2620
|
console.warn("No primitive inside mesh item ".concat(name));
|
|
2616
2621
|
}
|
|
2617
|
-
_this.boundingBox = _this.getItemBoundingBox(
|
|
2622
|
+
_this.boundingBox = _this.getItemBoundingBox(meshData.interaction);
|
|
2618
2623
|
return _this;
|
|
2619
2624
|
}
|
|
2620
2625
|
/**
|
|
@@ -2884,15 +2889,15 @@ var PPrimitive = /** @class */ (function () {
|
|
|
2884
2889
|
}
|
|
2885
2890
|
/**
|
|
2886
2891
|
* 创建 Primitive 对象
|
|
2887
|
-
* @param
|
|
2892
|
+
* @param data - Primitive 参数
|
|
2888
2893
|
* @param parent - 所属 Mesh 对象
|
|
2889
2894
|
*/
|
|
2890
|
-
PPrimitive.prototype.create = function (
|
|
2895
|
+
PPrimitive.prototype.create = function (data, parent) {
|
|
2891
2896
|
this.parent = parent;
|
|
2892
2897
|
this.skin = parent.skin;
|
|
2893
2898
|
this.morph = parent.morph;
|
|
2894
|
-
this.setGeometry(
|
|
2895
|
-
this.setMaterial(
|
|
2899
|
+
this.setGeometry(data.geometry);
|
|
2900
|
+
this.setMaterial(data.material);
|
|
2896
2901
|
this.name = parent.name;
|
|
2897
2902
|
this.effectsPriority = parent.priority;
|
|
2898
2903
|
this.geometry.setHide(parent.hide);
|
|
@@ -2936,15 +2941,36 @@ var PPrimitive = /** @class */ (function () {
|
|
|
2936
2941
|
//newSemantics["uView"] = 'VIEWINVERSE';
|
|
2937
2942
|
newSemantics['u_ModelMatrix'] = 'MODEL';
|
|
2938
2943
|
newSemantics['uEditorTransform'] = 'EDITOR_TRANSFORM';
|
|
2939
|
-
var material
|
|
2940
|
-
|
|
2944
|
+
var material;
|
|
2945
|
+
var isWebGL2 = PGlobalState.getInstance().isWebGL2;
|
|
2946
|
+
if (this.material.material) {
|
|
2947
|
+
material = this.material.material;
|
|
2948
|
+
// @ts-expect-error
|
|
2949
|
+
material.uniformSemantics = newSemantics;
|
|
2950
|
+
var shader = new effects.Shader(this.engine);
|
|
2951
|
+
shader.fromData({
|
|
2952
|
+
id: '10000000000000000000000000000000',
|
|
2953
|
+
dataType: 'Shader',
|
|
2941
2954
|
vertex: this.material.vertexShaderCode,
|
|
2942
2955
|
fragment: this.material.fragmentShaderCode,
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2956
|
+
// @ts-expect-error
|
|
2957
|
+
glslVersion: isWebGL2 ? effects.GLSLVersion.GLSL3 : effects.GLSLVersion.GLSL1,
|
|
2958
|
+
});
|
|
2959
|
+
// @ts-expect-error
|
|
2960
|
+
material.shader = shader;
|
|
2961
|
+
this.material.setMaterialStates(material);
|
|
2962
|
+
}
|
|
2963
|
+
else {
|
|
2964
|
+
material = effects.Material.create(this.engine, {
|
|
2965
|
+
shader: {
|
|
2966
|
+
vertex: this.material.vertexShaderCode,
|
|
2967
|
+
fragment: this.material.fragmentShaderCode,
|
|
2968
|
+
shared: globalState.shaderShared,
|
|
2969
|
+
glslVersion: isWebGL2 ? effects.GLSLVersion.GLSL3 : effects.GLSLVersion.GLSL1,
|
|
2970
|
+
},
|
|
2971
|
+
uniformSemantics: newSemantics,
|
|
2972
|
+
});
|
|
2973
|
+
}
|
|
2948
2974
|
var mesh = effects.Mesh.create(this.engine, {
|
|
2949
2975
|
name: this.name,
|
|
2950
2976
|
material: material,
|
|
@@ -2955,6 +2981,7 @@ var PPrimitive = /** @class */ (function () {
|
|
|
2955
2981
|
this.effectsMesh.dispose();
|
|
2956
2982
|
}
|
|
2957
2983
|
this.effectsMesh = mesh;
|
|
2984
|
+
this.material.setMaterialStates(material);
|
|
2958
2985
|
};
|
|
2959
2986
|
PPrimitive.prototype.getFeatureList = function (lightCount, pbrPass, skybox) {
|
|
2960
2987
|
var featureList = [];
|
|
@@ -3244,7 +3271,35 @@ var PPrimitive = /** @class */ (function () {
|
|
|
3244
3271
|
this.geometry = val;
|
|
3245
3272
|
}
|
|
3246
3273
|
else {
|
|
3247
|
-
|
|
3274
|
+
// FIXME: 临时兼容代码,后续要解决掉
|
|
3275
|
+
// @ts-expect-error
|
|
3276
|
+
var aNormal = val.attributes['aNormal'];
|
|
3277
|
+
// @ts-expect-error
|
|
3278
|
+
var aPos = val.attributes['aPos'];
|
|
3279
|
+
// @ts-expect-error
|
|
3280
|
+
var aUV = val.attributes['aUV'];
|
|
3281
|
+
if (aNormal && aPos && aUV) {
|
|
3282
|
+
var aNormalData = val.getAttributeData('aNormal');
|
|
3283
|
+
var aPosData = val.getAttributeData('aPos');
|
|
3284
|
+
var aUVData = val.getAttributeData('aUV');
|
|
3285
|
+
var newGeom = effects.Geometry.create(val.engine, {
|
|
3286
|
+
attributes: {
|
|
3287
|
+
a_Position: __assign(__assign({}, aPos), { data: aPosData }),
|
|
3288
|
+
a_UV1: __assign(__assign({}, aUV), { data: aUVData }),
|
|
3289
|
+
a_Normal: __assign(__assign({}, aNormal), { data: aNormalData }),
|
|
3290
|
+
},
|
|
3291
|
+
// @ts-expect-error
|
|
3292
|
+
indices: { data: val.getIndexData() },
|
|
3293
|
+
// @ts-expect-error
|
|
3294
|
+
mode: val.mode,
|
|
3295
|
+
drawStart: val.getDrawStart(),
|
|
3296
|
+
drawCount: val.getDrawCount(),
|
|
3297
|
+
});
|
|
3298
|
+
this.geometry = new PGeometry(newGeom);
|
|
3299
|
+
}
|
|
3300
|
+
else {
|
|
3301
|
+
this.geometry = new PGeometry(val);
|
|
3302
|
+
}
|
|
3248
3303
|
}
|
|
3249
3304
|
};
|
|
3250
3305
|
/**
|
|
@@ -3428,16 +3483,15 @@ var PGeometry = /** @class */ (function () {
|
|
|
3428
3483
|
return PGeometry;
|
|
3429
3484
|
}());
|
|
3430
3485
|
var EffectsMeshProxy = /** @class */ (function () {
|
|
3431
|
-
function EffectsMeshProxy(
|
|
3432
|
-
this.
|
|
3486
|
+
function EffectsMeshProxy(itemData, parentItem) {
|
|
3487
|
+
this.itemData = itemData;
|
|
3433
3488
|
this.parentItem = parentItem;
|
|
3434
|
-
this.
|
|
3489
|
+
this.data = itemData;
|
|
3435
3490
|
// Morph 对象创建,需要为每个 Primitive 中 Geometry 对象创建 Morph
|
|
3436
3491
|
// 并且要求创建的 Morph 对象状态是相同的,否则就报错
|
|
3437
3492
|
var isSuccess = true;
|
|
3438
3493
|
var morphObj = new PMorph();
|
|
3439
|
-
var
|
|
3440
|
-
var primitives = meshOptions.primitives;
|
|
3494
|
+
var _a = this.data, primitives = _a.primitives, morph = _a.morph;
|
|
3441
3495
|
primitives.forEach(function (prim, idx) {
|
|
3442
3496
|
if (idx === 0) {
|
|
3443
3497
|
morphObj.create(prim.geometry);
|
|
@@ -3457,8 +3511,8 @@ var EffectsMeshProxy = /** @class */ (function () {
|
|
|
3457
3511
|
});
|
|
3458
3512
|
if (isSuccess) {
|
|
3459
3513
|
// 设置初始权重数组
|
|
3460
|
-
if (
|
|
3461
|
-
morphObj.initWeights(
|
|
3514
|
+
if ((morph === null || morph === void 0 ? void 0 : morph.weights) !== undefined) {
|
|
3515
|
+
morphObj.initWeights(morph.weights);
|
|
3462
3516
|
}
|
|
3463
3517
|
this.morphObj = morphObj;
|
|
3464
3518
|
}
|
|
@@ -3482,7 +3536,7 @@ var EffectsMeshProxy = /** @class */ (function () {
|
|
|
3482
3536
|
return this.morphObj;
|
|
3483
3537
|
};
|
|
3484
3538
|
EffectsMeshProxy.prototype.isHide = function () {
|
|
3485
|
-
return this.
|
|
3539
|
+
return this.data.hide === true;
|
|
3486
3540
|
};
|
|
3487
3541
|
EffectsMeshProxy.prototype.getParentNode = function () {
|
|
3488
3542
|
var _a;
|
|
@@ -3494,20 +3548,23 @@ var EffectsMeshProxy = /** @class */ (function () {
|
|
|
3494
3548
|
return undefined;
|
|
3495
3549
|
};
|
|
3496
3550
|
EffectsMeshProxy.prototype.getParentIndex = function () {
|
|
3497
|
-
|
|
3498
|
-
return (_a = this.options.parent) !== null && _a !== void 0 ? _a : -1;
|
|
3551
|
+
return -1;
|
|
3499
3552
|
};
|
|
3500
3553
|
EffectsMeshProxy.prototype.getPrimitives = function () {
|
|
3501
|
-
return this.
|
|
3554
|
+
return this.data.primitives;
|
|
3502
3555
|
};
|
|
3503
3556
|
EffectsMeshProxy.prototype.getPrimitiveCount = function () {
|
|
3504
|
-
return this.
|
|
3557
|
+
return this.data.primitives.length;
|
|
3505
3558
|
};
|
|
3506
3559
|
EffectsMeshProxy.prototype.hasSkin = function () {
|
|
3507
|
-
|
|
3560
|
+
// FIXME: skin
|
|
3561
|
+
//return this.options.skin !== undefined;
|
|
3562
|
+
return false;
|
|
3508
3563
|
};
|
|
3509
3564
|
EffectsMeshProxy.prototype.getSkinOpts = function () {
|
|
3510
|
-
|
|
3565
|
+
// FIXME: skin
|
|
3566
|
+
//return this.options.skin;
|
|
3567
|
+
return;
|
|
3511
3568
|
};
|
|
3512
3569
|
EffectsMeshProxy.prototype.getSkinObj = function (engine) {
|
|
3513
3570
|
var skin = this.getSkinOpts();
|
|
@@ -3924,7 +3981,7 @@ var PSceneManager = /** @class */ (function () {
|
|
|
3924
3981
|
|
|
3925
3982
|
var primitiveVert = "precision highp float;\n#define FEATURES\n#include <webglCompatibility.glsl>\n#include <animation.vert.glsl>\nvsIn vec4 a_Position;vsOut vec3 v_Position;\n#ifdef HAS_NORMALS\nvsIn vec4 a_Normal;\n#endif\n#ifdef HAS_TANGENTS\nvsIn vec4 a_Tangent;\n#endif\n#ifdef HAS_NORMALS\n#ifdef HAS_TANGENTS\nvsOut mat3 v_TBN;\n#else\nvsOut vec3 v_Normal;\n#endif\n#endif\n#ifdef HAS_UV_SET1\nvsIn vec2 a_UV1;\n#endif\n#ifdef HAS_UV_SET2\nvsIn vec2 a_UV2;\n#endif\nvsOut vec2 v_UVCoord1;\n#ifdef HAS_UV_SET2\nvsOut vec2 v_UVCoord2;\n#endif\n#ifdef HAS_VERTEX_COLOR_VEC3\nvsIn vec3 a_Color;vsOut vec3 v_Color;\n#endif\n#ifdef HAS_VERTEX_COLOR_VEC4\nvsIn vec4 a_Color;vsOut vec4 v_Color;\n#endif\nuniform mat4 u_ViewProjectionMatrix;uniform mat4 u_ModelMatrix;uniform mat4 u_NormalMatrix;\n#ifdef EDITOR_TRANSFORM\nuniform vec4 uEditorTransform;\n#endif\n#ifdef USE_SHADOW_MAPPING\nuniform mat4 u_LightViewProjectionMatrix;uniform float u_DeltaSceneSize;vsOut vec4 v_PositionLightSpace;vsOut vec4 v_dPositionLightSpace;\n#endif\nvec4 getPosition(){vec4 pos=vec4(a_Position.xyz,1.0);\n#ifdef USE_MORPHING\npos+=getTargetPosition();\n#endif\n#ifdef USE_SKINNING\npos=getSkinningMatrix()*pos;\n#endif\nreturn pos;}\n#ifdef HAS_NORMALS\nvec4 getNormal(){vec4 normal=a_Normal;\n#ifdef USE_MORPHING\nnormal+=getTargetNormal();\n#endif\n#ifdef USE_SKINNING\nnormal=getSkinningNormalMatrix()*normal;\n#endif\nreturn normalize(normal);}\n#endif\n#ifdef HAS_TANGENTS\nvec4 getTangent(){vec4 tangent=a_Tangent;\n#ifdef USE_MORPHING\ntangent+=getTargetTangent();\n#endif\n#ifdef USE_SKINNING\ntangent=getSkinningMatrix()*tangent;\n#endif\nreturn normalize(tangent);}\n#endif\nvoid main(){vec4 pos=u_ModelMatrix*getPosition();v_Position=vec3(pos.xyz)/pos.w;\n#ifdef HAS_NORMALS\n#ifdef HAS_TANGENTS\nvec4 tangent=getTangent();vec3 normalW=normalize(vec3(u_NormalMatrix*vec4(getNormal().xyz,0.0)));vec3 tangentW=normalize(vec3(u_ModelMatrix*vec4(tangent.xyz,0.0)));vec3 bitangentW=cross(normalW,tangentW)*tangent.w;v_TBN=mat3(tangentW,bitangentW,normalW);\n#else\nv_Normal=normalize(vec3(u_NormalMatrix*vec4(getNormal().xyz,0.0)));\n#endif\n#endif\nv_UVCoord1=vec2(0.0,0.0);\n#ifdef HAS_UV_SET1\nv_UVCoord1=a_UV1;\n#endif\n#ifdef HAS_UV_SET2\nv_UVCoord2=a_UV2;\n#endif\n#if defined(HAS_VERTEX_COLOR_VEC3) || defined(HAS_VERTEX_COLOR_VEC4)\nv_Color=a_Color;\n#endif\n#ifdef USE_SHADOW_MAPPING\nv_PositionLightSpace=u_LightViewProjectionMatrix*pos;vec3 dpos=vec3(u_DeltaSceneSize);v_dPositionLightSpace=u_LightViewProjectionMatrix*(pos+vec4(dpos,0));\n#endif\ngl_Position=u_ViewProjectionMatrix*pos;\n#ifdef EDITOR_TRANSFORM\ngl_Position=vec4(gl_Position.xy*uEditorTransform.xy+uEditorTransform.zw*gl_Position.w,gl_Position.zw);\n#endif\n}";
|
|
3926
3983
|
|
|
3927
|
-
var metallicRoughnessFrag = "\n#define FEATURES\n#ifndef WEBGL2\n#extension GL_OES_standard_derivatives : enable\n#endif\n#if !defined(WEBGL2) && defined(USE_TEX_LOD)\n#extension GL_EXT_shader_texture_lod : enable\n#endif\n#ifdef USE_HDR\n#extension GL_OES_texture_float : enable\n#extension GL_OES_texture_float_linear : enable\n#endif\n#if !defined(WEBGL2) && defined(USE_WBOIT)\n#extension GL_EXT_draw_buffers: require\n#endif\n#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n#ifdef WEBGL2\n#ifdef USE_WBOIT\nlayout(location=0)out vec4 outFragColor0;layout(location=1)out vec4 outFragColor1;\n#else\nout vec4 outFragColor;\n#endif\n#else\n#ifdef USE_WBOIT\n#define outFragColor0 gl_FragData[0]\n#define outFragColor1 gl_FragData[1]\n#else\n#define outFragColor gl_FragColor\n#endif\n#endif\n#include <webglCompatibility.glsl>\n#include <extensions.frag.glsl>\n#include <tonemapping.frag.glsl>\n#include <textures.vert.glsl>\n#include <functions.frag.glsl>\n#include <shadowCommon.vert.glsl>\n#include <shadow.frag.glsl>\nstruct Light{vec3 direction;float range;vec3 color;float intensity;vec3 position;float innerConeCos;float outerConeCos;int type;vec2 padding;};const int LightType_Directional=0;const int LightType_Point=1;const int LightType_Spot=2;const int LightType_Ambient=3;\n#ifdef USE_PUNCTUAL\nuniform Light u_Lights[LIGHT_COUNT];\n#endif\n#if defined(MATERIAL_SPECULARGLOSSINESS) || defined(MATERIAL_METALLICROUGHNESS)\nuniform float u_MetallicFactor;uniform float u_RoughnessFactor;uniform vec4 u_BaseColorFactor;\n#endif\n#ifdef MATERIAL_SPECULARGLOSSINESS\nuniform vec3 u_SpecularFactor;uniform vec4 u_DiffuseFactor;uniform float u_GlossinessFactor;\n#endif\n#ifdef ALPHAMODE_MASK\nuniform float u_AlphaCutoff;\n#endif\n#ifdef ADD_FOG\nuniform vec4 u_FogColor;\n#ifdef LINEAR_FOG\nuniform float u_FogNear;uniform float u_FogFar;\n#endif\n#ifdef EXP_FOG\nuniform float u_FogDensity;\n#endif\n#endif\n#ifdef PREVIEW_BORDER\nuniform vec4 uPreviewColor;\n#endif\nuniform vec3 u_Camera;uniform int u_MipCount;struct MaterialInfo{float perceptualRoughness;vec3 reflectance0;float alphaRoughness;vec3 diffuseColor;vec3 reflectance90;vec3 specularColor;};\n#ifdef ADD_FOG\nvec3 getMixFogColor(vec3 baseColor){vec3 distance=u_Camera-v_Position;float fogAmount=0.0;\n#ifdef LINEAR_FOG\nfogAmount=smoothstep(u_FogNear,u_FogFar,distance[2]);\n#endif\n#ifdef EXP_FOG\n#define LOG2 1.442695\nfogAmount=1.-exp2(-u_FogDensity*u_FogDensity*distance[2]*distance[2]*LOG2);fogAmount=clamp(fogAmount,0.,1.);\n#endif\nvec3 mixColor=baseColor.rgb+(vec3(u_FogColor)-baseColor.rgb)*fogAmount;return mixColor;}\n#endif\n#ifdef IRRADIANCE_COEFFICIENTS\nvec3 getIrradiance(vec3 norm,SHCoefficients c){float x=norm.x;float y=norm.y;float z=norm.z;float c1=0.429043;float c2=0.511664;float c3=0.743125;float c4=0.886227;float c5=0.247708;vec3 irradiance=c1*c.l22*(x*x-y*y)+c3*c.l20*(z*z)+c4*c.l00-c5*c.l20+2.0*c1*(c.l2m2*x*y+c.l21*x*z+c.l2m1*y*z)+2.0*c2*(c.l11*x+c.l1m1*y+c.l10*z);return irradiance;}\n#endif\n#ifdef USE_IBL\nvec3 getIBLContribution(MaterialInfo materialInfo,vec3 n,vec3 v){float NdotV=clamp(dot(n,v),0.0,1.0);float lod=clamp(materialInfo.perceptualRoughness*float(u_MipCount),0.0,float(u_MipCount));vec3 reflection=normalize(reflect(-v,n));vec2 brdfSamplePoint=clamp(vec2(NdotV,materialInfo.perceptualRoughness),vec2(0.0,0.0),vec2(1.0,1.0));vec2 brdf=texture2D(u_brdfLUT,brdfSamplePoint).rg;vec4 diffuseColor=vec4(1.0,0.0,0.0,1.0);\n#ifdef IRRADIANCE_COEFFICIENTS\nvec3 irradiance=getIrradiance(n,u_shCoefficients);diffuseColor=vec4(irradiance,1.0);\n#else\ndiffuseColor=textureCube(u_DiffuseEnvSampler,n);\n#endif\n#ifdef USE_TEX_LOD\nvec4 specularSample=_textureCubeLodEXT(u_SpecularEnvSampler,reflection,lod);\n#else\nvec4 specularSample=textureCube(u_SpecularEnvSampler,reflection,lod);\n#endif\n#ifdef USE_HDR\nvec3 diffuseLight=diffuseColor.rgb;vec3 specularLight=specularSample.rgb;\n#else\nvec3 diffuseLight=SRGBtoLINEAR(diffuseColor).rgb;vec3 specularLight=SRGBtoLINEAR(specularSample).rgb;\n#endif\nvec3 diffuse=diffuseLight*materialInfo.diffuseColor;vec3 specular=specularLight*(materialInfo.specularColor*brdf.x+brdf.y);return diffuse*u_IblIntensity[0]+specular*u_IblIntensity[1];}\n#endif\nvec3 diffuse(MaterialInfo materialInfo){return materialInfo.diffuseColor/M_PI;}vec3 specularReflection(MaterialInfo materialInfo,AngularInfo angularInfo){return materialInfo.reflectance0+(materialInfo.reflectance90-materialInfo.reflectance0)*pow(clamp(1.0-angularInfo.VdotH,0.0,1.0),5.0);}float visibilityOcclusion(MaterialInfo materialInfo,AngularInfo angularInfo){float NdotL=angularInfo.NdotL;float NdotV=angularInfo.NdotV;float alphaRoughnessSq=materialInfo.alphaRoughness*materialInfo.alphaRoughness;float GGXV=NdotL*sqrt(NdotV*NdotV*(1.0-alphaRoughnessSq)+alphaRoughnessSq);float GGXL=NdotV*sqrt(NdotL*NdotL*(1.0-alphaRoughnessSq)+alphaRoughnessSq);float GGX=GGXV+GGXL;if(GGX>0.0){return 0.5/GGX;}return 0.0;}float microfacetDistribution(MaterialInfo materialInfo,AngularInfo angularInfo){float alphaRoughnessSq=materialInfo.alphaRoughness*materialInfo.alphaRoughness;float f=(angularInfo.NdotH*alphaRoughnessSq-angularInfo.NdotH)*angularInfo.NdotH+1.0;return alphaRoughnessSq/(M_PI*f*f);}vec3 getPointShade(vec3 pointToLight,MaterialInfo materialInfo,vec3 normal,vec3 view){AngularInfo angularInfo=getAngularInfo(pointToLight,normal,view);if(angularInfo.NdotL>0.0||angularInfo.NdotV>0.0){vec3 F=specularReflection(materialInfo,angularInfo);float Vis=visibilityOcclusion(materialInfo,angularInfo);float D=microfacetDistribution(materialInfo,angularInfo);vec3 diffuseContrib=(1.0-F)*diffuse(materialInfo);vec3 specContrib=F*Vis*D;return angularInfo.NdotL*(diffuseContrib+specContrib);}return vec3(0.0,0.0,0.0);}float getRangeAttenuation(float range,float distance){if(range<=0.0){return 1.0;}return 1.0/(pow(5.0*distance/range,2.0)+1.0);}float getSpotAttenuation(vec3 pointToLight,vec3 spotDirection,float outerConeCos,float innerConeCos){float actualCos=dot(normalize(spotDirection),normalize(-pointToLight));if(actualCos>outerConeCos){if(actualCos<innerConeCos){return smoothstep(outerConeCos,innerConeCos,actualCos);}return 1.0;}return 0.0;}vec3 applyDirectionalLight(Light light,MaterialInfo materialInfo,vec3 normal,vec3 view,float shadow){vec3 pointToLight=-light.direction;vec3 shade=getPointShade(pointToLight,materialInfo,normal,view)*shadow;return light.intensity*light.color*shade;}vec3 applyPointLight(Light light,MaterialInfo materialInfo,vec3 normal,vec3 view){vec3 pointToLight=light.position-v_Position;float distance=length(pointToLight);float attenuation=getRangeAttenuation(light.range,distance);vec3 shade=getPointShade(pointToLight,materialInfo,normal,view);return light.color*shade*attenuation*light.intensity;}vec3 applySpotLight(Light light,MaterialInfo materialInfo,vec3 normal,vec3 view,float shadow){vec3 pointToLight=light.position-v_Position;float distance=length(pointToLight);float rangeAttenuation=getRangeAttenuation(light.range,distance);float spotAttenuation=getSpotAttenuation(pointToLight,light.direction,light.outerConeCos,light.innerConeCos);vec3 shade=getPointShade(pointToLight,materialInfo,normal,view)*shadow;return rangeAttenuation*spotAttenuation*light.intensity*light.color*shade;}vec3 applyAmbientLight(Light light,MaterialInfo materialInfo){return light.intensity*light.color*diffuse(materialInfo);}float weight(float z,float a){return clamp(pow(min(1.0,a*10.0)+0.01,3.0)*1e8*pow(1.0-z*0.9,3.0),1e-2,3e3);}void writeFragmentColor(vec4 fragColor){\n#if !defined(ALPHAMODE_OPAQUE) && defined(USE_WBOIT)\nfloat w=weight(gl_FragCoord.z,fragColor.a);fragColor.rgb*=fragColor.a;outFragColor0=vec4(fragColor.rgb*w,fragColor.a);outFragColor1=vec4(fragColor.a*w);\n#else\noutFragColor=fragColor;\n#endif\n}void main(){float perceptualRoughness=0.0;float metallic=0.0;vec4 baseColor=vec4(0.0,0.0,0.0,1.0);vec3 diffuseColor=vec3(0.0);vec3 specularColor=vec3(0.0);vec3 f0=vec3(0.04);\n#ifdef PREVIEW_BORDER\nwriteFragmentColor(uPreviewColor);return;\n#endif\n#ifdef MATERIAL_SPECULARGLOSSINESS\n#ifdef HAS_SPECULAR_GLOSSINESS_MAP\nvec4 sgSample=SRGBtoLINEAR(texture2D(u_SpecularGlossinessSampler,getSpecularGlossinessUV()));perceptualRoughness=(1.0-sgSample.a*u_GlossinessFactor);f0=sgSample.rgb*u_SpecularFactor;\n#else\nf0=u_SpecularFactor;perceptualRoughness=1.0-u_GlossinessFactor;\n#endif\n#ifdef HAS_DIFFUSE_MAP\nbaseColor=SRGBtoLINEAR(texture2D(u_DiffuseSampler,getDiffuseUV()))*u_DiffuseFactor;\n#else\nbaseColor=SRGBtoLINEAR(u_DiffuseFactor);\n#endif\nbaseColor*=getVertexColor();specularColor=f0;float oneMinusSpecularStrength=1.0-max(max(f0.r,f0.g),f0.b);diffuseColor=baseColor.rgb*oneMinusSpecularStrength;\n#ifdef DEBUG_METALLIC\nmetallic=solveMetallic(baseColor.rgb,specularColor,oneMinusSpecularStrength);\n#endif\n#endif\n#ifdef MATERIAL_METALLICROUGHNESS\n#ifdef HAS_METALLIC_ROUGHNESS_MAP\nvec4 mrSample=texture2D(u_MetallicRoughnessSampler,getMetallicRoughnessUV());perceptualRoughness=mrSample.g*u_RoughnessFactor;metallic=mrSample.b*u_MetallicFactor;\n#else\nmetallic=u_MetallicFactor;perceptualRoughness=u_RoughnessFactor;\n#endif\n#ifdef HAS_BASE_COLOR_MAP\nbaseColor=SRGBtoLINEAR(texture2D(u_BaseColorSampler,getBaseColorUV()))*u_BaseColorFactor;\n#else\nbaseColor=SRGBtoLINEAR(u_BaseColorFactor);\n#endif\nbaseColor*=getVertexColor();diffuseColor=baseColor.rgb*(vec3(1.0)-f0)*(1.0-metallic);specularColor=mix(f0,baseColor.rgb,metallic);\n#endif\n#ifdef ALPHAMODE_MASK\nif(baseColor.a<u_AlphaCutoff){discard;}baseColor.a=1.0;\n#endif\n#ifdef ALPHAMODE_OPAQUE\nbaseColor.a=1.0;\n#endif\n#ifdef MATERIAL_UNLIT\n#ifndef DEBUG_OUTPUT\n#ifdef ADD_FOG\nvec3 mixColor=getMixFogColor(baseColor.rgb);vec4 fragColorUnlit=vec4(LINEARtoSRGB(mixColor)*baseColor.a,baseColor.a);\n#else\nvec4 fragColorUnlit=vec4(LINEARtoSRGB(baseColor.rgb)*baseColor.a,baseColor.a);\n#endif\nwriteFragmentColor(fragColorUnlit);\n#else\n#ifdef DEBUG_UV\noutFragColor.rgb=vec3(getDebugUVColor(getBaseColorUV(),getNormal()));\n#endif\n#ifdef DEBUG_METALLIC\noutFragColor.rgb=vec3(metallic);\n#endif\n#ifdef DEBUG_ROUGHNESS\noutFragColor.rgb=vec3(perceptualRoughness);\n#endif\n#ifdef DEBUG_NORMAL\noutFragColor.rgb=getNormal()*0.5+0.5;\n#endif\n#ifdef DEBUG_BASECOLOR\noutFragColor.rgb=LINEARtoSRGB(baseColor.rgb);\n#endif\n#ifdef DEBUG_OCCLUSION\noutFragColor.rgb=vec3(1.0);\n#endif\n#ifdef DEBUG_EMISSIVE\noutFragColor.rgb=vec3(0.0);\n#endif\n#ifdef DEBUG_ALPHA\noutFragColor.rgb=vec3(baseColor.a);\n#endif\noutFragColor.a=1.0;\n#endif\nreturn;\n#endif\nmetallic=clamp(metallic,0.0,1.0);float alphaRoughness=perceptualRoughness*perceptualRoughness;vec3 normal=getNormal();\n#ifdef USE_SPECULAR_AA\nfloat AARoughnessFactor=getAARoughnessFactor(normal);perceptualRoughness+=AARoughnessFactor;alphaRoughness+=AARoughnessFactor;\n#endif\nperceptualRoughness=clamp(perceptualRoughness,0.04,1.0);alphaRoughness=clamp(alphaRoughness,0.04,1.0);float reflectance=max(max(specularColor.r,specularColor.g),specularColor.b);vec3 specularEnvironmentR0=specularColor.rgb;vec3 specularEnvironmentR90=vec3(clamp(reflectance*50.0,0.0,1.0));MaterialInfo materialInfo=MaterialInfo(perceptualRoughness,specularEnvironmentR0,alphaRoughness,diffuseColor,specularEnvironmentR90,specularColor);vec3 color=vec3(0.0,0.0,0.0);vec3 view=normalize(u_Camera-v_Position);float shadow=1.0;\n#ifdef USE_SHADOW_MAPPING\nshadow=getShadowContribution();\n#endif\n#ifdef USE_PUNCTUAL\nfor(int i=0;i<LIGHT_COUNT;++i){Light light=u_Lights[i];if(light.type==LightType_Directional){color+=applyDirectionalLight(light,materialInfo,normal,view,shadow);}else if(light.type==LightType_Point){color+=applyPointLight(light,materialInfo,normal,view);}else if(light.type==LightType_Spot){color+=applySpotLight(light,materialInfo,normal,view,shadow);}else if(light.type==LightType_Ambient){color+=applyAmbientLight(light,materialInfo);}}\n#endif\n#ifdef USE_IBL\ncolor+=getIBLContribution(materialInfo,normal,view);\n#endif\nfloat ao=1.0;\n#ifdef HAS_OCCLUSION_MAP\nao=texture2D(u_OcclusionSampler,getOcclusionUV()).r;color=mix(color,color*ao,u_OcclusionStrength);\n#endif\nvec3 emissive=vec3(0);\n#ifndef DEBUG_OUTPUT\n#ifdef ADD_FOG\nvec4 toneMapColor=SRGBtoLINEAR(vec4(toneMap(color),baseColor.a));color=getMixFogColor(toneMapColor.rgb);vec4 fragColorOut=vec4(LINEARtoSRGB(color.rgb)*baseColor.a,baseColor.a);\n#else\ncolor=toneMap(color)*baseColor.a;\n#ifdef HAS_EMISSIVE\ncolor+=u_EmissiveFactor;\n#endif\n#ifdef HAS_EMISSIVE_MAP\nemissive=SRGBtoLINEAR(texture2D(u_EmissiveSampler,getEmissiveUV())).rgb*u_EmissiveFactor;color+=emissive;\n#endif\nvec4 fragColorOut=vec4(color,baseColor.a);\n#endif\nwriteFragmentColor(fragColorOut);\n#else\n#ifdef DEBUG_UV\noutFragColor.rgb=vec3(getDebugUVColor(getBaseColorUV(),normal));\n#endif\n#ifdef DEBUG_METALLIC\noutFragColor.rgb=vec3(metallic);\n#endif\n#ifdef DEBUG_ROUGHNESS\noutFragColor.rgb=vec3(perceptualRoughness);\n#endif\n#ifdef DEBUG_NORMAL\noutFragColor.rgb=normal*0.5+0.5;\n#endif\n#ifdef DEBUG_BASECOLOR\noutFragColor.rgb=LINEARtoSRGB(baseColor.rgb);\n#endif\n#ifdef DEBUG_OCCLUSION\n#ifdef HAS_OCCLUSION_MAP\noutFragColor.rgb=vec3(mix(1.0,ao,u_OcclusionStrength));\n#else\noutFragColor.rgb=vec3(1.0);\n#endif\n#endif\n#ifdef DEBUG_EMISSIVE\n#ifdef HAS_EMISSIVE\nemissive=u_EmissiveFactor;\n#endif\n#ifdef HAS_EMISSIVE_MAP\nemissive=SRGBtoLINEAR(texture2D(u_EmissiveSampler,getEmissiveUV())).rgb*u_EmissiveFactor;\n#endif\noutFragColor.rgb=LINEARtoSRGB(emissive);\n#endif\n#ifdef DEBUG_F0\noutFragColor.rgb=vec3(f0);\n#endif\n#ifdef DEBUG_ALPHA\noutFragColor.rgb=vec3(baseColor.a);\n#endif\noutFragColor.a=1.0;\n#endif\n}";
|
|
3984
|
+
var metallicRoughnessFrag = "\n#define FEATURES\n#ifndef WEBGL2\n#extension GL_OES_standard_derivatives : enable\n#endif\n#if !defined(WEBGL2) && defined(USE_TEX_LOD)\n#extension GL_EXT_shader_texture_lod : enable\n#endif\n#ifdef USE_HDR\n#extension GL_OES_texture_float : enable\n#extension GL_OES_texture_float_linear : enable\n#endif\n#if !defined(WEBGL2) && defined(USE_WBOIT)\n#extension GL_EXT_draw_buffers: require\n#endif\n#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n#ifdef WEBGL2\n#ifdef USE_WBOIT\nlayout(location=0)out vec4 outFragColor0;layout(location=1)out vec4 outFragColor1;\n#else\nout vec4 outFragColor;\n#endif\n#else\n#ifdef USE_WBOIT\n#define outFragColor0 gl_FragData[0]\n#define outFragColor1 gl_FragData[1]\n#else\n#define outFragColor gl_FragColor\n#endif\n#endif\n#include <webglCompatibility.glsl>\n#include <extensions.frag.glsl>\n#include <tonemapping.frag.glsl>\n#include <textures.vert.glsl>\n#include <functions.frag.glsl>\n#include <shadowCommon.vert.glsl>\n#include <shadow.frag.glsl>\nstruct Light{vec3 direction;float range;vec3 color;float intensity;vec3 position;float innerConeCos;float outerConeCos;int type;vec2 padding;};const int LightType_Directional=0;const int LightType_Point=1;const int LightType_Spot=2;const int LightType_Ambient=3;\n#ifdef USE_PUNCTUAL\nuniform Light u_Lights[LIGHT_COUNT];\n#endif\n#if defined(MATERIAL_SPECULARGLOSSINESS) || defined(MATERIAL_METALLICROUGHNESS)\nuniform float u_MetallicFactor;uniform float u_RoughnessFactor;uniform vec4 u_BaseColorFactor;\n#endif\n#ifdef MATERIAL_SPECULARGLOSSINESS\nuniform vec3 u_SpecularFactor;uniform vec4 u_DiffuseFactor;uniform float u_GlossinessFactor;\n#endif\n#ifdef ALPHAMODE_MASK\nuniform float u_AlphaCutoff;\n#endif\n#ifdef ADD_FOG\nuniform vec4 u_FogColor;\n#ifdef LINEAR_FOG\nuniform float u_FogNear;uniform float u_FogFar;\n#endif\n#ifdef EXP_FOG\nuniform float u_FogDensity;\n#endif\n#endif\n#ifdef PREVIEW_BORDER\nuniform vec4 uPreviewColor;\n#endif\nuniform vec3 u_Camera;uniform int u_MipCount;struct MaterialInfo{float perceptualRoughness;vec3 reflectance0;float alphaRoughness;vec3 diffuseColor;vec3 reflectance90;vec3 specularColor;};\n#ifdef ADD_FOG\nvec3 getMixFogColor(vec3 baseColor){vec3 distance=u_Camera-v_Position;float fogAmount=0.0;\n#ifdef LINEAR_FOG\nfogAmount=smoothstep(u_FogNear,u_FogFar,distance[2]);\n#endif\n#ifdef EXP_FOG\n#define LOG2 1.442695\nfogAmount=1.-exp2(-u_FogDensity*u_FogDensity*distance[2]*distance[2]*LOG2);fogAmount=clamp(fogAmount,0.,1.);\n#endif\nvec3 mixColor=baseColor.rgb+(vec3(u_FogColor)-baseColor.rgb)*fogAmount;return mixColor;}\n#endif\n#ifdef IRRADIANCE_COEFFICIENTS\nvec3 getIrradiance(vec3 norm,SHCoefficients c){float x=norm.x;float y=norm.y;float z=norm.z;float c1=0.429043;float c2=0.511664;float c3=0.743125;float c4=0.886227;float c5=0.247708;vec3 irradiance=c1*c.l22*(x*x-y*y)+c3*c.l20*(z*z)+c4*c.l00-c5*c.l20+2.0*c1*(c.l2m2*x*y+c.l21*x*z+c.l2m1*y*z)+2.0*c2*(c.l11*x+c.l1m1*y+c.l10*z);return irradiance;}\n#endif\n#ifdef USE_IBL\nvec3 getIBLContribution(MaterialInfo materialInfo,vec3 n,vec3 v){float NdotV=clamp(dot(n,v),0.0,1.0);float lod=clamp(materialInfo.perceptualRoughness*float(u_MipCount),0.0,float(u_MipCount));vec3 reflection=normalize(reflect(-v,n));vec2 brdfSamplePoint=clamp(vec2(NdotV,materialInfo.perceptualRoughness),vec2(0.0,0.0),vec2(1.0,1.0));vec2 brdf=texture2D(u_brdfLUT,brdfSamplePoint).rg;vec4 diffuseColor=vec4(1.0,0.0,0.0,1.0);\n#ifdef IRRADIANCE_COEFFICIENTS\nvec3 irradiance=getIrradiance(n,u_shCoefficients);diffuseColor=vec4(irradiance,1.0);\n#else\ndiffuseColor=textureCube(u_DiffuseEnvSampler,n);\n#endif\n#ifdef USE_TEX_LOD\nvec4 specularSample=_textureCubeLodEXT(u_SpecularEnvSampler,reflection,lod);\n#else\nvec4 specularSample=textureCube(u_SpecularEnvSampler,reflection,lod);\n#endif\n#ifdef USE_HDR\nvec3 diffuseLight=diffuseColor.rgb;vec3 specularLight=specularSample.rgb;\n#else\nvec3 diffuseLight=SRGBtoLINEAR(diffuseColor).rgb;vec3 specularLight=SRGBtoLINEAR(specularSample).rgb;\n#endif\nvec3 diffuse=diffuseLight*materialInfo.diffuseColor;vec3 specular=specularLight*(materialInfo.specularColor*brdf.x+brdf.y);return diffuse*u_IblIntensity[0]+specular*u_IblIntensity[1];}\n#endif\nvec3 diffuse(MaterialInfo materialInfo){return materialInfo.diffuseColor/M_PI;}vec3 specularReflection(MaterialInfo materialInfo,AngularInfo angularInfo){return materialInfo.reflectance0+(materialInfo.reflectance90-materialInfo.reflectance0)*pow(clamp(1.0-angularInfo.VdotH,0.0,1.0),5.0);}float visibilityOcclusion(MaterialInfo materialInfo,AngularInfo angularInfo){float NdotL=angularInfo.NdotL;float NdotV=angularInfo.NdotV;float alphaRoughnessSq=materialInfo.alphaRoughness*materialInfo.alphaRoughness;float GGXV=NdotL*sqrt(NdotV*NdotV*(1.0-alphaRoughnessSq)+alphaRoughnessSq);float GGXL=NdotV*sqrt(NdotL*NdotL*(1.0-alphaRoughnessSq)+alphaRoughnessSq);float GGX=GGXV+GGXL;if(GGX>0.0){return 0.5/GGX;}return 0.0;}float microfacetDistribution(MaterialInfo materialInfo,AngularInfo angularInfo){float alphaRoughnessSq=materialInfo.alphaRoughness*materialInfo.alphaRoughness;float f=(angularInfo.NdotH*alphaRoughnessSq-angularInfo.NdotH)*angularInfo.NdotH+1.0;return alphaRoughnessSq/(M_PI*f*f);}vec3 getPointShade(vec3 pointToLight,MaterialInfo materialInfo,vec3 normal,vec3 view){AngularInfo angularInfo=getAngularInfo(pointToLight,normal,view);if(angularInfo.NdotL>0.0||angularInfo.NdotV>0.0){vec3 F=specularReflection(materialInfo,angularInfo);float Vis=visibilityOcclusion(materialInfo,angularInfo);float D=microfacetDistribution(materialInfo,angularInfo);vec3 diffuseContrib=(1.0-F)*diffuse(materialInfo);vec3 specContrib=F*Vis*D;return angularInfo.NdotL*(diffuseContrib+specContrib);}return vec3(0.0,0.0,0.0);}float getRangeAttenuation(float range,float distance){if(range<=0.0){return 1.0;}return 1.0/(pow(5.0*distance/range,2.0)+1.0);}float getSpotAttenuation(vec3 pointToLight,vec3 spotDirection,float outerConeCos,float innerConeCos){float actualCos=dot(normalize(spotDirection),normalize(-pointToLight));if(actualCos>outerConeCos){if(actualCos<innerConeCos){return smoothstep(outerConeCos,innerConeCos,actualCos);}return 1.0;}return 0.0;}vec3 applyDirectionalLight(Light light,MaterialInfo materialInfo,vec3 normal,vec3 view,float shadow){vec3 pointToLight=-light.direction;vec3 shade=getPointShade(pointToLight,materialInfo,normal,view)*shadow;return light.intensity*light.color*shade;}vec3 applyPointLight(Light light,MaterialInfo materialInfo,vec3 normal,vec3 view){vec3 pointToLight=light.position-v_Position;float distance=length(pointToLight);float attenuation=getRangeAttenuation(light.range,distance);vec3 shade=getPointShade(pointToLight,materialInfo,normal,view);return light.color*shade*attenuation*light.intensity;}vec3 applySpotLight(Light light,MaterialInfo materialInfo,vec3 normal,vec3 view,float shadow){vec3 pointToLight=light.position-v_Position;float distance=length(pointToLight);float rangeAttenuation=getRangeAttenuation(light.range,distance);float spotAttenuation=getSpotAttenuation(pointToLight,light.direction,light.outerConeCos,light.innerConeCos);vec3 shade=getPointShade(pointToLight,materialInfo,normal,view)*shadow;return rangeAttenuation*spotAttenuation*light.intensity*light.color*shade;}vec3 applyAmbientLight(Light light,MaterialInfo materialInfo){return light.intensity*light.color*diffuse(materialInfo);}float weight(float z,float a){return clamp(pow(min(1.0,a*10.0)+0.01,3.0)*1e8*pow(1.0-z*0.9,3.0),1e-2,3e3);}void writeFragmentColor(vec4 fragColor){\n#if !defined(ALPHAMODE_OPAQUE) && defined(USE_WBOIT)\nfloat w=weight(gl_FragCoord.z,fragColor.a);fragColor.rgb*=fragColor.a;outFragColor0=vec4(fragColor.rgb*w,fragColor.a);outFragColor1=vec4(fragColor.a*w);\n#else\noutFragColor=fragColor;\n#endif\n}void main(){float perceptualRoughness=0.0;float metallic=0.0;vec4 baseColor=vec4(0.0,0.0,0.0,1.0);vec3 diffuseColor=vec3(0.0);vec3 specularColor=vec3(0.0);vec3 f0=vec3(0.04);\n#ifdef PREVIEW_BORDER\nwriteFragmentColor(uPreviewColor);return;\n#endif\n#ifdef MATERIAL_SPECULARGLOSSINESS\n#ifdef HAS_SPECULAR_GLOSSINESS_MAP\nvec4 sgSample=SRGBtoLINEAR(texture2D(u_SpecularGlossinessSampler,getSpecularGlossinessUV()));perceptualRoughness=(1.0-sgSample.a*u_GlossinessFactor);f0=sgSample.rgb*u_SpecularFactor;\n#else\nf0=u_SpecularFactor;perceptualRoughness=1.0-u_GlossinessFactor;\n#endif\n#ifdef HAS_DIFFUSE_MAP\nbaseColor=SRGBtoLINEAR(texture2D(u_DiffuseSampler,getDiffuseUV()))*u_DiffuseFactor;\n#else\nbaseColor=SRGBtoLINEAR(u_DiffuseFactor);\n#endif\nbaseColor*=getVertexColor();specularColor=f0;float oneMinusSpecularStrength=1.0-max(max(f0.r,f0.g),f0.b);diffuseColor=baseColor.rgb*oneMinusSpecularStrength;\n#ifdef DEBUG_METALLIC\nmetallic=solveMetallic(baseColor.rgb,specularColor,oneMinusSpecularStrength);\n#endif\n#endif\n#ifdef MATERIAL_METALLICROUGHNESS\n#ifdef HAS_METALLIC_ROUGHNESS_MAP\nvec4 mrSample=texture2D(u_MetallicRoughnessSampler,getMetallicRoughnessUV());perceptualRoughness=mrSample.g*u_RoughnessFactor;metallic=mrSample.b*u_MetallicFactor;\n#else\nmetallic=u_MetallicFactor;perceptualRoughness=u_RoughnessFactor;\n#endif\n#ifdef HAS_BASE_COLOR_MAP\nbaseColor=SRGBtoLINEAR(texture2D(u_BaseColorSampler,getBaseColorUV()))*u_BaseColorFactor;\n#else\nbaseColor=SRGBtoLINEAR(u_BaseColorFactor);\n#endif\nbaseColor*=getVertexColor();diffuseColor=baseColor.rgb*(vec3(1.0)-f0)*(1.0-metallic);specularColor=mix(f0,baseColor.rgb,metallic);\n#endif\n#ifdef ALPHAMODE_MASK\nif(baseColor.a<u_AlphaCutoff){discard;}baseColor.a=1.0;\n#endif\n#ifdef ALPHAMODE_OPAQUE\nbaseColor.a=1.0;\n#endif\n#ifdef MATERIAL_UNLIT\n#ifndef DEBUG_OUTPUT\n#ifdef ADD_FOG\nvec3 mixColor=getMixFogColor(baseColor.rgb);vec4 fragColorUnlit=vec4(LINEARtoSRGB(mixColor)*baseColor.a,baseColor.a);\n#else\nvec4 fragColorUnlit=vec4(LINEARtoSRGB(baseColor.rgb)*baseColor.a,baseColor.a);\n#endif\nwriteFragmentColor(fragColorUnlit);\n#else\n#ifdef DEBUG_UV\noutFragColor.rgb=vec3(getDebugUVColor(getBaseColorUV(),getNormal()));\n#endif\n#ifdef DEBUG_METALLIC\noutFragColor.rgb=vec3(metallic);\n#endif\n#ifdef DEBUG_ROUGHNESS\noutFragColor.rgb=vec3(perceptualRoughness);\n#endif\n#ifdef DEBUG_NORMAL\noutFragColor.rgb=getNormal()*0.5+0.5;\n#endif\n#ifdef DEBUG_BASECOLOR\noutFragColor.rgb=LINEARtoSRGB(baseColor.rgb);\n#endif\n#ifdef DEBUG_OCCLUSION\noutFragColor.rgb=vec3(1.0);\n#endif\n#ifdef DEBUG_EMISSIVE\noutFragColor.rgb=vec3(0.0);\n#endif\n#ifdef DEBUG_ALPHA\noutFragColor.rgb=vec3(baseColor.a);\n#endif\noutFragColor.a=1.0;\n#endif\nreturn;\n#endif\nmetallic=clamp(metallic,0.0,1.0);float alphaRoughness=perceptualRoughness*perceptualRoughness;vec3 normal=getNormal();\n#ifdef USE_SPECULAR_AA\nfloat AARoughnessFactor=getAARoughnessFactor(normal);perceptualRoughness+=AARoughnessFactor;alphaRoughness+=AARoughnessFactor;\n#endif\nperceptualRoughness=clamp(perceptualRoughness,0.04,1.0);alphaRoughness=clamp(alphaRoughness,0.04,1.0);float reflectance=max(max(specularColor.r,specularColor.g),specularColor.b);vec3 specularEnvironmentR0=specularColor.rgb;vec3 specularEnvironmentR90=vec3(clamp(reflectance*50.0,0.0,1.0));MaterialInfo materialInfo=MaterialInfo(perceptualRoughness,specularEnvironmentR0,alphaRoughness,diffuseColor,specularEnvironmentR90,specularColor);vec3 color=vec3(0.0,0.0,0.0);vec3 view=normalize(u_Camera-v_Position);float shadow=1.0;\n#ifdef USE_SHADOW_MAPPING\nshadow=getShadowContribution();\n#endif\n#ifdef USE_PUNCTUAL\nfor(int i=0;i<LIGHT_COUNT;++i){Light light=u_Lights[i];if(light.type==LightType_Directional){color+=applyDirectionalLight(light,materialInfo,normal,view,shadow);}else if(light.type==LightType_Point){color+=applyPointLight(light,materialInfo,normal,view);}else if(light.type==LightType_Spot){color+=applySpotLight(light,materialInfo,normal,view,shadow);}else if(light.type==LightType_Ambient){color+=applyAmbientLight(light,materialInfo);}}\n#endif\n#ifdef USE_IBL\ncolor+=getIBLContribution(materialInfo,normal,view);\n#endif\nfloat ao=1.0;\n#ifdef HAS_OCCLUSION_MAP\nao=texture2D(u_OcclusionSampler,getOcclusionUV()).r;color=mix(color,color*ao,u_OcclusionStrength);\n#endif\nvec3 emissive=vec3(0);\n#ifndef DEBUG_OUTPUT\n#ifdef ADD_FOG\nvec4 toneMapColor=SRGBtoLINEAR(vec4(toneMap(color),baseColor.a));color=getMixFogColor(toneMapColor.rgb);vec4 fragColorOut=vec4(LINEARtoSRGB(color.rgb)*baseColor.a,baseColor.a);\n#else\ncolor=toneMap(color)*baseColor.a;\n#ifdef HAS_EMISSIVE\ncolor+=u_EmissiveFactor.rgb;\n#endif\n#ifdef HAS_EMISSIVE_MAP\nemissive=SRGBtoLINEAR(texture2D(u_EmissiveSampler,getEmissiveUV())).rgb*u_EmissiveFactor.rgb;color+=emissive;\n#endif\nvec4 fragColorOut=vec4(color,baseColor.a);\n#endif\nwriteFragmentColor(fragColorOut);\n#else\n#ifdef DEBUG_UV\noutFragColor.rgb=vec3(getDebugUVColor(getBaseColorUV(),normal));\n#endif\n#ifdef DEBUG_METALLIC\noutFragColor.rgb=vec3(metallic);\n#endif\n#ifdef DEBUG_ROUGHNESS\noutFragColor.rgb=vec3(perceptualRoughness);\n#endif\n#ifdef DEBUG_NORMAL\noutFragColor.rgb=normal*0.5+0.5;\n#endif\n#ifdef DEBUG_BASECOLOR\noutFragColor.rgb=LINEARtoSRGB(baseColor.rgb);\n#endif\n#ifdef DEBUG_OCCLUSION\n#ifdef HAS_OCCLUSION_MAP\noutFragColor.rgb=vec3(mix(1.0,ao,u_OcclusionStrength));\n#else\noutFragColor.rgb=vec3(1.0);\n#endif\n#endif\n#ifdef DEBUG_EMISSIVE\n#ifdef HAS_EMISSIVE\nemissive=u_EmissiveFactor.rgb;\n#endif\n#ifdef HAS_EMISSIVE_MAP\nemissive=SRGBtoLINEAR(texture2D(u_EmissiveSampler,getEmissiveUV())).rgb*u_EmissiveFactor.rgb;\n#endif\noutFragColor.rgb=LINEARtoSRGB(emissive);\n#endif\n#ifdef DEBUG_F0\noutFragColor.rgb=vec3(f0);\n#endif\n#ifdef DEBUG_ALPHA\noutFragColor.rgb=vec3(baseColor.a);\n#endif\noutFragColor.a=1.0;\n#endif\n}";
|
|
3928
3985
|
|
|
3929
3986
|
var shadowPassFrag = "#define FEATURES\n#include <shadowCommon.vert.glsl>\n#include <webglCompatibility.glsl>\n#if defined(SHADOWMAP_VSM) && !defined(WEBGL2)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#ifdef GL_FRAGMENT_PRECISION_HIGH\nprecision highp float;\n#else\nprecision mediump float;\n#endif\n#ifdef WEBGL2\nout vec4 outFragColor;\n#else\n#define outFragColor gl_FragColor\n#endif\nvec4 CalcMomentVSM(float depth){float dx=0.0;float dy=0.0;\n#if defined(SHADOWMAP_VSM) && (defined(GL_OES_standard_derivatives) || defined(WEBGL2))\ndx=dFdx(depth);dy=dFdy(depth);\n#endif\nfloat moment2=depth*depth+0.25*(dx*dx+dy*dy);return vec4(1.0-depth,1.0-moment2,0.0,1.0);}vec4 CalcMomentEVSM(float depth){float pos=EVSM_FUNC0(depth);float neg=EVSM_FUNC1(depth);return vec4(pos,pos*pos,neg,neg*neg);}void main(){\n#if defined(SHADOWMAP_STANDARD) || defined(SHADOWMAP_VSM)\noutFragColor=CalcMomentVSM(gl_FragCoord.z);\n#else\noutFragColor=CalcMomentEVSM(gl_FragCoord.z);\n#endif\n}";
|
|
3930
3987
|
|
|
@@ -3938,7 +3995,7 @@ var extensionsFragGLSL = "vec3 _dFdx(vec3 coord){\n#if defined(GL_OES_standard_d
|
|
|
3938
3995
|
|
|
3939
3996
|
var tonemappingFragGLSL = "uniform float u_Exposure;const float GAMMA=2.2;const float INV_GAMMA=1.0/GAMMA;vec3 LINEARtoSRGB(vec3 color){return pow(color,vec3(INV_GAMMA));}vec4 SRGBtoLINEAR(vec4 srgbIn){return vec4(pow(srgbIn.xyz,vec3(GAMMA)),srgbIn.w);}vec3 toneMapUncharted2Impl(vec3 color){const float A=0.15;const float B=0.50;const float C=0.10;const float D=0.20;const float E=0.02;const float F=0.30;return((color*(A*color+C*B)+D*E)/(color*(A*color+B)+D*F))-E/F;}vec3 toneMapUncharted(vec3 color){const float W=11.2;color=toneMapUncharted2Impl(color*2.0);vec3 whiteScale=1.0/toneMapUncharted2Impl(vec3(W));return LINEARtoSRGB(color*whiteScale);}vec3 toneMapHejlRichard(vec3 color){color=max(vec3(0.0),color-vec3(0.004));return(color*(6.2*color+.5))/(color*(6.2*color+1.7)+0.06);}vec3 toneMapACES(vec3 color){const float A=2.51;const float B=0.03;const float C=2.43;const float D=0.59;const float E=0.14;return LINEARtoSRGB(clamp((color*(A*color+B))/(color*(C*color+D)+E),0.0,1.0));}vec3 toneMap(vec3 color){color*=u_Exposure;\n#ifdef TONEMAP_UNCHARTED\nreturn toneMapUncharted(color);\n#endif\n#ifdef TONEMAP_HEJLRICHARD\nreturn toneMapHejlRichard(color);\n#endif\n#ifdef TONEMAP_ACES\nreturn toneMapACES(color);\n#endif\nreturn LINEARtoSRGB(color);}";
|
|
3940
3997
|
|
|
3941
|
-
var texturesVertGLSL = "fsIn vec2 v_UVCoord1;\n#ifdef HAS_UV_SET2\nfsIn vec2 v_UVCoord2;\n#endif\n#ifdef HAS_NORMAL_MAP\nuniform sampler2D u_NormalSampler;uniform float u_NormalScale;uniform int u_NormalUVSet;uniform mat3 u_NormalUVTransform;\n#endif\n#ifdef HAS_EMISSIVE_MAP\nuniform sampler2D u_EmissiveSampler;uniform int u_EmissiveUVSet;uniform
|
|
3998
|
+
var texturesVertGLSL = "fsIn vec2 v_UVCoord1;\n#ifdef HAS_UV_SET2\nfsIn vec2 v_UVCoord2;\n#endif\n#ifdef HAS_NORMAL_MAP\nuniform sampler2D u_NormalSampler;uniform float u_NormalScale;uniform int u_NormalUVSet;uniform mat3 u_NormalUVTransform;\n#endif\n#ifdef HAS_EMISSIVE_MAP\nuniform sampler2D u_EmissiveSampler;uniform int u_EmissiveUVSet;uniform vec4 u_EmissiveFactor;uniform mat3 u_EmissiveUVTransform;\n#endif\n#ifdef HAS_EMISSIVE\nuniform vec4 u_EmissiveFactor;\n#endif\n#ifdef HAS_OCCLUSION_MAP\nuniform sampler2D u_OcclusionSampler;uniform int u_OcclusionUVSet;uniform float u_OcclusionStrength;uniform mat3 u_OcclusionUVTransform;\n#endif\n#ifdef HAS_BASE_COLOR_MAP\nuniform sampler2D u_BaseColorSampler;uniform int u_BaseColorUVSet;uniform mat3 u_BaseColorUVTransform;\n#endif\n#ifdef HAS_METALLIC_ROUGHNESS_MAP\nuniform sampler2D u_MetallicRoughnessSampler;uniform int u_MetallicRoughnessUVSet;uniform mat3 u_MetallicRoughnessUVTransform;\n#endif\n#ifdef HAS_DIFFUSE_MAP\nuniform sampler2D u_DiffuseSampler;uniform int u_DiffuseUVSet;uniform mat3 u_DiffuseUVTransform;\n#endif\n#ifdef HAS_SPECULAR_GLOSSINESS_MAP\nuniform sampler2D u_SpecularGlossinessSampler;uniform int u_SpecularGlossinessUVSet;uniform mat3 u_SpecularGlossinessUVTransform;\n#endif\n#ifdef USE_IBL\nuniform samplerCube u_DiffuseEnvSampler;uniform samplerCube u_SpecularEnvSampler;uniform sampler2D u_brdfLUT;uniform vec2 u_IblIntensity;\n#endif\n#ifdef IRRADIANCE_COEFFICIENTS\nstruct SHCoefficients{vec3 l00,l1m1,l10,l11,l2m2,l2m1,l20,l21,l22;};uniform SHCoefficients u_shCoefficients;\n#endif\n#ifdef USE_SHADOW_MAPPING\nuniform sampler2D u_ShadowSampler;\n#endif\nvec2 getNormalUV(){vec3 uv=vec3(v_UVCoord1,1.0);\n#ifdef HAS_NORMAL_MAP\n#ifdef HAS_UV_SET2\nuv.xy=u_NormalUVSet<1 ? v_UVCoord1 : v_UVCoord2;\n#endif\n#ifdef HAS_NORMAL_UV_TRANSFORM\nuv*=u_NormalUVTransform;\n#endif\n#endif\nreturn uv.xy;}vec2 getEmissiveUV(){vec3 uv=vec3(v_UVCoord1,1.0);\n#ifdef HAS_EMISSIVE_MAP\n#ifdef HAS_UV_SET2\nuv.xy=u_EmissiveUVSet<1 ? v_UVCoord1 : v_UVCoord2;\n#endif\n#ifdef HAS_EMISSIVE_UV_TRANSFORM\nuv*=u_EmissiveUVTransform;\n#endif\n#endif\nreturn uv.xy;}vec2 getOcclusionUV(){vec3 uv=vec3(v_UVCoord1,1.0);\n#ifdef HAS_OCCLUSION_MAP\n#ifdef HAS_UV_SET2\nuv.xy=u_OcclusionUVSet<1 ? v_UVCoord1 : v_UVCoord2;\n#endif\n#ifdef HAS_OCCLUSION_UV_TRANSFORM\nuv*=u_OcclusionUVTransform;\n#endif\n#endif\nreturn uv.xy;}vec2 getBaseColorUV(){vec3 uv=vec3(v_UVCoord1,1.0);\n#ifdef HAS_BASE_COLOR_MAP\n#ifdef HAS_UV_SET2\nuv.xy=u_BaseColorUVSet<1 ? v_UVCoord1 : v_UVCoord2;\n#endif\n#ifdef HAS_BASECOLOR_UV_TRANSFORM\nuv*=u_BaseColorUVTransform;\n#endif\n#endif\nreturn uv.xy;}vec2 getMetallicRoughnessUV(){vec3 uv=vec3(v_UVCoord1,1.0);\n#ifdef HAS_METALLIC_ROUGHNESS_MAP\n#ifdef HAS_UV_SET2\nuv.xy=u_MetallicRoughnessUVSet<1 ? v_UVCoord1 : v_UVCoord2;\n#endif\n#ifdef HAS_METALLICROUGHNESS_UV_TRANSFORM\nuv*=u_MetallicRoughnessUVTransform;\n#endif\n#endif\nreturn uv.xy;}vec2 getSpecularGlossinessUV(){vec3 uv=vec3(v_UVCoord1,1.0);\n#ifdef HAS_SPECULAR_GLOSSINESS_MAP\n#ifdef HAS_UV_SET2\nuv.xy=u_SpecularGlossinessUVSet<1 ? v_UVCoord1 : v_UVCoord2;\n#endif\n#ifdef HAS_SPECULARGLOSSINESS_UV_TRANSFORM\nuv*=u_SpecularGlossinessUVTransform;\n#endif\n#endif\nreturn uv.xy;}vec2 getDiffuseUV(){vec3 uv=vec3(v_UVCoord1,1.0);\n#ifdef HAS_DIFFUSE_MAP\n#ifdef HAS_UV_SET2\nuv.xy=u_DiffuseUVSet<1 ? v_UVCoord1 : v_UVCoord2;\n#endif\n#ifdef HAS_DIFFUSE_UV_TRANSFORM\nuv*=u_DiffuseUVTransform;\n#endif\n#endif\nreturn uv.xy;}";
|
|
3942
3999
|
|
|
3943
4000
|
var functionsFragGLSL = "const float M_PI=3.141592653589793;const float c_MinReflectance=0.04;fsIn vec3 v_Position;\n#ifdef HAS_NORMALS\n#ifdef HAS_TANGENTS\nfsIn mat3 v_TBN;\n#else\nfsIn vec3 v_Normal;\n#endif\n#endif\n#ifdef HAS_VERTEX_COLOR_VEC3\nfsIn vec3 v_Color;\n#endif\n#ifdef HAS_VERTEX_COLOR_VEC4\nfsIn vec4 v_Color;\n#endif\nstruct AngularInfo{float NdotL;float NdotV;float NdotH;float LdotH;float VdotH;vec3 padding;};vec4 getVertexColor(){vec4 color=vec4(1.0,1.0,1.0,1.0);\n#ifdef HAS_VERTEX_COLOR_VEC3\ncolor.rgb=v_Color;\n#endif\n#ifdef HAS_VERTEX_COLOR_VEC4\ncolor=v_Color;\n#endif\nreturn color;}vec3 getNormal(){vec2 UV=getNormalUV();\n#ifndef HAS_TANGENTS\nvec3 pos_dx=_dFdx(v_Position);vec3 pos_dy=_dFdy(v_Position);vec3 tex_dx=_dFdx(vec3(UV,0.0));vec3 tex_dy=_dFdy(vec3(UV,0.0));vec3 t=(tex_dy.t*pos_dx-tex_dx.t*pos_dy)/(tex_dx.s*tex_dy.t-tex_dy.s*tex_dx.t);\n#ifdef HAS_NORMALS\nvec3 ng=normalize(v_Normal);\n#else\nvec3 ng=cross(pos_dx,pos_dy);\n#endif\nt=normalize(t-ng*dot(ng,t));vec3 b=normalize(cross(ng,t));mat3 tbn=mat3(t,b,ng);\n#else\nmat3 tbn=v_TBN;\n#endif\n#ifdef HAS_NORMAL_MAP\nvec3 n=texture2D(u_NormalSampler,UV).rgb;n=normalize(tbn*((2.0*n-1.0)*vec3(u_NormalScale,u_NormalScale,1.0)));\n#else\nvec3 n=normalize(tbn[2].xyz);\n#endif\n#ifdef DOUBLE_SIDED\nfloat faceDirection=gl_FrontFacing ? 1.0 :-1.0;n=n*faceDirection;\n#endif\nreturn n;}float getPerceivedBrightness(vec3 vector){return sqrt(0.299*vector.r*vector.r+0.587*vector.g*vector.g+0.114*vector.b*vector.b);}float solveMetallic(vec3 diffuse,vec3 specular,float oneMinusSpecularStrength){float specularBrightness=getPerceivedBrightness(specular);if(specularBrightness<c_MinReflectance){return 0.0;}float diffuseBrightness=getPerceivedBrightness(diffuse);float a=c_MinReflectance;float b=diffuseBrightness*oneMinusSpecularStrength/(1.0-c_MinReflectance)+specularBrightness-2.0*c_MinReflectance;float c=c_MinReflectance-specularBrightness;float D=b*b-4.0*a*c;return clamp((-b+sqrt(D))/(2.0*a),0.0,1.0);}AngularInfo getAngularInfo(vec3 pointToLight,vec3 normal,vec3 view){vec3 n=normalize(normal);vec3 v=normalize(view);vec3 l=normalize(pointToLight);vec3 h=normalize(l+v);float NdotL=clamp(dot(n,l),0.0,1.0);float NdotV=clamp(dot(n,v),0.0,1.0);float NdotH=clamp(dot(n,h),0.0,1.0);float LdotH=clamp(dot(l,h),0.0,1.0);float VdotH=clamp(dot(v,h),0.0,1.0);return AngularInfo(NdotL,NdotV,NdotH,LdotH,VdotH,vec3(0,0,0));}float getAARoughnessFactor(vec3 normal){vec3 dxy=max(abs(_dFdx(normal)),abs(_dFdy(normal)));return max(max(dxy.x,dxy.y),dxy.z)*2.0;}\n#ifdef DEBUG_UV\nuniform float u_DebugUVGridSize;float getDebugUVColor(vec2 uv,vec3 n){float s=dot(abs(n),vec3(1,1,1))*0.6;uv=uv/(u_DebugUVGridSize*2.0);uv=uv-floor(uv);uv=uv*2.0-vec2(1.0);return s*(uv.x*uv.y>=0.0 ? 0.2: 1.0);}\n#endif\n";
|
|
3944
4001
|
|
|
@@ -4342,15 +4399,6 @@ function getPMeshList(player) {
|
|
|
4342
4399
|
return meshList;
|
|
4343
4400
|
}
|
|
4344
4401
|
|
|
4345
|
-
exports.ModelDataType = void 0;
|
|
4346
|
-
(function (ModelDataType) {
|
|
4347
|
-
ModelDataType[ModelDataType["MeshComponent"] = 10000] = "MeshComponent";
|
|
4348
|
-
ModelDataType[ModelDataType["SkyboxComponent"] = 10001] = "SkyboxComponent";
|
|
4349
|
-
ModelDataType[ModelDataType["LightComponent"] = 10002] = "LightComponent";
|
|
4350
|
-
ModelDataType[ModelDataType["CameraComponent"] = 10003] = "CameraComponent";
|
|
4351
|
-
ModelDataType[ModelDataType["ModelPluginComponent"] = 10004] = "ModelPluginComponent";
|
|
4352
|
-
ModelDataType[ModelDataType["TreeComponent"] = 10005] = "TreeComponent";
|
|
4353
|
-
})(exports.ModelDataType || (exports.ModelDataType = {}));
|
|
4354
4402
|
/**
|
|
4355
4403
|
* 插件 Mesh 组件类,支持 3D Mesh 渲染能力
|
|
4356
4404
|
* @since 2.0.0
|
|
@@ -4361,9 +4409,9 @@ var ModelMeshComponent = /** @class */ (function (_super) {
|
|
|
4361
4409
|
/**
|
|
4362
4410
|
* 构造函数,只保存传入参数,不在这里创建内部对象
|
|
4363
4411
|
* @param engine - 引擎
|
|
4364
|
-
* @param
|
|
4412
|
+
* @param data - Mesh 参数
|
|
4365
4413
|
*/
|
|
4366
|
-
function ModelMeshComponent(engine,
|
|
4414
|
+
function ModelMeshComponent(engine, data) {
|
|
4367
4415
|
var _this = _super.call(this, engine) || this;
|
|
4368
4416
|
/**
|
|
4369
4417
|
* 获取点击测试参数,根据元素包围盒进行相交测试,Mesh 对象会进行更加精确的点击测试
|
|
@@ -4418,8 +4466,8 @@ var ModelMeshComponent = /** @class */ (function (_super) {
|
|
|
4418
4466
|
}
|
|
4419
4467
|
}
|
|
4420
4468
|
};
|
|
4421
|
-
if (
|
|
4422
|
-
_this.fromData(
|
|
4469
|
+
if (data) {
|
|
4470
|
+
_this.fromData(data);
|
|
4423
4471
|
}
|
|
4424
4472
|
return _this;
|
|
4425
4473
|
}
|
|
@@ -4471,22 +4519,20 @@ var ModelMeshComponent = /** @class */ (function (_super) {
|
|
|
4471
4519
|
};
|
|
4472
4520
|
/**
|
|
4473
4521
|
* 反序列化,记录传入参数
|
|
4474
|
-
* @param
|
|
4522
|
+
* @param data - 组件参数
|
|
4475
4523
|
*/
|
|
4476
|
-
ModelMeshComponent.prototype.fromData = function (
|
|
4477
|
-
_super.prototype.fromData.call(this,
|
|
4478
|
-
this.
|
|
4524
|
+
ModelMeshComponent.prototype.fromData = function (data) {
|
|
4525
|
+
_super.prototype.fromData.call(this, data);
|
|
4526
|
+
this.data = data;
|
|
4479
4527
|
};
|
|
4480
4528
|
/**
|
|
4481
4529
|
* 创建内部对象
|
|
4482
4530
|
*/
|
|
4483
4531
|
ModelMeshComponent.prototype.createContent = function () {
|
|
4484
|
-
if (this.
|
|
4485
|
-
var bounding = this.
|
|
4532
|
+
if (this.data) {
|
|
4533
|
+
var bounding = this.data.interaction;
|
|
4486
4534
|
this.bounding = bounding && JSON.parse(JSON.stringify(bounding));
|
|
4487
|
-
|
|
4488
|
-
CheckerHelper.assertModelMeshOptions(meshOptions);
|
|
4489
|
-
this.content = new PMesh(this.engine, this.item.name, this.options, this, this.item.parentId);
|
|
4535
|
+
this.content = new PMesh(this.engine, this.item.name, this.data, this, this.item.parentId);
|
|
4490
4536
|
}
|
|
4491
4537
|
};
|
|
4492
4538
|
/**
|
|
@@ -4528,7 +4574,7 @@ var ModelMeshComponent = /** @class */ (function (_super) {
|
|
|
4528
4574
|
}
|
|
4529
4575
|
};
|
|
4530
4576
|
ModelMeshComponent = __decorate([
|
|
4531
|
-
effects.effectsClass(
|
|
4577
|
+
effects.effectsClass(effects.DataType.MeshComponent)
|
|
4532
4578
|
], ModelMeshComponent);
|
|
4533
4579
|
return ModelMeshComponent;
|
|
4534
4580
|
}(effects.RendererComponent));
|
|
@@ -4542,12 +4588,12 @@ var ModelSkyboxComponent = /** @class */ (function (_super) {
|
|
|
4542
4588
|
/**
|
|
4543
4589
|
* 构造函数,只保存传入参数,不在这里创建内部对象
|
|
4544
4590
|
* @param engine - 引擎
|
|
4545
|
-
* @param
|
|
4591
|
+
* @param data - Mesh 参数
|
|
4546
4592
|
*/
|
|
4547
|
-
function ModelSkyboxComponent(engine,
|
|
4593
|
+
function ModelSkyboxComponent(engine, data) {
|
|
4548
4594
|
var _this = _super.call(this, engine) || this;
|
|
4549
|
-
if (
|
|
4550
|
-
_this.fromData(
|
|
4595
|
+
if (data) {
|
|
4596
|
+
_this.fromData(data);
|
|
4551
4597
|
}
|
|
4552
4598
|
return _this;
|
|
4553
4599
|
}
|
|
@@ -4585,20 +4631,19 @@ var ModelSkyboxComponent = /** @class */ (function (_super) {
|
|
|
4585
4631
|
};
|
|
4586
4632
|
/**
|
|
4587
4633
|
* 反序列化,记录传入参数
|
|
4588
|
-
* @param
|
|
4634
|
+
* @param data - 组件参数
|
|
4589
4635
|
*/
|
|
4590
|
-
ModelSkyboxComponent.prototype.fromData = function (
|
|
4591
|
-
_super.prototype.fromData.call(this,
|
|
4592
|
-
this.
|
|
4636
|
+
ModelSkyboxComponent.prototype.fromData = function (data) {
|
|
4637
|
+
_super.prototype.fromData.call(this, data);
|
|
4638
|
+
this.data = data;
|
|
4593
4639
|
};
|
|
4594
4640
|
/**
|
|
4595
4641
|
* 创建内部对象
|
|
4596
4642
|
*/
|
|
4597
4643
|
ModelSkyboxComponent.prototype.createContent = function () {
|
|
4598
|
-
if (this.
|
|
4599
|
-
var
|
|
4600
|
-
|
|
4601
|
-
this.content = new PSkybox(this.item.name, skyboxOptions, this);
|
|
4644
|
+
if (this.data) {
|
|
4645
|
+
var skyboxData = this.data;
|
|
4646
|
+
this.content = new PSkybox(this.item.name, skyboxData, this);
|
|
4602
4647
|
}
|
|
4603
4648
|
};
|
|
4604
4649
|
/**
|
|
@@ -4617,7 +4662,7 @@ var ModelSkyboxComponent = /** @class */ (function (_super) {
|
|
|
4617
4662
|
return (_b = (_a = this.content) === null || _a === void 0 ? void 0 : _a.visible) !== null && _b !== void 0 ? _b : false;
|
|
4618
4663
|
};
|
|
4619
4664
|
ModelSkyboxComponent = __decorate([
|
|
4620
|
-
effects.effectsClass(
|
|
4665
|
+
effects.effectsClass(effects.DataType.SkyboxComponent)
|
|
4621
4666
|
], ModelSkyboxComponent);
|
|
4622
4667
|
return ModelSkyboxComponent;
|
|
4623
4668
|
}(effects.RendererComponent));
|
|
@@ -4631,12 +4676,12 @@ var ModelLightComponent = /** @class */ (function (_super) {
|
|
|
4631
4676
|
/**
|
|
4632
4677
|
* 构造函数,只保存传入参数,不在这里创建内部对象
|
|
4633
4678
|
* @param engine - 引擎
|
|
4634
|
-
* @param
|
|
4679
|
+
* @param data - Mesh 参数
|
|
4635
4680
|
*/
|
|
4636
|
-
function ModelLightComponent(engine,
|
|
4681
|
+
function ModelLightComponent(engine, data) {
|
|
4637
4682
|
var _this = _super.call(this, engine) || this;
|
|
4638
|
-
if (
|
|
4639
|
-
_this.fromData(
|
|
4683
|
+
if (data) {
|
|
4684
|
+
_this.fromData(data);
|
|
4640
4685
|
}
|
|
4641
4686
|
return _this;
|
|
4642
4687
|
}
|
|
@@ -4665,20 +4710,19 @@ var ModelLightComponent = /** @class */ (function (_super) {
|
|
|
4665
4710
|
};
|
|
4666
4711
|
/**
|
|
4667
4712
|
* 反序列化,记录传入参数
|
|
4668
|
-
* @param
|
|
4713
|
+
* @param data - 组件参数
|
|
4669
4714
|
*/
|
|
4670
|
-
ModelLightComponent.prototype.fromData = function (
|
|
4671
|
-
_super.prototype.fromData.call(this,
|
|
4672
|
-
this.
|
|
4715
|
+
ModelLightComponent.prototype.fromData = function (data) {
|
|
4716
|
+
_super.prototype.fromData.call(this, data);
|
|
4717
|
+
this.data = data;
|
|
4673
4718
|
};
|
|
4674
4719
|
/**
|
|
4675
4720
|
* 创建内部对象
|
|
4676
4721
|
*/
|
|
4677
4722
|
ModelLightComponent.prototype.createContent = function () {
|
|
4678
|
-
if (this.
|
|
4679
|
-
var
|
|
4680
|
-
|
|
4681
|
-
this.content = new PLight(this.item.name, lightOptions, this);
|
|
4723
|
+
if (this.data) {
|
|
4724
|
+
var lightData = this.data;
|
|
4725
|
+
this.content = new PLight(this.item.name, lightData, this);
|
|
4682
4726
|
}
|
|
4683
4727
|
};
|
|
4684
4728
|
/**
|
|
@@ -4697,7 +4741,7 @@ var ModelLightComponent = /** @class */ (function (_super) {
|
|
|
4697
4741
|
return (_b = (_a = this.content) === null || _a === void 0 ? void 0 : _a.visible) !== null && _b !== void 0 ? _b : false;
|
|
4698
4742
|
};
|
|
4699
4743
|
ModelLightComponent = __decorate([
|
|
4700
|
-
effects.effectsClass(
|
|
4744
|
+
effects.effectsClass(effects.DataType.LightComponent)
|
|
4701
4745
|
], ModelLightComponent);
|
|
4702
4746
|
return ModelLightComponent;
|
|
4703
4747
|
}(effects.ItemBehaviour));
|
|
@@ -4711,12 +4755,12 @@ var ModelCameraComponent = /** @class */ (function (_super) {
|
|
|
4711
4755
|
/**
|
|
4712
4756
|
* 构造函数,只保存传入参数,不在这里创建内部对象
|
|
4713
4757
|
* @param engine - 引擎
|
|
4714
|
-
* @param
|
|
4758
|
+
* @param data - Mesh 参数
|
|
4715
4759
|
*/
|
|
4716
|
-
function ModelCameraComponent(engine,
|
|
4760
|
+
function ModelCameraComponent(engine, data) {
|
|
4717
4761
|
var _this = _super.call(this, engine) || this;
|
|
4718
|
-
if (
|
|
4719
|
-
_this.fromData(
|
|
4762
|
+
if (data) {
|
|
4763
|
+
_this.fromData(data);
|
|
4720
4764
|
}
|
|
4721
4765
|
return _this;
|
|
4722
4766
|
}
|
|
@@ -4746,22 +4790,21 @@ var ModelCameraComponent = /** @class */ (function (_super) {
|
|
|
4746
4790
|
};
|
|
4747
4791
|
/**
|
|
4748
4792
|
* 反序列化,记录传入参数
|
|
4749
|
-
* @param
|
|
4793
|
+
* @param data - 组件参数
|
|
4750
4794
|
*/
|
|
4751
|
-
ModelCameraComponent.prototype.fromData = function (
|
|
4752
|
-
_super.prototype.fromData.call(this,
|
|
4753
|
-
this.
|
|
4795
|
+
ModelCameraComponent.prototype.fromData = function (data) {
|
|
4796
|
+
_super.prototype.fromData.call(this, data);
|
|
4797
|
+
this.data = data;
|
|
4754
4798
|
};
|
|
4755
4799
|
/**
|
|
4756
4800
|
* 创建内部对象
|
|
4757
4801
|
*/
|
|
4758
4802
|
ModelCameraComponent.prototype.createContent = function () {
|
|
4759
|
-
if (this.
|
|
4760
|
-
var
|
|
4761
|
-
CheckerHelper.assertModelCameraOptions(cameraOptions);
|
|
4803
|
+
if (this.data) {
|
|
4804
|
+
var cameraData = this.data;
|
|
4762
4805
|
var width = this.engine.renderer.getWidth();
|
|
4763
4806
|
var height = this.engine.renderer.getHeight();
|
|
4764
|
-
this.content = new PCamera(this.item.name, width, height,
|
|
4807
|
+
this.content = new PCamera(this.item.name, width, height, cameraData, this);
|
|
4765
4808
|
}
|
|
4766
4809
|
};
|
|
4767
4810
|
/**
|
|
@@ -4775,7 +4818,7 @@ var ModelCameraComponent = /** @class */ (function (_super) {
|
|
|
4775
4818
|
composition.camera.setQuat(this.transform.quat);
|
|
4776
4819
|
composition.camera.near = this.content.nearPlane;
|
|
4777
4820
|
composition.camera.far = this.content.farPlane;
|
|
4778
|
-
composition.camera.fov = this.content.
|
|
4821
|
+
composition.camera.fov = this.content.fov;
|
|
4779
4822
|
}
|
|
4780
4823
|
};
|
|
4781
4824
|
/**
|
|
@@ -4801,7 +4844,7 @@ var ModelCameraComponent = /** @class */ (function (_super) {
|
|
|
4801
4844
|
this.updateMainCamera();
|
|
4802
4845
|
};
|
|
4803
4846
|
ModelCameraComponent = __decorate([
|
|
4804
|
-
effects.effectsClass(
|
|
4847
|
+
effects.effectsClass(effects.DataType.CameraComponent)
|
|
4805
4848
|
], ModelCameraComponent);
|
|
4806
4849
|
return ModelCameraComponent;
|
|
4807
4850
|
}(effects.ItemBehaviour));
|
|
@@ -5467,11 +5510,13 @@ var MeshHelper = /** @class */ (function () {
|
|
|
5467
5510
|
var vertexShader = material.vertexShaderCode;
|
|
5468
5511
|
var fragmentShader = material.fragmentShaderCode;
|
|
5469
5512
|
var geometry = effects.Geometry.create(engine, MeshHelper.getPlaneGeometry());
|
|
5513
|
+
var isWebGL2 = engine.gpuCapability.level === 2;
|
|
5470
5514
|
var effectsMaterial = effects.Material.create(engine, {
|
|
5471
5515
|
shader: {
|
|
5472
5516
|
vertex: vertexShader,
|
|
5473
5517
|
fragment: fragmentShader,
|
|
5474
5518
|
shared: globalState.shaderShared,
|
|
5519
|
+
glslVersion: isWebGL2 ? effects.GLSLVersion.GLSL3 : effects.GLSLVersion.GLSL1,
|
|
5475
5520
|
},
|
|
5476
5521
|
uniformSemantics: uniformSemantics,
|
|
5477
5522
|
});
|
|
@@ -7650,6 +7695,7 @@ var PMaterialBase = /** @class */ (function (_super) {
|
|
|
7650
7695
|
__extends(PMaterialBase, _super);
|
|
7651
7696
|
function PMaterialBase() {
|
|
7652
7697
|
var _this = _super !== null && _super.apply(this, arguments) || this;
|
|
7698
|
+
_this.fromMaterial = false;
|
|
7653
7699
|
/**
|
|
7654
7700
|
* 材质类型,主要是 pbr 和 unlit 两类
|
|
7655
7701
|
*/
|
|
@@ -7722,6 +7768,19 @@ var PMaterialBase = /** @class */ (function (_super) {
|
|
|
7722
7768
|
* @param inFeatureList - 外部特性列表
|
|
7723
7769
|
*/
|
|
7724
7770
|
PMaterialBase.prototype.build = function (inFeatureList) {
|
|
7771
|
+
var finalFeatureList = this.getFeatureList(inFeatureList);
|
|
7772
|
+
var isWebGL2 = PGlobalState.getInstance().isWebGL2;
|
|
7773
|
+
//
|
|
7774
|
+
var shaderManager = PShaderManager.getInstance();
|
|
7775
|
+
var shaderResult = shaderManager.genShaderCode({
|
|
7776
|
+
material: this,
|
|
7777
|
+
isWebGL2: isWebGL2,
|
|
7778
|
+
featureList: finalFeatureList,
|
|
7779
|
+
});
|
|
7780
|
+
this.vertexShaderCode = shaderResult.vertexShaderCode;
|
|
7781
|
+
this.fragmentShaderCode = shaderResult.fragmentShaderCode;
|
|
7782
|
+
};
|
|
7783
|
+
PMaterialBase.prototype.getFeatureList = function (inFeatureList) {
|
|
7725
7784
|
var finalFeatureList = this.getShaderFeatures();
|
|
7726
7785
|
if (inFeatureList !== undefined) {
|
|
7727
7786
|
finalFeatureList.push.apply(finalFeatureList, __spreadArray([], __read(inFeatureList), false));
|
|
@@ -7738,15 +7797,7 @@ var PMaterialBase = /** @class */ (function (_super) {
|
|
|
7738
7797
|
finalFeatureList.push('EDITOR_TRANSFORM');
|
|
7739
7798
|
}
|
|
7740
7799
|
}
|
|
7741
|
-
|
|
7742
|
-
var shaderManager = PShaderManager.getInstance();
|
|
7743
|
-
var shaderResult = shaderManager.genShaderCode({
|
|
7744
|
-
material: this,
|
|
7745
|
-
isWebGL2: isWebGL2,
|
|
7746
|
-
featureList: finalFeatureList,
|
|
7747
|
-
});
|
|
7748
|
-
this.vertexShaderCode = shaderResult.vertexShaderCode;
|
|
7749
|
-
this.fragmentShaderCode = shaderResult.fragmentShaderCode;
|
|
7800
|
+
return finalFeatureList;
|
|
7750
7801
|
};
|
|
7751
7802
|
/**
|
|
7752
7803
|
* 获取混合模式,根据 GE 混合模式
|
|
@@ -8058,9 +8109,9 @@ var PMaterialPBR = /** @class */ (function (_super) {
|
|
|
8058
8109
|
*/
|
|
8059
8110
|
_this.occlusionTextureStrength = 1;
|
|
8060
8111
|
/**
|
|
8061
|
-
* 自发光颜色值,默认是黑色
|
|
8112
|
+
* 自发光颜色值,默认是黑色 Vector4(0, 0, 0, 0)
|
|
8062
8113
|
*/
|
|
8063
|
-
_this.emissiveFactor = new
|
|
8114
|
+
_this.emissiveFactor = new Vector4(0, 0, 0, 0);
|
|
8064
8115
|
/**
|
|
8065
8116
|
* 自发光强度
|
|
8066
8117
|
*/
|
|
@@ -8116,7 +8167,7 @@ var PMaterialPBR = /** @class */ (function (_super) {
|
|
|
8116
8167
|
this.emissiveTextureTrans = PluginHelper.createUVTransform(options.emissiveTextureTransform);
|
|
8117
8168
|
}
|
|
8118
8169
|
var emissiveFactor = PluginHelper.toPluginColor4(options.emissiveFactor);
|
|
8119
|
-
this.
|
|
8170
|
+
this.setEmissiveFactor(Vector3.fromArray(emissiveFactor));
|
|
8120
8171
|
this.emissiveIntensity = options.emissiveIntensity;
|
|
8121
8172
|
this.enableShadow = (_d = options.enableShadow) !== null && _d !== void 0 ? _d : false;
|
|
8122
8173
|
/**
|
|
@@ -8132,6 +8183,39 @@ var PMaterialPBR = /** @class */ (function (_super) {
|
|
|
8132
8183
|
this.alphaCutOff = (_e = options.alphaCutOff) !== null && _e !== void 0 ? _e : 0;
|
|
8133
8184
|
this.faceSideMode = this.getFaceSideMode(options.side);
|
|
8134
8185
|
};
|
|
8186
|
+
PMaterialPBR.prototype.createFromMaterial = function (mat) {
|
|
8187
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
8188
|
+
this.fromMaterial = true;
|
|
8189
|
+
this.material = mat;
|
|
8190
|
+
this.name = mat.name;
|
|
8191
|
+
this.type = exports.PObjectType.material;
|
|
8192
|
+
this.materialType = mat.getInt('shaderType') ? exports.PMaterialType.unlit : exports.PMaterialType.pbr;
|
|
8193
|
+
//
|
|
8194
|
+
this.baseColorTexture = (_a = mat.getTexture('u_BaseColorSampler')) !== null && _a !== void 0 ? _a : undefined;
|
|
8195
|
+
this.baseColorFactor = (_b = mat.getVector4('u_BaseColorFactor')) !== null && _b !== void 0 ? _b : new Vector4(255, 255, 255, 255);
|
|
8196
|
+
this.baseColorFactor.multiply(1 / 255.0);
|
|
8197
|
+
this.metallicRoughnessTexture = (_c = mat.getTexture('u_MetallicRoughnessSampler')) !== null && _c !== void 0 ? _c : undefined;
|
|
8198
|
+
this.useSpecularAA = mat.getInt('useSpecularAA') === 1;
|
|
8199
|
+
this.metallicFactor = (_d = mat.getFloat('u_MetallicFactor')) !== null && _d !== void 0 ? _d : 1;
|
|
8200
|
+
this.roughnessFactor = (_e = mat.getFloat('u_RoughnessFactor')) !== null && _e !== void 0 ? _e : 1;
|
|
8201
|
+
this.normalTexture = (_f = mat.getTexture('u_NormalSampler')) !== null && _f !== void 0 ? _f : undefined;
|
|
8202
|
+
this.normalTextureScale = (_g = mat.getFloat('u_NormalScale')) !== null && _g !== void 0 ? _g : 1;
|
|
8203
|
+
this.occlusionTexture = (_h = mat.getTexture('u_OcclusionSampler')) !== null && _h !== void 0 ? _h : undefined;
|
|
8204
|
+
this.occlusionTextureStrength = (_j = mat.getFloat('u_OcclusionTextureStrength')) !== null && _j !== void 0 ? _j : 1;
|
|
8205
|
+
this.emissiveTexture = (_k = mat.getTexture('u_EmissiveSampler')) !== null && _k !== void 0 ? _k : undefined;
|
|
8206
|
+
this.emissiveFactor = (_l = mat.getVector4('u_EmissiveFactor')) !== null && _l !== void 0 ? _l : new Vector4(0, 0, 0, 0);
|
|
8207
|
+
this.emissiveFactor.multiply(1 / 255.0);
|
|
8208
|
+
this.emissiveIntensity = (_m = mat.getFloat('u_EmissiveIntensity')) !== null && _m !== void 0 ? _m : 1;
|
|
8209
|
+
var emissiveFactor = this.emissiveFactor.clone().multiply(this.emissiveIntensity);
|
|
8210
|
+
mat.setVector4('u_EmissiveFactor', emissiveFactor);
|
|
8211
|
+
this.enableShadow = false;
|
|
8212
|
+
this.depthMask = false;
|
|
8213
|
+
var blending = (_o = mat.getInt('blending')) !== null && _o !== void 0 ? _o : effects.spec.MaterialBlending.opaque;
|
|
8214
|
+
this.blendMode = this.getBlendMode(blending);
|
|
8215
|
+
this.alphaCutOff = (_p = mat.getFloat('u_AlphaCutoff')) !== null && _p !== void 0 ? _p : 0;
|
|
8216
|
+
var side = (_q = mat.getInt('side')) !== null && _q !== void 0 ? _q : effects.spec.SideMode.FRONT;
|
|
8217
|
+
this.faceSideMode = this.getFaceSideMode(side);
|
|
8218
|
+
};
|
|
8135
8219
|
/**
|
|
8136
8220
|
* 销毁材质
|
|
8137
8221
|
*/
|
|
@@ -8194,6 +8278,35 @@ var PMaterialPBR = /** @class */ (function (_super) {
|
|
|
8194
8278
|
*/
|
|
8195
8279
|
PMaterialPBR.prototype.updateUniforms = function (material) {
|
|
8196
8280
|
_super.prototype.updateUniforms.call(this, material);
|
|
8281
|
+
if (this.fromMaterial) {
|
|
8282
|
+
var uvTransform_1 = new Matrix3().identity();
|
|
8283
|
+
if (this.baseColorTexture !== undefined) {
|
|
8284
|
+
material.setInt('u_BaseColorUVSet', 0);
|
|
8285
|
+
material.setMatrix3('u_BaseColorUVTransform', uvTransform_1);
|
|
8286
|
+
}
|
|
8287
|
+
//
|
|
8288
|
+
if (this.metallicRoughnessTexture !== undefined) {
|
|
8289
|
+
material.setInt('u_MetallicRoughnessUVSet', 0);
|
|
8290
|
+
material.setMatrix3('u_MetallicRoughnessUVTransform', uvTransform_1);
|
|
8291
|
+
}
|
|
8292
|
+
//
|
|
8293
|
+
if (this.normalTexture !== undefined) {
|
|
8294
|
+
material.setInt('u_NormalUVSet', 0);
|
|
8295
|
+
material.setMatrix3('u_NormalUVTransform', uvTransform_1);
|
|
8296
|
+
}
|
|
8297
|
+
//
|
|
8298
|
+
if (this.occlusionTexture !== undefined) {
|
|
8299
|
+
material.setInt('u_OcclusionUVSet', 0);
|
|
8300
|
+
material.setMatrix3('u_OcclusionUVTransform', uvTransform_1);
|
|
8301
|
+
}
|
|
8302
|
+
//
|
|
8303
|
+
if (this.emissiveTexture !== undefined) {
|
|
8304
|
+
material.setInt('u_EmissiveUVSet', 0);
|
|
8305
|
+
material.setMatrix3('u_EmissiveUVTransform', uvTransform_1);
|
|
8306
|
+
}
|
|
8307
|
+
material.setFloat('u_Exposure', 3.0);
|
|
8308
|
+
return;
|
|
8309
|
+
}
|
|
8197
8310
|
//
|
|
8198
8311
|
var uvTransform = new Matrix3().identity();
|
|
8199
8312
|
material.setVector4('u_BaseColorFactor', this.baseColorFactor);
|
|
@@ -8252,7 +8365,7 @@ var PMaterialPBR = /** @class */ (function (_super) {
|
|
|
8252
8365
|
if (this.emissiveTexture !== undefined) {
|
|
8253
8366
|
var emissiveFactor = this.getEmissiveFactor();
|
|
8254
8367
|
material.setTexture('u_EmissiveSampler', this.emissiveTexture);
|
|
8255
|
-
material.
|
|
8368
|
+
material.setVector4('u_EmissiveFactor', emissiveFactor);
|
|
8256
8369
|
material.setInt('u_EmissiveUVSet', 0);
|
|
8257
8370
|
if (this.emissiveTextureTrans !== undefined) {
|
|
8258
8371
|
material.setMatrix3('u_EmissiveUVTransform', this.emissiveTextureTrans);
|
|
@@ -8264,7 +8377,7 @@ var PMaterialPBR = /** @class */ (function (_super) {
|
|
|
8264
8377
|
}
|
|
8265
8378
|
else if (this.hasEmissiveFactor()) {
|
|
8266
8379
|
var emissiveFactor = this.getEmissiveFactor();
|
|
8267
|
-
material.
|
|
8380
|
+
material.setVector4('u_EmissiveFactor', emissiveFactor);
|
|
8268
8381
|
}
|
|
8269
8382
|
material.setFloat('u_Exposure', 3.0);
|
|
8270
8383
|
};
|
|
@@ -8443,11 +8556,17 @@ var PMaterialPBR = /** @class */ (function (_super) {
|
|
|
8443
8556
|
PMaterialPBR.prototype.setEmissiveFactor = function (val) {
|
|
8444
8557
|
if (val instanceof Vector3) {
|
|
8445
8558
|
// Vector3
|
|
8446
|
-
this.emissiveFactor.set(val.x, val.y, val.z);
|
|
8559
|
+
this.emissiveFactor.set(val.x, val.y, val.z, 0);
|
|
8447
8560
|
}
|
|
8448
8561
|
else {
|
|
8449
8562
|
// vec3
|
|
8450
|
-
this.emissiveFactor.set(val[0], val[1], val[2]);
|
|
8563
|
+
this.emissiveFactor.set(val[0], val[1], val[2], 0);
|
|
8564
|
+
}
|
|
8565
|
+
};
|
|
8566
|
+
PMaterialPBR.prototype.getTextureFromMaterial = function (mat, texName) {
|
|
8567
|
+
var tex = mat.getTexture(texName);
|
|
8568
|
+
if (tex !== null) {
|
|
8569
|
+
return tex;
|
|
8451
8570
|
}
|
|
8452
8571
|
};
|
|
8453
8572
|
return PMaterialPBR;
|
|
@@ -8458,15 +8577,22 @@ var PMaterialPBR = /** @class */ (function (_super) {
|
|
|
8458
8577
|
* @returns 材质对象
|
|
8459
8578
|
*/
|
|
8460
8579
|
function createPluginMaterial(options) {
|
|
8461
|
-
if (options
|
|
8580
|
+
if (options instanceof effects.Material) {
|
|
8462
8581
|
var materialPBR = new PMaterialPBR();
|
|
8463
|
-
materialPBR.
|
|
8582
|
+
materialPBR.createFromMaterial(options);
|
|
8464
8583
|
return materialPBR;
|
|
8465
8584
|
}
|
|
8466
8585
|
else {
|
|
8467
|
-
|
|
8468
|
-
|
|
8469
|
-
|
|
8586
|
+
if (options.type === effects.spec.MaterialType.pbr) {
|
|
8587
|
+
var materialPBR = new PMaterialPBR();
|
|
8588
|
+
materialPBR.create(options);
|
|
8589
|
+
return materialPBR;
|
|
8590
|
+
}
|
|
8591
|
+
else {
|
|
8592
|
+
var materialUnlit = new PMaterialUnlit();
|
|
8593
|
+
materialUnlit.create(options);
|
|
8594
|
+
return materialUnlit;
|
|
8595
|
+
}
|
|
8470
8596
|
}
|
|
8471
8597
|
}
|
|
8472
8598
|
function createInternalMaterial(options) {
|
|
@@ -8481,10 +8607,10 @@ var PSkybox = /** @class */ (function (_super) {
|
|
|
8481
8607
|
/**
|
|
8482
8608
|
* 构造函数
|
|
8483
8609
|
* @param name - 名称
|
|
8484
|
-
* @param
|
|
8610
|
+
* @param data - 天空盒参数
|
|
8485
8611
|
* @param owner - 所属天空盒组件元素
|
|
8486
8612
|
*/
|
|
8487
|
-
function PSkybox(name,
|
|
8613
|
+
function PSkybox(name, data, owner) {
|
|
8488
8614
|
var _a;
|
|
8489
8615
|
var _this = _super.call(this) || this;
|
|
8490
8616
|
/**
|
|
@@ -8519,14 +8645,27 @@ var PSkybox = /** @class */ (function (_super) {
|
|
|
8519
8645
|
_this.type = exports.PObjectType.skybox;
|
|
8520
8646
|
_this.visible = false;
|
|
8521
8647
|
_this.owner = owner;
|
|
8522
|
-
|
|
8523
|
-
_this.
|
|
8524
|
-
_this.
|
|
8525
|
-
_this.
|
|
8526
|
-
|
|
8527
|
-
|
|
8528
|
-
|
|
8529
|
-
|
|
8648
|
+
var irradianceCoeffs = data.irradianceCoeffs;
|
|
8649
|
+
_this.renderable = data.renderable;
|
|
8650
|
+
_this.intensity = data.intensity;
|
|
8651
|
+
_this.reflectionsIntensity = data.reflectionsIntensity;
|
|
8652
|
+
if (irradianceCoeffs) {
|
|
8653
|
+
_this.irradianceCoeffs = [];
|
|
8654
|
+
for (var i = 0; i < irradianceCoeffs.length; i += 3) {
|
|
8655
|
+
_this.irradianceCoeffs.push([
|
|
8656
|
+
irradianceCoeffs[i],
|
|
8657
|
+
irradianceCoeffs[i + 1],
|
|
8658
|
+
irradianceCoeffs[i + 2],
|
|
8659
|
+
]);
|
|
8660
|
+
}
|
|
8661
|
+
}
|
|
8662
|
+
else {
|
|
8663
|
+
_this.irradianceCoeffs = [];
|
|
8664
|
+
}
|
|
8665
|
+
_this.diffuseImage = data.diffuseImage;
|
|
8666
|
+
_this.specularImage = data.specularImage;
|
|
8667
|
+
_this.specularImageSize = data.specularImageSize;
|
|
8668
|
+
_this.specularMipCount = data.specularMipCount;
|
|
8530
8669
|
_this.priority = ((_a = owner === null || owner === void 0 ? void 0 : owner.item) === null || _a === void 0 ? void 0 : _a.listIndex) || 0;
|
|
8531
8670
|
return _this;
|
|
8532
8671
|
}
|
|
@@ -8591,7 +8730,7 @@ var PSkybox = /** @class */ (function (_super) {
|
|
|
8591
8730
|
var sceneStates = scene.sceneStates;
|
|
8592
8731
|
var camera = sceneStates.camera;
|
|
8593
8732
|
var viewMatrix = sceneStates.viewMatrix;
|
|
8594
|
-
var newProjViewMatrix = camera.getNewProjectionMatrix(camera.
|
|
8733
|
+
var newProjViewMatrix = camera.getNewProjectionMatrix(camera.fov).multiply(viewMatrix).invert();
|
|
8595
8734
|
var material = this.skyboxMesh.material;
|
|
8596
8735
|
this.skyboxMaterial.updateUniforms(material);
|
|
8597
8736
|
material.setMatrix('u_InvViewProjectionMatrix', newProjViewMatrix);
|
|
@@ -9399,6 +9538,28 @@ var ModelPlugin = /** @class */ (function (_super) {
|
|
|
9399
9538
|
});
|
|
9400
9539
|
});
|
|
9401
9540
|
};
|
|
9541
|
+
ModelPlugin.precompile = function (compositions, renderer) {
|
|
9542
|
+
var isWebGL2 = renderer.engine.gpuCapability.level === 2;
|
|
9543
|
+
var context = {
|
|
9544
|
+
// @ts-expect-error
|
|
9545
|
+
material: {
|
|
9546
|
+
materialType: exports.PMaterialType.pbr,
|
|
9547
|
+
},
|
|
9548
|
+
isWebGL2: isWebGL2,
|
|
9549
|
+
featureList: [],
|
|
9550
|
+
};
|
|
9551
|
+
var pbrShader = getPBRPassShaderCode(context);
|
|
9552
|
+
renderer.engine.addEffectsObjectData({
|
|
9553
|
+
// FIXME: 'unlit000000000000000000000000000',
|
|
9554
|
+
id: 'pbr00000000000000000000000000000',
|
|
9555
|
+
dataType: 'Shader',
|
|
9556
|
+
// @ts-expect-error
|
|
9557
|
+
fragment: pbrShader.fragmentShaderCode,
|
|
9558
|
+
vertex: pbrShader.vertexShaderCode,
|
|
9559
|
+
glslVersion: isWebGL2 ? effects.GLSLVersion.GLSL3 : effects.GLSLVersion.GLSL1,
|
|
9560
|
+
});
|
|
9561
|
+
return Promise.resolve();
|
|
9562
|
+
};
|
|
9402
9563
|
/**
|
|
9403
9564
|
* 创建 3D 场景管理器和缓存器
|
|
9404
9565
|
* @param composition - 合成
|
|
@@ -9595,14 +9756,14 @@ var ModelPluginComponent = /** @class */ (function (_super) {
|
|
|
9595
9756
|
var lightItemCount = 0;
|
|
9596
9757
|
var items = (_b = (_a = this.item.composition) === null || _a === void 0 ? void 0 : _a.items) !== null && _b !== void 0 ? _b : [];
|
|
9597
9758
|
items.forEach(function (item) {
|
|
9598
|
-
if (item.
|
|
9759
|
+
if (item.getComponent(ModelLightComponent)) {
|
|
9599
9760
|
lightItemCount++;
|
|
9600
9761
|
}
|
|
9601
9762
|
});
|
|
9602
9763
|
return lightItemCount;
|
|
9603
9764
|
};
|
|
9604
9765
|
ModelPluginComponent = __decorate([
|
|
9605
|
-
effects.effectsClass(
|
|
9766
|
+
effects.effectsClass(effects.DataType.ModelPluginComponent)
|
|
9606
9767
|
], ModelPluginComponent);
|
|
9607
9768
|
return ModelPluginComponent;
|
|
9608
9769
|
}(effects.ItemBehaviour));
|
|
@@ -9815,7 +9976,7 @@ var ModelTreeComponent = /** @class */ (function (_super) {
|
|
|
9815
9976
|
}
|
|
9816
9977
|
};
|
|
9817
9978
|
ModelTreeComponent = __decorate([
|
|
9818
|
-
effects.effectsClass(
|
|
9979
|
+
effects.effectsClass(effects.DataType.TreeComponent)
|
|
9819
9980
|
], ModelTreeComponent);
|
|
9820
9981
|
return ModelTreeComponent;
|
|
9821
9982
|
}(effects.ItemBehaviour));
|
|
@@ -9867,7 +10028,7 @@ var CameraGestureHandlerImp = /** @class */ (function () {
|
|
|
9867
10028
|
CameraGestureHandlerImp.prototype.getItem = function () {
|
|
9868
10029
|
var _this = this;
|
|
9869
10030
|
var _a;
|
|
9870
|
-
return (_a = this.composition.items) === null || _a === void 0 ? void 0 : _a.find(function (item) { return item.
|
|
10031
|
+
return (_a = this.composition.items) === null || _a === void 0 ? void 0 : _a.find(function (item) { return item.name === _this.getCurrentTarget(); });
|
|
9871
10032
|
};
|
|
9872
10033
|
CameraGestureHandlerImp.prototype.getCurrentTarget = function () {
|
|
9873
10034
|
return this.startParams.target;
|
|
@@ -10924,7 +11085,7 @@ var LoaderImpl = /** @class */ (function () {
|
|
|
10924
11085
|
name: 'skybox',
|
|
10925
11086
|
duration: this.getItemDuration(),
|
|
10926
11087
|
endBehavior: this.getItemEndBehavior(),
|
|
10927
|
-
type:
|
|
11088
|
+
type: effects.spec.ItemType.skybox,
|
|
10928
11089
|
pluginName: 'model',
|
|
10929
11090
|
content: {
|
|
10930
11091
|
options: this._skyboxOptions,
|
|
@@ -11648,7 +11809,7 @@ var GLTFHelper = /** @class */ (function () {
|
|
|
11648
11809
|
|
|
11649
11810
|
effects.registerPlugin('tree', ModelTreePlugin, effects.VFXItem, true);
|
|
11650
11811
|
effects.registerPlugin('model', ModelPlugin, effects.VFXItem);
|
|
11651
|
-
var version = "2.0.0-alpha.
|
|
11812
|
+
var version = "2.0.0-alpha.4";
|
|
11652
11813
|
effects.logger.info('plugin model version: ' + version);
|
|
11653
11814
|
|
|
11654
11815
|
exports.BoxMesh = BoxMesh;
|