@galacean/effects-plugin-model 2.0.0-alpha.7 → 2.0.0-alpha.9
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 +2 -2
- package/dist/gltf/loader-ecs.d.ts +21 -7
- package/dist/gltf/protocol.d.ts +17 -7
- package/dist/index.js +552 -449
- 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 +550 -450
- package/dist/index.mjs.map +1 -1
- package/dist/loader.mjs +4439 -4336
- package/dist/loader.mjs.map +1 -1
- package/dist/runtime/common.d.ts +2 -0
- package/dist/runtime/material.d.ts +76 -93
- package/dist/runtime/math.d.ts +2 -1
- package/dist/runtime/mesh.d.ts +5 -0
- package/dist/runtime/shader-libs/standard-shader-source.d.ts +1 -0
- package/dist/runtime/shader-libs/standard-shader.d.ts +8 -0
- package/dist/runtime/skybox.d.ts +1 -1
- package/dist/utility/plugin-helper.d.ts +7 -6
- package/dist/utility/shader-helper.d.ts +2 -0
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* Description: Galacean Effects player model plugin
|
|
4
4
|
* Author: Ant Group CO., Ltd.
|
|
5
5
|
* Contributors: 飂兮
|
|
6
|
-
* Version: v2.0.0-alpha.
|
|
6
|
+
* Version: v2.0.0-alpha.9
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { math, Transform, PLAYER_OPTIONS_ENV_EDITOR, spec, glContext, Texture, TextureSourceType, RenderPassAttachmentStorageType, Material, Mesh, Geometry,
|
|
9
|
+
import { math, Transform, PLAYER_OPTIONS_ENV_EDITOR, spec, glContext, Texture, TextureSourceType, RenderPassAttachmentStorageType, Material, Mesh, Geometry, GLSLVersion, DestroyOptions, addItem, removeItem, effectsClass, RendererComponent, ItemBehaviour, TimelineComponent, HitTestType, RenderPass, TextureLoadAction, RenderPassDestroyAttachmentType, Player, Renderer, getDefaultTextureFactory, loadImage, VFXItem, AbstractPlugin, registerPlugin, logger } from '@galacean/effects';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Model 插件元素类型
|
|
@@ -199,7 +199,7 @@ function _extends() {
|
|
|
199
199
|
return _extends.apply(this, arguments);
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
-
var Vector2 = math.Vector2, Vector3 = math.Vector3, Vector4 = math.Vector4, Matrix3 = math.Matrix3, Matrix4 = math.Matrix4, Euler = math.Euler, EulerOrder = math.EulerOrder, Quaternion = math.Quaternion, Box3 = math.Box3; math.Sphere; math.Ray; var DEG2RAD = math.DEG2RAD;
|
|
202
|
+
var Vector2 = math.Vector2, Vector3 = math.Vector3, Vector4 = math.Vector4, Matrix3 = math.Matrix3, Matrix4 = math.Matrix4, Color = math.Color, Euler = math.Euler, EulerOrder = math.EulerOrder, Quaternion = math.Quaternion, Box3 = math.Box3; math.Sphere; math.Ray; var DEG2RAD = math.DEG2RAD;
|
|
203
203
|
|
|
204
204
|
var PObjectType;
|
|
205
205
|
(function(PObjectType) {
|
|
@@ -264,6 +264,8 @@ var PShadowType;
|
|
|
264
264
|
PShadowType[PShadowType["variance"] = 2] = "variance";
|
|
265
265
|
PShadowType[PShadowType["expVariance"] = 3] = "expVariance";
|
|
266
266
|
})(PShadowType || (PShadowType = {}));
|
|
267
|
+
var PBRShaderGUID = "pbr00000000000000000000000000000";
|
|
268
|
+
var UnlitShaderGUID = "unlit000000000000000000000000000";
|
|
267
269
|
/**
|
|
268
270
|
* 插件变换类
|
|
269
271
|
*/ var PTransform = /*#__PURE__*/ function() {
|
|
@@ -2081,11 +2083,11 @@ var deg2rad = Math.PI / 180;
|
|
|
2081
2083
|
var color = data.color;
|
|
2082
2084
|
_this.color = new Vector3(color.r, color.g, color.b);
|
|
2083
2085
|
_this.intensity = data.intensity;
|
|
2084
|
-
if (data.lightType ===
|
|
2086
|
+
if (data.lightType === spec.LightType.point) {
|
|
2085
2087
|
_this.lightType = PLightType.point;
|
|
2086
2088
|
var _data_range;
|
|
2087
2089
|
_this.range = (_data_range = data.range) != null ? _data_range : -1;
|
|
2088
|
-
} else if (data.lightType ===
|
|
2090
|
+
} else if (data.lightType === spec.LightType.spot) {
|
|
2089
2091
|
_this.lightType = PLightType.spot;
|
|
2090
2092
|
var _data_range1;
|
|
2091
2093
|
_this.range = (_data_range1 = data.range) != null ? _data_range1 : -1;
|
|
@@ -2093,7 +2095,7 @@ var deg2rad = Math.PI / 180;
|
|
|
2093
2095
|
_this.outerConeAngle = (_data_outerConeAngle = data.outerConeAngle) != null ? _data_outerConeAngle : Math.PI;
|
|
2094
2096
|
var _data_innerConeAngle;
|
|
2095
2097
|
_this.innerConeAngle = (_data_innerConeAngle = data.innerConeAngle) != null ? _data_innerConeAngle : 0;
|
|
2096
|
-
} else if (data.lightType ===
|
|
2098
|
+
} else if (data.lightType === spec.LightType.directional) {
|
|
2097
2099
|
_this.lightType = PLightType.directional;
|
|
2098
2100
|
} else {
|
|
2099
2101
|
_this.lightType = PLightType.ambient;
|
|
@@ -2506,14 +2508,10 @@ function _assert_this_initialized(self) {
|
|
|
2506
2508
|
this.updateMaterial(scene);
|
|
2507
2509
|
this.primitives.forEach(function(prim) {
|
|
2508
2510
|
var mesh = prim.effectsMesh;
|
|
2509
|
-
mesh.geometry.flush();
|
|
2510
|
-
mesh.material.initialize();
|
|
2511
2511
|
renderer.drawGeometry(mesh.geometry, mesh.material);
|
|
2512
2512
|
});
|
|
2513
2513
|
if (this.visBoundingBox && this.boundingBoxMesh !== undefined) {
|
|
2514
2514
|
var mesh = this.boundingBoxMesh.mesh;
|
|
2515
|
-
mesh.geometry.flush();
|
|
2516
|
-
mesh.material.initialize();
|
|
2517
2515
|
renderer.drawGeometry(mesh.geometry, mesh.material);
|
|
2518
2516
|
}
|
|
2519
2517
|
};
|
|
@@ -2797,8 +2795,8 @@ function _assert_this_initialized(self) {
|
|
|
2797
2795
|
* @param skybox - 天空盒
|
|
2798
2796
|
*/ _proto.build = function build(lightCount, uniformSemantics, skybox) {
|
|
2799
2797
|
var globalState = PGlobalState.getInstance();
|
|
2800
|
-
var
|
|
2801
|
-
this.material.
|
|
2798
|
+
var primitiveMacroList = this.getMacroList(lightCount, true, skybox);
|
|
2799
|
+
var materialMacroList = this.material.getMacroList(primitiveMacroList);
|
|
2802
2800
|
var newSemantics = uniformSemantics != null ? uniformSemantics : {};
|
|
2803
2801
|
newSemantics["_ViewProjectionMatrix"] = "VIEWPROJECTION";
|
|
2804
2802
|
//newSemantics["uView"] = 'VIEWINVERSE';
|
|
@@ -2806,23 +2804,14 @@ function _assert_this_initialized(self) {
|
|
|
2806
2804
|
newSemantics["uEditorTransform"] = "EDITOR_TRANSFORM";
|
|
2807
2805
|
var material;
|
|
2808
2806
|
var isWebGL2 = PGlobalState.getInstance().isWebGL2;
|
|
2809
|
-
if (this.material.
|
|
2810
|
-
material = this.material.
|
|
2807
|
+
if (this.material.effectMaterial) {
|
|
2808
|
+
material = this.material.effectMaterial;
|
|
2811
2809
|
// @ts-expect-error
|
|
2812
2810
|
material.uniformSemantics = newSemantics;
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
//id: 'pbr00000000000000000000000000000',
|
|
2817
|
-
id: generateGUID(),
|
|
2818
|
-
dataType: "Shader",
|
|
2819
|
-
vertex: this.material.vertexShaderCode,
|
|
2820
|
-
fragment: this.material.fragmentShaderCode,
|
|
2821
|
-
// @ts-expect-error
|
|
2822
|
-
glslVersion: isWebGL2 ? GLSLVersion.GLSL3 : GLSLVersion.GLSL1
|
|
2811
|
+
materialMacroList.forEach(function(macro) {
|
|
2812
|
+
var name = macro.name, value = macro.value;
|
|
2813
|
+
material.enableMacro(name, value);
|
|
2823
2814
|
});
|
|
2824
|
-
// @ts-expect-error
|
|
2825
|
-
material.shader = shader;
|
|
2826
2815
|
this.material.setMaterialStates(material);
|
|
2827
2816
|
} else {
|
|
2828
2817
|
material = Material.create(this.engine, {
|
|
@@ -2888,11 +2877,14 @@ function _assert_this_initialized(self) {
|
|
|
2888
2877
|
}
|
|
2889
2878
|
}
|
|
2890
2879
|
if (this.material.materialType !== PMaterialType.unlit) {
|
|
2880
|
+
// let hasLight = false;
|
|
2891
2881
|
if (lightCount > 0 && this.geometry.hasNormals()) {
|
|
2882
|
+
// hasLight = true;
|
|
2892
2883
|
featureList.push("USE_PUNCTUAL 1");
|
|
2893
2884
|
featureList.push("LIGHT_COUNT " + lightCount);
|
|
2894
2885
|
}
|
|
2895
2886
|
if (skybox !== undefined && skybox.available) {
|
|
2887
|
+
// hasLight = true;
|
|
2896
2888
|
featureList.push("USE_IBL 1");
|
|
2897
2889
|
featureList.push("USE_TEX_LOD 1");
|
|
2898
2890
|
if (skybox.hasDiffuseImage) ; else {
|
|
@@ -2912,6 +2904,116 @@ function _assert_this_initialized(self) {
|
|
|
2912
2904
|
}
|
|
2913
2905
|
return featureList;
|
|
2914
2906
|
};
|
|
2907
|
+
_proto.getMacroList = function getMacroList(lightCount, pbrPass, skybox) {
|
|
2908
|
+
var macroList = [];
|
|
2909
|
+
if (this.geometry.hasNormals()) {
|
|
2910
|
+
macroList.push({
|
|
2911
|
+
name: "HAS_NORMALS"
|
|
2912
|
+
});
|
|
2913
|
+
}
|
|
2914
|
+
if (this.geometry.hasTangents()) {
|
|
2915
|
+
macroList.push({
|
|
2916
|
+
name: "HAS_TANGENTS"
|
|
2917
|
+
});
|
|
2918
|
+
}
|
|
2919
|
+
if (this.geometry.hasUVCoords(1)) {
|
|
2920
|
+
macroList.push({
|
|
2921
|
+
name: "HAS_UV_SET1"
|
|
2922
|
+
});
|
|
2923
|
+
}
|
|
2924
|
+
if (this.geometry.hasUVCoords(2)) {
|
|
2925
|
+
macroList.push({
|
|
2926
|
+
name: "HAS_UV_SET2"
|
|
2927
|
+
});
|
|
2928
|
+
}
|
|
2929
|
+
if (this.morph !== undefined && this.morph.hasMorph()) {
|
|
2930
|
+
// 存在 Morph 动画,需要配置 Morph 动画相关的 Shader 宏定义
|
|
2931
|
+
// USE_MORPHING 是总开关,WEIGHT_COUNT 是 weights 数组长度(Shader)
|
|
2932
|
+
macroList.push({
|
|
2933
|
+
name: "USE_MORPHING"
|
|
2934
|
+
});
|
|
2935
|
+
macroList.push({
|
|
2936
|
+
name: "WEIGHT_COUNT",
|
|
2937
|
+
value: this.morph.morphWeightsLength
|
|
2938
|
+
});
|
|
2939
|
+
for(var i = 0; i < this.morph.morphWeightsLength; i++){
|
|
2940
|
+
if (this.morph.hasPositionMorph) {
|
|
2941
|
+
macroList.push({
|
|
2942
|
+
name: "HAS_TARGET_POSITION" + i
|
|
2943
|
+
});
|
|
2944
|
+
}
|
|
2945
|
+
if (this.morph.hasNormalMorph) {
|
|
2946
|
+
macroList.push({
|
|
2947
|
+
name: "HAS_TARGET_NORMAL" + i
|
|
2948
|
+
});
|
|
2949
|
+
}
|
|
2950
|
+
if (this.morph.hasTangentMorph) {
|
|
2951
|
+
macroList.push({
|
|
2952
|
+
name: "HAS_TARGET_TANGENT" + i
|
|
2953
|
+
});
|
|
2954
|
+
}
|
|
2955
|
+
}
|
|
2956
|
+
}
|
|
2957
|
+
if (this.skin !== undefined) {
|
|
2958
|
+
macroList.push({
|
|
2959
|
+
name: "USE_SKINNING"
|
|
2960
|
+
});
|
|
2961
|
+
macroList.push({
|
|
2962
|
+
name: "JOINT_COUNT",
|
|
2963
|
+
value: this.skin.getJointCount()
|
|
2964
|
+
});
|
|
2965
|
+
macroList.push({
|
|
2966
|
+
name: "HAS_JOINT_SET1"
|
|
2967
|
+
});
|
|
2968
|
+
macroList.push({
|
|
2969
|
+
name: "HAS_WEIGHT_SET1"
|
|
2970
|
+
});
|
|
2971
|
+
if (this.skin.textureDataMode) {
|
|
2972
|
+
macroList.push({
|
|
2973
|
+
name: "USE_SKINNING_TEXTURE"
|
|
2974
|
+
});
|
|
2975
|
+
}
|
|
2976
|
+
}
|
|
2977
|
+
if (this.material.materialType !== PMaterialType.unlit) {
|
|
2978
|
+
if (lightCount > 0 && this.geometry.hasNormals()) {
|
|
2979
|
+
macroList.push({
|
|
2980
|
+
name: "USE_PUNCTUAL"
|
|
2981
|
+
});
|
|
2982
|
+
macroList.push({
|
|
2983
|
+
name: "LIGHT_COUNT",
|
|
2984
|
+
value: lightCount
|
|
2985
|
+
});
|
|
2986
|
+
}
|
|
2987
|
+
if (skybox !== undefined && skybox.available) {
|
|
2988
|
+
macroList.push({
|
|
2989
|
+
name: "USE_IBL"
|
|
2990
|
+
});
|
|
2991
|
+
macroList.push({
|
|
2992
|
+
name: "USE_TEX_LOD"
|
|
2993
|
+
});
|
|
2994
|
+
if (skybox.hasDiffuseImage) ; else {
|
|
2995
|
+
macroList.push({
|
|
2996
|
+
name: "IRRADIANCE_COEFFICIENTS"
|
|
2997
|
+
});
|
|
2998
|
+
}
|
|
2999
|
+
}
|
|
3000
|
+
// if(!hasLight){
|
|
3001
|
+
// featureList.push('MATERIAL_UNLIT 1');
|
|
3002
|
+
// }
|
|
3003
|
+
}
|
|
3004
|
+
// 渲染中间结果输出,用于渲染效果调试,支持 pbr 和 unlit
|
|
3005
|
+
var renderMode = PGlobalState.getInstance().renderMode3D;
|
|
3006
|
+
var outputDefine = this.getRenderMode3DDefine(renderMode);
|
|
3007
|
+
if (outputDefine !== undefined) {
|
|
3008
|
+
macroList.push({
|
|
3009
|
+
name: "DEBUG_OUTPUT"
|
|
3010
|
+
});
|
|
3011
|
+
macroList.push({
|
|
3012
|
+
name: outputDefine
|
|
3013
|
+
});
|
|
3014
|
+
}
|
|
3015
|
+
return macroList;
|
|
3016
|
+
};
|
|
2915
3017
|
/**
|
|
2916
3018
|
* 销毁,需要释放创建的 GE 对象
|
|
2917
3019
|
*/ _proto.dispose = function dispose() {
|
|
@@ -2968,7 +3070,7 @@ function _assert_this_initialized(self) {
|
|
|
2968
3070
|
});
|
|
2969
3071
|
}
|
|
2970
3072
|
var proxy = new HitTestingProxy();
|
|
2971
|
-
var doubleSided = this.material.
|
|
3073
|
+
var doubleSided = this.material.isDoubleSide();
|
|
2972
3074
|
proxy.create(this.geometry.geometry, doubleSided, bindMatrices);
|
|
2973
3075
|
return proxy.getHitPoint(newOrigin, newDirection);
|
|
2974
3076
|
};
|
|
@@ -3776,9 +3878,9 @@ var EffectsMeshProxy = /*#__PURE__*/ function() {
|
|
|
3776
3878
|
return PSceneManager;
|
|
3777
3879
|
}();
|
|
3778
3880
|
|
|
3779
|
-
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
|
|
3881
|
+
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 aUV2;\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=aUV2;\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}";
|
|
3780
3882
|
|
|
3781
|
-
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}";
|
|
3883
|
+
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*_EmissiveIntensity;\n#endif\n#ifdef HAS_EMISSIVE_MAP\nemissive=SRGBtoLINEAR(texture2D(_EmissiveSampler,getEmissiveUV())).rgb*_EmissiveFactor.rgb*_EmissiveIntensity;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*_EmissiveIntensity;\n#endif\n#ifdef HAS_EMISSIVE_MAP\nemissive=SRGBtoLINEAR(texture2D(_EmissiveSampler,getEmissiveUV())).rgb*_EmissiveFactor.rgb*_EmissiveIntensity;\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}";
|
|
3782
3884
|
|
|
3783
3885
|
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}";
|
|
3784
3886
|
|
|
@@ -3792,7 +3894,7 @@ var extensionsFragGLSL = "vec3 _dFdx(vec3 coord){\n#if defined(GL_OES_standard_d
|
|
|
3792
3894
|
|
|
3793
3895
|
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);}";
|
|
3794
3896
|
|
|
3795
|
-
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;}";
|
|
3897
|
+
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 float _EmissiveIntensity;uniform mat3 _EmissiveUVTransform;\n#endif\n#ifdef HAS_EMISSIVE\nuniform vec4 _EmissiveFactor;uniform float _EmissiveIntensity;\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;}";
|
|
3796
3898
|
|
|
3797
3899
|
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";
|
|
3798
3900
|
|
|
@@ -3835,6 +3937,18 @@ var StandardShaderSource;
|
|
|
3835
3937
|
* @param isWebGL2 - 是否 WebGL2
|
|
3836
3938
|
* @returns 最终代码
|
|
3837
3939
|
*/ StandardShaderSource.build = build;
|
|
3940
|
+
function getSourceCode(source, isWebGL2) {
|
|
3941
|
+
var match;
|
|
3942
|
+
while((match = /#include <(.+)>/gm.exec(source)) !== null){
|
|
3943
|
+
source = source.replace(match[0], glsl[match[1]]);
|
|
3944
|
+
}
|
|
3945
|
+
if (isWebGL2) {
|
|
3946
|
+
return "#version 300 es\n" + source;
|
|
3947
|
+
} else {
|
|
3948
|
+
return "#version 100\n" + source;
|
|
3949
|
+
}
|
|
3950
|
+
}
|
|
3951
|
+
StandardShaderSource.getSourceCode = getSourceCode;
|
|
3838
3952
|
})(StandardShaderSource || (StandardShaderSource = {}));
|
|
3839
3953
|
|
|
3840
3954
|
/**
|
|
@@ -3880,12 +3994,57 @@ var StandardShaderSource;
|
|
|
3880
3994
|
throw new Error("Invalid material type " + materialType + " for getFragmentShaderString!");
|
|
3881
3995
|
}
|
|
3882
3996
|
};
|
|
3997
|
+
StandardShader.genVertexShaderCode = function genVertexShaderCode(materialType, isWebGL2) {
|
|
3998
|
+
switch(materialType){
|
|
3999
|
+
case PMaterialType.unlit:
|
|
4000
|
+
case PMaterialType.pbr:
|
|
4001
|
+
case PMaterialType.shadowBase:
|
|
4002
|
+
return StandardShaderSource.getSourceCode(primitiveVert, isWebGL2);
|
|
4003
|
+
case PMaterialType.skyboxFilter:
|
|
4004
|
+
return StandardShaderSource.getSourceCode(skyboxVert, isWebGL2);
|
|
4005
|
+
default:
|
|
4006
|
+
throw new Error("Invalid material type " + materialType + " for genVertexShaderCode!");
|
|
4007
|
+
}
|
|
4008
|
+
};
|
|
4009
|
+
/**
|
|
4010
|
+
* 获取片段着色器代码
|
|
4011
|
+
* @param materialType - 材质类型
|
|
4012
|
+
* @returns
|
|
4013
|
+
*/ StandardShader.genFragmentShaderCode = function genFragmentShaderCode(materialType, isWebGL2) {
|
|
4014
|
+
switch(materialType){
|
|
4015
|
+
case PMaterialType.unlit:
|
|
4016
|
+
case PMaterialType.pbr:
|
|
4017
|
+
return StandardShaderSource.getSourceCode(metallicRoughnessFrag, isWebGL2);
|
|
4018
|
+
case PMaterialType.shadowBase:
|
|
4019
|
+
return StandardShaderSource.getSourceCode(shadowPassFrag, isWebGL2);
|
|
4020
|
+
case PMaterialType.skyboxFilter:
|
|
4021
|
+
return StandardShaderSource.getSourceCode(skyboxFrag, isWebGL2);
|
|
4022
|
+
default:
|
|
4023
|
+
throw new Error("Invalid material type " + materialType + " for genFragmentShaderCode!");
|
|
4024
|
+
}
|
|
4025
|
+
};
|
|
3883
4026
|
return StandardShader;
|
|
3884
4027
|
}();
|
|
3885
4028
|
/**
|
|
3886
4029
|
* WebGL 环境
|
|
3887
4030
|
*/ StandardShader.environment = "webgl1";
|
|
3888
4031
|
|
|
4032
|
+
function fetchPBRShaderCode(isWebGL2) {
|
|
4033
|
+
var vertexShaderCode = StandardShader.genVertexShaderCode(PMaterialType.pbr, isWebGL2);
|
|
4034
|
+
var fragmentShaderCode = StandardShader.genFragmentShaderCode(PMaterialType.pbr, isWebGL2);
|
|
4035
|
+
return {
|
|
4036
|
+
vertexShaderCode: vertexShaderCode,
|
|
4037
|
+
fragmentShaderCode: fragmentShaderCode
|
|
4038
|
+
};
|
|
4039
|
+
}
|
|
4040
|
+
function fetchUnlitShaderCode(isWebGL2) {
|
|
4041
|
+
var vertexShaderCode = StandardShader.genVertexShaderCode(PMaterialType.unlit, isWebGL2);
|
|
4042
|
+
var fragmentShaderCode = StandardShader.genFragmentShaderCode(PMaterialType.unlit, isWebGL2);
|
|
4043
|
+
return {
|
|
4044
|
+
vertexShaderCode: vertexShaderCode,
|
|
4045
|
+
fragmentShaderCode: fragmentShaderCode
|
|
4046
|
+
};
|
|
4047
|
+
}
|
|
3889
4048
|
/**
|
|
3890
4049
|
* 获取 PBR 材质着色器代码
|
|
3891
4050
|
* @param context - 着色器上下文
|
|
@@ -4341,7 +4500,7 @@ var ModelMeshComponent = /*#__PURE__*/ function(RendererComponent) {
|
|
|
4341
4500
|
return ModelMeshComponent;
|
|
4342
4501
|
}(RendererComponent);
|
|
4343
4502
|
ModelMeshComponent = __decorate([
|
|
4344
|
-
effectsClass(DataType.MeshComponent)
|
|
4503
|
+
effectsClass(spec.DataType.MeshComponent)
|
|
4345
4504
|
], ModelMeshComponent);
|
|
4346
4505
|
var ModelSkyboxComponent = /*#__PURE__*/ function(RendererComponent) {
|
|
4347
4506
|
_inherits(ModelSkyboxComponent, RendererComponent);
|
|
@@ -4415,7 +4574,7 @@ var ModelSkyboxComponent = /*#__PURE__*/ function(RendererComponent) {
|
|
|
4415
4574
|
return ModelSkyboxComponent;
|
|
4416
4575
|
}(RendererComponent);
|
|
4417
4576
|
ModelSkyboxComponent = __decorate([
|
|
4418
|
-
effectsClass(DataType.SkyboxComponent)
|
|
4577
|
+
effectsClass(spec.DataType.SkyboxComponent)
|
|
4419
4578
|
], ModelSkyboxComponent);
|
|
4420
4579
|
var ModelLightComponent = /*#__PURE__*/ function(ItemBehaviour) {
|
|
4421
4580
|
_inherits(ModelLightComponent, ItemBehaviour);
|
|
@@ -4480,7 +4639,7 @@ var ModelLightComponent = /*#__PURE__*/ function(ItemBehaviour) {
|
|
|
4480
4639
|
return ModelLightComponent;
|
|
4481
4640
|
}(ItemBehaviour);
|
|
4482
4641
|
ModelLightComponent = __decorate([
|
|
4483
|
-
effectsClass(DataType.LightComponent)
|
|
4642
|
+
effectsClass(spec.DataType.LightComponent)
|
|
4484
4643
|
], ModelLightComponent);
|
|
4485
4644
|
var ModelCameraComponent = /*#__PURE__*/ function(ItemBehaviour) {
|
|
4486
4645
|
_inherits(ModelCameraComponent, ItemBehaviour);
|
|
@@ -4568,9 +4727,21 @@ var ModelCameraComponent = /*#__PURE__*/ function(ItemBehaviour) {
|
|
|
4568
4727
|
return ModelCameraComponent;
|
|
4569
4728
|
}(ItemBehaviour);
|
|
4570
4729
|
ModelCameraComponent = __decorate([
|
|
4571
|
-
effectsClass(DataType.CameraComponent)
|
|
4730
|
+
effectsClass(spec.DataType.CameraComponent)
|
|
4572
4731
|
], ModelCameraComponent);
|
|
4573
4732
|
|
|
4733
|
+
// 射线与带旋转的包围盒求交
|
|
4734
|
+
// function transformDirection (m: Matrix4, direction: Vector3) {
|
|
4735
|
+
// const x = direction.x;
|
|
4736
|
+
// const y = direction.y;
|
|
4737
|
+
// const z = direction.z;
|
|
4738
|
+
// const me = m.elements;
|
|
4739
|
+
// const result = new Vector3();
|
|
4740
|
+
// result.x = me[0] * x + me[4] * y + me[8] * z;
|
|
4741
|
+
// result.y = me[1] * x + me[5] * y + me[9] * z;
|
|
4742
|
+
// result.z = me[2] * x + me[6] * y + me[10] * z;
|
|
4743
|
+
// return result.normalize();
|
|
4744
|
+
// }
|
|
4574
4745
|
/**
|
|
4575
4746
|
* 带旋转的射线与包围盒求交
|
|
4576
4747
|
* @param ray - 射线
|
|
@@ -5169,7 +5340,7 @@ var normal = new Vector3();
|
|
|
5169
5340
|
* @returns 纹理获取或 undefined
|
|
5170
5341
|
*/ WebGLHelper.getTexture = function getTexture(index, textures) {
|
|
5171
5342
|
if (index < 0 || index >= textures.length) {
|
|
5172
|
-
return
|
|
5343
|
+
return null;
|
|
5173
5344
|
} else {
|
|
5174
5345
|
return textures[index];
|
|
5175
5346
|
}
|
|
@@ -5496,12 +5667,13 @@ var normal = new Vector3();
|
|
|
5496
5667
|
}
|
|
5497
5668
|
var p = camera.perspective;
|
|
5498
5669
|
var _p_zfar;
|
|
5499
|
-
|
|
5670
|
+
var options = {
|
|
5500
5671
|
near: p.znear,
|
|
5501
5672
|
far: (_p_zfar = p.zfar) != null ? _p_zfar : 1000,
|
|
5502
5673
|
fov: p.yfov,
|
|
5503
5674
|
clipMode: 0
|
|
5504
|
-
}
|
|
5675
|
+
};
|
|
5676
|
+
return options;
|
|
5505
5677
|
};
|
|
5506
5678
|
/**
|
|
5507
5679
|
* 转成播放器中 [0, 255] 区间的颜色值
|
|
@@ -5555,36 +5727,30 @@ var normal = new Vector3();
|
|
|
5555
5727
|
};
|
|
5556
5728
|
/**
|
|
5557
5729
|
* 创建 UV 变换矩阵,从 UV 变换参数中
|
|
5558
|
-
* @param
|
|
5730
|
+
* @param stValue - UV 的缩放和平移参数
|
|
5731
|
+
* @param rotateValue - UV 的旋转参数
|
|
5559
5732
|
* @returns 3阶变换矩阵
|
|
5560
|
-
*/ PluginHelper.createUVTransform = function createUVTransform(
|
|
5561
|
-
|
|
5562
|
-
|
|
5563
|
-
return;
|
|
5564
|
-
}
|
|
5565
|
-
if (transform.offset === undefined && transform.rotation === undefined && transform.scale === undefined) {
|
|
5566
|
-
// no transform, again
|
|
5567
|
-
return;
|
|
5568
|
-
}
|
|
5733
|
+
*/ PluginHelper.createUVTransform = function createUVTransform(material, stName, rotateName) {
|
|
5734
|
+
var stValue = material.getVector4(stName);
|
|
5735
|
+
var rotateValue = material.getFloat(rotateName);
|
|
5569
5736
|
var res = Matrix3.fromIdentity();
|
|
5570
|
-
|
|
5571
|
-
|
|
5572
|
-
temp.setFromArray([
|
|
5737
|
+
if (stValue) {
|
|
5738
|
+
res.setFromArray([
|
|
5573
5739
|
1,
|
|
5574
5740
|
0,
|
|
5575
5741
|
0,
|
|
5576
5742
|
0,
|
|
5577
5743
|
1,
|
|
5578
5744
|
0,
|
|
5579
|
-
|
|
5580
|
-
|
|
5745
|
+
stValue.z,
|
|
5746
|
+
stValue.w,
|
|
5581
5747
|
1
|
|
5582
5748
|
]);
|
|
5583
|
-
res.multiply(temp);
|
|
5584
5749
|
}
|
|
5585
|
-
|
|
5586
|
-
|
|
5587
|
-
var
|
|
5750
|
+
var temp = new Matrix3();
|
|
5751
|
+
if (rotateValue) {
|
|
5752
|
+
var cosTheta = Math.cos(rotateValue);
|
|
5753
|
+
var sinTheta = Math.sin(rotateValue);
|
|
5588
5754
|
temp.setFromArray([
|
|
5589
5755
|
cosTheta,
|
|
5590
5756
|
sinTheta,
|
|
@@ -5598,13 +5764,13 @@ var normal = new Vector3();
|
|
|
5598
5764
|
]);
|
|
5599
5765
|
res.multiply(temp);
|
|
5600
5766
|
}
|
|
5601
|
-
if (
|
|
5767
|
+
if (stValue) {
|
|
5602
5768
|
temp.setFromArray([
|
|
5603
|
-
|
|
5769
|
+
stValue.x,
|
|
5604
5770
|
0,
|
|
5605
5771
|
0,
|
|
5606
5772
|
0,
|
|
5607
|
-
|
|
5773
|
+
stValue.y,
|
|
5608
5774
|
0,
|
|
5609
5775
|
0,
|
|
5610
5776
|
0,
|
|
@@ -5682,7 +5848,7 @@ var normal = new Vector3();
|
|
|
5682
5848
|
var textures = scene.textureOptions;
|
|
5683
5849
|
jsonScene.compositions.forEach(function(comp) {
|
|
5684
5850
|
comp.items.forEach(function(item) {
|
|
5685
|
-
if (item.type ===
|
|
5851
|
+
if (item.type === spec.ItemType.mesh) {
|
|
5686
5852
|
var meshItem = item;
|
|
5687
5853
|
var primitives = meshItem.content.options.primitives;
|
|
5688
5854
|
primitives.forEach(function(prim) {
|
|
@@ -5709,7 +5875,7 @@ var normal = new Vector3();
|
|
|
5709
5875
|
}
|
|
5710
5876
|
}
|
|
5711
5877
|
});
|
|
5712
|
-
} else if (item.type ===
|
|
5878
|
+
} else if (item.type === spec.ItemType.skybox) {
|
|
5713
5879
|
loadSkybox = true;
|
|
5714
5880
|
//
|
|
5715
5881
|
var skyboxItem = item;
|
|
@@ -5724,7 +5890,7 @@ var normal = new Vector3();
|
|
|
5724
5890
|
} else {
|
|
5725
5891
|
jsonScene.compositions.forEach(function(comp) {
|
|
5726
5892
|
comp.items.forEach(function(item) {
|
|
5727
|
-
if (item.type ===
|
|
5893
|
+
if (item.type === spec.ItemType.skybox) {
|
|
5728
5894
|
loadSkybox = true;
|
|
5729
5895
|
}
|
|
5730
5896
|
});
|
|
@@ -5734,7 +5900,7 @@ var normal = new Vector3();
|
|
|
5734
5900
|
jsonScene.compositions.forEach(function(comp) {
|
|
5735
5901
|
var lightCount = 0;
|
|
5736
5902
|
comp.items.forEach(function(item) {
|
|
5737
|
-
if (item.type ===
|
|
5903
|
+
if (item.type === spec.ItemType.light || item.type === spec.ItemType.skybox) {
|
|
5738
5904
|
++lightCount;
|
|
5739
5905
|
}
|
|
5740
5906
|
});
|
|
@@ -5861,7 +6027,7 @@ var normal = new Vector3();
|
|
|
5861
6027
|
sceneComp.items.forEach(function(data) {
|
|
5862
6028
|
var itemId = data.id;
|
|
5863
6029
|
var item = composition.getEngine().jsonSceneData[itemId];
|
|
5864
|
-
if (item.type ===
|
|
6030
|
+
if (item.type === spec.ItemType.mesh) {
|
|
5865
6031
|
var meshItem = item;
|
|
5866
6032
|
var skin = meshItem.content.options.skin;
|
|
5867
6033
|
var primitives = meshItem.content.options.primitives;
|
|
@@ -5896,7 +6062,7 @@ var normal = new Vector3();
|
|
|
5896
6062
|
console.error("setupItem3DOptions: Invalid inverseBindMatrices type, " + inverseBindMatrices);
|
|
5897
6063
|
}
|
|
5898
6064
|
}
|
|
5899
|
-
} else if (item.type ===
|
|
6065
|
+
} else if (item.type === spec.ItemType.tree) {
|
|
5900
6066
|
var jsonItem = item;
|
|
5901
6067
|
var studioItem = item;
|
|
5902
6068
|
var jsonAnimations = jsonItem.content.options.tree.animations;
|
|
@@ -5921,7 +6087,7 @@ var normal = new Vector3();
|
|
|
5921
6087
|
});
|
|
5922
6088
|
});
|
|
5923
6089
|
}
|
|
5924
|
-
} else if (item.type ===
|
|
6090
|
+
} else if (item.type === spec.ItemType.skybox) {
|
|
5925
6091
|
var skybox = item;
|
|
5926
6092
|
var studioSkybox = item;
|
|
5927
6093
|
var options = skybox.content.options;
|
|
@@ -6011,7 +6177,7 @@ var normal = new Vector3();
|
|
|
6011
6177
|
* @returns
|
|
6012
6178
|
*/ PluginHelper.getTextureObj = function getTextureObj(textures, index) {
|
|
6013
6179
|
if (typeof index !== "number") {
|
|
6014
|
-
return
|
|
6180
|
+
return null;
|
|
6015
6181
|
}
|
|
6016
6182
|
if (index < 0 || index >= textures.length) {
|
|
6017
6183
|
console.error("Invalid index for textures: " + index + ", " + textures.length);
|
|
@@ -6138,7 +6304,7 @@ var normal = new Vector3();
|
|
|
6138
6304
|
if (b) {
|
|
6139
6305
|
resolve(b.arrayBuffer());
|
|
6140
6306
|
} else {
|
|
6141
|
-
reject(Error("no canvas blob"));
|
|
6307
|
+
reject(new Error("no canvas blob"));
|
|
6142
6308
|
}
|
|
6143
6309
|
}, "image/png", 1);
|
|
6144
6310
|
})
|
|
@@ -6544,7 +6710,7 @@ var AttributeArray = /*#__PURE__*/ function() {
|
|
|
6544
6710
|
var r0 = this.getPosition(i0, p0, q0);
|
|
6545
6711
|
var r1 = this.getPosition(i1, p1, q1);
|
|
6546
6712
|
var r2 = this.getPosition(i2, p2, q2);
|
|
6547
|
-
if (r0
|
|
6713
|
+
if (!r0 || !r1 || !r2) {
|
|
6548
6714
|
continue;
|
|
6549
6715
|
}
|
|
6550
6716
|
var t = RayTriangleTesting(rayOrigin, rayDirection, r0, r1, r2, backfaceCulling);
|
|
@@ -6566,7 +6732,7 @@ var AttributeArray = /*#__PURE__*/ function() {
|
|
|
6566
6732
|
*/ _proto.getPosition = function getPosition(index, vec3, vec4) {
|
|
6567
6733
|
var posData = this.position.getData(index);
|
|
6568
6734
|
if (posData === undefined) {
|
|
6569
|
-
return;
|
|
6735
|
+
return null;
|
|
6570
6736
|
}
|
|
6571
6737
|
if (this.hasAnimation) {
|
|
6572
6738
|
var _this_joint, _this_weight;
|
|
@@ -7514,6 +7680,18 @@ var toHalf = function() {
|
|
|
7514
7680
|
};
|
|
7515
7681
|
}();
|
|
7516
7682
|
|
|
7683
|
+
var RenderType;
|
|
7684
|
+
(function(RenderType) {
|
|
7685
|
+
RenderType["Opaque"] = "Opaque";
|
|
7686
|
+
RenderType["Mask"] = "Mask";
|
|
7687
|
+
RenderType["Blend"] = "Blend";
|
|
7688
|
+
})(RenderType || (RenderType = {}));
|
|
7689
|
+
var CullMode;
|
|
7690
|
+
(function(CullMode) {
|
|
7691
|
+
CullMode["Front"] = "Front";
|
|
7692
|
+
CullMode["Back"] = "Back";
|
|
7693
|
+
CullMode["Double"] = "Double";
|
|
7694
|
+
})(CullMode || (CullMode = {}));
|
|
7517
7695
|
/**
|
|
7518
7696
|
* 3D 材质基础类,支持公共的材质功能
|
|
7519
7697
|
*/ var PMaterialBase = /*#__PURE__*/ function(PObject) {
|
|
@@ -7521,7 +7699,6 @@ var toHalf = function() {
|
|
|
7521
7699
|
function PMaterialBase() {
|
|
7522
7700
|
var _this;
|
|
7523
7701
|
_this = PObject.apply(this, arguments) || this;
|
|
7524
|
-
_this.fromMaterial = false;
|
|
7525
7702
|
/**
|
|
7526
7703
|
* 材质类型,主要是 pbr 和 unlit 两类
|
|
7527
7704
|
*/ _this.materialType = PMaterialType.none;
|
|
@@ -7533,19 +7710,19 @@ var toHalf = function() {
|
|
|
7533
7710
|
*/ _this.fragmentShaderCode = "";
|
|
7534
7711
|
/**
|
|
7535
7712
|
* 深度是否写入,默认是写入
|
|
7536
|
-
*/ _this.
|
|
7713
|
+
*/ _this.ZWrite = true;
|
|
7537
7714
|
/**
|
|
7538
7715
|
* 是否深度测试提示,默认开启
|
|
7539
|
-
*/ _this.
|
|
7716
|
+
*/ _this.ZTest = true;
|
|
7540
7717
|
/**
|
|
7541
|
-
*
|
|
7542
|
-
*/ _this.
|
|
7718
|
+
* 渲染类型,默认是不透明
|
|
7719
|
+
*/ _this.renderType = "Opaque";
|
|
7543
7720
|
/**
|
|
7544
7721
|
* Alpha 测试截断值
|
|
7545
7722
|
*/ _this.alphaCutOff = 0.5;
|
|
7546
7723
|
/**
|
|
7547
7724
|
* 面侧模式,默认是正面
|
|
7548
|
-
*/ _this.
|
|
7725
|
+
*/ _this.cullMode = "Front";
|
|
7549
7726
|
return _this;
|
|
7550
7727
|
}
|
|
7551
7728
|
var _proto = PMaterialBase.prototype;
|
|
@@ -7559,18 +7736,33 @@ var toHalf = function() {
|
|
|
7559
7736
|
} else if (this.isMasked()) {
|
|
7560
7737
|
featureList.push("ALPHAMODE_MASK 1");
|
|
7561
7738
|
}
|
|
7562
|
-
if (this.
|
|
7739
|
+
if (this.cullMode === "Double") {
|
|
7563
7740
|
featureList.push("DOUBLE_SIDED 1");
|
|
7564
7741
|
}
|
|
7565
7742
|
return featureList;
|
|
7566
7743
|
};
|
|
7744
|
+
_proto.getShaderMacros = function getShaderMacros() {
|
|
7745
|
+
var macroList = [];
|
|
7746
|
+
if (this.isOpaque()) {
|
|
7747
|
+
macroList.push({
|
|
7748
|
+
name: "ALPHAMODE_OPAQUE"
|
|
7749
|
+
});
|
|
7750
|
+
} else if (this.isMasked()) {
|
|
7751
|
+
macroList.push({
|
|
7752
|
+
name: "ALPHAMODE_MASK"
|
|
7753
|
+
});
|
|
7754
|
+
}
|
|
7755
|
+
if (this.cullMode === "Double") {
|
|
7756
|
+
macroList.push({
|
|
7757
|
+
name: "DOUBLE_SIDED"
|
|
7758
|
+
});
|
|
7759
|
+
}
|
|
7760
|
+
return macroList;
|
|
7761
|
+
};
|
|
7567
7762
|
/**
|
|
7568
7763
|
* 根据材质状态,更新 GE 材质状态
|
|
7569
7764
|
* @param material - GE 材质
|
|
7570
7765
|
*/ _proto.updateUniforms = function updateUniforms(material) {
|
|
7571
|
-
if (this.isMasked()) {
|
|
7572
|
-
material.setFloat("_AlphaCutoff", this.alphaCutOff);
|
|
7573
|
-
}
|
|
7574
7766
|
// 渲染 UV 结果输出时,设置 uv 大小
|
|
7575
7767
|
var renderMode = PGlobalState.getInstance().renderMode3D;
|
|
7576
7768
|
if (renderMode === spec.RenderMode3D.uv) {
|
|
@@ -7615,61 +7807,48 @@ var toHalf = function() {
|
|
|
7615
7807
|
}
|
|
7616
7808
|
return finalFeatureList;
|
|
7617
7809
|
};
|
|
7618
|
-
|
|
7619
|
-
|
|
7620
|
-
|
|
7621
|
-
|
|
7622
|
-
|
|
7623
|
-
if (mode === spec.MaterialBlending.masked) {
|
|
7624
|
-
return PBlendMode.masked;
|
|
7625
|
-
} else if (mode === spec.MaterialBlending.translucent) {
|
|
7626
|
-
return PBlendMode.translucent;
|
|
7627
|
-
} else if (mode === spec.MaterialBlending.additive) {
|
|
7628
|
-
return PBlendMode.additive;
|
|
7629
|
-
} else {
|
|
7630
|
-
return PBlendMode.opaque;
|
|
7810
|
+
_proto.getMacroList = function getMacroList(inMacroList) {
|
|
7811
|
+
var finalMacroList = this.getShaderMacros();
|
|
7812
|
+
if (inMacroList !== undefined) {
|
|
7813
|
+
var _finalMacroList;
|
|
7814
|
+
(_finalMacroList = finalMacroList).push.apply(_finalMacroList, [].concat(inMacroList));
|
|
7631
7815
|
}
|
|
7632
|
-
|
|
7633
|
-
|
|
7634
|
-
|
|
7635
|
-
|
|
7636
|
-
|
|
7637
|
-
|
|
7638
|
-
|
|
7639
|
-
|
|
7640
|
-
|
|
7641
|
-
|
|
7642
|
-
|
|
7643
|
-
|
|
7816
|
+
var isWebGL2 = PGlobalState.getInstance().isWebGL2;
|
|
7817
|
+
if (isWebGL2) {
|
|
7818
|
+
finalMacroList.push({
|
|
7819
|
+
name: "WEBGL2"
|
|
7820
|
+
});
|
|
7821
|
+
}
|
|
7822
|
+
// 目前只有 PRB 和 Unlit 是需要 EDITOR_TRANSFORM,适配编辑器的视口 Offset
|
|
7823
|
+
// 阴影 Pass 的渲染是不需要,所以这里特殊处理下
|
|
7824
|
+
if (this.materialType !== PMaterialType.shadowBase) {
|
|
7825
|
+
var isEditorEvn = PGlobalState.getInstance().isEditorEnv;
|
|
7826
|
+
if (isEditorEvn) {
|
|
7827
|
+
finalMacroList.push({
|
|
7828
|
+
name: "EDITOR_TRANSFORM"
|
|
7829
|
+
});
|
|
7830
|
+
}
|
|
7644
7831
|
}
|
|
7832
|
+
return finalMacroList;
|
|
7645
7833
|
};
|
|
7646
7834
|
/**
|
|
7647
7835
|
* 设置材质状态,根据 GE 材质状态
|
|
7648
7836
|
* @param material - GE 材质
|
|
7649
7837
|
*/ _proto.setMaterialStates = function setMaterialStates(material) {
|
|
7650
|
-
if (this.
|
|
7838
|
+
if (this.renderType === "Blend") {
|
|
7651
7839
|
material.blending = true;
|
|
7652
7840
|
material.depthTest = true;
|
|
7653
7841
|
material.blendEquation = [
|
|
7654
7842
|
glContext.FUNC_ADD,
|
|
7655
7843
|
glContext.FUNC_ADD
|
|
7656
7844
|
];
|
|
7657
|
-
|
|
7658
|
-
|
|
7659
|
-
|
|
7660
|
-
|
|
7661
|
-
|
|
7662
|
-
|
|
7663
|
-
|
|
7664
|
-
} else {
|
|
7665
|
-
material.blendFunction = [
|
|
7666
|
-
glContext.ONE,
|
|
7667
|
-
glContext.ONE,
|
|
7668
|
-
glContext.ONE,
|
|
7669
|
-
glContext.ONE
|
|
7670
|
-
];
|
|
7671
|
-
}
|
|
7672
|
-
material.depthMask = this.depthMask;
|
|
7845
|
+
material.blendFunction = [
|
|
7846
|
+
glContext.ONE,
|
|
7847
|
+
glContext.ONE_MINUS_SRC_ALPHA,
|
|
7848
|
+
glContext.ONE,
|
|
7849
|
+
glContext.ONE_MINUS_SRC_ALPHA
|
|
7850
|
+
];
|
|
7851
|
+
material.depthMask = this.ZWrite;
|
|
7673
7852
|
} else {
|
|
7674
7853
|
if (PGlobalState.getInstance().isTiny3dMode) {
|
|
7675
7854
|
material.blending = false;
|
|
@@ -7678,16 +7857,16 @@ var toHalf = function() {
|
|
|
7678
7857
|
material.depthMask = true;
|
|
7679
7858
|
} else {
|
|
7680
7859
|
material.blending = false;
|
|
7681
|
-
material.depthTest = this.
|
|
7682
|
-
material.depthMask = this.
|
|
7860
|
+
material.depthTest = this.ZTest;
|
|
7861
|
+
material.depthMask = this.ZWrite;
|
|
7683
7862
|
}
|
|
7684
7863
|
}
|
|
7685
7864
|
this.setFaceSideStates(material);
|
|
7686
7865
|
};
|
|
7687
7866
|
_proto.setFaceSideStates = function setFaceSideStates(material) {
|
|
7688
|
-
if (this.
|
|
7867
|
+
if (this.isDoubleSide()) {
|
|
7689
7868
|
material.culling = false;
|
|
7690
|
-
} else if (this.
|
|
7869
|
+
} else if (this.isBackSide()) {
|
|
7691
7870
|
material.cullFace = glContext.FRONT;
|
|
7692
7871
|
material.frontFace = glContext.CCW;
|
|
7693
7872
|
material.culling = true;
|
|
@@ -7713,49 +7892,37 @@ var toHalf = function() {
|
|
|
7713
7892
|
* 是否不透明
|
|
7714
7893
|
* @returns
|
|
7715
7894
|
*/ _proto.isOpaque = function isOpaque() {
|
|
7716
|
-
return this.
|
|
7895
|
+
return this.renderType === "Opaque";
|
|
7717
7896
|
};
|
|
7718
7897
|
/**
|
|
7719
7898
|
* 是否遮罩
|
|
7720
7899
|
* @returns
|
|
7721
7900
|
*/ _proto.isMasked = function isMasked() {
|
|
7722
|
-
return this.
|
|
7901
|
+
return this.renderType === "Mask";
|
|
7723
7902
|
};
|
|
7724
7903
|
/**
|
|
7725
7904
|
* 是否半透明
|
|
7726
7905
|
* @returns
|
|
7727
|
-
*/ _proto.
|
|
7728
|
-
return this.
|
|
7729
|
-
};
|
|
7730
|
-
/**
|
|
7731
|
-
* 是否加法混合
|
|
7732
|
-
* @returns
|
|
7733
|
-
*/ _proto.isAdditive = function isAdditive() {
|
|
7734
|
-
return this.blendMode === PBlendMode.additive;
|
|
7735
|
-
};
|
|
7736
|
-
/**
|
|
7737
|
-
* 是否需要混合
|
|
7738
|
-
* @returns
|
|
7739
|
-
*/ _proto.requireBlend = function requireBlend() {
|
|
7740
|
-
return this.blendMode === PBlendMode.translucent || this.blendMode === PBlendMode.additive;
|
|
7906
|
+
*/ _proto.isBlend = function isBlend() {
|
|
7907
|
+
return this.renderType === "Blend";
|
|
7741
7908
|
};
|
|
7742
7909
|
/**
|
|
7743
7910
|
* 是否正面模式
|
|
7744
7911
|
* @returns
|
|
7745
|
-
*/ _proto.
|
|
7746
|
-
return this.
|
|
7912
|
+
*/ _proto.isFrontSide = function isFrontSide() {
|
|
7913
|
+
return this.cullMode === "Front";
|
|
7747
7914
|
};
|
|
7748
7915
|
/**
|
|
7749
7916
|
* 是否背面模式
|
|
7750
7917
|
* @returns
|
|
7751
|
-
*/ _proto.
|
|
7752
|
-
return this.
|
|
7918
|
+
*/ _proto.isBackSide = function isBackSide() {
|
|
7919
|
+
return this.cullMode === "Back";
|
|
7753
7920
|
};
|
|
7754
7921
|
/**
|
|
7755
7922
|
* 是否双面模式
|
|
7756
7923
|
* @returns
|
|
7757
|
-
*/ _proto.
|
|
7758
|
-
return this.
|
|
7924
|
+
*/ _proto.isDoubleSide = function isDoubleSide() {
|
|
7925
|
+
return this.cullMode === "Double";
|
|
7759
7926
|
};
|
|
7760
7927
|
return PMaterialBase;
|
|
7761
7928
|
}(PObject);
|
|
@@ -7766,33 +7933,35 @@ var toHalf = function() {
|
|
|
7766
7933
|
function PMaterialUnlit() {
|
|
7767
7934
|
var _this;
|
|
7768
7935
|
_this = PMaterialBase.apply(this, arguments) || this;
|
|
7769
|
-
|
|
7936
|
+
/**
|
|
7937
|
+
* 基础颜色值,默认是白色 Color(1, 1, 1, 1)
|
|
7938
|
+
*/ _this.baseColorFactor = new Color(1, 1, 1, 1);
|
|
7770
7939
|
return _this;
|
|
7771
7940
|
}
|
|
7772
7941
|
var _proto = PMaterialUnlit.prototype;
|
|
7773
7942
|
/**
|
|
7774
7943
|
* 创建无光照材质,支持基础颜色纹理
|
|
7775
|
-
* @param
|
|
7776
|
-
*/ _proto.create = function create(
|
|
7777
|
-
this.
|
|
7944
|
+
* @param material - effect 材质对象
|
|
7945
|
+
*/ _proto.create = function create(material) {
|
|
7946
|
+
this.effectMaterial = material;
|
|
7947
|
+
this.name = material.name;
|
|
7778
7948
|
this.type = PObjectType.material;
|
|
7779
7949
|
this.materialType = PMaterialType.unlit;
|
|
7950
|
+
var _material_getTexture;
|
|
7780
7951
|
//
|
|
7781
|
-
|
|
7782
|
-
|
|
7783
|
-
|
|
7784
|
-
this.
|
|
7785
|
-
|
|
7786
|
-
|
|
7787
|
-
|
|
7788
|
-
|
|
7789
|
-
|
|
7790
|
-
|
|
7791
|
-
|
|
7792
|
-
|
|
7793
|
-
|
|
7794
|
-
this.alphaCutOff = (_options_alphaCutOff = options.alphaCutOff) != null ? _options_alphaCutOff : 0;
|
|
7795
|
-
this.faceSideMode = this.getFaceSideMode(options.side);
|
|
7952
|
+
this.baseColorTexture = (_material_getTexture = material.getTexture("_BaseColorSampler")) != null ? _material_getTexture : undefined;
|
|
7953
|
+
this.baseColorTextureTrans = PluginHelper.createUVTransform(material, "_BaseColorSampler_ST", "_BaseColorRotation");
|
|
7954
|
+
var _material_getColor;
|
|
7955
|
+
this.baseColorFactor = (_material_getColor = material.getColor("_BaseColorFactor")) != null ? _material_getColor : new Color(1.0, 1.0, 1.0, 1.0);
|
|
7956
|
+
//
|
|
7957
|
+
this.ZWrite = material.stringTags["ZWrite"] !== "false";
|
|
7958
|
+
this.ZTest = material.stringTags["ZTest"] !== "false";
|
|
7959
|
+
var _material_stringTags_RenderType;
|
|
7960
|
+
this.renderType = (_material_stringTags_RenderType = material.stringTags["RenderType"]) != null ? _material_stringTags_RenderType : "Opaque";
|
|
7961
|
+
var _material_getFloat;
|
|
7962
|
+
this.alphaCutOff = (_material_getFloat = material.getFloat("_AlphaCutoff")) != null ? _material_getFloat : 0;
|
|
7963
|
+
var _material_stringTags_Cull;
|
|
7964
|
+
this.cullMode = (_material_stringTags_Cull = material.stringTags["Cull"]) != null ? _material_stringTags_Cull : "Front";
|
|
7796
7965
|
};
|
|
7797
7966
|
/**
|
|
7798
7967
|
* 销毁材质
|
|
@@ -7812,21 +7981,32 @@ var toHalf = function() {
|
|
|
7812
7981
|
featureList.push("MATERIAL_UNLIT 1");
|
|
7813
7982
|
return featureList;
|
|
7814
7983
|
};
|
|
7984
|
+
_proto.getShaderMacros = function getShaderMacros() {
|
|
7985
|
+
var macroList = PMaterialBase.prototype.getShaderMacros.call(this);
|
|
7986
|
+
macroList.push({
|
|
7987
|
+
name: "MATERIAL_METALLICROUGHNESS"
|
|
7988
|
+
});
|
|
7989
|
+
if (this.hasBaseColorTexture()) {
|
|
7990
|
+
macroList.push({
|
|
7991
|
+
name: "HAS_BASE_COLOR_MAP"
|
|
7992
|
+
});
|
|
7993
|
+
}
|
|
7994
|
+
macroList.push({
|
|
7995
|
+
name: "MATERIAL_UNLIT"
|
|
7996
|
+
});
|
|
7997
|
+
return macroList;
|
|
7998
|
+
};
|
|
7815
7999
|
/**
|
|
7816
8000
|
* 更新对应的 GE 材质中着色器的 Uniform 数据
|
|
7817
8001
|
* @param material - GE 材质
|
|
7818
8002
|
*/ _proto.updateUniforms = function updateUniforms(material) {
|
|
7819
8003
|
PMaterialBase.prototype.updateUniforms.call(this, material);
|
|
7820
|
-
|
|
7821
|
-
var uvTransform = new Matrix3().identity();
|
|
7822
|
-
material.setVector4("_BaseColorFactor", this.baseColorFactor);
|
|
7823
|
-
if (this.hasBaseColorTexture()) {
|
|
7824
|
-
material.setTexture("_BaseColorSampler", this.getBaseColorTexture());
|
|
8004
|
+
if (this.baseColorTexture !== undefined) {
|
|
7825
8005
|
material.setInt("_BaseColorUVSet", 0);
|
|
7826
|
-
material.setMatrix3("_BaseColorUVTransform",
|
|
8006
|
+
material.setMatrix3("_BaseColorUVTransform", this.baseColorTextureTrans);
|
|
7827
8007
|
}
|
|
7828
|
-
material.setFloat("_MetallicFactor", 0
|
|
7829
|
-
material.setFloat("_RoughnessFactor", 0
|
|
8008
|
+
material.setFloat("_MetallicFactor", 0);
|
|
8009
|
+
material.setFloat("_RoughnessFactor", 0);
|
|
7830
8010
|
material.setFloat("_Exposure", 1.0);
|
|
7831
8011
|
};
|
|
7832
8012
|
/**
|
|
@@ -7848,7 +8028,7 @@ var toHalf = function() {
|
|
|
7848
8028
|
this.baseColorTexture = val;
|
|
7849
8029
|
};
|
|
7850
8030
|
/**
|
|
7851
|
-
*
|
|
8031
|
+
* 获取基础颜色纹理
|
|
7852
8032
|
* @returns
|
|
7853
8033
|
*/ _proto.getBaseColorFactor = function getBaseColorFactor() {
|
|
7854
8034
|
return this.baseColorFactor;
|
|
@@ -7857,9 +8037,14 @@ var toHalf = function() {
|
|
|
7857
8037
|
* 设置基础颜色值
|
|
7858
8038
|
* @param val - 颜色值
|
|
7859
8039
|
*/ _proto.setBaseColorFactor = function setBaseColorFactor(val) {
|
|
7860
|
-
if (_instanceof1(val,
|
|
8040
|
+
if (_instanceof1(val, Color)) {
|
|
8041
|
+
// for Color
|
|
8042
|
+
this.baseColorFactor.set(val.r, val.g, val.b, val.a);
|
|
8043
|
+
} else if (_instanceof1(val, Vector4)) {
|
|
8044
|
+
// for Vector4
|
|
7861
8045
|
this.baseColorFactor.set(val.x, val.y, val.z, val.w);
|
|
7862
8046
|
} else {
|
|
8047
|
+
// for vec4
|
|
7863
8048
|
this.baseColorFactor.set(val[0], val[1], val[2], val[3]);
|
|
7864
8049
|
}
|
|
7865
8050
|
};
|
|
@@ -7874,8 +8059,8 @@ var toHalf = function() {
|
|
|
7874
8059
|
var _this;
|
|
7875
8060
|
_this = PMaterialBase.apply(this, arguments) || this;
|
|
7876
8061
|
/**
|
|
7877
|
-
* 基础颜色值,默认是白色
|
|
7878
|
-
*/ _this.baseColorFactor = new
|
|
8062
|
+
* 基础颜色值,默认是白色 Color(1, 1, 1, 1)
|
|
8063
|
+
*/ _this.baseColorFactor = new Color(1, 1, 1, 1);
|
|
7879
8064
|
/**
|
|
7880
8065
|
* 是否高光抗锯齿,能够明显提升高光表现效果
|
|
7881
8066
|
*/ _this.useSpecularAA = false;
|
|
@@ -7893,123 +8078,65 @@ var toHalf = function() {
|
|
|
7893
8078
|
*/ _this.occlusionTextureStrength = 1;
|
|
7894
8079
|
/**
|
|
7895
8080
|
* 自发光颜色值,默认是黑色 Vector4(0, 0, 0, 0)
|
|
7896
|
-
*/ _this.emissiveFactor = new
|
|
8081
|
+
*/ _this.emissiveFactor = new Color(0, 0, 0, 0);
|
|
7897
8082
|
/**
|
|
7898
8083
|
* 自发光强度
|
|
7899
8084
|
*/ _this.emissiveIntensity = 1;
|
|
7900
|
-
//
|
|
7901
|
-
_this.enableShadow = false;
|
|
7902
8085
|
return _this;
|
|
7903
8086
|
}
|
|
7904
8087
|
var _proto = PMaterialPBR.prototype;
|
|
7905
8088
|
/**
|
|
7906
8089
|
* 创建材质
|
|
7907
|
-
* @param
|
|
7908
|
-
*/ _proto.create = function create(
|
|
7909
|
-
this.
|
|
8090
|
+
* @param material - effect 材质对象
|
|
8091
|
+
*/ _proto.create = function create(material) {
|
|
8092
|
+
this.effectMaterial = material;
|
|
8093
|
+
this.name = material.name;
|
|
7910
8094
|
this.type = PObjectType.material;
|
|
7911
8095
|
this.materialType = PMaterialType.pbr;
|
|
8096
|
+
var _material_getTexture;
|
|
7912
8097
|
//
|
|
7913
|
-
|
|
7914
|
-
|
|
7915
|
-
|
|
7916
|
-
|
|
7917
|
-
|
|
7918
|
-
|
|
7919
|
-
this.
|
|
7920
|
-
|
|
7921
|
-
|
|
7922
|
-
|
|
7923
|
-
|
|
7924
|
-
|
|
7925
|
-
|
|
7926
|
-
var
|
|
7927
|
-
|
|
7928
|
-
this.
|
|
7929
|
-
this.
|
|
7930
|
-
|
|
7931
|
-
|
|
7932
|
-
|
|
7933
|
-
if (options.normalTextureTransform) {
|
|
7934
|
-
this.normalTextureTrans = PluginHelper.createUVTransform(options.normalTextureTransform);
|
|
7935
|
-
}
|
|
7936
|
-
var _options_normalTextureScale;
|
|
7937
|
-
this.normalTextureScale = (_options_normalTextureScale = options.normalTextureScale) != null ? _options_normalTextureScale : 1.0;
|
|
7938
|
-
if (options.occlusionTexture) {
|
|
7939
|
-
this.occlusionTexture = options.occlusionTexture;
|
|
7940
|
-
}
|
|
7941
|
-
if (options.occlusionTextureTransform) {
|
|
7942
|
-
this.occlusionTextureTrans = PluginHelper.createUVTransform(options.occlusionTextureTransform);
|
|
7943
|
-
}
|
|
7944
|
-
var _options_occlusionTextureStrength;
|
|
7945
|
-
this.occlusionTextureStrength = (_options_occlusionTextureStrength = options.occlusionTextureStrength) != null ? _options_occlusionTextureStrength : 1.0;
|
|
7946
|
-
if (options.emissiveTexture) {
|
|
7947
|
-
this.emissiveTexture = options.emissiveTexture;
|
|
7948
|
-
}
|
|
7949
|
-
if (options.emissiveTextureTransform) {
|
|
7950
|
-
this.emissiveTextureTrans = PluginHelper.createUVTransform(options.emissiveTextureTransform);
|
|
7951
|
-
}
|
|
7952
|
-
var emissiveFactor = PluginHelper.toPluginColor4(options.emissiveFactor);
|
|
7953
|
-
this.setEmissiveFactor(Vector3.fromArray(emissiveFactor));
|
|
7954
|
-
this.emissiveIntensity = options.emissiveIntensity;
|
|
7955
|
-
var _options_enableShadow;
|
|
7956
|
-
this.enableShadow = (_options_enableShadow = options.enableShadow) != null ? _options_enableShadow : false;
|
|
7957
|
-
/**
|
|
7958
|
-
* 默认需要写入深度值,只有传入false才是false
|
|
7959
|
-
*/ if (options.depthMask === false) {
|
|
7960
|
-
this.depthMask = false;
|
|
7961
|
-
} else {
|
|
7962
|
-
this.depthMask = true;
|
|
7963
|
-
}
|
|
7964
|
-
this.blendMode = this.getBlendMode(options.blending);
|
|
7965
|
-
var _options_alphaCutOff;
|
|
7966
|
-
this.alphaCutOff = (_options_alphaCutOff = options.alphaCutOff) != null ? _options_alphaCutOff : 0;
|
|
7967
|
-
this.faceSideMode = this.getFaceSideMode(options.side);
|
|
7968
|
-
};
|
|
7969
|
-
_proto.createFromMaterial = function createFromMaterial(mat) {
|
|
7970
|
-
this.fromMaterial = true;
|
|
7971
|
-
this.material = mat;
|
|
7972
|
-
this.name = mat.name;
|
|
7973
|
-
this.type = PObjectType.material;
|
|
7974
|
-
this.materialType = mat.getInt("shaderType") ? PMaterialType.unlit : PMaterialType.pbr;
|
|
7975
|
-
var _mat_getTexture;
|
|
8098
|
+
this.baseColorTexture = (_material_getTexture = material.getTexture("_BaseColorSampler")) != null ? _material_getTexture : undefined;
|
|
8099
|
+
this.baseColorTextureTrans = PluginHelper.createUVTransform(material, "_BaseColorSampler_ST", "_BaseColorRotation");
|
|
8100
|
+
var _material_getColor;
|
|
8101
|
+
this.baseColorFactor = (_material_getColor = material.getColor("_BaseColorFactor")) != null ? _material_getColor : new Color(1.0, 1.0, 1.0, 1.0);
|
|
8102
|
+
var _material_getTexture1;
|
|
8103
|
+
//
|
|
8104
|
+
this.metallicRoughnessTexture = (_material_getTexture1 = material.getTexture("_MetallicRoughnessSampler")) != null ? _material_getTexture1 : undefined;
|
|
8105
|
+
this.metallicRoughnessTextureTrans = PluginHelper.createUVTransform(material, "_MetallicRoughnessSampler_ST", "_MetallicRoughnessRotation");
|
|
8106
|
+
this.useSpecularAA = material.getFloat("_SpecularAA") === 1;
|
|
8107
|
+
var _material_getFloat;
|
|
8108
|
+
this.metallicFactor = (_material_getFloat = material.getFloat("_MetallicFactor")) != null ? _material_getFloat : 1;
|
|
8109
|
+
var _material_getFloat1;
|
|
8110
|
+
this.roughnessFactor = (_material_getFloat1 = material.getFloat("_RoughnessFactor")) != null ? _material_getFloat1 : 0;
|
|
8111
|
+
var _material_getTexture2;
|
|
8112
|
+
//
|
|
8113
|
+
this.normalTexture = (_material_getTexture2 = material.getTexture("_NormalSampler")) != null ? _material_getTexture2 : undefined;
|
|
8114
|
+
this.normalTextureTrans = PluginHelper.createUVTransform(material, "_NormalSampler_ST", "_NormalRotation");
|
|
8115
|
+
var _material_getFloat2;
|
|
8116
|
+
this.normalTextureScale = (_material_getFloat2 = material.getFloat("_NormalScale")) != null ? _material_getFloat2 : 1;
|
|
8117
|
+
var _material_getTexture3;
|
|
7976
8118
|
//
|
|
7977
|
-
this.
|
|
7978
|
-
|
|
7979
|
-
|
|
7980
|
-
|
|
7981
|
-
|
|
7982
|
-
|
|
7983
|
-
|
|
7984
|
-
this.
|
|
7985
|
-
var
|
|
7986
|
-
this.
|
|
7987
|
-
var
|
|
7988
|
-
this.
|
|
7989
|
-
|
|
7990
|
-
this.
|
|
7991
|
-
|
|
7992
|
-
|
|
7993
|
-
|
|
7994
|
-
|
|
7995
|
-
|
|
7996
|
-
|
|
7997
|
-
|
|
7998
|
-
this.emissiveFactor = (_mat_getVector41 = mat.getVector4("_EmissiveFactor")) != null ? _mat_getVector41 : new Vector4(0, 0, 0, 0);
|
|
7999
|
-
var _mat_getFloat4;
|
|
8000
|
-
this.emissiveIntensity = (_mat_getFloat4 = mat.getFloat("_EmissiveIntensity")) != null ? _mat_getFloat4 : 1;
|
|
8001
|
-
var emissiveFactor = this.emissiveFactor.clone().multiply(this.emissiveIntensity);
|
|
8002
|
-
mat.setVector4("_EmissiveFactor", emissiveFactor);
|
|
8003
|
-
this.enableShadow = false;
|
|
8004
|
-
this.depthMask = true;
|
|
8005
|
-
var _mat_getInt;
|
|
8006
|
-
var blending = (_mat_getInt = mat.getInt("blending")) != null ? _mat_getInt : spec.MaterialBlending.opaque;
|
|
8007
|
-
this.blendMode = this.getBlendMode(blending);
|
|
8008
|
-
var _mat_getFloat5;
|
|
8009
|
-
this.alphaCutOff = (_mat_getFloat5 = mat.getFloat("_AlphaCutoff")) != null ? _mat_getFloat5 : 0;
|
|
8010
|
-
var _mat_getInt1;
|
|
8011
|
-
var side = (_mat_getInt1 = mat.getInt("side")) != null ? _mat_getInt1 : spec.SideMode.FRONT;
|
|
8012
|
-
this.faceSideMode = this.getFaceSideMode(side);
|
|
8119
|
+
this.occlusionTexture = (_material_getTexture3 = material.getTexture("_OcclusionSampler")) != null ? _material_getTexture3 : undefined;
|
|
8120
|
+
this.occlusionTextureTrans = PluginHelper.createUVTransform(material, "_OcclusionSampler_ST", "_OcclusionRotation");
|
|
8121
|
+
var _material_getFloat3;
|
|
8122
|
+
this.occlusionTextureStrength = (_material_getFloat3 = material.getFloat("_OcclusionStrength")) != null ? _material_getFloat3 : 1;
|
|
8123
|
+
var _material_getTexture4;
|
|
8124
|
+
//
|
|
8125
|
+
this.emissiveTexture = (_material_getTexture4 = material.getTexture("_EmissiveSampler")) != null ? _material_getTexture4 : undefined;
|
|
8126
|
+
this.emissiveTextureTrans = PluginHelper.createUVTransform(material, "_EmissiveSampler_ST", "_EmissiveRotation");
|
|
8127
|
+
var _material_getColor1;
|
|
8128
|
+
this.emissiveFactor = (_material_getColor1 = material.getColor("_EmissiveFactor")) != null ? _material_getColor1 : new Color(0, 0, 0, 1);
|
|
8129
|
+
var _material_getFloat4;
|
|
8130
|
+
this.emissiveIntensity = (_material_getFloat4 = material.getFloat("_EmissiveIntensity")) != null ? _material_getFloat4 : 1;
|
|
8131
|
+
//
|
|
8132
|
+
this.ZWrite = material.stringTags["ZWrite"] !== "false";
|
|
8133
|
+
this.ZTest = material.stringTags["ZTest"] !== "false";
|
|
8134
|
+
var _material_stringTags_RenderType;
|
|
8135
|
+
this.renderType = (_material_stringTags_RenderType = material.stringTags["RenderType"]) != null ? _material_stringTags_RenderType : "Opaque";
|
|
8136
|
+
var _material_getFloat5;
|
|
8137
|
+
this.alphaCutOff = (_material_getFloat5 = material.getFloat("_AlphaCutoff")) != null ? _material_getFloat5 : 0;
|
|
8138
|
+
var _material_stringTags_Cull;
|
|
8139
|
+
this.cullMode = (_material_stringTags_Cull = material.stringTags["Cull"]) != null ? _material_stringTags_Cull : "Front";
|
|
8013
8140
|
};
|
|
8014
8141
|
/**
|
|
8015
8142
|
* 销毁材质
|
|
@@ -8059,110 +8186,105 @@ var toHalf = function() {
|
|
|
8059
8186
|
if (this.emissiveTextureTrans !== undefined) {
|
|
8060
8187
|
featureList.push("HAS_EMISSIVE_UV_TRANSFORM 1");
|
|
8061
8188
|
}
|
|
8062
|
-
} else if (this.
|
|
8189
|
+
} else if (this.hasEmissiveValue()) {
|
|
8063
8190
|
featureList.push("HAS_EMISSIVE 1");
|
|
8064
8191
|
}
|
|
8065
8192
|
return featureList;
|
|
8066
8193
|
};
|
|
8067
|
-
|
|
8068
|
-
|
|
8069
|
-
|
|
8070
|
-
|
|
8071
|
-
|
|
8072
|
-
if (this.
|
|
8073
|
-
|
|
8074
|
-
|
|
8075
|
-
|
|
8076
|
-
|
|
8194
|
+
_proto.getShaderMacros = function getShaderMacros() {
|
|
8195
|
+
var macroList = PMaterialBase.prototype.getShaderMacros.call(this);
|
|
8196
|
+
macroList.push({
|
|
8197
|
+
name: "MATERIAL_METALLICROUGHNESS"
|
|
8198
|
+
});
|
|
8199
|
+
if (this.hasBaseColorTexture()) {
|
|
8200
|
+
macroList.push({
|
|
8201
|
+
name: "HAS_BASE_COLOR_MAP"
|
|
8202
|
+
});
|
|
8203
|
+
if (this.baseColorTextureTrans !== undefined) {
|
|
8204
|
+
macroList.push({
|
|
8205
|
+
name: "HAS_BASECOLOR_UV_TRANSFORM"
|
|
8206
|
+
});
|
|
8077
8207
|
}
|
|
8078
|
-
|
|
8079
|
-
|
|
8080
|
-
|
|
8081
|
-
|
|
8208
|
+
}
|
|
8209
|
+
if (this.hasMetallicRoughnessTexture()) {
|
|
8210
|
+
macroList.push({
|
|
8211
|
+
name: "HAS_METALLIC_ROUGHNESS_MAP"
|
|
8212
|
+
});
|
|
8213
|
+
if (this.metallicRoughnessTextureTrans !== undefined) {
|
|
8214
|
+
macroList.push({
|
|
8215
|
+
name: "HAS_METALLICROUGHNESS_UV_TRANSFORM"
|
|
8216
|
+
});
|
|
8082
8217
|
}
|
|
8083
|
-
|
|
8084
|
-
|
|
8085
|
-
|
|
8086
|
-
|
|
8218
|
+
}
|
|
8219
|
+
if (this.useSpecularAA) {
|
|
8220
|
+
macroList.push({
|
|
8221
|
+
name: "USE_SPECULAR_AA"
|
|
8222
|
+
});
|
|
8223
|
+
}
|
|
8224
|
+
if (this.hasNormalTexture()) {
|
|
8225
|
+
macroList.push({
|
|
8226
|
+
name: "HAS_NORMAL_MAP"
|
|
8227
|
+
});
|
|
8228
|
+
if (this.normalTextureTrans !== undefined) {
|
|
8229
|
+
macroList.push({
|
|
8230
|
+
name: "HAS_NORMAL_UV_TRANSFORM"
|
|
8231
|
+
});
|
|
8087
8232
|
}
|
|
8088
|
-
|
|
8089
|
-
|
|
8090
|
-
|
|
8091
|
-
|
|
8233
|
+
}
|
|
8234
|
+
if (this.hasOcclusionTexture()) {
|
|
8235
|
+
macroList.push({
|
|
8236
|
+
name: "HAS_OCCLUSION_MAP"
|
|
8237
|
+
});
|
|
8238
|
+
if (this.occlusionTextureTrans !== undefined) {
|
|
8239
|
+
macroList.push({
|
|
8240
|
+
name: "HAS_OCCLUSION_UV_TRANSFORM"
|
|
8241
|
+
});
|
|
8092
8242
|
}
|
|
8093
|
-
|
|
8094
|
-
|
|
8095
|
-
|
|
8096
|
-
|
|
8243
|
+
}
|
|
8244
|
+
if (this.hasEmissiveTexture()) {
|
|
8245
|
+
macroList.push({
|
|
8246
|
+
name: "HAS_EMISSIVE_MAP"
|
|
8247
|
+
});
|
|
8248
|
+
if (this.emissiveTextureTrans !== undefined) {
|
|
8249
|
+
macroList.push({
|
|
8250
|
+
name: "HAS_EMISSIVE_UV_TRANSFORM"
|
|
8251
|
+
});
|
|
8097
8252
|
}
|
|
8098
|
-
|
|
8099
|
-
|
|
8253
|
+
} else if (this.hasEmissiveValue()) {
|
|
8254
|
+
macroList.push({
|
|
8255
|
+
name: "HAS_EMISSIVE"
|
|
8256
|
+
});
|
|
8100
8257
|
}
|
|
8101
|
-
|
|
8102
|
-
|
|
8103
|
-
|
|
8258
|
+
return macroList;
|
|
8259
|
+
};
|
|
8260
|
+
/**
|
|
8261
|
+
* 更新关联的 GE 材质中着色器的 Uniform 数据
|
|
8262
|
+
* @param material - GE 材质
|
|
8263
|
+
*/ _proto.updateUniforms = function updateUniforms(material) {
|
|
8264
|
+
PMaterialBase.prototype.updateUniforms.call(this, material);
|
|
8104
8265
|
if (this.baseColorTexture !== undefined) {
|
|
8105
|
-
material.setTexture("_BaseColorSampler", this.baseColorTexture);
|
|
8106
8266
|
material.setInt("_BaseColorUVSet", 0);
|
|
8107
|
-
|
|
8108
|
-
material.setMatrix3("_BaseColorUVTransform", this.baseColorTextureTrans);
|
|
8109
|
-
} else {
|
|
8110
|
-
// fill other data
|
|
8111
|
-
material.setMatrix3("_BaseColorUVTransform", uvTransform1);
|
|
8112
|
-
}
|
|
8267
|
+
material.setMatrix3("_BaseColorUVTransform", this.baseColorTextureTrans);
|
|
8113
8268
|
}
|
|
8114
8269
|
//
|
|
8115
|
-
material.setFloat("_MetallicFactor", this.metallicFactor);
|
|
8116
|
-
material.setFloat("_RoughnessFactor", this.roughnessFactor);
|
|
8117
8270
|
if (this.metallicRoughnessTexture !== undefined) {
|
|
8118
|
-
material.setTexture("_MetallicRoughnessSampler", this.metallicRoughnessTexture);
|
|
8119
8271
|
material.setInt("_MetallicRoughnessUVSet", 0);
|
|
8120
|
-
|
|
8121
|
-
material.setMatrix3("_MetallicRoughnessUVTransform", this.metallicRoughnessTextureTrans);
|
|
8122
|
-
} else {
|
|
8123
|
-
// fill other data
|
|
8124
|
-
material.setMatrix3("_MetallicRoughnessUVTransform", uvTransform1);
|
|
8125
|
-
}
|
|
8272
|
+
material.setMatrix3("_MetallicRoughnessUVTransform", this.metallicRoughnessTextureTrans);
|
|
8126
8273
|
}
|
|
8127
8274
|
//
|
|
8128
8275
|
if (this.normalTexture !== undefined) {
|
|
8129
|
-
material.setTexture("_NormalSampler", this.normalTexture);
|
|
8130
|
-
material.setFloat("_NormalScale", this.normalTextureScale);
|
|
8131
8276
|
material.setInt("_NormalUVSet", 0);
|
|
8132
|
-
|
|
8133
|
-
material.setMatrix3("_NormalUVTransform", this.normalTextureTrans);
|
|
8134
|
-
} else {
|
|
8135
|
-
// fill other data
|
|
8136
|
-
material.setMatrix3("_NormalUVTransform", uvTransform1);
|
|
8137
|
-
}
|
|
8277
|
+
material.setMatrix3("_NormalUVTransform", this.normalTextureTrans);
|
|
8138
8278
|
}
|
|
8139
8279
|
//
|
|
8140
8280
|
if (this.occlusionTexture !== undefined) {
|
|
8141
|
-
material.setTexture("_OcclusionSampler", this.occlusionTexture);
|
|
8142
|
-
material.setFloat("_OcclusionStrength", this.occlusionTextureStrength);
|
|
8143
8281
|
material.setInt("_OcclusionUVSet", 0);
|
|
8144
|
-
|
|
8145
|
-
material.setMatrix3("_OcclusionUVTransform", this.occlusionTextureTrans);
|
|
8146
|
-
} else {
|
|
8147
|
-
// fill other data
|
|
8148
|
-
material.setMatrix3("_OcclusionUVTransform", uvTransform1);
|
|
8149
|
-
}
|
|
8282
|
+
material.setMatrix3("_OcclusionUVTransform", this.occlusionTextureTrans);
|
|
8150
8283
|
}
|
|
8151
8284
|
//
|
|
8152
8285
|
if (this.emissiveTexture !== undefined) {
|
|
8153
|
-
var emissiveFactor = this.getEmissiveFactor();
|
|
8154
|
-
material.setTexture("_EmissiveSampler", this.emissiveTexture);
|
|
8155
|
-
material.setVector4("_EmissiveFactor", emissiveFactor);
|
|
8156
8286
|
material.setInt("_EmissiveUVSet", 0);
|
|
8157
|
-
|
|
8158
|
-
material.setMatrix3("_EmissiveUVTransform", this.emissiveTextureTrans);
|
|
8159
|
-
} else {
|
|
8160
|
-
// fill other data
|
|
8161
|
-
material.setMatrix3("_EmissiveUVTransform", uvTransform1);
|
|
8162
|
-
}
|
|
8163
|
-
} else if (this.hasEmissiveFactor()) {
|
|
8164
|
-
var emissiveFactor1 = this.getEmissiveFactor();
|
|
8165
|
-
material.setVector4("_EmissiveFactor", emissiveFactor1);
|
|
8287
|
+
material.setMatrix3("_EmissiveUVTransform", this.emissiveTextureTrans);
|
|
8166
8288
|
}
|
|
8167
8289
|
material.setFloat("_Exposure", 3.0);
|
|
8168
8290
|
};
|
|
@@ -8173,12 +8295,6 @@ var toHalf = function() {
|
|
|
8173
8295
|
return this.baseColorTexture !== undefined;
|
|
8174
8296
|
};
|
|
8175
8297
|
/**
|
|
8176
|
-
* 是否有基础颜色纹理变换
|
|
8177
|
-
* @returns
|
|
8178
|
-
*/ _proto.hasBaseColorTextureTrans = function hasBaseColorTextureTrans() {
|
|
8179
|
-
return this.baseColorTextureTrans !== undefined;
|
|
8180
|
-
};
|
|
8181
|
-
/**
|
|
8182
8298
|
* 设置基础颜色纹理
|
|
8183
8299
|
* @param val - 纹理
|
|
8184
8300
|
*/ _proto.setBaseColorTexture = function setBaseColorTexture(val) {
|
|
@@ -8194,7 +8310,10 @@ var toHalf = function() {
|
|
|
8194
8310
|
* 设置基础颜色值
|
|
8195
8311
|
* @param val - 颜色值
|
|
8196
8312
|
*/ _proto.setBaseColorFactor = function setBaseColorFactor(val) {
|
|
8197
|
-
if (_instanceof1(val,
|
|
8313
|
+
if (_instanceof1(val, Color)) {
|
|
8314
|
+
// for Vector4
|
|
8315
|
+
this.baseColorFactor.set(val.r, val.g, val.b, val.a);
|
|
8316
|
+
} else if (_instanceof1(val, Vector4)) {
|
|
8198
8317
|
// for Vector4
|
|
8199
8318
|
this.baseColorFactor.set(val.x, val.y, val.z, val.w);
|
|
8200
8319
|
} else {
|
|
@@ -8209,12 +8328,6 @@ var toHalf = function() {
|
|
|
8209
8328
|
return this.metallicRoughnessTexture !== undefined;
|
|
8210
8329
|
};
|
|
8211
8330
|
/**
|
|
8212
|
-
* 是否有金属度粗超度纹理坐标变换
|
|
8213
|
-
* @returns
|
|
8214
|
-
*/ _proto.hasMetallicRoughnessTextureTrans = function hasMetallicRoughnessTextureTrans() {
|
|
8215
|
-
return this.metallicRoughnessTextureTrans !== undefined;
|
|
8216
|
-
};
|
|
8217
|
-
/**
|
|
8218
8331
|
* 获取金属度粗超度纹理
|
|
8219
8332
|
* @returns
|
|
8220
8333
|
*/ _proto.getMetallicRoughnessTexture = function getMetallicRoughnessTexture() {
|
|
@@ -8233,12 +8346,6 @@ var toHalf = function() {
|
|
|
8233
8346
|
return this.normalTexture !== undefined;
|
|
8234
8347
|
};
|
|
8235
8348
|
/**
|
|
8236
|
-
* 是否有法线纹理坐标变换
|
|
8237
|
-
* @returns
|
|
8238
|
-
*/ _proto.hasNormalTextureTrans = function hasNormalTextureTrans() {
|
|
8239
|
-
return this.normalTextureTrans !== undefined;
|
|
8240
|
-
};
|
|
8241
|
-
/**
|
|
8242
8349
|
* 获取法线纹理
|
|
8243
8350
|
* @returns
|
|
8244
8351
|
*/ _proto.getNormalTexture = function getNormalTexture() {
|
|
@@ -8257,12 +8364,6 @@ var toHalf = function() {
|
|
|
8257
8364
|
return this.occlusionTexture !== undefined;
|
|
8258
8365
|
};
|
|
8259
8366
|
/**
|
|
8260
|
-
* 是否有遮挡纹理坐标变换
|
|
8261
|
-
* @returns
|
|
8262
|
-
*/ _proto.hasOcclusionTextureTrans = function hasOcclusionTextureTrans() {
|
|
8263
|
-
return this.occlusionTextureTrans !== undefined;
|
|
8264
|
-
};
|
|
8265
|
-
/**
|
|
8266
8367
|
* 获取遮挡纹理
|
|
8267
8368
|
* @returns
|
|
8268
8369
|
*/ _proto.getOcclusionTexture = function getOcclusionTexture() {
|
|
@@ -8281,12 +8382,6 @@ var toHalf = function() {
|
|
|
8281
8382
|
return this.emissiveTexture !== undefined;
|
|
8282
8383
|
};
|
|
8283
8384
|
/**
|
|
8284
|
-
* 是否有自发光纹理坐标变换
|
|
8285
|
-
* @returns
|
|
8286
|
-
*/ _proto.hasEmissiveTextureTrans = function hasEmissiveTextureTrans() {
|
|
8287
|
-
return this.emissiveTextureTrans !== undefined;
|
|
8288
|
-
};
|
|
8289
|
-
/**
|
|
8290
8385
|
* 获取自发光纹理
|
|
8291
8386
|
* @returns
|
|
8292
8387
|
*/ _proto.getEmissiveTexture = function getEmissiveTexture() {
|
|
@@ -8299,22 +8394,25 @@ var toHalf = function() {
|
|
|
8299
8394
|
this.emissiveTexture = val;
|
|
8300
8395
|
};
|
|
8301
8396
|
/**
|
|
8302
|
-
*
|
|
8397
|
+
* 是否有自发光值,包含强度
|
|
8303
8398
|
* @returns
|
|
8304
|
-
*/ _proto.
|
|
8305
|
-
return this.emissiveFactor.
|
|
8399
|
+
*/ _proto.hasEmissiveValue = function hasEmissiveValue() {
|
|
8400
|
+
return this.emissiveFactor.luminance() * this.emissiveIntensity > 0;
|
|
8306
8401
|
};
|
|
8307
8402
|
/**
|
|
8308
|
-
*
|
|
8403
|
+
* 获取自发光颜色
|
|
8309
8404
|
* @returns
|
|
8310
8405
|
*/ _proto.getEmissiveFactor = function getEmissiveFactor() {
|
|
8311
|
-
return this.emissiveFactor
|
|
8406
|
+
return this.emissiveFactor;
|
|
8312
8407
|
};
|
|
8313
8408
|
/**
|
|
8314
8409
|
* 设置自发光颜色
|
|
8315
8410
|
* @param val - 颜色
|
|
8316
8411
|
*/ _proto.setEmissiveFactor = function setEmissiveFactor(val) {
|
|
8317
|
-
if (_instanceof1(val,
|
|
8412
|
+
if (_instanceof1(val, Color)) {
|
|
8413
|
+
// Color
|
|
8414
|
+
this.emissiveFactor.set(val.r, val.g, val.b, val.a);
|
|
8415
|
+
} else if (_instanceof1(val, Vector3)) {
|
|
8318
8416
|
// Vector3
|
|
8319
8417
|
this.emissiveFactor.set(val.x, val.y, val.z, 0);
|
|
8320
8418
|
} else {
|
|
@@ -8322,38 +8420,35 @@ var toHalf = function() {
|
|
|
8322
8420
|
this.emissiveFactor.set(val[0], val[1], val[2], 0);
|
|
8323
8421
|
}
|
|
8324
8422
|
};
|
|
8325
|
-
|
|
8326
|
-
|
|
8327
|
-
|
|
8328
|
-
|
|
8329
|
-
|
|
8423
|
+
/**
|
|
8424
|
+
* 获取自发光强度
|
|
8425
|
+
* @returns
|
|
8426
|
+
*/ _proto.getEmissiveIntensity = function getEmissiveIntensity() {
|
|
8427
|
+
return this.emissiveIntensity;
|
|
8428
|
+
};
|
|
8429
|
+
/**
|
|
8430
|
+
* 设置自发光强度
|
|
8431
|
+
* @param val - 强度
|
|
8432
|
+
*/ _proto.setEmissiveIntensity = function setEmissiveIntensity(val) {
|
|
8433
|
+
this.emissiveIntensity = val;
|
|
8330
8434
|
};
|
|
8331
8435
|
return PMaterialPBR;
|
|
8332
8436
|
}(PMaterialBase);
|
|
8333
8437
|
/**
|
|
8334
8438
|
* 创建插件材质对象
|
|
8335
|
-
* @param
|
|
8439
|
+
* @param material - Effects 材质对象
|
|
8336
8440
|
* @returns 材质对象
|
|
8337
|
-
*/ function createPluginMaterial(
|
|
8338
|
-
if (
|
|
8441
|
+
*/ function createPluginMaterial(material) {
|
|
8442
|
+
if (material.shader.getInstanceId() === PBRShaderGUID) {
|
|
8339
8443
|
var materialPBR = new PMaterialPBR();
|
|
8340
|
-
materialPBR.
|
|
8444
|
+
materialPBR.create(material);
|
|
8341
8445
|
return materialPBR;
|
|
8342
8446
|
} else {
|
|
8343
|
-
|
|
8344
|
-
|
|
8345
|
-
|
|
8346
|
-
return materialPBR1;
|
|
8347
|
-
} else {
|
|
8348
|
-
var materialUnlit = new PMaterialUnlit();
|
|
8349
|
-
materialUnlit.create(options);
|
|
8350
|
-
return materialUnlit;
|
|
8351
|
-
}
|
|
8447
|
+
var materialUnlit = new PMaterialUnlit();
|
|
8448
|
+
materialUnlit.create(material);
|
|
8449
|
+
return materialUnlit;
|
|
8352
8450
|
}
|
|
8353
8451
|
}
|
|
8354
|
-
function createInternalMaterial(options) {
|
|
8355
|
-
return {};
|
|
8356
|
-
}
|
|
8357
8452
|
|
|
8358
8453
|
/**
|
|
8359
8454
|
* 天空盒类,支持天空盒的渲染和 IBL 光照效果
|
|
@@ -8444,8 +8539,6 @@ function createInternalMaterial(options) {
|
|
|
8444
8539
|
this.updateMaterial(scene);
|
|
8445
8540
|
if (this.visible && this.renderable && this.skyboxMesh !== undefined) {
|
|
8446
8541
|
var mesh = this.skyboxMesh;
|
|
8447
|
-
mesh.geometry.flush();
|
|
8448
|
-
mesh.material.initialize();
|
|
8449
8542
|
renderer.drawGeometry(mesh.geometry, mesh.material);
|
|
8450
8543
|
}
|
|
8451
8544
|
};
|
|
@@ -8553,7 +8646,7 @@ function createInternalMaterial(options) {
|
|
|
8553
8646
|
*/ _proto.create = function create(skybox) {
|
|
8554
8647
|
this.type = PObjectType.material;
|
|
8555
8648
|
this.materialType = PMaterialType.skyboxFilter;
|
|
8556
|
-
this.
|
|
8649
|
+
this.ZTest = false;
|
|
8557
8650
|
//
|
|
8558
8651
|
this.name = skybox.name;
|
|
8559
8652
|
this.intensity = skybox.intensity;
|
|
@@ -8806,12 +8899,12 @@ var PSkyboxType;
|
|
|
8806
8899
|
*/ PSkyboxCreator.createSpecularCubeMap = function createSpecularCubeMap(engine, params) {
|
|
8807
8900
|
return _async_to_generator(function() {
|
|
8808
8901
|
return __generator(this, function(_state) {
|
|
8809
|
-
|
|
8810
|
-
|
|
8811
|
-
|
|
8812
|
-
|
|
8813
|
-
|
|
8814
|
-
}
|
|
8902
|
+
// const configOptions: TextureConfigOptions = {
|
|
8903
|
+
// wrapS: glContext.CLAMP_TO_EDGE,
|
|
8904
|
+
// wrapT: glContext.CLAMP_TO_EDGE,
|
|
8905
|
+
// magFilter: glContext.LINEAR,
|
|
8906
|
+
// minFilter: glContext.LINEAR_MIPMAP_LINEAR,
|
|
8907
|
+
// };
|
|
8815
8908
|
if (params.type === "url") {
|
|
8816
8909
|
return [
|
|
8817
8910
|
2,
|
|
@@ -8836,7 +8929,8 @@ var PSkyboxType;
|
|
|
8836
8929
|
return __generator(this, function(_state) {
|
|
8837
8930
|
if (params.diffuseImage === undefined) {
|
|
8838
8931
|
return [
|
|
8839
|
-
2
|
|
8932
|
+
2,
|
|
8933
|
+
null
|
|
8840
8934
|
];
|
|
8841
8935
|
}
|
|
8842
8936
|
if (params.type === "url") {
|
|
@@ -8877,7 +8971,9 @@ var PSkyboxType;
|
|
|
8877
8971
|
var dataArray = [];
|
|
8878
8972
|
switch(skyboxType){
|
|
8879
8973
|
case 0:
|
|
8880
|
-
|
|
8974
|
+
{
|
|
8975
|
+
return undefined;
|
|
8976
|
+
}
|
|
8881
8977
|
case 1:
|
|
8882
8978
|
dataArray = [
|
|
8883
8979
|
0.2665672302246094,
|
|
@@ -9367,7 +9463,7 @@ var PSkyboxType;
|
|
|
9367
9463
|
* @param options - 加载选项
|
|
9368
9464
|
*/ ModelPlugin.prepareResource = function prepareResource(scene, options) {
|
|
9369
9465
|
return _async_to_generator(function() {
|
|
9370
|
-
var
|
|
9466
|
+
var keyList, pluginData, _options_env, runtimeEnv;
|
|
9371
9467
|
return __generator(this, function(_state) {
|
|
9372
9468
|
switch(_state.label){
|
|
9373
9469
|
case 0:
|
|
@@ -9389,8 +9485,8 @@ var PSkyboxType;
|
|
|
9389
9485
|
//
|
|
9390
9486
|
runtimeEnv = (_options_env = options.env) != null ? _options_env : "";
|
|
9391
9487
|
scene.storage["runtimeEnv"] = runtimeEnv;
|
|
9392
|
-
|
|
9393
|
-
|
|
9488
|
+
// const compatibleMode = options.pluginData?.['compatibleMode'] ?? 'gltf';
|
|
9489
|
+
// const autoAdjustScene = options.pluginData?.['autoAdjustScene'] ?? false;
|
|
9394
9490
|
//
|
|
9395
9491
|
//PluginHelper.preprocessScene(scene, runtimeEnv, compatibleMode, autoAdjustScene);
|
|
9396
9492
|
return [
|
|
@@ -9408,24 +9504,28 @@ var PSkyboxType;
|
|
|
9408
9504
|
};
|
|
9409
9505
|
ModelPlugin.precompile = function precompile(compositions, renderer) {
|
|
9410
9506
|
var isWebGL2 = renderer.engine.gpuCapability.level === 2;
|
|
9411
|
-
var
|
|
9507
|
+
var pbrShaderCode = fetchPBRShaderCode(isWebGL2);
|
|
9508
|
+
var unlitShaderCode = fetchUnlitShaderCode(isWebGL2);
|
|
9509
|
+
var pbrShaderData = {
|
|
9510
|
+
id: PBRShaderGUID,
|
|
9511
|
+
name: "PBR Shader",
|
|
9512
|
+
dataType: spec.DataType.Shader,
|
|
9513
|
+
fragment: pbrShaderCode.fragmentShaderCode,
|
|
9514
|
+
vertex: pbrShaderCode.vertexShaderCode,
|
|
9412
9515
|
// @ts-expect-error
|
|
9413
|
-
|
|
9414
|
-
materialType: PMaterialType.pbr
|
|
9415
|
-
},
|
|
9416
|
-
isWebGL2: isWebGL2,
|
|
9417
|
-
featureList: []
|
|
9516
|
+
glslVersion: isWebGL2 ? GLSLVersion.GLSL3 : GLSLVersion.GLSL1
|
|
9418
9517
|
};
|
|
9419
|
-
var
|
|
9420
|
-
|
|
9421
|
-
|
|
9422
|
-
|
|
9423
|
-
|
|
9518
|
+
var unlitShaderData = {
|
|
9519
|
+
id: UnlitShaderGUID,
|
|
9520
|
+
name: "Unlit Shader",
|
|
9521
|
+
dataType: spec.DataType.Shader,
|
|
9522
|
+
fragment: unlitShaderCode.fragmentShaderCode,
|
|
9523
|
+
vertex: unlitShaderCode.vertexShaderCode,
|
|
9424
9524
|
// @ts-expect-error
|
|
9425
|
-
fragment: pbrShader.fragmentShaderCode,
|
|
9426
|
-
vertex: pbrShader.vertexShaderCode,
|
|
9427
9525
|
glslVersion: isWebGL2 ? GLSLVersion.GLSL3 : GLSLVersion.GLSL1
|
|
9428
|
-
}
|
|
9526
|
+
};
|
|
9527
|
+
renderer.engine.addEffectsObjectData(pbrShaderData);
|
|
9528
|
+
renderer.engine.addEffectsObjectData(unlitShaderData);
|
|
9429
9529
|
return Promise.resolve();
|
|
9430
9530
|
};
|
|
9431
9531
|
return ModelPlugin;
|
|
@@ -9585,7 +9685,7 @@ var ModelPluginComponent = /*#__PURE__*/ function(ItemBehaviour) {
|
|
|
9585
9685
|
return ModelPluginComponent;
|
|
9586
9686
|
}(ItemBehaviour);
|
|
9587
9687
|
ModelPluginComponent = __decorate([
|
|
9588
|
-
effectsClass(DataType.ModelPluginComponent)
|
|
9688
|
+
effectsClass(spec.DataType.ModelPluginComponent)
|
|
9589
9689
|
], ModelPluginComponent);
|
|
9590
9690
|
/**
|
|
9591
9691
|
* 获取场景管理器,从合成中查找
|
|
@@ -9781,7 +9881,7 @@ var ModelTreeComponent = /*#__PURE__*/ function(ItemBehaviour) {
|
|
|
9781
9881
|
return ModelTreeComponent;
|
|
9782
9882
|
}(ItemBehaviour);
|
|
9783
9883
|
ModelTreeComponent = __decorate([
|
|
9784
|
-
effectsClass(DataType.TreeComponent)
|
|
9884
|
+
effectsClass(spec.DataType.TreeComponent)
|
|
9785
9885
|
], ModelTreeComponent);
|
|
9786
9886
|
|
|
9787
9887
|
/**
|
|
@@ -11701,8 +11801,8 @@ var GLTFHelper = /*#__PURE__*/ function() {
|
|
|
11701
11801
|
|
|
11702
11802
|
registerPlugin("tree", ModelTreePlugin, VFXItem, true);
|
|
11703
11803
|
registerPlugin("model", ModelPlugin, VFXItem);
|
|
11704
|
-
var version = "2.0.0-alpha.
|
|
11804
|
+
var version = "2.0.0-alpha.9";
|
|
11705
11805
|
logger.info("plugin model version: " + version);
|
|
11706
11806
|
|
|
11707
|
-
export { BoxMesh, CameraGestureHandlerImp, CameraGestureType, CheckerHelper, CompositionCache, CompositionHitTest, FBOOptions, Float16ArrayWrapper, GeometryBoxProxy, HitTestingProxy, HookOGLFunc, InterpolationSampler, LoaderHelper, LoaderImpl, MeshHelper, ModelCameraComponent, ModelLightComponent, ModelMeshComponent, ModelPlugin, ModelPluginComponent, ModelSkyboxComponent, ModelTreeComponent, ModelTreeItem, ModelTreePlugin, PAnimInterpType, PAnimPathType, PAnimTexture, PAnimTrack, PAnimation, PAnimationManager, PBlendMode, PCamera, PCameraManager, PCoordinate, PEntity, PFaceSideMode, PGeometry, PGlobalState, PLight, PLightManager, PLightType, PMaterialBase, PMaterialPBR, PMaterialSkyboxFilter, PMaterialType, PMaterialUnlit, PMesh, PMorph, PObject, PObjectType, PPrimitive, PSceneManager, PShaderManager, PShadowType, PSkin, PSkybox, PSkyboxCreator, PSkyboxType, PTextureType, PTransform, PluginHelper, RayBoxTesting, RayIntersectsBoxWithRotation, RayTriangleTesting, TextureDataMode, ToggleItemBounding, TwoStatesSet, VFX_ITEM_TYPE_3D, VertexAttribBuffer, WebGLHelper, WebHelper, createAnimationSampler,
|
|
11807
|
+
export { BoxMesh, CameraGestureHandlerImp, CameraGestureType, CheckerHelper, CompositionCache, CompositionHitTest, CullMode, FBOOptions, Float16ArrayWrapper, GeometryBoxProxy, HitTestingProxy, HookOGLFunc, InterpolationSampler, LoaderHelper, LoaderImpl, MeshHelper, ModelCameraComponent, ModelLightComponent, ModelMeshComponent, ModelPlugin, ModelPluginComponent, ModelSkyboxComponent, ModelTreeComponent, ModelTreeItem, ModelTreePlugin, PAnimInterpType, PAnimPathType, PAnimTexture, PAnimTrack, PAnimation, PAnimationManager, PBRShaderGUID, PBlendMode, PCamera, PCameraManager, PCoordinate, PEntity, PFaceSideMode, PGeometry, PGlobalState, PLight, PLightManager, PLightType, PMaterialBase, PMaterialPBR, PMaterialSkyboxFilter, PMaterialType, PMaterialUnlit, PMesh, PMorph, PObject, PObjectType, PPrimitive, PSceneManager, PShaderManager, PShadowType, PSkin, PSkybox, PSkyboxCreator, PSkyboxType, PTextureType, PTransform, PluginHelper, RayBoxTesting, RayIntersectsBoxWithRotation, RayTriangleTesting, RenderType, TextureDataMode, ToggleItemBounding, TwoStatesSet, UnlitShaderGUID, VFX_ITEM_TYPE_3D, VertexAttribBuffer, WebGLHelper, WebHelper, createAnimationSampler, createPluginMaterial, fetchPBRShaderCode, fetchUnlitShaderCode, getDefaultEffectsGLTFLoader, getDiffuseOnlyShaderCode, getGaussianBlurShaderCodeV1, getGaussianBlurShaderCodeV2, getKawaseBlurShaderCode, getNormalVisShaderCode, getPBRPassShaderCode, getPMeshList, getQuadFilterShaderCode, getRendererGPUInfo, getSceneManager, getShadowPassShaderCode, getSimpleFilterShaderCode, getSkyBoxShaderCode, getTransparecyBaseShader, getTransparecyFilterShader, setDefaultEffectsGLTFLoader, version };
|
|
11708
11808
|
//# sourceMappingURL=index.mjs.map
|