babylon.gradientMaterial.min.js 8.9 KB

1
  1. var BABYLON,__extends=this&&this.__extends||(function(){var i=function(e,t){return(i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};return function(e,t){function n(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}})(),__decorate=this&&this.__decorate||function(e,t,n,i){var o,r=arguments.length,a=r<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var s=e.length-1;0<=s;s--)(o=e[s])&&(a=(r<3?o(a):3<r?o(t,n,a):o(t,n))||a);return 3<r&&a&&Object.defineProperty(t,n,a),a};!(function(u){var p=(function(t){function e(){var e=t.call(this)||this;return e.EMISSIVE=!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.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,t),e})(u.MaterialDefines),e=(function(i){function o(e,t){var n=i.call(this,e,t)||this;return n._maxSimultaneousLights=4,n.topColor=new u.Color3(1,0,0),n.topColorAlpha=1,n.bottomColor=new u.Color3(0,0,1),n.bottomColorAlpha=1,n.offset=0,n.scale=1,n.smoothness=1,n._disableLighting=!1,n}return __extends(o,i),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,t,n){if(this.isFrozen&&this._wasPreviouslyReady&&t.effect)return!0;t._materialDefines||(t._materialDefines=new p);var i=t._materialDefines,o=this.getScene();if(!this.checkReadyOnEveryCall&&t.effect&&this._renderId===o.getRenderId())return!0;var r=o.getEngine();if(u.MaterialHelper.PrepareDefinesForFrameBoundValues(o,r,i,!!n),u.MaterialHelper.PrepareDefinesForMisc(e,o,!1,this.pointsCloud,this.fogEnabled,this._shouldTurnAlphaTestOn(e),i),i._needNormals=u.MaterialHelper.PrepareDefinesForLights(o,e,i,!1,this._maxSimultaneousLights,this._disableLighting),i.EMISSIVE=this._disableLighting,u.MaterialHelper.PrepareDefinesForAttributes(e,i,!1,!0),i.isDirty){i.markAsProcessed(),o.resetCachedMaterial();var a=new u.EffectFallbacks;i.FOG&&a.addFallback(1,"FOG"),u.MaterialHelper.HandleFallbacksForShadows(i,a),0<i.NUM_BONE_INFLUENCERS&&a.addCPUSkinningFallback(0,e);var s=[u.VertexBuffer.PositionKind];i.NORMAL&&s.push(u.VertexBuffer.NormalKind),i.UV1&&s.push(u.VertexBuffer.UVKind),i.UV2&&s.push(u.VertexBuffer.UV2Kind),i.VERTEXCOLOR&&s.push(u.VertexBuffer.ColorKind),u.MaterialHelper.PrepareAttributesForBones(s,e,i,a),u.MaterialHelper.PrepareAttributesForInstances(s,i);var l=i.toString(),f=["world","view","viewProjection","vEyePosition","vLightsType","vFogInfos","vFogColor","pointSize","mBones","vClipPlane","vClipPlane2","vClipPlane3","vClipPlane4","topColor","bottomColor","offset","smoothness","scale"],c=[],d=new Array;u.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:f,uniformBuffersNames:d,samplers:c,defines:i,maxSimultaneousLights:4}),t.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),i)}return!(!t.effect||!t.effect.isReady())&&(this._renderId=o.getRenderId(),this._wasPreviouslyReady=!0)},o.prototype.bindForSubMesh=function(e,t,n){var i=this.getScene(),o=n._materialDefines;if(o){var r=n.effect;r&&(this._activeEffect=r,this.bindOnlyWorldMatrix(e),this._activeEffect.setMatrix("viewProjection",i.getTransformMatrix()),u.MaterialHelper.BindBonesParameters(t,r),this._mustRebind(i,r)&&(u.MaterialHelper.BindClipPlane(r,i),this.pointsCloud&&this._activeEffect.setFloat("pointSize",this.pointSize),u.MaterialHelper.BindEyePosition(r,i)),i.lightsEnabled&&!this.disableLighting&&u.MaterialHelper.BindLights(i,t,this._activeEffect,o,this.maxSimultaneousLights),i.fogEnabled&&t.applyFog&&i.fogMode!==u.Scene.FOGMODE_NONE&&this._activeEffect.setMatrix("view",i.getViewMatrix()),u.MaterialHelper.BindFogParameters(i,t,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(t,this._activeEffect))}},o.prototype.getAnimatables=function(){return[]},o.prototype.dispose=function(e){i.prototype.dispose.call(this,e)},o.prototype.clone=function(e){var t=this;return u.SerializationHelper.Clone((function(){return new o(e,t.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,t,n){return u.SerializationHelper.Parse((function(){return new o(e.name,t)}),e,t,n)},__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("disableLighting")],o.prototype,"_disableLighting",void 0),__decorate([u.expandToProperty("_markAllSubMeshesAsLightsDirty")],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 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\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;\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#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\n#ifdef EMISSIVE\nvec3 diffuseBase=baseColor.rgb;\n#else\nvec3 diffuseBase=vec3(0.,0.,0.);\n#endif\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\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}\n";