babylon.gradientMaterial.min.js 9.7 KB

1
  1. var __extends=this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var i in n)n.hasOwnProperty(i)&&(e[i]=n[i])};return function(n,i){function t(){this.constructor=n}e(n,i),n.prototype=null===i?Object.create(i):(t.prototype=i.prototype,new t)}})(),__decorate=this&&this.__decorate||function(e,n,i,t){var o,r=arguments.length,a=r<3?n:null===t?t=Object.getOwnPropertyDescriptor(n,i):t;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,n,i,t);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(r<3?o(a):r>3?o(n,i,a):o(n,i))||a);return r>3&&a&&Object.defineProperty(n,i,a),a},BABYLON;!(function(e){var n=(function(e){function n(){var n=e.call(this)||this;return n.DIFFUSE=!1,n.CLIPPLANE=!1,n.ALPHATEST=!1,n.DEPTHPREPASS=!1,n.POINTSIZE=!1,n.FOG=!1,n.LIGHT0=!1,n.LIGHT1=!1,n.LIGHT2=!1,n.LIGHT3=!1,n.SPOTLIGHT0=!1,n.SPOTLIGHT1=!1,n.SPOTLIGHT2=!1,n.SPOTLIGHT3=!1,n.HEMILIGHT0=!1,n.HEMILIGHT1=!1,n.HEMILIGHT2=!1,n.HEMILIGHT3=!1,n.DIRLIGHT0=!1,n.DIRLIGHT1=!1,n.DIRLIGHT2=!1,n.DIRLIGHT3=!1,n.POINTLIGHT0=!1,n.POINTLIGHT1=!1,n.POINTLIGHT2=!1,n.POINTLIGHT3=!1,n.SHADOW0=!1,n.SHADOW1=!1,n.SHADOW2=!1,n.SHADOW3=!1,n.SHADOWS=!1,n.SHADOWESM0=!1,n.SHADOWESM1=!1,n.SHADOWESM2=!1,n.SHADOWESM3=!1,n.SHADOWPOISSON0=!1,n.SHADOWPOISSON1=!1,n.SHADOWPOISSON2=!1,n.SHADOWPOISSON3=!1,n.SHADOWPCF0=!1,n.SHADOWPCF1=!1,n.SHADOWPCF2=!1,n.SHADOWPCF3=!1,n.SHADOWPCSS0=!1,n.SHADOWPCSS1=!1,n.SHADOWPCSS2=!1,n.SHADOWPCSS3=!1,n.NORMAL=!1,n.UV1=!1,n.UV2=!1,n.VERTEXCOLOR=!1,n.VERTEXALPHA=!1,n.NUM_BONE_INFLUENCERS=0,n.BonesPerMesh=0,n.INSTANCES=!1,n.rebuild(),n}return __extends(n,e),n})(e.MaterialDefines),i=(function(i){function t(n,t){var o=i.call(this,n,t)||this;return o._maxSimultaneousLights=4,o.topColor=new e.Color3(1,0,0),o.topColorAlpha=1,o.bottomColor=new e.Color3(0,0,1),o.bottomColorAlpha=1,o.offset=0,o.smoothness=1,o.disableLighting=!1,o._scaledDiffuse=new e.Color3,o}return __extends(t,i),t.prototype.needAlphaBlending=function(){return this.alpha<1||this.topColorAlpha<1||this.bottomColorAlpha<1},t.prototype.needAlphaTesting=function(){return!0},t.prototype.getAlphaTestTexture=function(){return null},t.prototype.isReadyForSubMesh=function(i,t,o){if(this.isFrozen&&this._wasPreviouslyReady&&t.effect)return!0;t._materialDefines||(t._materialDefines=new n);var r=t._materialDefines,a=this.getScene();if(!this.checkReadyOnEveryCall&&t.effect&&this._renderId===a.getRenderId())return!0;var s=a.getEngine();if(e.MaterialHelper.PrepareDefinesForFrameBoundValues(a,s,r,!!o),e.MaterialHelper.PrepareDefinesForMisc(i,a,!1,this.pointsCloud,this.fogEnabled,this._shouldTurnAlphaTestOn(i),r),r._needNormals=e.MaterialHelper.PrepareDefinesForLights(a,i,r,!1,this._maxSimultaneousLights),e.MaterialHelper.PrepareDefinesForAttributes(i,r,!1,!0),r.isDirty){r.markAsProcessed(),a.resetCachedMaterial();var l=new e.EffectFallbacks;r.FOG&&l.addFallback(1,"FOG"),e.MaterialHelper.HandleFallbacksForShadows(r,l),r.NUM_BONE_INFLUENCERS>0&&l.addCPUSkinningFallback(0,i);var f=[e.VertexBuffer.PositionKind];r.NORMAL&&f.push(e.VertexBuffer.NormalKind),r.UV1&&f.push(e.VertexBuffer.UVKind),r.UV2&&f.push(e.VertexBuffer.UV2Kind),r.VERTEXCOLOR&&f.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(f,i,r,l),e.MaterialHelper.PrepareAttributesForInstances(f,r);var c=r.toString(),d=["world","view","viewProjection","vEyePosition","vLightsType","vDiffuseColor","vFogInfos","vFogColor","pointSize","vDiffuseInfos","mBones","vClipPlane","diffuseMatrix","topColor","bottomColor","offset","smoothness"],u=["diffuseSampler"],p=new Array;e.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:d,uniformBuffersNames:p,samplers:u,defines:r,maxSimultaneousLights:4}),t.setEffect(a.getEngine().createEffect("gradient",{attributes:f,uniformsNames:d,uniformBuffersNames:p,samplers:u,defines:c,fallbacks:l,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{maxSimultaneousLights:4}},s),r)}return!(!t.effect||!t.effect.isReady())&&(this._renderId=a.getRenderId(),this._wasPreviouslyReady=!0,!0)},t.prototype.bindForSubMesh=function(n,i,t){var o=this.getScene(),r=t._materialDefines;if(r){var a=t.effect;a&&(this._activeEffect=a,this.bindOnlyWorldMatrix(n),this._activeEffect.setMatrix("viewProjection",o.getTransformMatrix()),e.MaterialHelper.BindBonesParameters(i,a),this._mustRebind(o,a)&&(e.MaterialHelper.BindClipPlane(a,o),this.pointsCloud&&this._activeEffect.setFloat("pointSize",this.pointSize),e.MaterialHelper.BindEyePosition(a,o)),this._activeEffect.setColor4("vDiffuseColor",this._scaledDiffuse,this.alpha*i.visibility),o.lightsEnabled&&!this.disableLighting&&e.MaterialHelper.BindLights(o,i,this._activeEffect,r),o.fogEnabled&&i.applyFog&&o.fogMode!==e.Scene.FOGMODE_NONE&&this._activeEffect.setMatrix("view",o.getViewMatrix()),e.MaterialHelper.BindFogParameters(o,i,this._activeEffect),this._activeEffect.setColor4("topColor",this.topColor,this.topColorAlpha),this._activeEffect.setColor4("bottomColor",this.bottomColor,this.bottomColorAlpha),this._activeEffect.setFloat("offset",this.offset),this._activeEffect.setFloat("smoothness",this.smoothness),this._afterBind(i,this._activeEffect))}},t.prototype.getAnimatables=function(){return[]},t.prototype.dispose=function(e){i.prototype.dispose.call(this,e)},t.prototype.clone=function(n){var i=this;return e.SerializationHelper.Clone((function(){return new t(n,i.getScene())}),this)},t.prototype.serialize=function(){var n=e.SerializationHelper.Serialize(this);return n.customType="BABYLON.GradientMaterial",n},t.prototype.getClassName=function(){return"GradientMaterial"},t.Parse=function(n,i,o){return e.SerializationHelper.Parse((function(){return new t(n.name,i)}),n,i,o)},__decorate([e.serialize("maxSimultaneousLights")],t.prototype,"_maxSimultaneousLights",void 0),__decorate([e.expandToProperty("_markAllSubMeshesAsLightsDirty")],t.prototype,"maxSimultaneousLights",void 0),__decorate([e.serializeAsColor3()],t.prototype,"topColor",void 0),__decorate([e.serialize()],t.prototype,"topColorAlpha",void 0),__decorate([e.serializeAsColor3()],t.prototype,"bottomColor",void 0),__decorate([e.serialize()],t.prototype,"bottomColorAlpha",void 0),__decorate([e.serialize()],t.prototype,"offset",void 0),__decorate([e.serialize()],t.prototype,"smoothness",void 0),__decorate([e.serialize()],t.prototype,"disableLighting",void 0),t})(e.PushMaterial);e.GradientMaterial=i})(BABYLON||(BABYLON={})),BABYLON.Effect.ShadersStore.gradientVertexShader="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;\nvarying vec3 vPosition;\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);\nvPosition=position;\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.gradientPixelShader="precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nuniform vec4 topColor;\nuniform vec4 bottomColor;\nuniform float offset;\nuniform float smoothness;\n\nvarying vec3 vPositionW;\nvarying vec3 vPosition;\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]\n#include<__decl__lightFragment>[1]\n#include<__decl__lightFragment>[2]\n#include<__decl__lightFragment>[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);\nfloat h=normalize(vPosition).y+offset;\nfloat mysmoothness=clamp(smoothness,0.01,max(smoothness,10.));\nvec4 baseColor=mix(bottomColor,topColor,max(pow(max(h,0.0),mysmoothness),0.0));\n\nvec3 diffuseColor=baseColor.rgb;\n\nfloat alpha=baseColor.a;\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\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}\n";