babylon.lavaMaterial.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("babylonjs"));
  4. else if(typeof define === 'function' && define.amd)
  5. define("babylonjs-materials", ["babylonjs"], factory);
  6. else if(typeof exports === 'object')
  7. exports["babylonjs-materials"] = factory(require("babylonjs"));
  8. else
  9. root["MATLIB"] = factory(root["BABYLON"]);
  10. })(window, function(__WEBPACK_EXTERNAL_MODULE_babylonjs__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = "./legacy/legacy-lava.ts");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "../node_modules/webpack/buildin/global.js":
  99. /*!*************************************************!*\
  100. !*** ../node_modules/webpack/buildin/global.js ***!
  101. \*************************************************/
  102. /*! no static exports found */
  103. /***/ (function(module, exports) {
  104. var g;
  105. // This works in non-strict mode
  106. g = (function() {
  107. return this;
  108. })();
  109. try {
  110. // This works if eval is allowed (see CSP)
  111. g = g || Function("return this")() || (1, eval)("this");
  112. } catch (e) {
  113. // This works if the window reference is available
  114. if (typeof window === "object") g = window;
  115. }
  116. // g can still be undefined, but nothing to do about it...
  117. // We return undefined, instead of nothing here, so it's
  118. // easier to handle this case. if(!global) { ...}
  119. module.exports = g;
  120. /***/ }),
  121. /***/ "./legacy/legacy-lava.ts":
  122. /*!*******************************!*\
  123. !*** ./legacy/legacy-lava.ts ***!
  124. \*******************************/
  125. /*! no static exports found */
  126. /***/ (function(module, exports, __webpack_require__) {
  127. "use strict";
  128. /* WEBPACK VAR INJECTION */(function(global) {
  129. function __export(m) {
  130. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  131. }
  132. Object.defineProperty(exports, "__esModule", { value: true });
  133. var MatLib = __webpack_require__(/*! ../src/lava/index */ "./src/lava/index.ts");
  134. /**
  135. * This is the entry point for the UMD module.
  136. * The entry point for a future ESM package should be index.ts
  137. */
  138. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  139. if (typeof globalObject !== "undefined") {
  140. for (var key in MatLib) {
  141. globalObject.BABYLON[key] = MatLib[key];
  142. }
  143. }
  144. __export(__webpack_require__(/*! ../src/lava/index */ "./src/lava/index.ts"));
  145. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../node_modules/webpack/buildin/global.js */ "../node_modules/webpack/buildin/global.js")))
  146. /***/ }),
  147. /***/ "./src/lava/index.ts":
  148. /*!***************************!*\
  149. !*** ./src/lava/index.ts ***!
  150. \***************************/
  151. /*! no static exports found */
  152. /***/ (function(module, exports, __webpack_require__) {
  153. "use strict";
  154. function __export(m) {
  155. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  156. }
  157. Object.defineProperty(exports, "__esModule", { value: true });
  158. __export(__webpack_require__(/*! ./lavaMaterial */ "./src/lava/lavaMaterial.ts"));
  159. /***/ }),
  160. /***/ "./src/lava/lava.fragment.fx":
  161. /*!***********************************!*\
  162. !*** ./src/lava/lava.fragment.fx ***!
  163. \***********************************/
  164. /*! no static exports found */
  165. /***/ (function(module, exports) {
  166. module.exports = "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<helperFunctions>\n\n#include<__decl__lightFragment>[0]\n#include<__decl__lightFragment>[1]\n#include<__decl__lightFragment>[2]\n#include<__decl__lightFragment>[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\n#include<depthPrePass>\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#ifdef UNLIT\nvec3 diffuseBase=vec3(1.,1.,1.);\n#else\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#endif\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}"
  167. /***/ }),
  168. /***/ "./src/lava/lava.vertex.fx":
  169. /*!*********************************!*\
  170. !*** ./src/lava/lava.vertex.fx ***!
  171. \*********************************/
  172. /*! no static exports found */
  173. /***/ (function(module, exports) {
  174. module.exports = "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<__decl__lightFragment>[0..maxSimultaneousLights]\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>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}"
  175. /***/ }),
  176. /***/ "./src/lava/lavaMaterial.ts":
  177. /*!**********************************!*\
  178. !*** ./src/lava/lavaMaterial.ts ***!
  179. \**********************************/
  180. /*! no static exports found */
  181. /***/ (function(module, exports, __webpack_require__) {
  182. "use strict";
  183. var __extends = (this && this.__extends) || (function () {
  184. var extendStatics = function (d, b) {
  185. extendStatics = Object.setPrototypeOf ||
  186. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  187. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  188. return extendStatics(d, b);
  189. }
  190. return function (d, b) {
  191. extendStatics(d, b);
  192. function __() { this.constructor = d; }
  193. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  194. };
  195. })();
  196. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  197. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  198. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  199. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  200. return c > 3 && r && Object.defineProperty(target, key, r), r;
  201. };
  202. Object.defineProperty(exports, "__esModule", { value: true });
  203. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  204. babylonjs_1.Effect.ShadersStore["lavaPixelShader"] = __webpack_require__(/*! ./lava.fragment.fx */ "./src/lava/lava.fragment.fx");
  205. babylonjs_1.Effect.ShadersStore["lavaVertexShader"] = __webpack_require__(/*! ./lava.vertex.fx */ "./src/lava/lava.vertex.fx");
  206. var LavaMaterialDefines = /** @class */ (function (_super) {
  207. __extends(LavaMaterialDefines, _super);
  208. function LavaMaterialDefines() {
  209. var _this = _super.call(this) || this;
  210. _this.DIFFUSE = false;
  211. _this.CLIPPLANE = false;
  212. _this.CLIPPLANE2 = false;
  213. _this.CLIPPLANE3 = false;
  214. _this.CLIPPLANE4 = false;
  215. _this.ALPHATEST = false;
  216. _this.DEPTHPREPASS = false;
  217. _this.POINTSIZE = false;
  218. _this.FOG = false;
  219. _this.LIGHT0 = false;
  220. _this.LIGHT1 = false;
  221. _this.LIGHT2 = false;
  222. _this.LIGHT3 = false;
  223. _this.SPOTLIGHT0 = false;
  224. _this.SPOTLIGHT1 = false;
  225. _this.SPOTLIGHT2 = false;
  226. _this.SPOTLIGHT3 = false;
  227. _this.HEMILIGHT0 = false;
  228. _this.HEMILIGHT1 = false;
  229. _this.HEMILIGHT2 = false;
  230. _this.HEMILIGHT3 = false;
  231. _this.DIRLIGHT0 = false;
  232. _this.DIRLIGHT1 = false;
  233. _this.DIRLIGHT2 = false;
  234. _this.DIRLIGHT3 = false;
  235. _this.POINTLIGHT0 = false;
  236. _this.POINTLIGHT1 = false;
  237. _this.POINTLIGHT2 = false;
  238. _this.POINTLIGHT3 = false;
  239. _this.SHADOW0 = false;
  240. _this.SHADOW1 = false;
  241. _this.SHADOW2 = false;
  242. _this.SHADOW3 = false;
  243. _this.SHADOWS = false;
  244. _this.SHADOWESM0 = false;
  245. _this.SHADOWESM1 = false;
  246. _this.SHADOWESM2 = false;
  247. _this.SHADOWESM3 = false;
  248. _this.SHADOWPOISSON0 = false;
  249. _this.SHADOWPOISSON1 = false;
  250. _this.SHADOWPOISSON2 = false;
  251. _this.SHADOWPOISSON3 = false;
  252. _this.SHADOWPCF0 = false;
  253. _this.SHADOWPCF1 = false;
  254. _this.SHADOWPCF2 = false;
  255. _this.SHADOWPCF3 = false;
  256. _this.SHADOWPCSS0 = false;
  257. _this.SHADOWPCSS1 = false;
  258. _this.SHADOWPCSS2 = false;
  259. _this.SHADOWPCSS3 = false;
  260. _this.NORMAL = false;
  261. _this.UV1 = false;
  262. _this.UV2 = false;
  263. _this.VERTEXCOLOR = false;
  264. _this.VERTEXALPHA = false;
  265. _this.NUM_BONE_INFLUENCERS = 0;
  266. _this.BonesPerMesh = 0;
  267. _this.INSTANCES = false;
  268. _this.UNLIT = false;
  269. _this.rebuild();
  270. return _this;
  271. }
  272. return LavaMaterialDefines;
  273. }(babylonjs_1.MaterialDefines));
  274. var LavaMaterial = /** @class */ (function (_super) {
  275. __extends(LavaMaterial, _super);
  276. function LavaMaterial(name, scene) {
  277. var _this = _super.call(this, name, scene) || this;
  278. _this.speed = 1;
  279. _this.movingSpeed = 1;
  280. _this.lowFrequencySpeed = 1;
  281. _this.fogDensity = 0.15;
  282. _this._lastTime = 0;
  283. _this.diffuseColor = new babylonjs_1.Color3(1, 1, 1);
  284. _this._disableLighting = false;
  285. _this._unlit = false;
  286. _this._maxSimultaneousLights = 4;
  287. _this._scaledDiffuse = new babylonjs_1.Color3();
  288. return _this;
  289. }
  290. LavaMaterial.prototype.needAlphaBlending = function () {
  291. return (this.alpha < 1.0);
  292. };
  293. LavaMaterial.prototype.needAlphaTesting = function () {
  294. return false;
  295. };
  296. LavaMaterial.prototype.getAlphaTestTexture = function () {
  297. return null;
  298. };
  299. // Methods
  300. LavaMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  301. if (this.isFrozen) {
  302. if (this._wasPreviouslyReady && subMesh.effect) {
  303. return true;
  304. }
  305. }
  306. if (!subMesh._materialDefines) {
  307. subMesh._materialDefines = new LavaMaterialDefines();
  308. }
  309. var defines = subMesh._materialDefines;
  310. var scene = this.getScene();
  311. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  312. if (this._renderId === scene.getRenderId()) {
  313. return true;
  314. }
  315. }
  316. var engine = scene.getEngine();
  317. // Textures
  318. if (defines._areTexturesDirty) {
  319. defines._needUVs = false;
  320. if (scene.texturesEnabled) {
  321. if (this._diffuseTexture && babylonjs_1.StandardMaterial.DiffuseTextureEnabled) {
  322. if (!this._diffuseTexture.isReady()) {
  323. return false;
  324. }
  325. else {
  326. defines._needUVs = true;
  327. defines.DIFFUSE = true;
  328. }
  329. }
  330. }
  331. }
  332. // Misc.
  333. babylonjs_1.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  334. // Lights
  335. defines._needNormals = true;
  336. babylonjs_1.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  337. // Values that need to be evaluated on every frame
  338. babylonjs_1.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  339. // Attribs
  340. babylonjs_1.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  341. // Get correct effect
  342. if (defines.isDirty) {
  343. defines.markAsProcessed();
  344. scene.resetCachedMaterial();
  345. // Fallbacks
  346. var fallbacks = new babylonjs_1.EffectFallbacks();
  347. if (defines.FOG) {
  348. fallbacks.addFallback(1, "FOG");
  349. }
  350. babylonjs_1.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks);
  351. if (defines.NUM_BONE_INFLUENCERS > 0) {
  352. fallbacks.addCPUSkinningFallback(0, mesh);
  353. }
  354. //Attributes
  355. var attribs = [babylonjs_1.VertexBuffer.PositionKind];
  356. if (defines.NORMAL) {
  357. attribs.push(babylonjs_1.VertexBuffer.NormalKind);
  358. }
  359. if (defines.UV1) {
  360. attribs.push(babylonjs_1.VertexBuffer.UVKind);
  361. }
  362. if (defines.UV2) {
  363. attribs.push(babylonjs_1.VertexBuffer.UV2Kind);
  364. }
  365. if (defines.VERTEXCOLOR) {
  366. attribs.push(babylonjs_1.VertexBuffer.ColorKind);
  367. }
  368. babylonjs_1.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  369. babylonjs_1.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  370. // Legacy browser patch
  371. var shaderName = "lava";
  372. var join = defines.toString();
  373. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  374. "vFogInfos", "vFogColor", "pointSize",
  375. "vDiffuseInfos",
  376. "mBones",
  377. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "diffuseMatrix",
  378. "time", "speed", "movingSpeed",
  379. "fogColor", "fogDensity", "lowFrequencySpeed"
  380. ];
  381. var samplers = ["diffuseSampler",
  382. "noiseTexture"
  383. ];
  384. var uniformBuffers = new Array();
  385. babylonjs_1.MaterialHelper.PrepareUniformsAndSamplersList({
  386. uniformsNames: uniforms,
  387. uniformBuffersNames: uniformBuffers,
  388. samplers: samplers,
  389. defines: defines,
  390. maxSimultaneousLights: this.maxSimultaneousLights
  391. });
  392. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  393. attributes: attribs,
  394. uniformsNames: uniforms,
  395. uniformBuffersNames: uniformBuffers,
  396. samplers: samplers,
  397. defines: join,
  398. fallbacks: fallbacks,
  399. onCompiled: this.onCompiled,
  400. onError: this.onError,
  401. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  402. }, engine), defines);
  403. }
  404. if (!subMesh.effect || !subMesh.effect.isReady()) {
  405. return false;
  406. }
  407. this._renderId = scene.getRenderId();
  408. this._wasPreviouslyReady = true;
  409. return true;
  410. };
  411. LavaMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  412. var scene = this.getScene();
  413. var defines = subMesh._materialDefines;
  414. if (!defines) {
  415. return;
  416. }
  417. var effect = subMesh.effect;
  418. if (!effect) {
  419. return;
  420. }
  421. this._activeEffect = effect;
  422. defines.UNLIT = this._unlit;
  423. // Matrices
  424. this.bindOnlyWorldMatrix(world);
  425. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  426. // Bones
  427. babylonjs_1.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  428. if (this._mustRebind(scene, effect)) {
  429. // Textures
  430. if (this.diffuseTexture && babylonjs_1.StandardMaterial.DiffuseTextureEnabled) {
  431. this._activeEffect.setTexture("diffuseSampler", this.diffuseTexture);
  432. this._activeEffect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
  433. this._activeEffect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
  434. }
  435. if (this.noiseTexture) {
  436. this._activeEffect.setTexture("noiseTexture", this.noiseTexture);
  437. }
  438. // Clip plane
  439. babylonjs_1.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  440. // Point size
  441. if (this.pointsCloud) {
  442. this._activeEffect.setFloat("pointSize", this.pointSize);
  443. }
  444. babylonjs_1.MaterialHelper.BindEyePosition(effect, scene);
  445. }
  446. this._activeEffect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
  447. if (scene.lightsEnabled && !this.disableLighting) {
  448. babylonjs_1.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines);
  449. }
  450. // View
  451. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== babylonjs_1.Scene.FOGMODE_NONE) {
  452. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  453. }
  454. // Fog
  455. babylonjs_1.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  456. this._lastTime += scene.getEngine().getDeltaTime();
  457. this._activeEffect.setFloat("time", this._lastTime * this.speed / 1000);
  458. if (!this.fogColor) {
  459. this.fogColor = babylonjs_1.Color3.Black();
  460. }
  461. this._activeEffect.setColor3("fogColor", this.fogColor);
  462. this._activeEffect.setFloat("fogDensity", this.fogDensity);
  463. this._activeEffect.setFloat("lowFrequencySpeed", this.lowFrequencySpeed);
  464. this._activeEffect.setFloat("movingSpeed", this.movingSpeed);
  465. this._afterBind(mesh, this._activeEffect);
  466. };
  467. LavaMaterial.prototype.getAnimatables = function () {
  468. var results = [];
  469. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  470. results.push(this.diffuseTexture);
  471. }
  472. if (this.noiseTexture && this.noiseTexture.animations && this.noiseTexture.animations.length > 0) {
  473. results.push(this.noiseTexture);
  474. }
  475. return results;
  476. };
  477. LavaMaterial.prototype.getActiveTextures = function () {
  478. var activeTextures = _super.prototype.getActiveTextures.call(this);
  479. if (this._diffuseTexture) {
  480. activeTextures.push(this._diffuseTexture);
  481. }
  482. return activeTextures;
  483. };
  484. LavaMaterial.prototype.hasTexture = function (texture) {
  485. if (_super.prototype.hasTexture.call(this, texture)) {
  486. return true;
  487. }
  488. if (this.diffuseTexture === texture) {
  489. return true;
  490. }
  491. return false;
  492. };
  493. LavaMaterial.prototype.dispose = function (forceDisposeEffect) {
  494. if (this.diffuseTexture) {
  495. this.diffuseTexture.dispose();
  496. }
  497. if (this.noiseTexture) {
  498. this.noiseTexture.dispose();
  499. }
  500. _super.prototype.dispose.call(this, forceDisposeEffect);
  501. };
  502. LavaMaterial.prototype.clone = function (name) {
  503. var _this = this;
  504. return babylonjs_1.SerializationHelper.Clone(function () { return new LavaMaterial(name, _this.getScene()); }, this);
  505. };
  506. LavaMaterial.prototype.serialize = function () {
  507. var serializationObject = babylonjs_1.SerializationHelper.Serialize(this);
  508. serializationObject.customType = "BABYLON.LavaMaterial";
  509. return serializationObject;
  510. };
  511. LavaMaterial.prototype.getClassName = function () {
  512. return "LavaMaterial";
  513. };
  514. // Statics
  515. LavaMaterial.Parse = function (source, scene, rootUrl) {
  516. return babylonjs_1.SerializationHelper.Parse(function () { return new LavaMaterial(source.name, scene); }, source, scene, rootUrl);
  517. };
  518. __decorate([
  519. babylonjs_1.serializeAsTexture("diffuseTexture")
  520. ], LavaMaterial.prototype, "_diffuseTexture", void 0);
  521. __decorate([
  522. babylonjs_1.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  523. ], LavaMaterial.prototype, "diffuseTexture", void 0);
  524. __decorate([
  525. babylonjs_1.serializeAsTexture()
  526. ], LavaMaterial.prototype, "noiseTexture", void 0);
  527. __decorate([
  528. babylonjs_1.serializeAsColor3()
  529. ], LavaMaterial.prototype, "fogColor", void 0);
  530. __decorate([
  531. babylonjs_1.serialize()
  532. ], LavaMaterial.prototype, "speed", void 0);
  533. __decorate([
  534. babylonjs_1.serialize()
  535. ], LavaMaterial.prototype, "movingSpeed", void 0);
  536. __decorate([
  537. babylonjs_1.serialize()
  538. ], LavaMaterial.prototype, "lowFrequencySpeed", void 0);
  539. __decorate([
  540. babylonjs_1.serialize()
  541. ], LavaMaterial.prototype, "fogDensity", void 0);
  542. __decorate([
  543. babylonjs_1.serializeAsColor3()
  544. ], LavaMaterial.prototype, "diffuseColor", void 0);
  545. __decorate([
  546. babylonjs_1.serialize("disableLighting")
  547. ], LavaMaterial.prototype, "_disableLighting", void 0);
  548. __decorate([
  549. babylonjs_1.expandToProperty("_markAllSubMeshesAsLightsDirty")
  550. ], LavaMaterial.prototype, "disableLighting", void 0);
  551. __decorate([
  552. babylonjs_1.serialize("unlit")
  553. ], LavaMaterial.prototype, "_unlit", void 0);
  554. __decorate([
  555. babylonjs_1.expandToProperty("_markAllSubMeshesAsLightsDirty")
  556. ], LavaMaterial.prototype, "unlit", void 0);
  557. __decorate([
  558. babylonjs_1.serialize("maxSimultaneousLights")
  559. ], LavaMaterial.prototype, "_maxSimultaneousLights", void 0);
  560. __decorate([
  561. babylonjs_1.expandToProperty("_markAllSubMeshesAsLightsDirty")
  562. ], LavaMaterial.prototype, "maxSimultaneousLights", void 0);
  563. return LavaMaterial;
  564. }(babylonjs_1.PushMaterial));
  565. exports.LavaMaterial = LavaMaterial;
  566. /***/ }),
  567. /***/ "babylonjs":
  568. /*!****************************************************************************************************!*\
  569. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  570. \****************************************************************************************************/
  571. /*! no static exports found */
  572. /***/ (function(module, exports) {
  573. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs__;
  574. /***/ })
  575. /******/ });
  576. });
  577. //# sourceMappingURL=babylon.lavaMaterial.js.map