babylonjs-materials
Version:
Babylon.js Materials Library =====================
2 lines • 27.3 kB
JavaScript
!function(e,r){"object"==typeof exports&&"object"==typeof module?module.exports=r(require("babylonjs")):"function"==typeof define&&define.amd?define("babylonjs-materials",["babylonjs"],r):"object"==typeof exports?exports["babylonjs-materials"]=r(require("babylonjs")):e.MATERIALS=r(e.BABYLON)}("undefined"!=typeof self?self:"undefined"!=typeof global?global:this,(e=>(()=>{"use strict";var r={597:r=>{r.exports=e}},t={};function i(e){var o=t[e];if(void 0!==o)return o.exports;var n=t[e]={exports:{}};return r[e](n,n.exports,i),n.exports}i.d=(e,r)=>{for(var t in r)i.o(r,t)&&!i.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},i.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),i.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),i.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{i.d(o,{default:()=>u});var e={};i.r(e),i.d(e,{WaterMaterial:()=>f});var r={};i.r(r),i.d(r,{WaterMaterial:()=>f});var t=function(e,r){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,r){e.__proto__=r}||function(e,r){for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(e[t]=r[t])},t(e,r)};function n(e,r){if("function"!=typeof r&&null!==r)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");function i(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(i.prototype=r.prototype,new i)}function a(e,r,t,i){var o,n=arguments.length,a=n<3?r:null===i?i=Object.getOwnPropertyDescriptor(r,t):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,r,t,i);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(n<3?o(a):n>3?o(r,t,a):o(r,t))||a);return n>3&&a&&Object.defineProperty(r,t,a),a}Object.create,Object.create,"function"==typeof SuppressedError&&SuppressedError;var s=i(597);s.ShaderStore.ShadersStore.waterPixelShader="#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nprecision highp float;uniform vec4 vEyePosition;uniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nvarying vec4 vColor;\n#endif\n#include<helperFunctions>\n#include<imageProcessingDeclaration>\n#include<imageProcessingFunctions>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#ifdef BUMP\nvarying vec2 vNormalUV;\n#ifdef BUMPSUPERIMPOSE\nvarying vec2 vNormalUV2;\n#endif\nuniform sampler2D normalSampler;uniform vec2 vNormalInfos;\n#endif\nuniform sampler2D refractionSampler;uniform sampler2D reflectionSampler;const float LOG2=1.442695;uniform vec3 cameraPosition;uniform vec4 waterColor;uniform float colorBlendFactor;uniform vec4 waterColor2;uniform float colorBlendFactor2;uniform float bumpHeight;uniform float time;varying vec3 vRefractionMapTexCoord;varying vec3 vReflectionMapTexCoord;\n#include<clipPlaneFragmentDeclaration>\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);vec4 baseColor=vec4(1.,1.,1.,1.);vec3 diffuseColor=vDiffuseColor.rgb;float alpha=vDiffuseColor.a;\n#ifdef BUMP\n#ifdef BUMPSUPERIMPOSE\nbaseColor=0.6*texture2D(normalSampler,vNormalUV)+0.4*texture2D(normalSampler,vec2(vNormalUV2.x,vNormalUV2.y));\n#else\nbaseColor=texture2D(normalSampler,vNormalUV);\n#endif\nvec3 bumpColor=baseColor.rgb;\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\nbaseColor.rgb*=vNormalInfos.y;\n#else\nvec3 bumpColor=vec3(1.0);\n#endif\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nbaseColor.rgb*=vColor.rgb;\n#endif\n#ifdef NORMAL\nvec2 perturbation=bumpHeight*(baseColor.rg-0.5);\n#ifdef BUMPAFFECTSREFLECTION\nvec3 normalW=normalize(vNormalW+vec3(perturbation.x*8.0,0.0,perturbation.y*8.0));if (normalW.y<0.0) {normalW.y=-normalW.y;}\n#else\nvec3 normalW=normalize(vNormalW);\n#endif\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);vec2 perturbation=bumpHeight*(vec2(1.0,1.0)-0.5);\n#endif\n#ifdef FRESNELSEPARATE\n#ifdef REFLECTION\nvec2 projectedRefractionTexCoords=clamp(vRefractionMapTexCoord.xy/vRefractionMapTexCoord.z+perturbation*0.5,0.0,1.0);vec4 refractiveColor=texture2D(refractionSampler,projectedRefractionTexCoords);\n#ifdef IS_REFRACTION_LINEAR\nrefractiveColor.rgb=toGammaSpace(refractiveColor.rgb);\n#endif\nvec2 projectedReflectionTexCoords=clamp(vec2(\nvReflectionMapTexCoord.x/vReflectionMapTexCoord.z+perturbation.x*0.3,\nvReflectionMapTexCoord.y/vReflectionMapTexCoord.z+perturbation.y\n),0.0,1.0);vec4 reflectiveColor=texture2D(reflectionSampler,projectedReflectionTexCoords);\n#ifdef IS_REFLECTION_LINEAR\nreflectiveColor.rgb=toGammaSpace(reflectiveColor.rgb);\n#endif\nvec3 upVector=vec3(0.0,1.0,0.0);float fresnelTerm=clamp(abs(pow(dot(viewDirectionW,upVector),3.0)),0.05,0.65);float IfresnelTerm=1.0-fresnelTerm;refractiveColor=colorBlendFactor*waterColor+(1.0-colorBlendFactor)*refractiveColor;reflectiveColor=IfresnelTerm*colorBlendFactor2*waterColor+(1.0-colorBlendFactor2*IfresnelTerm)*reflectiveColor;vec4 combinedColor=refractiveColor*fresnelTerm+reflectiveColor*IfresnelTerm;baseColor=combinedColor;\n#endif\nvec3 diffuseBase=vec3(0.,0.,0.);lightingInfo info;float shadow=1.;float aggShadow=0.;float numLights=0.;\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;vec3 specularBase=vec3(0.,0.,0.);vec3 specularColor=vSpecularColor.rgb;\n#else\nfloat glossiness=0.;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\nvec3 finalDiffuse=clamp(baseColor.rgb,0.0,1.0);\n#if defined(VERTEXALPHA) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nalpha*=vColor.a;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#else \n#ifdef REFLECTION\nvec2 projectedRefractionTexCoords=clamp(vRefractionMapTexCoord.xy/vRefractionMapTexCoord.z+perturbation,0.0,1.0);vec4 refractiveColor=texture2D(refractionSampler,projectedRefractionTexCoords);\n#ifdef IS_REFRACTION_LINEAR\nrefractiveColor.rgb=toGammaSpace(refractiveColor.rgb);\n#endif\nvec2 projectedReflectionTexCoords=clamp(vReflectionMapTexCoord.xy/vReflectionMapTexCoord.z+perturbation,0.0,1.0);vec4 reflectiveColor=texture2D(reflectionSampler,projectedReflectionTexCoords);\n#ifdef IS_REFLECTION_LINEAR\nreflectiveColor.rgb=toGammaSpace(reflectiveColor.rgb);\n#endif\nvec3 upVector=vec3(0.0,1.0,0.0);float fresnelTerm=max(dot(viewDirectionW,upVector),0.0);vec4 combinedColor=refractiveColor*fresnelTerm+reflectiveColor*(1.0-fresnelTerm);baseColor=colorBlendFactor*waterColor+(1.0-colorBlendFactor)*combinedColor;\n#endif\nvec3 diffuseBase=vec3(0.,0.,0.);lightingInfo info;float shadow=1.;float aggShadow=0.;float numLights=0.;\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;vec3 specularBase=vec3(0.,0.,0.);vec3 specularColor=vSpecularColor.rgb;\n#else\nfloat glossiness=0.;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\nvec3 finalDiffuse=clamp(baseColor.rgb,0.0,1.0);\n#if defined(VERTEXALPHA) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nalpha*=vColor.a;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#endif\nvec4 color=vec4(finalDiffuse+finalSpecular,alpha);\n#include<logDepthFragment>\n#include<fogFragment>\n#ifdef IMAGEPROCESSINGPOSTPROCESS\ncolor.rgb=toLinearSpace(color.rgb);\n#elif defined(IMAGEPROCESSING)\ncolor.rgb=toLinearSpace(color.rgb);color=applyImageProcessing(color);\n#endif\ngl_FragColor=color;\n#define CUSTOM_FRAGMENT_MAIN_END\n}\n";s.ShaderStore.ShadersStore.waterVertexShader="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 BUMP\nvarying vec2 vNormalUV;\n#ifdef BUMPSUPERIMPOSE\nvarying vec2 vNormalUV2;\n#endif\nuniform mat4 normalMatrix;uniform vec2 vNormalInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<logDepthDeclaration>\nuniform mat4 reflectionViewProjection;uniform vec2 windDirection;uniform float waveLength;uniform float time;uniform float windForce;uniform float waveHeight;uniform float waveSpeed;uniform float waveCount;varying vec3 vRefractionMapTexCoord;varying vec3 vReflectionMapTexCoord;\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);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 BUMP\nif (vNormalInfos.x==0.)\n{vNormalUV=vec2(normalMatrix*vec4((uv*1.0)/waveLength+time*windForce*windDirection,1.0,0.0));\n#ifdef BUMPSUPERIMPOSE\nvNormalUV2=vec2(normalMatrix*vec4((uv*0.721)/waveLength+time*1.2*windForce*windDirection,1.0,0.0));\n#endif\n}\nelse\n{vNormalUV=vec2(normalMatrix*vec4((uv2*1.0)/waveLength+time*windForce*windDirection ,1.0,0.0));\n#ifdef BUMPSUPERIMPOSE\nvNormalUV2=vec2(normalMatrix*vec4((uv2*0.721)/waveLength+time*1.2*windForce*windDirection ,1.0,0.0));\n#endif\n}\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\nfloat finalWaveCount=1.0/(waveCount*0.5);\n#ifdef USE_WORLD_COORDINATES\nvec3 p=worldPos.xyz;\n#else\nvec3 p=position;\n#endif\nfloat newY=(sin(((p.x/finalWaveCount)+time*waveSpeed))*waveHeight*windDirection.x*5.0)\n+ (cos(((p.z/finalWaveCount)+ time*waveSpeed))*waveHeight*windDirection.y*5.0);p.y+=abs(newY);\n#ifdef USE_WORLD_COORDINATES\ngl_Position=viewProjection*vec4(p,1.0);\n#else\ngl_Position=viewProjection*finalWorld*vec4(p,1.0);\n#endif\n#ifdef REFLECTION\nvRefractionMapTexCoord.x=0.5*(gl_Position.w+gl_Position.x);vRefractionMapTexCoord.y=0.5*(gl_Position.w+gl_Position.y);vRefractionMapTexCoord.z=gl_Position.w;worldPos=reflectionViewProjection*finalWorld*vec4(position,1.0);vReflectionMapTexCoord.x=0.5*(worldPos.w+worldPos.x);vReflectionMapTexCoord.y=0.5*(worldPos.w+worldPos.y);vReflectionMapTexCoord.z=worldPos.w;\n#endif\n#include<logDepthVertex>\n#define CUSTOM_VERTEX_MAIN_END\n}\n";var l=function(e){function r(){var r=e.call(this)||this;return r.BUMP=!1,r.REFLECTION=!1,r.CLIPPLANE=!1,r.CLIPPLANE2=!1,r.CLIPPLANE3=!1,r.CLIPPLANE4=!1,r.CLIPPLANE5=!1,r.CLIPPLANE6=!1,r.ALPHATEST=!1,r.DEPTHPREPASS=!1,r.POINTSIZE=!1,r.FOG=!1,r.NORMAL=!1,r.UV1=!1,r.UV2=!1,r.VERTEXCOLOR=!1,r.VERTEXALPHA=!1,r.NUM_BONE_INFLUENCERS=0,r.BonesPerMesh=0,r.INSTANCES=!1,r.INSTANCESCOLOR=!1,r.SPECULARTERM=!1,r.LOGARITHMICDEPTH=!1,r.USE_REVERSE_DEPTHBUFFER=!1,r.FRESNELSEPARATE=!1,r.BUMPSUPERIMPOSE=!1,r.BUMPAFFECTSREFLECTION=!1,r.USE_WORLD_COORDINATES=!1,r.IMAGEPROCESSING=!1,r.VIGNETTE=!1,r.VIGNETTEBLENDMODEMULTIPLY=!1,r.VIGNETTEBLENDMODEOPAQUE=!1,r.TONEMAPPING=!1,r.TONEMAPPING_ACES=!1,r.CONTRAST=!1,r.EXPOSURE=!1,r.COLORCURVES=!1,r.COLORGRADING=!1,r.COLORGRADING3D=!1,r.SAMPLER3DGREENDEPTH=!1,r.SAMPLER3DBGRMAP=!1,r.DITHER=!1,r.IMAGEPROCESSINGPOSTPROCESS=!1,r.SKIPFINALCOLORCLAMP=!1,r.rebuild(),r}return n(r,e),r}(s.MaterialDefines),f=function(e){function r(r,t,i){void 0===i&&(i=new s.Vector2(512,512));var o=e.call(this,r,t)||this;return o.renderTargetSize=i,o.diffuseColor=new s.Color3(1,1,1),o.specularColor=new s.Color3(0,0,0),o.specularPower=64,o._disableLighting=!1,o._maxSimultaneousLights=4,o.windForce=6,o.windDirection=new s.Vector2(0,1),o.waveHeight=.4,o.bumpHeight=.4,o._bumpSuperimpose=!1,o._fresnelSeparate=!1,o._bumpAffectsReflection=!1,o.waterColor=new s.Color3(.1,.1,.6),o.colorBlendFactor=.2,o.waterColor2=new s.Color3(.1,.1,.6),o.colorBlendFactor2=.2,o.waveLength=.1,o.waveSpeed=1,o.waveCount=20,o.disableClipPlane=!1,o._useWorldCoordinatesForWaveDeformation=!1,o._renderTargets=new s.SmartArray(16),o._mesh=null,o._reflectionTransform=s.Matrix.Zero(),o._lastTime=0,o._lastDeltaTime=0,o._createRenderTargets(o.getScene(),i),o.getRenderTargetTextures=function(){return o._renderTargets.reset(),o._renderTargets.push(o._reflectionRTT),o._renderTargets.push(o._refractionRTT),o._renderTargets},o._imageProcessingConfiguration=o.getScene().imageProcessingConfiguration,o._imageProcessingConfiguration&&(o._imageProcessingObserver=o._imageProcessingConfiguration.onUpdateParameters.add((function(){o._markAllSubMeshesAsImageProcessingDirty()}))),o}return n(r,e),Object.defineProperty(r.prototype,"hasRenderTargetTextures",{get:function(){return!0},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"refractionTexture",{get:function(){return this._refractionRTT},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"reflectionTexture",{get:function(){return this._reflectionRTT},enumerable:!1,configurable:!0}),r.prototype.addToRenderList=function(e){this._refractionRTT&&this._refractionRTT.renderList&&this._refractionRTT.renderList.push(e),this._reflectionRTT&&this._reflectionRTT.renderList&&this._reflectionRTT.renderList.push(e)},r.prototype.removeFromRenderList=function(e){var r;this._refractionRTT&&this._refractionRTT.renderList&&-1!==(r=this._refractionRTT.renderList.indexOf(e))&&this._refractionRTT.renderList.splice(r,1),this._reflectionRTT&&this._reflectionRTT.renderList&&-1!==(r=this._reflectionRTT.renderList.indexOf(e))&&this._reflectionRTT.renderList.splice(r,1)},r.prototype.enableRenderTargets=function(e){var r=e?1:0;this._refractionRTT&&(this._refractionRTT.refreshRate=r),this._reflectionRTT&&(this._reflectionRTT.refreshRate=r)},r.prototype.getRenderList=function(){return this._refractionRTT?this._refractionRTT.renderList:[]},Object.defineProperty(r.prototype,"renderTargetsEnabled",{get:function(){return!(this._refractionRTT&&0===this._refractionRTT.refreshRate)},enumerable:!1,configurable:!0}),r.prototype.needAlphaBlending=function(){return this.alpha<1},r.prototype.needAlphaTesting=function(){return!1},r.prototype.getAlphaTestTexture=function(){return null},r.prototype.isReadyForSubMesh=function(e,r,t){var i=r._drawWrapper;if(this.isFrozen&&i.effect&&i._wasPreviouslyReady&&i._wasPreviouslyUsingInstances===t)return!0;r.materialDefines||(r.materialDefines=new l);var o=r.materialDefines,n=this.getScene();if(this._isReadyForSubMesh(r))return!0;var a=n.getEngine();if(o._areTexturesDirty&&(o._needUVs=!1,n.texturesEnabled)){if(this.bumpTexture&&s.MaterialFlags.BumpTextureEnabled){if(!this.bumpTexture.isReady())return!1;o._needUVs=!0,o.BUMP=!0}s.MaterialFlags.ReflectionTextureEnabled&&(o.REFLECTION=!0)}if((0,s.PrepareDefinesForFrameBoundValues)(n,a,this,o,!!t),(0,s.PrepareDefinesForMisc)(e,n,this._useLogarithmicDepth,this.pointsCloud,this.fogEnabled,this._shouldTurnAlphaTestOn(e),o),o._areMiscDirty&&(o.FRESNELSEPARATE=this._fresnelSeparate,o.BUMPSUPERIMPOSE=this._bumpSuperimpose,o.BUMPAFFECTSREFLECTION=this._bumpAffectsReflection,o.USE_WORLD_COORDINATES=this._useWorldCoordinatesForWaveDeformation),o._needNormals=(0,s.PrepareDefinesForLights)(n,e,o,!0,this._maxSimultaneousLights,this._disableLighting),o._areImageProcessingDirty&&this._imageProcessingConfiguration){if(!this._imageProcessingConfiguration.isReady())return!1;this._imageProcessingConfiguration.prepareDefines(o),o.IS_REFLECTION_LINEAR=null!=this.reflectionTexture&&!this.reflectionTexture.gammaSpace,o.IS_REFRACTION_LINEAR=null!=this.refractionTexture&&!this.refractionTexture.gammaSpace}if((0,s.PrepareDefinesForAttributes)(e,o,!0,!0),this._mesh=e,this._waitingRenderList){for(var f=0;f<this._waitingRenderList.length;f++)this.addToRenderList(n.getNodeById(this._waitingRenderList[f]));this._waitingRenderList=null}if(o.isDirty){o.markAsProcessed(),n.resetCachedMaterial();var c=new s.EffectFallbacks;o.FOG&&c.addFallback(1,"FOG"),o.LOGARITHMICDEPTH&&c.addFallback(0,"LOGARITHMICDEPTH"),(0,s.HandleFallbacksForShadows)(o,c,this.maxSimultaneousLights),o.NUM_BONE_INFLUENCERS>0&&c.addCPUSkinningFallback(0,e);var d=[s.VertexBuffer.PositionKind];o.NORMAL&&d.push(s.VertexBuffer.NormalKind),o.UV1&&d.push(s.VertexBuffer.UVKind),o.UV2&&d.push(s.VertexBuffer.UV2Kind),o.VERTEXCOLOR&&d.push(s.VertexBuffer.ColorKind),(0,s.PrepareAttributesForBones)(d,e,o,c),(0,s.PrepareAttributesForInstances)(d,o);var u=o.toString(),p=["world","view","viewProjection","vEyePosition","vLightsType","vDiffuseColor","vSpecularColor","vFogInfos","vFogColor","pointSize","vNormalInfos","mBones","normalMatrix","logarithmicDepthConstant","reflectionViewProjection","windDirection","waveLength","time","windForce","cameraPosition","bumpHeight","waveHeight","waterColor","waterColor2","colorBlendFactor","colorBlendFactor2","waveSpeed","waveCount"],v=["normalSampler","refractionSampler","reflectionSampler"],m=[];s.ImageProcessingConfiguration&&(s.ImageProcessingConfiguration.PrepareUniforms(p,o),s.ImageProcessingConfiguration.PrepareSamplers(v,o)),(0,s.addClipPlaneUniforms)(p),(0,s.PrepareUniformsAndSamplersList)({uniformsNames:p,uniformBuffersNames:m,samplers:v,defines:o,maxSimultaneousLights:this.maxSimultaneousLights}),r.setEffect(n.getEngine().createEffect("water",{attributes:d,uniformsNames:p,uniformBuffersNames:m,samplers:v,defines:u,fallbacks:c,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{maxSimultaneousLights:this._maxSimultaneousLights}},a),o,this._materialContext)}return!(!r.effect||!r.effect.isReady()||(o._renderId=n.getRenderId(),i._wasPreviouslyReady=!0,i._wasPreviouslyUsingInstances=!!t,0))},r.prototype.bindForSubMesh=function(e,r,t){var i=this.getScene(),o=t.materialDefines;if(o){var n=t.effect;if(n&&this._mesh){this._activeEffect=n,this.bindOnlyWorldMatrix(e),this._activeEffect.setMatrix("viewProjection",i.getTransformMatrix()),(0,s.BindBonesParameters)(r,this._activeEffect),this._mustRebind(i,n,t)&&(this.bumpTexture&&s.MaterialFlags.BumpTextureEnabled&&(this._activeEffect.setTexture("normalSampler",this.bumpTexture),this._activeEffect.setFloat2("vNormalInfos",this.bumpTexture.coordinatesIndex,this.bumpTexture.level),this._activeEffect.setMatrix("normalMatrix",this.bumpTexture.getTextureMatrix())),(0,s.bindClipPlane)(n,this,i),this.pointsCloud&&this._activeEffect.setFloat("pointSize",this.pointSize),this._useLogarithmicDepth&&(0,s.BindLogDepth)(o,n,i),i.bindEyePosition(n)),this._activeEffect.setColor4("vDiffuseColor",this.diffuseColor,this.alpha*r.visibility),o.SPECULARTERM&&this._activeEffect.setColor4("vSpecularColor",this.specularColor,this.specularPower),i.lightsEnabled&&!this.disableLighting&&(0,s.BindLights)(i,r,this._activeEffect,o,this.maxSimultaneousLights),i.fogEnabled&&r.applyFog&&i.fogMode!==s.Scene.FOGMODE_NONE&&this._activeEffect.setMatrix("view",i.getViewMatrix()),(0,s.BindFogParameters)(i,r,this._activeEffect),(0,s.BindLogDepth)(o,this._activeEffect,i),s.MaterialFlags.ReflectionTextureEnabled&&(this._activeEffect.setTexture("refractionSampler",this._refractionRTT),this._activeEffect.setTexture("reflectionSampler",this._reflectionRTT));var a=this._reflectionTransform.multiply(i.getProjectionMatrix()),l=i.getEngine().getDeltaTime();l!==this._lastDeltaTime&&(this._lastDeltaTime=l,this._lastTime+=this._lastDeltaTime),this._activeEffect.setMatrix("reflectionViewProjection",a),this._activeEffect.setVector2("windDirection",this.windDirection),this._activeEffect.setFloat("waveLength",this.waveLength),this._activeEffect.setFloat("time",this._lastTime/1e5),this._activeEffect.setFloat("windForce",this.windForce),this._activeEffect.setFloat("waveHeight",this.waveHeight),this._activeEffect.setFloat("bumpHeight",this.bumpHeight),this._activeEffect.setColor4("waterColor",this.waterColor,1),this._activeEffect.setFloat("colorBlendFactor",this.colorBlendFactor),this._activeEffect.setColor4("waterColor2",this.waterColor2,1),this._activeEffect.setFloat("colorBlendFactor2",this.colorBlendFactor2),this._activeEffect.setFloat("waveSpeed",this.waveSpeed),this._activeEffect.setFloat("waveCount",this.waveCount),this._imageProcessingConfiguration&&!this._imageProcessingConfiguration.applyByPostProcess&&this._imageProcessingConfiguration.bind(this._activeEffect),this._afterBind(r,this._activeEffect,t)}}},r.prototype._createRenderTargets=function(e,r){var t,i=this;this._refractionRTT=new s.RenderTargetTexture(name+"_refraction",{width:r.x,height:r.y},e,!1,!0),this._refractionRTT.wrapU=s.Constants.TEXTURE_MIRROR_ADDRESSMODE,this._refractionRTT.wrapV=s.Constants.TEXTURE_MIRROR_ADDRESSMODE,this._refractionRTT.ignoreCameraViewport=!0,this._reflectionRTT=new s.RenderTargetTexture(name+"_reflection",{width:r.x,height:r.y},e,!1,!0),this._reflectionRTT.wrapU=s.Constants.TEXTURE_MIRROR_ADDRESSMODE,this._reflectionRTT.wrapV=s.Constants.TEXTURE_MIRROR_ADDRESSMODE,this._reflectionRTT.ignoreCameraViewport=!0;var o,n=null,a=s.Matrix.Zero();this._refractionRTT.onBeforeRender=function(){if(i._mesh&&(t=i._mesh.isVisible,i._mesh.isVisible=!1),!i.disableClipPlane){n=e.clipPlane;var r=i._mesh?i._mesh.absolutePosition.y:0;e.clipPlane=s.Plane.FromPositionAndNormal(new s.Vector3(0,r+.05,0),new s.Vector3(0,1,0))}},this._refractionRTT.onAfterRender=function(){i._mesh&&(i._mesh.isVisible=t),i.disableClipPlane||(e.clipPlane=n)},this._reflectionRTT.onBeforeRender=function(){if(i._mesh&&(t=i._mesh.isVisible,i._mesh.isVisible=!1),!i.disableClipPlane){n=e.clipPlane;var r=i._mesh?i._mesh.absolutePosition.y:0;e.clipPlane=s.Plane.FromPositionAndNormal(new s.Vector3(0,r-.05,0),new s.Vector3(0,-1,0)),s.Matrix.ReflectionToRef(e.clipPlane,a)}o=e.getViewMatrix(),a.multiplyToRef(o,i._reflectionTransform),e.setTransformMatrix(i._reflectionTransform,e.getProjectionMatrix()),e._mirroredCameraPosition=s.Vector3.TransformCoordinates(e.activeCamera.position,a)},this._reflectionRTT.onAfterRender=function(){i._mesh&&(i._mesh.isVisible=t),e.clipPlane=n,e.setTransformMatrix(o,e.getProjectionMatrix()),e._mirroredCameraPosition=null}},r.prototype.getAnimatables=function(){var e=[];return this.bumpTexture&&this.bumpTexture.animations&&this.bumpTexture.animations.length>0&&e.push(this.bumpTexture),this._reflectionRTT&&this._reflectionRTT.animations&&this._reflectionRTT.animations.length>0&&e.push(this._reflectionRTT),this._refractionRTT&&this._refractionRTT.animations&&this._refractionRTT.animations.length>0&&e.push(this._refractionRTT),e},r.prototype.getActiveTextures=function(){var r=e.prototype.getActiveTextures.call(this);return this._bumpTexture&&r.push(this._bumpTexture),r},r.prototype.hasTexture=function(r){return!!e.prototype.hasTexture.call(this,r)||this._bumpTexture===r},r.prototype.dispose=function(r){this.bumpTexture&&this.bumpTexture.dispose();var t=this.getScene().customRenderTargets.indexOf(this._refractionRTT);-1!=t&&this.getScene().customRenderTargets.splice(t,1),t=-1,-1!=(t=this.getScene().customRenderTargets.indexOf(this._reflectionRTT))&&this.getScene().customRenderTargets.splice(t,1),this._reflectionRTT&&this._reflectionRTT.dispose(),this._refractionRTT&&this._refractionRTT.dispose(),this._imageProcessingConfiguration&&this._imageProcessingObserver&&this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver),e.prototype.dispose.call(this,r)},r.prototype.clone=function(e){var t=this;return s.SerializationHelper.Clone((function(){return new r(e,t.getScene())}),this)},r.prototype.serialize=function(){var r=e.prototype.serialize.call(this);if(r.customType="BABYLON.WaterMaterial",r.renderList=[],this._refractionRTT&&this._refractionRTT.renderList)for(var t=0;t<this._refractionRTT.renderList.length;t++)r.renderList.push(this._refractionRTT.renderList[t].id);return r},r.prototype.getClassName=function(){return"WaterMaterial"},r.Parse=function(e,t,i){var o=s.SerializationHelper.Parse((function(){return new r(e.name,t)}),e,t,i);return o._waitingRenderList=e.renderList,o},r.CreateDefaultMesh=function(e,r){return(0,s.CreateGround)(e,{width:512,height:512,subdivisions:32,updatable:!1},r)},a([(0,s.serializeAsTexture)("bumpTexture")],r.prototype,"_bumpTexture",void 0),a([(0,s.expandToProperty)("_markAllSubMeshesAsTexturesDirty")],r.prototype,"bumpTexture",void 0),a([(0,s.serializeAsColor3)()],r.prototype,"diffuseColor",void 0),a([(0,s.serializeAsColor3)()],r.prototype,"specularColor",void 0),a([(0,s.serialize)()],r.prototype,"specularPower",void 0),a([(0,s.serialize)("disableLighting")],r.prototype,"_disableLighting",void 0),a([(0,s.expandToProperty)("_markAllSubMeshesAsLightsDirty")],r.prototype,"disableLighting",void 0),a([(0,s.serialize)("maxSimultaneousLights")],r.prototype,"_maxSimultaneousLights",void 0),a([(0,s.expandToProperty)("_markAllSubMeshesAsLightsDirty")],r.prototype,"maxSimultaneousLights",void 0),a([(0,s.serialize)()],r.prototype,"windForce",void 0),a([(0,s.serializeAsVector2)()],r.prototype,"windDirection",void 0),a([(0,s.serialize)()],r.prototype,"waveHeight",void 0),a([(0,s.serialize)()],r.prototype,"bumpHeight",void 0),a([(0,s.serialize)("bumpSuperimpose")],r.prototype,"_bumpSuperimpose",void 0),a([(0,s.expandToProperty)("_markAllSubMeshesAsMiscDirty")],r.prototype,"bumpSuperimpose",void 0),a([(0,s.serialize)("fresnelSeparate")],r.prototype,"_fresnelSeparate",void 0),a([(0,s.expandToProperty)("_markAllSubMeshesAsMiscDirty")],r.prototype,"fresnelSeparate",void 0),a([(0,s.serialize)("bumpAffectsReflection")],r.prototype,"_bumpAffectsReflection",void 0),a([(0,s.expandToProperty)("_markAllSubMeshesAsMiscDirty")],r.prototype,"bumpAffectsReflection",void 0),a([(0,s.serializeAsColor3)()],r.prototype,"waterColor",void 0),a([(0,s.serialize)()],r.prototype,"colorBlendFactor",void 0),a([(0,s.serializeAsColor3)()],r.prototype,"waterColor2",void 0),a([(0,s.serialize)()],r.prototype,"colorBlendFactor2",void 0),a([(0,s.serialize)()],r.prototype,"waveLength",void 0),a([(0,s.serialize)()],r.prototype,"waveSpeed",void 0),a([(0,s.serialize)()],r.prototype,"waveCount",void 0),a([(0,s.serialize)()],r.prototype,"disableClipPlane",void 0),a([(0,s.serialize)("useWorldCoordinatesForWaveDeformation")],r.prototype,"_useWorldCoordinatesForWaveDeformation",void 0),a([(0,s.expandToProperty)("_markAllSubMeshesAsMiscDirty")],r.prototype,"useWorldCoordinatesForWaveDeformation",void 0),r}(s.PushMaterial);(0,s.RegisterClass)("BABYLON.WaterMaterial",f);var c=void 0!==i.g?i.g:"undefined"!=typeof window?window:void 0;if(void 0!==c)for(var d in e)c.BABYLON[d]=e[d];const u=r})(),o.default})()));
//# sourceMappingURL=babylon.waterMaterial.min.js.map