@galacean/effects-plugin-model 2.0.0-alpha.6 → 2.0.0-alpha.7
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/gltf/loader-ecs-ext.d.ts +24 -0
- package/dist/gltf/loader-ecs.d.ts +86 -0
- package/dist/gltf/protocol.d.ts +9 -1
- package/dist/helper/index.d.ts +1 -0
- package/dist/index.js +171 -202
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +1 -1
- package/dist/index.mjs +172 -203
- package/dist/index.mjs.map +1 -1
- package/dist/loader.mjs +167 -198
- package/dist/loader.mjs.map +1 -1
- package/dist/runtime/material.d.ts +1 -2
- package/dist/runtime/mesh.d.ts +2 -2
- package/package.json +5 -5
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.7
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
'use strict';
|
|
@@ -2322,12 +2322,12 @@ function _assert_this_initialized(self) {
|
|
|
2322
2322
|
* @param lineColor - 线颜色
|
|
2323
2323
|
*/ _proto.update = function update(modelMatrix, viewProjMatrix, positions, lineColor) {
|
|
2324
2324
|
var material = this.mesh.material;
|
|
2325
|
-
material.setMatrix("
|
|
2326
|
-
material.setMatrix("
|
|
2325
|
+
material.setMatrix("_ModelMatrix", modelMatrix);
|
|
2326
|
+
material.setMatrix("_ViewProjectionMatrix", viewProjMatrix);
|
|
2327
2327
|
for(var i = 0; i < positions.length; i += 3){
|
|
2328
|
-
material.setVector3("
|
|
2328
|
+
material.setVector3("_PositionList[" + i / 3 + "]", Vector3.fromArray(positions, i));
|
|
2329
2329
|
}
|
|
2330
|
-
material.setVector3("
|
|
2330
|
+
material.setVector3("_LineColor", lineColor);
|
|
2331
2331
|
};
|
|
2332
2332
|
/**
|
|
2333
2333
|
* 销毁,需要销毁 Mesh 对象
|
|
@@ -2342,7 +2342,7 @@ function _assert_this_initialized(self) {
|
|
|
2342
2342
|
get: /**
|
|
2343
2343
|
* 获取顶点着色器代码
|
|
2344
2344
|
*/ function get() {
|
|
2345
|
-
return "\n #version 100\n precision highp float;\n\n uniform mat4
|
|
2345
|
+
return "\n #version 100\n precision highp float;\n\n uniform mat4 _ModelMatrix;\n uniform mat4 _ViewProjectionMatrix;\n uniform vec3 _PositionList[8];\n attribute vec3 aPos;\n void main(){\n int index = int(aPos.x + 0.5);\n vec4 pos = _ModelMatrix * vec4(_PositionList[index], 1);\n gl_Position = _ViewProjectionMatrix * pos;\n }\n ";
|
|
2346
2346
|
}
|
|
2347
2347
|
},
|
|
2348
2348
|
{
|
|
@@ -2350,7 +2350,7 @@ function _assert_this_initialized(self) {
|
|
|
2350
2350
|
get: /**
|
|
2351
2351
|
* 获取片段着色器代码
|
|
2352
2352
|
*/ function get() {
|
|
2353
|
-
return "\n #version 100\n precision highp float;\n\n uniform vec3
|
|
2353
|
+
return "\n #version 100\n precision highp float;\n\n uniform vec3 _LineColor;\n void main(){\n gl_FragColor = vec4(_LineColor, 1);\n }\n ";
|
|
2354
2354
|
}
|
|
2355
2355
|
},
|
|
2356
2356
|
{
|
|
@@ -2396,7 +2396,7 @@ function _assert_this_initialized(self) {
|
|
|
2396
2396
|
]);
|
|
2397
2397
|
return {
|
|
2398
2398
|
attributes: {
|
|
2399
|
-
|
|
2399
|
+
aPos: {
|
|
2400
2400
|
type: effects.glContext.FLOAT,
|
|
2401
2401
|
size: 1,
|
|
2402
2402
|
data: data,
|
|
@@ -2804,9 +2804,9 @@ function _assert_this_initialized(self) {
|
|
|
2804
2804
|
var featureList = this.getFeatureList(lightCount, true, skybox);
|
|
2805
2805
|
this.material.build(featureList);
|
|
2806
2806
|
var newSemantics = uniformSemantics != null ? uniformSemantics : {};
|
|
2807
|
-
newSemantics["
|
|
2807
|
+
newSemantics["_ViewProjectionMatrix"] = "VIEWPROJECTION";
|
|
2808
2808
|
//newSemantics["uView"] = 'VIEWINVERSE';
|
|
2809
|
-
newSemantics["
|
|
2809
|
+
newSemantics["_ModelMatrix"] = "MODEL";
|
|
2810
2810
|
newSemantics["uEditorTransform"] = "EDITOR_TRANSFORM";
|
|
2811
2811
|
var material;
|
|
2812
2812
|
var isWebGL2 = PGlobalState.getInstance().isWebGL2;
|
|
@@ -2816,7 +2816,9 @@ function _assert_this_initialized(self) {
|
|
|
2816
2816
|
material.uniformSemantics = newSemantics;
|
|
2817
2817
|
var shader = new effects.Shader(this.engine);
|
|
2818
2818
|
shader.fromData({
|
|
2819
|
-
|
|
2819
|
+
// FIXME: check shader id
|
|
2820
|
+
//id: 'pbr00000000000000000000000000000',
|
|
2821
|
+
id: effects.generateGUID(),
|
|
2820
2822
|
dataType: "Shader",
|
|
2821
2823
|
vertex: this.material.vertexShaderCode,
|
|
2822
2824
|
fragment: this.material.fragmentShaderCode,
|
|
@@ -3021,8 +3023,8 @@ function _assert_this_initialized(self) {
|
|
|
3021
3023
|
};
|
|
3022
3024
|
_proto.updateUniformsByAnimation = function updateUniformsByAnimation(worldMatrix, normalMatrix) {
|
|
3023
3025
|
var material = this.getModelMaterial();
|
|
3024
|
-
material.setMatrix("
|
|
3025
|
-
material.setMatrix("
|
|
3026
|
+
material.setMatrix("_ModelMatrix", worldMatrix);
|
|
3027
|
+
material.setMatrix("_NormalMatrix", normalMatrix);
|
|
3026
3028
|
//
|
|
3027
3029
|
var skin = this.skin;
|
|
3028
3030
|
if (skin !== undefined) {
|
|
@@ -3034,8 +3036,8 @@ function _assert_this_initialized(self) {
|
|
|
3034
3036
|
var jointNormalMatTexture = this.jointNormalMatTexture;
|
|
3035
3037
|
jointMatrixTexture.update(jointMatrixList);
|
|
3036
3038
|
jointNormalMatTexture.update(jointNormalMatList);
|
|
3037
|
-
material.setTexture("
|
|
3038
|
-
material.setTexture("
|
|
3039
|
+
material.setTexture("_jointMatrixSampler", jointMatrixTexture.getTexture());
|
|
3040
|
+
material.setTexture("_jointNormalMatrixSampler", jointNormalMatTexture.getTexture());
|
|
3039
3041
|
} else {
|
|
3040
3042
|
var jointMatrixNumbers = [];
|
|
3041
3043
|
var jointNormalMatNumbers = [];
|
|
@@ -3045,8 +3047,8 @@ function _assert_this_initialized(self) {
|
|
|
3045
3047
|
jointNormalMatList.forEach(function(val) {
|
|
3046
3048
|
return jointNormalMatNumbers.push(val);
|
|
3047
3049
|
});
|
|
3048
|
-
material.setMatrixNumberArray("
|
|
3049
|
-
material.setMatrixNumberArray("
|
|
3050
|
+
material.setMatrixNumberArray("_jointMatrix", jointMatrixNumbers);
|
|
3051
|
+
material.setMatrixNumberArray("_jointNormalMatrix", jointNormalMatNumbers);
|
|
3050
3052
|
}
|
|
3051
3053
|
}
|
|
3052
3054
|
// Morph 相关的数据更新,仅需要更新 weights 数组
|
|
@@ -3057,13 +3059,13 @@ function _assert_this_initialized(self) {
|
|
|
3057
3059
|
morphWeights.forEach(function(val) {
|
|
3058
3060
|
return morphWeightNumbers.push(val);
|
|
3059
3061
|
});
|
|
3060
|
-
material.setFloats("
|
|
3062
|
+
material.setFloats("_morphWeights", morphWeightNumbers);
|
|
3061
3063
|
}
|
|
3062
3064
|
};
|
|
3063
3065
|
_proto.updateUniformsByScene = function updateUniformsByScene(sceneStates) {
|
|
3064
3066
|
var material = this.getModelMaterial();
|
|
3065
|
-
material.setMatrix("
|
|
3066
|
-
material.setVector3("
|
|
3067
|
+
material.setMatrix("_ViewProjectionMatrix", sceneStates.viewProjectionMatrix);
|
|
3068
|
+
material.setVector3("_Camera", sceneStates.cameraPosition);
|
|
3067
3069
|
//
|
|
3068
3070
|
if (!this.isUnlitMaterial()) {
|
|
3069
3071
|
var maxLightCount = sceneStates.maxLightCount, lightList = sceneStates.lightList;
|
|
@@ -3071,33 +3073,33 @@ function _assert_this_initialized(self) {
|
|
|
3071
3073
|
if (i < lightList.length) {
|
|
3072
3074
|
var light = lightList[i];
|
|
3073
3075
|
var intensity = light.visible ? light.intensity : 0;
|
|
3074
|
-
material.setVector3("
|
|
3075
|
-
material.setFloat("
|
|
3076
|
-
material.setVector3("
|
|
3077
|
-
material.setFloat("
|
|
3078
|
-
material.setVector3("
|
|
3079
|
-
material.setFloat("
|
|
3080
|
-
material.setFloat("
|
|
3081
|
-
material.setInt("
|
|
3082
|
-
material.setVector2("
|
|
3076
|
+
material.setVector3("_Lights[" + i + "].direction", light.getWorldDirection());
|
|
3077
|
+
material.setFloat("_Lights[" + i + "].range", light.range);
|
|
3078
|
+
material.setVector3("_Lights[" + i + "].color", light.color);
|
|
3079
|
+
material.setFloat("_Lights[" + i + "].intensity", intensity);
|
|
3080
|
+
material.setVector3("_Lights[" + i + "].position", light.getWorldPosition());
|
|
3081
|
+
material.setFloat("_Lights[" + i + "].innerConeCos", Math.cos(light.innerConeAngle));
|
|
3082
|
+
material.setFloat("_Lights[" + i + "].outerConeCos", Math.cos(light.outerConeAngle));
|
|
3083
|
+
material.setInt("_Lights[" + i + "].type", light.lightType);
|
|
3084
|
+
material.setVector2("_Lights[" + i + "].padding", light.padding);
|
|
3083
3085
|
} else {
|
|
3084
|
-
material.setVector3("
|
|
3085
|
-
material.setFloat("
|
|
3086
|
-
material.setVector3("
|
|
3087
|
-
material.setFloat("
|
|
3088
|
-
material.setVector3("
|
|
3089
|
-
material.setFloat("
|
|
3090
|
-
material.setFloat("
|
|
3091
|
-
material.setInt("
|
|
3092
|
-
material.setVector2("
|
|
3086
|
+
material.setVector3("_Lights[" + i + "].direction", Vector3.ZERO);
|
|
3087
|
+
material.setFloat("_Lights[" + i + "].range", 0);
|
|
3088
|
+
material.setVector3("_Lights[" + i + "].color", Vector3.ZERO);
|
|
3089
|
+
material.setFloat("_Lights[" + i + "].intensity", 0);
|
|
3090
|
+
material.setVector3("_Lights[" + i + "].position", Vector3.ZERO);
|
|
3091
|
+
material.setFloat("_Lights[" + i + "].innerConeCos", 0);
|
|
3092
|
+
material.setFloat("_Lights[" + i + "].outerConeCos", 0);
|
|
3093
|
+
material.setInt("_Lights[" + i + "].type", 99999);
|
|
3094
|
+
material.setVector2("_Lights[" + i + "].padding", Vector2.ZERO);
|
|
3093
3095
|
}
|
|
3094
3096
|
}
|
|
3095
3097
|
var skybox = sceneStates.skybox;
|
|
3096
3098
|
if (skybox !== undefined && skybox.available) {
|
|
3097
|
-
material.setVector2("
|
|
3098
|
-
material.setTexture("
|
|
3099
|
+
material.setVector2("_IblIntensity", new Vector2(skybox.currentIntensity, skybox.currentReflectionsIntensity));
|
|
3100
|
+
material.setTexture("_brdfLUT", skybox.brdfLUT);
|
|
3099
3101
|
if (skybox.diffuseImage !== undefined) {
|
|
3100
|
-
material.setTexture("
|
|
3102
|
+
material.setTexture("_DiffuseEnvSampler", skybox.diffuseImage);
|
|
3101
3103
|
} else {
|
|
3102
3104
|
var coeffs = skybox.irradianceCoeffs;
|
|
3103
3105
|
var aliasName = [
|
|
@@ -3112,12 +3114,12 @@ function _assert_this_initialized(self) {
|
|
|
3112
3114
|
"l22"
|
|
3113
3115
|
];
|
|
3114
3116
|
aliasName.forEach(function(n, i) {
|
|
3115
|
-
material.setVector3("
|
|
3117
|
+
material.setVector3("_shCoefficients." + n, Vector3.fromArray(coeffs[i]));
|
|
3116
3118
|
});
|
|
3117
3119
|
}
|
|
3118
3120
|
var _skybox_specularMipCount;
|
|
3119
|
-
material.setInt("
|
|
3120
|
-
material.setTexture("
|
|
3121
|
+
material.setInt("_MipCount", (_skybox_specularMipCount = skybox.specularMipCount) != null ? _skybox_specularMipCount : 1);
|
|
3122
|
+
material.setTexture("_SpecularEnvSampler", skybox.specularImage);
|
|
3121
3123
|
}
|
|
3122
3124
|
}
|
|
3123
3125
|
};
|
|
@@ -3140,42 +3142,7 @@ function _assert_this_initialized(self) {
|
|
|
3140
3142
|
if (_instanceof1(val, PGeometry)) {
|
|
3141
3143
|
this.geometry = val;
|
|
3142
3144
|
} else {
|
|
3143
|
-
|
|
3144
|
-
// @ts-expect-error
|
|
3145
|
-
var aNormal = val.attributes["aNormal"];
|
|
3146
|
-
// @ts-expect-error
|
|
3147
|
-
var aPos = val.attributes["aPos"];
|
|
3148
|
-
// @ts-expect-error
|
|
3149
|
-
var aUV = val.attributes["aUV"];
|
|
3150
|
-
if (aNormal && aPos && aUV) {
|
|
3151
|
-
var aNormalData = val.getAttributeData("aNormal");
|
|
3152
|
-
var aPosData = val.getAttributeData("aPos");
|
|
3153
|
-
var aUVData = val.getAttributeData("aUV");
|
|
3154
|
-
var newGeom = effects.Geometry.create(val.engine, {
|
|
3155
|
-
attributes: {
|
|
3156
|
-
a_Position: _extends({}, aPos, {
|
|
3157
|
-
data: aPosData
|
|
3158
|
-
}),
|
|
3159
|
-
a_UV1: _extends({}, aUV, {
|
|
3160
|
-
data: aUVData
|
|
3161
|
-
}),
|
|
3162
|
-
a_Normal: _extends({}, aNormal, {
|
|
3163
|
-
data: aNormalData
|
|
3164
|
-
})
|
|
3165
|
-
},
|
|
3166
|
-
// @ts-expect-error
|
|
3167
|
-
indices: {
|
|
3168
|
-
data: val.getIndexData()
|
|
3169
|
-
},
|
|
3170
|
-
// @ts-expect-error
|
|
3171
|
-
mode: val.mode,
|
|
3172
|
-
drawStart: val.getDrawStart(),
|
|
3173
|
-
drawCount: val.getDrawCount()
|
|
3174
|
-
});
|
|
3175
|
-
this.geometry = new PGeometry(newGeom);
|
|
3176
|
-
} else {
|
|
3177
|
-
this.geometry = new PGeometry(val);
|
|
3178
|
-
}
|
|
3145
|
+
this.geometry = new PGeometry(val);
|
|
3179
3146
|
}
|
|
3180
3147
|
};
|
|
3181
3148
|
/**
|
|
@@ -3281,7 +3248,7 @@ function _assert_this_initialized(self) {
|
|
|
3281
3248
|
* 是否压缩格式
|
|
3282
3249
|
* @returns
|
|
3283
3250
|
*/ _proto.isCompressed = function isCompressed() {
|
|
3284
|
-
var positionAttrib = this.geometry.getAttributeData("
|
|
3251
|
+
var positionAttrib = this.geometry.getAttributeData("aPos");
|
|
3285
3252
|
if (positionAttrib === undefined) {
|
|
3286
3253
|
return false;
|
|
3287
3254
|
}
|
|
@@ -3293,13 +3260,13 @@ function _assert_this_initialized(self) {
|
|
|
3293
3260
|
* 是否有位置属性
|
|
3294
3261
|
* @returns
|
|
3295
3262
|
*/ _proto.hasPositions = function hasPositions() {
|
|
3296
|
-
return this.hasAttribute("
|
|
3263
|
+
return this.hasAttribute("aPos");
|
|
3297
3264
|
};
|
|
3298
3265
|
/**
|
|
3299
3266
|
* 是否有法线属性
|
|
3300
3267
|
* @returns
|
|
3301
3268
|
*/ _proto.hasNormals = function hasNormals() {
|
|
3302
|
-
return this.hasAttribute("
|
|
3269
|
+
return this.hasAttribute("aNormal");
|
|
3303
3270
|
};
|
|
3304
3271
|
/**
|
|
3305
3272
|
* 是否有切线属性
|
|
@@ -3312,7 +3279,11 @@ function _assert_this_initialized(self) {
|
|
|
3312
3279
|
* @param index - 纹理坐标索引
|
|
3313
3280
|
* @returns
|
|
3314
3281
|
*/ _proto.hasUVCoords = function hasUVCoords(index) {
|
|
3315
|
-
|
|
3282
|
+
if (index === 1) {
|
|
3283
|
+
return this.hasAttribute("aUV");
|
|
3284
|
+
} else {
|
|
3285
|
+
return this.hasAttribute("aUV" + index);
|
|
3286
|
+
}
|
|
3316
3287
|
};
|
|
3317
3288
|
/**
|
|
3318
3289
|
* 是否有颜色属性
|
|
@@ -3809,27 +3780,27 @@ var EffectsMeshProxy = /*#__PURE__*/ function() {
|
|
|
3809
3780
|
return PSceneManager;
|
|
3810
3781
|
}();
|
|
3811
3782
|
|
|
3812
|
-
var primitiveVert = "precision highp float;\n#define FEATURES\n#include <webglCompatibility.glsl>\n#include <animation.vert.glsl>\nvsIn vec4
|
|
3783
|
+
var primitiveVert = "precision highp float;\n#define FEATURES\n#include <webglCompatibility.glsl>\n#include <animation.vert.glsl>\nvsIn vec4 aPos;vsOut vec3 v_Position;\n#ifdef HAS_NORMALS\nvsIn vec4 aNormal;\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 aUV;\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 _ViewProjectionMatrix;uniform mat4 _ModelMatrix;uniform mat4 _NormalMatrix;\n#ifdef EDITOR_TRANSFORM\nuniform vec4 uEditorTransform;\n#endif\n#ifdef USE_SHADOW_MAPPING\nuniform mat4 _LightViewProjectionMatrix;uniform float _DeltaSceneSize;vsOut vec4 v_PositionLightSpace;vsOut vec4 v_dPositionLightSpace;\n#endif\nvec4 getPosition(){vec4 pos=vec4(aPos.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=aNormal;\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=_ModelMatrix*getPosition();v_Position=vec3(pos.xyz)/pos.w;\n#ifdef HAS_NORMALS\n#ifdef HAS_TANGENTS\nvec4 tangent=getTangent();vec3 normalW=normalize(vec3(_NormalMatrix*vec4(getNormal().xyz,0.0)));vec3 tangentW=normalize(vec3(_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(_NormalMatrix*vec4(getNormal().xyz,0.0)));\n#endif\n#endif\nv_UVCoord1=vec2(0.0,0.0);\n#ifdef HAS_UV_SET1\nv_UVCoord1=aUV;\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=_LightViewProjectionMatrix*pos;vec3 dpos=vec3(_DeltaSceneSize);v_dPositionLightSpace=_LightViewProjectionMatrix*(pos+vec4(dpos,0));\n#endif\ngl_Position=_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}";
|
|
3813
3784
|
|
|
3814
|
-
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}";
|
|
3785
|
+
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 _Lights[LIGHT_COUNT];\n#endif\n#if defined(MATERIAL_SPECULARGLOSSINESS) || defined(MATERIAL_METALLICROUGHNESS)\nuniform float _MetallicFactor;uniform float _RoughnessFactor;uniform vec4 _BaseColorFactor;\n#endif\n#ifdef MATERIAL_SPECULARGLOSSINESS\nuniform vec3 _SpecularFactor;uniform vec4 _DiffuseFactor;uniform float _GlossinessFactor;\n#endif\n#ifdef ALPHAMODE_MASK\nuniform float _AlphaCutoff;\n#endif\n#ifdef ADD_FOG\nuniform vec4 _FogColor;\n#ifdef LINEAR_FOG\nuniform float _FogNear;uniform float _FogFar;\n#endif\n#ifdef EXP_FOG\nuniform float _FogDensity;\n#endif\n#endif\n#ifdef PREVIEW_BORDER\nuniform vec4 uPreviewColor;\n#endif\nuniform vec3 _Camera;uniform int _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=_Camera-v_Position;float fogAmount=0.0;\n#ifdef LINEAR_FOG\nfogAmount=smoothstep(_FogNear,_FogFar,distance[2]);\n#endif\n#ifdef EXP_FOG\n#define LOG2 1.442695\nfogAmount=1.-exp2(-_FogDensity*_FogDensity*distance[2]*distance[2]*LOG2);fogAmount=clamp(fogAmount,0.,1.);\n#endif\nvec3 mixColor=baseColor.rgb+(vec3(_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(_MipCount),0.0,float(_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(_brdfLUT,brdfSamplePoint).rg;vec4 diffuseColor=vec4(1.0,0.0,0.0,1.0);\n#ifdef IRRADIANCE_COEFFICIENTS\nvec3 irradiance=getIrradiance(n,_shCoefficients);diffuseColor=vec4(irradiance,1.0);\n#else\ndiffuseColor=textureCube(_DiffuseEnvSampler,n);\n#endif\n#ifdef USE_TEX_LOD\nvec4 specularSample=_textureCubeLodEXT(_SpecularEnvSampler,reflection,lod);\n#else\nvec4 specularSample=textureCube(_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*_IblIntensity[0]+specular*_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(_SpecularGlossinessSampler,getSpecularGlossinessUV()));perceptualRoughness=(1.0-sgSample.a*_GlossinessFactor);f0=sgSample.rgb*_SpecularFactor;\n#else\nf0=_SpecularFactor;perceptualRoughness=1.0-_GlossinessFactor;\n#endif\n#ifdef HAS_DIFFUSE_MAP\nbaseColor=SRGBtoLINEAR(texture2D(_DiffuseSampler,getDiffuseUV()))*_DiffuseFactor;\n#else\nbaseColor=SRGBtoLINEAR(_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(_MetallicRoughnessSampler,getMetallicRoughnessUV());perceptualRoughness=mrSample.g*_RoughnessFactor;metallic=mrSample.b*_MetallicFactor;\n#else\nmetallic=_MetallicFactor;perceptualRoughness=_RoughnessFactor;\n#endif\n#ifdef HAS_BASE_COLOR_MAP\nbaseColor=SRGBtoLINEAR(texture2D(_BaseColorSampler,getBaseColorUV()))*_BaseColorFactor;\n#else\nbaseColor=SRGBtoLINEAR(_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<_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(_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=_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(_OcclusionSampler,getOcclusionUV()).r;color=mix(color,color*ao,_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+=_EmissiveFactor.rgb;\n#endif\n#ifdef HAS_EMISSIVE_MAP\nemissive=SRGBtoLINEAR(texture2D(_EmissiveSampler,getEmissiveUV())).rgb*_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,_OcclusionStrength));\n#else\noutFragColor.rgb=vec3(1.0);\n#endif\n#endif\n#ifdef DEBUG_EMISSIVE\n#ifdef HAS_EMISSIVE\nemissive=_EmissiveFactor.rgb;\n#endif\n#ifdef HAS_EMISSIVE_MAP\nemissive=SRGBtoLINEAR(texture2D(_EmissiveSampler,getEmissiveUV())).rgb*_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}";
|
|
3815
3786
|
|
|
3816
3787
|
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}";
|
|
3817
3788
|
|
|
3818
|
-
var skyboxVert = "precision highp float;\n#define FEATURES\n#include <webglCompatibility.glsl>\nvsIn vec3
|
|
3789
|
+
var skyboxVert = "precision highp float;\n#define FEATURES\n#include <webglCompatibility.glsl>\nvsIn vec3 aPos;vsOut vec3 v_CameraDir;uniform mat4 _InvViewProjectionMatrix;void main(){vec4 dir=_InvViewProjectionMatrix*vec4(aPos.xy,1,1);v_CameraDir=normalize(dir.xyz/dir.w);gl_Position=vec4(aPos.xy,0.99999,1);}";
|
|
3819
3790
|
|
|
3820
|
-
var skyboxFrag = "precision highp float;\n#define FEATURES\n#if !defined(WEBGL2) && defined(USE_TEX_LOD)\n#extension GL_EXT_shader_texture_lod : enable\n#endif\n#if !defined(WEBGL2)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#include <webglCompatibility.glsl>\n#include <extensions.frag.glsl>\n#ifdef WEBGL2\nout vec4 outFragColor;\n#else\n#define outFragColor gl_FragColor\n#endif\nuniform sampler2D
|
|
3791
|
+
var skyboxFrag = "precision highp float;\n#define FEATURES\n#if !defined(WEBGL2) && defined(USE_TEX_LOD)\n#extension GL_EXT_shader_texture_lod : enable\n#endif\n#if !defined(WEBGL2)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#include <webglCompatibility.glsl>\n#include <extensions.frag.glsl>\n#ifdef WEBGL2\nout vec4 outFragColor;\n#else\n#define outFragColor gl_FragColor\n#endif\nuniform sampler2D _brdfLUT;uniform vec2 _IblIntensity;uniform int _MipCount;uniform samplerCube _DiffuseEnvSampler;uniform samplerCube _SpecularEnvSampler;fsIn vec3 v_CameraDir;\n#ifdef IRRADIANCE_COEFFICIENTS\nstruct SHCoefficients{vec3 l00,l1m1,l10,l11,l2m2,l2m1,l20,l21,l22;};uniform SHCoefficients _shCoefficients;vec3 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\nvec3 getIBLContribution(vec3 n,vec3 v){const float metallic=0.9;const float perceptualRoughness=0.1;const vec4 baseColor=vec4(1.0);const vec3 f0=vec3(0.04);const vec3 diffuseColor=baseColor.rgb*(vec3(1.0)-f0)*(1.0-metallic);const vec3 specularColor=mix(f0,baseColor.rgb,metallic);float NdotV=clamp(dot(n,v),0.0,1.0);float lod=clamp(perceptualRoughness*float(_MipCount),0.0,float(_MipCount));vec3 reflection=normalize(reflect(-v,n));vec2 brdfSamplePoint=clamp(vec2(NdotV,perceptualRoughness),vec2(0.0,0.0),vec2(1.0,1.0));vec2 brdf=texture2D(_brdfLUT,brdfSamplePoint).rg;vec4 diffuseSample=vec4(1.0,0.0,0.0,1.0);\n#ifdef IRRADIANCE_COEFFICIENTS\nvec3 irradiance=getIrradiance(n,_shCoefficients);diffuseSample=vec4(irradiance,1.0);\n#else\ndiffuseSample=textureCube(_DiffuseEnvSampler,n);\n#endif\n#ifdef USE_TEX_LOD\nvec4 specularSample=_textureCubeLodEXT(_SpecularEnvSampler,reflection,lod);\n#else\nvec4 specularSample=textureCube(_SpecularEnvSampler,reflection,lod);\n#endif\nvec3 diffuseLight=diffuseSample.rgb;vec3 specularLight=specularSample.rgb;vec3 diffuse=diffuseLight*diffuseColor;vec3 specular=specularLight*(specularColor*brdf.x+brdf.y);return diffuse*_IblIntensity[0]+specular*_IblIntensity[1];}void main(){vec3 dir=normalize(v_CameraDir);outFragColor=vec4(getIBLContribution(dir,dir),1.0);}";
|
|
3821
3792
|
|
|
3822
|
-
var animationVertGLSL = "#ifdef HAS_TARGET_POSITION0\nvsIn vec3 a_Target_Position0;\n#endif\n#ifdef HAS_TARGET_POSITION1\nvsIn vec3 a_Target_Position1;\n#endif\n#ifdef HAS_TARGET_POSITION2\nvsIn vec3 a_Target_Position2;\n#endif\n#ifdef HAS_TARGET_POSITION3\nvsIn vec3 a_Target_Position3;\n#endif\n#ifdef HAS_TARGET_POSITION4\nvsIn vec3 a_Target_Position4;\n#endif\n#ifdef HAS_TARGET_POSITION5\nvsIn vec3 a_Target_Position5;\n#endif\n#ifdef HAS_TARGET_POSITION6\nvsIn vec3 a_Target_Position6;\n#endif\n#ifdef HAS_TARGET_POSITION7\nvsIn vec3 a_Target_Position7;\n#endif\n#ifdef HAS_TARGET_NORMAL0\nvsIn vec3 a_Target_Normal0;\n#endif\n#ifdef HAS_TARGET_NORMAL1\nvsIn vec3 a_Target_Normal1;\n#endif\n#ifdef HAS_TARGET_NORMAL2\nvsIn vec3 a_Target_Normal2;\n#endif\n#ifdef HAS_TARGET_NORMAL3\nvsIn vec3 a_Target_Normal3;\n#endif\n#ifdef HAS_TARGET_NORMAL4\nvsIn vec3 a_Target_Normal4;\n#endif\n#ifdef HAS_TARGET_TANGENT0\nvsIn vec3 a_Target_Tangent0;\n#endif\n#ifdef HAS_TARGET_TANGENT1\nvsIn vec3 a_Target_Tangent1;\n#endif\n#ifdef HAS_TARGET_TANGENT2\nvsIn vec3 a_Target_Tangent2;\n#endif\n#ifdef HAS_TARGET_TANGENT3\nvsIn vec3 a_Target_Tangent3;\n#endif\n#ifdef HAS_TARGET_TANGENT4\nvsIn vec3 a_Target_Tangent4;\n#endif\n#ifdef USE_MORPHING\nuniform float
|
|
3793
|
+
var animationVertGLSL = "#ifdef HAS_TARGET_POSITION0\nvsIn vec3 a_Target_Position0;\n#endif\n#ifdef HAS_TARGET_POSITION1\nvsIn vec3 a_Target_Position1;\n#endif\n#ifdef HAS_TARGET_POSITION2\nvsIn vec3 a_Target_Position2;\n#endif\n#ifdef HAS_TARGET_POSITION3\nvsIn vec3 a_Target_Position3;\n#endif\n#ifdef HAS_TARGET_POSITION4\nvsIn vec3 a_Target_Position4;\n#endif\n#ifdef HAS_TARGET_POSITION5\nvsIn vec3 a_Target_Position5;\n#endif\n#ifdef HAS_TARGET_POSITION6\nvsIn vec3 a_Target_Position6;\n#endif\n#ifdef HAS_TARGET_POSITION7\nvsIn vec3 a_Target_Position7;\n#endif\n#ifdef HAS_TARGET_NORMAL0\nvsIn vec3 a_Target_Normal0;\n#endif\n#ifdef HAS_TARGET_NORMAL1\nvsIn vec3 a_Target_Normal1;\n#endif\n#ifdef HAS_TARGET_NORMAL2\nvsIn vec3 a_Target_Normal2;\n#endif\n#ifdef HAS_TARGET_NORMAL3\nvsIn vec3 a_Target_Normal3;\n#endif\n#ifdef HAS_TARGET_NORMAL4\nvsIn vec3 a_Target_Normal4;\n#endif\n#ifdef HAS_TARGET_TANGENT0\nvsIn vec3 a_Target_Tangent0;\n#endif\n#ifdef HAS_TARGET_TANGENT1\nvsIn vec3 a_Target_Tangent1;\n#endif\n#ifdef HAS_TARGET_TANGENT2\nvsIn vec3 a_Target_Tangent2;\n#endif\n#ifdef HAS_TARGET_TANGENT3\nvsIn vec3 a_Target_Tangent3;\n#endif\n#ifdef HAS_TARGET_TANGENT4\nvsIn vec3 a_Target_Tangent4;\n#endif\n#ifdef USE_MORPHING\nuniform float _morphWeights[WEIGHT_COUNT];\n#endif\n#ifdef HAS_JOINT_SET1\nvsIn vec4 a_Joint1;\n#endif\n#ifdef HAS_JOINT_SET2\nvsIn vec4 a_Joint2;\n#endif\n#ifdef HAS_WEIGHT_SET1\nvsIn vec4 a_Weight1;\n#endif\n#ifdef HAS_WEIGHT_SET2\nvsIn vec4 a_Weight2;\n#endif\n#ifdef USE_SKINNING\n#ifdef USE_SKINNING_TEXTURE\nuniform sampler2D _jointMatrixSampler;uniform sampler2D _jointNormalMatrixSampler;\n#else\nuniform mat4 _jointMatrix[JOINT_COUNT];uniform mat4 _jointNormalMatrix[JOINT_COUNT];\n#endif\n#endif\n#define ROW0_U ((0.5 + 0.0) / 4.0)\n#define ROW1_U ((0.5 + 1.0) / 4.0)\n#define ROW2_U ((0.5 + 2.0) / 4.0)\n#define ROW3_U ((0.5 + 3.0) / 4.0)\n#ifdef USE_SKINNING\nmat4 getJointMatrix(float boneNdx){\n#ifdef USE_SKINNING_TEXTURE\nfloat v=(boneNdx+0.5)/float(JOINT_COUNT);return mat4(texture2D(_jointMatrixSampler,vec2(ROW0_U,v)),texture2D(_jointMatrixSampler,vec2(ROW1_U,v)),texture2D(_jointMatrixSampler,vec2(ROW2_U,v)),texture2D(_jointMatrixSampler,vec2(ROW3_U,v)));\n#else\nreturn _jointMatrix[int(boneNdx)];\n#endif\n}mat4 getJointNormalMatrix(float boneNdx){\n#ifdef USE_SKINNING_TEXTURE\nfloat v=(boneNdx+0.5)/float(JOINT_COUNT);return mat4(texture2D(_jointNormalMatrixSampler,vec2(ROW0_U,v)),texture2D(_jointNormalMatrixSampler,vec2(ROW1_U,v)),texture2D(_jointNormalMatrixSampler,vec2(ROW2_U,v)),texture2D(_jointNormalMatrixSampler,vec2(ROW3_U,v)));\n#else\nreturn _jointNormalMatrix[int(boneNdx)];\n#endif\n}mat4 getSkinningMatrix(){mat4 skin=mat4(0);\n#if defined(HAS_WEIGHT_SET1) && defined(HAS_JOINT_SET1)\nskin+=a_Weight1.x*getJointMatrix(a_Joint1.x)+a_Weight1.y*getJointMatrix(a_Joint1.y)+a_Weight1.z*getJointMatrix(a_Joint1.z)+a_Weight1.w*getJointMatrix(a_Joint1.w);\n#endif\nreturn skin;}mat4 getSkinningNormalMatrix(){mat4 skin=mat4(0);\n#if defined(HAS_WEIGHT_SET1) && defined(HAS_JOINT_SET1)\nskin+=a_Weight1.x*getJointNormalMatrix(a_Joint1.x)+a_Weight1.y*getJointNormalMatrix(a_Joint1.y)+a_Weight1.z*getJointNormalMatrix(a_Joint1.z)+a_Weight1.w*getJointNormalMatrix(a_Joint1.w);\n#endif\nreturn skin;}\n#endif\n#ifdef USE_MORPHING\nvec4 getTargetPosition(){vec4 pos=vec4(0);\n#ifdef HAS_TARGET_POSITION0\npos.xyz+=_morphWeights[0]*a_Target_Position0;\n#endif\n#ifdef HAS_TARGET_POSITION1\npos.xyz+=_morphWeights[1]*a_Target_Position1;\n#endif\n#ifdef HAS_TARGET_POSITION2\npos.xyz+=_morphWeights[2]*a_Target_Position2;\n#endif\n#ifdef HAS_TARGET_POSITION3\npos.xyz+=_morphWeights[3]*a_Target_Position3;\n#endif\n#ifdef HAS_TARGET_POSITION4\npos.xyz+=_morphWeights[4]*a_Target_Position4;\n#endif\nreturn pos;}vec4 getTargetNormal(){vec4 normal=vec4(0);\n#ifdef HAS_TARGET_NORMAL0\nnormal.xyz+=_morphWeights[0]*a_Target_Normal0;\n#endif\n#ifdef HAS_TARGET_NORMAL1\nnormal.xyz+=_morphWeights[1]*a_Target_Normal1;\n#endif\n#ifdef HAS_TARGET_NORMAL2\nnormal.xyz+=_morphWeights[2]*a_Target_Normal2;\n#endif\n#ifdef HAS_TARGET_NORMAL3\nnormal.xyz+=_morphWeights[3]*a_Target_Normal3;\n#endif\n#ifdef HAS_TARGET_NORMAL4\nnormal.xyz+=_morphWeights[4]*a_Target_Normal4;\n#endif\nreturn normal;}vec4 getTargetTangent(){vec4 tangent=vec4(0);\n#ifdef HAS_TARGET_TANGENT0\ntangent.xyz+=_morphWeights[0]*a_Target_Tangent0;\n#endif\n#ifdef HAS_TARGET_TANGENT1\ntangent.xyz+=_morphWeights[1]*a_Target_Tangent1;\n#endif\n#ifdef HAS_TARGET_TANGENT2\ntangent.xyz+=_morphWeights[2]*a_Target_Tangent2;\n#endif\n#ifdef HAS_TARGET_TANGENT3\ntangent.xyz+=_morphWeights[3]*a_Target_Tangent3;\n#endif\n#ifdef HAS_TARGET_TANGENT4\ntangent.xyz+=_morphWeights[4]*a_Target_Tangent4;\n#endif\nreturn tangent;}\n#endif\n";
|
|
3823
3794
|
|
|
3824
3795
|
var extensionsFragGLSL = "vec3 _dFdx(vec3 coord){\n#if defined(GL_OES_standard_derivatives) || defined(WEBGL2)\nreturn dFdx(coord);\n#endif\nreturn vec3(0.0);}vec3 _dFdy(vec3 coord){\n#if defined(GL_OES_standard_derivatives) || defined(WEBGL2)\nreturn dFdy(coord);\n#endif\nreturn vec3(0.0);}\n#ifdef USE_TEX_LOD\nvec4 _textureCubeLodEXT(samplerCube sampler,vec3 coord,float lod){\n#if defined(WEBGL2) || defined(GL_EXT_shader_texture_lod)\nreturn textureCubeLodEXT(sampler,coord,lod);\n#else\nreturn textureCube(sampler,coord,lod);\n#endif\n}\n#endif\n";
|
|
3825
3796
|
|
|
3826
|
-
var tonemappingFragGLSL = "uniform float
|
|
3797
|
+
var tonemappingFragGLSL = "uniform float _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*=_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);}";
|
|
3827
3798
|
|
|
3828
|
-
var texturesVertGLSL = "fsIn vec2 v_UVCoord1;\n#ifdef HAS_UV_SET2\nfsIn vec2 v_UVCoord2;\n#endif\n#ifdef HAS_NORMAL_MAP\nuniform sampler2D
|
|
3799
|
+
var texturesVertGLSL = "fsIn vec2 v_UVCoord1;\n#ifdef HAS_UV_SET2\nfsIn vec2 v_UVCoord2;\n#endif\n#ifdef HAS_NORMAL_MAP\nuniform sampler2D _NormalSampler;uniform float _NormalScale;uniform int _NormalUVSet;uniform mat3 _NormalUVTransform;\n#endif\n#ifdef HAS_EMISSIVE_MAP\nuniform sampler2D _EmissiveSampler;uniform int _EmissiveUVSet;uniform vec4 _EmissiveFactor;uniform mat3 _EmissiveUVTransform;\n#endif\n#ifdef HAS_EMISSIVE\nuniform vec4 _EmissiveFactor;\n#endif\n#ifdef HAS_OCCLUSION_MAP\nuniform sampler2D _OcclusionSampler;uniform int _OcclusionUVSet;uniform float _OcclusionStrength;uniform mat3 _OcclusionUVTransform;\n#endif\n#ifdef HAS_BASE_COLOR_MAP\nuniform sampler2D _BaseColorSampler;uniform int _BaseColorUVSet;uniform mat3 _BaseColorUVTransform;\n#endif\n#ifdef HAS_METALLIC_ROUGHNESS_MAP\nuniform sampler2D _MetallicRoughnessSampler;uniform int _MetallicRoughnessUVSet;uniform mat3 _MetallicRoughnessUVTransform;\n#endif\n#ifdef HAS_DIFFUSE_MAP\nuniform sampler2D _DiffuseSampler;uniform int _DiffuseUVSet;uniform mat3 _DiffuseUVTransform;\n#endif\n#ifdef HAS_SPECULAR_GLOSSINESS_MAP\nuniform sampler2D _SpecularGlossinessSampler;uniform int _SpecularGlossinessUVSet;uniform mat3 _SpecularGlossinessUVTransform;\n#endif\n#ifdef USE_IBL\nuniform samplerCube _DiffuseEnvSampler;uniform samplerCube _SpecularEnvSampler;uniform sampler2D _brdfLUT;uniform vec2 _IblIntensity;\n#endif\n#ifdef IRRADIANCE_COEFFICIENTS\nstruct SHCoefficients{vec3 l00,l1m1,l10,l11,l2m2,l2m1,l20,l21,l22;};uniform SHCoefficients _shCoefficients;\n#endif\n#ifdef USE_SHADOW_MAPPING\nuniform sampler2D _ShadowSampler;\n#endif\nvec2 getNormalUV(){vec3 uv=vec3(v_UVCoord1,1.0);\n#ifdef HAS_NORMAL_MAP\n#ifdef HAS_UV_SET2\nuv.xy=_NormalUVSet<1 ? v_UVCoord1 : v_UVCoord2;\n#endif\n#ifdef HAS_NORMAL_UV_TRANSFORM\nuv*=_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=_EmissiveUVSet<1 ? v_UVCoord1 : v_UVCoord2;\n#endif\n#ifdef HAS_EMISSIVE_UV_TRANSFORM\nuv*=_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=_OcclusionUVSet<1 ? v_UVCoord1 : v_UVCoord2;\n#endif\n#ifdef HAS_OCCLUSION_UV_TRANSFORM\nuv*=_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=_BaseColorUVSet<1 ? v_UVCoord1 : v_UVCoord2;\n#endif\n#ifdef HAS_BASECOLOR_UV_TRANSFORM\nuv*=_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=_MetallicRoughnessUVSet<1 ? v_UVCoord1 : v_UVCoord2;\n#endif\n#ifdef HAS_METALLICROUGHNESS_UV_TRANSFORM\nuv*=_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=_SpecularGlossinessUVSet<1 ? v_UVCoord1 : v_UVCoord2;\n#endif\n#ifdef HAS_SPECULARGLOSSINESS_UV_TRANSFORM\nuv*=_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=_DiffuseUVSet<1 ? v_UVCoord1 : v_UVCoord2;\n#endif\n#ifdef HAS_DIFFUSE_UV_TRANSFORM\nuv*=_DiffuseUVTransform;\n#endif\n#endif\nreturn uv.xy;}";
|
|
3829
3800
|
|
|
3830
|
-
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(
|
|
3801
|
+
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(_NormalSampler,UV).rgb;n=normalize(tbn*((2.0*n-1.0)*vec3(_NormalScale,_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 _DebugUVGridSize;float getDebugUVColor(vec2 uv,vec3 n){float s=dot(abs(n),vec3(1,1,1))*0.6;uv=uv/(_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";
|
|
3831
3802
|
|
|
3832
|
-
var shadowFragGLSL = "#ifdef USE_SHADOW_MAPPING\nuniform vec2
|
|
3803
|
+
var shadowFragGLSL = "#ifdef USE_SHADOW_MAPPING\nuniform vec2 _ShadowMapSizeInv;fsIn vec4 v_PositionLightSpace;fsIn vec4 v_dPositionLightSpace;\n#endif\nfloat linstep(float low,float high,float v){return clamp((v-low)/(high-low),0.0,1.0);}\n#ifdef USE_SHADOW_MAPPING\nfloat chebyshev(vec2 moments,float depth,float minVar){float p=step(depth,moments.x+SHADOWMAP_BAIS);float variance=max(moments.y-moments.x*moments.x,minVar);float d=depth-(moments.x+SHADOWMAP_BAIS);float pMax=linstep(0.2,1.0,variance/(variance+d*d));return mix(0.1,1.0,min(max(p,pMax),1.0));}float getShadowContributionSM(){vec3 coords=v_PositionLightSpace.xyz/v_PositionLightSpace.w*0.5+0.5;if(coords.z<0.01||coords.z>0.99||coords.x<0.01||coords.x>0.99||coords.y<0.01||coords.y>0.99){return 1.0;}vec2 moments=vec2(1.0)-texture2D(_ShadowSampler,coords.xy).xy;return coords.z<moments.x*1.008+0.008? 1.0: 0.2;}float getShadowContributionVSM(){vec3 coords=v_PositionLightSpace.xyz/v_PositionLightSpace.w*0.5+0.5;if(coords.z<0.01||coords.z>0.99||coords.x<0.01||coords.x>0.99||coords.y<0.01||coords.y>0.99){return 1.0;}vec2 moments=vec2(1.0)-texture2D(_ShadowSampler,coords.xy).xy;return chebyshev(moments,coords.z,0.00002);}float computeEVSMShadow(vec2 coords,float pos,float neg){vec4 moments=texture2D(_ShadowSampler,coords);float posShadow=chebyshev(moments.xy,pos,0.00002);float negShadow=chebyshev(moments.zw,neg,0.00002);return min(posShadow,negShadow);}float getShadowContributionEVSM(){vec3 coords=v_PositionLightSpace.xyz/v_PositionLightSpace.w*0.5+0.5;if(coords.z<0.01||coords.z>0.99||coords.x<0.01||coords.x>0.99||coords.y<0.01||coords.y>0.99){return 1.0;}float depth=coords.z;float pos=EVSM_FUNC0(depth);float neg=EVSM_FUNC1(depth);\n#ifdef SHADOWMAP_EVSM_PCF\nvec2 newCoords=v_dPositionLightSpace.xy/v_dPositionLightSpace.w*0.5+0.5;vec2 dCoords=min(abs(newCoords-coords.xy),_ShadowMapSizeInv);if(max(dCoords.x,dCoords.y)>=min(_ShadowMapSizeInv.x,_ShadowMapSizeInv.y)*0.5){vec2 coords0=coords.xy+vec2(-1.0,-1.0)*dCoords;vec2 coords1=coords.xy+vec2(-1.0,1.0)*dCoords;vec2 coords2=coords.xy+vec2(1.0,-1.0)*dCoords;vec2 coords3=coords.xy+vec2(1.0,1.0)*dCoords;float shadow0=computeEVSMShadow(coords0,pos,neg);float shadow1=computeEVSMShadow(coords1,pos,neg);float shadow2=computeEVSMShadow(coords2,pos,neg);float shadow3=computeEVSMShadow(coords3,pos,neg);return(shadow0+shadow1+shadow2+shadow3)*0.25;}else{return computeEVSMShadow(coords.xy,pos,neg);}\n#else\nreturn computeEVSMShadow(coords.xy,pos,neg);\n#endif\n}float getShadowContribution(){\n#if defined(SHADOWMAP_STANDARD)\nreturn getShadowContributionSM();\n#elif defined(SHADOWMAP_VSM)\nreturn getShadowContributionVSM();\n#else\nreturn getShadowContributionEVSM();\n#endif\n}\n#endif\n";
|
|
3833
3804
|
|
|
3834
3805
|
var webglCompatibilityGLSL = "#ifdef WEBGL2\n#define vsIn in\n#define vsOut out\n#define fsIn in\n#define fsOut out\n#define texture2D texture\n#define textureCube texture\n#define textureCubeLodEXT textureLod\n#else\n#define vsIn attribute\n#define vsOut varying\n#define fsIn varying\n#define fsOut varying\n#endif\n";
|
|
3835
3806
|
|
|
@@ -3956,7 +3927,7 @@ function getShadowPassShaderCode(context) {
|
|
|
3956
3927
|
* @param context - 着色器上下文
|
|
3957
3928
|
* @returns
|
|
3958
3929
|
*/ function getQuadFilterShaderCode(context) {
|
|
3959
|
-
var fragmentShaderCode = "\n #version 100\n precision highp float;\n uniform sampler2D
|
|
3930
|
+
var fragmentShaderCode = "\n #version 100\n precision highp float;\n uniform sampler2D _ColorSampler;\n\n varying vec2 v_UVCoord1;\n void main(){\n gl_FragColor = texture2D(_ColorSampler, v_UVCoord1);\n }\n ";
|
|
3960
3931
|
return {
|
|
3961
3932
|
vertexShaderCode: getQuadFilterVS(),
|
|
3962
3933
|
fragmentShaderCode: fragmentShaderCode
|
|
@@ -3993,7 +3964,7 @@ function getShadowPassShaderCode(context) {
|
|
|
3993
3964
|
* @param context - 着色器上下文
|
|
3994
3965
|
* @returns
|
|
3995
3966
|
*/ function getKawaseBlurShaderCode(context) {
|
|
3996
|
-
var fragmentShaderCode = "\n #version 100\n precision highp float;\n uniform float
|
|
3967
|
+
var fragmentShaderCode = "\n #version 100\n precision highp float;\n uniform float _Offset;\n uniform vec2 _TextureSizeInv;\n uniform sampler2D _TexturSampler;\n\n varying vec2 v_UVCoord1;\n void main() {\n vec4 color = vec4(0.0);\n color += texture2D(_TexturSampler, v_UVCoord1 + vec2(-_Offset-0.5,-_Offset-0.5) * _TextureSizeInv);\n color += texture2D(_TexturSampler, v_UVCoord1 + vec2(-_Offset-0.5, _Offset+0.5) * _TextureSizeInv);\n color += texture2D(_TexturSampler, v_UVCoord1 + vec2( _Offset+0.5,-_Offset-0.5) * _TextureSizeInv);\n color += texture2D(_TexturSampler, v_UVCoord1 + vec2( _Offset+0.5, _Offset+0.5) * _TextureSizeInv);\n gl_FragColor = color * 0.25;\n }\n ";
|
|
3997
3968
|
return {
|
|
3998
3969
|
vertexShaderCode: getQuadFilterVS(),
|
|
3999
3970
|
fragmentShaderCode: fragmentShaderCode
|
|
@@ -4004,7 +3975,7 @@ function getShadowPassShaderCode(context) {
|
|
|
4004
3975
|
* @param context - 着色器上下文
|
|
4005
3976
|
* @returns
|
|
4006
3977
|
*/ function getSimpleFilterShaderCode(context) {
|
|
4007
|
-
var fragmentShaderCode = "\n #version 100\n precision highp float;\n uniform sampler2D
|
|
3978
|
+
var fragmentShaderCode = "\n #version 100\n precision highp float;\n uniform sampler2D _FilterSampler;\n\n varying vec2 v_UVCoord1;\n void main() {\n gl_FragColor = texture2D(_FilterSampler, v_UVCoord1) * vec4(0.5);\n }\n ";
|
|
4008
3979
|
return {
|
|
4009
3980
|
vertexShaderCode: getQuadFilterVS(),
|
|
4010
3981
|
fragmentShaderCode: fragmentShaderCode
|
|
@@ -4015,7 +3986,7 @@ function getShadowPassShaderCode(context) {
|
|
|
4015
3986
|
* @param context - 着色器上下文
|
|
4016
3987
|
* @returns
|
|
4017
3988
|
*/ function getGaussianBlurShaderCodeV2(context) {
|
|
4018
|
-
var fragmentShaderCode = "\n #version 100\n precision highp float;\n uniform vec2
|
|
3989
|
+
var fragmentShaderCode = "\n #version 100\n precision highp float;\n uniform vec2 _BlurScale;\n uniform sampler2D _FilterSampler;\n\n varying vec2 v_UVCoord1;\n void main() {\n vec4 color = vec4(0);\n vec2 offset0 = vec2(0.53805) * _BlurScale.xy;\n vec2 offset1 = vec2(2.06278) * _BlurScale.xy;\n color += (texture2D(_FilterSampler, v_UVCoord1 + offset0) + texture2D(_FilterSampler, v_UVCoord1 - offset0)) * 0.44908;\n color += (texture2D(_FilterSampler, v_UVCoord1 + offset1) + texture2D(_FilterSampler, v_UVCoord1 - offset1)) * 0.05092;\n gl_FragColor = color;\n }\n ";
|
|
4019
3990
|
return {
|
|
4020
3991
|
vertexShaderCode: getQuadFilterVS(),
|
|
4021
3992
|
fragmentShaderCode: fragmentShaderCode
|
|
@@ -4026,7 +3997,7 @@ function getShadowPassShaderCode(context) {
|
|
|
4026
3997
|
* @param context - 着色器上下文
|
|
4027
3998
|
* @returns
|
|
4028
3999
|
*/ function getGaussianBlurShaderCodeV1(context) {
|
|
4029
|
-
var fragmentShaderCode = "\n #version 100\n precision highp float;\n uniform vec2
|
|
4000
|
+
var fragmentShaderCode = "\n #version 100\n precision highp float;\n uniform vec2 _BlurScale;\n uniform sampler2D _FilterSampler;\n\n varying vec2 v_UVCoord1;\n void main() {\n vec4 color = vec4(0.0);\n color += texture2D(_FilterSampler, v_UVCoord1 + (vec2(-3.0) * _BlurScale.xy)) * (1.0/64.0);\n color += texture2D(_FilterSampler, v_UVCoord1 + (vec2(-2.0) * _BlurScale.xy)) * (6.0/64.0);\n color += texture2D(_FilterSampler, v_UVCoord1 + (vec2(-1.0) * _BlurScale.xy)) * (15.0/64.0);\n color += texture2D(_FilterSampler, v_UVCoord1 + (vec2(+0.0) * _BlurScale.xy)) * (20.0/64.0);\n color += texture2D(_FilterSampler, v_UVCoord1 + (vec2(+1.0) * _BlurScale.xy)) * (15.0/64.0);\n color += texture2D(_FilterSampler, v_UVCoord1 + (vec2(+2.0) * _BlurScale.xy)) * (6.0/64.0);\n color += texture2D(_FilterSampler, v_UVCoord1 + (vec2(+3.0) * _BlurScale.xy)) * (1.0/64.0);\n gl_FragColor = color;\n }\n ";
|
|
4030
4001
|
return {
|
|
4031
4002
|
vertexShaderCode: getQuadFilterVS(),
|
|
4032
4003
|
fragmentShaderCode: fragmentShaderCode
|
|
@@ -4042,7 +4013,7 @@ function getShadowPassShaderCode(context) {
|
|
|
4042
4013
|
hasNormals: true
|
|
4043
4014
|
});
|
|
4044
4015
|
} else {
|
|
4045
|
-
return "\n #version 100\n #extension GL_EXT_draw_buffers: require\n\n precision highp float;\n uniform vec4
|
|
4016
|
+
return "\n #version 100\n #extension GL_EXT_draw_buffers: require\n\n precision highp float;\n uniform vec4 _BaseColorFactor;\n\n #ifdef HAS_UVS\n uniform sampler2D _BaseColorSampler;\n varying vec2 v_UVCoord1;\n #endif\n\n varying vec3 v_Normal;\n\n float weight(float z, float a) {\n 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);\n }\n\n void main() {\n vec4 color = _BaseColorFactor;\n\n #ifdef HAS_UVS\n color *= texture2D(_BaseColorSampler, v_UVCoord1);\n #endif\n\n color.rgb *= color.a * dot(normalize(v_Normal), normalize(vec3(0, 1, 3))) * 5.0;\n float w = weight(gl_FragCoord.z, color.a);\n gl_FragData[0] = vec4(color.rgb * w, color.a);\n gl_FragData[1] = vec4(color.a * w);\n }\n ";
|
|
4046
4017
|
}
|
|
4047
4018
|
}
|
|
4048
4019
|
/**
|
|
@@ -4053,7 +4024,7 @@ function getShadowPassShaderCode(context) {
|
|
|
4053
4024
|
if (isVertexShader) {
|
|
4054
4025
|
return getQuadFilterVS();
|
|
4055
4026
|
} else {
|
|
4056
|
-
return "\n #version 100\n precision highp float;\n uniform sampler2D
|
|
4027
|
+
return "\n #version 100\n precision highp float;\n uniform sampler2D _AccumColorSampler;\n uniform sampler2D _AccumAlphaSampler;\n\n varying vec2 v_UVCoord1;\n void main() {\n vec4 accumColor = texture2D(_AccumColorSampler, v_UVCoord1);\n vec4 accumAlpha = texture2D(_AccumAlphaSampler, v_UVCoord1);\n float finalAlpha = 1.0 - accumColor.a;\n vec3 finalColor = accumColor.rgb / clamp(accumAlpha.r, 0.001, 50000.0);\n gl_FragColor = vec4(finalColor, finalAlpha);\n }\n ";
|
|
4057
4028
|
}
|
|
4058
4029
|
}
|
|
4059
4030
|
function getBasicVS(params) {
|
|
@@ -4067,11 +4038,11 @@ function getBasicVS(params) {
|
|
|
4067
4038
|
if (params.hasNormals) {
|
|
4068
4039
|
featureList.push("#define HAS_NORMALS 1");
|
|
4069
4040
|
}
|
|
4070
|
-
featureList.push("\n precision highp float;\n\n uniform mat4
|
|
4041
|
+
featureList.push("\n precision highp float;\n\n uniform mat4 _ModelMatrix;\n uniform mat4 _ViewProjectionMatrix;\n attribute vec3 aPos;\n varying vec3 v_Position;\n\n #ifdef HAS_UVS\n attribute vec2 aUV;\n varying vec2 v_UVCoord1;\n #endif\n\n #ifdef HAS_NORMALS\n uniform mat4 _NormalMatrix;\n attribute vec3 aNormal;\n varying vec3 v_Normal;\n #endif\n\n void main(){\n vec4 pos = _ModelMatrix * vec4(aPos, 1);\n v_Position = pos.xyz / pos.w;\n\n #ifdef HAS_UVS\n v_UVCoord1 = aUV;\n #endif\n\n #ifdef HAS_NORMALS\n v_Normal = normalize(vec3(_ModelMatrix * vec4(aNormal, 0)));\n #endif\n\n gl_Position = _ViewProjectionMatrix * pos;\n }\n ");
|
|
4071
4042
|
return featureList.join("\n");
|
|
4072
4043
|
}
|
|
4073
4044
|
function getQuadFilterVS() {
|
|
4074
|
-
return "\n #version 100\n precision highp float;\n attribute vec3
|
|
4045
|
+
return "\n #version 100\n precision highp float;\n attribute vec3 aPos;\n attribute vec2 aUV;\n\n varying vec2 v_UVCoord1;\n void main(){\n v_UVCoord1 = aUV;\n gl_Position = vec4(aPos.xy, 0.0, 1.0);\n }\n ";
|
|
4075
4046
|
}
|
|
4076
4047
|
|
|
4077
4048
|
/**
|
|
@@ -5389,26 +5360,26 @@ var normal = new Vector3();
|
|
|
5389
5360
|
var data = MeshHelper.getPlaneVertexArray();
|
|
5390
5361
|
return {
|
|
5391
5362
|
attributes: {
|
|
5392
|
-
|
|
5363
|
+
aPos: {
|
|
5393
5364
|
type: effects.glContext.FLOAT,
|
|
5394
5365
|
size: 3,
|
|
5395
5366
|
data: data,
|
|
5396
5367
|
stride: Float32Array.BYTES_PER_ELEMENT * 8,
|
|
5397
5368
|
offset: 0
|
|
5398
5369
|
},
|
|
5399
|
-
|
|
5370
|
+
aUV: {
|
|
5400
5371
|
type: effects.glContext.FLOAT,
|
|
5401
5372
|
size: 2,
|
|
5402
5373
|
stride: Float32Array.BYTES_PER_ELEMENT * 8,
|
|
5403
5374
|
offset: Float32Array.BYTES_PER_ELEMENT * 3,
|
|
5404
|
-
dataSource: "
|
|
5375
|
+
dataSource: "aPos"
|
|
5405
5376
|
},
|
|
5406
|
-
|
|
5377
|
+
aNormal: {
|
|
5407
5378
|
type: effects.glContext.FLOAT,
|
|
5408
5379
|
size: 3,
|
|
5409
5380
|
stride: Float32Array.BYTES_PER_ELEMENT * 8,
|
|
5410
5381
|
offset: Float32Array.BYTES_PER_ELEMENT * 5,
|
|
5411
|
-
dataSource: "
|
|
5382
|
+
dataSource: "aPos"
|
|
5412
5383
|
}
|
|
5413
5384
|
},
|
|
5414
5385
|
drawStart: 0,
|
|
@@ -6015,23 +5986,23 @@ var normal = new Vector3();
|
|
|
6015
5986
|
*/ PluginHelper.getAttributeName = function getAttributeName(name) {
|
|
6016
5987
|
switch(name){
|
|
6017
5988
|
case "POSITION":
|
|
6018
|
-
return "
|
|
5989
|
+
return "aPos";
|
|
6019
5990
|
case "NORMAL":
|
|
6020
|
-
return "
|
|
5991
|
+
return "aNormal";
|
|
6021
5992
|
case "TANGENT":
|
|
6022
5993
|
return "a_Tangent";
|
|
6023
5994
|
case "TEXCOORD_0":
|
|
6024
|
-
return "
|
|
5995
|
+
return "aUV";
|
|
6025
5996
|
case "TEXCOORD_1":
|
|
6026
|
-
return "
|
|
5997
|
+
return "aUV2";
|
|
6027
5998
|
case "JOINTS_0":
|
|
6028
5999
|
return "a_Joint1";
|
|
6029
6000
|
case "WEIGHTS_0":
|
|
6030
6001
|
return "a_Weight1";
|
|
6031
6002
|
}
|
|
6032
6003
|
if (!name.startsWith("a_")) {
|
|
6033
|
-
//
|
|
6034
|
-
//
|
|
6004
|
+
// aPos, aNormal, a_Tangent,
|
|
6005
|
+
// aUV, aUV2, a_Joint1, a_Weight1
|
|
6035
6006
|
// a_Target_XXX
|
|
6036
6007
|
console.warn("Unknown attribute name: " + name);
|
|
6037
6008
|
}
|
|
@@ -6422,8 +6393,8 @@ var AttributeArray = /*#__PURE__*/ function() {
|
|
|
6422
6393
|
var attributes = geometry.attributes;
|
|
6423
6394
|
//
|
|
6424
6395
|
this.index = geometry.getIndexData();
|
|
6425
|
-
var positionAttrib = attributes["
|
|
6426
|
-
var positionArray = geometry.getAttributeData("
|
|
6396
|
+
var positionAttrib = attributes["aPos"];
|
|
6397
|
+
var positionArray = geometry.getAttributeData("aPos");
|
|
6427
6398
|
this.position = new AttributeArray();
|
|
6428
6399
|
this.position.create(positionAttrib, positionArray);
|
|
6429
6400
|
//
|
|
@@ -6536,8 +6507,8 @@ var AttributeArray = /*#__PURE__*/ function() {
|
|
|
6536
6507
|
var attributes = geometry.attributes;
|
|
6537
6508
|
//
|
|
6538
6509
|
this.index = geometry.getIndexData();
|
|
6539
|
-
var positionAttrib = attributes["
|
|
6540
|
-
var positionArray = geometry.getAttributeData("
|
|
6510
|
+
var positionAttrib = attributes["aPos"];
|
|
6511
|
+
var positionArray = geometry.getAttributeData("aPos");
|
|
6541
6512
|
this.position = new AttributeArray();
|
|
6542
6513
|
this.position.create(positionAttrib, positionArray);
|
|
6543
6514
|
//
|
|
@@ -6961,14 +6932,14 @@ var AttributeArray = /*#__PURE__*/ function() {
|
|
|
6961
6932
|
// }
|
|
6962
6933
|
// maxLength = maxIndex + 1;
|
|
6963
6934
|
// }
|
|
6964
|
-
// const positionAttrib = opts.attributes['
|
|
6935
|
+
// const positionAttrib = opts.attributes['aPos'] as Attribute;
|
|
6965
6936
|
// if (positionAttrib === undefined) {
|
|
6966
6937
|
// throw new Error(`Position attribute is required, ${this.stringify(v)}`);
|
|
6967
6938
|
// }
|
|
6968
|
-
// this.assertGeometryBuffer(v, '
|
|
6969
|
-
// this.assertGeometryBuffer(v, '
|
|
6939
|
+
// this.assertGeometryBuffer(v, 'aPos', maxLength);
|
|
6940
|
+
// this.assertGeometryBuffer(v, 'aNormal', maxLength);
|
|
6970
6941
|
// this.assertGeometryBuffer(v, 'a_Tangent', maxLength);
|
|
6971
|
-
// this.assertGeometryBuffer(v, '
|
|
6942
|
+
// this.assertGeometryBuffer(v, 'aUV', maxLength);
|
|
6972
6943
|
// this.assertGeometryBuffer(v, 'a_Joint1', maxLength);
|
|
6973
6944
|
// this.assertGeometryBuffer(v, 'a_Weight1', maxLength);
|
|
6974
6945
|
// // 索引检查
|
|
@@ -7602,13 +7573,13 @@ var toHalf = function() {
|
|
|
7602
7573
|
* @param material - GE 材质
|
|
7603
7574
|
*/ _proto.updateUniforms = function updateUniforms(material) {
|
|
7604
7575
|
if (this.isMasked()) {
|
|
7605
|
-
material.setFloat("
|
|
7576
|
+
material.setFloat("_AlphaCutoff", this.alphaCutOff);
|
|
7606
7577
|
}
|
|
7607
7578
|
// 渲染 UV 结果输出时,设置 uv 大小
|
|
7608
7579
|
var renderMode = PGlobalState.getInstance().renderMode3D;
|
|
7609
7580
|
if (renderMode === effects.spec.RenderMode3D.uv) {
|
|
7610
7581
|
var debugUVGridSize = PGlobalState.getInstance().renderMode3DUVGridSize;
|
|
7611
|
-
material.setFloat("
|
|
7582
|
+
material.setFloat("_DebugUVGridSize", debugUVGridSize);
|
|
7612
7583
|
}
|
|
7613
7584
|
};
|
|
7614
7585
|
/**
|
|
@@ -7852,15 +7823,15 @@ var toHalf = function() {
|
|
|
7852
7823
|
PMaterialBase.prototype.updateUniforms.call(this, material);
|
|
7853
7824
|
//
|
|
7854
7825
|
var uvTransform = new Matrix3().identity();
|
|
7855
|
-
material.setVector4("
|
|
7826
|
+
material.setVector4("_BaseColorFactor", this.baseColorFactor);
|
|
7856
7827
|
if (this.hasBaseColorTexture()) {
|
|
7857
|
-
material.setTexture("
|
|
7858
|
-
material.setInt("
|
|
7859
|
-
material.setMatrix3("
|
|
7828
|
+
material.setTexture("_BaseColorSampler", this.getBaseColorTexture());
|
|
7829
|
+
material.setInt("_BaseColorUVSet", 0);
|
|
7830
|
+
material.setMatrix3("_BaseColorUVTransform", uvTransform);
|
|
7860
7831
|
}
|
|
7861
|
-
material.setFloat("
|
|
7862
|
-
material.setFloat("
|
|
7863
|
-
material.setFloat("
|
|
7832
|
+
material.setFloat("_MetallicFactor", 0.0);
|
|
7833
|
+
material.setFloat("_RoughnessFactor", 0.0);
|
|
7834
|
+
material.setFloat("_Exposure", 1.0);
|
|
7864
7835
|
};
|
|
7865
7836
|
/**
|
|
7866
7837
|
* 是否有基础颜色纹理
|
|
@@ -8007,41 +7978,39 @@ var toHalf = function() {
|
|
|
8007
7978
|
this.materialType = mat.getInt("shaderType") ? exports.PMaterialType.unlit : exports.PMaterialType.pbr;
|
|
8008
7979
|
var _mat_getTexture;
|
|
8009
7980
|
//
|
|
8010
|
-
this.baseColorTexture = (_mat_getTexture = mat.getTexture("
|
|
7981
|
+
this.baseColorTexture = (_mat_getTexture = mat.getTexture("_BaseColorSampler")) != null ? _mat_getTexture : undefined;
|
|
8011
7982
|
var _mat_getVector4;
|
|
8012
|
-
this.baseColorFactor = (_mat_getVector4 = mat.getVector4("
|
|
8013
|
-
this.baseColorFactor.multiply(1 / 255.0);
|
|
7983
|
+
this.baseColorFactor = (_mat_getVector4 = mat.getVector4("_BaseColorFactor")) != null ? _mat_getVector4 : new Vector4(1.0, 1.0, 1.0, 1.0);
|
|
8014
7984
|
var _mat_getTexture1;
|
|
8015
|
-
this.metallicRoughnessTexture = (_mat_getTexture1 = mat.getTexture("
|
|
8016
|
-
this.useSpecularAA = mat.
|
|
7985
|
+
this.metallicRoughnessTexture = (_mat_getTexture1 = mat.getTexture("_MetallicRoughnessSampler")) != null ? _mat_getTexture1 : undefined;
|
|
7986
|
+
this.useSpecularAA = mat.getFloat("_useSpecularAA") === 1;
|
|
8017
7987
|
var _mat_getFloat;
|
|
8018
|
-
this.metallicFactor = (_mat_getFloat = mat.getFloat("
|
|
7988
|
+
this.metallicFactor = (_mat_getFloat = mat.getFloat("_MetallicFactor")) != null ? _mat_getFloat : 1;
|
|
8019
7989
|
var _mat_getFloat1;
|
|
8020
|
-
this.roughnessFactor = (_mat_getFloat1 = mat.getFloat("
|
|
7990
|
+
this.roughnessFactor = (_mat_getFloat1 = mat.getFloat("_RoughnessFactor")) != null ? _mat_getFloat1 : 1;
|
|
8021
7991
|
var _mat_getTexture2;
|
|
8022
|
-
this.normalTexture = (_mat_getTexture2 = mat.getTexture("
|
|
7992
|
+
this.normalTexture = (_mat_getTexture2 = mat.getTexture("_NormalSampler")) != null ? _mat_getTexture2 : undefined;
|
|
8023
7993
|
var _mat_getFloat2;
|
|
8024
|
-
this.normalTextureScale = (_mat_getFloat2 = mat.getFloat("
|
|
7994
|
+
this.normalTextureScale = (_mat_getFloat2 = mat.getFloat("_NormalScale")) != null ? _mat_getFloat2 : 1;
|
|
8025
7995
|
var _mat_getTexture3;
|
|
8026
|
-
this.occlusionTexture = (_mat_getTexture3 = mat.getTexture("
|
|
7996
|
+
this.occlusionTexture = (_mat_getTexture3 = mat.getTexture("_OcclusionSampler")) != null ? _mat_getTexture3 : undefined;
|
|
8027
7997
|
var _mat_getFloat3;
|
|
8028
|
-
this.occlusionTextureStrength = (_mat_getFloat3 = mat.getFloat("
|
|
7998
|
+
this.occlusionTextureStrength = (_mat_getFloat3 = mat.getFloat("_OcclusionTextureStrength")) != null ? _mat_getFloat3 : 1;
|
|
8029
7999
|
var _mat_getTexture4;
|
|
8030
|
-
this.emissiveTexture = (_mat_getTexture4 = mat.getTexture("
|
|
8000
|
+
this.emissiveTexture = (_mat_getTexture4 = mat.getTexture("_EmissiveSampler")) != null ? _mat_getTexture4 : undefined;
|
|
8031
8001
|
var _mat_getVector41;
|
|
8032
|
-
this.emissiveFactor = (_mat_getVector41 = mat.getVector4("
|
|
8033
|
-
this.emissiveFactor.multiply(1 / 255.0);
|
|
8002
|
+
this.emissiveFactor = (_mat_getVector41 = mat.getVector4("_EmissiveFactor")) != null ? _mat_getVector41 : new Vector4(0, 0, 0, 0);
|
|
8034
8003
|
var _mat_getFloat4;
|
|
8035
|
-
this.emissiveIntensity = (_mat_getFloat4 = mat.getFloat("
|
|
8004
|
+
this.emissiveIntensity = (_mat_getFloat4 = mat.getFloat("_EmissiveIntensity")) != null ? _mat_getFloat4 : 1;
|
|
8036
8005
|
var emissiveFactor = this.emissiveFactor.clone().multiply(this.emissiveIntensity);
|
|
8037
|
-
mat.setVector4("
|
|
8006
|
+
mat.setVector4("_EmissiveFactor", emissiveFactor);
|
|
8038
8007
|
this.enableShadow = false;
|
|
8039
|
-
this.depthMask =
|
|
8008
|
+
this.depthMask = true;
|
|
8040
8009
|
var _mat_getInt;
|
|
8041
8010
|
var blending = (_mat_getInt = mat.getInt("blending")) != null ? _mat_getInt : effects.spec.MaterialBlending.opaque;
|
|
8042
8011
|
this.blendMode = this.getBlendMode(blending);
|
|
8043
8012
|
var _mat_getFloat5;
|
|
8044
|
-
this.alphaCutOff = (_mat_getFloat5 = mat.getFloat("
|
|
8013
|
+
this.alphaCutOff = (_mat_getFloat5 = mat.getFloat("_AlphaCutoff")) != null ? _mat_getFloat5 : 0;
|
|
8045
8014
|
var _mat_getInt1;
|
|
8046
8015
|
var side = (_mat_getInt1 = mat.getInt("side")) != null ? _mat_getInt1 : effects.spec.SideMode.FRONT;
|
|
8047
8016
|
this.faceSideMode = this.getFaceSideMode(side);
|
|
@@ -8107,99 +8076,99 @@ var toHalf = function() {
|
|
|
8107
8076
|
if (this.fromMaterial) {
|
|
8108
8077
|
var uvTransform = new Matrix3().identity();
|
|
8109
8078
|
if (this.baseColorTexture !== undefined) {
|
|
8110
|
-
material.setInt("
|
|
8111
|
-
material.setMatrix3("
|
|
8079
|
+
material.setInt("_BaseColorUVSet", 0);
|
|
8080
|
+
material.setMatrix3("_BaseColorUVTransform", uvTransform);
|
|
8112
8081
|
}
|
|
8113
8082
|
//
|
|
8114
8083
|
if (this.metallicRoughnessTexture !== undefined) {
|
|
8115
|
-
material.setInt("
|
|
8116
|
-
material.setMatrix3("
|
|
8084
|
+
material.setInt("_MetallicRoughnessUVSet", 0);
|
|
8085
|
+
material.setMatrix3("_MetallicRoughnessUVTransform", uvTransform);
|
|
8117
8086
|
}
|
|
8118
8087
|
//
|
|
8119
8088
|
if (this.normalTexture !== undefined) {
|
|
8120
|
-
material.setInt("
|
|
8121
|
-
material.setMatrix3("
|
|
8089
|
+
material.setInt("_NormalUVSet", 0);
|
|
8090
|
+
material.setMatrix3("_NormalUVTransform", uvTransform);
|
|
8122
8091
|
}
|
|
8123
8092
|
//
|
|
8124
8093
|
if (this.occlusionTexture !== undefined) {
|
|
8125
|
-
material.setInt("
|
|
8126
|
-
material.setMatrix3("
|
|
8094
|
+
material.setInt("_OcclusionUVSet", 0);
|
|
8095
|
+
material.setMatrix3("_OcclusionUVTransform", uvTransform);
|
|
8127
8096
|
}
|
|
8128
8097
|
//
|
|
8129
8098
|
if (this.emissiveTexture !== undefined) {
|
|
8130
|
-
material.setInt("
|
|
8131
|
-
material.setMatrix3("
|
|
8099
|
+
material.setInt("_EmissiveUVSet", 0);
|
|
8100
|
+
material.setMatrix3("_EmissiveUVTransform", uvTransform);
|
|
8132
8101
|
}
|
|
8133
|
-
material.setFloat("
|
|
8102
|
+
material.setFloat("_Exposure", 3.0);
|
|
8134
8103
|
return;
|
|
8135
8104
|
}
|
|
8136
8105
|
//
|
|
8137
8106
|
var uvTransform1 = new Matrix3().identity();
|
|
8138
|
-
material.setVector4("
|
|
8107
|
+
material.setVector4("_BaseColorFactor", this.baseColorFactor);
|
|
8139
8108
|
if (this.baseColorTexture !== undefined) {
|
|
8140
|
-
material.setTexture("
|
|
8141
|
-
material.setInt("
|
|
8109
|
+
material.setTexture("_BaseColorSampler", this.baseColorTexture);
|
|
8110
|
+
material.setInt("_BaseColorUVSet", 0);
|
|
8142
8111
|
if (this.baseColorTextureTrans !== undefined) {
|
|
8143
|
-
material.setMatrix3("
|
|
8112
|
+
material.setMatrix3("_BaseColorUVTransform", this.baseColorTextureTrans);
|
|
8144
8113
|
} else {
|
|
8145
8114
|
// fill other data
|
|
8146
|
-
material.setMatrix3("
|
|
8115
|
+
material.setMatrix3("_BaseColorUVTransform", uvTransform1);
|
|
8147
8116
|
}
|
|
8148
8117
|
}
|
|
8149
8118
|
//
|
|
8150
|
-
material.setFloat("
|
|
8151
|
-
material.setFloat("
|
|
8119
|
+
material.setFloat("_MetallicFactor", this.metallicFactor);
|
|
8120
|
+
material.setFloat("_RoughnessFactor", this.roughnessFactor);
|
|
8152
8121
|
if (this.metallicRoughnessTexture !== undefined) {
|
|
8153
|
-
material.setTexture("
|
|
8154
|
-
material.setInt("
|
|
8122
|
+
material.setTexture("_MetallicRoughnessSampler", this.metallicRoughnessTexture);
|
|
8123
|
+
material.setInt("_MetallicRoughnessUVSet", 0);
|
|
8155
8124
|
if (this.metallicRoughnessTextureTrans !== undefined) {
|
|
8156
|
-
material.setMatrix3("
|
|
8125
|
+
material.setMatrix3("_MetallicRoughnessUVTransform", this.metallicRoughnessTextureTrans);
|
|
8157
8126
|
} else {
|
|
8158
8127
|
// fill other data
|
|
8159
|
-
material.setMatrix3("
|
|
8128
|
+
material.setMatrix3("_MetallicRoughnessUVTransform", uvTransform1);
|
|
8160
8129
|
}
|
|
8161
8130
|
}
|
|
8162
8131
|
//
|
|
8163
8132
|
if (this.normalTexture !== undefined) {
|
|
8164
|
-
material.setTexture("
|
|
8165
|
-
material.setFloat("
|
|
8166
|
-
material.setInt("
|
|
8133
|
+
material.setTexture("_NormalSampler", this.normalTexture);
|
|
8134
|
+
material.setFloat("_NormalScale", this.normalTextureScale);
|
|
8135
|
+
material.setInt("_NormalUVSet", 0);
|
|
8167
8136
|
if (this.normalTextureTrans !== undefined) {
|
|
8168
|
-
material.setMatrix3("
|
|
8137
|
+
material.setMatrix3("_NormalUVTransform", this.normalTextureTrans);
|
|
8169
8138
|
} else {
|
|
8170
8139
|
// fill other data
|
|
8171
|
-
material.setMatrix3("
|
|
8140
|
+
material.setMatrix3("_NormalUVTransform", uvTransform1);
|
|
8172
8141
|
}
|
|
8173
8142
|
}
|
|
8174
8143
|
//
|
|
8175
8144
|
if (this.occlusionTexture !== undefined) {
|
|
8176
|
-
material.setTexture("
|
|
8177
|
-
material.setFloat("
|
|
8178
|
-
material.setInt("
|
|
8145
|
+
material.setTexture("_OcclusionSampler", this.occlusionTexture);
|
|
8146
|
+
material.setFloat("_OcclusionStrength", this.occlusionTextureStrength);
|
|
8147
|
+
material.setInt("_OcclusionUVSet", 0);
|
|
8179
8148
|
if (this.occlusionTextureTrans !== undefined) {
|
|
8180
|
-
material.setMatrix3("
|
|
8149
|
+
material.setMatrix3("_OcclusionUVTransform", this.occlusionTextureTrans);
|
|
8181
8150
|
} else {
|
|
8182
8151
|
// fill other data
|
|
8183
|
-
material.setMatrix3("
|
|
8152
|
+
material.setMatrix3("_OcclusionUVTransform", uvTransform1);
|
|
8184
8153
|
}
|
|
8185
8154
|
}
|
|
8186
8155
|
//
|
|
8187
8156
|
if (this.emissiveTexture !== undefined) {
|
|
8188
8157
|
var emissiveFactor = this.getEmissiveFactor();
|
|
8189
|
-
material.setTexture("
|
|
8190
|
-
material.setVector4("
|
|
8191
|
-
material.setInt("
|
|
8158
|
+
material.setTexture("_EmissiveSampler", this.emissiveTexture);
|
|
8159
|
+
material.setVector4("_EmissiveFactor", emissiveFactor);
|
|
8160
|
+
material.setInt("_EmissiveUVSet", 0);
|
|
8192
8161
|
if (this.emissiveTextureTrans !== undefined) {
|
|
8193
|
-
material.setMatrix3("
|
|
8162
|
+
material.setMatrix3("_EmissiveUVTransform", this.emissiveTextureTrans);
|
|
8194
8163
|
} else {
|
|
8195
8164
|
// fill other data
|
|
8196
|
-
material.setMatrix3("
|
|
8165
|
+
material.setMatrix3("_EmissiveUVTransform", uvTransform1);
|
|
8197
8166
|
}
|
|
8198
8167
|
} else if (this.hasEmissiveFactor()) {
|
|
8199
8168
|
var emissiveFactor1 = this.getEmissiveFactor();
|
|
8200
|
-
material.setVector4("
|
|
8169
|
+
material.setVector4("_EmissiveFactor", emissiveFactor1);
|
|
8201
8170
|
}
|
|
8202
|
-
material.setFloat("
|
|
8171
|
+
material.setFloat("_Exposure", 3.0);
|
|
8203
8172
|
};
|
|
8204
8173
|
/**
|
|
8205
8174
|
* 是否有基础颜色纹理
|
|
@@ -8507,7 +8476,7 @@ function createInternalMaterial(options) {
|
|
|
8507
8476
|
var newProjViewMatrix = camera.getNewProjectionMatrix(camera.fov).multiply(viewMatrix).invert();
|
|
8508
8477
|
var material = this.skyboxMesh.material;
|
|
8509
8478
|
this.skyboxMaterial.updateUniforms(material);
|
|
8510
|
-
material.setMatrix("
|
|
8479
|
+
material.setMatrix("_InvViewProjectionMatrix", newProjViewMatrix);
|
|
8511
8480
|
}
|
|
8512
8481
|
};
|
|
8513
8482
|
_create_class(PSkybox, [
|
|
@@ -8628,10 +8597,10 @@ function createInternalMaterial(options) {
|
|
|
8628
8597
|
if (this.brdfLUT === undefined) {
|
|
8629
8598
|
throw new Error("Setup brdfLUT for skybox at first.");
|
|
8630
8599
|
}
|
|
8631
|
-
material.setVector2("
|
|
8632
|
-
material.setTexture("
|
|
8600
|
+
material.setVector2("_IblIntensity", new Vector2(2.0, 2.0));
|
|
8601
|
+
material.setTexture("_brdfLUT", this.brdfLUT);
|
|
8633
8602
|
if (this.diffuseImage !== undefined) {
|
|
8634
|
-
material.setTexture("
|
|
8603
|
+
material.setTexture("_DiffuseEnvSampler", this.diffuseImage);
|
|
8635
8604
|
} else {
|
|
8636
8605
|
var coeffs = this.irradianceCoeffs;
|
|
8637
8606
|
if (coeffs === undefined || coeffs.length != 9) {
|
|
@@ -8649,11 +8618,11 @@ function createInternalMaterial(options) {
|
|
|
8649
8618
|
"l22"
|
|
8650
8619
|
];
|
|
8651
8620
|
aliasName.forEach(function(n, i) {
|
|
8652
|
-
material.setVector3("
|
|
8621
|
+
material.setVector3("_shCoefficients." + n, Vector3.fromArray(coeffs[i]));
|
|
8653
8622
|
});
|
|
8654
8623
|
}
|
|
8655
|
-
material.setInt("
|
|
8656
|
-
material.setTexture("
|
|
8624
|
+
material.setInt("_MipCount", this.specularMipCount);
|
|
8625
|
+
material.setTexture("_SpecularEnvSampler", this.specularImage);
|
|
8657
8626
|
};
|
|
8658
8627
|
/**
|
|
8659
8628
|
* 设置对应的材质状态
|
|
@@ -9402,7 +9371,7 @@ exports.PSkyboxType = void 0;
|
|
|
9402
9371
|
* @param options - 加载选项
|
|
9403
9372
|
*/ ModelPlugin.prepareResource = function prepareResource(scene, options) {
|
|
9404
9373
|
return _async_to_generator(function() {
|
|
9405
|
-
var _options_pluginData, _options_pluginData1, keyList, pluginData, _options_env, runtimeEnv, _options_pluginData_compatibleMode,
|
|
9374
|
+
var _options_pluginData, _options_pluginData1, keyList, pluginData, _options_env, runtimeEnv, _options_pluginData_compatibleMode, _options_pluginData_autoAdjustScene;
|
|
9406
9375
|
return __generator(this, function(_state) {
|
|
9407
9376
|
switch(_state.label){
|
|
9408
9377
|
case 0:
|
|
@@ -9424,10 +9393,10 @@ exports.PSkyboxType = void 0;
|
|
|
9424
9393
|
//
|
|
9425
9394
|
runtimeEnv = (_options_env = options.env) != null ? _options_env : "";
|
|
9426
9395
|
scene.storage["runtimeEnv"] = runtimeEnv;
|
|
9427
|
-
|
|
9428
|
-
|
|
9396
|
+
(_options_pluginData_compatibleMode = (_options_pluginData = options.pluginData) == null ? void 0 : _options_pluginData["compatibleMode"]) != null ? _options_pluginData_compatibleMode : "gltf";
|
|
9397
|
+
(_options_pluginData_autoAdjustScene = (_options_pluginData1 = options.pluginData) == null ? void 0 : _options_pluginData1["autoAdjustScene"]) != null ? _options_pluginData_autoAdjustScene : false;
|
|
9429
9398
|
//
|
|
9430
|
-
PluginHelper.preprocessScene(scene, runtimeEnv, compatibleMode, autoAdjustScene);
|
|
9399
|
+
//PluginHelper.preprocessScene(scene, runtimeEnv, compatibleMode, autoAdjustScene);
|
|
9431
9400
|
return [
|
|
9432
9401
|
4,
|
|
9433
9402
|
CompositionCache.loadStaticResources()
|
|
@@ -11240,14 +11209,14 @@ var GeometryProxy = /*#__PURE__*/ function() {
|
|
|
11240
11209
|
var attributes = {};
|
|
11241
11210
|
if (this.hasPosition) {
|
|
11242
11211
|
var attrib = this.positionAttrib;
|
|
11243
|
-
attributes["
|
|
11212
|
+
attributes["aPos"] = this._getBufferAttrib(attrib);
|
|
11244
11213
|
} else {
|
|
11245
11214
|
throw new Error("Position attribute missing");
|
|
11246
11215
|
}
|
|
11247
11216
|
if (this.hasNormal) {
|
|
11248
11217
|
var attrib1 = this.normalAttrib;
|
|
11249
11218
|
if (attrib1 !== undefined) {
|
|
11250
|
-
attributes["
|
|
11219
|
+
attributes["aNormal"] = this._getBufferAttrib(attrib1);
|
|
11251
11220
|
}
|
|
11252
11221
|
}
|
|
11253
11222
|
if (this.hasTangent) {
|
|
@@ -11258,7 +11227,7 @@ var GeometryProxy = /*#__PURE__*/ function() {
|
|
|
11258
11227
|
}
|
|
11259
11228
|
this.texCoordList.forEach(function(val) {
|
|
11260
11229
|
var attrib = _this.texCoordAttrib(val);
|
|
11261
|
-
var attribName = "
|
|
11230
|
+
var attribName = "aUV" + (val + 1);
|
|
11262
11231
|
attributes[attribName] = _this._getBufferAttrib(attrib);
|
|
11263
11232
|
});
|
|
11264
11233
|
if (this.hasSkinAnimation) {
|
|
@@ -11736,7 +11705,7 @@ var GLTFHelper = /*#__PURE__*/ function() {
|
|
|
11736
11705
|
|
|
11737
11706
|
effects.registerPlugin("tree", ModelTreePlugin, effects.VFXItem, true);
|
|
11738
11707
|
effects.registerPlugin("model", ModelPlugin, effects.VFXItem);
|
|
11739
|
-
var version = "2.0.0-alpha.
|
|
11708
|
+
var version = "2.0.0-alpha.7";
|
|
11740
11709
|
effects.logger.info("plugin model version: " + version);
|
|
11741
11710
|
|
|
11742
11711
|
exports.BoxMesh = BoxMesh;
|