babylon.lavaMaterial.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  3. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
  4. switch (arguments.length) {
  5. case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
  6. case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
  7. case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
  8. }
  9. };
  10. var BABYLON;
  11. (function (BABYLON) {
  12. var maxSimultaneousLights = 4;
  13. var LavaMaterialDefines = (function (_super) {
  14. __extends(LavaMaterialDefines, _super);
  15. function LavaMaterialDefines() {
  16. _super.call(this);
  17. this.DIFFUSE = false;
  18. this.CLIPPLANE = false;
  19. this.ALPHATEST = false;
  20. this.POINTSIZE = false;
  21. this.FOG = false;
  22. this.LIGHT0 = false;
  23. this.LIGHT1 = false;
  24. this.LIGHT2 = false;
  25. this.LIGHT3 = false;
  26. this.SPOTLIGHT0 = false;
  27. this.SPOTLIGHT1 = false;
  28. this.SPOTLIGHT2 = false;
  29. this.SPOTLIGHT3 = false;
  30. this.HEMILIGHT0 = false;
  31. this.HEMILIGHT1 = false;
  32. this.HEMILIGHT2 = false;
  33. this.HEMILIGHT3 = false;
  34. this.DIRLIGHT0 = false;
  35. this.DIRLIGHT1 = false;
  36. this.DIRLIGHT2 = false;
  37. this.DIRLIGHT3 = false;
  38. this.POINTLIGHT0 = false;
  39. this.POINTLIGHT1 = false;
  40. this.POINTLIGHT2 = false;
  41. this.POINTLIGHT3 = false;
  42. this.SHADOW0 = false;
  43. this.SHADOW1 = false;
  44. this.SHADOW2 = false;
  45. this.SHADOW3 = false;
  46. this.SHADOWS = false;
  47. this.SHADOWVSM0 = false;
  48. this.SHADOWVSM1 = false;
  49. this.SHADOWVSM2 = false;
  50. this.SHADOWVSM3 = false;
  51. this.SHADOWPCF0 = false;
  52. this.SHADOWPCF1 = false;
  53. this.SHADOWPCF2 = false;
  54. this.SHADOWPCF3 = false;
  55. this.NORMAL = false;
  56. this.UV1 = false;
  57. this.UV2 = false;
  58. this.VERTEXCOLOR = false;
  59. this.VERTEXALPHA = false;
  60. this.NUM_BONE_INFLUENCERS = 0;
  61. this.BonesPerMesh = 0;
  62. this.INSTANCES = false;
  63. this._keys = Object.keys(this);
  64. }
  65. return LavaMaterialDefines;
  66. })(BABYLON.MaterialDefines);
  67. var LavaMaterial = (function (_super) {
  68. __extends(LavaMaterial, _super);
  69. function LavaMaterial(name, scene) {
  70. _super.call(this, name, scene);
  71. this.speed = 1;
  72. this.movingSpeed = 1;
  73. this.lowFrequencySpeed = 1;
  74. this.fogDensity = 0.15;
  75. this._lastTime = 0;
  76. this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  77. this.disableLighting = false;
  78. this._worldViewProjectionMatrix = BABYLON.Matrix.Zero();
  79. this._scaledDiffuse = new BABYLON.Color3();
  80. this._defines = new LavaMaterialDefines();
  81. this._cachedDefines = new LavaMaterialDefines();
  82. this._cachedDefines.BonesPerMesh = -1;
  83. }
  84. LavaMaterial.prototype.needAlphaBlending = function () {
  85. return (this.alpha < 1.0);
  86. };
  87. LavaMaterial.prototype.needAlphaTesting = function () {
  88. return false;
  89. };
  90. LavaMaterial.prototype.getAlphaTestTexture = function () {
  91. return null;
  92. };
  93. // Methods
  94. LavaMaterial.prototype._checkCache = function (scene, mesh, useInstances) {
  95. if (!mesh) {
  96. return true;
  97. }
  98. if (this._defines.INSTANCES !== useInstances) {
  99. return false;
  100. }
  101. if (mesh._materialDefines && mesh._materialDefines.isEqual(this._defines)) {
  102. return true;
  103. }
  104. return false;
  105. };
  106. LavaMaterial.prototype.isReady = function (mesh, useInstances) {
  107. if (this.checkReadyOnlyOnce) {
  108. if (this._wasPreviouslyReady) {
  109. return true;
  110. }
  111. }
  112. var scene = this.getScene();
  113. if (!this.checkReadyOnEveryCall) {
  114. if (this._renderId === scene.getRenderId()) {
  115. if (this._checkCache(scene, mesh, useInstances)) {
  116. return true;
  117. }
  118. }
  119. }
  120. var engine = scene.getEngine();
  121. var needUVs = false;
  122. this._defines.reset();
  123. // Textures
  124. if (scene.texturesEnabled) {
  125. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  126. if (!this.diffuseTexture.isReady()) {
  127. return false;
  128. }
  129. else {
  130. needUVs = true;
  131. this._defines.DIFFUSE = true;
  132. }
  133. }
  134. }
  135. // Effect
  136. if (scene.clipPlane) {
  137. this._defines.CLIPPLANE = true;
  138. }
  139. if (engine.getAlphaTesting()) {
  140. this._defines.ALPHATEST = true;
  141. }
  142. // Point size
  143. if (this.pointsCloud || scene.forcePointsCloud) {
  144. this._defines.POINTSIZE = true;
  145. }
  146. // Fog
  147. if (scene.fogEnabled && mesh && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled) {
  148. this._defines.FOG = true;
  149. }
  150. var lightIndex = 0;
  151. if (scene.lightsEnabled && !this.disableLighting) {
  152. BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines);
  153. }
  154. // Attribs
  155. if (mesh) {
  156. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
  157. this._defines.NORMAL = true;
  158. }
  159. if (needUVs) {
  160. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
  161. this._defines.UV1 = true;
  162. }
  163. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind)) {
  164. this._defines.UV2 = true;
  165. }
  166. }
  167. if (mesh.useVertexColors && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind)) {
  168. this._defines.VERTEXCOLOR = true;
  169. if (mesh.hasVertexAlpha) {
  170. this._defines.VERTEXALPHA = true;
  171. }
  172. }
  173. if (mesh.useBones && mesh.computeBonesUsingShaders) {
  174. this._defines.NUM_BONE_INFLUENCERS = mesh.numBoneInfluencers;
  175. this._defines.BonesPerMesh = (mesh.skeleton.bones.length + 1);
  176. }
  177. // Instances
  178. if (useInstances) {
  179. this._defines.INSTANCES = true;
  180. }
  181. }
  182. // Get correct effect
  183. if (!this._defines.isEqual(this._cachedDefines)) {
  184. this._defines.cloneTo(this._cachedDefines);
  185. scene.resetCachedMaterial();
  186. // Fallbacks
  187. var fallbacks = new BABYLON.EffectFallbacks();
  188. if (this._defines.FOG) {
  189. fallbacks.addFallback(1, "FOG");
  190. }
  191. BABYLON.MaterialHelper.HandleFallbacksForShadows(this._defines, fallbacks);
  192. if (this._defines.NUM_BONE_INFLUENCERS > 0) {
  193. fallbacks.addCPUSkinningFallback(0, mesh);
  194. }
  195. //Attributes
  196. var attribs = [BABYLON.VertexBuffer.PositionKind];
  197. if (this._defines.NORMAL) {
  198. attribs.push(BABYLON.VertexBuffer.NormalKind);
  199. }
  200. if (this._defines.UV1) {
  201. attribs.push(BABYLON.VertexBuffer.UVKind);
  202. }
  203. if (this._defines.UV2) {
  204. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  205. }
  206. if (this._defines.VERTEXCOLOR) {
  207. attribs.push(BABYLON.VertexBuffer.ColorKind);
  208. }
  209. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
  210. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, this._defines);
  211. // Legacy browser patch
  212. var shaderName = "lava";
  213. var join = this._defines.toString();
  214. this._effect = scene.getEngine().createEffect(shaderName, attribs, ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  215. "vLightData0", "vLightDiffuse0", "vLightSpecular0", "vLightDirection0", "vLightGround0", "lightMatrix0",
  216. "vLightData1", "vLightDiffuse1", "vLightSpecular1", "vLightDirection1", "vLightGround1", "lightMatrix1",
  217. "vLightData2", "vLightDiffuse2", "vLightSpecular2", "vLightDirection2", "vLightGround2", "lightMatrix2",
  218. "vLightData3", "vLightDiffuse3", "vLightSpecular3", "vLightDirection3", "vLightGround3", "lightMatrix3",
  219. "vFogInfos", "vFogColor", "pointSize",
  220. "vDiffuseInfos",
  221. "mBones",
  222. "vClipPlane", "diffuseMatrix",
  223. "shadowsInfo0", "shadowsInfo1", "shadowsInfo2", "shadowsInfo3", "depthValues",
  224. "time", "speed", "movingSpeed",
  225. "fogColor", "fogDensity", "lowFrequencySpeed"
  226. ], ["diffuseSampler",
  227. "shadowSampler0", "shadowSampler1", "shadowSampler2", "shadowSampler3", "noiseTexture"
  228. ], join, fallbacks, this.onCompiled, this.onError);
  229. }
  230. if (!this._effect.isReady()) {
  231. return false;
  232. }
  233. this._renderId = scene.getRenderId();
  234. this._wasPreviouslyReady = true;
  235. if (mesh) {
  236. if (!mesh._materialDefines) {
  237. mesh._materialDefines = new LavaMaterialDefines();
  238. }
  239. this._defines.cloneTo(mesh._materialDefines);
  240. }
  241. return true;
  242. };
  243. LavaMaterial.prototype.bindOnlyWorldMatrix = function (world) {
  244. this._effect.setMatrix("world", world);
  245. };
  246. LavaMaterial.prototype.bind = function (world, mesh) {
  247. var scene = this.getScene();
  248. // Matrices
  249. this.bindOnlyWorldMatrix(world);
  250. this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
  251. // Bones
  252. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._effect);
  253. if (scene.getCachedMaterial() !== this) {
  254. // Textures
  255. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  256. this._effect.setTexture("diffuseSampler", this.diffuseTexture);
  257. this._effect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
  258. this._effect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
  259. }
  260. if (this.noiseTexture) {
  261. this._effect.setTexture("noiseTexture", this.noiseTexture);
  262. }
  263. // Clip plane
  264. BABYLON.MaterialHelper.BindClipPlane(this._effect, scene);
  265. // Point size
  266. if (this.pointsCloud) {
  267. this._effect.setFloat("pointSize", this.pointSize);
  268. }
  269. this._effect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
  270. }
  271. this._effect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
  272. if (scene.lightsEnabled && !this.disableLighting) {
  273. BABYLON.MaterialHelper.BindLights(scene, mesh, this._effect, this._defines);
  274. }
  275. // View
  276. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  277. this._effect.setMatrix("view", scene.getViewMatrix());
  278. }
  279. // Fog
  280. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._effect);
  281. this._lastTime += scene.getEngine().getDeltaTime();
  282. this._effect.setFloat("time", this._lastTime * this.speed / 1000);
  283. if (!this.fogColor) {
  284. this.fogColor = BABYLON.Color3.Black();
  285. }
  286. this._effect.setColor3("fogColor", this.fogColor);
  287. this._effect.setFloat("fogDensity", this.fogDensity);
  288. this._effect.setFloat("lowFrequencySpeed", this.lowFrequencySpeed);
  289. this._effect.setFloat("movingSpeed", this.movingSpeed);
  290. _super.prototype.bind.call(this, world, mesh);
  291. };
  292. LavaMaterial.prototype.getAnimatables = function () {
  293. var results = [];
  294. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  295. results.push(this.diffuseTexture);
  296. }
  297. if (this.noiseTexture && this.noiseTexture.animations && this.noiseTexture.animations.length > 0) {
  298. results.push(this.noiseTexture);
  299. }
  300. return results;
  301. };
  302. LavaMaterial.prototype.dispose = function (forceDisposeEffect) {
  303. if (this.diffuseTexture) {
  304. this.diffuseTexture.dispose();
  305. }
  306. if (this.noiseTexture) {
  307. this.noiseTexture.dispose();
  308. }
  309. _super.prototype.dispose.call(this, forceDisposeEffect);
  310. };
  311. LavaMaterial.prototype.clone = function (name) {
  312. var _this = this;
  313. return BABYLON.SerializationHelper.Clone(function () { return new LavaMaterial(name, _this.getScene()); }, this);
  314. };
  315. LavaMaterial.prototype.serialize = function () {
  316. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  317. serializationObject.customType = "BABYLON.LavaMaterial";
  318. return serializationObject;
  319. };
  320. // Statics
  321. LavaMaterial.Parse = function (source, scene, rootUrl) {
  322. return BABYLON.SerializationHelper.Parse(function () { return new LavaMaterial(source.name, scene); }, source, scene, rootUrl);
  323. };
  324. __decorate([
  325. BABYLON.serializeAsTexture()
  326. ], LavaMaterial.prototype, "diffuseTexture");
  327. __decorate([
  328. BABYLON.serializeAsTexture()
  329. ], LavaMaterial.prototype, "noiseTexture");
  330. __decorate([
  331. BABYLON.serializeAsColor3()
  332. ], LavaMaterial.prototype, "fogColor");
  333. __decorate([
  334. BABYLON.serialize()
  335. ], LavaMaterial.prototype, "speed");
  336. __decorate([
  337. BABYLON.serialize()
  338. ], LavaMaterial.prototype, "movingSpeed");
  339. __decorate([
  340. BABYLON.serialize()
  341. ], LavaMaterial.prototype, "lowFrequencySpeed");
  342. __decorate([
  343. BABYLON.serialize()
  344. ], LavaMaterial.prototype, "fogDensity");
  345. __decorate([
  346. BABYLON.serializeAsColor3()
  347. ], LavaMaterial.prototype, "diffuseColor");
  348. __decorate([
  349. BABYLON.serialize()
  350. ], LavaMaterial.prototype, "disableLighting");
  351. return LavaMaterial;
  352. })(BABYLON.Material);
  353. BABYLON.LavaMaterial = LavaMaterial;
  354. })(BABYLON || (BABYLON = {}));
  355. BABYLON.Effect.ShadersStore['lavaVertexShader'] = "precision highp float;\n\nuniform float time;\nuniform float lowFrequencySpeed;\n\nvarying float noise;\n\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#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<shadowsVertexDeclaration>\n\n\n\nvec3 mod289(vec3 x)\n{\nreturn x-floor(x*(1.0/289.0))*289.0;\n}\nvec4 mod289(vec4 x)\n{\nreturn x-floor(x*(1.0/289.0))*289.0;\n}\nvec4 permute(vec4 x)\n{\nreturn mod289(((x*34.0)+1.0)*x);\n}\nvec4 taylorInvSqrt(vec4 r)\n{\nreturn 1.79284291400159-0.85373472095314*r;\n}\nvec3 fade(vec3 t) {\nreturn t*t*t*(t*(t*6.0-15.0)+10.0);\n}\n\nfloat pnoise(vec3 P,vec3 rep)\n{\nvec3 Pi0=mod(floor(P),rep); \nvec3 Pi1=mod(Pi0+vec3(1.0),rep); \nPi0=mod289(Pi0);\nPi1=mod289(Pi1);\nvec3 Pf0=fract(P); \nvec3 Pf1=Pf0-vec3(1.0); \nvec4 ix=vec4(Pi0.x,Pi1.x,Pi0.x,Pi1.x);\nvec4 iy=vec4(Pi0.yy,Pi1.yy);\nvec4 iz0=Pi0.zzzz;\nvec4 iz1=Pi1.zzzz;\nvec4 ixy=permute(permute(ix)+iy);\nvec4 ixy0=permute(ixy+iz0);\nvec4 ixy1=permute(ixy+iz1);\nvec4 gx0=ixy0*(1.0/7.0);\nvec4 gy0=fract(floor(gx0)*(1.0/7.0))-0.5;\ngx0=fract(gx0);\nvec4 gz0=vec4(0.5)-abs(gx0)-abs(gy0);\nvec4 sz0=step(gz0,vec4(0.0));\ngx0-=sz0*(step(0.0,gx0)-0.5);\ngy0-=sz0*(step(0.0,gy0)-0.5);\nvec4 gx1=ixy1*(1.0/7.0);\nvec4 gy1=fract(floor(gx1)*(1.0/7.0))-0.5;\ngx1=fract(gx1);\nvec4 gz1=vec4(0.5)-abs(gx1)-abs(gy1);\nvec4 sz1=step(gz1,vec4(0.0));\ngx1-=sz1*(step(0.0,gx1)-0.5);\ngy1-=sz1*(step(0.0,gy1)-0.5);\nvec3 g000=vec3(gx0.x,gy0.x,gz0.x);\nvec3 g100=vec3(gx0.y,gy0.y,gz0.y);\nvec3 g010=vec3(gx0.z,gy0.z,gz0.z);\nvec3 g110=vec3(gx0.w,gy0.w,gz0.w);\nvec3 g001=vec3(gx1.x,gy1.x,gz1.x);\nvec3 g101=vec3(gx1.y,gy1.y,gz1.y);\nvec3 g011=vec3(gx1.z,gy1.z,gz1.z);\nvec3 g111=vec3(gx1.w,gy1.w,gz1.w);\nvec4 norm0=taylorInvSqrt(vec4(dot(g000,g000),dot(g010,g010),dot(g100,g100),dot(g110,g110)));\ng000*=norm0.x;\ng010*=norm0.y;\ng100*=norm0.z;\ng110*=norm0.w;\nvec4 norm1=taylorInvSqrt(vec4(dot(g001,g001),dot(g011,g011),dot(g101,g101),dot(g111,g111)));\ng001*=norm1.x;\ng011*=norm1.y;\ng101*=norm1.z;\ng111*=norm1.w;\nfloat n000=dot(g000,Pf0);\nfloat n100=dot(g100,vec3(Pf1.x,Pf0.yz));\nfloat n010=dot(g010,vec3(Pf0.x,Pf1.y,Pf0.z));\nfloat n110=dot(g110,vec3(Pf1.xy,Pf0.z));\nfloat n001=dot(g001,vec3(Pf0.xy,Pf1.z));\nfloat n101=dot(g101,vec3(Pf1.x,Pf0.y,Pf1.z));\nfloat n011=dot(g011,vec3(Pf0.x,Pf1.yz));\nfloat n111=dot(g111,Pf1);\nvec3 fade_xyz=fade(Pf0);\nvec4 n_z=mix(vec4(n000,n100,n010,n110),vec4(n001,n101,n011,n111),fade_xyz.z);\nvec2 n_yz=mix(n_z.xy,n_z.zw,fade_xyz.y);\nfloat n_xyz=mix(n_yz.x,n_yz.y,fade_xyz.x);\nreturn 2.2*n_xyz;\n}\n\nfloat turbulence( vec3 p ) {\nfloat w=100.0;\nfloat t=-.5;\nfor (float f=1.0 ; f<=10.0 ; f++ ){\nfloat power=pow( 2.0,f );\nt+=abs( pnoise( vec3( power*p ),vec3( 10.0,10.0,10.0 ) )/power );\n}\nreturn t;\n}\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\n#ifdef NORMAL\n\nnoise=10.0*-.10*turbulence( .5*normal+time*1.15 );\n\nfloat b=lowFrequencySpeed*5.0*pnoise( 0.05*position +vec3(time*1.025),vec3( 100.0 ) );\n\nfloat displacement =-1.5*noise+b;\n\nvec3 newPosition=position+normal*displacement;\ngl_Position=viewProjection*finalWorld*vec4( newPosition,1.0 );\nvec4 worldPos=finalWorld*vec4(newPosition,1.0);\nvPositionW=vec3(worldPos);\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\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{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}";
  356. BABYLON.Effect.ShadersStore['lavaPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nvarying vec3 vPositionW;\n\nuniform float time;\nuniform float speed;\nuniform float movingSpeed;\nuniform vec3 fogColor;\nuniform sampler2D noiseTexture;\nuniform float fogDensity;\n\nvarying float noise;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<lightFragmentDeclaration>[0]\n#include<lightFragmentDeclaration>[1]\n#include<lightFragmentDeclaration>[2]\n#include<lightFragmentDeclaration>[3]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nfloat random( vec3 scale,float seed ){\nreturn fract( sin( dot( gl_FragCoord.xyz+seed,scale ) )*43758.5453+seed ) ;\n}\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef DIFFUSE\n\nvec4 noiseTex=texture2D( noiseTexture,vDiffuseUV );\nvec2 T1=vDiffuseUV+vec2( 1.5,-1.5 )*time*0.02;\nvec2 T2=vDiffuseUV+vec2( -0.5,2.0 )*time*0.01*speed;\nT1.x+=noiseTex.x*2.0;\nT1.y+=noiseTex.y*2.0;\nT2.x-=noiseTex.y*0.2+time*0.001*movingSpeed;\nT2.y+=noiseTex.z*0.2+time*0.002*movingSpeed;\nfloat p=texture2D( noiseTexture,T1*3.0 ).a;\nvec4 lavaColor=texture2D( diffuseSampler,T2*4.0);\nvec4 temp=lavaColor*( vec4( p,p,p,p )*2. )+( lavaColor*lavaColor-0.1 );\nbaseColor=temp;\nfloat depth=gl_FragCoord.z*4.0;\nconst float LOG2=1.442695;\nfloat fogFactor=exp2(-fogDensity*fogDensity*depth*depth*LOG2 );\nfogFactor=1.0-clamp( fogFactor,0.0,1.0 );\nbaseColor=mix( baseColor,vec4( fogColor,baseColor.w ),fogFactor );\ndiffuseColor=baseColor.rgb;\n\n\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#include<lightFragment>[0]\n#include<lightFragment>[1]\n#include<lightFragment>[2]\n#include<lightFragment>[3]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor,0.0,1.0)*baseColor.rgb;\n\nvec4 color=vec4(finalDiffuse,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";