@galacean/effects-plugin-model 2.0.0-alpha.27 → 2.0.0-alpha.29
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/alipay.js +88 -32
- package/dist/alipay.js.map +1 -1
- package/dist/alipay.mjs +88 -32
- package/dist/alipay.mjs.map +1 -1
- package/dist/douyin.js +13928 -0
- package/dist/douyin.js.map +1 -0
- package/dist/douyin.mjs +13809 -0
- package/dist/douyin.mjs.map +1 -0
- package/dist/gltf/json-converter.d.ts +2 -1
- package/dist/index.js +89 -33
- 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 +89 -33
- package/dist/index.mjs.map +1 -1
- package/dist/loader.mjs +90 -34
- package/dist/loader.mjs.map +1 -1
- package/dist/plugin/model-plugin.d.ts +1 -0
- package/dist/runtime/animation.d.ts +5 -1
- package/dist/runtime/mesh.d.ts +1 -1
- package/dist/runtime/scene.d.ts +12 -0
- package/dist/weapp.js +13928 -0
- package/dist/weapp.js.map +1 -0
- package/dist/weapp.mjs +13809 -0
- package/dist/weapp.mjs.map +1 -0
- package/package.json +15 -5
package/dist/loader.mjs
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
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.29
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import * as EFFECTS from '@galacean/effects';
|
|
10
|
-
import { math, Transform, spec, PLAYER_OPTIONS_ENV_EDITOR, glContext, generateGUID, TextureSourceType, loadImage, Texture, Material, Mesh, Geometry, effectsClass, VFXItem, GLSLVersion, ItemBehaviour, AbstractPlugin, registerPlugin, logger,
|
|
10
|
+
import { math, Transform, spec, PLAYER_OPTIONS_ENV_EDITOR, glContext, generateGUID, TextureSourceType, loadImage, Texture, Material, Mesh, Geometry, effectsClass, VFXItem, GLSLVersion, ItemBehaviour, AbstractPlugin, registerPlugin, logger, RendererComponent, HitTestType, AnimationClip, RenderPass, TextureLoadAction, DestroyOptions, RenderPassDestroyAttachmentType, Renderer, getDefaultTextureFactory, Player, addItem, removeItem, glType2VertexFormatType, Downloader, getStandardJSON, isObject } from '@galacean/effects';
|
|
11
11
|
|
|
12
12
|
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;
|
|
13
13
|
|
|
@@ -1224,21 +1224,21 @@ var objectIndex = 1;
|
|
|
1224
1224
|
* Model 插件元素类型
|
|
1225
1225
|
*/ var VFX_ITEM_TYPE_3D = "PluginModel";
|
|
1226
1226
|
|
|
1227
|
-
var primitiveVert = "precision highp float;\n#define FEATURES\n#include <
|
|
1227
|
+
var primitiveVert = "precision highp float;\n#define FEATURES\n#include <webgl-compatibility.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 aTangent;\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 aColor;vsOut vec3 v_Color;\n#endif\n#ifdef HAS_VERTEX_COLOR_VEC4\nvsIn vec4 aColor;vsOut vec4 v_Color;\n#endif\nuniform mat4 effects_MatrixVP;uniform mat4 effects_ObjectToWorld;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=aTangent;\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=effects_ObjectToWorld*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(effects_ObjectToWorld*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=aColor;\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=effects_MatrixVP*pos;\n#ifdef EDITOR_TRANSFORM\ngl_Position=vec4(gl_Position.xy*uEditorTransform.xy+uEditorTransform.zw*gl_Position.w,gl_Position.zw);\n#endif\n}";
|
|
1228
1228
|
|
|
1229
|
-
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}";
|
|
1229
|
+
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 <webgl-compatibility.glsl>\n#include <extensions.frag.glsl>\n#include <tone-mapping.frag.glsl>\n#include <textures.vert.glsl>\n#include <functions.frag.glsl>\n#include <shadow-common.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}";
|
|
1230
1230
|
|
|
1231
|
-
var shadowPassFrag = "#define FEATURES\n#include <
|
|
1231
|
+
var shadowPassFrag = "#define FEATURES\n#include <shadow-common.vert.glsl>\n#include <webgl-compatibility.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}";
|
|
1232
1232
|
|
|
1233
|
-
var skyboxVert = "precision highp float;\n#define FEATURES\n#include <
|
|
1233
|
+
var skyboxVert = "precision highp float;\n#define FEATURES\n#include <webgl-compatibility.glsl>\nvsIn vec3 aPos;vsOut vec3 v_CameraDir;uniform mat4 _InvViewProjectionMatrix;void main(){vec4 dir=_InvViewProjectionMatrix*vec4(aPos.xy,1,1);v_CameraDir=normalize(dir.xyz/dir.w);gl_Position=vec4(aPos.xy,0.99999,1);}";
|
|
1234
1234
|
|
|
1235
|
-
var skyboxFrag = "\n#define FEATURES\n#if !defined(WEBGL2) && defined(USE_TEX_LOD)\n#extension GL_EXT_shader_texture_lod : enable\n#endif\n#if !defined(WEBGL2)\n#extension GL_OES_standard_derivatives : enable\n#endif\nprecision highp float;\n#include <
|
|
1235
|
+
var skyboxFrag = "\n#define FEATURES\n#if !defined(WEBGL2) && defined(USE_TEX_LOD)\n#extension GL_EXT_shader_texture_lod : enable\n#endif\n#if !defined(WEBGL2)\n#extension GL_OES_standard_derivatives : enable\n#endif\nprecision highp float;\n#include <webgl-compatibility.glsl>\n#include <extensions.frag.glsl>\n#ifdef WEBGL2\nout vec4 outFragColor;\n#else\n#define outFragColor gl_FragColor\n#endif\nuniform sampler2D _brdfLUT;uniform vec2 _IblIntensity;uniform int _MipCount;uniform samplerCube _DiffuseEnvSampler;uniform samplerCube _SpecularEnvSampler;fsIn vec3 v_CameraDir;\n#ifdef IRRADIANCE_COEFFICIENTS\nstruct SHCoefficients{vec3 l00,l1m1,l10,l11,l2m2,l2m1,l20,l21,l22;};uniform SHCoefficients _shCoefficients;vec3 getIrradiance(vec3 norm,SHCoefficients c){float x=norm.x;float y=norm.y;float z=norm.z;float c1=0.429043;float c2=0.511664;float c3=0.743125;float c4=0.886227;float c5=0.247708;vec3 irradiance=c1*c.l22*(x*x-y*y)+c3*c.l20*(z*z)+c4*c.l00-c5*c.l20+2.0*c1*(c.l2m2*x*y+c.l21*x*z+c.l2m1*y*z)+2.0*c2*(c.l11*x+c.l1m1*y+c.l10*z);return irradiance;}\n#endif\nvec3 getIBLContribution(vec3 n,vec3 v){const float metallic=0.9;const float perceptualRoughness=0.1;const vec4 baseColor=vec4(1.0);const vec3 f0=vec3(0.04);const vec3 diffuseColor=baseColor.rgb*(vec3(1.0)-f0)*(1.0-metallic);const vec3 specularColor=mix(f0,baseColor.rgb,metallic);float NdotV=clamp(dot(n,v),0.0,1.0);float lod=clamp(perceptualRoughness*float(_MipCount),0.0,float(_MipCount));vec3 reflection=normalize(reflect(-v,n));vec2 brdfSamplePoint=clamp(vec2(NdotV,perceptualRoughness),vec2(0.0,0.0),vec2(1.0,1.0));vec2 brdf=texture2D(_brdfLUT,brdfSamplePoint).rg;vec4 diffuseSample=vec4(1.0,0.0,0.0,1.0);\n#ifdef IRRADIANCE_COEFFICIENTS\nvec3 irradiance=getIrradiance(n,_shCoefficients);diffuseSample=vec4(irradiance,1.0);\n#else\ndiffuseSample=textureCube(_DiffuseEnvSampler,n);\n#endif\n#ifdef USE_TEX_LOD\nvec4 specularSample=_textureCubeLodEXT(_SpecularEnvSampler,reflection,lod);\n#else\nvec4 specularSample=textureCube(_SpecularEnvSampler,reflection,lod);\n#endif\nvec3 diffuseLight=diffuseSample.rgb;vec3 specularLight=specularSample.rgb;vec3 diffuse=diffuseLight*diffuseColor;vec3 specular=specularLight*(specularColor*brdf.x+brdf.y);return diffuse*_IblIntensity[0]+specular*_IblIntensity[1];}void main(){vec3 dir=normalize(v_CameraDir);outFragColor=vec4(getIBLContribution(dir,dir),1.0);}";
|
|
1236
1236
|
|
|
1237
1237
|
var animationVertGLSL = "#ifdef HAS_TARGET_POSITION0\nvsIn vec3 aTargetPosition0;\n#endif\n#ifdef HAS_TARGET_POSITION1\nvsIn vec3 aTargetPosition1;\n#endif\n#ifdef HAS_TARGET_POSITION2\nvsIn vec3 aTargetPosition2;\n#endif\n#ifdef HAS_TARGET_POSITION3\nvsIn vec3 aTargetPosition3;\n#endif\n#ifdef HAS_TARGET_POSITION4\nvsIn vec3 aTargetPosition4;\n#endif\n#ifdef HAS_TARGET_POSITION5\nvsIn vec3 aTargetPosition5;\n#endif\n#ifdef HAS_TARGET_POSITION6\nvsIn vec3 aTargetPosition6;\n#endif\n#ifdef HAS_TARGET_POSITION7\nvsIn vec3 aTargetPosition7;\n#endif\n#ifdef HAS_TARGET_NORMAL0\nvsIn vec3 aTargetNormal0;\n#endif\n#ifdef HAS_TARGET_NORMAL1\nvsIn vec3 aTargetNormal1;\n#endif\n#ifdef HAS_TARGET_NORMAL2\nvsIn vec3 aTargetNormal2;\n#endif\n#ifdef HAS_TARGET_NORMAL3\nvsIn vec3 aTargetNormal3;\n#endif\n#ifdef HAS_TARGET_NORMAL4\nvsIn vec3 aTargetNormal4;\n#endif\n#ifdef HAS_TARGET_TANGENT0\nvsIn vec3 aTargetTangent0;\n#endif\n#ifdef HAS_TARGET_TANGENT1\nvsIn vec3 aTargetTangent1;\n#endif\n#ifdef HAS_TARGET_TANGENT2\nvsIn vec3 aTargetTangent2;\n#endif\n#ifdef HAS_TARGET_TANGENT3\nvsIn vec3 aTargetTangent3;\n#endif\n#ifdef HAS_TARGET_TANGENT4\nvsIn vec3 aTargetTangent4;\n#endif\n#ifdef USE_MORPHING\nuniform float _morphWeights[WEIGHT_COUNT];\n#endif\n#ifdef HAS_JOINT_SET1\nvsIn vec4 aJoints;\n#endif\n#ifdef HAS_JOINT_SET2\nvsIn vec4 aJoint2;\n#endif\n#ifdef HAS_WEIGHT_SET1\nvsIn vec4 aWeights;\n#endif\n#ifdef HAS_WEIGHT_SET2\nvsIn vec4 aWeight2;\n#endif\n#ifdef USE_SKINNING\n#ifdef USE_SKINNING_TEXTURE\nuniform sampler2D _jointMatrixSampler;uniform sampler2D _jointNormalMatrixSampler;\n#else\nuniform mat4 _jointMatrix[JOINT_COUNT];uniform mat4 _jointNormalMatrix[JOINT_COUNT];\n#endif\n#endif\n#define ROW0_U ((0.5 + 0.0) / 4.0)\n#define ROW1_U ((0.5 + 1.0) / 4.0)\n#define ROW2_U ((0.5 + 2.0) / 4.0)\n#define ROW3_U ((0.5 + 3.0) / 4.0)\n#ifdef USE_SKINNING\nmat4 getJointMatrix(float boneNdx){\n#ifdef USE_SKINNING_TEXTURE\nfloat v=(boneNdx+0.5)/float(JOINT_COUNT);return mat4(texture2D(_jointMatrixSampler,vec2(ROW0_U,v)),texture2D(_jointMatrixSampler,vec2(ROW1_U,v)),texture2D(_jointMatrixSampler,vec2(ROW2_U,v)),texture2D(_jointMatrixSampler,vec2(ROW3_U,v)));\n#else\nreturn _jointMatrix[int(boneNdx)];\n#endif\n}mat4 getJointNormalMatrix(float boneNdx){\n#ifdef USE_SKINNING_TEXTURE\nfloat v=(boneNdx+0.5)/float(JOINT_COUNT);return mat4(texture2D(_jointNormalMatrixSampler,vec2(ROW0_U,v)),texture2D(_jointNormalMatrixSampler,vec2(ROW1_U,v)),texture2D(_jointNormalMatrixSampler,vec2(ROW2_U,v)),texture2D(_jointNormalMatrixSampler,vec2(ROW3_U,v)));\n#else\nreturn _jointNormalMatrix[int(boneNdx)];\n#endif\n}mat4 getSkinningMatrix(){mat4 skin=mat4(0);\n#if defined(HAS_WEIGHT_SET1) && defined(HAS_JOINT_SET1)\nskin+=aWeights.x*getJointMatrix(aJoints.x)+aWeights.y*getJointMatrix(aJoints.y)+aWeights.z*getJointMatrix(aJoints.z)+aWeights.w*getJointMatrix(aJoints.w);\n#endif\nreturn skin;}mat4 getSkinningNormalMatrix(){mat4 skin=mat4(0);\n#if defined(HAS_WEIGHT_SET1) && defined(HAS_JOINT_SET1)\nskin+=aWeights.x*getJointNormalMatrix(aJoints.x)+aWeights.y*getJointNormalMatrix(aJoints.y)+aWeights.z*getJointNormalMatrix(aJoints.z)+aWeights.w*getJointNormalMatrix(aJoints.w);\n#endif\nreturn skin;}\n#endif\n#ifdef USE_MORPHING\nvec4 getTargetPosition(){vec4 pos=vec4(0);\n#ifdef HAS_TARGET_POSITION0\npos.xyz+=_morphWeights[0]*aTargetPosition0;\n#endif\n#ifdef HAS_TARGET_POSITION1\npos.xyz+=_morphWeights[1]*aTargetPosition1;\n#endif\n#ifdef HAS_TARGET_POSITION2\npos.xyz+=_morphWeights[2]*aTargetPosition2;\n#endif\n#ifdef HAS_TARGET_POSITION3\npos.xyz+=_morphWeights[3]*aTargetPosition3;\n#endif\n#ifdef HAS_TARGET_POSITION4\npos.xyz+=_morphWeights[4]*aTargetPosition4;\n#endif\nreturn pos;}vec4 getTargetNormal(){vec4 normal=vec4(0);\n#ifdef HAS_TARGET_NORMAL0\nnormal.xyz+=_morphWeights[0]*aTargetNormal0;\n#endif\n#ifdef HAS_TARGET_NORMAL1\nnormal.xyz+=_morphWeights[1]*aTargetNormal1;\n#endif\n#ifdef HAS_TARGET_NORMAL2\nnormal.xyz+=_morphWeights[2]*aTargetNormal2;\n#endif\n#ifdef HAS_TARGET_NORMAL3\nnormal.xyz+=_morphWeights[3]*aTargetNormal3;\n#endif\n#ifdef HAS_TARGET_NORMAL4\nnormal.xyz+=_morphWeights[4]*aTargetNormal4;\n#endif\nreturn normal;}vec4 getTargetTangent(){vec4 tangent=vec4(0);\n#ifdef HAS_TARGET_TANGENT0\ntangent.xyz+=_morphWeights[0]*aTargetTangent0;\n#endif\n#ifdef HAS_TARGET_TANGENT1\ntangent.xyz+=_morphWeights[1]*aTargetTangent1;\n#endif\n#ifdef HAS_TARGET_TANGENT2\ntangent.xyz+=_morphWeights[2]*aTargetTangent2;\n#endif\n#ifdef HAS_TARGET_TANGENT3\ntangent.xyz+=_morphWeights[3]*aTargetTangent3;\n#endif\n#ifdef HAS_TARGET_TANGENT4\ntangent.xyz+=_morphWeights[4]*aTargetTangent4;\n#endif\nreturn tangent;}\n#endif\n";
|
|
1238
1238
|
|
|
1239
1239
|
var extensionsFragGLSL = "vec3 _dFdx(vec3 coord){\n#if defined(GL_OES_standard_derivatives) || defined(WEBGL2)\nreturn dFdx(coord);\n#endif\nreturn vec3(0.0);}vec3 _dFdy(vec3 coord){\n#if defined(GL_OES_standard_derivatives) || defined(WEBGL2)\nreturn dFdy(coord);\n#endif\nreturn vec3(0.0);}\n#ifdef USE_TEX_LOD\nvec4 _textureCubeLodEXT(samplerCube sampler,vec3 coord,float lod){\n#if defined(WEBGL2) || defined(GL_EXT_shader_texture_lod)\nreturn textureCubeLodEXT(sampler,coord,lod);\n#else\nreturn textureCube(sampler,coord,lod);\n#endif\n}\n#endif\n";
|
|
1240
1240
|
|
|
1241
|
-
var
|
|
1241
|
+
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);}";
|
|
1242
1242
|
|
|
1243
1243
|
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;}";
|
|
1244
1244
|
|
|
@@ -1253,12 +1253,12 @@ var shadowCommonVert = "\n#define SHADOWMAP_BAIS 0.001\n#define EVSM_FUNC0(DEPTH
|
|
|
1253
1253
|
var glsl = {
|
|
1254
1254
|
"animation.vert.glsl": animationVertGLSL,
|
|
1255
1255
|
"extensions.frag.glsl": extensionsFragGLSL,
|
|
1256
|
-
"
|
|
1256
|
+
"tone-mapping.frag.glsl": toneMappingFragGLSL,
|
|
1257
1257
|
"textures.vert.glsl": texturesVertGLSL,
|
|
1258
1258
|
"functions.frag.glsl": functionsFragGLSL,
|
|
1259
1259
|
"shadow.frag.glsl": shadowFragGLSL,
|
|
1260
|
-
"
|
|
1261
|
-
"
|
|
1260
|
+
"webgl-compatibility.glsl": webglCompatibilityGLSL,
|
|
1261
|
+
"shadow-common.vert.glsl": shadowCommonVert
|
|
1262
1262
|
};
|
|
1263
1263
|
var StandardShaderSource;
|
|
1264
1264
|
(function(StandardShaderSource) {
|
|
@@ -2558,6 +2558,7 @@ var PSkyboxType;
|
|
|
2558
2558
|
*/ var PSkyboxCreator = /*#__PURE__*/ function() {
|
|
2559
2559
|
function PSkyboxCreator() {}
|
|
2560
2560
|
var _proto = PSkyboxCreator.prototype;
|
|
2561
|
+
// TODO: 待移除?
|
|
2561
2562
|
_proto.checkCubeMapImage = function checkCubeMapImage(imageList) {
|
|
2562
2563
|
return _async_to_generator(function() {
|
|
2563
2564
|
var lastImage, specularImageLists, i, image, lastList;
|
|
@@ -3769,7 +3770,8 @@ var ModelPluginComponent = /*#__PURE__*/ function(ItemBehaviour) {
|
|
|
3769
3770
|
renderMode3D: this.renderMode3D,
|
|
3770
3771
|
renderMode3DUVGridSize: this.renderMode3DUVGridSize,
|
|
3771
3772
|
renderSkybox: this.renderSkybox,
|
|
3772
|
-
lightItemCount: this.getLightItemCount()
|
|
3773
|
+
lightItemCount: this.getLightItemCount(),
|
|
3774
|
+
maxJointCount: this.getMaxJointCount()
|
|
3773
3775
|
});
|
|
3774
3776
|
this.updateSceneCamera(component);
|
|
3775
3777
|
};
|
|
@@ -3793,6 +3795,25 @@ var ModelPluginComponent = /*#__PURE__*/ function(ItemBehaviour) {
|
|
|
3793
3795
|
});
|
|
3794
3796
|
return lightItemCount;
|
|
3795
3797
|
};
|
|
3798
|
+
_proto.getMaxJointCount = function getMaxJointCount() {
|
|
3799
|
+
var _this_item_composition;
|
|
3800
|
+
var maxJointCount = 0;
|
|
3801
|
+
var _this_item_composition_items;
|
|
3802
|
+
var items = (_this_item_composition_items = (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.items) != null ? _this_item_composition_items : [];
|
|
3803
|
+
items.forEach(function(item) {
|
|
3804
|
+
var meshComp = item.getComponent(ModelMeshComponent);
|
|
3805
|
+
if (meshComp && meshComp.data) {
|
|
3806
|
+
var geometry = meshComp.data.geometry;
|
|
3807
|
+
if (_instanceof1(geometry, Geometry)) {
|
|
3808
|
+
var skin = geometry.getSkinProps();
|
|
3809
|
+
if (skin.boneNames) {
|
|
3810
|
+
maxJointCount = Math.max(skin.boneNames.length, maxJointCount);
|
|
3811
|
+
}
|
|
3812
|
+
}
|
|
3813
|
+
}
|
|
3814
|
+
});
|
|
3815
|
+
return maxJointCount;
|
|
3816
|
+
};
|
|
3796
3817
|
return ModelPluginComponent;
|
|
3797
3818
|
}(ItemBehaviour);
|
|
3798
3819
|
ModelPluginComponent = __decorate([
|
|
@@ -4415,7 +4436,7 @@ var CameraGestureHandlerImp = /*#__PURE__*/ function() {
|
|
|
4415
4436
|
|
|
4416
4437
|
registerPlugin("tree", ModelTreePlugin, VFXItem, true);
|
|
4417
4438
|
registerPlugin("model", ModelPlugin, VFXItem);
|
|
4418
|
-
var version = "2.0.0-alpha.
|
|
4439
|
+
var version = "2.0.0-alpha.29";
|
|
4419
4440
|
logger.info("Plugin model version: " + version + ".");
|
|
4420
4441
|
if (version !== EFFECTS.version) {
|
|
4421
4442
|
console.error("注意:请统一 Model 插件与 Player 版本,不统一的版本混用会有不可预知的后果!", "\nAttention: Please ensure the Model plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!");
|
|
@@ -4489,10 +4510,10 @@ var ModelMeshComponent = /*#__PURE__*/ function(RendererComponent) {
|
|
|
4489
4510
|
* 组件开始,需要创建内部对象,更新父元素信息和添加到场景管理器中
|
|
4490
4511
|
*/ _proto.start = function start() {
|
|
4491
4512
|
var _this_sceneManager;
|
|
4513
|
+
this.sceneManager = getSceneManager(this);
|
|
4492
4514
|
this.createContent();
|
|
4493
4515
|
this.item.type = VFX_ITEM_TYPE_3D;
|
|
4494
4516
|
this.priority = this.item.renderOrder;
|
|
4495
|
-
this.sceneManager = getSceneManager(this);
|
|
4496
4517
|
(_this_sceneManager = this.sceneManager) == null ? void 0 : _this_sceneManager.addItem(this.content);
|
|
4497
4518
|
if (this.item.parentId && this.item.parent) {
|
|
4498
4519
|
this.content.updateParentInfo(this.item.parentId, this.item.parent);
|
|
@@ -7767,6 +7788,9 @@ var TextureDataMode;
|
|
|
7767
7788
|
/**
|
|
7768
7789
|
* 纹理数据模式
|
|
7769
7790
|
*/ _this.textureDataMode = 0;
|
|
7791
|
+
/**
|
|
7792
|
+
* 最大骨骼数目
|
|
7793
|
+
*/ _this.maxJointCount = 0;
|
|
7770
7794
|
return _this;
|
|
7771
7795
|
}
|
|
7772
7796
|
var _proto = PSkin.prototype;
|
|
@@ -7775,7 +7799,7 @@ var TextureDataMode;
|
|
|
7775
7799
|
* @param props - 蒙皮相关数据
|
|
7776
7800
|
* @param engine - 引擎对象
|
|
7777
7801
|
* @param rootBoneItem - 场景树父元素
|
|
7778
|
-
*/ _proto.create = function create(props, engine, rootBoneItem) {
|
|
7802
|
+
*/ _proto.create = function create(props, engine, rootBoneItem, maxJointCount) {
|
|
7779
7803
|
var _props_rootBoneName;
|
|
7780
7804
|
this.name = (_props_rootBoneName = props.rootBoneName) != null ? _props_rootBoneName : "Unnamed skin";
|
|
7781
7805
|
this.type = PObjectType.skin;
|
|
@@ -7783,11 +7807,12 @@ var TextureDataMode;
|
|
|
7783
7807
|
this.rootBoneItem = rootBoneItem;
|
|
7784
7808
|
this.skeleton = -1;
|
|
7785
7809
|
this.jointItem = this.getJointItems(props, rootBoneItem);
|
|
7810
|
+
this.maxJointCount = Math.max(maxJointCount, this.jointItem.length);
|
|
7786
7811
|
this.animationMatrices = [];
|
|
7787
7812
|
//
|
|
7788
7813
|
this.inverseBindMatrices = [];
|
|
7789
7814
|
//
|
|
7790
|
-
this.textureDataMode = this.getTextureDataMode(this.
|
|
7815
|
+
this.textureDataMode = this.getTextureDataMode(this.maxJointCount, engine);
|
|
7791
7816
|
var matList = props.inverseBindMatrices;
|
|
7792
7817
|
if (matList !== undefined && matList.length > 0) {
|
|
7793
7818
|
if (matList.length % 16 !== 0 || matList.length !== this.jointItem.length * 16) {
|
|
@@ -8963,7 +8988,7 @@ function _assert_this_initialized(self) {
|
|
|
8963
8988
|
_this./**
|
|
8964
8989
|
* 是否销毁
|
|
8965
8990
|
*/ isDisposed = false;
|
|
8966
|
-
var proxy = new EffectsMeshProxy(meshData, parent);
|
|
8991
|
+
var proxy = new EffectsMeshProxy(meshData, owner, parent);
|
|
8967
8992
|
_this.name = name;
|
|
8968
8993
|
_this.type = PObjectType.mesh;
|
|
8969
8994
|
_this.visible = false;
|
|
@@ -9276,7 +9301,7 @@ function _assert_this_initialized(self) {
|
|
|
9276
9301
|
this.effectsPriority = parent.priority;
|
|
9277
9302
|
this.geometry.setHide(parent.hide);
|
|
9278
9303
|
if (this.skin !== undefined) {
|
|
9279
|
-
var jointCount = this.skin.
|
|
9304
|
+
var jointCount = this.skin.maxJointCount;
|
|
9280
9305
|
this.jointMatrixList = new Float32Array(jointCount * 16);
|
|
9281
9306
|
this.jointNormalMatList = new Float32Array(jointCount * 16);
|
|
9282
9307
|
if (this.skin.isTextureDataMode()) {
|
|
@@ -9327,6 +9352,7 @@ function _assert_this_initialized(self) {
|
|
|
9327
9352
|
this.material.setMaterialStates(material);
|
|
9328
9353
|
}
|
|
9329
9354
|
};
|
|
9355
|
+
// TODO: 待移除?
|
|
9330
9356
|
_proto.getFeatureList = function getFeatureList(lightCount, pbrPass, skybox) {
|
|
9331
9357
|
var featureList = [];
|
|
9332
9358
|
if (this.geometry.hasNormals()) {
|
|
@@ -9451,7 +9477,7 @@ function _assert_this_initialized(self) {
|
|
|
9451
9477
|
});
|
|
9452
9478
|
macroList.push({
|
|
9453
9479
|
name: "JOINT_COUNT",
|
|
9454
|
-
value: this.skin.
|
|
9480
|
+
value: this.skin.maxJointCount
|
|
9455
9481
|
});
|
|
9456
9482
|
macroList.push({
|
|
9457
9483
|
name: "HAS_JOINT_SET1"
|
|
@@ -9884,8 +9910,9 @@ function _assert_this_initialized(self) {
|
|
|
9884
9910
|
return PGeometry;
|
|
9885
9911
|
}();
|
|
9886
9912
|
var EffectsMeshProxy = /*#__PURE__*/ function() {
|
|
9887
|
-
function EffectsMeshProxy(itemData, parentItem) {
|
|
9913
|
+
function EffectsMeshProxy(itemData, parentComponent, parentItem) {
|
|
9888
9914
|
this.itemData = itemData;
|
|
9915
|
+
this.parentComponent = parentComponent;
|
|
9889
9916
|
this.parentItem = parentItem;
|
|
9890
9917
|
this.data = itemData;
|
|
9891
9918
|
this.geometry = itemData.geometry;
|
|
@@ -9950,8 +9977,11 @@ var EffectsMeshProxy = /*#__PURE__*/ function() {
|
|
|
9950
9977
|
_proto.getSkinObj = function getSkinObj(engine) {
|
|
9951
9978
|
var skin = this.getSkinOpts();
|
|
9952
9979
|
if (skin.rootBoneName && skin.boneNames && skin.inverseBindMatrices && this.rootBoneItem) {
|
|
9980
|
+
var _this_parentComponent_sceneManager;
|
|
9953
9981
|
var skinObj = new PSkin();
|
|
9954
|
-
|
|
9982
|
+
var _this_parentComponent_sceneManager_maxJointCount;
|
|
9983
|
+
var maxJointCount = (_this_parentComponent_sceneManager_maxJointCount = (_this_parentComponent_sceneManager = this.parentComponent.sceneManager) == null ? void 0 : _this_parentComponent_sceneManager.maxJointCount) != null ? _this_parentComponent_sceneManager_maxJointCount : 0;
|
|
9984
|
+
skinObj.create(skin, engine, this.rootBoneItem, maxJointCount);
|
|
9955
9985
|
return skinObj;
|
|
9956
9986
|
}
|
|
9957
9987
|
return undefined;
|
|
@@ -9966,6 +9996,9 @@ var EffectsMeshProxy = /*#__PURE__*/ function() {
|
|
|
9966
9996
|
/**
|
|
9967
9997
|
* 最多灯光数目
|
|
9968
9998
|
*/ this.maxLightCount = 16;
|
|
9999
|
+
/**
|
|
10000
|
+
* 最大骨骼数目
|
|
10001
|
+
*/ this.maxJointCount = 0;
|
|
9969
10002
|
this.renderSkybox = false;
|
|
9970
10003
|
this.compName = "SceneManger";
|
|
9971
10004
|
this.itemList = [];
|
|
@@ -9995,6 +10028,7 @@ var EffectsMeshProxy = /*#__PURE__*/ function() {
|
|
|
9995
10028
|
this.enableDynamicSort = opts.enableDynamicSort === true;
|
|
9996
10029
|
this.renderSkybox = opts.renderSkybox;
|
|
9997
10030
|
this.maxLightCount = opts.lightItemCount;
|
|
10031
|
+
this.maxJointCount = opts.maxJointCount;
|
|
9998
10032
|
this.cameraManager.initial(this.renderer.getWidth(), this.renderer.getHeight());
|
|
9999
10033
|
this.brdfLUT = this.sceneCache.getBrdfLutTexture();
|
|
10000
10034
|
this.initGlobalState(opts);
|
|
@@ -10142,6 +10176,7 @@ var EffectsMeshProxy = /*#__PURE__*/ function() {
|
|
|
10142
10176
|
//
|
|
10143
10177
|
lightList: this.lightManager.lightList,
|
|
10144
10178
|
maxLightCount: this.maxLightCount,
|
|
10179
|
+
maxJointCount: this.maxJointCount,
|
|
10145
10180
|
skybox: this.skybox
|
|
10146
10181
|
};
|
|
10147
10182
|
if (this.enableDynamicSort) {
|
|
@@ -10297,8 +10332,10 @@ var EffectsMeshProxy = /*#__PURE__*/ function() {
|
|
|
10297
10332
|
}();
|
|
10298
10333
|
|
|
10299
10334
|
var JSONConverter = /*#__PURE__*/ function() {
|
|
10300
|
-
function JSONConverter(renderer) {
|
|
10335
|
+
function JSONConverter(renderer, keepIBLData) {
|
|
10336
|
+
if (keepIBLData === void 0) keepIBLData = true;
|
|
10301
10337
|
this.renderer = renderer;
|
|
10338
|
+
this.keepIBLData = keepIBLData;
|
|
10302
10339
|
this.treeInfo = new TreeInfo();
|
|
10303
10340
|
this.engine = renderer.engine;
|
|
10304
10341
|
this.downloader = new Downloader();
|
|
@@ -10307,7 +10344,7 @@ var JSONConverter = /*#__PURE__*/ function() {
|
|
|
10307
10344
|
_proto.processScene = function processScene(sceneData) {
|
|
10308
10345
|
var _this = this;
|
|
10309
10346
|
return _async_to_generator(function() {
|
|
10310
|
-
var sceneJSON, _tmp, oldScene, binFiles, _iterator, _step, bin, _, newScene;
|
|
10347
|
+
var sceneJSON, _tmp, oldScene, _oldScene_bins, oldBinUrls, binFiles, _iterator, _step, bin, _, newScene;
|
|
10311
10348
|
return __generator(this, function(_state) {
|
|
10312
10349
|
switch(_state.label){
|
|
10313
10350
|
case 0:
|
|
@@ -10330,13 +10367,19 @@ var JSONConverter = /*#__PURE__*/ function() {
|
|
|
10330
10367
|
_state.label = 3;
|
|
10331
10368
|
case 3:
|
|
10332
10369
|
sceneJSON = _tmp;
|
|
10333
|
-
|
|
10370
|
+
//@ts-expect-error
|
|
10371
|
+
if (!sceneJSON.textures) {
|
|
10372
|
+
//@ts-expect-error
|
|
10373
|
+
sceneJSON.textures = [];
|
|
10374
|
+
}
|
|
10375
|
+
//@ts-expect-error
|
|
10334
10376
|
sceneJSON.textures.forEach(function(tex) {
|
|
10335
10377
|
if (tex.source === undefined) {
|
|
10336
10378
|
tex.source = 0;
|
|
10337
10379
|
}
|
|
10338
10380
|
});
|
|
10339
10381
|
oldScene = getStandardJSON(sceneJSON);
|
|
10382
|
+
oldBinUrls = (_oldScene_bins = oldScene.bins) != null ? _oldScene_bins : [];
|
|
10340
10383
|
binFiles = [];
|
|
10341
10384
|
if (!oldScene.bins) return [
|
|
10342
10385
|
3,
|
|
@@ -10394,6 +10437,7 @@ var JSONConverter = /*#__PURE__*/ function() {
|
|
|
10394
10437
|
_this.setComponent(newScene, oldScene);
|
|
10395
10438
|
_this.setItem(newScene, oldScene);
|
|
10396
10439
|
_this.setComposition(newScene, oldScene);
|
|
10440
|
+
newScene.bins = oldBinUrls;
|
|
10397
10441
|
return [
|
|
10398
10442
|
2,
|
|
10399
10443
|
newScene
|
|
@@ -10420,20 +10464,30 @@ var JSONConverter = /*#__PURE__*/ function() {
|
|
|
10420
10464
|
bins = oldScene.bins;
|
|
10421
10465
|
if (!oldScene.textures) return [
|
|
10422
10466
|
3,
|
|
10423
|
-
|
|
10467
|
+
7
|
|
10424
10468
|
];
|
|
10425
10469
|
_iterator = _create_for_of_iterator_helper_loose(oldScene.textures);
|
|
10426
10470
|
_state.label = 1;
|
|
10427
10471
|
case 1:
|
|
10428
10472
|
if (!!(_step = _iterator()).done) return [
|
|
10429
10473
|
3,
|
|
10430
|
-
|
|
10474
|
+
7
|
|
10431
10475
|
];
|
|
10432
10476
|
tex = _step.value;
|
|
10433
10477
|
if (!(tex.target === 34067)) return [
|
|
10434
10478
|
3,
|
|
10435
|
-
|
|
10479
|
+
5
|
|
10436
10480
|
];
|
|
10481
|
+
if (!_this.keepIBLData) return [
|
|
10482
|
+
3,
|
|
10483
|
+
2
|
|
10484
|
+
];
|
|
10485
|
+
newTextures.push(tex);
|
|
10486
|
+
return [
|
|
10487
|
+
3,
|
|
10488
|
+
4
|
|
10489
|
+
];
|
|
10490
|
+
case 2:
|
|
10437
10491
|
mipmaps = tex.mipmaps, target = tex.target;
|
|
10438
10492
|
jobs = mipmaps.map(function(mipmap) {
|
|
10439
10493
|
return Promise.all(mipmap.map(function(pointer) {
|
|
@@ -10444,7 +10498,7 @@ var JSONConverter = /*#__PURE__*/ function() {
|
|
|
10444
10498
|
4,
|
|
10445
10499
|
Promise.all(jobs)
|
|
10446
10500
|
];
|
|
10447
|
-
case
|
|
10501
|
+
case 3:
|
|
10448
10502
|
loadedMipmaps = _state.sent();
|
|
10449
10503
|
newMipmaps = loadedMipmaps.map(function(mipmaps) {
|
|
10450
10504
|
return mipmaps.map(function(img) {
|
|
@@ -10479,11 +10533,13 @@ var JSONConverter = /*#__PURE__*/ function() {
|
|
|
10479
10533
|
});
|
|
10480
10534
|
// @ts-expect-error
|
|
10481
10535
|
newTextures.push(newTex);
|
|
10536
|
+
_state.label = 4;
|
|
10537
|
+
case 4:
|
|
10482
10538
|
return [
|
|
10483
10539
|
3,
|
|
10484
|
-
|
|
10540
|
+
6
|
|
10485
10541
|
];
|
|
10486
|
-
case
|
|
10542
|
+
case 5:
|
|
10487
10543
|
// @ts-expect-error
|
|
10488
10544
|
source = tex.source;
|
|
10489
10545
|
if (typeof source === "number") {
|
|
@@ -10493,13 +10549,13 @@ var JSONConverter = /*#__PURE__*/ function() {
|
|
|
10493
10549
|
};
|
|
10494
10550
|
}
|
|
10495
10551
|
newTextures.push(tex);
|
|
10496
|
-
_state.label =
|
|
10497
|
-
case
|
|
10552
|
+
_state.label = 6;
|
|
10553
|
+
case 6:
|
|
10498
10554
|
return [
|
|
10499
10555
|
3,
|
|
10500
10556
|
1
|
|
10501
10557
|
];
|
|
10502
|
-
case
|
|
10558
|
+
case 7:
|
|
10503
10559
|
newScene.textures = newTextures;
|
|
10504
10560
|
return [
|
|
10505
10561
|
2
|
|
@@ -11727,7 +11783,7 @@ var LoaderImpl = /*#__PURE__*/ function() {
|
|
|
11727
11783
|
_proto.loadScene = function loadScene(options) {
|
|
11728
11784
|
var _this = this;
|
|
11729
11785
|
return _async_to_generator(function() {
|
|
11730
|
-
var _this_components, _this_components1, _this_components2, // @ts-expect-error
|
|
11786
|
+
var _this_components, _this_components1, _this_components2, // @ts-expect-error
|
|
11731
11787
|
_this_items, gltfResource, gltfScene, component, clips, index;
|
|
11732
11788
|
return __generator(this, function(_state) {
|
|
11733
11789
|
switch(_state.label){
|