babylon.backgroundMaterial.js 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = Object.setPrototypeOf ||
  4. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6. return function (d, b) {
  7. extendStatics(d, b);
  8. function __() { this.constructor = d; }
  9. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10. };
  11. })();
  12. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  13. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  15. 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;
  16. return c > 3 && r && Object.defineProperty(target, key, r), r;
  17. };
  18. var BABYLON;
  19. (function (BABYLON) {
  20. /**
  21. * Background material defines definition.
  22. */
  23. var BackgroundMaterialDefines = /** @class */ (function (_super) {
  24. __extends(BackgroundMaterialDefines, _super);
  25. /**
  26. * Constructor of the defines.
  27. */
  28. function BackgroundMaterialDefines() {
  29. var _this = _super.call(this) || this;
  30. /**
  31. * True if the diffuse texture is in use.
  32. */
  33. _this.DIFFUSE = false;
  34. /**
  35. * The direct UV channel to use.
  36. */
  37. _this.DIFFUSEDIRECTUV = 0;
  38. /**
  39. * True if the diffuse texture is in gamma space.
  40. */
  41. _this.GAMMADIFFUSE = false;
  42. /**
  43. * True if the diffuse texture has opacity in the alpha channel.
  44. */
  45. _this.DIFFUSEHASALPHA = false;
  46. /**
  47. * True if you want the material to fade to transparent at grazing angle.
  48. */
  49. _this.OPACITYFRESNEL = false;
  50. /**
  51. * True if an extra blur needs to be added in the reflection.
  52. */
  53. _this.REFLECTIONBLUR = false;
  54. /**
  55. * True if you want the material to fade to reflection at grazing angle.
  56. */
  57. _this.REFLECTIONFRESNEL = false;
  58. /**
  59. * True if you want the material to falloff as far as you move away from the scene center.
  60. */
  61. _this.REFLECTIONFALLOFF = false;
  62. /**
  63. * False if the current Webgl implementation does not support the texture lod extension.
  64. */
  65. _this.TEXTURELODSUPPORT = false;
  66. /**
  67. * True to ensure the data are premultiplied.
  68. */
  69. _this.PREMULTIPLYALPHA = false;
  70. /**
  71. * True if the texture contains cooked RGB values and not gray scaled multipliers.
  72. */
  73. _this.USERGBCOLOR = false;
  74. // Image Processing Configuration.
  75. _this.IMAGEPROCESSING = false;
  76. _this.VIGNETTE = false;
  77. _this.VIGNETTEBLENDMODEMULTIPLY = false;
  78. _this.VIGNETTEBLENDMODEOPAQUE = false;
  79. _this.TONEMAPPING = false;
  80. _this.CONTRAST = false;
  81. _this.COLORCURVES = false;
  82. _this.COLORGRADING = false;
  83. _this.COLORGRADING3D = false;
  84. _this.SAMPLER3DGREENDEPTH = false;
  85. _this.SAMPLER3DBGRMAP = false;
  86. _this.IMAGEPROCESSINGPOSTPROCESS = false;
  87. _this.EXPOSURE = false;
  88. // Reflection.
  89. _this.REFLECTION = false;
  90. _this.REFLECTIONMAP_3D = false;
  91. _this.REFLECTIONMAP_SPHERICAL = false;
  92. _this.REFLECTIONMAP_PLANAR = false;
  93. _this.REFLECTIONMAP_CUBIC = false;
  94. _this.REFLECTIONMAP_PROJECTION = false;
  95. _this.REFLECTIONMAP_SKYBOX = false;
  96. _this.REFLECTIONMAP_EXPLICIT = false;
  97. _this.REFLECTIONMAP_EQUIRECTANGULAR = false;
  98. _this.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;
  99. _this.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false;
  100. _this.INVERTCUBICMAP = false;
  101. _this.REFLECTIONMAP_OPPOSITEZ = false;
  102. _this.LODINREFLECTIONALPHA = false;
  103. _this.GAMMAREFLECTION = false;
  104. // Default BJS.
  105. _this.MAINUV1 = false;
  106. _this.MAINUV2 = false;
  107. _this.UV1 = false;
  108. _this.UV2 = false;
  109. _this.CLIPPLANE = false;
  110. _this.POINTSIZE = false;
  111. _this.FOG = false;
  112. _this.NORMAL = false;
  113. _this.NUM_BONE_INFLUENCERS = 0;
  114. _this.BonesPerMesh = 0;
  115. _this.INSTANCES = false;
  116. _this.SHADOWFLOAT = false;
  117. _this.rebuild();
  118. return _this;
  119. }
  120. return BackgroundMaterialDefines;
  121. }(BABYLON.MaterialDefines));
  122. /**
  123. * Background material
  124. */
  125. var BackgroundMaterial = /** @class */ (function (_super) {
  126. __extends(BackgroundMaterial, _super);
  127. /**
  128. * constructor
  129. * @param name The name of the material
  130. * @param scene The scene to add the material to
  131. */
  132. function BackgroundMaterial(name, scene) {
  133. var _this = _super.call(this, name, scene) || this;
  134. _this.primaryColor = BABYLON.Color3.White();
  135. _this.primaryLevel = 1;
  136. _this.secondaryColor = BABYLON.Color3.Gray();
  137. _this.secondaryLevel = 1;
  138. _this.tertiaryColor = BABYLON.Color3.Black();
  139. _this.tertiaryLevel = 1;
  140. _this.reflectionTexture = null;
  141. _this.reflectionBlur = 0;
  142. _this.diffuseTexture = null;
  143. /**
  144. * Specify the list of lights casting shadow on the material.
  145. * All scene shadow lights will be included if null.
  146. */
  147. _this._shadowLights = null;
  148. _this.shadowLights = null;
  149. _this.shadowBlurScale = 1;
  150. _this.shadowLevel = 0;
  151. _this.sceneCenter = BABYLON.Vector3.Zero();
  152. _this.opacityFresnel = true;
  153. _this.reflectionFresnel = false;
  154. _this.reflectionFalloffDistance = 0.0;
  155. _this.reflectionAmount = 1.0;
  156. _this.reflectionReflectance0 = 0.05;
  157. _this.reflectionReflectance90 = 0.5;
  158. _this.useRGBColor = true;
  159. /**
  160. * Number of Simultaneous lights allowed on the material.
  161. */
  162. _this._maxSimultaneousLights = 4;
  163. _this.maxSimultaneousLights = 4;
  164. /**
  165. * Keep track of the image processing observer to allow dispose and replace.
  166. */
  167. _this._imageProcessingObserver = null;
  168. // Temp values kept as cache in the material.
  169. _this._renderTargets = new BABYLON.SmartArray(16);
  170. _this._reflectionControls = BABYLON.Vector4.Zero();
  171. // Setup the default processing configuration to the scene.
  172. _this._attachImageProcessingConfiguration(null);
  173. _this.getRenderTargetTextures = function () {
  174. _this._renderTargets.reset();
  175. if (_this._diffuseTexture && _this._diffuseTexture.isRenderTarget) {
  176. _this._renderTargets.push(_this._diffuseTexture);
  177. }
  178. if (_this._reflectionTexture && _this._reflectionTexture.isRenderTarget) {
  179. _this._renderTargets.push(_this._reflectionTexture);
  180. }
  181. return _this._renderTargets;
  182. };
  183. return _this;
  184. }
  185. /**
  186. * Attaches a new image processing configuration to the PBR Material.
  187. * @param configuration (if null the scene configuration will be use)
  188. */
  189. BackgroundMaterial.prototype._attachImageProcessingConfiguration = function (configuration) {
  190. var _this = this;
  191. if (configuration === this._imageProcessingConfiguration) {
  192. return;
  193. }
  194. // Detaches observer.
  195. if (this._imageProcessingConfiguration && this._imageProcessingObserver) {
  196. this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);
  197. }
  198. // Pick the scene configuration if needed.
  199. if (!configuration) {
  200. this._imageProcessingConfiguration = this.getScene().imageProcessingConfiguration;
  201. }
  202. else {
  203. this._imageProcessingConfiguration = configuration;
  204. }
  205. // Attaches observer.
  206. this._imageProcessingObserver = this._imageProcessingConfiguration.onUpdateParameters.add(function (conf) {
  207. _this._markAllSubMeshesAsImageProcessingDirty();
  208. });
  209. };
  210. Object.defineProperty(BackgroundMaterial.prototype, "imageProcessingConfiguration", {
  211. /**
  212. * Gets the image processing configuration used either in this material.
  213. */
  214. get: function () {
  215. return this._imageProcessingConfiguration;
  216. },
  217. /**
  218. * Sets the Default image processing configuration used either in the this material.
  219. *
  220. * If sets to null, the scene one is in use.
  221. */
  222. set: function (value) {
  223. this._attachImageProcessingConfiguration(value);
  224. // Ensure the effect will be rebuilt.
  225. this._markAllSubMeshesAsTexturesDirty();
  226. },
  227. enumerable: true,
  228. configurable: true
  229. });
  230. Object.defineProperty(BackgroundMaterial.prototype, "cameraColorCurvesEnabled", {
  231. /**
  232. * Gets wether the color curves effect is enabled.
  233. */
  234. get: function () {
  235. return this.imageProcessingConfiguration.colorCurvesEnabled;
  236. },
  237. /**
  238. * Sets wether the color curves effect is enabled.
  239. */
  240. set: function (value) {
  241. this.imageProcessingConfiguration.colorCurvesEnabled = value;
  242. },
  243. enumerable: true,
  244. configurable: true
  245. });
  246. Object.defineProperty(BackgroundMaterial.prototype, "cameraColorGradingEnabled", {
  247. /**
  248. * Gets wether the color grading effect is enabled.
  249. */
  250. get: function () {
  251. return this.imageProcessingConfiguration.colorGradingEnabled;
  252. },
  253. /**
  254. * Gets wether the color grading effect is enabled.
  255. */
  256. set: function (value) {
  257. this.imageProcessingConfiguration.colorGradingEnabled = value;
  258. },
  259. enumerable: true,
  260. configurable: true
  261. });
  262. Object.defineProperty(BackgroundMaterial.prototype, "cameraToneMappingEnabled", {
  263. /**
  264. * Gets wether tonemapping is enabled or not.
  265. */
  266. get: function () {
  267. return this._imageProcessingConfiguration.toneMappingEnabled;
  268. },
  269. /**
  270. * Sets wether tonemapping is enabled or not
  271. */
  272. set: function (value) {
  273. this._imageProcessingConfiguration.toneMappingEnabled = value;
  274. },
  275. enumerable: true,
  276. configurable: true
  277. });
  278. ;
  279. ;
  280. Object.defineProperty(BackgroundMaterial.prototype, "cameraExposure", {
  281. /**
  282. * The camera exposure used on this material.
  283. * This property is here and not in the camera to allow controlling exposure without full screen post process.
  284. * This corresponds to a photographic exposure.
  285. */
  286. get: function () {
  287. return this._imageProcessingConfiguration.exposure;
  288. },
  289. /**
  290. * The camera exposure used on this material.
  291. * This property is here and not in the camera to allow controlling exposure without full screen post process.
  292. * This corresponds to a photographic exposure.
  293. */
  294. set: function (value) {
  295. this._imageProcessingConfiguration.exposure = value;
  296. },
  297. enumerable: true,
  298. configurable: true
  299. });
  300. ;
  301. ;
  302. Object.defineProperty(BackgroundMaterial.prototype, "cameraContrast", {
  303. /**
  304. * Gets The camera contrast used on this material.
  305. */
  306. get: function () {
  307. return this._imageProcessingConfiguration.contrast;
  308. },
  309. /**
  310. * Sets The camera contrast used on this material.
  311. */
  312. set: function (value) {
  313. this._imageProcessingConfiguration.contrast = value;
  314. },
  315. enumerable: true,
  316. configurable: true
  317. });
  318. Object.defineProperty(BackgroundMaterial.prototype, "cameraColorGradingTexture", {
  319. /**
  320. * Gets the Color Grading 2D Lookup Texture.
  321. */
  322. get: function () {
  323. return this._imageProcessingConfiguration.colorGradingTexture;
  324. },
  325. /**
  326. * Sets the Color Grading 2D Lookup Texture.
  327. */
  328. set: function (value) {
  329. this.imageProcessingConfiguration.colorGradingTexture = value;
  330. },
  331. enumerable: true,
  332. configurable: true
  333. });
  334. Object.defineProperty(BackgroundMaterial.prototype, "cameraColorCurves", {
  335. /**
  336. * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
  337. * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.
  338. * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;
  339. * corresponding to low luminance, medium luminance, and high luminance areas respectively.
  340. */
  341. get: function () {
  342. return this.imageProcessingConfiguration.colorCurves;
  343. },
  344. /**
  345. * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
  346. * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.
  347. * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;
  348. * corresponding to low luminance, medium luminance, and high luminance areas respectively.
  349. */
  350. set: function (value) {
  351. this.imageProcessingConfiguration.colorCurves = value;
  352. },
  353. enumerable: true,
  354. configurable: true
  355. });
  356. /**
  357. * The entire material has been created in order to prevent overdraw.
  358. * @returns false
  359. */
  360. BackgroundMaterial.prototype.needAlphaTesting = function () {
  361. return false;
  362. };
  363. /**
  364. * The entire material has been created in order to prevent overdraw.
  365. * @returns true if blending is enable
  366. */
  367. BackgroundMaterial.prototype.needAlphaBlending = function () {
  368. return ((this.alpha < 0) || (this._diffuseTexture != null && this._diffuseTexture.hasAlpha));
  369. };
  370. /**
  371. * Checks wether the material is ready to be rendered for a given mesh.
  372. * @param mesh The mesh to render
  373. * @param subMesh The submesh to check against
  374. * @param useInstances Specify wether or not the material is used with instances
  375. */
  376. BackgroundMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  377. var _this = this;
  378. if (useInstances === void 0) { useInstances = false; }
  379. if (subMesh.effect && this.isFrozen) {
  380. if (this._wasPreviouslyReady) {
  381. return true;
  382. }
  383. }
  384. if (!subMesh._materialDefines) {
  385. subMesh._materialDefines = new BackgroundMaterialDefines();
  386. }
  387. var scene = this.getScene();
  388. var defines = subMesh._materialDefines;
  389. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  390. if (defines._renderId === scene.getRenderId()) {
  391. return true;
  392. }
  393. }
  394. var engine = scene.getEngine();
  395. // Lights
  396. BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights);
  397. defines._needNormals = true;
  398. // Textures
  399. if (defines._areTexturesDirty) {
  400. defines._needUVs = false;
  401. if (scene.texturesEnabled) {
  402. if (scene.getEngine().getCaps().textureLOD) {
  403. defines.TEXTURELODSUPPORT = true;
  404. }
  405. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  406. if (!this._diffuseTexture.isReadyOrNotBlocking()) {
  407. return false;
  408. }
  409. BABYLON.MaterialHelper.PrepareDefinesForMergedUV(this._diffuseTexture, defines, "DIFFUSE");
  410. defines.DIFFUSEHASALPHA = this._diffuseTexture.hasAlpha;
  411. defines.GAMMADIFFUSE = this._diffuseTexture.gammaSpace;
  412. defines.OPACITYFRESNEL = this._opacityFresnel;
  413. }
  414. else {
  415. defines.DIFFUSE = false;
  416. defines.DIFFUSEHASALPHA = false;
  417. defines.GAMMADIFFUSE = false;
  418. defines.OPACITYFRESNEL = false;
  419. }
  420. var reflectionTexture = this._reflectionTexture;
  421. if (reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  422. if (!reflectionTexture.isReadyOrNotBlocking()) {
  423. return false;
  424. }
  425. defines.REFLECTION = true;
  426. defines.GAMMAREFLECTION = reflectionTexture.gammaSpace;
  427. defines.REFLECTIONBLUR = this._reflectionBlur > 0;
  428. defines.REFLECTIONMAP_OPPOSITEZ = this.getScene().useRightHandedSystem ? !reflectionTexture.invertZ : reflectionTexture.invertZ;
  429. defines.LODINREFLECTIONALPHA = reflectionTexture.lodLevelInAlpha;
  430. if (reflectionTexture.coordinatesMode === BABYLON.Texture.INVCUBIC_MODE) {
  431. defines.INVERTCUBICMAP = true;
  432. }
  433. defines.REFLECTIONMAP_3D = reflectionTexture.isCube;
  434. switch (reflectionTexture.coordinatesMode) {
  435. case BABYLON.Texture.CUBIC_MODE:
  436. case BABYLON.Texture.INVCUBIC_MODE:
  437. defines.REFLECTIONMAP_CUBIC = true;
  438. break;
  439. case BABYLON.Texture.EXPLICIT_MODE:
  440. defines.REFLECTIONMAP_EXPLICIT = true;
  441. break;
  442. case BABYLON.Texture.PLANAR_MODE:
  443. defines.REFLECTIONMAP_PLANAR = true;
  444. break;
  445. case BABYLON.Texture.PROJECTION_MODE:
  446. defines.REFLECTIONMAP_PROJECTION = true;
  447. break;
  448. case BABYLON.Texture.SKYBOX_MODE:
  449. defines.REFLECTIONMAP_SKYBOX = true;
  450. break;
  451. case BABYLON.Texture.SPHERICAL_MODE:
  452. defines.REFLECTIONMAP_SPHERICAL = true;
  453. break;
  454. case BABYLON.Texture.EQUIRECTANGULAR_MODE:
  455. defines.REFLECTIONMAP_EQUIRECTANGULAR = true;
  456. break;
  457. case BABYLON.Texture.FIXED_EQUIRECTANGULAR_MODE:
  458. defines.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = true;
  459. break;
  460. case BABYLON.Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE:
  461. defines.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = true;
  462. break;
  463. }
  464. if (this.reflectionFresnel) {
  465. defines.REFLECTIONFRESNEL = true;
  466. defines.REFLECTIONFALLOFF = this.reflectionFalloffDistance > 0;
  467. this._reflectionControls.x = this.reflectionAmount;
  468. this._reflectionControls.y = this.reflectionReflectance0;
  469. this._reflectionControls.z = this.reflectionReflectance90;
  470. this._reflectionControls.w = this.reflectionFalloffDistance;
  471. }
  472. else {
  473. defines.REFLECTIONFRESNEL = false;
  474. defines.REFLECTIONFALLOFF = false;
  475. }
  476. }
  477. else {
  478. defines.REFLECTION = false;
  479. defines.REFLECTIONFALLOFF = false;
  480. defines.REFLECTIONBLUR = false;
  481. defines.REFLECTIONMAP_3D = false;
  482. defines.REFLECTIONMAP_SPHERICAL = false;
  483. defines.REFLECTIONMAP_PLANAR = false;
  484. defines.REFLECTIONMAP_CUBIC = false;
  485. defines.REFLECTIONMAP_PROJECTION = false;
  486. defines.REFLECTIONMAP_SKYBOX = false;
  487. defines.REFLECTIONMAP_EXPLICIT = false;
  488. defines.REFLECTIONMAP_EQUIRECTANGULAR = false;
  489. defines.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;
  490. defines.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false;
  491. defines.INVERTCUBICMAP = false;
  492. defines.REFLECTIONMAP_OPPOSITEZ = false;
  493. defines.LODINREFLECTIONALPHA = false;
  494. defines.GAMMAREFLECTION = false;
  495. }
  496. }
  497. defines.PREMULTIPLYALPHA = (this.alphaMode === BABYLON.Engine.ALPHA_PREMULTIPLIED || this.alphaMode === BABYLON.Engine.ALPHA_PREMULTIPLIED_PORTERDUFF);
  498. defines.USERGBCOLOR = this._useRGBColor;
  499. }
  500. if (defines._areImageProcessingDirty) {
  501. if (!this._imageProcessingConfiguration.isReady()) {
  502. return false;
  503. }
  504. this._imageProcessingConfiguration.prepareDefines(defines);
  505. }
  506. // Misc.
  507. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  508. // Values that need to be evaluated on every frame
  509. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances, false);
  510. // Attribs
  511. if (BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true, false)) {
  512. if (mesh) {
  513. if (!scene.getEngine().getCaps().standardDerivatives && !mesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
  514. mesh.createNormals(true);
  515. BABYLON.Tools.Warn("BackgroundMaterial: Normals have been created for the mesh: " + mesh.name);
  516. }
  517. }
  518. }
  519. // Get correct effect
  520. if (defines.isDirty) {
  521. defines.markAsProcessed();
  522. scene.resetCachedMaterial();
  523. // Fallbacks
  524. var fallbacks = new BABYLON.EffectFallbacks();
  525. if (defines.FOG) {
  526. fallbacks.addFallback(0, "FOG");
  527. }
  528. if (defines.POINTSIZE) {
  529. fallbacks.addFallback(1, "POINTSIZE");
  530. }
  531. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this._maxSimultaneousLights);
  532. if (defines.NUM_BONE_INFLUENCERS > 0) {
  533. fallbacks.addCPUSkinningFallback(0, mesh);
  534. }
  535. //Attributes
  536. var attribs = [BABYLON.VertexBuffer.PositionKind];
  537. if (defines.NORMAL) {
  538. attribs.push(BABYLON.VertexBuffer.NormalKind);
  539. }
  540. if (defines.UV1) {
  541. attribs.push(BABYLON.VertexBuffer.UVKind);
  542. }
  543. if (defines.UV2) {
  544. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  545. }
  546. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  547. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  548. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType",
  549. "vFogInfos", "vFogColor", "pointSize",
  550. "vClipPlane", "mBones",
  551. "vPrimaryColor", "vSecondaryColor", "vTertiaryColor",
  552. "vReflectionInfos", "reflectionMatrix", "vReflectionMicrosurfaceInfos",
  553. "shadowLevel", "alpha",
  554. "vBackgroundCenter", "vReflectionControl",
  555. "vDiffuseInfos", "diffuseMatrix",
  556. ];
  557. var samplers = ["diffuseSampler", "reflectionSampler", "reflectionSamplerLow", "reflectionSamplerHigh"];
  558. var uniformBuffers = ["Material", "Scene"];
  559. BABYLON.ImageProcessingConfiguration.PrepareUniforms(uniforms, defines);
  560. BABYLON.ImageProcessingConfiguration.PrepareSamplers(samplers, defines);
  561. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  562. uniformsNames: uniforms,
  563. uniformBuffersNames: uniformBuffers,
  564. samplers: samplers,
  565. defines: defines,
  566. maxSimultaneousLights: this._maxSimultaneousLights
  567. });
  568. var onCompiled = function (effect) {
  569. if (_this.onCompiled) {
  570. _this.onCompiled(effect);
  571. }
  572. _this.bindSceneUniformBuffer(effect, scene.getSceneUniformBuffer());
  573. };
  574. var join = defines.toString();
  575. subMesh.setEffect(scene.getEngine().createEffect("background", {
  576. attributes: attribs,
  577. uniformsNames: uniforms,
  578. uniformBuffersNames: uniformBuffers,
  579. samplers: samplers,
  580. defines: join,
  581. fallbacks: fallbacks,
  582. onCompiled: onCompiled,
  583. onError: this.onError,
  584. indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights }
  585. }, engine), defines);
  586. this.buildUniformLayout();
  587. }
  588. if (!subMesh.effect || !subMesh.effect.isReady()) {
  589. return false;
  590. }
  591. defines._renderId = scene.getRenderId();
  592. this._wasPreviouslyReady = true;
  593. return true;
  594. };
  595. /**
  596. * Build the uniform buffer used in the material.
  597. */
  598. BackgroundMaterial.prototype.buildUniformLayout = function () {
  599. // Order is important !
  600. this._uniformBuffer.addUniform("vPrimaryColor", 4);
  601. this._uniformBuffer.addUniform("vSecondaryColor", 4);
  602. this._uniformBuffer.addUniform("vTertiaryColor", 4);
  603. this._uniformBuffer.addUniform("vDiffuseInfos", 2);
  604. this._uniformBuffer.addUniform("vReflectionInfos", 2);
  605. this._uniformBuffer.addUniform("diffuseMatrix", 16);
  606. this._uniformBuffer.addUniform("reflectionMatrix", 16);
  607. this._uniformBuffer.addUniform("vReflectionMicrosurfaceInfos", 3);
  608. this._uniformBuffer.addUniform("pointSize", 1);
  609. this._uniformBuffer.addUniform("shadowLevel", 1);
  610. this._uniformBuffer.addUniform("alpha", 1);
  611. this._uniformBuffer.addUniform("vBackgroundCenter", 3);
  612. this._uniformBuffer.addUniform("vReflectionControl", 4);
  613. this._uniformBuffer.create();
  614. };
  615. /**
  616. * Unbind the material.
  617. */
  618. BackgroundMaterial.prototype.unbind = function () {
  619. if (this._diffuseTexture && this._diffuseTexture.isRenderTarget) {
  620. this._uniformBuffer.setTexture("diffuseSampler", null);
  621. }
  622. if (this._reflectionTexture && this._reflectionTexture.isRenderTarget) {
  623. this._uniformBuffer.setTexture("reflectionSampler", null);
  624. }
  625. _super.prototype.unbind.call(this);
  626. };
  627. /**
  628. * Bind only the world matrix to the material.
  629. * @param world The world matrix to bind.
  630. */
  631. BackgroundMaterial.prototype.bindOnlyWorldMatrix = function (world) {
  632. this._activeEffect.setMatrix("world", world);
  633. };
  634. /**
  635. * Bind the material for a dedicated submeh (every used meshes will be considered opaque).
  636. * @param world The world matrix to bind.
  637. * @param subMesh The submesh to bind for.
  638. */
  639. BackgroundMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  640. var scene = this.getScene();
  641. var defines = subMesh._materialDefines;
  642. if (!defines) {
  643. return;
  644. }
  645. var effect = subMesh.effect;
  646. if (!effect) {
  647. return;
  648. }
  649. this._activeEffect = effect;
  650. // Matrices
  651. this.bindOnlyWorldMatrix(world);
  652. // Bones
  653. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  654. var mustRebind = this._mustRebind(scene, effect, mesh.visibility);
  655. if (mustRebind) {
  656. this._uniformBuffer.bindToEffect(effect, "Material");
  657. this.bindViewProjection(effect);
  658. var reflectionTexture = this._reflectionTexture;
  659. if (!this._uniformBuffer.useUbo || !this.isFrozen || !this._uniformBuffer.isSync) {
  660. // Texture uniforms
  661. if (scene.texturesEnabled) {
  662. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  663. this._uniformBuffer.updateFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  664. BABYLON.MaterialHelper.BindTextureMatrix(this._diffuseTexture, this._uniformBuffer, "diffuse");
  665. }
  666. if (reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  667. this._uniformBuffer.updateMatrix("reflectionMatrix", reflectionTexture.getReflectionTextureMatrix());
  668. this._uniformBuffer.updateFloat2("vReflectionInfos", reflectionTexture.level, this._reflectionBlur);
  669. this._uniformBuffer.updateFloat3("vReflectionMicrosurfaceInfos", reflectionTexture.getSize().width, reflectionTexture.lodGenerationScale, reflectionTexture.lodGenerationOffset);
  670. }
  671. }
  672. if (this.shadowLevel > 0) {
  673. this._uniformBuffer.updateFloat("shadowLevel", this.shadowLevel);
  674. }
  675. this._uniformBuffer.updateFloat("alpha", this.alpha);
  676. // Point size
  677. if (this.pointsCloud) {
  678. this._uniformBuffer.updateFloat("pointSize", this.pointSize);
  679. }
  680. this._uniformBuffer.updateColor4("vPrimaryColor", this._primaryColor, this._primaryLevel);
  681. this._uniformBuffer.updateColor4("vSecondaryColor", this._secondaryColor, this._secondaryLevel);
  682. this._uniformBuffer.updateColor4("vTertiaryColor", this._tertiaryColor, this._tertiaryLevel);
  683. }
  684. // Textures
  685. if (scene.texturesEnabled) {
  686. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  687. this._uniformBuffer.setTexture("diffuseSampler", this._diffuseTexture);
  688. }
  689. if (reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  690. if (defines.REFLECTIONBLUR && defines.TEXTURELODSUPPORT) {
  691. this._uniformBuffer.setTexture("reflectionSampler", reflectionTexture);
  692. }
  693. else if (!defines.REFLECTIONBLUR) {
  694. this._uniformBuffer.setTexture("reflectionSampler", reflectionTexture);
  695. }
  696. else {
  697. this._uniformBuffer.setTexture("reflectionSampler", reflectionTexture._lodTextureMid || reflectionTexture);
  698. this._uniformBuffer.setTexture("reflectionSamplerLow", reflectionTexture._lodTextureLow || reflectionTexture);
  699. this._uniformBuffer.setTexture("reflectionSamplerHigh", reflectionTexture._lodTextureHigh || reflectionTexture);
  700. }
  701. if (defines.REFLECTIONFRESNEL) {
  702. this._uniformBuffer.updateFloat3("vBackgroundCenter", this.sceneCenter.x, this.sceneCenter.y, this.sceneCenter.z);
  703. this._uniformBuffer.updateFloat4("vReflectionControl", this._reflectionControls.x, this._reflectionControls.y, this._reflectionControls.z, this._reflectionControls.w);
  704. }
  705. }
  706. }
  707. // Clip plane
  708. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  709. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  710. }
  711. if (mustRebind || !this.isFrozen) {
  712. if (scene.lightsEnabled) {
  713. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this._maxSimultaneousLights, false);
  714. }
  715. // View
  716. this.bindView(effect);
  717. // Fog
  718. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  719. // image processing
  720. this._imageProcessingConfiguration.bind(this._activeEffect);
  721. }
  722. this._uniformBuffer.update();
  723. this._afterBind(mesh);
  724. };
  725. /**
  726. * Dispose the material.
  727. * @forceDisposeEffect Force disposal of the associated effect.
  728. * @forceDisposeTextures Force disposal of the associated textures.
  729. */
  730. BackgroundMaterial.prototype.dispose = function (forceDisposeEffect, forceDisposeTextures) {
  731. if (forceDisposeEffect === void 0) { forceDisposeEffect = false; }
  732. if (forceDisposeTextures === void 0) { forceDisposeTextures = false; }
  733. if (forceDisposeTextures) {
  734. if (this.diffuseTexture) {
  735. this.diffuseTexture.dispose();
  736. }
  737. if (this.reflectionTexture) {
  738. this.reflectionTexture.dispose();
  739. }
  740. }
  741. this._renderTargets.dispose();
  742. if (this._imageProcessingConfiguration && this._imageProcessingObserver) {
  743. this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);
  744. }
  745. _super.prototype.dispose.call(this, forceDisposeEffect);
  746. };
  747. /**
  748. * Clones the material.
  749. * @name The cloned name.
  750. * @returns The cloned material.
  751. */
  752. BackgroundMaterial.prototype.clone = function (name) {
  753. var _this = this;
  754. return BABYLON.SerializationHelper.Clone(function () { return new BackgroundMaterial(name, _this.getScene()); }, this);
  755. };
  756. /**
  757. * Serializes the current material to its JSON representation.
  758. * @returns The JSON representation.
  759. */
  760. BackgroundMaterial.prototype.serialize = function () {
  761. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  762. serializationObject.customType = "BABYLON.BackgroundMaterial";
  763. return serializationObject;
  764. };
  765. /**
  766. * Gets the class name of the material
  767. * @returns "BackgroundMaterial"
  768. */
  769. BackgroundMaterial.prototype.getClassName = function () {
  770. return "BackgroundMaterial";
  771. };
  772. /**
  773. * Parse a JSON input to create back a background material.
  774. * @param source
  775. * @param scene
  776. * @param rootUrl
  777. * @returns the instantiated BackgroundMaterial.
  778. */
  779. BackgroundMaterial.Parse = function (source, scene, rootUrl) {
  780. return BABYLON.SerializationHelper.Parse(function () { return new BackgroundMaterial(source.name, scene); }, source, scene, rootUrl);
  781. };
  782. __decorate([
  783. BABYLON.serializeAsColor3()
  784. ], BackgroundMaterial.prototype, "_primaryColor", void 0);
  785. __decorate([
  786. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  787. ], BackgroundMaterial.prototype, "primaryColor", void 0);
  788. __decorate([
  789. BABYLON.serialize()
  790. ], BackgroundMaterial.prototype, "_primaryLevel", void 0);
  791. __decorate([
  792. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  793. ], BackgroundMaterial.prototype, "primaryLevel", void 0);
  794. __decorate([
  795. BABYLON.serializeAsColor3()
  796. ], BackgroundMaterial.prototype, "_secondaryColor", void 0);
  797. __decorate([
  798. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  799. ], BackgroundMaterial.prototype, "secondaryColor", void 0);
  800. __decorate([
  801. BABYLON.serialize()
  802. ], BackgroundMaterial.prototype, "_secondaryLevel", void 0);
  803. __decorate([
  804. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  805. ], BackgroundMaterial.prototype, "secondaryLevel", void 0);
  806. __decorate([
  807. BABYLON.serializeAsColor3()
  808. ], BackgroundMaterial.prototype, "_tertiaryColor", void 0);
  809. __decorate([
  810. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  811. ], BackgroundMaterial.prototype, "tertiaryColor", void 0);
  812. __decorate([
  813. BABYLON.serialize()
  814. ], BackgroundMaterial.prototype, "_tertiaryLevel", void 0);
  815. __decorate([
  816. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  817. ], BackgroundMaterial.prototype, "tertiaryLevel", void 0);
  818. __decorate([
  819. BABYLON.serializeAsTexture()
  820. ], BackgroundMaterial.prototype, "_reflectionTexture", void 0);
  821. __decorate([
  822. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  823. ], BackgroundMaterial.prototype, "reflectionTexture", void 0);
  824. __decorate([
  825. BABYLON.serialize()
  826. ], BackgroundMaterial.prototype, "_reflectionBlur", void 0);
  827. __decorate([
  828. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  829. ], BackgroundMaterial.prototype, "reflectionBlur", void 0);
  830. __decorate([
  831. BABYLON.serializeAsTexture()
  832. ], BackgroundMaterial.prototype, "_diffuseTexture", void 0);
  833. __decorate([
  834. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  835. ], BackgroundMaterial.prototype, "diffuseTexture", void 0);
  836. __decorate([
  837. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  838. ], BackgroundMaterial.prototype, "shadowLights", void 0);
  839. __decorate([
  840. BABYLON.serialize()
  841. ], BackgroundMaterial.prototype, "_shadowBlurScale", void 0);
  842. __decorate([
  843. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  844. ], BackgroundMaterial.prototype, "shadowBlurScale", void 0);
  845. __decorate([
  846. BABYLON.serialize()
  847. ], BackgroundMaterial.prototype, "_shadowLevel", void 0);
  848. __decorate([
  849. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  850. ], BackgroundMaterial.prototype, "shadowLevel", void 0);
  851. __decorate([
  852. BABYLON.serializeAsVector3()
  853. ], BackgroundMaterial.prototype, "_sceneCenter", void 0);
  854. __decorate([
  855. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  856. ], BackgroundMaterial.prototype, "sceneCenter", void 0);
  857. __decorate([
  858. BABYLON.serialize()
  859. ], BackgroundMaterial.prototype, "_opacityFresnel", void 0);
  860. __decorate([
  861. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  862. ], BackgroundMaterial.prototype, "opacityFresnel", void 0);
  863. __decorate([
  864. BABYLON.serialize()
  865. ], BackgroundMaterial.prototype, "_reflectionFresnel", void 0);
  866. __decorate([
  867. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  868. ], BackgroundMaterial.prototype, "reflectionFresnel", void 0);
  869. __decorate([
  870. BABYLON.serialize()
  871. ], BackgroundMaterial.prototype, "_reflectionFalloffDistance", void 0);
  872. __decorate([
  873. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  874. ], BackgroundMaterial.prototype, "reflectionFalloffDistance", void 0);
  875. __decorate([
  876. BABYLON.serialize()
  877. ], BackgroundMaterial.prototype, "_reflectionAmount", void 0);
  878. __decorate([
  879. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  880. ], BackgroundMaterial.prototype, "reflectionAmount", void 0);
  881. __decorate([
  882. BABYLON.serialize()
  883. ], BackgroundMaterial.prototype, "_reflectionReflectance0", void 0);
  884. __decorate([
  885. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  886. ], BackgroundMaterial.prototype, "reflectionReflectance0", void 0);
  887. __decorate([
  888. BABYLON.serialize()
  889. ], BackgroundMaterial.prototype, "_reflectionReflectance90", void 0);
  890. __decorate([
  891. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  892. ], BackgroundMaterial.prototype, "reflectionReflectance90", void 0);
  893. __decorate([
  894. BABYLON.serialize()
  895. ], BackgroundMaterial.prototype, "_useRGBColor", void 0);
  896. __decorate([
  897. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  898. ], BackgroundMaterial.prototype, "useRGBColor", void 0);
  899. __decorate([
  900. BABYLON.serialize()
  901. ], BackgroundMaterial.prototype, "_maxSimultaneousLights", void 0);
  902. __decorate([
  903. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  904. ], BackgroundMaterial.prototype, "maxSimultaneousLights", void 0);
  905. __decorate([
  906. BABYLON.serializeAsImageProcessingConfiguration()
  907. ], BackgroundMaterial.prototype, "_imageProcessingConfiguration", void 0);
  908. return BackgroundMaterial;
  909. }(BABYLON.PushMaterial));
  910. BABYLON.BackgroundMaterial = BackgroundMaterial;
  911. })(BABYLON || (BABYLON = {}));
  912. //# sourceMappingURL=babylon.backgroundMaterial.js.map
  913. BABYLON.Effect.ShadersStore['backgroundVertexShader'] = "precision highp float;\n#include<__decl__backgroundVertex>\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2; \n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0\nvarying vec2 vDiffuseUV;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\nvoid main(void) {\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=position;\n#endif \n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normal);\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(position,0.0)));\n#endif\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef MAINUV1\nvMainUV1=uv;\n#endif \n#ifdef MAINUV2\nvMainUV2=uv2;\n#endif\n#if defined(DIFFUSE) && DIFFUSEDIRECTUV == 0 \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\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  914. BABYLON.Effect.ShadersStore['backgroundPixelShader'] = "#ifdef TEXTURELODSUPPORT\n#extension GL_EXT_shader_texture_lod : enable\n#endif\nprecision highp float;\n#include<__decl__backgroundFragment>\n\nuniform vec3 vEyePosition;\n\nvarying vec3 vPositionW;\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif \n#ifdef MAINUV2 \nvarying vec2 vMainUV2; \n#endif \n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef DIFFUSE\n#if DIFFUSEDIRECTUV == 1\n#define vDiffuseUV vMainUV1\n#elif DIFFUSEDIRECTUV == 2\n#define vDiffuseUV vMainUV2\n#else\nvarying vec2 vDiffuseUV;\n#endif\nuniform sampler2D diffuseSampler;\n#endif\n\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\n#define sampleReflection(s,c) textureCube(s,c)\nuniform samplerCube reflectionSampler;\n#ifdef TEXTURELODSUPPORT\n#define sampleReflectionLod(s,c,l) textureCubeLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;\nuniform samplerCube reflectionSamplerHigh;\n#endif\n#else\n#define sampleReflection(s,c) texture2D(s,c)\nuniform sampler2D reflectionSampler;\n#ifdef TEXTURELODSUPPORT\n#define sampleReflectionLod(s,c,l) texture2DLodEXT(s,c,l)\n#else\nuniform samplerCube reflectionSamplerLow;\nuniform samplerCube reflectionSamplerHigh;\n#endif\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include<reflectionFunction>\n#endif\n\n#ifndef FROMLINEARSPACE\n#define FROMLINEARSPACE;\n#endif\n\n#ifndef SHADOWONLY\n#define SHADOWONLY;\n#endif\n#include<imageProcessingDeclaration>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<helperFunctions>\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<imageProcessingFunctions>\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\n#ifdef REFLECTIONFRESNEL\n#define FRESNEL_MAXIMUM_ON_ROUGH 0.25\nvec3 fresnelSchlickEnvironmentGGX(float VdotN,vec3 reflectance0,vec3 reflectance90,float smoothness)\n{\n\nfloat weight=mix(FRESNEL_MAXIMUM_ON_ROUGH,1.0,smoothness);\nreturn reflectance0+weight*(reflectance90-reflectance0)*pow(clamp(1.0-VdotN,0.,1.),5.0);\n}\n#endif\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(0.0,1.0,0.0);\n#endif\n\nfloat shadow=1.;\nfloat globalShadow=0.;\nfloat shadowLightCount=0.;\n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef SHADOWINUSE\nglobalShadow/=shadowLightCount;\n#else\nglobalShadow=1.0;\n#endif\n\nvec3 reflectionColor=vec3(1.,1.,1.);\n#ifdef REFLECTION\nvec3 reflectionVector=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef REFLECTIONMAP_OPPOSITEZ\nreflectionVector.z*=-1.0;\n#endif\n\n#ifdef REFLECTIONMAP_3D\nvec3 reflectionCoords=reflectionVector;\n#else\nvec2 reflectionCoords=reflectionVector.xy;\n#ifdef REFLECTIONMAP_PROJECTION\nreflectionCoords/=reflectionVector.z;\n#endif\nreflectionCoords.y=1.0-reflectionCoords.y;\n#endif\n#ifdef REFLECTIONBLUR\nfloat reflectionLOD=vReflectionInfos.y;\n#ifdef TEXTURELODSUPPORT\n\nreflectionLOD=reflectionLOD*log2(vReflectionMicrosurfaceInfos.x)*vReflectionMicrosurfaceInfos.y+vReflectionMicrosurfaceInfos.z;\nreflectionColor=sampleReflectionLod(reflectionSampler,reflectionCoords,reflectionLOD).rgb;\n#else\nfloat lodReflectionNormalized=clamp(reflectionLOD,0.,1.);\nfloat lodReflectionNormalizedDoubled=lodReflectionNormalized*2.0;\nvec3 reflectionSpecularMid=sampleReflection(reflectionSampler,reflectionCoords).rgb;\nif(lodReflectionNormalizedDoubled<1.0){\nreflectionColor=mix(\nsampleReflection(reflectionSamplerHigh,reflectionCoords).rgb,\nreflectionSpecularMid,\nlodReflectionNormalizedDoubled\n);\n} else {\nreflectionColor=mix(\nreflectionSpecularMid,\nsampleReflection(reflectionSamplerLow,reflectionCoords).rgb,\nlodReflectionNormalizedDoubled-1.0\n);\n}\n#endif\n#else\nvec4 reflectionSample=sampleReflection(reflectionSampler,reflectionCoords);\nreflectionColor=reflectionSample.rgb;\n#endif\n#ifdef GAMMAREFLECTION\nreflectionColor=toLinearSpace(reflectionColor.rgb);\n#endif\n\nreflectionColor*=vReflectionInfos.x;\n#endif\n\nvec3 diffuseColor=vec3(1.,1.,1.);\nfloat finalAlpha=alpha;\n#ifdef DIFFUSE\nvec4 diffuseMap=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef GAMMADIFFUSE\ndiffuseMap.rgb=toLinearSpace(diffuseMap.rgb);\n#endif\n\ndiffuseMap.rgb*=vDiffuseInfos.y;\n#ifdef DIFFUSEHASALPHA\nfinalAlpha*=diffuseMap.a;\n#endif\ndiffuseColor=diffuseMap.rgb;\n#endif\n\n#ifdef REFLECTIONFRESNEL\nvec3 colorBase=diffuseColor;\n#else\nvec3 colorBase=reflectionColor*diffuseColor;\n#endif\ncolorBase=max(colorBase,0.0);\n\n#ifdef USERGBCOLOR\nvec3 finalColor=colorBase;\n#else\nvec3 finalColor=colorBase.r*vPrimaryColor.rgb*vPrimaryColor.a;\nfinalColor+=colorBase.g*vSecondaryColor.rgb*vSecondaryColor.a;\nfinalColor+=colorBase.b*vTertiaryColor.rgb*vTertiaryColor.a;\n#endif\n\n#ifdef REFLECTIONFRESNEL\nvec3 reflectionAmount=vReflectionControl.xxx;\nvec3 reflectionReflectance0=vReflectionControl.yyy;\nvec3 reflectionReflectance90=vReflectionControl.zzz;\nfloat VdotN=dot(normalize(vEyePosition),normalW);\nvec3 planarReflectionFresnel=fresnelSchlickEnvironmentGGX(clamp(VdotN,0.0,1.0),reflectionReflectance0,reflectionReflectance90,1.0);\nreflectionAmount*=planarReflectionFresnel;\n#ifdef REFLECTIONFALLOFF\nfloat reflectionDistanceFalloff=1.0-clamp(length(vPositionW.xyz-vBackgroundCenter)*vReflectionControl.w,0.0,1.0);\nreflectionDistanceFalloff*=reflectionDistanceFalloff;\nreflectionAmount*=reflectionDistanceFalloff;\n#endif\nfinalColor=mix(finalColor,reflectionColor,clamp(reflectionAmount,0.,1.));\n#endif\n#ifdef OPACITYFRESNEL\nfloat viewAngleToFloor=dot(normalW,normalize(vEyePosition-vBackgroundCenter));\n\nconst float startAngle=0.1;\nfloat fadeFactor=clamp(viewAngleToFloor/startAngle,0.0,1.0);\nfinalAlpha*=fadeFactor*fadeFactor;\n#endif\n\n#ifdef SHADOWINUSE\nfinalColor=mix(finalColor*shadowLevel,finalColor,globalShadow);\n#endif\n\nvec4 color=vec4(finalColor,finalAlpha);\n#include<fogFragment>\n#ifdef IMAGEPROCESSINGPOSTPROCESS\n\n\ncolor.rgb=clamp(color.rgb,0.,30.0);\n#else\n\ncolor=applyImageProcessing(color);\n#endif\n#ifdef PREMULTIPLYALPHA\n\ncolor.rgb*=color.a;\n#endif\ngl_FragColor=color;\n}";
  915. BABYLON.Effect.IncludesShadersStore['backgroundFragmentDeclaration'] = " uniform vec4 vPrimaryColor;\nuniform vec4 vSecondaryColor;\nuniform vec4 vTertiaryColor;\nuniform float shadowLevel;\nuniform float alpha;\n#ifdef DIFFUSE\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\nuniform mat4 reflectionMatrix;\nuniform vec3 vReflectionMicrosurfaceInfos;\n#endif\n#if defined(REFLECTIONFRESNEL) || defined(OPACITYFRESNEL)\nuniform vec3 vBackgroundCenter;\n#endif\n#ifdef REFLECTIONFRESNEL\nuniform vec4 vReflectionControl;\n#endif";
  916. BABYLON.Effect.IncludesShadersStore['backgroundUboDeclaration'] = "layout(std140,column_major) uniform;\nuniform Material\n{\nuniform vec4 vPrimaryColor;\nuniform vec4 vSecondaryColor;\nuniform vec4 vTertiaryColor;\nuniform vec2 vDiffuseInfos;\nuniform vec2 vReflectionInfos;\nuniform mat4 diffuseMatrix;\nuniform mat4 reflectionMatrix;\nuniform vec3 vReflectionMicrosurfaceInfos;\nuniform float pointSize;\nuniform float shadowLevel;\nuniform float alpha;\n#if defined(REFLECTIONFRESNEL) || defined(OPACITYFRESNEL)\nuniform vec3 vBackgroundCenter;\n#endif\n#ifdef REFLECTIONFRESNEL\nuniform vec4 vReflectionControl;\n#endif\n};\nuniform Scene {\nmat4 viewProjection;\nmat4 view;\n};";
  917. BABYLON.Effect.IncludesShadersStore['backgroundVertexDeclaration'] = "uniform mat4 view;\nuniform mat4 viewProjection;\nuniform float shadowLevel;\n#ifdef DIFFUSE\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\nuniform mat4 reflectionMatrix;\nuniform vec3 vReflectionMicrosurfaceInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif";