babylon.lavaMaterial.min.js 17 KB

1
  1. var __decorate=this&&this.__decorate||function(e,n,i,t){if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)return Reflect.decorate(e,n,i,t);switch(arguments.length){case 2:return e.reduceRight(function(e,n){return n&&n(e)||e},n);case 3:return e.reduceRight(function(e,t){return void(t&&t(n,i))},void 0);case 4:return e.reduceRight(function(e,t){return t&&t(n,i,e)||e},t)}},BABYLON;!function(e){var n=function(e){function n(){e.call(this),this.DIFFUSE=!1,this.CLIPPLANE=!1,this.ALPHATEST=!1,this.POINTSIZE=!1,this.FOG=!1,this.LIGHT0=!1,this.LIGHT1=!1,this.LIGHT2=!1,this.LIGHT3=!1,this.SPOTLIGHT0=!1,this.SPOTLIGHT1=!1,this.SPOTLIGHT2=!1,this.SPOTLIGHT3=!1,this.HEMILIGHT0=!1,this.HEMILIGHT1=!1,this.HEMILIGHT2=!1,this.HEMILIGHT3=!1,this.DIRLIGHT0=!1,this.DIRLIGHT1=!1,this.DIRLIGHT2=!1,this.DIRLIGHT3=!1,this.POINTLIGHT0=!1,this.POINTLIGHT1=!1,this.POINTLIGHT2=!1,this.POINTLIGHT3=!1,this.SHADOW0=!1,this.SHADOW1=!1,this.SHADOW2=!1,this.SHADOW3=!1,this.SHADOWS=!1,this.SHADOWVSM0=!1,this.SHADOWVSM1=!1,this.SHADOWVSM2=!1,this.SHADOWVSM3=!1,this.SHADOWPCF0=!1,this.SHADOWPCF1=!1,this.SHADOWPCF2=!1,this.SHADOWPCF3=!1,this.NORMAL=!1,this.UV1=!1,this.UV2=!1,this.VERTEXCOLOR=!1,this.VERTEXALPHA=!1,this.NUM_BONE_INFLUENCERS=0,this.BonesPerMesh=0,this.INSTANCES=!1,this._keys=Object.keys(this)}return __extends(n,e),n}(e.MaterialDefines),i=function(i){function t(t,o){i.call(this,t,o),this.speed=1,this.movingSpeed=1,this.lowFrequencySpeed=1,this.fogDensity=.15,this._lastTime=0,this.diffuseColor=new e.Color3(1,1,1),this.disableLighting=!1,this._worldViewProjectionMatrix=e.Matrix.Zero(),this._scaledDiffuse=new e.Color3,this._defines=new n,this._cachedDefines=new n,this._cachedDefines.BonesPerMesh=-1}return __extends(t,i),t.prototype.needAlphaBlending=function(){return this.alpha<1},t.prototype.needAlphaTesting=function(){return!1},t.prototype.getAlphaTestTexture=function(){return null},t.prototype._checkCache=function(e,n,i){return n?this._defines.INSTANCES!==i?!1:n._materialDefines&&n._materialDefines.isEqual(this._defines)?!0:!1:!0},t.prototype.isReady=function(i,t){if(this.checkReadyOnlyOnce&&this._wasPreviouslyReady)return!0;var o=this.getScene();if(!this.checkReadyOnEveryCall&&this._renderId===o.getRenderId()&&this._checkCache(o,i,t))return!0;var s=o.getEngine(),r=!1;if(this._defines.reset(),o.texturesEnabled&&this.diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled){if(!this.diffuseTexture.isReady())return!1;r=!0,this._defines.DIFFUSE=!0}o.clipPlane&&(this._defines.CLIPPLANE=!0),s.getAlphaTesting()&&(this._defines.ALPHATEST=!0),(this.pointsCloud||o.forcePointsCloud)&&(this._defines.POINTSIZE=!0),o.fogEnabled&&i&&i.applyFog&&o.fogMode!==e.Scene.FOGMODE_NONE&&this.fogEnabled&&(this._defines.FOG=!0);if(o.lightsEnabled&&!this.disableLighting&&e.MaterialHelper.PrepareDefinesForLights(o,i,this._defines),i&&(i.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(this._defines.NORMAL=!0),r&&(i.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(this._defines.UV1=!0),i.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(this._defines.UV2=!0)),i.useVertexColors&&i.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(this._defines.VERTEXCOLOR=!0,i.hasVertexAlpha&&(this._defines.VERTEXALPHA=!0)),i.useBones&&i.computeBonesUsingShaders&&(this._defines.NUM_BONE_INFLUENCERS=i.numBoneInfluencers,this._defines.BonesPerMesh=i.skeleton.bones.length+1),t&&(this._defines.INSTANCES=!0)),!this._defines.isEqual(this._cachedDefines)){this._defines.cloneTo(this._cachedDefines),o.resetCachedMaterial();var a=new e.EffectFallbacks;this._defines.FOG&&a.addFallback(1,"FOG"),e.MaterialHelper.HandleFallbacksForShadows(this._defines,a),this._defines.NUM_BONE_INFLUENCERS>0&&a.addCPUSkinningFallback(0,i);var f=[e.VertexBuffer.PositionKind];this._defines.NORMAL&&f.push(e.VertexBuffer.NormalKind),this._defines.UV1&&f.push(e.VertexBuffer.UVKind),this._defines.UV2&&f.push(e.VertexBuffer.UV2Kind),this._defines.VERTEXCOLOR&&f.push(e.VertexBuffer.ColorKind),e.MaterialHelper.PrepareAttributesForBones(f,i,this._defines,a),e.MaterialHelper.PrepareAttributesForInstances(f,this._defines);var l="lava",c=this._defines.toString();this._effect=o.getEngine().createEffect(l,f,["world","view","viewProjection","vEyePosition","vLightsType","vDiffuseColor","vLightData0","vLightDiffuse0","vLightSpecular0","vLightDirection0","vLightGround0","lightMatrix0","vLightData1","vLightDiffuse1","vLightSpecular1","vLightDirection1","vLightGround1","lightMatrix1","vLightData2","vLightDiffuse2","vLightSpecular2","vLightDirection2","vLightGround2","lightMatrix2","vLightData3","vLightDiffuse3","vLightSpecular3","vLightDirection3","vLightGround3","lightMatrix3","vFogInfos","vFogColor","pointSize","vDiffuseInfos","mBones","vClipPlane","diffuseMatrix","shadowsInfo0","shadowsInfo1","shadowsInfo2","shadowsInfo3","depthValues","time","speed","movingSpeed","fogColor","fogDensity","lowFrequencySpeed"],["diffuseSampler","shadowSampler0","shadowSampler1","shadowSampler2","shadowSampler3","noiseTexture"],c,a,this.onCompiled,this.onError)}return this._effect.isReady()?(this._renderId=o.getRenderId(),this._wasPreviouslyReady=!0,i&&(i._materialDefines||(i._materialDefines=new n),this._defines.cloneTo(i._materialDefines)),!0):!1},t.prototype.bindOnlyWorldMatrix=function(e){this._effect.setMatrix("world",e)},t.prototype.bind=function(n,t){var o=this.getScene();this.bindOnlyWorldMatrix(n),this._effect.setMatrix("viewProjection",o.getTransformMatrix()),e.MaterialHelper.BindBonesParameters(t,this._effect),o.getCachedMaterial()!==this&&(this.diffuseTexture&&e.StandardMaterial.DiffuseTextureEnabled&&(this._effect.setTexture("diffuseSampler",this.diffuseTexture),this._effect.setFloat2("vDiffuseInfos",this.diffuseTexture.coordinatesIndex,this.diffuseTexture.level),this._effect.setMatrix("diffuseMatrix",this.diffuseTexture.getTextureMatrix())),this.noiseTexture&&this._effect.setTexture("noiseTexture",this.noiseTexture),e.MaterialHelper.BindClipPlane(this._effect,o),this.pointsCloud&&this._effect.setFloat("pointSize",this.pointSize),this._effect.setVector3("vEyePosition",o._mirroredCameraPosition?o._mirroredCameraPosition:o.activeCamera.position)),this._effect.setColor4("vDiffuseColor",this._scaledDiffuse,this.alpha*t.visibility),o.lightsEnabled&&!this.disableLighting&&e.MaterialHelper.BindLights(o,t,this._effect,this._defines),o.fogEnabled&&t.applyFog&&o.fogMode!==e.Scene.FOGMODE_NONE&&this._effect.setMatrix("view",o.getViewMatrix()),e.MaterialHelper.BindFogParameters(o,t,this._effect),this._lastTime+=o.getEngine().getDeltaTime(),this._effect.setFloat("time",this._lastTime*this.speed/1e3),this.fogColor||(this.fogColor=e.Color3.Black()),this._effect.setColor3("fogColor",this.fogColor),this._effect.setFloat("fogDensity",this.fogDensity),this._effect.setFloat("lowFrequencySpeed",this.lowFrequencySpeed),this._effect.setFloat("movingSpeed",this.movingSpeed),i.prototype.bind.call(this,n,t)},t.prototype.getAnimatables=function(){var e=[];return this.diffuseTexture&&this.diffuseTexture.animations&&this.diffuseTexture.animations.length>0&&e.push(this.diffuseTexture),this.noiseTexture&&this.noiseTexture.animations&&this.noiseTexture.animations.length>0&&e.push(this.noiseTexture),e},t.prototype.dispose=function(e){this.diffuseTexture&&this.diffuseTexture.dispose(),this.noiseTexture&&this.noiseTexture.dispose(),i.prototype.dispose.call(this,e)},t.prototype.clone=function(n){var i=this;return e.SerializationHelper.Clone(function(){return new t(n,i.getScene())},this)},t.prototype.serialize=function(){var n=e.SerializationHelper.Serialize(this);return n.customType="BABYLON.LavaMaterial",n},t.Parse=function(n,i,o){return e.SerializationHelper.Parse(function(){return new t(n.name,i)},n,i,o)},__decorate([e.serializeAsTexture()],t.prototype,"diffuseTexture"),__decorate([e.serializeAsTexture()],t.prototype,"noiseTexture"),__decorate([e.serializeAsColor3()],t.prototype,"fogColor"),__decorate([e.serialize()],t.prototype,"speed"),__decorate([e.serialize()],t.prototype,"movingSpeed"),__decorate([e.serialize()],t.prototype,"lowFrequencySpeed"),__decorate([e.serialize()],t.prototype,"fogDensity"),__decorate([e.serializeAsColor3()],t.prototype,"diffuseColor"),__decorate([e.serialize()],t.prototype,"disableLighting"),t}(e.Material);e.LavaMaterial=i}(BABYLON||(BABYLON={})),BABYLON.Effect.ShadersStore.lavaVertexShader="precision highp float;\n// Inputs\nuniform float time;\nuniform float lowFrequencySpeed;\n// Varying\nvarying float noise;\n\n// Attributes\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\n#include<bonesDeclaration>\n\n// Uniforms\n#include<instancesDeclaration>\n\nuniform mat4 view;\nuniform mat4 viewProjection;\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\n// Output\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n\n#include<clipPlaneVertexDeclaration>\n\n#include<fogVertexDeclaration>\n#include<shadowsVertexDeclaration>\n\n/* NOISE FUNCTIONS */\n////// ASHIMA webgl noise\n////// https://github.com/ashima/webgl-noise/blob/master/src/classicnoise3D.glsl\nvec3 mod289(vec3 x)\n{\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\n\nvec4 mod289(vec4 x)\n{\n return x - floor(x * (1.0 / 289.0)) * 289.0;\n}\n\nvec4 permute(vec4 x)\n{\n return mod289(((x*34.0)+1.0)*x);\n}\n\nvec4 taylorInvSqrt(vec4 r)\n{\n return 1.79284291400159 - 0.85373472095314 * r;\n}\n\nvec3 fade(vec3 t) {\n return t*t*t*(t*(t*6.0-15.0)+10.0);\n}\n\n// Classic Perlin noise, periodic variant\nfloat pnoise(vec3 P, vec3 rep)\n{\n vec3 Pi0 = mod(floor(P), rep); // Integer part, modulo period\n vec3 Pi1 = mod(Pi0 + vec3(1.0), rep); // Integer part + 1, mod period\n Pi0 = mod289(Pi0);\n Pi1 = mod289(Pi1);\n vec3 Pf0 = fract(P); // Fractional part for interpolation\n vec3 Pf1 = Pf0 - vec3(1.0); // Fractional part - 1.0\n vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);\n vec4 iy = vec4(Pi0.yy, Pi1.yy);\n vec4 iz0 = Pi0.zzzz;\n vec4 iz1 = Pi1.zzzz;\n\n vec4 ixy = permute(permute(ix) + iy);\n vec4 ixy0 = permute(ixy + iz0);\n vec4 ixy1 = permute(ixy + iz1);\n\n vec4 gx0 = ixy0 * (1.0 / 7.0);\n vec4 gy0 = fract(floor(gx0) * (1.0 / 7.0)) - 0.5;\n gx0 = fract(gx0);\n vec4 gz0 = vec4(0.5) - abs(gx0) - abs(gy0);\n vec4 sz0 = step(gz0, vec4(0.0));\n gx0 -= sz0 * (step(0.0, gx0) - 0.5);\n gy0 -= sz0 * (step(0.0, gy0) - 0.5);\n\n vec4 gx1 = ixy1 * (1.0 / 7.0);\n vec4 gy1 = fract(floor(gx1) * (1.0 / 7.0)) - 0.5;\n gx1 = fract(gx1);\n vec4 gz1 = vec4(0.5) - abs(gx1) - abs(gy1);\n vec4 sz1 = step(gz1, vec4(0.0));\n gx1 -= sz1 * (step(0.0, gx1) - 0.5);\n gy1 -= sz1 * (step(0.0, gy1) - 0.5);\n\n vec3 g000 = vec3(gx0.x,gy0.x,gz0.x);\n vec3 g100 = vec3(gx0.y,gy0.y,gz0.y);\n vec3 g010 = vec3(gx0.z,gy0.z,gz0.z);\n vec3 g110 = vec3(gx0.w,gy0.w,gz0.w);\n vec3 g001 = vec3(gx1.x,gy1.x,gz1.x);\n vec3 g101 = vec3(gx1.y,gy1.y,gz1.y);\n vec3 g011 = vec3(gx1.z,gy1.z,gz1.z);\n vec3 g111 = vec3(gx1.w,gy1.w,gz1.w);\n\n vec4 norm0 = taylorInvSqrt(vec4(dot(g000, g000), dot(g010, g010), dot(g100, g100), dot(g110, g110)));\n g000 *= norm0.x;\n g010 *= norm0.y;\n g100 *= norm0.z;\n g110 *= norm0.w;\n vec4 norm1 = taylorInvSqrt(vec4(dot(g001, g001), dot(g011, g011), dot(g101, g101), dot(g111, g111)));\n g001 *= norm1.x;\n g011 *= norm1.y;\n g101 *= norm1.z;\n g111 *= norm1.w;\n\n float n000 = dot(g000, Pf0);\n float n100 = dot(g100, vec3(Pf1.x, Pf0.yz));\n float n010 = dot(g010, vec3(Pf0.x, Pf1.y, Pf0.z));\n float n110 = dot(g110, vec3(Pf1.xy, Pf0.z));\n float n001 = dot(g001, vec3(Pf0.xy, Pf1.z));\n float n101 = dot(g101, vec3(Pf1.x, Pf0.y, Pf1.z));\n float n011 = dot(g011, vec3(Pf0.x, Pf1.yz));\n float n111 = dot(g111, Pf1);\n\n vec3 fade_xyz = fade(Pf0);\n vec4 n_z = mix(vec4(n000, n100, n010, n110), vec4(n001, n101, n011, n111), fade_xyz.z);\n vec2 n_yz = mix(n_z.xy, n_z.zw, fade_xyz.y);\n float n_xyz = mix(n_yz.x, n_yz.y, fade_xyz.x);\n return 2.2 * n_xyz;\n}\n/* END FUNCTION */\n\nfloat turbulence( vec3 p ) {\n float w = 100.0;\n float t = -.5;\n for (float f = 1.0 ; f <= 10.0 ; f++ ){\n float power = pow( 2.0, f );\n t += abs( pnoise( vec3( power * p ), vec3( 10.0, 10.0, 10.0 ) ) / power );\n }\n return t;\n}\n\nvoid main(void) {\n\n#include<instancesVertex>\n#include<bonesVertex>\n\n#ifdef NORMAL\n // get a turbulent 3d noise using the normal, normal to high freq\n noise = 10.0 * -.10 * turbulence( .5 * normal + time*1.15 );\n // get a 3d noise using the position, low frequency\n float b = lowFrequencySpeed * 5.0 * pnoise( 0.05 * position +vec3(time*1.025), vec3( 100.0 ) );\n // compose both noises\n float displacement = - 1.5 * noise + b;\n\n // move the position along the normal and transform it\n vec3 newPosition = position + normal * displacement;\n gl_Position = viewProjection * finalWorld * vec4( newPosition, 1.0 );\n\n\n vec4 worldPos = finalWorld * vec4(newPosition, 1.0);\n vPositionW = vec3(worldPos);\n\n vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));\n#endif\n\n // Texture coordinates\n#ifndef UV1\n vec2 uv = vec2(0., 0.);\n#endif\n#ifndef UV2\n vec2 uv2 = vec2(0., 0.);\n#endif\n\n#ifdef DIFFUSE\n if (vDiffuseInfos.x == 0.)\n {\n vDiffuseUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));\n }\n else\n {\n vDiffuseUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));\n }\n#endif\n\n // Clip plane\n#include<clipPlaneVertex>\n\n // Fog\n#include<fogVertex>\n#include<shadowsVertex>\n\n // Vertex color\n#ifdef VERTEXCOLOR\n vColor = color;\n#endif\n\n // Point size\n#ifdef POINTSIZE\n gl_PointSize = pointSize;\n#endif\n}",BABYLON.Effect.ShadersStore.lavaPixelShader="precision highp float;\n\n// Constants\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\n// Input\nvarying vec3 vPositionW;\n\n// MAGMAAAA\nuniform float time;\nuniform float speed;\nuniform float movingSpeed;\nuniform vec3 fogColor;\nuniform sampler2D noiseTexture;\nuniform float fogDensity;\n\n// Varying\nvarying float noise;\n\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n// Lights\n#include<light0FragmentDeclaration>\n#include<light1FragmentDeclaration>\n#include<light2FragmentDeclaration>\n#include<light3FragmentDeclaration>\n\n\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n// Samplers\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n\n#include<clipPlaneFragmentDeclaration>\n\n// Fog\n#include<fogFragmentDeclaration>\n\n\nfloat random( vec3 scale, float seed ){\n return fract( sin( dot( gl_FragCoord.xyz + seed, scale ) ) * 43758.5453 + seed ) ;\n}\n\n\nvoid main(void) {\n#include<clipPlaneFragment>\n\n vec3 viewDirectionW = normalize(vEyePosition - vPositionW);\n\n // Base color\n vec4 baseColor = vec4(1., 1., 1., 1.);\n vec3 diffuseColor = vDiffuseColor.rgb;\n\n // Alpha\n float alpha = vDiffuseColor.a;\n\n\n\n#ifdef DIFFUSE\n ////// MAGMA ///\n\n vec4 noiseTex = texture2D( noiseTexture, vDiffuseUV );\n vec2 T1 = vDiffuseUV + vec2( 1.5, -1.5 ) * time * 0.02;\n vec2 T2 = vDiffuseUV + vec2( -0.5, 2.0 ) * time * 0.01 * speed;\n\n T1.x += noiseTex.x * 2.0;\n T1.y += noiseTex.y * 2.0;\n T2.x -= noiseTex.y * 0.2 + time*0.001*movingSpeed;\n T2.y += noiseTex.z * 0.2 + time*0.002*movingSpeed;\n\n float p = texture2D( noiseTexture, T1 * 3.0 ).a;\n\n vec4 lavaColor = texture2D( diffuseSampler, T2 * 4.0);\n vec4 temp = lavaColor * ( vec4( p, p, p, p ) * 2. ) + ( lavaColor * lavaColor - 0.1 );\n\n baseColor = temp;\n\n float depth = gl_FragCoord.z * 4.0;\n const float LOG2 = 1.442695;\n float fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );\n fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );\n\n baseColor = mix( baseColor, vec4( fogColor, baseColor.w ), fogFactor );\n diffuseColor = baseColor.rgb;\n ///// END MAGMA ////\n\n\n\n// baseColor = texture2D(diffuseSampler, vDiffuseUV);\n\n#ifdef ALPHATEST\n if (baseColor.a < 0.4)\n discard;\n#endif\n\n baseColor.rgb *= vDiffuseInfos.y;\n#endif\n\n#ifdef VERTEXCOLOR\n baseColor.rgb *= vColor.rgb;\n#endif\n\n // Bump\n#ifdef NORMAL\n vec3 normalW = normalize(vNormalW);\n#else\n vec3 normalW = vec3(1.0, 1.0, 1.0);\n#endif\n\n // Lighting\n vec3 diffuseBase = vec3(0., 0., 0.);\n float shadow = 1.;\n float glossiness = 0.;\n \n#include<light0Fragment>\n#include<light1Fragment>\n#include<light2Fragment>\n#include<light3Fragment>\n\n\n#ifdef VERTEXALPHA\n alpha *= vColor.a;\n#endif\n\n vec3 finalDiffuse = clamp(diffuseBase * diffuseColor, 0.0, 1.0) * baseColor.rgb;\n\n // Composition\n vec4 color = vec4(finalDiffuse, alpha);\n\n#include<fogFragment>\n\n gl_FragColor = color;\n}";