babylon.lavaMaterial.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. var BABYLON;
  3. (function (BABYLON) {
  4. var maxSimultaneousLights = 4;
  5. var LavaMaterialDefines = (function (_super) {
  6. __extends(LavaMaterialDefines, _super);
  7. function LavaMaterialDefines() {
  8. _super.call(this);
  9. this.DIFFUSE = false;
  10. this.CLIPPLANE = false;
  11. this.ALPHATEST = false;
  12. this.POINTSIZE = false;
  13. this.FOG = false;
  14. this.LIGHT0 = false;
  15. this.LIGHT1 = false;
  16. this.LIGHT2 = false;
  17. this.LIGHT3 = false;
  18. this.SPOTLIGHT0 = false;
  19. this.SPOTLIGHT1 = false;
  20. this.SPOTLIGHT2 = false;
  21. this.SPOTLIGHT3 = false;
  22. this.HEMILIGHT0 = false;
  23. this.HEMILIGHT1 = false;
  24. this.HEMILIGHT2 = false;
  25. this.HEMILIGHT3 = false;
  26. this.DIRLIGHT0 = false;
  27. this.DIRLIGHT1 = false;
  28. this.DIRLIGHT2 = false;
  29. this.DIRLIGHT3 = false;
  30. this.POINTLIGHT0 = false;
  31. this.POINTLIGHT1 = false;
  32. this.POINTLIGHT2 = false;
  33. this.POINTLIGHT3 = false;
  34. this.SHADOW0 = false;
  35. this.SHADOW1 = false;
  36. this.SHADOW2 = false;
  37. this.SHADOW3 = false;
  38. this.SHADOWS = false;
  39. this.SHADOWVSM0 = false;
  40. this.SHADOWVSM1 = false;
  41. this.SHADOWVSM2 = false;
  42. this.SHADOWVSM3 = false;
  43. this.SHADOWPCF0 = false;
  44. this.SHADOWPCF1 = false;
  45. this.SHADOWPCF2 = false;
  46. this.SHADOWPCF3 = false;
  47. this.NORMAL = false;
  48. this.UV1 = false;
  49. this.UV2 = false;
  50. this.VERTEXCOLOR = false;
  51. this.VERTEXALPHA = false;
  52. this.NUM_BONE_INFLUENCERS = 0;
  53. this.BonesPerMesh = 0;
  54. this.INSTANCES = false;
  55. this._keys = Object.keys(this);
  56. }
  57. return LavaMaterialDefines;
  58. })(BABYLON.MaterialDefines);
  59. var LavaMaterial = (function (_super) {
  60. __extends(LavaMaterial, _super);
  61. function LavaMaterial(name, scene) {
  62. _super.call(this, name, scene);
  63. this.speed = 1;
  64. this.movingSpeed = 1;
  65. this.lowFrequencySpeed = 1;
  66. this.fogDensity = 0.15;
  67. this._lastTime = 0;
  68. this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  69. this.disableLighting = false;
  70. this._worldViewProjectionMatrix = BABYLON.Matrix.Zero();
  71. this._scaledDiffuse = new BABYLON.Color3();
  72. this._defines = new LavaMaterialDefines();
  73. this._cachedDefines = new LavaMaterialDefines();
  74. this._cachedDefines.BonesPerMesh = -1;
  75. }
  76. LavaMaterial.prototype.needAlphaBlending = function () {
  77. return (this.alpha < 1.0);
  78. };
  79. LavaMaterial.prototype.needAlphaTesting = function () {
  80. return false;
  81. };
  82. LavaMaterial.prototype.getAlphaTestTexture = function () {
  83. return null;
  84. };
  85. // Methods
  86. LavaMaterial.prototype._checkCache = function (scene, mesh, useInstances) {
  87. if (!mesh) {
  88. return true;
  89. }
  90. if (this._defines.INSTANCES !== useInstances) {
  91. return false;
  92. }
  93. if (mesh._materialDefines && mesh._materialDefines.isEqual(this._defines)) {
  94. return true;
  95. }
  96. return false;
  97. };
  98. LavaMaterial.prototype.isReady = function (mesh, useInstances) {
  99. if (this.checkReadyOnlyOnce) {
  100. if (this._wasPreviouslyReady) {
  101. return true;
  102. }
  103. }
  104. var scene = this.getScene();
  105. if (!this.checkReadyOnEveryCall) {
  106. if (this._renderId === scene.getRenderId()) {
  107. if (this._checkCache(scene, mesh, useInstances)) {
  108. return true;
  109. }
  110. }
  111. }
  112. var engine = scene.getEngine();
  113. var needUVs = false;
  114. this._defines.reset();
  115. // Textures
  116. if (scene.texturesEnabled) {
  117. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  118. if (!this.diffuseTexture.isReady()) {
  119. return false;
  120. }
  121. else {
  122. needUVs = true;
  123. this._defines.DIFFUSE = true;
  124. }
  125. }
  126. }
  127. // Effect
  128. if (scene.clipPlane) {
  129. this._defines.CLIPPLANE = true;
  130. }
  131. if (engine.getAlphaTesting()) {
  132. this._defines.ALPHATEST = true;
  133. }
  134. // Point size
  135. if (this.pointsCloud || scene.forcePointsCloud) {
  136. this._defines.POINTSIZE = true;
  137. }
  138. // Fog
  139. if (scene.fogEnabled && mesh && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled) {
  140. this._defines.FOG = true;
  141. }
  142. var lightIndex = 0;
  143. if (scene.lightsEnabled && !this.disableLighting) {
  144. BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines);
  145. }
  146. // Attribs
  147. if (mesh) {
  148. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
  149. this._defines.NORMAL = true;
  150. }
  151. if (needUVs) {
  152. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
  153. this._defines.UV1 = true;
  154. }
  155. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind)) {
  156. this._defines.UV2 = true;
  157. }
  158. }
  159. if (mesh.useVertexColors && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind)) {
  160. this._defines.VERTEXCOLOR = true;
  161. if (mesh.hasVertexAlpha) {
  162. this._defines.VERTEXALPHA = true;
  163. }
  164. }
  165. if (mesh.useBones && mesh.computeBonesUsingShaders) {
  166. this._defines.NUM_BONE_INFLUENCERS = mesh.numBoneInfluencers;
  167. this._defines.BonesPerMesh = (mesh.skeleton.bones.length + 1);
  168. }
  169. // Instances
  170. if (useInstances) {
  171. this._defines.INSTANCES = true;
  172. }
  173. }
  174. // Get correct effect
  175. if (!this._defines.isEqual(this._cachedDefines)) {
  176. this._defines.cloneTo(this._cachedDefines);
  177. scene.resetCachedMaterial();
  178. // Fallbacks
  179. var fallbacks = new BABYLON.EffectFallbacks();
  180. if (this._defines.FOG) {
  181. fallbacks.addFallback(1, "FOG");
  182. }
  183. BABYLON.MaterialHelper.HandleFallbacksForShadows(this._defines, fallbacks);
  184. if (this._defines.NUM_BONE_INFLUENCERS > 0) {
  185. fallbacks.addCPUSkinningFallback(0, mesh);
  186. }
  187. //Attributes
  188. var attribs = [BABYLON.VertexBuffer.PositionKind];
  189. if (this._defines.NORMAL) {
  190. attribs.push(BABYLON.VertexBuffer.NormalKind);
  191. }
  192. if (this._defines.UV1) {
  193. attribs.push(BABYLON.VertexBuffer.UVKind);
  194. }
  195. if (this._defines.UV2) {
  196. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  197. }
  198. if (this._defines.VERTEXCOLOR) {
  199. attribs.push(BABYLON.VertexBuffer.ColorKind);
  200. }
  201. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
  202. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, this._defines);
  203. // Legacy browser patch
  204. var shaderName = "lava";
  205. var join = this._defines.toString();
  206. this._effect = scene.getEngine().createEffect(shaderName, attribs, ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  207. "vLightData0", "vLightDiffuse0", "vLightSpecular0", "vLightDirection0", "vLightGround0", "lightMatrix0",
  208. "vLightData1", "vLightDiffuse1", "vLightSpecular1", "vLightDirection1", "vLightGround1", "lightMatrix1",
  209. "vLightData2", "vLightDiffuse2", "vLightSpecular2", "vLightDirection2", "vLightGround2", "lightMatrix2",
  210. "vLightData3", "vLightDiffuse3", "vLightSpecular3", "vLightDirection3", "vLightGround3", "lightMatrix3",
  211. "vFogInfos", "vFogColor", "pointSize",
  212. "vDiffuseInfos",
  213. "mBones",
  214. "vClipPlane", "diffuseMatrix",
  215. "shadowsInfo0", "shadowsInfo1", "shadowsInfo2", "shadowsInfo3", "depthValues",
  216. "time", "speed", "movingSpeed",
  217. "fogColor", "fogDensity", "lowFrequencySpeed"
  218. ], ["diffuseSampler",
  219. "shadowSampler0", "shadowSampler1", "shadowSampler2", "shadowSampler3", "noiseTexture"
  220. ], join, fallbacks, this.onCompiled, this.onError);
  221. }
  222. if (!this._effect.isReady()) {
  223. return false;
  224. }
  225. this._renderId = scene.getRenderId();
  226. this._wasPreviouslyReady = true;
  227. if (mesh) {
  228. if (!mesh._materialDefines) {
  229. mesh._materialDefines = new LavaMaterialDefines();
  230. }
  231. this._defines.cloneTo(mesh._materialDefines);
  232. }
  233. return true;
  234. };
  235. LavaMaterial.prototype.bindOnlyWorldMatrix = function (world) {
  236. this._effect.setMatrix("world", world);
  237. };
  238. LavaMaterial.prototype.bind = function (world, mesh) {
  239. var scene = this.getScene();
  240. // Matrices
  241. this.bindOnlyWorldMatrix(world);
  242. this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
  243. // Bones
  244. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._effect);
  245. if (scene.getCachedMaterial() !== this) {
  246. // Textures
  247. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  248. this._effect.setTexture("diffuseSampler", this.diffuseTexture);
  249. this._effect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
  250. this._effect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
  251. }
  252. if (this.noiseTexture) {
  253. this._effect.setTexture("noiseTexture", this.noiseTexture);
  254. }
  255. // Clip plane
  256. BABYLON.MaterialHelper.BindClipPlane(this._effect, scene);
  257. // Point size
  258. if (this.pointsCloud) {
  259. this._effect.setFloat("pointSize", this.pointSize);
  260. }
  261. this._effect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
  262. }
  263. this._effect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
  264. if (scene.lightsEnabled && !this.disableLighting) {
  265. BABYLON.MaterialHelper.BindLights(scene, mesh, this._effect, this._defines);
  266. }
  267. // View
  268. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  269. this._effect.setMatrix("view", scene.getViewMatrix());
  270. }
  271. // Fog
  272. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._effect);
  273. this._lastTime += scene.getEngine().getDeltaTime();
  274. this._effect.setFloat("time", this._lastTime * this.speed / 1000);
  275. if (!this.fogColor) {
  276. this.fogColor = BABYLON.Color3.Black();
  277. }
  278. this._effect.setColor3("fogColor", this.fogColor);
  279. this._effect.setFloat("fogDensity", this.fogDensity);
  280. this._effect.setFloat("lowFrequencySpeed", this.lowFrequencySpeed);
  281. this._effect.setFloat("movingSpeed", this.movingSpeed);
  282. _super.prototype.bind.call(this, world, mesh);
  283. };
  284. LavaMaterial.prototype.getAnimatables = function () {
  285. var results = [];
  286. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  287. results.push(this.diffuseTexture);
  288. }
  289. if (this.noiseTexture && this.noiseTexture.animations && this.noiseTexture.animations.length > 0) {
  290. results.push(this.noiseTexture);
  291. }
  292. return results;
  293. };
  294. LavaMaterial.prototype.dispose = function (forceDisposeEffect) {
  295. if (this.diffuseTexture) {
  296. this.diffuseTexture.dispose();
  297. }
  298. if (this.noiseTexture) {
  299. this.noiseTexture.dispose();
  300. }
  301. _super.prototype.dispose.call(this, forceDisposeEffect);
  302. };
  303. LavaMaterial.prototype.clone = function (name) {
  304. var newMaterial = new LavaMaterial(name, this.getScene());
  305. // Base material
  306. this.copyTo(newMaterial);
  307. // Lava material
  308. if (this.diffuseTexture && this.diffuseTexture.clone) {
  309. newMaterial.diffuseTexture = this.diffuseTexture.clone();
  310. }
  311. if (this.noiseTexture && this.noiseTexture.clone) {
  312. newMaterial.noiseTexture = this.noiseTexture.clone();
  313. }
  314. if (this.fogColor && this.fogColor.clone) {
  315. newMaterial.fogColor = this.fogColor.clone();
  316. }
  317. return newMaterial;
  318. };
  319. LavaMaterial.prototype.serialize = function () {
  320. var serializationObject = _super.prototype.serialize.call(this);
  321. serializationObject.customType = "BABYLON.LavaMaterial";
  322. serializationObject.diffuseColor = this.diffuseColor.asArray();
  323. serializationObject.fogColor = this.fogColor.asArray();
  324. serializationObject.speed = this.speed;
  325. serializationObject.movingSpeed = this.movingSpeed;
  326. serializationObject.lowFrequencySpeed = this.lowFrequencySpeed;
  327. serializationObject.fogDensity = this.fogDensity;
  328. serializationObject.checkReadyOnlyOnce = this.checkReadyOnlyOnce;
  329. if (this.diffuseTexture) {
  330. serializationObject.diffuseTexture = this.diffuseTexture.serialize();
  331. }
  332. if (this.noiseTexture) {
  333. serializationObject.noiseTexture = this.noiseTexture.serialize();
  334. }
  335. return serializationObject;
  336. };
  337. LavaMaterial.Parse = function (source, scene, rootUrl) {
  338. var material = new LavaMaterial(source.name, scene);
  339. material.diffuseColor = BABYLON.Color3.FromArray(source.diffuseColor);
  340. material.speed = source.speed;
  341. material.fogColor = BABYLON.Color3.FromArray(source.fogColor);
  342. material.movingSpeed = source.movingSpeed;
  343. material.lowFrequencySpeed = source.lowFrequencySpeed;
  344. material.fogDensity = source.lowFrequencySpeed;
  345. material.alpha = source.alpha;
  346. material.id = source.id;
  347. BABYLON.Tags.AddTagsTo(material, source.tags);
  348. material.backFaceCulling = source.backFaceCulling;
  349. material.wireframe = source.wireframe;
  350. if (source.diffuseTexture) {
  351. material.diffuseTexture = BABYLON.Texture.Parse(source.diffuseTexture, scene, rootUrl);
  352. }
  353. if (source.noiseTexture) {
  354. material.noiseTexture = BABYLON.Texture.Parse(source.noiseTexture, scene, rootUrl);
  355. }
  356. if (source.checkReadyOnlyOnce) {
  357. material.checkReadyOnlyOnce = source.checkReadyOnlyOnce;
  358. }
  359. return material;
  360. };
  361. return LavaMaterial;
  362. })(BABYLON.Material);
  363. BABYLON.LavaMaterial = LavaMaterial;
  364. })(BABYLON || (BABYLON = {}));
  365. 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\tvec4 worldPos = finalWorld * vec4(newPosition, 1.0);\n\tvPositionW = vec3(worldPos);\n\n\tvNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));\n#endif\n\n\t// Texture coordinates\n#ifndef UV1\n\tvec2 uv = vec2(0., 0.);\n#endif\n#ifndef UV2\n\tvec2 uv2 = vec2(0., 0.);\n#endif\n\n#ifdef DIFFUSE\n\tif (vDiffuseInfos.x == 0.)\n\t{\n\t\tvDiffuseUV = vec2(diffuseMatrix * vec4(uv, 1.0, 0.0));\n\t}\n\telse\n\t{\n\t\tvDiffuseUV = vec2(diffuseMatrix * vec4(uv2, 1.0, 0.0));\n\t}\n#endif\n\n\t// Clip plane\n#include<clipPlaneVertex>\n\n\t// Fog\n#include<fogVertex>\n#include<shadowsVertex>\n\n\t// Vertex color\n#ifdef VERTEXCOLOR\n\tvColor = color;\n#endif\n\n\t// Point size\n#ifdef POINTSIZE\n\tgl_PointSize = pointSize;\n#endif\n}";
  366. 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\tvec3 viewDirectionW = normalize(vEyePosition - vPositionW);\n\n\t// Base color\n\tvec4 baseColor = vec4(1., 1., 1., 1.);\n\tvec3 diffuseColor = vDiffuseColor.rgb;\n\n\t// Alpha\n\tfloat alpha = vDiffuseColor.a;\n\n\n\n#ifdef DIFFUSE\n ////// MAGMA ///\n\n\tvec4 noiseTex = texture2D( noiseTexture, vDiffuseUV );\n\tvec2 T1 = vDiffuseUV + vec2( 1.5, -1.5 ) * time * 0.02;\n\tvec2 T2 = vDiffuseUV + vec2( -0.5, 2.0 ) * time * 0.01 * speed;\n\n\tT1.x += noiseTex.x * 2.0;\n\tT1.y += noiseTex.y * 2.0;\n\tT2.x -= noiseTex.y * 0.2 + time*0.001*movingSpeed;\n\tT2.y += noiseTex.z * 0.2 + time*0.002*movingSpeed;\n\n\tfloat p = texture2D( noiseTexture, T1 * 3.0 ).a;\n\n\tvec4 lavaColor = texture2D( diffuseSampler, T2 * 4.0);\n\tvec4 temp = lavaColor * ( vec4( p, p, p, p ) * 2. ) + ( lavaColor * lavaColor - 0.1 );\n\n\tbaseColor = temp;\n\n\tfloat depth = gl_FragCoord.z * 4.0;\n\tconst 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//\tbaseColor = texture2D(diffuseSampler, vDiffuseUV);\n\n#ifdef ALPHATEST\n\tif (baseColor.a < 0.4)\n\t\tdiscard;\n#endif\n\n\tbaseColor.rgb *= vDiffuseInfos.y;\n#endif\n\n#ifdef VERTEXCOLOR\n\tbaseColor.rgb *= vColor.rgb;\n#endif\n\n\t// Bump\n#ifdef NORMAL\n\tvec3 normalW = normalize(vNormalW);\n#else\n\tvec3 normalW = vec3(1.0, 1.0, 1.0);\n#endif\n\n\t// Lighting\n\tvec3 diffuseBase = vec3(0., 0., 0.);\n\tfloat 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\talpha *= vColor.a;\n#endif\n\n\tvec3 finalDiffuse = clamp(diffuseBase * diffuseColor, 0.0, 1.0) * baseColor.rgb;\n\n\t// Composition\n\tvec4 color = vec4(finalDiffuse, alpha);\n\n#include<fogFragment>\n\n\tgl_FragColor = color;\n}";