UNPKG

babylonjs-materials

Version:

Babylon.js Materials Library =====================

2 lines 11.2 kB
!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,(e=>(()=>{"use strict";var t={597:t=>{t.exports=e}},i={};function o(e){var n=i[e];if(void 0!==n)return n.exports;var r=i[e]={exports:{}};return t[e](r,r.exports,o),r.exports}o.d=(e,t)=>{for(var i in t)o.o(t,i)&&!o.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},o.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};return(()=>{o.d(n,{default:()=>u});var e={};o.r(e),o.d(e,{GradientMaterial:()=>f});var t={};o.r(t),o.d(t,{GradientMaterial:()=>f});var i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i])},i(e,t)};function r(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function o(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}function a(e,t,i,o){var n,r=arguments.length,a=r<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,o);else for(var s=e.length-1;s>=0;s--)(n=e[s])&&(a=(r<3?n(a):r>3?n(t,i,a):n(t,i))||a);return r>3&&a&&Object.defineProperty(t,i,a),a}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var s=o(597);s.ShaderStore.ShadersStore.gradientPixelShader="precision highp float;uniform vec4 vEyePosition;uniform vec4 topColor;uniform vec4 bottomColor;uniform float offset;uniform float scale;uniform float smoothness;varying vec3 vPositionW;varying vec3 vPosition;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<helperFunctions>\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#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\n#include<logDepthDeclaration>\n#include<fogFragmentDeclaration>\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition.xyz-vPositionW);float h=vPosition.y*scale+offset;float mysmoothness=clamp(smoothness,0.01,max(smoothness,10.));vec4 baseColor=mix(bottomColor,topColor,max(pow(max(h,0.0),mysmoothness),0.0));vec3 diffuseColor=baseColor.rgb;float 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#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n#ifdef EMISSIVE\nvec3 diffuseBase=baseColor.rgb;\n#else\nvec3 diffuseBase=vec3(0.,0.,0.);\n#endif\nlightingInfo info;float shadow=1.;float glossiness=0.;float aggShadow=0.;float numLights=0.;\n#include<lightFragment>[0..maxSimultaneousLights]\n#if defined(VERTEXALPHA) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;vec4 color=vec4(finalDiffuse,alpha);\n#include<logDepthFragment>\n#include<fogFragment>\ngl_FragColor=color;\n#include<imageProcessingCompatibility>\n#define CUSTOM_FRAGMENT_MAIN_END\n}\n";s.ShaderStore.ShadersStore.gradientVertexShader="precision highp float;attribute 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#include<bakedVertexAnimationDeclaration>\n#include<instancesDeclaration>\nuniform mat4 view;uniform mat4 viewProjection;\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\nvarying vec3 vPositionW;varying vec3 vPosition;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<logDepthDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#define CUSTOM_VERTEX_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_VERTEX_MAIN_BEGIN\n#include<instancesVertex>\n#include<bonesVertex>\n#include<bakedVertexAnimation>\nvec4 worldPos=finalWorld*vec4(position,1.0);gl_Position=viewProjection*worldPos;vPositionW=vec3(worldPos);vPosition=position;\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#include<clipPlaneVertex>\n#include<logDepthVertex>\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n#include<vertexColorMixing>\n#if defined(POINTSIZE) && !defined(WEBGPU)\ngl_PointSize=pointSize;\n#endif\n#define CUSTOM_VERTEX_MAIN_END\n}\n";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.INSTANCESCOLOR=!1,t.IMAGEPROCESSINGPOSTPROCESS=!1,t.SKIPFINALCOLORCLAMP=!1,t.LOGARITHMICDEPTH=!1,t.rebuild(),t}return r(t,e),t}(s.MaterialDefines),f=function(e){function t(t,i){var o=e.call(this,t,i)||this;return o._maxSimultaneousLights=4,o.topColor=new s.Color3(1,0,0),o.topColorAlpha=1,o.bottomColor=new s.Color3(0,0,1),o.bottomColorAlpha=1,o.offset=0,o.scale=1,o.smoothness=1,o._disableLighting=!1,o}return r(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,i){var o=t._drawWrapper;if(this.isFrozen&&o.effect&&o._wasPreviouslyReady&&o._wasPreviouslyUsingInstances===i)return!0;t.materialDefines||(t.materialDefines=new l);var n=t.materialDefines,r=this.getScene();if(this._isReadyForSubMesh(t))return!0;var a=r.getEngine();if((0,s.PrepareDefinesForFrameBoundValues)(r,a,this,n,!!i),(0,s.PrepareDefinesForMisc)(e,r,this._useLogarithmicDepth,this.pointsCloud,this.fogEnabled,this._shouldTurnAlphaTestOn(e),n),n._needNormals=(0,s.PrepareDefinesForLights)(r,e,n,!1,this._maxSimultaneousLights,this._disableLighting),n.EMISSIVE=this._disableLighting,(0,s.PrepareDefinesForAttributes)(e,n,!1,!0),n.isDirty){n.markAsProcessed(),r.resetCachedMaterial();var f=new s.EffectFallbacks;n.FOG&&f.addFallback(1,"FOG"),(0,s.HandleFallbacksForShadows)(n,f),n.NUM_BONE_INFLUENCERS>0&&f.addCPUSkinningFallback(0,e),n.IMAGEPROCESSINGPOSTPROCESS=r.imageProcessingConfiguration.applyByPostProcess;var d=[s.VertexBuffer.PositionKind];n.NORMAL&&d.push(s.VertexBuffer.NormalKind),n.UV1&&d.push(s.VertexBuffer.UVKind),n.UV2&&d.push(s.VertexBuffer.UV2Kind),n.VERTEXCOLOR&&d.push(s.VertexBuffer.ColorKind),(0,s.PrepareAttributesForBones)(d,e,n,f),(0,s.PrepareAttributesForInstances)(d,n);var c=n.toString(),u=["world","view","viewProjection","vEyePosition","vLightsType","vFogInfos","vFogColor","pointSize","mBones","logarithmicDepthConstant","topColor","bottomColor","offset","smoothness","scale"];(0,s.addClipPlaneUniforms)(u);var p=[],h=[];(0,s.PrepareUniformsAndSamplersList)({uniformsNames:u,uniformBuffersNames:h,samplers:p,defines:n,maxSimultaneousLights:4}),t.setEffect(r.getEngine().createEffect("gradient",{attributes:d,uniformsNames:u,uniformBuffersNames:h,samplers:p,defines:c,fallbacks:f,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{maxSimultaneousLights:4}},a),n,this._materialContext)}return!(!t.effect||!t.effect.isReady()||(n._renderId=r.getRenderId(),o._wasPreviouslyReady=!0,o._wasPreviouslyUsingInstances=!!i,0))},t.prototype.bindForSubMesh=function(e,t,i){var o=this.getScene(),n=i.materialDefines;if(n){var r=i.effect;r&&(this._activeEffect=r,this.bindOnlyWorldMatrix(e),this._activeEffect.setMatrix("viewProjection",o.getTransformMatrix()),(0,s.BindBonesParameters)(t,r),this._mustRebind(o,r,i)&&((0,s.bindClipPlane)(r,this,o),this.pointsCloud&&this._activeEffect.setFloat("pointSize",this.pointSize),this._useLogarithmicDepth&&(0,s.BindLogDepth)(n,r,o),o.bindEyePosition(r)),o.lightsEnabled&&!this.disableLighting&&(0,s.BindLights)(o,t,this._activeEffect,n,this.maxSimultaneousLights),o.fogEnabled&&t.applyFog&&o.fogMode!==s.Scene.FOGMODE_NONE&&this._activeEffect.setMatrix("view",o.getViewMatrix()),(0,s.BindFogParameters)(o,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,i))}},t.prototype.getAnimatables=function(){return[]},t.prototype.dispose=function(t){e.prototype.dispose.call(this,t)},t.prototype.clone=function(e){var i=this;return s.SerializationHelper.Clone((function(){return new t(e,i.getScene())}),this)},t.prototype.serialize=function(){var t=e.prototype.serialize.call(this);return t.customType="BABYLON.GradientMaterial",t},t.prototype.getClassName=function(){return"GradientMaterial"},t.Parse=function(e,i,o){return s.SerializationHelper.Parse((function(){return new t(e.name,i)}),e,i,o)},a([(0,s.serialize)("maxSimultaneousLights")],t.prototype,"_maxSimultaneousLights",void 0),a([(0,s.expandToProperty)("_markAllSubMeshesAsLightsDirty")],t.prototype,"maxSimultaneousLights",void 0),a([(0,s.serializeAsColor3)()],t.prototype,"topColor",void 0),a([(0,s.serialize)()],t.prototype,"topColorAlpha",void 0),a([(0,s.serializeAsColor3)()],t.prototype,"bottomColor",void 0),a([(0,s.serialize)()],t.prototype,"bottomColorAlpha",void 0),a([(0,s.serialize)()],t.prototype,"offset",void 0),a([(0,s.serialize)()],t.prototype,"scale",void 0),a([(0,s.serialize)()],t.prototype,"smoothness",void 0),a([(0,s.serialize)("disableLighting")],t.prototype,"_disableLighting",void 0),a([(0,s.expandToProperty)("_markAllSubMeshesAsLightsDirty")],t.prototype,"disableLighting",void 0),t}(s.PushMaterial);(0,s.RegisterClass)("BABYLON.GradientMaterial",f);var d=void 0!==o.g?o.g:"undefined"!=typeof window?window:void 0;if(void 0!==d)for(var c in e)d.BABYLON[c]=e[c];const u=t})(),n.default})())); //# sourceMappingURL=babylon.gradientMaterial.min.js.map