@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.mjs CHANGED
@@ -3,10 +3,10 @@
3
3
  * Description: Galacean Effects player model plugin
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 飂兮
6
- * Version: v2.0.0-alpha.2
6
+ * Version: v2.0.0-alpha.4
7
7
  */
8
8
 
9
- import { math, Transform, PLAYER_OPTIONS_ENV_EDITOR, spec, glContext, Texture, TextureSourceType, RenderPassAttachmentStorageType, Material, Mesh, Geometry, DestroyOptions, addItem, removeItem, effectsClass, RendererComponent, ItemBehaviour, TimelineComponent, HitTestType, Renderer, RenderPass, TextureLoadAction, RenderPassDestroyAttachmentType, Player, getDefaultTextureFactory, loadImage, VFXItem, AbstractPlugin, registerPlugin, logger } from '@galacean/effects';
9
+ import { math, Transform, PLAYER_OPTIONS_ENV_EDITOR, spec, glContext, Texture, TextureSourceType, RenderPassAttachmentStorageType, Material, Mesh, Geometry, Shader, GLSLVersion, DestroyOptions, addItem, removeItem, effectsClass, DataType, RendererComponent, ItemBehaviour, TimelineComponent, HitTestType, RenderPass, TextureLoadAction, RenderPassDestroyAttachmentType, Player, Renderer, getDefaultTextureFactory, loadImage, VFXItem, AbstractPlugin, registerPlugin, logger } from '@galacean/effects';
10
10
 
11
11
  /**
12
12
  * Model 插件元素类型
@@ -1894,8 +1894,8 @@ var PCamera = /** @class */ (function (_super) {
1894
1894
  * @param height - 画布高度
1895
1895
  * @param owner - 所属的相机组件
1896
1896
  */
1897
- function PCamera(name, width, height, options, owner) {
1898
- var _a;
1897
+ function PCamera(name, width, height, data, owner) {
1898
+ var _a, _b, _c, _d, _e;
1899
1899
  var _this = _super.call(this) || this;
1900
1900
  /**
1901
1901
  * 画布宽度
@@ -1916,7 +1916,7 @@ var PCamera = /** @class */ (function (_super) {
1916
1916
  /**
1917
1917
  * Y 轴上视角
1918
1918
  */
1919
- _this.fovy = 45;
1919
+ _this.fov = 45;
1920
1920
  /**
1921
1921
  * 纵横比
1922
1922
  */
@@ -1940,11 +1940,11 @@ var PCamera = /** @class */ (function (_super) {
1940
1940
  _this.name = name;
1941
1941
  _this.width = width;
1942
1942
  _this.height = height;
1943
- _this.nearPlane = options.near;
1944
- _this.farPlane = options.far;
1945
- _this.fovy = options.fov;
1946
- _this.aspect = (_a = options.aspect) !== null && _a !== void 0 ? _a : (_this.width / _this.height);
1947
- _this.clipMode = options.clipMode;
1943
+ _this.nearPlane = (_a = data.near) !== null && _a !== void 0 ? _a : 0.001;
1944
+ _this.farPlane = (_b = data.far) !== null && _b !== void 0 ? _b : 1000;
1945
+ _this.fov = (_c = data.fov) !== null && _c !== void 0 ? _c : 45;
1946
+ _this.aspect = (_d = data.aspect) !== null && _d !== void 0 ? _d : (_this.width / _this.height);
1947
+ _this.clipMode = (_e = data.clipMode) !== null && _e !== void 0 ? _e : spec.CameraClipMode.landscape;
1948
1948
  _this.update();
1949
1949
  return _this;
1950
1950
  }
@@ -1956,7 +1956,7 @@ var PCamera = /** @class */ (function (_super) {
1956
1956
  this.transform.fromEffectsTransform(this.owner.transform);
1957
1957
  }
1958
1958
  var reverse = this.clipMode === spec.CameraClipMode.portrait;
1959
- this.projectionMatrix.perspective(this.fovy * deg2rad, this.aspect, this.nearPlane, this.farPlane, reverse);
1959
+ this.projectionMatrix.perspective(this.fov * deg2rad, this.aspect, this.nearPlane, this.farPlane, reverse);
1960
1960
  this.viewMatrix = this.matrix.invert();
1961
1961
  };
1962
1962
  /**
@@ -1974,7 +1974,7 @@ var PCamera = /** @class */ (function (_super) {
1974
1974
  * @returns 视角中的包围盒
1975
1975
  */
1976
1976
  PCamera.prototype.computeViewAABB = function (box) {
1977
- var tanTheta = Math.tan(this.fovy * deg2rad * 0.5);
1977
+ var tanTheta = Math.tan(this.fov * deg2rad * 0.5);
1978
1978
  var aspect = this.aspect;
1979
1979
  var yFarCoord = 0;
1980
1980
  var yNearCoord = 0;
@@ -2044,11 +2044,13 @@ var PCameraManager = /** @class */ (function () {
2044
2044
  this.winHeight = 512;
2045
2045
  this.cameraList = [];
2046
2046
  this.defaultCamera = new PCamera('camera', 512, 512, {
2047
+ id: '0',
2048
+ dataType: 'camera',
2047
2049
  fov: 60,
2048
2050
  far: 1000,
2049
2051
  near: 0.001,
2050
- position: [0, 0, -1.5],
2051
2052
  clipMode: spec.CameraClipMode.portrait,
2053
+ item: { id: '0' },
2052
2054
  });
2053
2055
  }
2054
2056
  /**
@@ -2067,12 +2069,13 @@ var PCameraManager = /** @class */ (function () {
2067
2069
  };
2068
2070
  /**
2069
2071
  * 插入相机数据,创建新的相机对象
2070
- * @param inCamera - 相机数据
2071
- * @param owner - 所属的相机组件
2072
+ * @param name - 相机名称
2073
+ * @param data - 相机相关数据
2074
+ * @param owner - 相机所属组件
2072
2075
  * @returns 新的相机对象
2073
2076
  */
2074
- PCameraManager.prototype.insert = function (name, options, owner) {
2075
- var camera = new PCamera(name, this.winWidth, this.winHeight, options, owner);
2077
+ PCameraManager.prototype.insert = function (name, data, owner) {
2078
+ var camera = new PCamera(name, this.winWidth, this.winHeight, data, owner);
2076
2079
  this.cameraList.push(camera);
2077
2080
  return camera;
2078
2081
  };
@@ -2119,7 +2122,7 @@ var PCameraManager = /** @class */ (function () {
2119
2122
  * @param clipMode - 剪裁模式
2120
2123
  */
2121
2124
  PCameraManager.prototype.updateDefaultCamera = function (fovy, aspect, nearPlane, farPlane, position, rotation, clipMode) {
2122
- this.defaultCamera.fovy = fovy;
2125
+ this.defaultCamera.fov = fovy;
2123
2126
  this.defaultCamera.aspect = aspect;
2124
2127
  this.defaultCamera.nearPlane = nearPlane;
2125
2128
  this.defaultCamera.farPlane = farPlane;
@@ -2174,10 +2177,12 @@ var PLight = /** @class */ (function (_super) {
2174
2177
  __extends(PLight, _super);
2175
2178
  /**
2176
2179
  * 创建灯光对象
2177
- * @param light - 灯光参数
2178
- * @param ownerI - 所属灯光组件
2180
+ * @param name - 灯光名称
2181
+ * @param data - 灯光相关数据
2182
+ * @param owner - 所属灯光组件
2179
2183
  */
2180
- function PLight(name, options, owner) {
2184
+ function PLight(name, data, owner) {
2185
+ var _a, _b, _c, _d;
2181
2186
  var _this = _super.call(this) || this;
2182
2187
  /**
2183
2188
  * 方向,仅用于方向光和聚光灯
@@ -2217,20 +2222,20 @@ var PLight = /** @class */ (function (_super) {
2217
2222
  _this.outerConeAngle = 0;
2218
2223
  _this.innerConeAngle = 0;
2219
2224
  //
2220
- var pluginColor = PluginHelper.toPluginColor4(options.color);
2221
- _this.color = new Vector3(pluginColor[0], pluginColor[1], pluginColor[2]);
2222
- _this.intensity = options.intensity;
2223
- if (options.lightType === 'point') {
2225
+ var color = data.color;
2226
+ _this.color = new Vector3(color.r, color.g, color.b);
2227
+ _this.intensity = data.intensity;
2228
+ if (data.lightType === 'point') {
2224
2229
  _this.lightType = PLightType.point;
2225
- _this.range = options.range;
2230
+ _this.range = (_a = data.range) !== null && _a !== void 0 ? _a : -1;
2226
2231
  }
2227
- else if (options.lightType === 'spot') {
2232
+ else if (data.lightType === 'spot') {
2228
2233
  _this.lightType = PLightType.spot;
2229
- _this.range = options.range;
2230
- _this.outerConeAngle = options.outerConeAngle;
2231
- _this.innerConeAngle = options.innerConeAngle;
2234
+ _this.range = (_b = data.range) !== null && _b !== void 0 ? _b : -1;
2235
+ _this.outerConeAngle = (_c = data.outerConeAngle) !== null && _c !== void 0 ? _c : Math.PI;
2236
+ _this.innerConeAngle = (_d = data.innerConeAngle) !== null && _d !== void 0 ? _d : 0;
2232
2237
  }
2233
- else if (options.lightType === 'directional') {
2238
+ else if (data.lightType === 'directional') {
2234
2239
  _this.lightType = PLightType.directional;
2235
2240
  }
2236
2241
  else {
@@ -2546,12 +2551,12 @@ var PMesh = /** @class */ (function (_super) {
2546
2551
  * 构造函数,创建 Mesh 对象,并与所属组件和父元素相关联
2547
2552
  * @param engine - 引擎
2548
2553
  * @param name - 名称
2549
- * @param meshContent - Mesh 参数
2554
+ * @param meshData - Mesh 参数
2550
2555
  * @param owner - 所属的 Mesh 组件
2551
2556
  * @param parentId - 父元素索引
2552
2557
  * @param parent - 父元素
2553
2558
  */
2554
- function PMesh(engine, name, meshContent, owner, parentId, parent) {
2559
+ function PMesh(engine, name, meshData, owner, parentId, parent) {
2555
2560
  var _a;
2556
2561
  var _this = _super.call(this) || this;
2557
2562
  _this.engine = engine;
@@ -2587,7 +2592,7 @@ var PMesh = /** @class */ (function (_super) {
2587
2592
  * 是否销毁
2588
2593
  */
2589
2594
  _this.isDisposed = false;
2590
- var proxy = new EffectsMeshProxy(meshContent, parent);
2595
+ var proxy = new EffectsMeshProxy(meshData, parent);
2591
2596
  _this.name = name;
2592
2597
  _this.type = PObjectType.mesh;
2593
2598
  _this.visible = false;
@@ -2610,7 +2615,7 @@ var PMesh = /** @class */ (function (_super) {
2610
2615
  if (_this.primitives.length <= 0) {
2611
2616
  console.warn("No primitive inside mesh item ".concat(name));
2612
2617
  }
2613
- _this.boundingBox = _this.getItemBoundingBox(meshContent.interaction);
2618
+ _this.boundingBox = _this.getItemBoundingBox(meshData.interaction);
2614
2619
  return _this;
2615
2620
  }
2616
2621
  /**
@@ -2880,15 +2885,15 @@ var PPrimitive = /** @class */ (function () {
2880
2885
  }
2881
2886
  /**
2882
2887
  * 创建 Primitive 对象
2883
- * @param options - Primitive 参数
2888
+ * @param data - Primitive 参数
2884
2889
  * @param parent - 所属 Mesh 对象
2885
2890
  */
2886
- PPrimitive.prototype.create = function (options, parent) {
2891
+ PPrimitive.prototype.create = function (data, parent) {
2887
2892
  this.parent = parent;
2888
2893
  this.skin = parent.skin;
2889
2894
  this.morph = parent.morph;
2890
- this.setGeometry(options.geometry);
2891
- this.setMaterial(options.material);
2895
+ this.setGeometry(data.geometry);
2896
+ this.setMaterial(data.material);
2892
2897
  this.name = parent.name;
2893
2898
  this.effectsPriority = parent.priority;
2894
2899
  this.geometry.setHide(parent.hide);
@@ -2932,15 +2937,36 @@ var PPrimitive = /** @class */ (function () {
2932
2937
  //newSemantics["uView"] = 'VIEWINVERSE';
2933
2938
  newSemantics['u_ModelMatrix'] = 'MODEL';
2934
2939
  newSemantics['uEditorTransform'] = 'EDITOR_TRANSFORM';
2935
- var material = Material.create(this.engine, {
2936
- shader: {
2940
+ var material;
2941
+ var isWebGL2 = PGlobalState.getInstance().isWebGL2;
2942
+ if (this.material.material) {
2943
+ material = this.material.material;
2944
+ // @ts-expect-error
2945
+ material.uniformSemantics = newSemantics;
2946
+ var shader = new Shader(this.engine);
2947
+ shader.fromData({
2948
+ id: '10000000000000000000000000000000',
2949
+ dataType: 'Shader',
2937
2950
  vertex: this.material.vertexShaderCode,
2938
2951
  fragment: this.material.fragmentShaderCode,
2939
- shared: globalState.shaderShared,
2940
- },
2941
- uniformSemantics: newSemantics,
2942
- });
2943
- this.material.setMaterialStates(material);
2952
+ // @ts-expect-error
2953
+ glslVersion: isWebGL2 ? GLSLVersion.GLSL3 : GLSLVersion.GLSL1,
2954
+ });
2955
+ // @ts-expect-error
2956
+ material.shader = shader;
2957
+ this.material.setMaterialStates(material);
2958
+ }
2959
+ else {
2960
+ material = Material.create(this.engine, {
2961
+ shader: {
2962
+ vertex: this.material.vertexShaderCode,
2963
+ fragment: this.material.fragmentShaderCode,
2964
+ shared: globalState.shaderShared,
2965
+ glslVersion: isWebGL2 ? GLSLVersion.GLSL3 : GLSLVersion.GLSL1,
2966
+ },
2967
+ uniformSemantics: newSemantics,
2968
+ });
2969
+ }
2944
2970
  var mesh = Mesh.create(this.engine, {
2945
2971
  name: this.name,
2946
2972
  material: material,
@@ -2951,6 +2977,7 @@ var PPrimitive = /** @class */ (function () {
2951
2977
  this.effectsMesh.dispose();
2952
2978
  }
2953
2979
  this.effectsMesh = mesh;
2980
+ this.material.setMaterialStates(material);
2954
2981
  };
2955
2982
  PPrimitive.prototype.getFeatureList = function (lightCount, pbrPass, skybox) {
2956
2983
  var featureList = [];
@@ -3240,7 +3267,35 @@ var PPrimitive = /** @class */ (function () {
3240
3267
  this.geometry = val;
3241
3268
  }
3242
3269
  else {
3243
- this.geometry = new PGeometry(val);
3270
+ // FIXME: 临时兼容代码,后续要解决掉
3271
+ // @ts-expect-error
3272
+ var aNormal = val.attributes['aNormal'];
3273
+ // @ts-expect-error
3274
+ var aPos = val.attributes['aPos'];
3275
+ // @ts-expect-error
3276
+ var aUV = val.attributes['aUV'];
3277
+ if (aNormal && aPos && aUV) {
3278
+ var aNormalData = val.getAttributeData('aNormal');
3279
+ var aPosData = val.getAttributeData('aPos');
3280
+ var aUVData = val.getAttributeData('aUV');
3281
+ var newGeom = Geometry.create(val.engine, {
3282
+ attributes: {
3283
+ a_Position: __assign(__assign({}, aPos), { data: aPosData }),
3284
+ a_UV1: __assign(__assign({}, aUV), { data: aUVData }),
3285
+ a_Normal: __assign(__assign({}, aNormal), { data: aNormalData }),
3286
+ },
3287
+ // @ts-expect-error
3288
+ indices: { data: val.getIndexData() },
3289
+ // @ts-expect-error
3290
+ mode: val.mode,
3291
+ drawStart: val.getDrawStart(),
3292
+ drawCount: val.getDrawCount(),
3293
+ });
3294
+ this.geometry = new PGeometry(newGeom);
3295
+ }
3296
+ else {
3297
+ this.geometry = new PGeometry(val);
3298
+ }
3244
3299
  }
3245
3300
  };
3246
3301
  /**
@@ -3424,16 +3479,15 @@ var PGeometry = /** @class */ (function () {
3424
3479
  return PGeometry;
3425
3480
  }());
3426
3481
  var EffectsMeshProxy = /** @class */ (function () {
3427
- function EffectsMeshProxy(itemContent, parentItem) {
3428
- this.itemContent = itemContent;
3482
+ function EffectsMeshProxy(itemData, parentItem) {
3483
+ this.itemData = itemData;
3429
3484
  this.parentItem = parentItem;
3430
- this.options = itemContent.options;
3485
+ this.data = itemData;
3431
3486
  // Morph 对象创建,需要为每个 Primitive 中 Geometry 对象创建 Morph
3432
3487
  // 并且要求创建的 Morph 对象状态是相同的,否则就报错
3433
3488
  var isSuccess = true;
3434
3489
  var morphObj = new PMorph();
3435
- var meshOptions = itemContent.options;
3436
- var primitives = meshOptions.primitives;
3490
+ var _a = this.data, primitives = _a.primitives, morph = _a.morph;
3437
3491
  primitives.forEach(function (prim, idx) {
3438
3492
  if (idx === 0) {
3439
3493
  morphObj.create(prim.geometry);
@@ -3453,8 +3507,8 @@ var EffectsMeshProxy = /** @class */ (function () {
3453
3507
  });
3454
3508
  if (isSuccess) {
3455
3509
  // 设置初始权重数组
3456
- if (meshOptions.weights !== undefined) {
3457
- morphObj.initWeights(meshOptions.weights);
3510
+ if ((morph === null || morph === void 0 ? void 0 : morph.weights) !== undefined) {
3511
+ morphObj.initWeights(morph.weights);
3458
3512
  }
3459
3513
  this.morphObj = morphObj;
3460
3514
  }
@@ -3478,7 +3532,7 @@ var EffectsMeshProxy = /** @class */ (function () {
3478
3532
  return this.morphObj;
3479
3533
  };
3480
3534
  EffectsMeshProxy.prototype.isHide = function () {
3481
- return this.options.hide === true;
3535
+ return this.data.hide === true;
3482
3536
  };
3483
3537
  EffectsMeshProxy.prototype.getParentNode = function () {
3484
3538
  var _a;
@@ -3490,20 +3544,23 @@ var EffectsMeshProxy = /** @class */ (function () {
3490
3544
  return undefined;
3491
3545
  };
3492
3546
  EffectsMeshProxy.prototype.getParentIndex = function () {
3493
- var _a;
3494
- return (_a = this.options.parent) !== null && _a !== void 0 ? _a : -1;
3547
+ return -1;
3495
3548
  };
3496
3549
  EffectsMeshProxy.prototype.getPrimitives = function () {
3497
- return this.options.primitives;
3550
+ return this.data.primitives;
3498
3551
  };
3499
3552
  EffectsMeshProxy.prototype.getPrimitiveCount = function () {
3500
- return this.options.primitives.length;
3553
+ return this.data.primitives.length;
3501
3554
  };
3502
3555
  EffectsMeshProxy.prototype.hasSkin = function () {
3503
- return this.options.skin !== undefined;
3556
+ // FIXME: skin
3557
+ //return this.options.skin !== undefined;
3558
+ return false;
3504
3559
  };
3505
3560
  EffectsMeshProxy.prototype.getSkinOpts = function () {
3506
- return this.options.skin;
3561
+ // FIXME: skin
3562
+ //return this.options.skin;
3563
+ return;
3507
3564
  };
3508
3565
  EffectsMeshProxy.prototype.getSkinObj = function (engine) {
3509
3566
  var skin = this.getSkinOpts();
@@ -3920,7 +3977,7 @@ var PSceneManager = /** @class */ (function () {
3920
3977
 
3921
3978
  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}";
3922
3979
 
3923
- 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}";
3980
+ 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}";
3924
3981
 
3925
3982
  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}";
3926
3983
 
@@ -3934,7 +3991,7 @@ var extensionsFragGLSL = "vec3 _dFdx(vec3 coord){\n#if defined(GL_OES_standard_d
3934
3991
 
3935
3992
  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);}";
3936
3993
 
3937
- 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 vec3 u_EmissiveFactor;uniform mat3 u_EmissiveUVTransform;\n#endif\n#ifdef HAS_EMISSIVE\nuniform vec3 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;}";
3994
+ 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;}";
3938
3995
 
3939
3996
  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";
3940
3997
 
@@ -4338,15 +4395,6 @@ function getPMeshList(player) {
4338
4395
  return meshList;
4339
4396
  }
4340
4397
 
4341
- var ModelDataType;
4342
- (function (ModelDataType) {
4343
- ModelDataType[ModelDataType["MeshComponent"] = 10000] = "MeshComponent";
4344
- ModelDataType[ModelDataType["SkyboxComponent"] = 10001] = "SkyboxComponent";
4345
- ModelDataType[ModelDataType["LightComponent"] = 10002] = "LightComponent";
4346
- ModelDataType[ModelDataType["CameraComponent"] = 10003] = "CameraComponent";
4347
- ModelDataType[ModelDataType["ModelPluginComponent"] = 10004] = "ModelPluginComponent";
4348
- ModelDataType[ModelDataType["TreeComponent"] = 10005] = "TreeComponent";
4349
- })(ModelDataType || (ModelDataType = {}));
4350
4398
  /**
4351
4399
  * 插件 Mesh 组件类,支持 3D Mesh 渲染能力
4352
4400
  * @since 2.0.0
@@ -4357,9 +4405,9 @@ var ModelMeshComponent = /** @class */ (function (_super) {
4357
4405
  /**
4358
4406
  * 构造函数,只保存传入参数,不在这里创建内部对象
4359
4407
  * @param engine - 引擎
4360
- * @param options - Mesh 参数
4408
+ * @param data - Mesh 参数
4361
4409
  */
4362
- function ModelMeshComponent(engine, options) {
4410
+ function ModelMeshComponent(engine, data) {
4363
4411
  var _this = _super.call(this, engine) || this;
4364
4412
  /**
4365
4413
  * 获取点击测试参数,根据元素包围盒进行相交测试,Mesh 对象会进行更加精确的点击测试
@@ -4414,8 +4462,8 @@ var ModelMeshComponent = /** @class */ (function (_super) {
4414
4462
  }
4415
4463
  }
4416
4464
  };
4417
- if (options) {
4418
- _this.fromData(options);
4465
+ if (data) {
4466
+ _this.fromData(data);
4419
4467
  }
4420
4468
  return _this;
4421
4469
  }
@@ -4467,22 +4515,20 @@ var ModelMeshComponent = /** @class */ (function (_super) {
4467
4515
  };
4468
4516
  /**
4469
4517
  * 反序列化,记录传入参数
4470
- * @param options - 组件参数
4518
+ * @param data - 组件参数
4471
4519
  */
4472
- ModelMeshComponent.prototype.fromData = function (options) {
4473
- _super.prototype.fromData.call(this, options);
4474
- this.options = options;
4520
+ ModelMeshComponent.prototype.fromData = function (data) {
4521
+ _super.prototype.fromData.call(this, data);
4522
+ this.data = data;
4475
4523
  };
4476
4524
  /**
4477
4525
  * 创建内部对象
4478
4526
  */
4479
4527
  ModelMeshComponent.prototype.createContent = function () {
4480
- if (this.options) {
4481
- var bounding = this.options.interaction;
4528
+ if (this.data) {
4529
+ var bounding = this.data.interaction;
4482
4530
  this.bounding = bounding && JSON.parse(JSON.stringify(bounding));
4483
- var meshOptions = this.options.options;
4484
- CheckerHelper.assertModelMeshOptions(meshOptions);
4485
- this.content = new PMesh(this.engine, this.item.name, this.options, this, this.item.parentId);
4531
+ this.content = new PMesh(this.engine, this.item.name, this.data, this, this.item.parentId);
4486
4532
  }
4487
4533
  };
4488
4534
  /**
@@ -4524,7 +4570,7 @@ var ModelMeshComponent = /** @class */ (function (_super) {
4524
4570
  }
4525
4571
  };
4526
4572
  ModelMeshComponent = __decorate([
4527
- effectsClass(ModelDataType.MeshComponent)
4573
+ effectsClass(DataType.MeshComponent)
4528
4574
  ], ModelMeshComponent);
4529
4575
  return ModelMeshComponent;
4530
4576
  }(RendererComponent));
@@ -4538,12 +4584,12 @@ var ModelSkyboxComponent = /** @class */ (function (_super) {
4538
4584
  /**
4539
4585
  * 构造函数,只保存传入参数,不在这里创建内部对象
4540
4586
  * @param engine - 引擎
4541
- * @param options - Mesh 参数
4587
+ * @param data - Mesh 参数
4542
4588
  */
4543
- function ModelSkyboxComponent(engine, options) {
4589
+ function ModelSkyboxComponent(engine, data) {
4544
4590
  var _this = _super.call(this, engine) || this;
4545
- if (options) {
4546
- _this.fromData(options);
4591
+ if (data) {
4592
+ _this.fromData(data);
4547
4593
  }
4548
4594
  return _this;
4549
4595
  }
@@ -4581,20 +4627,19 @@ var ModelSkyboxComponent = /** @class */ (function (_super) {
4581
4627
  };
4582
4628
  /**
4583
4629
  * 反序列化,记录传入参数
4584
- * @param options - 组件参数
4630
+ * @param data - 组件参数
4585
4631
  */
4586
- ModelSkyboxComponent.prototype.fromData = function (options) {
4587
- _super.prototype.fromData.call(this, options);
4588
- this.options = options;
4632
+ ModelSkyboxComponent.prototype.fromData = function (data) {
4633
+ _super.prototype.fromData.call(this, data);
4634
+ this.data = data;
4589
4635
  };
4590
4636
  /**
4591
4637
  * 创建内部对象
4592
4638
  */
4593
4639
  ModelSkyboxComponent.prototype.createContent = function () {
4594
- if (this.options) {
4595
- var skyboxOptions = this.options.options;
4596
- CheckerHelper.assertModelSkyboxOptions(skyboxOptions);
4597
- this.content = new PSkybox(this.item.name, skyboxOptions, this);
4640
+ if (this.data) {
4641
+ var skyboxData = this.data;
4642
+ this.content = new PSkybox(this.item.name, skyboxData, this);
4598
4643
  }
4599
4644
  };
4600
4645
  /**
@@ -4613,7 +4658,7 @@ var ModelSkyboxComponent = /** @class */ (function (_super) {
4613
4658
  return (_b = (_a = this.content) === null || _a === void 0 ? void 0 : _a.visible) !== null && _b !== void 0 ? _b : false;
4614
4659
  };
4615
4660
  ModelSkyboxComponent = __decorate([
4616
- effectsClass(ModelDataType.SkyboxComponent)
4661
+ effectsClass(DataType.SkyboxComponent)
4617
4662
  ], ModelSkyboxComponent);
4618
4663
  return ModelSkyboxComponent;
4619
4664
  }(RendererComponent));
@@ -4627,12 +4672,12 @@ var ModelLightComponent = /** @class */ (function (_super) {
4627
4672
  /**
4628
4673
  * 构造函数,只保存传入参数,不在这里创建内部对象
4629
4674
  * @param engine - 引擎
4630
- * @param options - Mesh 参数
4675
+ * @param data - Mesh 参数
4631
4676
  */
4632
- function ModelLightComponent(engine, options) {
4677
+ function ModelLightComponent(engine, data) {
4633
4678
  var _this = _super.call(this, engine) || this;
4634
- if (options) {
4635
- _this.fromData(options);
4679
+ if (data) {
4680
+ _this.fromData(data);
4636
4681
  }
4637
4682
  return _this;
4638
4683
  }
@@ -4661,20 +4706,19 @@ var ModelLightComponent = /** @class */ (function (_super) {
4661
4706
  };
4662
4707
  /**
4663
4708
  * 反序列化,记录传入参数
4664
- * @param options - 组件参数
4709
+ * @param data - 组件参数
4665
4710
  */
4666
- ModelLightComponent.prototype.fromData = function (options) {
4667
- _super.prototype.fromData.call(this, options);
4668
- this.options = options;
4711
+ ModelLightComponent.prototype.fromData = function (data) {
4712
+ _super.prototype.fromData.call(this, data);
4713
+ this.data = data;
4669
4714
  };
4670
4715
  /**
4671
4716
  * 创建内部对象
4672
4717
  */
4673
4718
  ModelLightComponent.prototype.createContent = function () {
4674
- if (this.options) {
4675
- var lightOptions = this.options.options;
4676
- CheckerHelper.assertModelLightOptions(lightOptions);
4677
- this.content = new PLight(this.item.name, lightOptions, this);
4719
+ if (this.data) {
4720
+ var lightData = this.data;
4721
+ this.content = new PLight(this.item.name, lightData, this);
4678
4722
  }
4679
4723
  };
4680
4724
  /**
@@ -4693,7 +4737,7 @@ var ModelLightComponent = /** @class */ (function (_super) {
4693
4737
  return (_b = (_a = this.content) === null || _a === void 0 ? void 0 : _a.visible) !== null && _b !== void 0 ? _b : false;
4694
4738
  };
4695
4739
  ModelLightComponent = __decorate([
4696
- effectsClass(ModelDataType.LightComponent)
4740
+ effectsClass(DataType.LightComponent)
4697
4741
  ], ModelLightComponent);
4698
4742
  return ModelLightComponent;
4699
4743
  }(ItemBehaviour));
@@ -4707,12 +4751,12 @@ var ModelCameraComponent = /** @class */ (function (_super) {
4707
4751
  /**
4708
4752
  * 构造函数,只保存传入参数,不在这里创建内部对象
4709
4753
  * @param engine - 引擎
4710
- * @param options - Mesh 参数
4754
+ * @param data - Mesh 参数
4711
4755
  */
4712
- function ModelCameraComponent(engine, options) {
4756
+ function ModelCameraComponent(engine, data) {
4713
4757
  var _this = _super.call(this, engine) || this;
4714
- if (options) {
4715
- _this.fromData(options);
4758
+ if (data) {
4759
+ _this.fromData(data);
4716
4760
  }
4717
4761
  return _this;
4718
4762
  }
@@ -4742,22 +4786,21 @@ var ModelCameraComponent = /** @class */ (function (_super) {
4742
4786
  };
4743
4787
  /**
4744
4788
  * 反序列化,记录传入参数
4745
- * @param options - 组件参数
4789
+ * @param data - 组件参数
4746
4790
  */
4747
- ModelCameraComponent.prototype.fromData = function (options) {
4748
- _super.prototype.fromData.call(this, options);
4749
- this.options = options;
4791
+ ModelCameraComponent.prototype.fromData = function (data) {
4792
+ _super.prototype.fromData.call(this, data);
4793
+ this.data = data;
4750
4794
  };
4751
4795
  /**
4752
4796
  * 创建内部对象
4753
4797
  */
4754
4798
  ModelCameraComponent.prototype.createContent = function () {
4755
- if (this.options) {
4756
- var cameraOptions = this.options.options;
4757
- CheckerHelper.assertModelCameraOptions(cameraOptions);
4799
+ if (this.data) {
4800
+ var cameraData = this.data;
4758
4801
  var width = this.engine.renderer.getWidth();
4759
4802
  var height = this.engine.renderer.getHeight();
4760
- this.content = new PCamera(this.item.name, width, height, cameraOptions, this);
4803
+ this.content = new PCamera(this.item.name, width, height, cameraData, this);
4761
4804
  }
4762
4805
  };
4763
4806
  /**
@@ -4771,7 +4814,7 @@ var ModelCameraComponent = /** @class */ (function (_super) {
4771
4814
  composition.camera.setQuat(this.transform.quat);
4772
4815
  composition.camera.near = this.content.nearPlane;
4773
4816
  composition.camera.far = this.content.farPlane;
4774
- composition.camera.fov = this.content.fovy;
4817
+ composition.camera.fov = this.content.fov;
4775
4818
  }
4776
4819
  };
4777
4820
  /**
@@ -4797,7 +4840,7 @@ var ModelCameraComponent = /** @class */ (function (_super) {
4797
4840
  this.updateMainCamera();
4798
4841
  };
4799
4842
  ModelCameraComponent = __decorate([
4800
- effectsClass(ModelDataType.CameraComponent)
4843
+ effectsClass(DataType.CameraComponent)
4801
4844
  ], ModelCameraComponent);
4802
4845
  return ModelCameraComponent;
4803
4846
  }(ItemBehaviour));
@@ -5463,11 +5506,13 @@ var MeshHelper = /** @class */ (function () {
5463
5506
  var vertexShader = material.vertexShaderCode;
5464
5507
  var fragmentShader = material.fragmentShaderCode;
5465
5508
  var geometry = Geometry.create(engine, MeshHelper.getPlaneGeometry());
5509
+ var isWebGL2 = engine.gpuCapability.level === 2;
5466
5510
  var effectsMaterial = Material.create(engine, {
5467
5511
  shader: {
5468
5512
  vertex: vertexShader,
5469
5513
  fragment: fragmentShader,
5470
5514
  shared: globalState.shaderShared,
5515
+ glslVersion: isWebGL2 ? GLSLVersion.GLSL3 : GLSLVersion.GLSL1,
5471
5516
  },
5472
5517
  uniformSemantics: uniformSemantics,
5473
5518
  });
@@ -7646,6 +7691,7 @@ var PMaterialBase = /** @class */ (function (_super) {
7646
7691
  __extends(PMaterialBase, _super);
7647
7692
  function PMaterialBase() {
7648
7693
  var _this = _super !== null && _super.apply(this, arguments) || this;
7694
+ _this.fromMaterial = false;
7649
7695
  /**
7650
7696
  * 材质类型,主要是 pbr 和 unlit 两类
7651
7697
  */
@@ -7718,6 +7764,19 @@ var PMaterialBase = /** @class */ (function (_super) {
7718
7764
  * @param inFeatureList - 外部特性列表
7719
7765
  */
7720
7766
  PMaterialBase.prototype.build = function (inFeatureList) {
7767
+ var finalFeatureList = this.getFeatureList(inFeatureList);
7768
+ var isWebGL2 = PGlobalState.getInstance().isWebGL2;
7769
+ //
7770
+ var shaderManager = PShaderManager.getInstance();
7771
+ var shaderResult = shaderManager.genShaderCode({
7772
+ material: this,
7773
+ isWebGL2: isWebGL2,
7774
+ featureList: finalFeatureList,
7775
+ });
7776
+ this.vertexShaderCode = shaderResult.vertexShaderCode;
7777
+ this.fragmentShaderCode = shaderResult.fragmentShaderCode;
7778
+ };
7779
+ PMaterialBase.prototype.getFeatureList = function (inFeatureList) {
7721
7780
  var finalFeatureList = this.getShaderFeatures();
7722
7781
  if (inFeatureList !== undefined) {
7723
7782
  finalFeatureList.push.apply(finalFeatureList, __spreadArray([], __read(inFeatureList), false));
@@ -7734,15 +7793,7 @@ var PMaterialBase = /** @class */ (function (_super) {
7734
7793
  finalFeatureList.push('EDITOR_TRANSFORM');
7735
7794
  }
7736
7795
  }
7737
- //
7738
- var shaderManager = PShaderManager.getInstance();
7739
- var shaderResult = shaderManager.genShaderCode({
7740
- material: this,
7741
- isWebGL2: isWebGL2,
7742
- featureList: finalFeatureList,
7743
- });
7744
- this.vertexShaderCode = shaderResult.vertexShaderCode;
7745
- this.fragmentShaderCode = shaderResult.fragmentShaderCode;
7796
+ return finalFeatureList;
7746
7797
  };
7747
7798
  /**
7748
7799
  * 获取混合模式,根据 GE 混合模式
@@ -8054,9 +8105,9 @@ var PMaterialPBR = /** @class */ (function (_super) {
8054
8105
  */
8055
8106
  _this.occlusionTextureStrength = 1;
8056
8107
  /**
8057
- * 自发光颜色值,默认是黑色 Vector3(0, 0, 0)
8108
+ * 自发光颜色值,默认是黑色 Vector4(0, 0, 0, 0)
8058
8109
  */
8059
- _this.emissiveFactor = new Vector3(0, 0, 0);
8110
+ _this.emissiveFactor = new Vector4(0, 0, 0, 0);
8060
8111
  /**
8061
8112
  * 自发光强度
8062
8113
  */
@@ -8112,7 +8163,7 @@ var PMaterialPBR = /** @class */ (function (_super) {
8112
8163
  this.emissiveTextureTrans = PluginHelper.createUVTransform(options.emissiveTextureTransform);
8113
8164
  }
8114
8165
  var emissiveFactor = PluginHelper.toPluginColor4(options.emissiveFactor);
8115
- this.emissiveFactor = Vector3.fromArray(emissiveFactor);
8166
+ this.setEmissiveFactor(Vector3.fromArray(emissiveFactor));
8116
8167
  this.emissiveIntensity = options.emissiveIntensity;
8117
8168
  this.enableShadow = (_d = options.enableShadow) !== null && _d !== void 0 ? _d : false;
8118
8169
  /**
@@ -8128,6 +8179,39 @@ var PMaterialPBR = /** @class */ (function (_super) {
8128
8179
  this.alphaCutOff = (_e = options.alphaCutOff) !== null && _e !== void 0 ? _e : 0;
8129
8180
  this.faceSideMode = this.getFaceSideMode(options.side);
8130
8181
  };
8182
+ PMaterialPBR.prototype.createFromMaterial = function (mat) {
8183
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
8184
+ this.fromMaterial = true;
8185
+ this.material = mat;
8186
+ this.name = mat.name;
8187
+ this.type = PObjectType.material;
8188
+ this.materialType = mat.getInt('shaderType') ? PMaterialType.unlit : PMaterialType.pbr;
8189
+ //
8190
+ this.baseColorTexture = (_a = mat.getTexture('u_BaseColorSampler')) !== null && _a !== void 0 ? _a : undefined;
8191
+ this.baseColorFactor = (_b = mat.getVector4('u_BaseColorFactor')) !== null && _b !== void 0 ? _b : new Vector4(255, 255, 255, 255);
8192
+ this.baseColorFactor.multiply(1 / 255.0);
8193
+ this.metallicRoughnessTexture = (_c = mat.getTexture('u_MetallicRoughnessSampler')) !== null && _c !== void 0 ? _c : undefined;
8194
+ this.useSpecularAA = mat.getInt('useSpecularAA') === 1;
8195
+ this.metallicFactor = (_d = mat.getFloat('u_MetallicFactor')) !== null && _d !== void 0 ? _d : 1;
8196
+ this.roughnessFactor = (_e = mat.getFloat('u_RoughnessFactor')) !== null && _e !== void 0 ? _e : 1;
8197
+ this.normalTexture = (_f = mat.getTexture('u_NormalSampler')) !== null && _f !== void 0 ? _f : undefined;
8198
+ this.normalTextureScale = (_g = mat.getFloat('u_NormalScale')) !== null && _g !== void 0 ? _g : 1;
8199
+ this.occlusionTexture = (_h = mat.getTexture('u_OcclusionSampler')) !== null && _h !== void 0 ? _h : undefined;
8200
+ this.occlusionTextureStrength = (_j = mat.getFloat('u_OcclusionTextureStrength')) !== null && _j !== void 0 ? _j : 1;
8201
+ this.emissiveTexture = (_k = mat.getTexture('u_EmissiveSampler')) !== null && _k !== void 0 ? _k : undefined;
8202
+ this.emissiveFactor = (_l = mat.getVector4('u_EmissiveFactor')) !== null && _l !== void 0 ? _l : new Vector4(0, 0, 0, 0);
8203
+ this.emissiveFactor.multiply(1 / 255.0);
8204
+ this.emissiveIntensity = (_m = mat.getFloat('u_EmissiveIntensity')) !== null && _m !== void 0 ? _m : 1;
8205
+ var emissiveFactor = this.emissiveFactor.clone().multiply(this.emissiveIntensity);
8206
+ mat.setVector4('u_EmissiveFactor', emissiveFactor);
8207
+ this.enableShadow = false;
8208
+ this.depthMask = false;
8209
+ var blending = (_o = mat.getInt('blending')) !== null && _o !== void 0 ? _o : spec.MaterialBlending.opaque;
8210
+ this.blendMode = this.getBlendMode(blending);
8211
+ this.alphaCutOff = (_p = mat.getFloat('u_AlphaCutoff')) !== null && _p !== void 0 ? _p : 0;
8212
+ var side = (_q = mat.getInt('side')) !== null && _q !== void 0 ? _q : spec.SideMode.FRONT;
8213
+ this.faceSideMode = this.getFaceSideMode(side);
8214
+ };
8131
8215
  /**
8132
8216
  * 销毁材质
8133
8217
  */
@@ -8190,6 +8274,35 @@ var PMaterialPBR = /** @class */ (function (_super) {
8190
8274
  */
8191
8275
  PMaterialPBR.prototype.updateUniforms = function (material) {
8192
8276
  _super.prototype.updateUniforms.call(this, material);
8277
+ if (this.fromMaterial) {
8278
+ var uvTransform_1 = new Matrix3().identity();
8279
+ if (this.baseColorTexture !== undefined) {
8280
+ material.setInt('u_BaseColorUVSet', 0);
8281
+ material.setMatrix3('u_BaseColorUVTransform', uvTransform_1);
8282
+ }
8283
+ //
8284
+ if (this.metallicRoughnessTexture !== undefined) {
8285
+ material.setInt('u_MetallicRoughnessUVSet', 0);
8286
+ material.setMatrix3('u_MetallicRoughnessUVTransform', uvTransform_1);
8287
+ }
8288
+ //
8289
+ if (this.normalTexture !== undefined) {
8290
+ material.setInt('u_NormalUVSet', 0);
8291
+ material.setMatrix3('u_NormalUVTransform', uvTransform_1);
8292
+ }
8293
+ //
8294
+ if (this.occlusionTexture !== undefined) {
8295
+ material.setInt('u_OcclusionUVSet', 0);
8296
+ material.setMatrix3('u_OcclusionUVTransform', uvTransform_1);
8297
+ }
8298
+ //
8299
+ if (this.emissiveTexture !== undefined) {
8300
+ material.setInt('u_EmissiveUVSet', 0);
8301
+ material.setMatrix3('u_EmissiveUVTransform', uvTransform_1);
8302
+ }
8303
+ material.setFloat('u_Exposure', 3.0);
8304
+ return;
8305
+ }
8193
8306
  //
8194
8307
  var uvTransform = new Matrix3().identity();
8195
8308
  material.setVector4('u_BaseColorFactor', this.baseColorFactor);
@@ -8248,7 +8361,7 @@ var PMaterialPBR = /** @class */ (function (_super) {
8248
8361
  if (this.emissiveTexture !== undefined) {
8249
8362
  var emissiveFactor = this.getEmissiveFactor();
8250
8363
  material.setTexture('u_EmissiveSampler', this.emissiveTexture);
8251
- material.setVector3('u_EmissiveFactor', emissiveFactor);
8364
+ material.setVector4('u_EmissiveFactor', emissiveFactor);
8252
8365
  material.setInt('u_EmissiveUVSet', 0);
8253
8366
  if (this.emissiveTextureTrans !== undefined) {
8254
8367
  material.setMatrix3('u_EmissiveUVTransform', this.emissiveTextureTrans);
@@ -8260,7 +8373,7 @@ var PMaterialPBR = /** @class */ (function (_super) {
8260
8373
  }
8261
8374
  else if (this.hasEmissiveFactor()) {
8262
8375
  var emissiveFactor = this.getEmissiveFactor();
8263
- material.setVector3('u_EmissiveFactor', emissiveFactor);
8376
+ material.setVector4('u_EmissiveFactor', emissiveFactor);
8264
8377
  }
8265
8378
  material.setFloat('u_Exposure', 3.0);
8266
8379
  };
@@ -8439,11 +8552,17 @@ var PMaterialPBR = /** @class */ (function (_super) {
8439
8552
  PMaterialPBR.prototype.setEmissiveFactor = function (val) {
8440
8553
  if (val instanceof Vector3) {
8441
8554
  // Vector3
8442
- this.emissiveFactor.set(val.x, val.y, val.z);
8555
+ this.emissiveFactor.set(val.x, val.y, val.z, 0);
8443
8556
  }
8444
8557
  else {
8445
8558
  // vec3
8446
- this.emissiveFactor.set(val[0], val[1], val[2]);
8559
+ this.emissiveFactor.set(val[0], val[1], val[2], 0);
8560
+ }
8561
+ };
8562
+ PMaterialPBR.prototype.getTextureFromMaterial = function (mat, texName) {
8563
+ var tex = mat.getTexture(texName);
8564
+ if (tex !== null) {
8565
+ return tex;
8447
8566
  }
8448
8567
  };
8449
8568
  return PMaterialPBR;
@@ -8454,15 +8573,22 @@ var PMaterialPBR = /** @class */ (function (_super) {
8454
8573
  * @returns 材质对象
8455
8574
  */
8456
8575
  function createPluginMaterial(options) {
8457
- if (options.type === spec.MaterialType.pbr) {
8576
+ if (options instanceof Material) {
8458
8577
  var materialPBR = new PMaterialPBR();
8459
- materialPBR.create(options);
8578
+ materialPBR.createFromMaterial(options);
8460
8579
  return materialPBR;
8461
8580
  }
8462
8581
  else {
8463
- var materialUnlit = new PMaterialUnlit();
8464
- materialUnlit.create(options);
8465
- return materialUnlit;
8582
+ if (options.type === spec.MaterialType.pbr) {
8583
+ var materialPBR = new PMaterialPBR();
8584
+ materialPBR.create(options);
8585
+ return materialPBR;
8586
+ }
8587
+ else {
8588
+ var materialUnlit = new PMaterialUnlit();
8589
+ materialUnlit.create(options);
8590
+ return materialUnlit;
8591
+ }
8466
8592
  }
8467
8593
  }
8468
8594
  function createInternalMaterial(options) {
@@ -8477,10 +8603,10 @@ var PSkybox = /** @class */ (function (_super) {
8477
8603
  /**
8478
8604
  * 构造函数
8479
8605
  * @param name - 名称
8480
- * @param options - 天空盒参数
8606
+ * @param data - 天空盒参数
8481
8607
  * @param owner - 所属天空盒组件元素
8482
8608
  */
8483
- function PSkybox(name, options, owner) {
8609
+ function PSkybox(name, data, owner) {
8484
8610
  var _a;
8485
8611
  var _this = _super.call(this) || this;
8486
8612
  /**
@@ -8515,14 +8641,27 @@ var PSkybox = /** @class */ (function (_super) {
8515
8641
  _this.type = PObjectType.skybox;
8516
8642
  _this.visible = false;
8517
8643
  _this.owner = owner;
8518
- _this.renderable = options.renderable;
8519
- _this.intensity = options.intensity;
8520
- _this.reflectionsIntensity = options.reflectionsIntensity;
8521
- _this.irradianceCoeffs = options.irradianceCoeffs;
8522
- _this.diffuseImage = options.diffuseImage;
8523
- _this.specularImage = options.specularImage;
8524
- _this.specularImageSize = options.specularImageSize;
8525
- _this.specularMipCount = options.specularMipCount;
8644
+ var irradianceCoeffs = data.irradianceCoeffs;
8645
+ _this.renderable = data.renderable;
8646
+ _this.intensity = data.intensity;
8647
+ _this.reflectionsIntensity = data.reflectionsIntensity;
8648
+ if (irradianceCoeffs) {
8649
+ _this.irradianceCoeffs = [];
8650
+ for (var i = 0; i < irradianceCoeffs.length; i += 3) {
8651
+ _this.irradianceCoeffs.push([
8652
+ irradianceCoeffs[i],
8653
+ irradianceCoeffs[i + 1],
8654
+ irradianceCoeffs[i + 2],
8655
+ ]);
8656
+ }
8657
+ }
8658
+ else {
8659
+ _this.irradianceCoeffs = [];
8660
+ }
8661
+ _this.diffuseImage = data.diffuseImage;
8662
+ _this.specularImage = data.specularImage;
8663
+ _this.specularImageSize = data.specularImageSize;
8664
+ _this.specularMipCount = data.specularMipCount;
8526
8665
  _this.priority = ((_a = owner === null || owner === void 0 ? void 0 : owner.item) === null || _a === void 0 ? void 0 : _a.listIndex) || 0;
8527
8666
  return _this;
8528
8667
  }
@@ -8587,7 +8726,7 @@ var PSkybox = /** @class */ (function (_super) {
8587
8726
  var sceneStates = scene.sceneStates;
8588
8727
  var camera = sceneStates.camera;
8589
8728
  var viewMatrix = sceneStates.viewMatrix;
8590
- var newProjViewMatrix = camera.getNewProjectionMatrix(camera.fovy).multiply(viewMatrix).invert();
8729
+ var newProjViewMatrix = camera.getNewProjectionMatrix(camera.fov).multiply(viewMatrix).invert();
8591
8730
  var material = this.skyboxMesh.material;
8592
8731
  this.skyboxMaterial.updateUniforms(material);
8593
8732
  material.setMatrix('u_InvViewProjectionMatrix', newProjViewMatrix);
@@ -9395,6 +9534,28 @@ var ModelPlugin = /** @class */ (function (_super) {
9395
9534
  });
9396
9535
  });
9397
9536
  };
9537
+ ModelPlugin.precompile = function (compositions, renderer) {
9538
+ var isWebGL2 = renderer.engine.gpuCapability.level === 2;
9539
+ var context = {
9540
+ // @ts-expect-error
9541
+ material: {
9542
+ materialType: PMaterialType.pbr,
9543
+ },
9544
+ isWebGL2: isWebGL2,
9545
+ featureList: [],
9546
+ };
9547
+ var pbrShader = getPBRPassShaderCode(context);
9548
+ renderer.engine.addEffectsObjectData({
9549
+ // FIXME: 'unlit000000000000000000000000000',
9550
+ id: 'pbr00000000000000000000000000000',
9551
+ dataType: 'Shader',
9552
+ // @ts-expect-error
9553
+ fragment: pbrShader.fragmentShaderCode,
9554
+ vertex: pbrShader.vertexShaderCode,
9555
+ glslVersion: isWebGL2 ? GLSLVersion.GLSL3 : GLSLVersion.GLSL1,
9556
+ });
9557
+ return Promise.resolve();
9558
+ };
9398
9559
  /**
9399
9560
  * 创建 3D 场景管理器和缓存器
9400
9561
  * @param composition - 合成
@@ -9591,14 +9752,14 @@ var ModelPluginComponent = /** @class */ (function (_super) {
9591
9752
  var lightItemCount = 0;
9592
9753
  var items = (_b = (_a = this.item.composition) === null || _a === void 0 ? void 0 : _a.items) !== null && _b !== void 0 ? _b : [];
9593
9754
  items.forEach(function (item) {
9594
- if (item.type === spec.ItemType.light) {
9755
+ if (item.getComponent(ModelLightComponent)) {
9595
9756
  lightItemCount++;
9596
9757
  }
9597
9758
  });
9598
9759
  return lightItemCount;
9599
9760
  };
9600
9761
  ModelPluginComponent = __decorate([
9601
- effectsClass(ModelDataType.ModelPluginComponent)
9762
+ effectsClass(DataType.ModelPluginComponent)
9602
9763
  ], ModelPluginComponent);
9603
9764
  return ModelPluginComponent;
9604
9765
  }(ItemBehaviour));
@@ -9811,7 +9972,7 @@ var ModelTreeComponent = /** @class */ (function (_super) {
9811
9972
  }
9812
9973
  };
9813
9974
  ModelTreeComponent = __decorate([
9814
- effectsClass(ModelDataType.TreeComponent)
9975
+ effectsClass(DataType.TreeComponent)
9815
9976
  ], ModelTreeComponent);
9816
9977
  return ModelTreeComponent;
9817
9978
  }(ItemBehaviour));
@@ -9863,7 +10024,7 @@ var CameraGestureHandlerImp = /** @class */ (function () {
9863
10024
  CameraGestureHandlerImp.prototype.getItem = function () {
9864
10025
  var _this = this;
9865
10026
  var _a;
9866
- return (_a = this.composition.items) === null || _a === void 0 ? void 0 : _a.find(function (item) { return item.id === _this.getCurrentTarget(); });
10027
+ return (_a = this.composition.items) === null || _a === void 0 ? void 0 : _a.find(function (item) { return item.name === _this.getCurrentTarget(); });
9867
10028
  };
9868
10029
  CameraGestureHandlerImp.prototype.getCurrentTarget = function () {
9869
10030
  return this.startParams.target;
@@ -10920,7 +11081,7 @@ var LoaderImpl = /** @class */ (function () {
10920
11081
  name: 'skybox',
10921
11082
  duration: this.getItemDuration(),
10922
11083
  endBehavior: this.getItemEndBehavior(),
10923
- type: 'skybox',
11084
+ type: spec.ItemType.skybox,
10924
11085
  pluginName: 'model',
10925
11086
  content: {
10926
11087
  options: this._skyboxOptions,
@@ -11644,8 +11805,8 @@ var GLTFHelper = /** @class */ (function () {
11644
11805
 
11645
11806
  registerPlugin('tree', ModelTreePlugin, VFXItem, true);
11646
11807
  registerPlugin('model', ModelPlugin, VFXItem);
11647
- var version = "2.0.0-alpha.2";
11808
+ var version = "2.0.0-alpha.4";
11648
11809
  logger.info('plugin model version: ' + version);
11649
11810
 
11650
- export { BoxMesh, CameraGestureHandlerImp, CameraGestureType, CheckerHelper, CompositionCache, CompositionHitTest, FBOOptions, Float16ArrayWrapper, GeometryBoxProxy, HitTestingProxy, HookOGLFunc, InterpolationSampler, LoaderHelper, LoaderImpl, MeshHelper, ModelCameraComponent, ModelDataType, ModelLightComponent, ModelMeshComponent, ModelPlugin, ModelPluginComponent, ModelSkyboxComponent, ModelTreeComponent, ModelTreeItem, ModelTreePlugin, PAnimInterpType, PAnimPathType, PAnimTexture, PAnimTrack, PAnimation, PAnimationManager, PBlendMode, PCamera, PCameraManager, PCoordinate, PEntity, PFaceSideMode, PGeometry, PGlobalState, PLight, PLightManager, PLightType, PMaterialBase, PMaterialPBR, PMaterialSkyboxFilter, PMaterialType, PMaterialUnlit, PMesh, PMorph, PObject, PObjectType, PPrimitive, PSceneManager, PShaderManager, PShadowType, PSkin, PSkybox, PSkyboxCreator, PSkyboxType, PTextureType, PTransform, PluginHelper, RayBoxTesting, RayIntersectsBoxWithRotation, RayTriangleTesting, TextureDataMode, ToggleItemBounding, TwoStatesSet, VFX_ITEM_TYPE_3D, VertexAttribBuffer, WebGLHelper, WebHelper, createAnimationSampler, createInternalMaterial, createPluginMaterial, getDefaultEffectsGLTFLoader, getDiffuseOnlyShaderCode, getGaussianBlurShaderCodeV1, getGaussianBlurShaderCodeV2, getKawaseBlurShaderCode, getNormalVisShaderCode, getPBRPassShaderCode, getPMeshList, getQuadFilterShaderCode, getRendererGPUInfo, getSceneManager, getShadowPassShaderCode, getSimpleFilterShaderCode, getSkyBoxShaderCode, getTransparecyBaseShader, getTransparecyFilterShader, setDefaultEffectsGLTFLoader, version };
11811
+ export { BoxMesh, CameraGestureHandlerImp, CameraGestureType, CheckerHelper, CompositionCache, CompositionHitTest, FBOOptions, Float16ArrayWrapper, GeometryBoxProxy, HitTestingProxy, HookOGLFunc, InterpolationSampler, LoaderHelper, LoaderImpl, MeshHelper, ModelCameraComponent, ModelLightComponent, ModelMeshComponent, ModelPlugin, ModelPluginComponent, ModelSkyboxComponent, ModelTreeComponent, ModelTreeItem, ModelTreePlugin, PAnimInterpType, PAnimPathType, PAnimTexture, PAnimTrack, PAnimation, PAnimationManager, PBlendMode, PCamera, PCameraManager, PCoordinate, PEntity, PFaceSideMode, PGeometry, PGlobalState, PLight, PLightManager, PLightType, PMaterialBase, PMaterialPBR, PMaterialSkyboxFilter, PMaterialType, PMaterialUnlit, PMesh, PMorph, PObject, PObjectType, PPrimitive, PSceneManager, PShaderManager, PShadowType, PSkin, PSkybox, PSkyboxCreator, PSkyboxType, PTextureType, PTransform, PluginHelper, RayBoxTesting, RayIntersectsBoxWithRotation, RayTriangleTesting, TextureDataMode, ToggleItemBounding, TwoStatesSet, VFX_ITEM_TYPE_3D, VertexAttribBuffer, WebGLHelper, WebHelper, createAnimationSampler, createInternalMaterial, createPluginMaterial, getDefaultEffectsGLTFLoader, getDiffuseOnlyShaderCode, getGaussianBlurShaderCodeV1, getGaussianBlurShaderCodeV2, getKawaseBlurShaderCode, getNormalVisShaderCode, getPBRPassShaderCode, getPMeshList, getQuadFilterShaderCode, getRendererGPUInfo, getSceneManager, getShadowPassShaderCode, getSimpleFilterShaderCode, getSkyBoxShaderCode, getTransparecyBaseShader, getTransparecyFilterShader, setDefaultEffectsGLTFLoader, version };
11651
11812
  //# sourceMappingURL=index.mjs.map