1 |
- var BABYLON;!function(e){var n=4,i=function(e){function n(){e.call(this),this.BUMP=!1,this.REFLECTION=!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.BONES=!1,this.BONES4=!1,this.BonesPerMesh=0,this.INSTANCES=!1,this.SPECULARTERM=!1,this._keys=Object.keys(this)}return __extends(n,e),n}(e.MaterialDefines),t=function(t){function o(n,o,r){void 0===r&&(r=new e.Vector2(512,512)),t.call(this,n,o),this.renderTargetSize=r,this.diffuseColor=new e.Color3(1,1,1),this.specularColor=new e.Color3(0,0,0),this.specularPower=64,this.disableLighting=!1,this.windForce=6,this.windDirection=new e.Vector2(0,1),this.waveHeight=.4,this.bumpHeight=.4,this.waterColor=new e.Color3(.1,.1,.6),this.colorBlendFactor=.2,this.waveLength=.1,this.waveSpeed=1,this._mesh=null,this._reflectionTransform=e.Matrix.Zero(),this._lastTime=0,this._scaledDiffuse=new e.Color3,this._scaledSpecular=new e.Color3,this._defines=new i,this._cachedDefines=new i,this._createRenderTargets(o,r)}return __extends(o,t),Object.defineProperty(o.prototype,"refractionTexture",{get:function(){return this._refractionRTT},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"reflectionTexture",{get:function(){return this._reflectionRTT},enumerable:!0,configurable:!0}),o.prototype.addToRenderList=function(e){this._refractionRTT.renderList.push(e),this._reflectionRTT.renderList.push(e)},o.prototype.enableRenderTargets=function(e){var n=e?1:0;this._refractionRTT.refreshRate=n,this._reflectionRTT.refreshRate=n},o.prototype.needAlphaBlending=function(){return this.alpha<1},o.prototype.needAlphaTesting=function(){return!1},o.prototype.getAlphaTestTexture=function(){return null},o.prototype._checkCache=function(e,n,i){return n?this._defines.INSTANCES!==i?!1:n._materialDefines&&n._materialDefines.isEqual(this._defines)?!0:!1:!0},o.prototype.isReady=function(t,o){if(this.checkReadyOnlyOnce&&this._wasPreviouslyReady)return!0;var r=this.getScene();if(!this.checkReadyOnEveryCall&&this._renderId===r.getRenderId()&&this._checkCache(r,t,o))return!0;var s=r.getEngine(),a=!1,f=!1;if(this._defines.reset(),r.texturesEnabled){if(this.bumpTexture&&e.StandardMaterial.BumpTextureEnabled){if(!this.bumpTexture.isReady())return!1;f=!0,this._defines.BUMP=!0}e.StandardMaterial.ReflectionTextureEnabled&&(this._defines.REFLECTION=!0)}r.clipPlane&&(this._defines.CLIPPLANE=!0),s.getAlphaTesting()&&(this._defines.ALPHATEST=!0),(this.pointsCloud||r.forcePointsCloud)&&(this._defines.POINTSIZE=!0),r.fogEnabled&&t&&t.applyFog&&r.fogMode!==e.Scene.FOGMODE_NONE&&this.fogEnabled&&(this._defines.FOG=!0);var d=0;if(r.lightsEnabled&&!this.disableLighting)for(var l=0;l<r.lights.length;l++){var h=r.lights[l];if(h.isEnabled()){if(h._excludedMeshesIds.length>0){for(var c=0;c<h._excludedMeshesIds.length;c++){var u=r.getMeshByID(h._excludedMeshesIds[c]);u&&h.excludedMeshes.push(u)}h._excludedMeshesIds=[]}if(h._includedOnlyMeshesIds.length>0){for(var v=0;v<h._includedOnlyMeshesIds.length;v++){var p=r.getMeshByID(h._includedOnlyMeshesIds[v]);p&&h.includedOnlyMeshes.push(p)}h._includedOnlyMeshesIds=[]}if(h.canAffectMesh(t)){a=!0,this._defines["LIGHT"+d]=!0;var g;if(g=h instanceof e.SpotLight?"SPOTLIGHT"+d:h instanceof e.HemisphericLight?"HEMILIGHT"+d:h instanceof e.PointLight?"POINTLIGHT"+d:"DIRLIGHT"+d,this._defines[g]=!0,h.specular.equalsFloats(0,0,0)||(this._defines.SPECULARTERM=!0),r.shadowsEnabled){var m=h.getShadowGenerator();t&&t.receiveShadows&&m&&(this._defines["SHADOW"+d]=!0,this._defines.SHADOWS=!0,(m.useVarianceShadowMap||m.useBlurVarianceShadowMap)&&(this._defines["SHADOWVSM"+d]=!0),m.usePoissonSampling&&(this._defines["SHADOWPCF"+d]=!0))}if(d++,d===n)break}}}if(t&&(a&&t.isVerticesDataPresent(e.VertexBuffer.NormalKind)&&(this._defines.NORMAL=!0),f&&(t.isVerticesDataPresent(e.VertexBuffer.UVKind)&&(this._defines.UV1=!0),t.isVerticesDataPresent(e.VertexBuffer.UV2Kind)&&(this._defines.UV2=!0)),t.useVertexColors&&t.isVerticesDataPresent(e.VertexBuffer.ColorKind)&&(this._defines.VERTEXCOLOR=!0,t.hasVertexAlpha&&(this._defines.VERTEXALPHA=!0)),t.useBones&&t.computeBonesUsingShaders&&(this._defines.BONES=!0,this._defines.BonesPerMesh=t.skeleton.bones.length+1,this._defines.BONES4=!0),o&&(this._defines.INSTANCES=!0)),this._mesh=t,!this._defines.isEqual(this._cachedDefines)){this._defines.cloneTo(this._cachedDefines),r.resetCachedMaterial();var T=new e.EffectFallbacks;for(this._defines.FOG&&T.addFallback(1,"FOG"),d=0;n>d;d++)this._defines["LIGHT"+d]&&(d>0&&T.addFallback(d,"LIGHT"+d),this._defines["SHADOW"+d]&&T.addFallback(0,"SHADOW"+d),this._defines["SHADOWPCF"+d]&&T.addFallback(0,"SHADOWPCF"+d),this._defines["SHADOWVSM"+d]&&T.addFallback(0,"SHADOWVSM"+d));this._defines.BONES4&&T.addFallback(0,"BONES4");var w=[e.VertexBuffer.PositionKind];this._defines.NORMAL&&w.push(e.VertexBuffer.NormalKind),this._defines.UV1&&w.push(e.VertexBuffer.UVKind),this._defines.UV2&&w.push(e.VertexBuffer.UV2Kind),this._defines.VERTEXCOLOR&&w.push(e.VertexBuffer.ColorKind),this._defines.BONES&&(w.push(e.VertexBuffer.MatricesIndicesKind),w.push(e.VertexBuffer.MatricesWeightsKind)),this._defines.INSTANCES&&(w.push("world0"),w.push("world1"),w.push("world2"),w.push("world3"));var L="water",S=this._defines.toString();this._effect=r.getEngine().createEffect(L,w,["world","view","viewProjection","vEyePosition","vLightsType","vDiffuseColor","vSpecularColor","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","vNormalInfos","mBones","vClipPlane","normalMatrix","shadowsInfo0","shadowsInfo1","shadowsInfo2","shadowsInfo3","worldReflectionViewProjection","windDirection","waveLength","time","windForce","cameraPosition","bumpHeight","waveHeight","waterColor","colorBlendFactor","waveSpeed"],["normalSampler","shadowSampler0","shadowSampler1","shadowSampler2","shadowSampler3","refractionSampler","reflectionSampler"],S,T,this.onCompiled,this.onError)}return this._effect.isReady()?(this._renderId=r.getRenderId(),this._wasPreviouslyReady=!0,t&&(t._materialDefines||(t._materialDefines=new i),this._defines.cloneTo(t._materialDefines)),!0):!1},o.prototype.bindOnlyWorldMatrix=function(e){this._effect.setMatrix("world",e)},o.prototype.bind=function(i,o){var r=this.getScene();if(this.bindOnlyWorldMatrix(i),this._effect.setMatrix("viewProjection",r.getTransformMatrix()),o&&o.useBones&&o.computeBonesUsingShaders&&this._effect.setMatrices("mBones",o.skeleton.getTransformMatrices()),r.getCachedMaterial()!==this){if(this.bumpTexture&&e.StandardMaterial.BumpTextureEnabled&&(this._effect.setTexture("normalSampler",this.bumpTexture),this._effect.setFloat2("vNormalInfos",this.bumpTexture.coordinatesIndex,this.bumpTexture.level),this._effect.setMatrix("normalMatrix",this.bumpTexture.getTextureMatrix())),r.clipPlane){var s=r.clipPlane;this._effect.setFloat4("vClipPlane",s.normal.x,s.normal.y,s.normal.z,s.d)}this.pointsCloud&&this._effect.setFloat("pointSize",this.pointSize),this._effect.setVector3("vEyePosition",r._mirroredCameraPosition?r._mirroredCameraPosition:r.activeCamera.position)}if(this._effect.setColor4("vDiffuseColor",this._scaledDiffuse,this.alpha*o.visibility),this._defines.SPECULARTERM&&this._effect.setColor4("vSpecularColor",this.specularColor,this.specularPower),r.lightsEnabled&&!this.disableLighting)for(var a=0,f=0;f<r.lights.length;f++){var d=r.lights[f];if(d.isEnabled()&&d.canAffectMesh(o)){if(d instanceof e.PointLight?d.transferToEffect(this._effect,"vLightData"+a):d instanceof e.DirectionalLight?d.transferToEffect(this._effect,"vLightData"+a):d instanceof e.SpotLight?d.transferToEffect(this._effect,"vLightData"+a,"vLightDirection"+a):d instanceof e.HemisphericLight&&d.transferToEffect(this._effect,"vLightData"+a,"vLightGround"+a),d.diffuse.scaleToRef(d.intensity,this._scaledDiffuse),this._effect.setColor4("vLightDiffuse"+a,this._scaledDiffuse,d.range),this._defines.SPECULARTERM&&(d.specular.scaleToRef(d.intensity,this._scaledSpecular),this._effect.setColor3("vLightSpecular"+a,this._scaledSpecular)),r.shadowsEnabled){var l=d.getShadowGenerator();o.receiveShadows&&l&&(this._effect.setMatrix("lightMatrix"+a,l.getTransformMatrix()),this._effect.setTexture("shadowSampler"+a,l.getShadowMapForRendering()),this._effect.setFloat3("shadowsInfo"+a,l.getDarkness(),l.getShadowMap().getSize().width,l.bias))}if(a++,a===n)break}}r.fogEnabled&&o.applyFog&&r.fogMode!==e.Scene.FOGMODE_NONE&&this._effect.setMatrix("view",r.getViewMatrix()),r.fogEnabled&&o.applyFog&&r.fogMode!==e.Scene.FOGMODE_NONE&&(this._effect.setFloat4("vFogInfos",r.fogMode,r.fogStart,r.fogEnd,r.fogDensity),this._effect.setColor3("vFogColor",r.fogColor)),e.StandardMaterial.ReflectionTextureEnabled&&(this._effect.setTexture("refractionSampler",this._refractionRTT),this._effect.setTexture("reflectionSampler",this._reflectionRTT));var h=this._mesh.getWorldMatrix().multiply(this._reflectionTransform).multiply(r.getProjectionMatrix());this._lastTime+=r.getEngine().getDeltaTime(),this._effect.setMatrix("worldReflectionViewProjection",h),this._effect.setVector2("windDirection",this.windDirection),this._effect.setFloat("waveLength",this.waveLength),this._effect.setFloat("time",this._lastTime/1e5),this._effect.setFloat("windForce",this.windForce),this._effect.setFloat("waveHeight",this.waveHeight),this._effect.setFloat("bumpHeight",this.bumpHeight),this._effect.setColor4("waterColor",this.waterColor,1),this._effect.setFloat("colorBlendFactor",this.colorBlendFactor),this._effect.setFloat("waveSpeed",this.waveSpeed),t.prototype.bind.call(this,i,o)},o.prototype._createRenderTargets=function(n,i){var t=this;this._refractionRTT=new e.RenderTargetTexture(name+"_refraction",{width:i.x,height:i.y},n,!1,!0),this._reflectionRTT=new e.RenderTargetTexture(name+"_reflection",{width:i.x,height:i.y},n,!1,!0),n.customRenderTargets.push(this._refractionRTT),n.customRenderTargets.push(this._reflectionRTT);var o,r,s=null,a=e.Matrix.Zero();this._refractionRTT.onBeforeRender=function(){t._mesh&&(o=t._mesh.isVisible,t._mesh.isVisible=!1),s=n.clipPlane;var i=t._mesh?t._mesh.position.y:0;n.clipPlane=e.Plane.FromPositionAndNormal(new e.Vector3(0,i+.05,0),new e.Vector3(0,1,0))},this._refractionRTT.onAfterRender=function(){t._mesh&&(t._mesh.isVisible=o),n.clipPlane=s},this._reflectionRTT.onBeforeRender=function(){t._mesh&&(o=t._mesh.isVisible,t._mesh.isVisible=!1),s=n.clipPlane;var i=t._mesh?t._mesh.position.y:0;n.clipPlane=e.Plane.FromPositionAndNormal(new e.Vector3(0,i-.05,0),new e.Vector3(0,-1,0)),e.Matrix.ReflectionToRef(n.clipPlane,a),r=n.getViewMatrix(),a.multiplyToRef(r,t._reflectionTransform),n.setTransformMatrix(t._reflectionTransform,n.getProjectionMatrix()),n.getEngine().cullBackFaces=!1,n._mirroredCameraPosition=e.Vector3.TransformCoordinates(n.activeCamera.position,a)},this._reflectionRTT.onAfterRender=function(){t._mesh&&(t._mesh.isVisible=o),n.clipPlane=s,n.setTransformMatrix(r,n.getProjectionMatrix()),n.getEngine().cullBackFaces=!0,n._mirroredCameraPosition=null}},o.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},o.prototype.dispose=function(e){this.bumpTexture&&this.bumpTexture.dispose(),this._reflectionRTT&&this._reflectionRTT.dispose(),this._refractionRTT&&this._refractionRTT.dispose(),t.prototype.dispose.call(this,e)},o.prototype.clone=function(e){var n=new o(e,this.getScene());return this.copyTo(n),this.bumpTexture&&this.bumpTexture.clone&&(n.bumpTexture=this.bumpTexture.clone()),n.diffuseColor=this.diffuseColor.clone(),n},o.prototype.serialize=function(){var e=t.prototype.serialize.call(this);return e.customType="water",e.diffuseColor=this.diffuseColor.asArray(),e.specularColor=this.specularColor.asArray(),e.specularPower=this.specularPower,e.disableLighting=this.disableLighting,e.windForce=this.windForce,e.windDirection=this.windDirection.asArray(),e.waveHeight=this.waveHeight,e.bumpHeight=this.bumpHeight,e.waterColor=this.waterColor.asArray(),e.colorBlendFactor=this.colorBlendFactor,e.waveLength=this.waveLength,e.renderTargetSize=this.renderTargetSize.asArray(),this.bumpTexture&&(e.bumpTexture=this.bumpTexture.serialize()),e},o.Parse=function(n,i,t){var r=n.renderTargetSize?e.Vector2.FromArray(n.renderTargetSize):null,s=new o(n.name,i,r);return s.diffuseColor=e.Color3.FromArray(n.diffuseColor),s.specularColor=e.Color3.FromArray(n.specularColor),s.specularPower=n.specularPower,s.disableLighting=n.disableLighting,s.windForce=n.windForce,s.windDirection=e.Vector2.FromArray(n.windDirection),s.waveHeight=n.waveHeight,s.bumpHeight=n.bumpHeight,s.waterColor=e.Color3.FromArray(n.waterColor),s.colorBlendFactor=n.colorBlendFactor,s.waveLength=n.waveLength,s.renderTargetSize=e.Vector2.FromArray(n.renderTargetSize),s.alpha=n.alpha,s.id=n.id,e.Tags.AddTagsTo(s,n.tags),s.backFaceCulling=n.backFaceCulling,s.wireframe=n.wireframe,n.bumpTexture&&(s.bumpTexture=e.Texture.Parse(n.bumpTexture,i,t)),n.checkReadyOnlyOnce&&(s.checkReadyOnlyOnce=n.checkReadyOnlyOnce),s},o.CreateDefaultMesh=function(n,i){var t=e.Mesh.CreateGround(n,512,512,32,i,!1);return t},o}(e.Material);e.WaterMaterial=t}(BABYLON||(BABYLON={})),BABYLON.Effect.ShadersStore.waterVertexShader="precision highp float;\r\n\r\n// Attributes\r\nattribute vec3 position;\r\n#ifdef NORMAL\r\nattribute vec3 normal;\r\n#endif\r\n#ifdef UV1\r\nattribute vec2 uv;\r\n#endif\r\n#ifdef UV2\r\nattribute vec2 uv2;\r\n#endif\r\n#ifdef VERTEXCOLOR\r\nattribute vec4 color;\r\n#endif\r\n#ifdef BONES\r\nattribute vec4 matricesIndices;\r\nattribute vec4 matricesWeights;\r\n#endif\r\n\r\n// Uniforms\r\n\r\n#ifdef INSTANCES\r\nattribute vec4 world0;\r\nattribute vec4 world1;\r\nattribute vec4 world2;\r\nattribute vec4 world3;\r\n#else\r\nuniform mat4 world;\r\n#endif\r\n\r\nuniform mat4 view;\r\nuniform mat4 viewProjection;\r\n\r\n#ifdef BUMP\r\nvarying vec2 vNormalUV;\r\nuniform mat4 normalMatrix;\r\nuniform vec2 vNormalInfos;\r\n#endif\r\n\r\n#ifdef BONES\r\nuniform mat4 mBones[BonesPerMesh];\r\n#endif\r\n\r\n#ifdef POINTSIZE\r\nuniform float pointSize;\r\n#endif\r\n\r\n// Output\r\nvarying vec3 vPositionW;\r\n#ifdef NORMAL\r\nvarying vec3 vNormalW;\r\n#endif\r\n\r\n#ifdef VERTEXCOLOR\r\nvarying vec4 vColor;\r\n#endif\r\n\r\n#ifdef CLIPPLANE\r\nuniform vec4 vClipPlane;\r\nvarying float fClipDistance;\r\n#endif\r\n\r\n#ifdef FOG\r\nvarying float fFogDistance;\r\n#endif\r\n\r\n#ifdef SHADOWS\r\n#if defined(SPOTLIGHT0) || defined(DIRLIGHT0)\r\nuniform mat4 lightMatrix0;\r\nvarying vec4 vPositionFromLight0;\r\n#endif\r\n#if defined(SPOTLIGHT1) || defined(DIRLIGHT1)\r\nuniform mat4 lightMatrix1;\r\nvarying vec4 vPositionFromLight1;\r\n#endif\r\n#if defined(SPOTLIGHT2) || defined(DIRLIGHT2)\r\nuniform mat4 lightMatrix2;\r\nvarying vec4 vPositionFromLight2;\r\n#endif\r\n#if defined(SPOTLIGHT3) || defined(DIRLIGHT3)\r\nuniform mat4 lightMatrix3;\r\nvarying vec4 vPositionFromLight3;\r\n#endif\r\n#endif\r\n\r\n// Water uniforms\r\nuniform mat4 worldReflectionViewProjection;\r\nuniform vec2 windDirection;\r\nuniform float waveLength;\r\nuniform float time;\r\nuniform float windForce;\r\nuniform float waveHeight;\r\nuniform float waveSpeed;\r\n\r\n// Water varyings\r\nvarying vec3 vPosition;\r\nvarying vec3 vRefractionMapTexCoord;\r\nvarying vec3 vReflectionMapTexCoord;\r\n\r\nvoid main(void) {\r\n mat4 finalWorld;\r\n\r\n#ifdef INSTANCES\r\n finalWorld = mat4(world0, world1, world2, world3);\r\n#else\r\n finalWorld = world;\r\n#endif\r\n\r\n#ifdef BONES\r\n mat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;\r\n mat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;\r\n mat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;\r\n\r\n#ifdef BONES4\r\n mat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\r\n finalWorld = finalWorld * (m0 + m1 + m2 + m3);\r\n#else\r\n finalWorld = finalWorld * (m0 + m1 + m2);\r\n#endif \r\n\r\n#endif\r\n\r\n vec4 worldPos = finalWorld * vec4(position, 1.0);\r\n vPositionW = vec3(worldPos);\r\n\r\n#ifdef NORMAL\r\n vNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));\r\n#endif\r\n\r\n // Texture coordinates\r\n#ifndef UV1\r\n vec2 uv = vec2(0., 0.);\r\n#endif\r\n#ifndef UV2\r\n vec2 uv2 = vec2(0., 0.);\r\n#endif\r\n\r\n#ifdef BUMP\r\n if (vNormalInfos.x == 0.)\r\n {\r\n vNormalUV = vec2(normalMatrix * vec4((uv * 1.0) / waveLength + time * windForce * windDirection, 1.0, 0.0));\r\n }\r\n else\r\n {\r\n vNormalUV = vec2(normalMatrix * vec4((uv2 * 1.0) / waveLength + time * windForce * windDirection, 1.0, 0.0));\r\n }\r\n#endif\r\n\r\n // Clip plane\r\n#ifdef CLIPPLANE\r\n fClipDistance = dot(worldPos, vClipPlane);\r\n#endif\r\n\r\n // Fog\r\n#ifdef FOG\r\n fFogDistance = (view * worldPos).z;\r\n#endif\r\n\r\n // Shadows\r\n#ifdef SHADOWS\r\n#if defined(SPOTLIGHT0) || defined(DIRLIGHT0)\r\n vPositionFromLight0 = lightMatrix0 * worldPos;\r\n#endif\r\n#if defined(SPOTLIGHT1) || defined(DIRLIGHT1)\r\n vPositionFromLight1 = lightMatrix1 * worldPos;\r\n#endif\r\n#if defined(SPOTLIGHT2) || defined(DIRLIGHT2)\r\n vPositionFromLight2 = lightMatrix2 * worldPos;\r\n#endif\r\n#if defined(SPOTLIGHT3) || defined(DIRLIGHT3)\r\n vPositionFromLight3 = lightMatrix3 * worldPos;\r\n#endif\r\n#endif\r\n\r\n // Vertex color\r\n#ifdef VERTEXCOLOR\r\n vColor = color;\r\n#endif\r\n\r\n // Point size\r\n#ifdef POINTSIZE\r\n gl_PointSize = pointSize;\r\n#endif\r\n\r\n vec3 p = position;\r\n float newY = (sin(((p.x / 0.05) + time * waveSpeed * windForce) * windDirection.x) * waveHeight * 5.0)\r\n + (cos(((p.z / 0.05) + time * waveSpeed * windForce) * windDirection.y) * waveHeight * 5.0);\r\n p.y += abs(newY);\r\n \r\n gl_Position = viewProjection * finalWorld * vec4(p, 1.0);\r\n\r\n#ifdef REFLECTION\r\n worldPos = viewProjection * finalWorld * vec4(p, 1.0);\r\n \r\n // Water\r\n vPosition = position;\r\n \r\n vRefractionMapTexCoord.x = 0.5 * (worldPos.w + worldPos.x);\r\n vRefractionMapTexCoord.y = 0.5 * (worldPos.w + worldPos.y);\r\n vRefractionMapTexCoord.z = worldPos.w;\r\n \r\n worldPos = worldReflectionViewProjection * vec4(position, 1.0);\r\n vReflectionMapTexCoord.x = 0.5 * (worldPos.w + worldPos.x);\r\n vReflectionMapTexCoord.y = 0.5 * (worldPos.w + worldPos.y);\r\n vReflectionMapTexCoord.z = worldPos.w;\r\n#endif\r\n}\r\n",BABYLON.Effect.ShadersStore.waterPixelShader="precision highp float;\n\n// Constants\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\n\n// Input\nvarying vec3 vPositionW;\n\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n// Lights\n#ifdef LIGHT0\nuniform vec4 vLightData0;\nuniform vec4 vLightDiffuse0;\n#ifdef SPECULARTERM\nuniform vec3 vLightSpecular0;\n#endif\n#ifdef SHADOW0\n#if defined(SPOTLIGHT0) || defined(DIRLIGHT0)\nvarying vec4 vPositionFromLight0;\nuniform sampler2D shadowSampler0;\n#else\nuniform samplerCube shadowSampler0;\n#endif\nuniform vec3 shadowsInfo0;\n#endif\n#ifdef SPOTLIGHT0\nuniform vec4 vLightDirection0;\n#endif\n#ifdef HEMILIGHT0\nuniform vec3 vLightGround0;\n#endif\n#endif\n\n#ifdef LIGHT1\nuniform vec4 vLightData1;\nuniform vec4 vLightDiffuse1;\n#ifdef SPECULARTERM\nuniform vec3 vLightSpecular1;\n#endif\n#ifdef SHADOW1\n#if defined(SPOTLIGHT1) || defined(DIRLIGHT1)\nvarying vec4 vPositionFromLight1;\nuniform sampler2D shadowSampler1;\n#else\nuniform samplerCube shadowSampler1;\n#endif\nuniform vec3 shadowsInfo1;\n#endif\n#ifdef SPOTLIGHT1\nuniform vec4 vLightDirection1;\n#endif\n#ifdef HEMILIGHT1\nuniform vec3 vLightGround1;\n#endif\n#endif\n\n#ifdef LIGHT2\nuniform vec4 vLightData2;\nuniform vec4 vLightDiffuse2;\n#ifdef SPECULARTERM\nuniform vec3 vLightSpecular2;\n#endif\n#ifdef SHADOW2\n#if defined(SPOTLIGHT2) || defined(DIRLIGHT2)\nvarying vec4 vPositionFromLight2;\nuniform sampler2D shadowSampler2;\n#else\nuniform samplerCube shadowSampler2;\n#endif\nuniform vec3 shadowsInfo2;\n#endif\n#ifdef SPOTLIGHT2\nuniform vec4 vLightDirection2;\n#endif\n#ifdef HEMILIGHT2\nuniform vec3 vLightGround2;\n#endif\n#endif\n\n#ifdef LIGHT3\nuniform vec4 vLightData3;\nuniform vec4 vLightDiffuse3;\n#ifdef SPECULARTERM\nuniform vec3 vLightSpecular3;\n#endif\n#ifdef SHADOW3\n#if defined(SPOTLIGHT3) || defined(DIRLIGHT3)\nvarying vec4 vPositionFromLight3;\nuniform sampler2D shadowSampler3;\n#else\nuniform samplerCube shadowSampler3;\n#endif\nuniform vec3 shadowsInfo3;\n#endif\n#ifdef SPOTLIGHT3\nuniform vec4 vLightDirection3;\n#endif\n#ifdef HEMILIGHT3\nuniform vec3 vLightGround3;\n#endif\n#endif\n\n// Samplers\n#ifdef BUMP\nvarying vec2 vNormalUV;\nuniform sampler2D normalSampler;\nuniform vec2 vNormalInfos;\n#endif\n\nuniform sampler2D refractionSampler;\nuniform sampler2D reflectionSampler;\n\n// Water uniforms\nconst float LOG2 = 1.442695;\n\nuniform vec3 cameraPosition;\n\nuniform vec4 waterColor;\nuniform float colorBlendFactor;\n\nuniform float bumpHeight;\n\n// Water varyings\nvarying vec3 vRefractionMapTexCoord;\nvarying vec3 vReflectionMapTexCoord;\nvarying vec3 vPosition;\n\n// Shadows\n#ifdef SHADOWS\n\nfloat unpack(vec4 color)\n{\n const vec4 bit_shift = vec4(1.0 / (255.0 * 255.0 * 255.0), 1.0 / (255.0 * 255.0), 1.0 / 255.0, 1.0);\n return dot(color, bit_shift);\n}\n\n#if defined(POINTLIGHT0) || defined(POINTLIGHT1) || defined(POINTLIGHT2) || defined(POINTLIGHT3)\nfloat computeShadowCube(vec3 lightPosition, samplerCube shadowSampler, float darkness, float bias)\n{\n vec3 directionToLight = vPositionW - lightPosition;\n float depth = length(directionToLight);\n\n depth = clamp(depth, 0., 1.);\n\n directionToLight.y = 1.0 - directionToLight.y;\n\n float shadow = unpack(textureCube(shadowSampler, directionToLight)) + bias;\n\n if (depth > shadow)\n {\n return darkness;\n }\n return 1.0;\n}\n\nfloat computeShadowWithPCFCube(vec3 lightPosition, samplerCube shadowSampler, float bias, float darkness)\n{\n vec3 directionToLight = vPositionW - lightPosition;\n float depth = length(directionToLight);\n\n depth = clamp(depth, 0., 1.);\n\n directionToLight.y = 1.0 - directionToLight.y;\n\n float visibility = 1.;\n\n vec3 poissonDisk[4];\n poissonDisk[0] = vec3(-0.094201624, 0.04, -0.039906216);\n poissonDisk[1] = vec3(0.094558609, -0.04, -0.076890725);\n poissonDisk[2] = vec3(-0.094184101, 0.01, -0.092938870);\n poissonDisk[3] = vec3(0.034495938, -0.01, 0.029387760);\n\n // Poisson Sampling\n float biasedDepth = depth - bias;\n\n if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[0])) < biasedDepth) visibility -= 0.25;\n if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[1])) < biasedDepth) visibility -= 0.25;\n if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[2])) < biasedDepth) visibility -= 0.25;\n if (unpack(textureCube(shadowSampler, directionToLight + poissonDisk[3])) < biasedDepth) visibility -= 0.25;\n\n return min(1.0, visibility + darkness);\n}\n#endif\n\n#if defined(SPOTLIGHT0) || defined(SPOTLIGHT1) || defined(SPOTLIGHT2) || defined(SPOTLIGHT3) || defined(DIRLIGHT0) || defined(DIRLIGHT1) || defined(DIRLIGHT2) || defined(DIRLIGHT3)\nfloat computeShadow(vec4 vPositionFromLight, sampler2D shadowSampler, float darkness, float bias)\n{\n vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\n depth = 0.5 * depth + vec3(0.5);\n vec2 uv = depth.xy;\n\n if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)\n {\n return 1.0;\n }\n\n float shadow = unpack(texture2D(shadowSampler, uv)) + bias;\n\n if (depth.z > shadow)\n {\n return darkness;\n }\n return 1.;\n}\n\nfloat computeShadowWithPCF(vec4 vPositionFromLight, sampler2D shadowSampler, float mapSize, float bias, float darkness)\n{\n vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\n depth = 0.5 * depth + vec3(0.5);\n vec2 uv = depth.xy;\n\n if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0)\n {\n return 1.0;\n }\n\n float visibility = 1.;\n\n vec2 poissonDisk[4];\n poissonDisk[0] = vec2(-0.94201624, -0.39906216);\n poissonDisk[1] = vec2(0.94558609, -0.76890725);\n poissonDisk[2] = vec2(-0.094184101, -0.92938870);\n poissonDisk[3] = vec2(0.34495938, 0.29387760);\n\n // Poisson Sampling\n float biasedDepth = depth.z - bias;\n\n if (unpack(texture2D(shadowSampler, uv + poissonDisk[0] / mapSize)) < biasedDepth) visibility -= 0.25;\n if (unpack(texture2D(shadowSampler, uv + poissonDisk[1] / mapSize)) < biasedDepth) visibility -= 0.25;\n if (unpack(texture2D(shadowSampler, uv + poissonDisk[2] / mapSize)) < biasedDepth) visibility -= 0.25;\n if (unpack(texture2D(shadowSampler, uv + poissonDisk[3] / mapSize)) < biasedDepth) visibility -= 0.25;\n\n return min(1.0, visibility + darkness);\n}\n\n// Thanks to http://devmaster.net/\nfloat unpackHalf(vec2 color)\n{\n return color.x + (color.y / 255.0);\n}\n\nfloat linstep(float low, float high, float v) {\n return clamp((v - low) / (high - low), 0.0, 1.0);\n}\n\nfloat ChebychevInequality(vec2 moments, float compare, float bias)\n{\n float p = smoothstep(compare - bias, compare, moments.x);\n float variance = max(moments.y - moments.x * moments.x, 0.02);\n float d = compare - moments.x;\n float p_max = linstep(0.2, 1.0, variance / (variance + d * d));\n\n return clamp(max(p, p_max), 0.0, 1.0);\n}\n\nfloat computeShadowWithVSM(vec4 vPositionFromLight, sampler2D shadowSampler, float bias, float darkness)\n{\n vec3 depth = vPositionFromLight.xyz / vPositionFromLight.w;\n depth = 0.5 * depth + vec3(0.5);\n vec2 uv = depth.xy;\n\n if (uv.x < 0. || uv.x > 1.0 || uv.y < 0. || uv.y > 1.0 || depth.z >= 1.0)\n {\n return 1.0;\n }\n\n vec4 texel = texture2D(shadowSampler, uv);\n\n vec2 moments = vec2(unpackHalf(texel.xy), unpackHalf(texel.zw));\n return min(1.0, 1.0 - ChebychevInequality(moments, depth.z, bias) + darkness);\n}\n#endif\n#endif\n\n#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif\n\n// Fog\n#ifdef FOG\n\n#define FOGMODE_NONE 0.\n#define FOGMODE_EXP 1.\n#define FOGMODE_EXP2 2.\n#define FOGMODE_LINEAR 3.\n#define E 2.71828\n\nuniform vec4 vFogInfos;\nuniform vec3 vFogColor;\nvarying float fFogDistance;\n\nfloat CalcFogFactor()\n{\n float fogCoeff = 1.0;\n float fogStart = vFogInfos.y;\n float fogEnd = vFogInfos.z;\n float fogDensity = vFogInfos.w;\n\n if (FOGMODE_LINEAR == vFogInfos.x)\n {\n fogCoeff = (fogEnd - fFogDistance) / (fogEnd - fogStart);\n }\n else if (FOGMODE_EXP == vFogInfos.x)\n {\n fogCoeff = 1.0 / pow(E, fFogDistance * fogDensity);\n }\n else if (FOGMODE_EXP2 == vFogInfos.x)\n {\n fogCoeff = 1.0 / pow(E, fFogDistance * fFogDistance * fogDensity * fogDensity);\n }\n\n return clamp(fogCoeff, 0.0, 1.0);\n}\n#endif\n\n// Light Computing\nstruct lightingInfo\n{\n vec3 diffuse;\n#ifdef SPECULARTERM\n vec3 specular;\n#endif\n};\n\nlightingInfo computeLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor, float range, float glossiness, vec3 bumpColor) {\n lightingInfo result;\n\n vec3 lightVectorW;\n float attenuation = 1.0;\n if (lightData.w == 0.)\n {\n vec3 direction = lightData.xyz - vPositionW;\n\n attenuation = max(0., 1.0 - length(direction) / range);\n lightVectorW = normalize(direction);\n }\n else\n {\n lightVectorW = normalize(-lightData.xyz);\n }\n\n // diffuse\n float ndl = max(0., dot(vNormal, lightVectorW));\n result.diffuse = ndl * diffuseColor * attenuation;\n\n // Specular\n#ifdef SPECULARTERM\n vec3 angleW = normalize(viewDirectionW + lightVectorW);\n vec3 perturbation = bumpHeight * (bumpColor.rgb - 0.5);\n vec3 halfvec = normalize(angleW + lightVectorW + vec3(perturbation.x, perturbation.y, perturbation.z));\n \n float temp = max(0., dot(vNormal, halfvec));\n temp = pow(temp, max(1., glossiness));\n \n result.specular = temp * specularColor * attenuation;\n#endif\n\n return result;\n}\n\nlightingInfo computeSpotLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec4 lightDirection, vec3 specularColor, vec3 diffuseColor, float range, float glossiness, vec3 bumpColor) {\n lightingInfo result;\n\n vec3 direction = lightData.xyz - vPositionW;\n vec3 lightVectorW = normalize(direction);\n float attenuation = max(0., 1.0 - length(direction) / range);\n\n // diffuse\n float cosAngle = max(0., dot(-lightDirection.xyz, lightVectorW));\n float spotAtten = 0.0;\n\n if (cosAngle >= lightDirection.w)\n {\n cosAngle = max(0., pow(cosAngle, lightData.w));\n spotAtten = clamp((cosAngle - lightDirection.w) / (1. - cosAngle), 0.0, 1.0);\n\n // Diffuse\n float ndl = max(0., dot(vNormal, -lightDirection.xyz));\n result.diffuse = ndl * spotAtten * diffuseColor * attenuation;\n\n // Specular\n#ifdef SPECULARTERM \n vec3 angleW = normalize(viewDirectionW - lightDirection.xyz);\n vec3 perturbation = bumpHeight * (bumpColor.rgb - 0.5);\n vec3 halfvec = normalize(angleW + vec3(perturbation.x, perturbation.y, perturbation.z));\n \n float temp = max(0., dot(vNormal, halfvec));\n temp = pow(temp, max(1., glossiness));\n \n result.specular = specularColor * temp * spotAtten * attenuation;\n#endif\n return result;\n }\n\n result.diffuse = vec3(0.);\n#ifdef SPECULARTERM\n result.specular = vec3(0.);\n#endif\n\n return result;\n}\n\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW, vec3 vNormal, vec4 lightData, vec3 diffuseColor, vec3 specularColor, vec3 groundColor, float glossiness, vec3 bumpColor) {\n lightingInfo result;\n\n // Diffuse\n float ndl = dot(vNormal, lightData.xyz) * 0.5 + 0.5;\n result.diffuse = mix(groundColor, diffuseColor, ndl);\n \n // Specular\n#ifdef SPECULARTERM\n vec3 angleW = normalize(viewDirectionW + lightData.xyz);\n vec3 perturbation = bumpHeight * (bumpColor.rgb - 0.5);\n vec3 halfvec = normalize(angleW + vec3(perturbation.x, perturbation.y, perturbation.z));\n \n float temp = max(0.0, dot(vNormal, halfvec));\n temp = pow(temp, max(1.0, glossiness));\n \n result.specular = temp * specularColor;\n#endif\n\n return result;\n}\n\nvoid main(void) {\n // Clip plane\n#ifdef CLIPPLANE\n if (fClipDistance > 0.0)\n discard;\n#endif\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#ifdef SPECULARTERM\n float glossiness = vSpecularColor.a;\n vec3 specularColor = vSpecularColor.rgb;\n#else\n float glossiness = 0.;\n#endif\n\n // Alpha\n float alpha = vDiffuseColor.a;\n\n#ifdef BUMP\n baseColor = texture2D(normalSampler, vNormalUV);\n vec3 bumpColor = baseColor.rgb;\n\n#ifdef ALPHATEST\n if (baseColor.a < 0.4)\n discard;\n#endif\n\n baseColor.rgb *= vNormalInfos.y;\n#else\n vec3 bumpColor = vec3(1.0);\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 vec2 perturbation = bumpHeight * (baseColor.rg - 0.5);\n#else\n vec3 normalW = vec3(1.0, 1.0, 1.0);\n vec2 perturbation = bumpHeight * (vec2(1.0, 1.0) - 0.5);\n#endif\n\n#ifdef REFLECTION\n // Water\n vec3 eyeVector = normalize(vEyePosition - vPosition);\n \n vec2 projectedRefractionTexCoords = clamp(vRefractionMapTexCoord.xy / vRefractionMapTexCoord.z + perturbation, 0.0, 1.0);\n vec4 refractiveColor = texture2D(refractionSampler, projectedRefractionTexCoords);\n \n vec2 projectedReflectionTexCoords = clamp(vReflectionMapTexCoord.xy / vReflectionMapTexCoord.z + perturbation, 0.0, 1.0);\n vec4 reflectiveColor = texture2D(reflectionSampler, projectedReflectionTexCoords);\n \n vec3 upVector = vec3(0.0, 1.0, 0.0);\n \n float fresnelTerm = max(dot(eyeVector, upVector), 0.0);\n \n vec4 combinedColor = refractiveColor * fresnelTerm + reflectiveColor * (1.0 - fresnelTerm);\n \n baseColor = colorBlendFactor * waterColor + (1.0 - colorBlendFactor) * combinedColor;\n#endif\n\n // Lighting\n vec3 diffuseBase = vec3(0., 0., 0.);\n#ifdef SPECULARTERM\n vec3 specularBase = vec3(0., 0., 0.);\n#endif\n float shadow = 1.;\n\n#ifdef LIGHT0\n#ifndef SPECULARTERM\n vec3 vLightSpecular0 = vec3(0.0);\n#endif\n#ifdef SPOTLIGHT0\n lightingInfo info = computeSpotLighting(viewDirectionW, normalW, vLightData0, vLightDirection0, vLightDiffuse0.rgb, vLightSpecular0, vLightDiffuse0.a, glossiness, bumpColor);\n#endif\n#ifdef HEMILIGHT0\n lightingInfo info = computeHemisphericLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0.rgb, vLightSpecular0, vLightGround0, glossiness, bumpColor);\n#endif\n#if defined(POINTLIGHT0) || defined(DIRLIGHT0)\n lightingInfo info = computeLighting(viewDirectionW, normalW, vLightData0, vLightDiffuse0.rgb, vLightSpecular0, vLightDiffuse0.a, glossiness, bumpColor);\n#endif\n#ifdef SHADOW0\n#ifdef SHADOWVSM0\n shadow = computeShadowWithVSM(vPositionFromLight0, shadowSampler0, shadowsInfo0.z, shadowsInfo0.x);\n#else\n#ifdef SHADOWPCF0\n #if defined(POINTLIGHT0)\n shadow = computeShadowWithPCFCube(vLightData0.xyz, shadowSampler0, shadowsInfo0.z, shadowsInfo0.x);\n #else\n shadow = computeShadowWithPCF(vPositionFromLight0, shadowSampler0, shadowsInfo0.y, shadowsInfo0.z, shadowsInfo0.x);\n #endif\n#else\n #if defined(POINTLIGHT0)\n shadow = computeShadowCube(vLightData0.xyz, shadowSampler0, shadowsInfo0.x, shadowsInfo0.z);\n #else\n shadow = computeShadow(vPositionFromLight0, shadowSampler0, shadowsInfo0.x, shadowsInfo0.z);\n #endif\n#endif\n#endif\n#else\n shadow = 1.;\n#endif\n diffuseBase += info.diffuse * shadow;\n#ifdef SPECULARTERM\n specularBase += info.specular * shadow;\n#endif\n#endif\n\n#ifdef LIGHT1\n#ifndef SPECULARTERM\n vec3 vLightSpecular1 = vec3(0.0);\n#endif\n#ifdef SPOTLIGHT1\n info = computeSpotLighting(viewDirectionW, normalW, vLightData1, vLightDirection1, vLightDiffuse1.rgb, vLightSpecular1, vLightDiffuse1.a, glossiness, bumpColor);\n#endif\n#ifdef HEMILIGHT1\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1.rgb, vLightSpecular1, vLightGround1.a, glossiness, bumpColor);\n#endif\n#if defined(POINTLIGHT1) || defined(DIRLIGHT1)\n info = computeLighting(viewDirectionW, normalW, vLightData1, vLightDiffuse1.rgb, vLightSpecular1, vLightDiffuse1.a, glossiness, bumpColor);\n#endif\n#ifdef SHADOW1\n#ifdef SHADOWVSM1\n shadow = computeShadowWithVSM(vPositionFromLight1, shadowSampler1, shadowsInfo1.z, shadowsInfo1.x);\n#else\n#ifdef SHADOWPCF1\n#if defined(POINTLIGHT1)\n shadow = computeShadowWithPCFCube(vLightData1.xyz, shadowSampler1, shadowsInfo1.z, shadowsInfo1.x);\n#else\n shadow = computeShadowWithPCF(vPositionFromLight1, shadowSampler1, shadowsInfo1.y, shadowsInfo1.z, shadowsInfo1.x);\n#endif\n#else\n #if defined(POINTLIGHT1)\n shadow = computeShadowCube(vLightData1.xyz, shadowSampler1, shadowsInfo1.x, shadowsInfo1.z);\n #else\n shadow = computeShadow(vPositionFromLight1, shadowSampler1, shadowsInfo1.x, shadowsInfo1.z);\n #endif\n#endif\n#endif\n#else\n shadow = 1.;\n#endif\n diffuseBase += info.diffuse * shadow;\n#ifdef SPECULARTERM\n specularBase += info.specular * shadow;\n#endif\n#endif\n\n#ifdef LIGHT2\n#ifndef SPECULARTERM\n vec3 vLightSpecular2 = vec3(0.0);\n#endif\n#ifdef SPOTLIGHT2\n info = computeSpotLighting(viewDirectionW, normalW, vLightData2, vLightDirection2, vLightDiffuse2.rgb, vLightSpecular2, vLightDiffuse2.a, glossiness, bumpColor);\n#endif\n#ifdef HEMILIGHT2\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2.rgb, vLightSpecular2, vLightGround2, glossiness, bumpColor);\n#endif\n#if defined(POINTLIGHT2) || defined(DIRLIGHT2)\n info = computeLighting(viewDirectionW, normalW, vLightData2, vLightDiffuse2.rgb, vLightSpecular2, vLightDiffuse2.a, glossiness, bumpColor);\n#endif\n#ifdef SHADOW2\n#ifdef SHADOWVSM2\n shadow = computeShadowWithVSM(vPositionFromLight2, shadowSampler2, shadowsInfo2.z, shadowsInfo2.x);\n#else\n#ifdef SHADOWPCF2\n#if defined(POINTLIGHT2)\n shadow = computeShadowWithPCFCube(vLightData2.xyz, shadowSampler2, shadowsInfo2.z, shadowsInfo2.x);\n#else\n shadow = computeShadowWithPCF(vPositionFromLight2, shadowSampler2, shadowsInfo2.y, shadowsInfo2.z, shadowsInfo2.x);\n#endif\n#else\n #if defined(POINTLIGHT2)\n shadow = computeShadowCube(vLightData2.xyz, shadowSampler2, shadowsInfo2.x, shadowsInfo2.z);\n #else\n shadow = computeShadow(vPositionFromLight2, shadowSampler2, shadowsInfo2.x, shadowsInfo2.z);\n #endif\n#endif \n#endif \n#else\n shadow = 1.;\n#endif\n diffuseBase += info.diffuse * shadow;\n#ifdef SPECULARTERM\n specularBase += info.specular * shadow;\n#endif\n#endif\n\n#ifdef LIGHT3\n#ifndef SPECULARTERM\n vec3 vLightSpecular3 = vec3(0.0);\n#endif\n#ifdef SPOTLIGHT3\n info = computeSpotLighting(viewDirectionW, normalW, vLightData3, vLightDirection3, vLightDiffuse3.rgb, vLightSpecular3, vLightDiffuse3.a, glossiness, bumpColor);\n#endif\n#ifdef HEMILIGHT3\n info = computeHemisphericLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3.rgb, vLightSpecular3, vLightGround3, glossiness, bumpColor);\n#endif\n#if defined(POINTLIGHT3) || defined(DIRLIGHT3)\n info = computeLighting(viewDirectionW, normalW, vLightData3, vLightDiffuse3.rgb, vLightSpecular3, vLightDiffuse3.a, glossiness, bumpColor);\n#endif\n#ifdef SHADOW3\n#ifdef SHADOWVSM3\n shadow = computeShadowWithVSM(vPositionFromLight3, shadowSampler3, shadowsInfo3.z, shadowsInfo3.x);\n#else\n#ifdef SHADOWPCF3\n#if defined(POINTLIGHT3)\n shadow = computeShadowWithPCFCube(vLightData3.xyz, shadowSampler3, shadowsInfo3.z, shadowsInfo3.x);\n#else\n shadow = computeShadowWithPCF(vPositionFromLight3, shadowSampler3, shadowsInfo3.y, shadowsInfo3.z, shadowsInfo3.x);\n#endif\n#else\n #if defined(POINTLIGHT3)\n shadow = computeShadowCube(vLightData3.xyz, shadowSampler3, shadowsInfo3.x, shadowsInfo3.z);\n #else\n shadow = computeShadow(vPositionFromLight3, shadowSampler3, shadowsInfo3.x, shadowsInfo3.z);\n #endif\n#endif \n#endif \n#else\n shadow = 1.;\n#endif\n diffuseBase += info.diffuse * shadow;\n#ifdef SPECULARTERM\n specularBase += info.specular * shadow;\n#endif\n#endif\n\n#ifdef VERTEXALPHA\n alpha *= vColor.a;\n#endif\n\n#ifdef SPECULARTERM\n vec3 finalSpecular = specularBase * specularColor;\n#else\n vec3 finalSpecular = vec3(0.0);\n#endif\n\n vec3 finalDiffuse = clamp(diffuseBase * diffuseColor, 0.0, 1.0) * baseColor.rgb;\n\n // Composition\n vec4 color = vec4(finalDiffuse + finalSpecular, alpha);\n\n#ifdef FOG\n float fog = CalcFogFactor();\n color.rgb = fog * color.rgb + (1.0 - fog) * vFogColor;\n#endif\n \n gl_FragColor = color;\n}";
|