babylonjs-materials
Version:
Babylon.js Materials Library =====================
2 lines • 13.1 kB
JavaScript
!function(e,i){"object"==typeof exports&&"object"==typeof module?module.exports=i(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-materials",["babylonjs"],i):"object"==typeof exports?exports["babylonjs-materials"]=i(require("babylonjs")):e.MATERIALS=i(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(e=>(()=>{"use strict";var i={597:i=>{i.exports=e}},n={};function t(e){var o=n[e];if(void 0!==o)return o.exports;var r=n[e]={exports:{}};return i[e](r,r.exports,t),r.exports}t.d=(e,i)=>{for(var n in i)t.o(i,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:i[n]})},t.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),t.o=(e,i)=>Object.prototype.hasOwnProperty.call(e,i),t.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{t.d(o,{default:()=>c});var e={};t.r(e),t.d(e,{CellMaterial:()=>l});var i={};t.r(i),t.d(i,{CellMaterial:()=>l});var n=function(e,i){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,i){e.__proto__=i}||function(e,i){for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=i[n])},n(e,i)};function r(e,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function t(){this.constructor=e}n(e,i),e.prototype=null===i?Object.create(i):(t.prototype=i.prototype,new t)}function s(e,i,n,t){var o,r=arguments.length,s=r<3?i:null===t?t=Object.getOwnPropertyDescriptor(i,n):t;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,i,n,t);else for(var f=e.length-1;f>=0;f--)(o=e[f])&&(s=(r<3?o(s):r>3?o(i,n,s):o(i,n))||s);return r>3&&s&&Object.defineProperty(i,n,s),s}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var f=t(597);f.ShaderStore.ShadersStore.cellPixelShader="precision highp float;uniform vec4 vEyePosition;uniform vec4 vDiffuseColor;varying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<helperFunctions>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;uniform sampler2D diffuseSampler;uniform vec2 vDiffuseInfos;\n#endif\n#include<clipPlaneFragmentDeclaration>\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\n#include<logDepthDeclaration>\n#include<fogFragmentDeclaration>\nvec3 computeCustomDiffuseLighting(lightingInfo info,vec3 diffuseBase,float shadow)\n{diffuseBase=info.diffuse*shadow;\n#ifdef CELLBASIC\nfloat level=1.0;if (info.ndl<0.5)\nlevel=0.5;diffuseBase.rgb*vec3(level,level,level);\n#else\nfloat ToonThresholds[4];ToonThresholds[0]=0.95;ToonThresholds[1]=0.5;ToonThresholds[2]=0.2;ToonThresholds[3]=0.03;float ToonBrightnessLevels[5];ToonBrightnessLevels[0]=1.0;ToonBrightnessLevels[1]=0.8;ToonBrightnessLevels[2]=0.6;ToonBrightnessLevels[3]=0.35;ToonBrightnessLevels[4]=0.2;if (info.ndl>ToonThresholds[0])\n{diffuseBase.rgb*=ToonBrightnessLevels[0];}\nelse if (info.ndl>ToonThresholds[1])\n{diffuseBase.rgb*=ToonBrightnessLevels[1];}\nelse if (info.ndl>ToonThresholds[2])\n{diffuseBase.rgb*=ToonBrightnessLevels[2];}\nelse if (info.ndl>ToonThresholds[3])\n{diffuseBase.rgb*=ToonBrightnessLevels[3];}\nelse\n{diffuseBase.rgb*=ToonBrightnessLevels[4];}\n#endif\nreturn max(diffuseBase,vec3(0.2));}\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition.xyz-vPositionW);vec4 baseColor=vec4(1.,1.,1.,1.);vec3 diffuseColor=vDiffuseColor.rgb;float alpha=vDiffuseColor.a;\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\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\nlightingInfo info;vec3 diffuseBase=vec3(0.,0.,0.);float shadow=1.;float glossiness=0.;float aggShadow=0.;float numLights=0.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif \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}";f.ShaderStore.ShadersStore.cellVertexShader="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 DIFFUSE\nvarying vec2 vDiffuseUV;uniform mat4 diffuseMatrix;uniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\nvarying vec3 vPositionW;\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);\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#ifdef DIFFUSE\nif (vDiffuseInfos.x==0.)\n{vDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));}\nelse\n{vDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));}\n#endif\n#include<clipPlaneVertex>\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n#include<vertexColorMixing>\n#if defined(POINTSIZE) && !defined(WEBGPU)\ngl_PointSize=pointSize;\n#endif\n#include<logDepthVertex>\n#define CUSTOM_VERTEX_MAIN_END\n}\n";var a=function(e){function i(){var i=e.call(this)||this;return i.DIFFUSE=!1,i.CLIPPLANE=!1,i.CLIPPLANE2=!1,i.CLIPPLANE3=!1,i.CLIPPLANE4=!1,i.CLIPPLANE5=!1,i.CLIPPLANE6=!1,i.ALPHATEST=!1,i.POINTSIZE=!1,i.FOG=!1,i.NORMAL=!1,i.UV1=!1,i.UV2=!1,i.VERTEXCOLOR=!1,i.VERTEXALPHA=!1,i.NUM_BONE_INFLUENCERS=0,i.BonesPerMesh=0,i.INSTANCES=!1,i.INSTANCESCOLOR=!1,i.NDOTL=!0,i.CUSTOMUSERLIGHTING=!0,i.CELLBASIC=!0,i.DEPTHPREPASS=!1,i.IMAGEPROCESSINGPOSTPROCESS=!1,i.SKIPFINALCOLORCLAMP=!1,i.LOGARITHMICDEPTH=!1,i.rebuild(),i}return r(i,e),i}(f.MaterialDefines),l=function(e){function i(i,n){var t=e.call(this,i,n)||this;return t.diffuseColor=new f.Color3(1,1,1),t._computeHighLevel=!1,t._disableLighting=!1,t._maxSimultaneousLights=4,t}return r(i,e),i.prototype.needAlphaBlending=function(){return this.alpha<1},i.prototype.needAlphaTesting=function(){return!1},i.prototype.getAlphaTestTexture=function(){return null},i.prototype.isReadyForSubMesh=function(e,i,n){var t=i._drawWrapper;if(this.isFrozen&&t.effect&&t._wasPreviouslyReady&&t._wasPreviouslyUsingInstances===n)return!0;i.materialDefines||(i.materialDefines=new a);var o=i.materialDefines,r=this.getScene();if(this._isReadyForSubMesh(i))return!0;var s=r.getEngine();if(o._areTexturesDirty&&(o._needUVs=!1,r.texturesEnabled&&this._diffuseTexture&&f.MaterialFlags.DiffuseTextureEnabled)){if(!this._diffuseTexture.isReady())return!1;o._needUVs=!0,o.DIFFUSE=!0}if(o.CELLBASIC=!this.computeHighLevel,(0,f.PrepareDefinesForMisc)(e,r,this._useLogarithmicDepth,this.pointsCloud,this.fogEnabled,this._shouldTurnAlphaTestOn(e),o),o._needNormals=(0,f.PrepareDefinesForLights)(r,e,o,!1,this._maxSimultaneousLights,this._disableLighting),(0,f.PrepareDefinesForFrameBoundValues)(r,s,this,o,!!n),(0,f.PrepareDefinesForAttributes)(e,o,!0,!0),o.isDirty){o.markAsProcessed(),r.resetCachedMaterial();var l=new f.EffectFallbacks;o.FOG&&l.addFallback(1,"FOG"),(0,f.HandleFallbacksForShadows)(o,l,this.maxSimultaneousLights),o.NUM_BONE_INFLUENCERS>0&&l.addCPUSkinningFallback(0,e),o.IMAGEPROCESSINGPOSTPROCESS=r.imageProcessingConfiguration.applyByPostProcess;var u=[f.VertexBuffer.PositionKind];o.NORMAL&&u.push(f.VertexBuffer.NormalKind),o.UV1&&u.push(f.VertexBuffer.UVKind),o.UV2&&u.push(f.VertexBuffer.UV2Kind),o.VERTEXCOLOR&&u.push(f.VertexBuffer.ColorKind),(0,f.PrepareAttributesForBones)(u,e,o,l),(0,f.PrepareAttributesForInstances)(u,o);var d=o.toString(),c=["world","view","viewProjection","vEyePosition","vLightsType","vDiffuseColor","vFogInfos","vFogColor","pointSize","vDiffuseInfos","mBones","diffuseMatrix","logarithmicDepthConstant"],h=["diffuseSampler"],v=[];(0,f.addClipPlaneUniforms)(c),(0,f.PrepareUniformsAndSamplersList)({uniformsNames:c,uniformBuffersNames:v,samplers:h,defines:o,maxSimultaneousLights:this.maxSimultaneousLights}),i.setEffect(r.getEngine().createEffect("cell",{attributes:u,uniformsNames:c,uniformBuffersNames:v,samplers:h,defines:d,fallbacks:l,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{maxSimultaneousLights:this.maxSimultaneousLights-1}},s),o,this._materialContext)}return!(!i.effect||!i.effect.isReady()||(o._renderId=r.getRenderId(),t._wasPreviouslyReady=!0,t._wasPreviouslyUsingInstances=!!n,0))},i.prototype.bindForSubMesh=function(e,i,n){var t=this.getScene(),o=n.materialDefines;if(o){var r=n.effect;r&&(this._activeEffect=r,this.bindOnlyWorldMatrix(e),this._activeEffect.setMatrix("viewProjection",t.getTransformMatrix()),(0,f.BindBonesParameters)(i,this._activeEffect),this._mustRebind(t,r,n)&&(this._diffuseTexture&&f.MaterialFlags.DiffuseTextureEnabled&&(this._activeEffect.setTexture("diffuseSampler",this._diffuseTexture),this._activeEffect.setFloat2("vDiffuseInfos",this._diffuseTexture.coordinatesIndex,this._diffuseTexture.level),this._activeEffect.setMatrix("diffuseMatrix",this._diffuseTexture.getTextureMatrix())),(0,f.bindClipPlane)(this._activeEffect,this,t),this.pointsCloud&&this._activeEffect.setFloat("pointSize",this.pointSize),this._useLogarithmicDepth&&(0,f.BindLogDepth)(o,r,t),t.bindEyePosition(r)),this._activeEffect.setColor4("vDiffuseColor",this.diffuseColor,this.alpha*i.visibility),t.lightsEnabled&&!this.disableLighting&&(0,f.BindLights)(t,i,this._activeEffect,o,this._maxSimultaneousLights),t.fogEnabled&&i.applyFog&&t.fogMode!==f.Scene.FOGMODE_NONE&&this._activeEffect.setMatrix("view",t.getViewMatrix()),(0,f.BindFogParameters)(t,i,this._activeEffect),this._afterBind(i,this._activeEffect,n))}},i.prototype.getAnimatables=function(){var e=[];return this._diffuseTexture&&this._diffuseTexture.animations&&this._diffuseTexture.animations.length>0&&e.push(this._diffuseTexture),e},i.prototype.getActiveTextures=function(){var i=e.prototype.getActiveTextures.call(this);return this._diffuseTexture&&i.push(this._diffuseTexture),i},i.prototype.hasTexture=function(i){return!!e.prototype.hasTexture.call(this,i)||this._diffuseTexture===i},i.prototype.dispose=function(i){this._diffuseTexture&&this._diffuseTexture.dispose(),e.prototype.dispose.call(this,i)},i.prototype.getClassName=function(){return"CellMaterial"},i.prototype.clone=function(e){var n=this;return f.SerializationHelper.Clone((function(){return new i(e,n.getScene())}),this)},i.prototype.serialize=function(){var i=e.prototype.serialize.call(this);return i.customType="BABYLON.CellMaterial",i},i.Parse=function(e,n,t){return f.SerializationHelper.Parse((function(){return new i(e.name,n)}),e,n,t)},s([(0,f.serializeAsTexture)("diffuseTexture")],i.prototype,"_diffuseTexture",void 0),s([(0,f.expandToProperty)("_markAllSubMeshesAsTexturesDirty")],i.prototype,"diffuseTexture",void 0),s([(0,f.serializeAsColor3)("diffuse")],i.prototype,"diffuseColor",void 0),s([(0,f.serialize)("computeHighLevel")],i.prototype,"_computeHighLevel",void 0),s([(0,f.expandToProperty)("_markAllSubMeshesAsTexturesDirty")],i.prototype,"computeHighLevel",void 0),s([(0,f.serialize)("disableLighting")],i.prototype,"_disableLighting",void 0),s([(0,f.expandToProperty)("_markAllSubMeshesAsLightsDirty")],i.prototype,"disableLighting",void 0),s([(0,f.serialize)("maxSimultaneousLights")],i.prototype,"_maxSimultaneousLights",void 0),s([(0,f.expandToProperty)("_markAllSubMeshesAsLightsDirty")],i.prototype,"maxSimultaneousLights",void 0),i}(f.PushMaterial);(0,f.RegisterClass)("BABYLON.CellMaterial",l);var u=void 0!==t.g?t.g:"undefined"!=typeof window?window:void 0;if(void 0!==u)for(var d in e)u.BABYLON[d]=e[d];const c=i})(),o.default})()));
//# sourceMappingURL=babylon.cellMaterial.min.js.map