1 |
- var BABYLON,__extends=this&&this.__extends||(function(){var t=function(e,i){return(t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,i){e.__proto__=i}||function(e,i){for(var n in i)i.hasOwnProperty(n)&&(e[n]=i[n])})(e,i)};return function(e,i){function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}})(),__decorate=this&&this.__decorate||function(e,i,n,t){var r,o=arguments.length,s=o<3?i:null===t?t=Object.getOwnPropertyDescriptor(i,n):t;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,i,n,t);else for(var a=e.length-1;0<=a;a--)(r=e[a])&&(s=(o<3?r(s):3<o?r(i,n,s):r(i,n))||s);return 3<o&&s&&Object.defineProperty(i,n,s),s};!(function(c){var h=(function(i){function e(){var e=i.call(this)||this;return e.DIFFUSE=!1,e.CLIPPLANE=!1,e.CLIPPLANE2=!1,e.CLIPPLANE3=!1,e.CLIPPLANE4=!1,e.ALPHATEST=!1,e.POINTSIZE=!1,e.FOG=!1,e.NORMAL=!1,e.UV1=!1,e.UV2=!1,e.VERTEXCOLOR=!1,e.VERTEXALPHA=!1,e.NUM_BONE_INFLUENCERS=0,e.BonesPerMesh=0,e.INSTANCES=!1,e.NDOTL=!0,e.CUSTOMUSERLIGHTING=!0,e.CELLBASIC=!0,e.DEPTHPREPASS=!1,e.rebuild(),e}return __extends(e,i),e})(c.MaterialDefines),e=(function(t){function r(e,i){var n=t.call(this,e,i)||this;return n.diffuseColor=new c.Color3(1,1,1),n._computeHighLevel=!1,n._disableLighting=!1,n._maxSimultaneousLights=4,n}return __extends(r,t),r.prototype.needAlphaBlending=function(){return this.alpha<1},r.prototype.needAlphaTesting=function(){return!1},r.prototype.getAlphaTestTexture=function(){return null},r.prototype.isReadyForSubMesh=function(e,i,n){if(this.isFrozen&&this._wasPreviouslyReady&&i.effect)return!0;i._materialDefines||(i._materialDefines=new h);var t=i._materialDefines,r=this.getScene();if(!this.checkReadyOnEveryCall&&i.effect&&this._renderId===r.getRenderId())return!0;var o=r.getEngine();if(t._areTexturesDirty&&(t._needUVs=!1,r.texturesEnabled&&this._diffuseTexture&&c.StandardMaterial.DiffuseTextureEnabled)){if(!this._diffuseTexture.isReady())return!1;t._needUVs=!0,t.DIFFUSE=!0}if(t.CELLBASIC=!this.computeHighLevel,c.MaterialHelper.PrepareDefinesForMisc(e,r,!1,this.pointsCloud,this.fogEnabled,this._shouldTurnAlphaTestOn(e),t),t._needNormals=c.MaterialHelper.PrepareDefinesForLights(r,e,t,!1,this._maxSimultaneousLights,this._disableLighting),c.MaterialHelper.PrepareDefinesForFrameBoundValues(r,o,t,!!n),c.MaterialHelper.PrepareDefinesForAttributes(e,t,!0,!0),t.isDirty){t.markAsProcessed(),r.resetCachedMaterial();var s=new c.EffectFallbacks;t.FOG&&s.addFallback(1,"FOG"),c.MaterialHelper.HandleFallbacksForShadows(t,s,this.maxSimultaneousLights),0<t.NUM_BONE_INFLUENCERS&&s.addCPUSkinningFallback(0,e);var a=[c.VertexBuffer.PositionKind];t.NORMAL&&a.push(c.VertexBuffer.NormalKind),t.UV1&&a.push(c.VertexBuffer.UVKind),t.UV2&&a.push(c.VertexBuffer.UV2Kind),t.VERTEXCOLOR&&a.push(c.VertexBuffer.ColorKind),c.MaterialHelper.PrepareAttributesForBones(a,e,t,s),c.MaterialHelper.PrepareAttributesForInstances(a,t);var f=t.toString(),l=["world","view","viewProjection","vEyePosition","vLightsType","vDiffuseColor","vFogInfos","vFogColor","pointSize","vDiffuseInfos","mBones","vClipPlane","vClipPlane2","vClipPlane3","vClipPlane4","diffuseMatrix"],u=["diffuseSampler"],d=new Array;c.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:l,uniformBuffersNames:d,samplers:u,defines:t,maxSimultaneousLights:this.maxSimultaneousLights}),i.setEffect(r.getEngine().createEffect("cell",{attributes:a,uniformsNames:l,uniformBuffersNames:d,samplers:u,defines:f,fallbacks:s,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{maxSimultaneousLights:this.maxSimultaneousLights-1}},o),t)}return!(!i.effect||!i.effect.isReady())&&(this._renderId=r.getRenderId(),this._wasPreviouslyReady=!0)},r.prototype.bindForSubMesh=function(e,i,n){var t=this.getScene(),r=n._materialDefines;if(r){var o=n.effect;o&&(this._activeEffect=o,this.bindOnlyWorldMatrix(e),this._activeEffect.setMatrix("viewProjection",t.getTransformMatrix()),c.MaterialHelper.BindBonesParameters(i,this._activeEffect),this._mustRebind(t,o)&&(this._diffuseTexture&&c.StandardMaterial.DiffuseTextureEnabled&&(this._activeEffect.setTexture("diffuseSampler",this._diffuseTexture),this._activeEffect.setFloat2("vDiffuseInfos",this._diffuseTexture.coordinatesIndex,this._diffuseTexture.level),this._activeEffect.setMatrix("diffuseMatrix",this._diffuseTexture.getTextureMatrix())),c.MaterialHelper.BindClipPlane(this._activeEffect,t),this.pointsCloud&&this._activeEffect.setFloat("pointSize",this.pointSize),c.MaterialHelper.BindEyePosition(o,t)),this._activeEffect.setColor4("vDiffuseColor",this.diffuseColor,this.alpha*i.visibility),t.lightsEnabled&&!this.disableLighting&&c.MaterialHelper.BindLights(t,i,this._activeEffect,r,this._maxSimultaneousLights),t.fogEnabled&&i.applyFog&&t.fogMode!==c.Scene.FOGMODE_NONE&&this._activeEffect.setMatrix("view",t.getViewMatrix()),c.MaterialHelper.BindFogParameters(t,i,this._activeEffect),this._afterBind(i,this._activeEffect))}},r.prototype.getAnimatables=function(){var e=[];return this._diffuseTexture&&this._diffuseTexture.animations&&0<this._diffuseTexture.animations.length&&e.push(this._diffuseTexture),e},r.prototype.getActiveTextures=function(){var e=t.prototype.getActiveTextures.call(this);return this._diffuseTexture&&e.push(this._diffuseTexture),e},r.prototype.hasTexture=function(e){return!!t.prototype.hasTexture.call(this,e)||this._diffuseTexture===e},r.prototype.dispose=function(e){this._diffuseTexture&&this._diffuseTexture.dispose(),t.prototype.dispose.call(this,e)},r.prototype.getClassName=function(){return"CellMaterial"},r.prototype.clone=function(e){var i=this;return c.SerializationHelper.Clone((function(){return new r(e,i.getScene())}),this)},r.prototype.serialize=function(){var e=c.SerializationHelper.Serialize(this);return e.customType="BABYLON.CellMaterial",e},r.Parse=function(e,i,n){return c.SerializationHelper.Parse((function(){return new r(e.name,i)}),e,i,n)},__decorate([c.serializeAsTexture("diffuseTexture")],r.prototype,"_diffuseTexture",void 0),__decorate([c.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"diffuseTexture",void 0),__decorate([c.serializeAsColor3("diffuse")],r.prototype,"diffuseColor",void 0),__decorate([c.serialize("computeHighLevel")],r.prototype,"_computeHighLevel",void 0),__decorate([c.expandToProperty("_markAllSubMeshesAsTexturesDirty")],r.prototype,"computeHighLevel",void 0),__decorate([c.serialize("disableLighting")],r.prototype,"_disableLighting",void 0),__decorate([c.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"disableLighting",void 0),__decorate([c.serialize("maxSimultaneousLights")],r.prototype,"_maxSimultaneousLights",void 0),__decorate([c.expandToProperty("_markAllSubMeshesAsLightsDirty")],r.prototype,"maxSimultaneousLights",void 0),r})(c.PushMaterial);c.CellMaterial=e})(BABYLON||(BABYLON={})),BABYLON.Effect.ShadersStore.cellVertexShader="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<__decl__lightFragment>[0..maxSimultaneousLights]\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>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n",BABYLON.Effect.ShadersStore.cellPixelShader="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<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\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>\n\nvec3 computeCustomDiffuseLighting(lightingInfo info,vec3 diffuseBase,float shadow)\n{\ndiffuseBase=info.diffuse*shadow;\n#ifdef CELLBASIC\nfloat level=1.0;\nif (info.ndl<0.5)\nlevel=0.5;\ndiffuseBase.rgb*vec3(level,level,level);\n#else\nfloat ToonThresholds[4];\nToonThresholds[0]=0.95;\nToonThresholds[1]=0.5;\nToonThresholds[2]=0.2;\nToonThresholds[3]=0.03;\nfloat ToonBrightnessLevels[5];\nToonBrightnessLevels[0]=1.0;\nToonBrightnessLevels[1]=0.8;\nToonBrightnessLevels[2]=0.6;\nToonBrightnessLevels[3]=0.35;\nToonBrightnessLevels[4]=0.2;\nif (info.ndl>ToonThresholds[0])\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[0];\n}\nelse if (info.ndl>ToonThresholds[1])\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[1];\n}\nelse if (info.ndl>ToonThresholds[2])\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[2];\n}\nelse if (info.ndl>ToonThresholds[3])\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[3];\n}\nelse\n{\ndiffuseBase.rgb*=ToonBrightnessLevels[4];\n}\n#endif\nreturn max(diffuseBase,vec3(0.2));\n}\nvoid main(void)\n{\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\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\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\nlightingInfo info;\nvec3 diffuseBase=vec3(0.,0.,0.);\nfloat shadow=1.;\nfloat glossiness=0.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif \n#include<lightFragment>[0..maxSimultaneousLights]\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}";
|