1 |
- var __decorate=this&&this.__decorate||function(e,i,n,t){if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)return Reflect.decorate(e,i,n,t);switch(arguments.length){case 2:return e.reduceRight(function(e,i){return i&&i(e)||e},i);case 3:return e.reduceRight(function(e,t){return void(t&&t(i,n))},void 0);case 4:return e.reduceRight(function(e,t){return t&&t(i,n,e)||e},t)}},BABYLON;!function(e){var i=function(e){function i(){e.call(this),this.DIFFUSE=!1,this.CLIPPLANE=!1,this.ALPHATEST=!1,this.POINTSIZE=!1,this.FOG=!1,this.LIGHT0=!1,this.LIGHT1=!1,this.LIGHT2=!1,this.LIGHT3=!1,this.SPOTLIGHT0=!1,this.SPOTLIGHT1=!1,this.SPOTLIGHT2=!1,this.SPOTLIGHT3=!1,this.HEMILIGHT0=!1,this.HEMILIGHT1=!1,this.HEMILIGHT2=!1,this.HEMILIGHT3=!1,this.DIRLIGHT0=!1,this.DIRLIGHT1=!1,this.DIRLIGHT2=!1,this.DIRLIGHT3=!1,this.POINTLIGHT0=!1,this.POINTLIGHT1=!1,this.POINTLIGHT2=!1,this.POINTLIGHT3=!1,this.SHADOW0=!1,this.SHADOW1=!1,this.SHADOW2=!1,this.SHADOW3=!1,this.SHADOWS=!1,this.SHADOWVSM0=!1,this.SHADOWVSM1=!1,this.SHADOWVSM2=!1,this.SHADOWVSM3=!1,this.SHADOWPCF0=!1,this.SHADOWPCF1=!1,this.SHADOWPCF2=!1,this.SHADOWPCF3=!1,this.NORMAL=!1,this.UV1=!1,this.UV2=!1,this.VERTEXCOLOR=!1,this.VERTEXALPHA=!1,this.NUM_BONE_INFLUENCERS=0,this.BonesPerMesh=0,this.INSTANCES=!1,this._keys=Object.keys(this)}return __extends(i,e),i}(e.MaterialDefines),n=function(n){function t(t,s){n.call(this,t,s),this.diffuseColor=new e.Color3(1,1,1),this.disableLighting=!1,this._worldViewProjectionMatrix=e.Matrix.Zero(),this._scaledDiffuse=new e.Color3,this._defines=new i,this._cachedDefines=new i,this._cachedDefines.BonesPerMesh=-1}return __extends(t,n),t.prototype.needAlphaBlending=function(){return this.alpha<1},t.prototype.needAlphaTesting=function(){return!1},t.prototype.getAlphaTestTexture=function(){return null},t.prototype._checkCache=function(e,i,n){return i?this._defines.INSTANCES!==n?!1:i._materialDefines&&i._materialDefines.isEqual(this._defines)?!0:!1:!0},t.prototype.isReady=function(n,t){if(this.checkReadyOnlyOnce&&this._wasPreviouslyReady)return!0;var s=this.getScene();if(!this.checkReadyOnEveryCall&&this._renderId===s.getRenderId()&&this._checkCache(s,n,t))return!0;var r=s.getEngine(),o=!1,f=!1;if(this._defines.reset(),s.texturesEnabled&&this.diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled){if(!this.diffuseTexture.isReady())return!1;f=!0,this._defines.DIFFUSE=!0}s.clipPlane&&(this._defines.CLIPPLANE=!0),r.getAlphaTesting()&&(this._defines.ALPHATEST=!0),(this.pointsCloud||s.forcePointsCloud)&&(this._defines.POINTSIZE=!0),s.fogEnabled&&n&&n.applyFog&&s.fogMode!==e.Scene.FOGMODE_NONE&&this.fogEnabled&&(this._defines.FOG=!0);if(s.lightsEnabled&&!this.disableLighting&&(o=e.MaterialHelper.PrepareDefinesForLights(s,n,this._defines)),n&&(o&&n.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(this._defines.NORMAL=!0),f&&(n.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(this._defines.UV1=!0),n.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(this._defines.UV2=!0)),n.useVertexColors&&n.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(this._defines.VERTEXCOLOR=!0,n.hasVertexAlpha&&(this._defines.VERTEXALPHA=!0)),n.useBones&&n.computeBonesUsingShaders&&(this._defines.NUM_BONE_INFLUENCERS=n.numBoneInfluencers,this._defines.BonesPerMesh=n.skeleton.bones.length+1),t&&(this._defines.INSTANCES=!0)),!this._defines.isEqual(this._cachedDefines)){this._defines.cloneTo(this._cachedDefines),s.resetCachedMaterial();var a=new e.EffectFallbacks;this._defines.FOG&&a.addFallback(1,"FOG"),e.MaterialHelper.HandleFallbacksForShadows(this._defines,a),this._defines.NUM_BONE_INFLUENCERS>0&&a.addCPUSkinningFallback(0,n);var l=[e.VertexBuffer.PositionKind];this._defines.NORMAL&&l.push(e.VertexBuffer.NormalKind),this._defines.UV1&&l.push(e.VertexBuffer.UVKind),this._defines.UV2&&l.push(e.VertexBuffer.UV2Kind),this._defines.VERTEXCOLOR&&l.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(l,n,this._defines,a),e.MaterialHelper.PrepareAttributesForInstances(l,this._defines);var d="normal",h=this._defines.toString();this._effect=s.getEngine().createEffect(d,l,["world","view","viewProjection","vEyePosition","vLightsType","vDiffuseColor","vLightData0","vLightDiffuse0","vLightSpecular0","vLightDirection0","vLightGround0","lightMatrix0","vLightData1","vLightDiffuse1","vLightSpecular1","vLightDirection1","vLightGround1","lightMatrix1","vLightData2","vLightDiffuse2","vLightSpecular2","vLightDirection2","vLightGround2","lightMatrix2","vLightData3","vLightDiffuse3","vLightSpecular3","vLightDirection3","vLightGround3","lightMatrix3","vFogInfos","vFogColor","pointSize","vDiffuseInfos","mBones","vClipPlane","diffuseMatrix","shadowsInfo0","shadowsInfo1","shadowsInfo2","shadowsInfo3","depthValues"],["diffuseSampler","shadowSampler0","shadowSampler1","shadowSampler2","shadowSampler3"],h,a,this.onCompiled,this.onError)}return this._effect.isReady()?(this._renderId=s.getRenderId(),this._wasPreviouslyReady=!0,n&&(n._materialDefines||(n._materialDefines=new i),this._defines.cloneTo(n._materialDefines)),!0):!1},t.prototype.bindOnlyWorldMatrix=function(e){this._effect.setMatrix("world",e)},t.prototype.bind=function(i,t){var s=this.getScene();this.bindOnlyWorldMatrix(i),this._effect.setMatrix("viewProjection",s.getTransformMatrix()),e.MaterialHelper.BindBonesParameters(t,this._effect),s.getCachedMaterial()!==this&&(this.diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled&&(this._effect.setTexture("diffuseSampler",this.diffuseTexture),this._effect.setFloat2("vDiffuseInfos",this.diffuseTexture.coordinatesIndex,this.diffuseTexture.level),this._effect.setMatrix("diffuseMatrix",this.diffuseTexture.getTextureMatrix())),e.MaterialHelper.BindClipPlane(this._effect,s),this.pointsCloud&&this._effect.setFloat("pointSize",this.pointSize),this._effect.setVector3("vEyePosition",s._mirroredCameraPosition?s._mirroredCameraPosition:s.activeCamera.position)),this._effect.setColor4("vDiffuseColor",this.diffuseColor,this.alpha*t.visibility),s.lightsEnabled&&!this.disableLighting&&e.MaterialHelper.BindLights(s,t,this._effect,this._defines),s.fogEnabled&&t.applyFog&&s.fogMode!==e.Scene.FOGMODE_NONE&&this._effect.setMatrix("view",s.getViewMatrix()),e.MaterialHelper.BindFogParameters(s,t,this._effect),n.prototype.bind.call(this,i,t)},t.prototype.getAnimatables=function(){var e=[];return this.diffuseTexture&&this.diffuseTexture.animations&&this.diffuseTexture.animations.length>0&&e.push(this.diffuseTexture),e},t.prototype.dispose=function(e){this.diffuseTexture&&this.diffuseTexture.dispose(),n.prototype.dispose.call(this,e)},t.prototype.clone=function(i){var n=this;return e.SerializationHelper.Clone(function(){return new t(i,n.getScene())},this)},t.prototype.serialize=function(){var i=e.SerializationHelper.Serialize(this);return i.customType="BABYLON.NormalMaterial",i},t.Parse=function(i,n,s){return e.SerializationHelper.Parse(function(){return new t(i.name,n)},i,n,s)},__decorate([e.serializeAsTexture()],t.prototype,"diffuseTexture"),__decorate([e.serializeAsColor3()],t.prototype,"diffuseColor"),__decorate([e.serialize()],t.prototype,"disableLighting"),t}(e.Material);e.NormalMaterial=n}(BABYLON||(BABYLON={})),BABYLON.Effect.ShadersStore.normalVertexShader="precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<shadowsVertexDeclaration>\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef DIFFUSE\nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n",BABYLON.Effect.ShadersStore.normalPixelShader="precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<lightFragmentDeclaration>[0]\n#include<lightFragmentDeclaration>[1]\n#include<lightFragmentDeclaration>[2]\n#include<lightFragmentDeclaration>[3]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef NORMAL\nbaseColor=mix(baseColor,vec4(vNormalW,1.0),0.5);\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#include<lightFragment>[0]\n#include<lightFragment>[1]\n#include<lightFragment>[2]\n#include<lightFragment>[3]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";
|