babylon.gradientMaterial.min.js 12 KB

12345678910111213141516
  1. !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-materials",["babylonjs"],t):"object"==typeof exports?exports["babylonjs-materials"]=t(require("babylonjs")):e.MATERIALS=t(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(function(e){return function(e){var t={};function n(i){if(t[i])return t[i].exports;var o=t[i]={i:i,l:!1,exports:{}};return e[i].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(i,o,function(t){return e[t]}.bind(null,o));return i},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=24)}({0:function(t,n){t.exports=e},1:function(e,t,n){"use strict";n.d(t,"b",(function(){return o})),n.d(t,"a",(function(){return r}));
  2. /*! *****************************************************************************
  3. Copyright (c) Microsoft Corporation.
  4. Permission to use, copy, modify, and/or distribute this software for any
  5. purpose with or without fee is hereby granted.
  6. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  7. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  8. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  9. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  10. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  11. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  12. PERFORMANCE OF THIS SOFTWARE.
  13. ***************************************************************************** */
  14. 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)};function o(e,t){function n(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}function r(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 l=e.length-1;l>=0;l--)(o=e[l])&&(a=(r<3?o(a):r>3?o(t,n,a):o(t,n))||a);return r>3&&a&&Object.defineProperty(t,n,a),a}Object.create;Object.create},2:function(e,t){var n;n=function(){return this}();try{n=n||new Function("return this")()}catch(e){"object"==typeof window&&(n=window)}e.exports=n},24:function(e,t,n){"use strict";n.r(t),function(e){var i=n(9);n.d(t,"GradientMaterial",(function(){return i.GradientMaterial}));var o=void 0!==e?e:"undefined"!=typeof window?window:void 0;if(void 0!==o)for(var r in i)o.BABYLON[r]=i[r]}.call(this,n(2))},9:function(e,t,n){"use strict";n.r(t),n.d(t,"GradientMaterial",(function(){return s}));var i=n(1),o=n(0),r="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";o.Effect.ShadersStore.gradientPixelShader=r;var a="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>\nvec4 worldPos=finalWorld*vec4(position,1.0);\ngl_Position=viewProjection*worldPos;\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";o.Effect.ShadersStore.gradientVertexShader=a;var l=function(e){function t(){var t=e.call(this)||this;return t.EMISSIVE=!1,t.CLIPPLANE=!1,t.CLIPPLANE2=!1,t.CLIPPLANE3=!1,t.CLIPPLANE4=!1,t.CLIPPLANE5=!1,t.CLIPPLANE6=!1,t.ALPHATEST=!1,t.DEPTHPREPASS=!1,t.POINTSIZE=!1,t.FOG=!1,t.NORMAL=!1,t.UV1=!1,t.UV2=!1,t.VERTEXCOLOR=!1,t.VERTEXALPHA=!1,t.NUM_BONE_INFLUENCERS=0,t.BonesPerMesh=0,t.INSTANCES=!1,t.rebuild(),t}return Object(i.b)(t,e),t}(o.MaterialDefines),s=function(e){function t(t,n){var i=e.call(this,t,n)||this;return i._maxSimultaneousLights=4,i.topColor=new o.Color3(1,0,0),i.topColorAlpha=1,i.bottomColor=new o.Color3(0,0,1),i.bottomColorAlpha=1,i.offset=0,i.scale=1,i.smoothness=1,i._disableLighting=!1,i}return Object(i.b)(t,e),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(e,t,n){if(this.isFrozen&&t.effect&&t.effect._wasPreviouslyReady)return!0;t._materialDefines||(t._materialDefines=new l);var i=t._materialDefines,r=this.getScene();if(this._isReadyForSubMesh(t))return!0;var a=r.getEngine();if(o.MaterialHelper.PrepareDefinesForFrameBoundValues(r,a,i,!!n),o.MaterialHelper.PrepareDefinesForMisc(e,r,!1,this.pointsCloud,this.fogEnabled,this._shouldTurnAlphaTestOn(e),i),i._needNormals=o.MaterialHelper.PrepareDefinesForLights(r,e,i,!1,this._maxSimultaneousLights,this._disableLighting),i.EMISSIVE=this._disableLighting,o.MaterialHelper.PrepareDefinesForAttributes(e,i,!1,!0),i.isDirty){i.markAsProcessed(),r.resetCachedMaterial();var s=new o.EffectFallbacks;i.FOG&&s.addFallback(1,"FOG"),o.MaterialHelper.HandleFallbacksForShadows(i,s),i.NUM_BONE_INFLUENCERS>0&&s.addCPUSkinningFallback(0,e);var f=[o.VertexBuffer.PositionKind];i.NORMAL&&f.push(o.VertexBuffer.NormalKind),i.UV1&&f.push(o.VertexBuffer.UVKind),i.UV2&&f.push(o.VertexBuffer.UV2Kind),i.VERTEXCOLOR&&f.push(o.VertexBuffer.ColorKind),o.MaterialHelper.PrepareAttributesForBones(f,e,i,s),o.MaterialHelper.PrepareAttributesForInstances(f,i);var c=i.toString(),u=["world","view","viewProjection","vEyePosition","vLightsType","vFogInfos","vFogColor","pointSize","mBones","vClipPlane","vClipPlane2","vClipPlane3","vClipPlane4","vClipPlane5","vClipPlane6","topColor","bottomColor","offset","smoothness","scale"],d=[],p=new Array;o.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:u,uniformBuffersNames:p,samplers:d,defines:i,maxSimultaneousLights:4}),t.setEffect(r.getEngine().createEffect("gradient",{attributes:f,uniformsNames:u,uniformBuffersNames:p,samplers:d,defines:c,fallbacks:s,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{maxSimultaneousLights:4}},a),i)}return!(!t.effect||!t.effect.isReady())&&(i._renderId=r.getRenderId(),t.effect._wasPreviouslyReady=!0,!0)},t.prototype.bindForSubMesh=function(e,t,n){var i=this.getScene(),r=n._materialDefines;if(r){var a=n.effect;a&&(this._activeEffect=a,this.bindOnlyWorldMatrix(e),this._activeEffect.setMatrix("viewProjection",i.getTransformMatrix()),o.MaterialHelper.BindBonesParameters(t,a),this._mustRebind(i,a)&&(o.MaterialHelper.BindClipPlane(a,i),this.pointsCloud&&this._activeEffect.setFloat("pointSize",this.pointSize),o.MaterialHelper.BindEyePosition(a,i)),i.lightsEnabled&&!this.disableLighting&&o.MaterialHelper.BindLights(i,t,this._activeEffect,r,this.maxSimultaneousLights),i.fogEnabled&&t.applyFog&&i.fogMode!==o.Scene.FOGMODE_NONE&&this._activeEffect.setMatrix("view",i.getViewMatrix()),o.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))}},t.prototype.getAnimatables=function(){return[]},t.prototype.dispose=function(t){e.prototype.dispose.call(this,t)},t.prototype.clone=function(e){var n=this;return o.SerializationHelper.Clone((function(){return new t(e,n.getScene())}),this)},t.prototype.serialize=function(){var e=o.SerializationHelper.Serialize(this);return e.customType="BABYLON.GradientMaterial",e},t.prototype.getClassName=function(){return"GradientMaterial"},t.Parse=function(e,n,i){return o.SerializationHelper.Parse((function(){return new t(e.name,n)}),e,n,i)},Object(i.a)([Object(o.serialize)("maxSimultaneousLights")],t.prototype,"_maxSimultaneousLights",void 0),Object(i.a)([Object(o.expandToProperty)("_markAllSubMeshesAsLightsDirty")],t.prototype,"maxSimultaneousLights",void 0),Object(i.a)([Object(o.serializeAsColor3)()],t.prototype,"topColor",void 0),Object(i.a)([Object(o.serialize)()],t.prototype,"topColorAlpha",void 0),Object(i.a)([Object(o.serializeAsColor3)()],t.prototype,"bottomColor",void 0),Object(i.a)([Object(o.serialize)()],t.prototype,"bottomColorAlpha",void 0),Object(i.a)([Object(o.serialize)()],t.prototype,"offset",void 0),Object(i.a)([Object(o.serialize)()],t.prototype,"scale",void 0),Object(i.a)([Object(o.serialize)()],t.prototype,"smoothness",void 0),Object(i.a)([Object(o.serialize)("disableLighting")],t.prototype,"_disableLighting",void 0),Object(i.a)([Object(o.expandToProperty)("_markAllSubMeshesAsLightsDirty")],t.prototype,"disableLighting",void 0),t}(o.PushMaterial);o._TypeStore.RegisteredTypes["BABYLON.GradientMaterial"]=s}})}));