babylon.gradientMaterial.min.js 9.9 KB

1
  1. var BABYLON,__extends=this&&this.__extends||(function(){var t=function(e,n){return(t=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])})(e,n)};return function(e,n){function i(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(i.prototype=n.prototype,new i)}})(),__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;0<=s;s--)(o=e[s])&&(a=(r<3?o(a):3<r?o(n,i,a):o(n,i))||a);return 3<r&&a&&Object.defineProperty(n,i,a),a};!(function(u){var p=(function(n){function e(){var e=n.call(this)||this;return e.DIFFUSE=!1,e.CLIPPLANE=!1,e.CLIPPLANE2=!1,e.CLIPPLANE3=!1,e.CLIPPLANE4=!1,e.ALPHATEST=!1,e.DEPTHPREPASS=!1,e.POINTSIZE=!1,e.FOG=!1,e.LIGHT0=!1,e.LIGHT1=!1,e.LIGHT2=!1,e.LIGHT3=!1,e.SPOTLIGHT0=!1,e.SPOTLIGHT1=!1,e.SPOTLIGHT2=!1,e.SPOTLIGHT3=!1,e.HEMILIGHT0=!1,e.HEMILIGHT1=!1,e.HEMILIGHT2=!1,e.HEMILIGHT3=!1,e.DIRLIGHT0=!1,e.DIRLIGHT1=!1,e.DIRLIGHT2=!1,e.DIRLIGHT3=!1,e.POINTLIGHT0=!1,e.POINTLIGHT1=!1,e.POINTLIGHT2=!1,e.POINTLIGHT3=!1,e.SHADOW0=!1,e.SHADOW1=!1,e.SHADOW2=!1,e.SHADOW3=!1,e.SHADOWS=!1,e.SHADOWESM0=!1,e.SHADOWESM1=!1,e.SHADOWESM2=!1,e.SHADOWESM3=!1,e.SHADOWPOISSON0=!1,e.SHADOWPOISSON1=!1,e.SHADOWPOISSON2=!1,e.SHADOWPOISSON3=!1,e.SHADOWPCF0=!1,e.SHADOWPCF1=!1,e.SHADOWPCF2=!1,e.SHADOWPCF3=!1,e.SHADOWPCSS0=!1,e.SHADOWPCSS1=!1,e.SHADOWPCSS2=!1,e.SHADOWPCSS3=!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.rebuild(),e}return __extends(e,n),e})(u.MaterialDefines),e=(function(t){function o(e,n){var i=t.call(this,e,n)||this;return i._maxSimultaneousLights=4,i.topColor=new u.Color3(1,0,0),i.topColorAlpha=1,i.bottomColor=new u.Color3(0,0,1),i.bottomColorAlpha=1,i.offset=0,i.scale=1,i.smoothness=1,i.disableLighting=!1,i._scaledDiffuse=new u.Color3,i}return __extends(o,t),o.prototype.needAlphaBlending=function(){return this.alpha<1||this.topColorAlpha<1||this.bottomColorAlpha<1},o.prototype.needAlphaTesting=function(){return!0},o.prototype.getAlphaTestTexture=function(){return null},o.prototype.isReadyForSubMesh=function(e,n,i){if(this.isFrozen&&this._wasPreviouslyReady&&n.effect)return!0;n._materialDefines||(n._materialDefines=new p);var t=n._materialDefines,o=this.getScene();if(!this.checkReadyOnEveryCall&&n.effect&&this._renderId===o.getRenderId())return!0;var r=o.getEngine();if(u.MaterialHelper.PrepareDefinesForFrameBoundValues(o,r,t,!!i),u.MaterialHelper.PrepareDefinesForMisc(e,o,!1,this.pointsCloud,this.fogEnabled,this._shouldTurnAlphaTestOn(e),t),t._needNormals=u.MaterialHelper.PrepareDefinesForLights(o,e,t,!1,this._maxSimultaneousLights),u.MaterialHelper.PrepareDefinesForAttributes(e,t,!1,!0),t.isDirty){t.markAsProcessed(),o.resetCachedMaterial();var a=new u.EffectFallbacks;t.FOG&&a.addFallback(1,"FOG"),u.MaterialHelper.HandleFallbacksForShadows(t,a),0<t.NUM_BONE_INFLUENCERS&&a.addCPUSkinningFallback(0,e);var s=[u.VertexBuffer.PositionKind];t.NORMAL&&s.push(u.VertexBuffer.NormalKind),t.UV1&&s.push(u.VertexBuffer.UVKind),t.UV2&&s.push(u.VertexBuffer.UV2Kind),t.VERTEXCOLOR&&s.push(u.VertexBuffer.ColorKind),u.MaterialHelper.PrepareAttributesForBones(s,e,t,a),u.MaterialHelper.PrepareAttributesForInstances(s,t);var l=t.toString(),f=["world","view","viewProjection","vEyePosition","vLightsType","vDiffuseColor","vFogInfos","vFogColor","pointSize","vDiffuseInfos","mBones","vClipPlane","vClipPlane2","vClipPlane3","vClipPlane4","diffuseMatrix","topColor","bottomColor","offset","smoothness","scale"],c=["diffuseSampler"],d=new Array;u.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:f,uniformBuffersNames:d,samplers:c,defines:t,maxSimultaneousLights:4}),n.setEffect(o.getEngine().createEffect("gradient",{attributes:s,uniformsNames:f,uniformBuffersNames:d,samplers:c,defines:l,fallbacks:a,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{maxSimultaneousLights:4}},r),t)}return!(!n.effect||!n.effect.isReady())&&(this._renderId=o.getRenderId(),this._wasPreviouslyReady=!0)},o.prototype.bindForSubMesh=function(e,n,i){var t=this.getScene(),o=i._materialDefines;if(o){var r=i.effect;r&&(this._activeEffect=r,this.bindOnlyWorldMatrix(e),this._activeEffect.setMatrix("viewProjection",t.getTransformMatrix()),u.MaterialHelper.BindBonesParameters(n,r),this._mustRebind(t,r)&&(u.MaterialHelper.BindClipPlane(r,t),this.pointsCloud&&this._activeEffect.setFloat("pointSize",this.pointSize),u.MaterialHelper.BindEyePosition(r,t)),this._activeEffect.setColor4("vDiffuseColor",this._scaledDiffuse,this.alpha*n.visibility),t.lightsEnabled&&!this.disableLighting&&u.MaterialHelper.BindLights(t,n,this._activeEffect,o),t.fogEnabled&&n.applyFog&&t.fogMode!==u.Scene.FOGMODE_NONE&&this._activeEffect.setMatrix("view",t.getViewMatrix()),u.MaterialHelper.BindFogParameters(t,n,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("scale",this.scale),this._activeEffect.setFloat("smoothness",this.smoothness),this._afterBind(n,this._activeEffect))}},o.prototype.getAnimatables=function(){return[]},o.prototype.dispose=function(e){t.prototype.dispose.call(this,e)},o.prototype.clone=function(e){var n=this;return u.SerializationHelper.Clone((function(){return new o(e,n.getScene())}),this)},o.prototype.serialize=function(){var e=u.SerializationHelper.Serialize(this);return e.customType="BABYLON.GradientMaterial",e},o.prototype.getClassName=function(){return"GradientMaterial"},o.Parse=function(e,n,i){return u.SerializationHelper.Parse((function(){return new o(e.name,n)}),e,n,i)},__decorate([u.serialize("maxSimultaneousLights")],o.prototype,"_maxSimultaneousLights",void 0),__decorate([u.expandToProperty("_markAllSubMeshesAsLightsDirty")],o.prototype,"maxSimultaneousLights",void 0),__decorate([u.serializeAsColor3()],o.prototype,"topColor",void 0),__decorate([u.serialize()],o.prototype,"topColorAlpha",void 0),__decorate([u.serializeAsColor3()],o.prototype,"bottomColor",void 0),__decorate([u.serialize()],o.prototype,"bottomColorAlpha",void 0),__decorate([u.serialize()],o.prototype,"offset",void 0),__decorate([u.serialize()],o.prototype,"scale",void 0),__decorate([u.serialize()],o.prototype,"smoothness",void 0),__decorate([u.serialize()],o.prototype,"disableLighting",void 0),o})(u.PushMaterial);u.GradientMaterial=e})(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 scale;\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=vPosition.y*scale+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";