es6.js 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064
  1. import * as BABYLON from 'babylonjs/core/es6';
  2. var BABYLON;
  3. (function (BABYLON) {
  4. var AudioEngine = /** @class */ (function () {
  5. function AudioEngine() {
  6. this._audioContext = null;
  7. this._audioContextInitialized = false;
  8. this.canUseWebAudio = false;
  9. this.WarnedWebAudioUnsupported = false;
  10. this.unlocked = false;
  11. this.isMP3supported = false;
  12. this.isOGGsupported = false;
  13. if (typeof window.AudioContext !== 'undefined' || typeof window.webkitAudioContext !== 'undefined') {
  14. window.AudioContext = window.AudioContext || window.webkitAudioContext;
  15. this.canUseWebAudio = true;
  16. }
  17. var audioElem = document.createElement('audio');
  18. try {
  19. if (audioElem && !!audioElem.canPlayType && audioElem.canPlayType('audio/mpeg; codecs="mp3"').replace(/^no$/, '')) {
  20. this.isMP3supported = true;
  21. }
  22. }
  23. catch (e) {
  24. // protect error during capability check.
  25. }
  26. try {
  27. if (audioElem && !!audioElem.canPlayType && audioElem.canPlayType('audio/ogg; codecs="vorbis"').replace(/^no$/, '')) {
  28. this.isOGGsupported = true;
  29. }
  30. }
  31. catch (e) {
  32. // protect error during capability check.
  33. }
  34. if (/iPad|iPhone|iPod/.test(navigator.platform)) {
  35. this._unlockiOSaudio();
  36. }
  37. else {
  38. this.unlocked = true;
  39. }
  40. }
  41. Object.defineProperty(AudioEngine.prototype, "audioContext", {
  42. get: function () {
  43. if (!this._audioContextInitialized) {
  44. this._initializeAudioContext();
  45. }
  46. return this._audioContext;
  47. },
  48. enumerable: true,
  49. configurable: true
  50. });
  51. AudioEngine.prototype._unlockiOSaudio = function () {
  52. var _this = this;
  53. var unlockaudio = function () {
  54. if (!_this.audioContext) {
  55. return;
  56. }
  57. var buffer = _this.audioContext.createBuffer(1, 1, 22050);
  58. var source = _this.audioContext.createBufferSource();
  59. source.buffer = buffer;
  60. source.connect(_this.audioContext.destination);
  61. source.start(0);
  62. setTimeout(function () {
  63. if ((source.playbackState === source.PLAYING_STATE || source.playbackState === source.FINISHED_STATE)) {
  64. _this.unlocked = true;
  65. window.removeEventListener('touchend', unlockaudio, false);
  66. if (_this.onAudioUnlocked) {
  67. _this.onAudioUnlocked();
  68. }
  69. }
  70. }, 0);
  71. };
  72. window.addEventListener('touchend', unlockaudio, false);
  73. };
  74. AudioEngine.prototype._initializeAudioContext = function () {
  75. try {
  76. if (this.canUseWebAudio) {
  77. this._audioContext = new AudioContext();
  78. // create a global volume gain node
  79. this.masterGain = this._audioContext.createGain();
  80. this.masterGain.gain.value = 1;
  81. this.masterGain.connect(this._audioContext.destination);
  82. this._audioContextInitialized = true;
  83. }
  84. }
  85. catch (e) {
  86. this.canUseWebAudio = false;
  87. BABYLON.Tools.Error("Web Audio: " + e.message);
  88. }
  89. };
  90. AudioEngine.prototype.dispose = function () {
  91. if (this.canUseWebAudio && this._audioContextInitialized) {
  92. if (this._connectedAnalyser && this._audioContext) {
  93. this._connectedAnalyser.stopDebugCanvas();
  94. this._connectedAnalyser.dispose();
  95. this.masterGain.disconnect();
  96. this.masterGain.connect(this._audioContext.destination);
  97. this._connectedAnalyser = null;
  98. }
  99. this.masterGain.gain.value = 1;
  100. }
  101. this.WarnedWebAudioUnsupported = false;
  102. };
  103. AudioEngine.prototype.getGlobalVolume = function () {
  104. if (this.canUseWebAudio && this._audioContextInitialized) {
  105. return this.masterGain.gain.value;
  106. }
  107. else {
  108. return -1;
  109. }
  110. };
  111. AudioEngine.prototype.setGlobalVolume = function (newVolume) {
  112. if (this.canUseWebAudio && this._audioContextInitialized) {
  113. this.masterGain.gain.value = newVolume;
  114. }
  115. };
  116. AudioEngine.prototype.connectToAnalyser = function (analyser) {
  117. if (this._connectedAnalyser) {
  118. this._connectedAnalyser.stopDebugCanvas();
  119. }
  120. if (this.canUseWebAudio && this._audioContextInitialized && this._audioContext) {
  121. this._connectedAnalyser = analyser;
  122. this.masterGain.disconnect();
  123. this._connectedAnalyser.connectAudioNodes(this.masterGain, this._audioContext.destination);
  124. }
  125. };
  126. return AudioEngine;
  127. }());
  128. BABYLON.AudioEngine = AudioEngine;
  129. })(BABYLON || (BABYLON = {}));
  130. //# sourceMappingURL=babylon.audioEngine.js.map
  131. var BABYLON;
  132. (function (BABYLON) {
  133. var Sound = /** @class */ (function () {
  134. /**
  135. * Create a sound and attach it to a scene
  136. * @param name Name of your sound
  137. * @param urlOrArrayBuffer Url to the sound to load async or ArrayBuffer
  138. * @param readyToPlayCallback Provide a callback function if you'd like to load your code once the sound is ready to be played
  139. * @param options Objects to provide with the current available options: autoplay, loop, volume, spatialSound, maxDistance, rolloffFactor, refDistance, distanceModel, panningModel, streaming
  140. */
  141. function Sound(name, urlOrArrayBuffer, scene, readyToPlayCallback, options) {
  142. if (readyToPlayCallback === void 0) { readyToPlayCallback = null; }
  143. var _this = this;
  144. this.autoplay = false;
  145. this.loop = false;
  146. this.useCustomAttenuation = false;
  147. this.spatialSound = false;
  148. this.refDistance = 1;
  149. this.rolloffFactor = 1;
  150. this.maxDistance = 100;
  151. this.distanceModel = "linear";
  152. this._panningModel = "equalpower";
  153. this._playbackRate = 1;
  154. this._streaming = false;
  155. this._startTime = 0;
  156. this._startOffset = 0;
  157. this._position = BABYLON.Vector3.Zero();
  158. this._localDirection = new BABYLON.Vector3(1, 0, 0);
  159. this._volume = 1;
  160. this._isReadyToPlay = false;
  161. this.isPlaying = false;
  162. this.isPaused = false;
  163. this._isDirectional = false;
  164. // Used if you'd like to create a directional sound.
  165. // If not set, the sound will be omnidirectional
  166. this._coneInnerAngle = 360;
  167. this._coneOuterAngle = 360;
  168. this._coneOuterGain = 0;
  169. this._isOutputConnected = false;
  170. this._urlType = "Unknown";
  171. this.name = name;
  172. this._scene = scene;
  173. this._readyToPlayCallback = readyToPlayCallback;
  174. // Default custom attenuation function is a linear attenuation
  175. this._customAttenuationFunction = function (currentVolume, currentDistance, maxDistance, refDistance, rolloffFactor) {
  176. if (currentDistance < maxDistance) {
  177. return currentVolume * (1 - currentDistance / maxDistance);
  178. }
  179. else {
  180. return 0;
  181. }
  182. };
  183. if (options) {
  184. this.autoplay = options.autoplay || false;
  185. this.loop = options.loop || false;
  186. // if volume === 0, we need another way to check this option
  187. if (options.volume !== undefined) {
  188. this._volume = options.volume;
  189. }
  190. this.spatialSound = options.spatialSound || false;
  191. this.maxDistance = options.maxDistance || 100;
  192. this.useCustomAttenuation = options.useCustomAttenuation || false;
  193. this.rolloffFactor = options.rolloffFactor || 1;
  194. this.refDistance = options.refDistance || 1;
  195. this.distanceModel = options.distanceModel || "linear";
  196. this._playbackRate = options.playbackRate || 1;
  197. this._streaming = options.streaming || false;
  198. }
  199. if (BABYLON.Engine.audioEngine.canUseWebAudio && BABYLON.Engine.audioEngine.audioContext) {
  200. this._soundGain = BABYLON.Engine.audioEngine.audioContext.createGain();
  201. this._soundGain.gain.value = this._volume;
  202. this._inputAudioNode = this._soundGain;
  203. this._ouputAudioNode = this._soundGain;
  204. if (this.spatialSound) {
  205. this._createSpatialParameters();
  206. }
  207. this._scene.mainSoundTrack.AddSound(this);
  208. var validParameter = true;
  209. // if no parameter is passed, you need to call setAudioBuffer yourself to prepare the sound
  210. if (urlOrArrayBuffer) {
  211. if (typeof (urlOrArrayBuffer) === "string")
  212. this._urlType = "String";
  213. if (Array.isArray(urlOrArrayBuffer))
  214. this._urlType = "Array";
  215. if (urlOrArrayBuffer instanceof ArrayBuffer)
  216. this._urlType = "ArrayBuffer";
  217. var urls = [];
  218. var codecSupportedFound = false;
  219. switch (this._urlType) {
  220. case "ArrayBuffer":
  221. if (urlOrArrayBuffer.byteLength > 0) {
  222. codecSupportedFound = true;
  223. this._soundLoaded(urlOrArrayBuffer);
  224. }
  225. break;
  226. case "String":
  227. urls.push(urlOrArrayBuffer);
  228. case "Array":
  229. if (urls.length === 0)
  230. urls = urlOrArrayBuffer;
  231. // If we found a supported format, we load it immediately and stop the loop
  232. for (var i = 0; i < urls.length; i++) {
  233. var url = urls[i];
  234. if (url.indexOf(".mp3", url.length - 4) !== -1 && BABYLON.Engine.audioEngine.isMP3supported) {
  235. codecSupportedFound = true;
  236. }
  237. if (url.indexOf(".ogg", url.length - 4) !== -1 && BABYLON.Engine.audioEngine.isOGGsupported) {
  238. codecSupportedFound = true;
  239. }
  240. if (url.indexOf(".wav", url.length - 4) !== -1) {
  241. codecSupportedFound = true;
  242. }
  243. if (url.indexOf("blob:") !== -1) {
  244. codecSupportedFound = true;
  245. }
  246. if (codecSupportedFound) {
  247. // Loading sound using XHR2
  248. if (!this._streaming) {
  249. this._scene._loadFile(url, function (data) { _this._soundLoaded(data); }, undefined, true, true);
  250. }
  251. else {
  252. this._htmlAudioElement = new Audio(url);
  253. this._htmlAudioElement.controls = false;
  254. this._htmlAudioElement.loop = this.loop;
  255. BABYLON.Tools.SetCorsBehavior(url, this._htmlAudioElement);
  256. this._htmlAudioElement.preload = "auto";
  257. this._htmlAudioElement.addEventListener("canplaythrough", function () {
  258. _this._isReadyToPlay = true;
  259. if (_this.autoplay) {
  260. _this.play();
  261. }
  262. if (_this._readyToPlayCallback) {
  263. _this._readyToPlayCallback();
  264. }
  265. });
  266. document.body.appendChild(this._htmlAudioElement);
  267. }
  268. break;
  269. }
  270. }
  271. break;
  272. default:
  273. validParameter = false;
  274. break;
  275. }
  276. if (!validParameter) {
  277. BABYLON.Tools.Error("Parameter must be a URL to the sound, an Array of URLs (.mp3 & .ogg) or an ArrayBuffer of the sound.");
  278. }
  279. else {
  280. if (!codecSupportedFound) {
  281. this._isReadyToPlay = true;
  282. // Simulating a ready to play event to avoid breaking code path
  283. if (this._readyToPlayCallback) {
  284. window.setTimeout(function () {
  285. if (_this._readyToPlayCallback) {
  286. _this._readyToPlayCallback();
  287. }
  288. }, 1000);
  289. }
  290. }
  291. }
  292. }
  293. }
  294. else {
  295. // Adding an empty sound to avoid breaking audio calls for non Web Audio browsers
  296. this._scene.mainSoundTrack.AddSound(this);
  297. if (!BABYLON.Engine.audioEngine.WarnedWebAudioUnsupported) {
  298. BABYLON.Tools.Error("Web Audio is not supported by your browser.");
  299. BABYLON.Engine.audioEngine.WarnedWebAudioUnsupported = true;
  300. }
  301. // Simulating a ready to play event to avoid breaking code for non web audio browsers
  302. if (this._readyToPlayCallback) {
  303. window.setTimeout(function () {
  304. if (_this._readyToPlayCallback) {
  305. _this._readyToPlayCallback();
  306. }
  307. }, 1000);
  308. }
  309. }
  310. }
  311. Sound.prototype.dispose = function () {
  312. if (BABYLON.Engine.audioEngine.canUseWebAudio && this._isReadyToPlay) {
  313. if (this.isPlaying) {
  314. this.stop();
  315. }
  316. this._isReadyToPlay = false;
  317. if (this.soundTrackId === -1) {
  318. this._scene.mainSoundTrack.RemoveSound(this);
  319. }
  320. else {
  321. this._scene.soundTracks[this.soundTrackId].RemoveSound(this);
  322. }
  323. if (this._soundGain) {
  324. this._soundGain.disconnect();
  325. this._soundGain = null;
  326. }
  327. if (this._soundPanner) {
  328. this._soundPanner.disconnect();
  329. this._soundPanner = null;
  330. }
  331. if (this._soundSource) {
  332. this._soundSource.disconnect();
  333. this._soundSource = null;
  334. }
  335. this._audioBuffer = null;
  336. if (this._htmlAudioElement) {
  337. this._htmlAudioElement.pause();
  338. this._htmlAudioElement.src = "";
  339. document.body.removeChild(this._htmlAudioElement);
  340. }
  341. if (this._connectedMesh && this._registerFunc) {
  342. this._connectedMesh.unregisterAfterWorldMatrixUpdate(this._registerFunc);
  343. this._connectedMesh = null;
  344. }
  345. }
  346. };
  347. Sound.prototype.isReady = function () {
  348. return this._isReadyToPlay;
  349. };
  350. Sound.prototype._soundLoaded = function (audioData) {
  351. var _this = this;
  352. if (!BABYLON.Engine.audioEngine.audioContext) {
  353. return;
  354. }
  355. BABYLON.Engine.audioEngine.audioContext.decodeAudioData(audioData, function (buffer) {
  356. _this._audioBuffer = buffer;
  357. _this._isReadyToPlay = true;
  358. if (_this.autoplay) {
  359. _this.play();
  360. }
  361. if (_this._readyToPlayCallback) {
  362. _this._readyToPlayCallback();
  363. }
  364. }, function (err) { BABYLON.Tools.Error("Error while decoding audio data for: " + _this.name + " / Error: " + err); });
  365. };
  366. Sound.prototype.setAudioBuffer = function (audioBuffer) {
  367. if (BABYLON.Engine.audioEngine.canUseWebAudio) {
  368. this._audioBuffer = audioBuffer;
  369. this._isReadyToPlay = true;
  370. }
  371. };
  372. Sound.prototype.updateOptions = function (options) {
  373. if (options) {
  374. this.loop = options.loop || this.loop;
  375. this.maxDistance = options.maxDistance || this.maxDistance;
  376. this.useCustomAttenuation = options.useCustomAttenuation || this.useCustomAttenuation;
  377. this.rolloffFactor = options.rolloffFactor || this.rolloffFactor;
  378. this.refDistance = options.refDistance || this.refDistance;
  379. this.distanceModel = options.distanceModel || this.distanceModel;
  380. this._playbackRate = options.playbackRate || this._playbackRate;
  381. this._updateSpatialParameters();
  382. if (this.isPlaying) {
  383. if (this._streaming) {
  384. this._htmlAudioElement.playbackRate = this._playbackRate;
  385. }
  386. else {
  387. if (this._soundSource) {
  388. this._soundSource.playbackRate.value = this._playbackRate;
  389. }
  390. }
  391. }
  392. }
  393. };
  394. Sound.prototype._createSpatialParameters = function () {
  395. if (BABYLON.Engine.audioEngine.canUseWebAudio && BABYLON.Engine.audioEngine.audioContext) {
  396. if (this._scene.headphone) {
  397. this._panningModel = "HRTF";
  398. }
  399. this._soundPanner = BABYLON.Engine.audioEngine.audioContext.createPanner();
  400. this._updateSpatialParameters();
  401. this._soundPanner.connect(this._ouputAudioNode);
  402. this._inputAudioNode = this._soundPanner;
  403. }
  404. };
  405. Sound.prototype._updateSpatialParameters = function () {
  406. if (this.spatialSound && this._soundPanner) {
  407. if (this.useCustomAttenuation) {
  408. // Tricks to disable in a way embedded Web Audio attenuation
  409. this._soundPanner.distanceModel = "linear";
  410. this._soundPanner.maxDistance = Number.MAX_VALUE;
  411. this._soundPanner.refDistance = 1;
  412. this._soundPanner.rolloffFactor = 1;
  413. this._soundPanner.panningModel = this._panningModel;
  414. }
  415. else {
  416. this._soundPanner.distanceModel = this.distanceModel;
  417. this._soundPanner.maxDistance = this.maxDistance;
  418. this._soundPanner.refDistance = this.refDistance;
  419. this._soundPanner.rolloffFactor = this.rolloffFactor;
  420. this._soundPanner.panningModel = this._panningModel;
  421. }
  422. }
  423. };
  424. Sound.prototype.switchPanningModelToHRTF = function () {
  425. this._panningModel = "HRTF";
  426. this._switchPanningModel();
  427. };
  428. Sound.prototype.switchPanningModelToEqualPower = function () {
  429. this._panningModel = "equalpower";
  430. this._switchPanningModel();
  431. };
  432. Sound.prototype._switchPanningModel = function () {
  433. if (BABYLON.Engine.audioEngine.canUseWebAudio && this.spatialSound && this._soundPanner) {
  434. this._soundPanner.panningModel = this._panningModel;
  435. }
  436. };
  437. Sound.prototype.connectToSoundTrackAudioNode = function (soundTrackAudioNode) {
  438. if (BABYLON.Engine.audioEngine.canUseWebAudio) {
  439. if (this._isOutputConnected) {
  440. this._ouputAudioNode.disconnect();
  441. }
  442. this._ouputAudioNode.connect(soundTrackAudioNode);
  443. this._isOutputConnected = true;
  444. }
  445. };
  446. /**
  447. * Transform this sound into a directional source
  448. * @param coneInnerAngle Size of the inner cone in degree
  449. * @param coneOuterAngle Size of the outer cone in degree
  450. * @param coneOuterGain Volume of the sound outside the outer cone (between 0.0 and 1.0)
  451. */
  452. Sound.prototype.setDirectionalCone = function (coneInnerAngle, coneOuterAngle, coneOuterGain) {
  453. if (coneOuterAngle < coneInnerAngle) {
  454. BABYLON.Tools.Error("setDirectionalCone(): outer angle of the cone must be superior or equal to the inner angle.");
  455. return;
  456. }
  457. this._coneInnerAngle = coneInnerAngle;
  458. this._coneOuterAngle = coneOuterAngle;
  459. this._coneOuterGain = coneOuterGain;
  460. this._isDirectional = true;
  461. if (this.isPlaying && this.loop) {
  462. this.stop();
  463. this.play();
  464. }
  465. };
  466. Sound.prototype.setPosition = function (newPosition) {
  467. this._position = newPosition;
  468. if (BABYLON.Engine.audioEngine.canUseWebAudio && this.spatialSound && this._soundPanner) {
  469. this._soundPanner.setPosition(this._position.x, this._position.y, this._position.z);
  470. }
  471. };
  472. Sound.prototype.setLocalDirectionToMesh = function (newLocalDirection) {
  473. this._localDirection = newLocalDirection;
  474. if (BABYLON.Engine.audioEngine.canUseWebAudio && this._connectedMesh && this.isPlaying) {
  475. this._updateDirection();
  476. }
  477. };
  478. Sound.prototype._updateDirection = function () {
  479. if (!this._connectedMesh || !this._soundPanner) {
  480. return;
  481. }
  482. var mat = this._connectedMesh.getWorldMatrix();
  483. var direction = BABYLON.Vector3.TransformNormal(this._localDirection, mat);
  484. direction.normalize();
  485. this._soundPanner.setOrientation(direction.x, direction.y, direction.z);
  486. };
  487. Sound.prototype.updateDistanceFromListener = function () {
  488. if (BABYLON.Engine.audioEngine.canUseWebAudio && this._connectedMesh && this.useCustomAttenuation && this._soundGain && this._scene.activeCamera) {
  489. var distance = this._connectedMesh.getDistanceToCamera(this._scene.activeCamera);
  490. this._soundGain.gain.value = this._customAttenuationFunction(this._volume, distance, this.maxDistance, this.refDistance, this.rolloffFactor);
  491. }
  492. };
  493. Sound.prototype.setAttenuationFunction = function (callback) {
  494. this._customAttenuationFunction = callback;
  495. };
  496. /**
  497. * Play the sound
  498. * @param time (optional) Start the sound after X seconds. Start immediately (0) by default.
  499. * @param offset (optional) Start the sound setting it at a specific time
  500. */
  501. Sound.prototype.play = function (time, offset) {
  502. var _this = this;
  503. if (this._isReadyToPlay && this._scene.audioEnabled && BABYLON.Engine.audioEngine.audioContext) {
  504. try {
  505. if (this._startOffset < 0) {
  506. time = -this._startOffset;
  507. this._startOffset = 0;
  508. }
  509. var startTime = time ? BABYLON.Engine.audioEngine.audioContext.currentTime + time : BABYLON.Engine.audioEngine.audioContext.currentTime;
  510. if (!this._soundSource || !this._streamingSource) {
  511. if (this.spatialSound && this._soundPanner) {
  512. this._soundPanner.setPosition(this._position.x, this._position.y, this._position.z);
  513. if (this._isDirectional) {
  514. this._soundPanner.coneInnerAngle = this._coneInnerAngle;
  515. this._soundPanner.coneOuterAngle = this._coneOuterAngle;
  516. this._soundPanner.coneOuterGain = this._coneOuterGain;
  517. if (this._connectedMesh) {
  518. this._updateDirection();
  519. }
  520. else {
  521. this._soundPanner.setOrientation(this._localDirection.x, this._localDirection.y, this._localDirection.z);
  522. }
  523. }
  524. }
  525. }
  526. if (this._streaming) {
  527. if (!this._streamingSource) {
  528. this._streamingSource = BABYLON.Engine.audioEngine.audioContext.createMediaElementSource(this._htmlAudioElement);
  529. this._htmlAudioElement.onended = function () { _this._onended(); };
  530. this._htmlAudioElement.playbackRate = this._playbackRate;
  531. }
  532. this._streamingSource.disconnect();
  533. this._streamingSource.connect(this._inputAudioNode);
  534. this._htmlAudioElement.play();
  535. }
  536. else {
  537. this._soundSource = BABYLON.Engine.audioEngine.audioContext.createBufferSource();
  538. this._soundSource.buffer = this._audioBuffer;
  539. this._soundSource.connect(this._inputAudioNode);
  540. this._soundSource.loop = this.loop;
  541. this._soundSource.playbackRate.value = this._playbackRate;
  542. this._soundSource.onended = function () { _this._onended(); };
  543. if (this._soundSource.buffer) {
  544. this._soundSource.start(startTime, this.isPaused ? this._startOffset % this._soundSource.buffer.duration : offset ? offset : 0);
  545. }
  546. }
  547. this._startTime = startTime;
  548. this.isPlaying = true;
  549. this.isPaused = false;
  550. }
  551. catch (ex) {
  552. BABYLON.Tools.Error("Error while trying to play audio: " + this.name + ", " + ex.message);
  553. }
  554. }
  555. };
  556. Sound.prototype._onended = function () {
  557. this.isPlaying = false;
  558. if (this.onended) {
  559. this.onended();
  560. }
  561. };
  562. /**
  563. * Stop the sound
  564. * @param time (optional) Stop the sound after X seconds. Stop immediately (0) by default.
  565. */
  566. Sound.prototype.stop = function (time) {
  567. if (this.isPlaying) {
  568. if (this._streaming) {
  569. this._htmlAudioElement.pause();
  570. // Test needed for Firefox or it will generate an Invalid State Error
  571. if (this._htmlAudioElement.currentTime > 0) {
  572. this._htmlAudioElement.currentTime = 0;
  573. }
  574. }
  575. else if (BABYLON.Engine.audioEngine.audioContext && this._soundSource) {
  576. var stopTime = time ? BABYLON.Engine.audioEngine.audioContext.currentTime + time : BABYLON.Engine.audioEngine.audioContext.currentTime;
  577. this._soundSource.stop(stopTime);
  578. this._soundSource.onended = function () { };
  579. if (!this.isPaused) {
  580. this._startOffset = 0;
  581. }
  582. }
  583. this.isPlaying = false;
  584. }
  585. };
  586. Sound.prototype.pause = function () {
  587. if (this.isPlaying) {
  588. this.isPaused = true;
  589. if (this._streaming) {
  590. this._htmlAudioElement.pause();
  591. }
  592. else if (BABYLON.Engine.audioEngine.audioContext) {
  593. this.stop(0);
  594. this._startOffset += BABYLON.Engine.audioEngine.audioContext.currentTime - this._startTime;
  595. }
  596. }
  597. };
  598. Sound.prototype.setVolume = function (newVolume, time) {
  599. if (BABYLON.Engine.audioEngine.canUseWebAudio && this._soundGain) {
  600. if (time && BABYLON.Engine.audioEngine.audioContext) {
  601. this._soundGain.gain.cancelScheduledValues(BABYLON.Engine.audioEngine.audioContext.currentTime);
  602. this._soundGain.gain.setValueAtTime(this._soundGain.gain.value, BABYLON.Engine.audioEngine.audioContext.currentTime);
  603. this._soundGain.gain.linearRampToValueAtTime(newVolume, BABYLON.Engine.audioEngine.audioContext.currentTime + time);
  604. }
  605. else {
  606. this._soundGain.gain.value = newVolume;
  607. }
  608. }
  609. this._volume = newVolume;
  610. };
  611. Sound.prototype.setPlaybackRate = function (newPlaybackRate) {
  612. this._playbackRate = newPlaybackRate;
  613. if (this.isPlaying) {
  614. if (this._streaming) {
  615. this._htmlAudioElement.playbackRate = this._playbackRate;
  616. }
  617. else if (this._soundSource) {
  618. this._soundSource.playbackRate.value = this._playbackRate;
  619. }
  620. }
  621. };
  622. Sound.prototype.getVolume = function () {
  623. return this._volume;
  624. };
  625. Sound.prototype.attachToMesh = function (meshToConnectTo) {
  626. var _this = this;
  627. if (this._connectedMesh && this._registerFunc) {
  628. this._connectedMesh.unregisterAfterWorldMatrixUpdate(this._registerFunc);
  629. this._registerFunc = null;
  630. }
  631. this._connectedMesh = meshToConnectTo;
  632. if (!this.spatialSound) {
  633. this.spatialSound = true;
  634. this._createSpatialParameters();
  635. if (this.isPlaying && this.loop) {
  636. this.stop();
  637. this.play();
  638. }
  639. }
  640. this._onRegisterAfterWorldMatrixUpdate(this._connectedMesh);
  641. this._registerFunc = function (connectedMesh) { return _this._onRegisterAfterWorldMatrixUpdate(connectedMesh); };
  642. meshToConnectTo.registerAfterWorldMatrixUpdate(this._registerFunc);
  643. };
  644. Sound.prototype.detachFromMesh = function () {
  645. if (this._connectedMesh && this._registerFunc) {
  646. this._connectedMesh.unregisterAfterWorldMatrixUpdate(this._registerFunc);
  647. this._registerFunc = null;
  648. this._connectedMesh = null;
  649. }
  650. };
  651. Sound.prototype._onRegisterAfterWorldMatrixUpdate = function (node) {
  652. if (!node.getBoundingInfo) {
  653. return;
  654. }
  655. var mesh = node;
  656. var boundingInfo = mesh.getBoundingInfo();
  657. this.setPosition(boundingInfo.boundingSphere.centerWorld);
  658. if (BABYLON.Engine.audioEngine.canUseWebAudio && this._isDirectional && this.isPlaying) {
  659. this._updateDirection();
  660. }
  661. };
  662. Sound.prototype.clone = function () {
  663. var _this = this;
  664. if (!this._streaming) {
  665. var setBufferAndRun = function () {
  666. if (_this._isReadyToPlay) {
  667. clonedSound._audioBuffer = _this.getAudioBuffer();
  668. clonedSound._isReadyToPlay = true;
  669. if (clonedSound.autoplay) {
  670. clonedSound.play();
  671. }
  672. }
  673. else {
  674. window.setTimeout(setBufferAndRun, 300);
  675. }
  676. };
  677. var currentOptions = {
  678. autoplay: this.autoplay, loop: this.loop,
  679. volume: this._volume, spatialSound: this.spatialSound, maxDistance: this.maxDistance,
  680. useCustomAttenuation: this.useCustomAttenuation, rolloffFactor: this.rolloffFactor,
  681. refDistance: this.refDistance, distanceModel: this.distanceModel
  682. };
  683. var clonedSound = new Sound(this.name + "_cloned", new ArrayBuffer(0), this._scene, null, currentOptions);
  684. if (this.useCustomAttenuation) {
  685. clonedSound.setAttenuationFunction(this._customAttenuationFunction);
  686. }
  687. clonedSound.setPosition(this._position);
  688. clonedSound.setPlaybackRate(this._playbackRate);
  689. setBufferAndRun();
  690. return clonedSound;
  691. }
  692. else {
  693. return null;
  694. }
  695. };
  696. Sound.prototype.getAudioBuffer = function () {
  697. return this._audioBuffer;
  698. };
  699. Sound.prototype.serialize = function () {
  700. var serializationObject = {
  701. name: this.name,
  702. url: this.name,
  703. autoplay: this.autoplay,
  704. loop: this.loop,
  705. volume: this._volume,
  706. spatialSound: this.spatialSound,
  707. maxDistance: this.maxDistance,
  708. rolloffFactor: this.rolloffFactor,
  709. refDistance: this.refDistance,
  710. distanceModel: this.distanceModel,
  711. playbackRate: this._playbackRate,
  712. panningModel: this._panningModel,
  713. soundTrackId: this.soundTrackId
  714. };
  715. if (this.spatialSound) {
  716. if (this._connectedMesh)
  717. serializationObject.connectedMeshId = this._connectedMesh.id;
  718. serializationObject.position = this._position.asArray();
  719. serializationObject.refDistance = this.refDistance;
  720. serializationObject.distanceModel = this.distanceModel;
  721. serializationObject.isDirectional = this._isDirectional;
  722. serializationObject.localDirectionToMesh = this._localDirection.asArray();
  723. serializationObject.coneInnerAngle = this._coneInnerAngle;
  724. serializationObject.coneOuterAngle = this._coneOuterAngle;
  725. serializationObject.coneOuterGain = this._coneOuterGain;
  726. }
  727. return serializationObject;
  728. };
  729. Sound.Parse = function (parsedSound, scene, rootUrl, sourceSound) {
  730. var soundName = parsedSound.name;
  731. var soundUrl;
  732. if (parsedSound.url) {
  733. soundUrl = rootUrl + parsedSound.url;
  734. }
  735. else {
  736. soundUrl = rootUrl + soundName;
  737. }
  738. var options = {
  739. autoplay: parsedSound.autoplay, loop: parsedSound.loop, volume: parsedSound.volume,
  740. spatialSound: parsedSound.spatialSound, maxDistance: parsedSound.maxDistance,
  741. rolloffFactor: parsedSound.rolloffFactor,
  742. refDistance: parsedSound.refDistance,
  743. distanceModel: parsedSound.distanceModel,
  744. playbackRate: parsedSound.playbackRate
  745. };
  746. var newSound;
  747. if (!sourceSound) {
  748. newSound = new Sound(soundName, soundUrl, scene, function () { scene._removePendingData(newSound); }, options);
  749. scene._addPendingData(newSound);
  750. }
  751. else {
  752. var setBufferAndRun = function () {
  753. if (sourceSound._isReadyToPlay) {
  754. newSound._audioBuffer = sourceSound.getAudioBuffer();
  755. newSound._isReadyToPlay = true;
  756. if (newSound.autoplay) {
  757. newSound.play();
  758. }
  759. }
  760. else {
  761. window.setTimeout(setBufferAndRun, 300);
  762. }
  763. };
  764. newSound = new Sound(soundName, new ArrayBuffer(0), scene, null, options);
  765. setBufferAndRun();
  766. }
  767. if (parsedSound.position) {
  768. var soundPosition = BABYLON.Vector3.FromArray(parsedSound.position);
  769. newSound.setPosition(soundPosition);
  770. }
  771. if (parsedSound.isDirectional) {
  772. newSound.setDirectionalCone(parsedSound.coneInnerAngle || 360, parsedSound.coneOuterAngle || 360, parsedSound.coneOuterGain || 0);
  773. if (parsedSound.localDirectionToMesh) {
  774. var localDirectionToMesh = BABYLON.Vector3.FromArray(parsedSound.localDirectionToMesh);
  775. newSound.setLocalDirectionToMesh(localDirectionToMesh);
  776. }
  777. }
  778. if (parsedSound.connectedMeshId) {
  779. var connectedMesh = scene.getMeshByID(parsedSound.connectedMeshId);
  780. if (connectedMesh) {
  781. newSound.attachToMesh(connectedMesh);
  782. }
  783. }
  784. return newSound;
  785. };
  786. return Sound;
  787. }());
  788. BABYLON.Sound = Sound;
  789. })(BABYLON || (BABYLON = {}));
  790. //# sourceMappingURL=babylon.sound.js.map
  791. BABYLON.Effect.ShadersStore['defaultVertexShader'] = "#include<__decl__defaultVertex>\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef TANGENT\nattribute vec4 tangent;\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<helperFunctions>\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\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#if defined(AMBIENT) && AMBIENTDIRECTUV == 0\nvarying vec2 vAmbientUV;\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0\nvarying vec2 vOpacityUV;\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0\nvarying vec2 vEmissiveUV;\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0\nvarying vec2 vLightmapUV;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0\nvarying vec2 vSpecularUV;\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0\nvarying vec2 vBumpUV;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<bumpVertexDeclaration>\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<morphTargetsVertexGlobalDeclaration>\n#include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#include<logDepthDeclaration>\nvoid main(void) {\nvec3 positionUpdated=position;\n#ifdef NORMAL \nvec3 normalUpdated=normal;\n#endif\n#ifdef TANGENT\nvec4 tangentUpdated=tangent;\n#endif\n#include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=positionUpdated;\n#endif \n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nmat3 normalWorld=mat3(finalWorld);\n#ifdef NONUNIFORMSCALING\nnormalWorld=transposeMat3(inverseMat3(normalWorld));\n#endif\nvNormalW=normalize(normalWorld*normalUpdated);\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,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 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#if defined(AMBIENT) && AMBIENTDIRECTUV == 0\nif (vAmbientInfos.x == 0.)\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(OPACITY) && OPACITYDIRECTUV == 0\nif (vOpacityInfos.x == 0.)\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(EMISSIVE) && EMISSIVEDIRECTUV == 0\nif (vEmissiveInfos.x == 0.)\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(LIGHTMAP) && LIGHTMAPDIRECTUV == 0\nif (vLightmapInfos.x == 0.)\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM) && SPECULARDIRECTUV == 0\nif (vSpecularInfos.x == 0.)\n{\nvSpecularUV=vec2(specularMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvSpecularUV=vec2(specularMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(BUMP) && BUMPDIRECTUV == 0\nif (vBumpInfos.x == 0.)\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#include<bumpVertex>\n#include<clipPlaneVertex>\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n#ifdef VERTEXCOLOR\n\nvColor=color;\n#endif\n#include<pointCloudVertex>\n#include<logDepthVertex>\n}";
  792. BABYLON.Effect.ShadersStore['defaultPixelShader'] = "#include<__decl__defaultFragment>\n#if defined(BUMP) || !defined(NORMAL)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\n\n#define RECIPROCAL_PI2 0.15915494\nuniform vec3 vEyePosition;\nuniform vec3 vAmbientColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#ifdef MAINUV1\nvarying vec2 vMainUV1;\n#endif\n#ifdef MAINUV2\nvarying vec2 vMainUV2;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n\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#ifdef AMBIENT\n#if AMBIENTDIRECTUV == 1\n#define vAmbientUV vMainUV1\n#elif AMBIENTDIRECTUV == 2\n#define vAmbientUV vMainUV2\n#else\nvarying vec2 vAmbientUV;\n#endif\nuniform sampler2D ambientSampler;\n#endif\n#ifdef OPACITY \n#if OPACITYDIRECTUV == 1\n#define vOpacityUV vMainUV1\n#elif OPACITYDIRECTUV == 2\n#define vOpacityUV vMainUV2\n#else\nvarying vec2 vOpacityUV;\n#endif\nuniform sampler2D opacitySampler;\n#endif\n#ifdef EMISSIVE\n#if EMISSIVEDIRECTUV == 1\n#define vEmissiveUV vMainUV1\n#elif EMISSIVEDIRECTUV == 2\n#define vEmissiveUV vMainUV2\n#else\nvarying vec2 vEmissiveUV;\n#endif\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\n#if LIGHTMAPDIRECTUV == 1\n#define vLightmapUV vMainUV1\n#elif LIGHTMAPDIRECTUV == 2\n#define vLightmapUV vMainUV2\n#else\nvarying vec2 vLightmapUV;\n#endif\nuniform sampler2D lightmapSampler;\n#endif\n#ifdef REFRACTION\n#ifdef REFRACTIONMAP_3D\nuniform samplerCube refractionCubeSampler;\n#else\nuniform sampler2D refraction2DSampler;\n#endif\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\n#if SPECULARDIRECTUV == 1\n#define vSpecularUV vMainUV1\n#elif SPECULARDIRECTUV == 2\n#define vSpecularUV vMainUV2\n#else\nvarying vec2 vSpecularUV;\n#endif\nuniform sampler2D specularSampler;\n#endif\n\n#include<fresnelFunction>\n\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\nuniform samplerCube reflectionCubeSampler;\n#else\nuniform sampler2D reflection2DSampler;\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#include<imageProcessingDeclaration>\n#include<imageProcessingFunctions>\n#include<bumpFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\n#include<fogFragmentDeclaration>\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\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=normalize(-cross(dFdx(vPositionW),dFdy(vPositionW)));\n#endif\n#include<bumpFragment>\n#ifdef TWOSIDEDLIGHTING\nnormalW=gl_FrontFacing ? normalW : -normalW;\n#endif\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV+uvOffset);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#ifdef ALPHAFROMDIFFUSE\nalpha*=baseColor.a;\n#endif\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#include<depthPrePass>\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\nvec3 baseAmbientColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nbaseAmbientColor=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;\n#endif\n\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularColor=vSpecularColor.rgb;\n#ifdef SPECULAR\nvec4 specularMapColor=texture2D(specularSampler,vSpecularUV+uvOffset);\nspecularColor=specularMapColor.rgb;\n#ifdef GLOSSINESS\nglossiness=glossiness*specularMapColor.a;\n#endif\n#endif\n#else\nfloat glossiness=0.;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\nfloat shadow=1.;\n#ifdef LIGHTMAP\nvec3 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset).rgb*vLightmapInfos.y;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\n\nvec3 refractionColor=vec3(0.,0.,0.);\n#ifdef REFRACTION\nvec3 refractionVector=normalize(refract(-viewDirectionW,normalW,vRefractionInfos.y));\n#ifdef REFRACTIONMAP_3D\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;\nif (dot(refractionVector,viewDirectionW)<1.0)\n{\nrefractionColor=textureCube(refractionCubeSampler,refractionVector).rgb*vRefractionInfos.x;\n}\n#else\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));\nvec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;\nrefractionCoords.y=1.0-refractionCoords.y;\nrefractionColor=texture2D(refraction2DSampler,refractionCoords).rgb*vRefractionInfos.x;\n#endif\n#endif\n\nvec3 reflectionColor=vec3(0.,0.,0.);\n#ifdef REFLECTION\nvec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef REFLECTIONMAP_3D\n#ifdef ROUGHNESS\nfloat bias=vReflectionInfos.y;\n#ifdef SPECULARTERM\n#ifdef SPECULAR\n#ifdef GLOSSINESS\nbias*=(1.0-specularMapColor.a);\n#endif\n#endif\n#endif\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW,bias).rgb*vReflectionInfos.x;\n#else\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW).rgb*vReflectionInfos.x;\n#endif\n#else\nvec2 coords=vReflectionUVW.xy;\n#ifdef REFLECTIONMAP_PROJECTION\ncoords/=vReflectionUVW.z;\n#endif\ncoords.y=1.0-coords.y;\nreflectionColor=texture2D(reflection2DSampler,coords).rgb*vReflectionInfos.x;\n#endif\n#ifdef REFLECTIONFRESNEL\nfloat reflectionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,reflectionRightColor.a,reflectionLeftColor.a);\n#ifdef REFLECTIONFRESNELFROMSPECULAR\n#ifdef SPECULARTERM\nreflectionColor*=specularColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#else\nreflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#else\nreflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#endif\n#endif\n#ifdef REFRACTIONFRESNEL\nfloat refractionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,refractionRightColor.a,refractionLeftColor.a);\nrefractionColor*=refractionLeftColor.rgb*(1.0-refractionFresnelTerm)+refractionFresnelTerm*refractionRightColor.rgb;\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n#ifdef OPACITYRGB\nopacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);\nalpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n#else\nalpha*=opacityMap.a*vOpacityInfos.y;\n#endif\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef OPACITYFRESNEL\nfloat opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);\nalpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;\n#endif\n\nvec3 emissiveColor=vEmissiveColor;\n#ifdef EMISSIVE\nemissiveColor+=texture2D(emissiveSampler,vEmissiveUV+uvOffset).rgb*vEmissiveInfos.y;\n#endif\n#ifdef EMISSIVEFRESNEL\nfloat emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);\nemissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;\n#endif\n\n#ifdef DIFFUSEFRESNEL\nfloat diffuseFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,diffuseRightColor.a,diffuseLeftColor.a);\ndiffuseBase*=diffuseLeftColor.rgb*(1.0-diffuseFresnelTerm)+diffuseFresnelTerm*diffuseRightColor.rgb;\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#else\n#ifdef LINKEMISSIVEWITHDIFFUSE\nvec3 finalDiffuse=clamp((diffuseBase+emissiveColor)*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#else\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+emissiveColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#endif\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#ifdef SPECULAROVERALPHA\nalpha=clamp(alpha+dot(finalSpecular,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#ifdef REFLECTIONOVERALPHA\nalpha=clamp(alpha+dot(reflectionColor,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec4 color=vec4(clamp(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+emissiveColor+refractionColor,0.0,1.0),alpha);\n#else\nvec4 color=vec4(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+refractionColor,alpha);\n#endif\n\n#ifdef LIGHTMAP\n#ifndef LIGHTMAPEXCLUDED\n#ifdef USELIGHTMAPASSHADOWMAP\ncolor.rgb*=lightmapColor;\n#else\ncolor.rgb+=lightmapColor;\n#endif\n#endif\n#endif\n#include<logDepthFragment>\n#include<fogFragment>\n\n\n#ifdef IMAGEPROCESSINGPOSTPROCESS\ncolor.rgb=toLinearSpace(color.rgb);\n#else\n#ifdef IMAGEPROCESSING\ncolor.rgb=toLinearSpace(color.rgb);\ncolor=applyImageProcessing(color);\n#endif\n#endif\n#ifdef PREMULTIPLYALPHA\n\ncolor.rgb*=color.a;\n#endif\ngl_FragColor=color;\n}";
  793. var BABYLON;
  794. (function (BABYLON) {
  795. var SoundTrack = /** @class */ (function () {
  796. function SoundTrack(scene, options) {
  797. this.id = -1;
  798. this._isMainTrack = false;
  799. this._isInitialized = false;
  800. this._scene = scene;
  801. this.soundCollection = new Array();
  802. this._options = options;
  803. if (!this._isMainTrack) {
  804. this._scene.soundTracks.push(this);
  805. this.id = this._scene.soundTracks.length - 1;
  806. }
  807. }
  808. SoundTrack.prototype._initializeSoundTrackAudioGraph = function () {
  809. if (BABYLON.Engine.audioEngine.canUseWebAudio && BABYLON.Engine.audioEngine.audioContext) {
  810. this._outputAudioNode = BABYLON.Engine.audioEngine.audioContext.createGain();
  811. this._outputAudioNode.connect(BABYLON.Engine.audioEngine.masterGain);
  812. if (this._options) {
  813. if (this._options.volume) {
  814. this._outputAudioNode.gain.value = this._options.volume;
  815. }
  816. if (this._options.mainTrack) {
  817. this._isMainTrack = this._options.mainTrack;
  818. }
  819. }
  820. this._isInitialized = true;
  821. }
  822. };
  823. SoundTrack.prototype.dispose = function () {
  824. if (BABYLON.Engine.audioEngine.canUseWebAudio) {
  825. if (this._connectedAnalyser) {
  826. this._connectedAnalyser.stopDebugCanvas();
  827. }
  828. while (this.soundCollection.length) {
  829. this.soundCollection[0].dispose();
  830. }
  831. if (this._outputAudioNode) {
  832. this._outputAudioNode.disconnect();
  833. }
  834. this._outputAudioNode = null;
  835. }
  836. };
  837. SoundTrack.prototype.AddSound = function (sound) {
  838. if (!this._isInitialized) {
  839. this._initializeSoundTrackAudioGraph();
  840. }
  841. if (BABYLON.Engine.audioEngine.canUseWebAudio && this._outputAudioNode) {
  842. sound.connectToSoundTrackAudioNode(this._outputAudioNode);
  843. }
  844. if (sound.soundTrackId) {
  845. if (sound.soundTrackId === -1) {
  846. this._scene.mainSoundTrack.RemoveSound(sound);
  847. }
  848. else {
  849. this._scene.soundTracks[sound.soundTrackId].RemoveSound(sound);
  850. }
  851. }
  852. this.soundCollection.push(sound);
  853. sound.soundTrackId = this.id;
  854. };
  855. SoundTrack.prototype.RemoveSound = function (sound) {
  856. var index = this.soundCollection.indexOf(sound);
  857. if (index !== -1) {
  858. this.soundCollection.splice(index, 1);
  859. }
  860. };
  861. SoundTrack.prototype.setVolume = function (newVolume) {
  862. if (BABYLON.Engine.audioEngine.canUseWebAudio && this._outputAudioNode) {
  863. this._outputAudioNode.gain.value = newVolume;
  864. }
  865. };
  866. SoundTrack.prototype.switchPanningModelToHRTF = function () {
  867. if (BABYLON.Engine.audioEngine.canUseWebAudio) {
  868. for (var i = 0; i < this.soundCollection.length; i++) {
  869. this.soundCollection[i].switchPanningModelToHRTF();
  870. }
  871. }
  872. };
  873. SoundTrack.prototype.switchPanningModelToEqualPower = function () {
  874. if (BABYLON.Engine.audioEngine.canUseWebAudio) {
  875. for (var i = 0; i < this.soundCollection.length; i++) {
  876. this.soundCollection[i].switchPanningModelToEqualPower();
  877. }
  878. }
  879. };
  880. SoundTrack.prototype.connectToAnalyser = function (analyser) {
  881. if (this._connectedAnalyser) {
  882. this._connectedAnalyser.stopDebugCanvas();
  883. }
  884. this._connectedAnalyser = analyser;
  885. if (BABYLON.Engine.audioEngine.canUseWebAudio && this._outputAudioNode) {
  886. this._outputAudioNode.disconnect();
  887. this._connectedAnalyser.connectAudioNodes(this._outputAudioNode, BABYLON.Engine.audioEngine.masterGain);
  888. }
  889. };
  890. return SoundTrack;
  891. }());
  892. BABYLON.SoundTrack = SoundTrack;
  893. })(BABYLON || (BABYLON = {}));
  894. //# sourceMappingURL=babylon.soundtrack.js.map
  895. var BABYLON;
  896. (function (BABYLON) {
  897. var Analyser = /** @class */ (function () {
  898. function Analyser(scene) {
  899. this.SMOOTHING = 0.75;
  900. this.FFT_SIZE = 512;
  901. this.BARGRAPHAMPLITUDE = 256;
  902. this.DEBUGCANVASPOS = { x: 20, y: 20 };
  903. this.DEBUGCANVASSIZE = { width: 320, height: 200 };
  904. this._scene = scene;
  905. this._audioEngine = BABYLON.Engine.audioEngine;
  906. if (this._audioEngine.canUseWebAudio && this._audioEngine.audioContext) {
  907. this._webAudioAnalyser = this._audioEngine.audioContext.createAnalyser();
  908. this._webAudioAnalyser.minDecibels = -140;
  909. this._webAudioAnalyser.maxDecibels = 0;
  910. this._byteFreqs = new Uint8Array(this._webAudioAnalyser.frequencyBinCount);
  911. this._byteTime = new Uint8Array(this._webAudioAnalyser.frequencyBinCount);
  912. this._floatFreqs = new Float32Array(this._webAudioAnalyser.frequencyBinCount);
  913. }
  914. }
  915. Analyser.prototype.getFrequencyBinCount = function () {
  916. if (this._audioEngine.canUseWebAudio) {
  917. return this._webAudioAnalyser.frequencyBinCount;
  918. }
  919. else {
  920. return 0;
  921. }
  922. };
  923. Analyser.prototype.getByteFrequencyData = function () {
  924. if (this._audioEngine.canUseWebAudio) {
  925. this._webAudioAnalyser.smoothingTimeConstant = this.SMOOTHING;
  926. this._webAudioAnalyser.fftSize = this.FFT_SIZE;
  927. this._webAudioAnalyser.getByteFrequencyData(this._byteFreqs);
  928. }
  929. return this._byteFreqs;
  930. };
  931. Analyser.prototype.getByteTimeDomainData = function () {
  932. if (this._audioEngine.canUseWebAudio) {
  933. this._webAudioAnalyser.smoothingTimeConstant = this.SMOOTHING;
  934. this._webAudioAnalyser.fftSize = this.FFT_SIZE;
  935. this._webAudioAnalyser.getByteTimeDomainData(this._byteTime);
  936. }
  937. return this._byteTime;
  938. };
  939. Analyser.prototype.getFloatFrequencyData = function () {
  940. if (this._audioEngine.canUseWebAudio) {
  941. this._webAudioAnalyser.smoothingTimeConstant = this.SMOOTHING;
  942. this._webAudioAnalyser.fftSize = this.FFT_SIZE;
  943. this._webAudioAnalyser.getFloatFrequencyData(this._floatFreqs);
  944. }
  945. return this._floatFreqs;
  946. };
  947. Analyser.prototype.drawDebugCanvas = function () {
  948. var _this = this;
  949. if (this._audioEngine.canUseWebAudio) {
  950. if (!this._debugCanvas) {
  951. this._debugCanvas = document.createElement("canvas");
  952. this._debugCanvas.width = this.DEBUGCANVASSIZE.width;
  953. this._debugCanvas.height = this.DEBUGCANVASSIZE.height;
  954. this._debugCanvas.style.position = "absolute";
  955. this._debugCanvas.style.top = this.DEBUGCANVASPOS.y + "px";
  956. this._debugCanvas.style.left = this.DEBUGCANVASPOS.x + "px";
  957. this._debugCanvasContext = this._debugCanvas.getContext("2d");
  958. document.body.appendChild(this._debugCanvas);
  959. this._registerFunc = function () {
  960. _this.drawDebugCanvas();
  961. };
  962. this._scene.registerBeforeRender(this._registerFunc);
  963. }
  964. if (this._registerFunc && this._debugCanvasContext) {
  965. var workingArray = this.getByteFrequencyData();
  966. this._debugCanvasContext.fillStyle = 'rgb(0, 0, 0)';
  967. this._debugCanvasContext.fillRect(0, 0, this.DEBUGCANVASSIZE.width, this.DEBUGCANVASSIZE.height);
  968. // Draw the frequency domain chart.
  969. for (var i = 0; i < this.getFrequencyBinCount(); i++) {
  970. var value = workingArray[i];
  971. var percent = value / this.BARGRAPHAMPLITUDE;
  972. var height = this.DEBUGCANVASSIZE.height * percent;
  973. var offset = this.DEBUGCANVASSIZE.height - height - 1;
  974. var barWidth = this.DEBUGCANVASSIZE.width / this.getFrequencyBinCount();
  975. var hue = i / this.getFrequencyBinCount() * 360;
  976. this._debugCanvasContext.fillStyle = 'hsl(' + hue + ', 100%, 50%)';
  977. this._debugCanvasContext.fillRect(i * barWidth, offset, barWidth, height);
  978. }
  979. }
  980. }
  981. };
  982. Analyser.prototype.stopDebugCanvas = function () {
  983. if (this._debugCanvas) {
  984. if (this._registerFunc) {
  985. this._scene.unregisterBeforeRender(this._registerFunc);
  986. this._registerFunc = null;
  987. }
  988. document.body.removeChild(this._debugCanvas);
  989. this._debugCanvas = null;
  990. this._debugCanvasContext = null;
  991. }
  992. };
  993. Analyser.prototype.connectAudioNodes = function (inputAudioNode, outputAudioNode) {
  994. if (this._audioEngine.canUseWebAudio) {
  995. inputAudioNode.connect(this._webAudioAnalyser);
  996. this._webAudioAnalyser.connect(outputAudioNode);
  997. }
  998. };
  999. Analyser.prototype.dispose = function () {
  1000. if (this._audioEngine.canUseWebAudio) {
  1001. this._webAudioAnalyser.disconnect();
  1002. }
  1003. };
  1004. return Analyser;
  1005. }());
  1006. BABYLON.Analyser = Analyser;
  1007. })(BABYLON || (BABYLON = {}));
  1008. //# sourceMappingURL=babylon.analyser.js.map
  1009. BABYLON.Effect.IncludesShadersStore['depthPrePass'] = "#ifdef DEPTHPREPASS\ngl_FragColor=vec4(0.,0.,0.,1.0);\nreturn;\n#endif";
  1010. BABYLON.Effect.IncludesShadersStore['bonesDeclaration'] = "#if NUM_BONE_INFLUENCERS>0\nuniform mat4 mBones[BonesPerMesh];\nattribute vec4 matricesIndices;\nattribute vec4 matricesWeights;\n#if NUM_BONE_INFLUENCERS>4\nattribute vec4 matricesIndicesExtra;\nattribute vec4 matricesWeightsExtra;\n#endif\n#endif";
  1011. BABYLON.Effect.IncludesShadersStore['instancesDeclaration'] = "#ifdef INSTANCES\nattribute vec4 world0;\nattribute vec4 world1;\nattribute vec4 world2;\nattribute vec4 world3;\n#else\nuniform mat4 world;\n#endif";
  1012. BABYLON.Effect.IncludesShadersStore['pointCloudVertexDeclaration'] = "#ifdef POINTSIZE\nuniform float pointSize;\n#endif";
  1013. BABYLON.Effect.IncludesShadersStore['bumpVertexDeclaration'] = "#if defined(BUMP) || defined(PARALLAX)\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\n#endif\n#endif\n";
  1014. BABYLON.Effect.IncludesShadersStore['clipPlaneVertexDeclaration'] = "#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nvarying float fClipDistance;\n#endif";
  1015. BABYLON.Effect.IncludesShadersStore['fogVertexDeclaration'] = "#ifdef FOG\nvarying vec3 vFogDistance;\n#endif";
  1016. BABYLON.Effect.IncludesShadersStore['morphTargetsVertexGlobalDeclaration'] = "#ifdef MORPHTARGETS\nuniform float morphTargetInfluences[NUM_MORPH_INFLUENCERS];\n#endif";
  1017. BABYLON.Effect.IncludesShadersStore['morphTargetsVertexDeclaration'] = "#ifdef MORPHTARGETS\nattribute vec3 position{X};\n#ifdef MORPHTARGETS_NORMAL\nattribute vec3 normal{X};\n#endif\n#ifdef MORPHTARGETS_TANGENT\nattribute vec3 tangent{X};\n#endif\n#endif";
  1018. BABYLON.Effect.IncludesShadersStore['logDepthDeclaration'] = "#ifdef LOGARITHMICDEPTH\nuniform float logarithmicDepthConstant;\nvarying float vFragmentDepth;\n#endif";
  1019. BABYLON.Effect.IncludesShadersStore['morphTargetsVertex'] = "#ifdef MORPHTARGETS\npositionUpdated+=(position{X}-position)*morphTargetInfluences[{X}];\n#ifdef MORPHTARGETS_NORMAL\nnormalUpdated+=(normal{X}-normal)*morphTargetInfluences[{X}];\n#endif\n#ifdef MORPHTARGETS_TANGENT\ntangentUpdated.xyz+=(tangent{X}-tangent.xyz)*morphTargetInfluences[{X}];\n#endif\n#endif";
  1020. BABYLON.Effect.IncludesShadersStore['instancesVertex'] = "#ifdef INSTANCES\nmat4 finalWorld=mat4(world0,world1,world2,world3);\n#else\nmat4 finalWorld=world;\n#endif";
  1021. BABYLON.Effect.IncludesShadersStore['bonesVertex'] = "#if NUM_BONE_INFLUENCERS>0\nmat4 influence;\ninfluence=mBones[int(matricesIndices[0])]*matricesWeights[0];\n#if NUM_BONE_INFLUENCERS>1\ninfluence+=mBones[int(matricesIndices[1])]*matricesWeights[1];\n#endif \n#if NUM_BONE_INFLUENCERS>2\ninfluence+=mBones[int(matricesIndices[2])]*matricesWeights[2];\n#endif \n#if NUM_BONE_INFLUENCERS>3\ninfluence+=mBones[int(matricesIndices[3])]*matricesWeights[3];\n#endif \n#if NUM_BONE_INFLUENCERS>4\ninfluence+=mBones[int(matricesIndicesExtra[0])]*matricesWeightsExtra[0];\n#endif \n#if NUM_BONE_INFLUENCERS>5\ninfluence+=mBones[int(matricesIndicesExtra[1])]*matricesWeightsExtra[1];\n#endif \n#if NUM_BONE_INFLUENCERS>6\ninfluence+=mBones[int(matricesIndicesExtra[2])]*matricesWeightsExtra[2];\n#endif \n#if NUM_BONE_INFLUENCERS>7\ninfluence+=mBones[int(matricesIndicesExtra[3])]*matricesWeightsExtra[3];\n#endif \nfinalWorld=finalWorld*influence;\n#endif";
  1022. BABYLON.Effect.IncludesShadersStore['bumpVertex'] = "#if defined(BUMP) || defined(PARALLAX)\n#if defined(TANGENT) && defined(NORMAL)\nvec3 tbnNormal=normalize(normalUpdated);\nvec3 tbnTangent=normalize(tangentUpdated.xyz);\nvec3 tbnBitangent=cross(tbnNormal,tbnTangent)*tangentUpdated.w;\nvTBN=mat3(finalWorld)*mat3(tbnTangent,tbnBitangent,tbnNormal);\n#endif\n#endif";
  1023. BABYLON.Effect.IncludesShadersStore['clipPlaneVertex'] = "#ifdef CLIPPLANE\nfClipDistance=dot(worldPos,vClipPlane);\n#endif";
  1024. BABYLON.Effect.IncludesShadersStore['fogVertex'] = "#ifdef FOG\nvFogDistance=(view*worldPos).xyz;\n#endif";
  1025. BABYLON.Effect.IncludesShadersStore['shadowsVertex'] = "#ifdef SHADOWS\n#if defined(SHADOW{X}) && !defined(SHADOWCUBE{X})\nvPositionFromLight{X}=lightMatrix{X}*worldPos;\nvDepthMetric{X}=((vPositionFromLight{X}.z+light{X}.depthValues.x)/(light{X}.depthValues.y));\n#endif\n#endif";
  1026. BABYLON.Effect.IncludesShadersStore['pointCloudVertex'] = "#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif";
  1027. BABYLON.Effect.IncludesShadersStore['logDepthVertex'] = "#ifdef LOGARITHMICDEPTH\nvFragmentDepth=1.0+gl_Position.w;\ngl_Position.z=log2(max(0.000001,vFragmentDepth))*logarithmicDepthConstant;\n#endif";
  1028. BABYLON.Effect.IncludesShadersStore['helperFunctions'] = "const float PI=3.1415926535897932384626433832795;\nconst float LinearEncodePowerApprox=2.2;\nconst float GammaEncodePowerApprox=1.0/LinearEncodePowerApprox;\nconst vec3 LuminanceEncodeApprox=vec3(0.2126,0.7152,0.0722);\nmat3 transposeMat3(mat3 inMatrix) {\nvec3 i0=inMatrix[0];\nvec3 i1=inMatrix[1];\nvec3 i2=inMatrix[2];\nmat3 outMatrix=mat3(\nvec3(i0.x,i1.x,i2.x),\nvec3(i0.y,i1.y,i2.y),\nvec3(i0.z,i1.z,i2.z)\n);\nreturn outMatrix;\n}\n\nmat3 inverseMat3(mat3 inMatrix) {\nfloat a00=inMatrix[0][0],a01=inMatrix[0][1],a02=inMatrix[0][2];\nfloat a10=inMatrix[1][0],a11=inMatrix[1][1],a12=inMatrix[1][2];\nfloat a20=inMatrix[2][0],a21=inMatrix[2][1],a22=inMatrix[2][2];\nfloat b01=a22*a11-a12*a21;\nfloat b11=-a22*a10+a12*a20;\nfloat b21=a21*a10-a11*a20;\nfloat det=a00*b01+a01*b11+a02*b21;\nreturn mat3(b01,(-a22*a01+a02*a21),(a12*a01-a02*a11),\nb11,(a22*a00-a02*a20),(-a12*a00+a02*a10),\nb21,(-a21*a00+a01*a20),(a11*a00-a01*a10))/det;\n}\nfloat computeFallOff(float value,vec2 clipSpace,float frustumEdgeFalloff)\n{\nfloat mask=smoothstep(1.0-frustumEdgeFalloff,1.0,clamp(dot(clipSpace,clipSpace),0.,1.));\nreturn mix(value,1.0,mask);\n}\nvec3 applyEaseInOut(vec3 x){\nreturn x*x*(3.0-2.0*x);\n}\nvec3 toLinearSpace(vec3 color)\n{\nreturn pow(color,vec3(LinearEncodePowerApprox));\n}\nvec3 toGammaSpace(vec3 color)\n{\nreturn pow(color,vec3(GammaEncodePowerApprox));\n}\nfloat square(float value)\n{\nreturn value*value;\n}\nfloat getLuminance(vec3 color)\n{\nreturn clamp(dot(color,LuminanceEncodeApprox),0.,1.);\n}\n\nfloat getRand(vec2 seed) {\nreturn fract(sin(dot(seed.xy ,vec2(12.9898,78.233)))*43758.5453);\n}\nvec3 dither(vec2 seed,vec3 color) {\nfloat rand=getRand(seed);\ncolor+=mix(-0.5/255.0,0.5/255.0,rand);\ncolor=max(color,0.0);\nreturn color;\n}";
  1029. BABYLON.Effect.IncludesShadersStore['lightFragmentDeclaration'] = "#ifdef LIGHT{X}\nuniform vec4 vLightData{X};\nuniform vec4 vLightDiffuse{X};\n#ifdef SPECULARTERM\nuniform vec3 vLightSpecular{X};\n#else\nvec3 vLightSpecular{X}=vec3(0.);\n#endif\n#ifdef SHADOW{X}\n#if defined(SHADOWCUBE{X})\nuniform samplerCube shadowSampler{X};\n#else\nvarying vec4 vPositionFromLight{X};\nvarying float vDepthMetric{X};\nuniform sampler2D shadowSampler{X};\nuniform mat4 lightMatrix{X};\n#endif\nuniform vec4 shadowsInfo{X};\nuniform vec2 depthValues{X};\n#endif\n#ifdef SPOTLIGHT{X}\nuniform vec4 vLightDirection{X};\n#endif\n#ifdef HEMILIGHT{X}\nuniform vec3 vLightGround{X};\n#endif\n#endif";
  1030. BABYLON.Effect.IncludesShadersStore['lightsFragmentFunctions'] = "\nstruct lightingInfo\n{\nvec3 diffuse;\n#ifdef SPECULARTERM\nvec3 specular;\n#endif\n#ifdef NDOTL\nfloat ndl;\n#endif\n};\nlightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {\nlightingInfo result;\nvec3 lightVectorW;\nfloat attenuation=1.0;\nif (lightData.w == 0.)\n{\nvec3 direction=lightData.xyz-vPositionW;\nattenuation=max(0.,1.0-length(direction)/range);\nlightVectorW=normalize(direction);\n}\nelse\n{\nlightVectorW=normalize(-lightData.xyz);\n}\n\nfloat ndl=max(0.,dot(vNormal,lightVectorW));\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=ndl*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightVectorW);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor*attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {\nlightingInfo result;\nvec3 direction=lightData.xyz-vPositionW;\nvec3 lightVectorW=normalize(direction);\nfloat attenuation=max(0.,1.0-length(direction)/range);\n\nfloat cosAngle=max(0.,dot(lightDirection.xyz,-lightVectorW));\nif (cosAngle>=lightDirection.w)\n{\ncosAngle=max(0.,pow(cosAngle,lightData.w));\nattenuation*=cosAngle;\n\nfloat ndl=max(0.,dot(vNormal,lightVectorW));\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=ndl*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightVectorW);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor*attenuation;\n#endif\nreturn result;\n}\nresult.diffuse=vec3(0.);\n#ifdef SPECULARTERM\nresult.specular=vec3(0.);\n#endif\n#ifdef NDOTL\nresult.ndl=0.;\n#endif\nreturn result;\n}\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float glossiness) {\nlightingInfo result;\n\nfloat ndl=dot(vNormal,lightData.xyz)*0.5+0.5;\n#ifdef NDOTL\nresult.ndl=ndl;\n#endif\nresult.diffuse=mix(groundColor,diffuseColor,ndl);\n#ifdef SPECULARTERM\n\nvec3 angleW=normalize(viewDirectionW+lightData.xyz);\nfloat specComp=max(0.,dot(vNormal,angleW));\nspecComp=pow(specComp,max(1.,glossiness));\nresult.specular=specComp*specularColor;\n#endif\nreturn result;\n}\n";
  1031. BABYLON.Effect.IncludesShadersStore['lightUboDeclaration'] = "#ifdef LIGHT{X}\nuniform Light{X}\n{\nvec4 vLightData;\nvec4 vLightDiffuse;\nvec3 vLightSpecular;\n#ifdef SPOTLIGHT{X}\nvec4 vLightDirection;\n#endif\n#ifdef HEMILIGHT{X}\nvec3 vLightGround;\n#endif\nvec4 shadowsInfo;\nvec2 depthValues;\n} light{X};\n#ifdef SHADOW{X}\n#if defined(SHADOWCUBE{X})\nuniform samplerCube shadowSampler{X};\n#else\nvarying vec4 vPositionFromLight{X};\nvarying float vDepthMetric{X};\nuniform sampler2D shadowSampler{X};\nuniform mat4 lightMatrix{X};\n#endif\n#endif\n#endif";
  1032. BABYLON.Effect.IncludesShadersStore['defaultVertexDeclaration'] = "\nuniform mat4 viewProjection;\nuniform mat4 view;\n#ifdef DIFFUSE\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nuniform mat4 ambientMatrix;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\nuniform mat4 lightmapMatrix;\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nuniform vec2 vSpecularInfos;\nuniform mat4 specularMatrix;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n";
  1033. BABYLON.Effect.IncludesShadersStore['defaultFragmentDeclaration'] = "uniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\nuniform vec3 vEmissiveColor;\n\n#ifdef DIFFUSE\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef AMBIENT\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY \nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform vec2 vTangentSpaceParams;\n#endif\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION)\nuniform mat4 view;\n#endif\n#ifdef REFRACTION\nuniform vec4 vRefractionInfos;\n#ifndef REFRACTIONMAP_3D\nuniform mat4 refractionMatrix;\n#endif\n#ifdef REFRACTIONFRESNEL\nuniform vec4 refractionLeftColor;\nuniform vec4 refractionRightColor;\n#endif\n#endif\n#if defined(SPECULAR) && defined(SPECULARTERM)\nuniform vec2 vSpecularInfos;\n#endif\n#ifdef DIFFUSEFRESNEL\nuniform vec4 diffuseLeftColor;\nuniform vec4 diffuseRightColor;\n#endif\n#ifdef OPACITYFRESNEL\nuniform vec4 opacityParts;\n#endif\n#ifdef EMISSIVEFRESNEL\nuniform vec4 emissiveLeftColor;\nuniform vec4 emissiveRightColor;\n#endif\n\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\n#ifdef REFLECTIONMAP_SKYBOX\n#else\n#if defined(REFLECTIONMAP_PLANAR) || defined(REFLECTIONMAP_CUBIC) || defined(REFLECTIONMAP_PROJECTION)\nuniform mat4 reflectionMatrix;\n#endif\n#endif\n#ifdef REFLECTIONFRESNEL\nuniform vec4 reflectionLeftColor;\nuniform vec4 reflectionRightColor;\n#endif\n#endif";
  1034. BABYLON.Effect.IncludesShadersStore['defaultUboDeclaration'] = "layout(std140,column_major) uniform;\nuniform Material\n{\nvec4 diffuseLeftColor;\nvec4 diffuseRightColor;\nvec4 opacityParts;\nvec4 reflectionLeftColor;\nvec4 reflectionRightColor;\nvec4 refractionLeftColor;\nvec4 refractionRightColor;\nvec4 emissiveLeftColor; \nvec4 emissiveRightColor;\nvec2 vDiffuseInfos;\nvec2 vAmbientInfos;\nvec2 vOpacityInfos;\nvec2 vReflectionInfos;\nvec2 vEmissiveInfos;\nvec2 vLightmapInfos;\nvec2 vSpecularInfos;\nvec3 vBumpInfos;\nmat4 diffuseMatrix;\nmat4 ambientMatrix;\nmat4 opacityMatrix;\nmat4 reflectionMatrix;\nmat4 emissiveMatrix;\nmat4 lightmapMatrix;\nmat4 specularMatrix;\nmat4 bumpMatrix; \nvec4 vTangentSpaceParams;\nmat4 refractionMatrix;\nvec4 vRefractionInfos;\nvec4 vSpecularColor;\nvec3 vEmissiveColor;\nvec4 vDiffuseColor;\nfloat pointSize; \n};\nuniform Scene {\nmat4 viewProjection;\nmat4 view;\n};";
  1035. BABYLON.Effect.IncludesShadersStore['shadowsFragmentFunctions'] = "#ifdef SHADOWS\n#ifndef SHADOWFLOAT\nfloat unpack(vec4 color)\n{\nconst vec4 bit_shift=vec4(1.0/(255.0*255.0*255.0),1.0/(255.0*255.0),1.0/255.0,1.0);\nreturn dot(color,bit_shift);\n}\n#endif\nfloat computeShadowCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadow=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadow=textureCube(shadowSampler,directionToLight).x;\n#endif\nif (depth>shadow)\n{\nreturn darkness;\n}\nreturn 1.0;\n}\nfloat computeShadowWithPCFCube(vec3 lightPosition,samplerCube shadowSampler,float mapSize,float darkness,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\nfloat visibility=1.;\nvec3 poissonDisk[4];\npoissonDisk[0]=vec3(-1.0,1.0,-1.0);\npoissonDisk[1]=vec3(1.0,-1.0,-1.0);\npoissonDisk[2]=vec3(-1.0,-1.0,-1.0);\npoissonDisk[3]=vec3(1.0,-1.0,1.0);\n\n#ifndef SHADOWFLOAT\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize))<depth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[1]*mapSize))<depth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[2]*mapSize))<depth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[3]*mapSize))<depth) visibility-=0.25;\n#else\nif (textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize).x<depth) visibility-=0.25;\nif (textureCube(shadowSampler,directionToLight+poissonDisk[1]*mapSize).x<depth) visibility-=0.25;\nif (textureCube(shadowSampler,directionToLight+poissonDisk[2]*mapSize).x<depth) visibility-=0.25;\nif (textureCube(shadowSampler,directionToLight+poissonDisk[3]*mapSize).x<depth) visibility-=0.25;\n#endif\nreturn min(1.0,visibility+darkness);\n}\nfloat computeShadowWithESMCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float depthScale,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\nfloat shadowPixelDepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadowMapSample=textureCube(shadowSampler,directionToLight).x;\n#endif\nfloat esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness); \nreturn esm;\n}\nfloat computeShadowWithCloseESMCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float depthScale,vec2 depthValues)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth+depthValues.x)/(depthValues.y);\nfloat shadowPixelDepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(textureCube(shadowSampler,directionToLight));\n#else\nfloat shadowMapSample=textureCube(shadowSampler,directionToLight).x;\n#endif\nfloat esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);\nreturn esm;\n}\nfloat computeShadow(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\n#ifndef SHADOWFLOAT\nfloat shadow=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadow=texture2D(shadowSampler,uv).x;\n#endif\nif (shadowPixelDepth>shadow)\n{\nreturn computeFallOff(darkness,clipSpace.xy,frustumEdgeFalloff);\n}\nreturn 1.;\n}\nfloat computeShadowWithPCF(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float mapSize,float darkness,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\nfloat visibility=1.;\nvec2 poissonDisk[4];\npoissonDisk[0]=vec2(-0.94201624,-0.39906216);\npoissonDisk[1]=vec2(0.94558609,-0.76890725);\npoissonDisk[2]=vec2(-0.094184101,-0.92938870);\npoissonDisk[3]=vec2(0.34495938,0.29387760);\n\n#ifndef SHADOWFLOAT\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[0]*mapSize))<shadowPixelDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[1]*mapSize))<shadowPixelDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[2]*mapSize))<shadowPixelDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[3]*mapSize))<shadowPixelDepth) visibility-=0.25;\n#else\nif (texture2D(shadowSampler,uv+poissonDisk[0]*mapSize).x<shadowPixelDepth) visibility-=0.25;\nif (texture2D(shadowSampler,uv+poissonDisk[1]*mapSize).x<shadowPixelDepth) visibility-=0.25;\nif (texture2D(shadowSampler,uv+poissonDisk[2]*mapSize).x<shadowPixelDepth) visibility-=0.25;\nif (texture2D(shadowSampler,uv+poissonDisk[3]*mapSize).x<shadowPixelDepth) visibility-=0.25;\n#endif\nreturn computeFallOff(min(1.0,visibility+darkness),clipSpace.xy,frustumEdgeFalloff);\n}\nfloat computeShadowWithESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0);\n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadowMapSample=texture2D(shadowSampler,uv).x;\n#endif\nfloat esm=1.0-clamp(exp(min(87.,depthScale*shadowPixelDepth))*shadowMapSample,0.,1.-darkness);\nreturn computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);\n}\nfloat computeShadowWithCloseESM(vec4 vPositionFromLight,float depthMetric,sampler2D shadowSampler,float darkness,float depthScale,float frustumEdgeFalloff)\n{\nvec3 clipSpace=vPositionFromLight.xyz/vPositionFromLight.w;\nvec2 uv=0.5*clipSpace.xy+vec2(0.5);\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadowPixelDepth=clamp(depthMetric,0.,1.0); \n#ifndef SHADOWFLOAT\nfloat shadowMapSample=unpack(texture2D(shadowSampler,uv));\n#else\nfloat shadowMapSample=texture2D(shadowSampler,uv).x;\n#endif\nfloat esm=clamp(exp(min(87.,-depthScale*(shadowPixelDepth-shadowMapSample))),darkness,1.);\nreturn computeFallOff(esm,clipSpace.xy,frustumEdgeFalloff);\n}\n#endif\n";
  1036. BABYLON.Effect.IncludesShadersStore['fresnelFunction'] = "#ifdef FRESNEL\nfloat computeFresnelTerm(vec3 viewDirection,vec3 worldNormal,float bias,float power)\n{\nfloat fresnelTerm=pow(bias+abs(dot(viewDirection,worldNormal)),power);\nreturn clamp(fresnelTerm,0.,1.);\n}\n#endif";
  1037. BABYLON.Effect.IncludesShadersStore['reflectionFunction'] = "vec3 computeReflectionCoords(vec4 worldPos,vec3 worldNormal)\n{\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvec3 direction=normalize(vDirectionW);\nfloat t=clamp(direction.y*-0.5+0.5,0.,1.0);\nfloat s=atan(direction.z,direction.x)*RECIPROCAL_PI2+0.5;\n#ifdef REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED\nreturn vec3(1.0-s,t,0);\n#else\nreturn vec3(s,t,0);\n#endif\n#endif\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR\nvec3 cameraToVertex=normalize(worldPos.xyz-vEyePosition.xyz);\nvec3 r=reflect(cameraToVertex,worldNormal);\nfloat t=clamp(r.y*-0.5+0.5,0.,1.0);\nfloat s=atan(r.z,r.x)*RECIPROCAL_PI2+0.5;\nreturn vec3(s,t,0);\n#endif\n#ifdef REFLECTIONMAP_SPHERICAL\nvec3 viewDir=normalize(vec3(view*worldPos));\nvec3 viewNormal=normalize(vec3(view*vec4(worldNormal,0.0)));\nvec3 r=reflect(viewDir,viewNormal);\nr.z=r.z-1.0;\nfloat m=2.0*length(r);\nreturn vec3(r.x/m+0.5,1.0-r.y/m-0.5,0);\n#endif\n#ifdef REFLECTIONMAP_PLANAR\nvec3 viewDir=worldPos.xyz-vEyePosition.xyz;\nvec3 coords=normalize(reflect(viewDir,worldNormal));\nreturn vec3(reflectionMatrix*vec4(coords,1));\n#endif\n#ifdef REFLECTIONMAP_CUBIC\nvec3 viewDir=worldPos.xyz-vEyePosition.xyz;\nvec3 coords=reflect(viewDir,worldNormal);\n#ifdef INVERTCUBICMAP\ncoords.y=1.0-coords.y;\n#endif\nreturn vec3(reflectionMatrix*vec4(coords,0));\n#endif\n#ifdef REFLECTIONMAP_PROJECTION\nreturn vec3(reflectionMatrix*(view*worldPos));\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nreturn vPositionUVW;\n#endif\n#ifdef REFLECTIONMAP_EXPLICIT\nreturn vec3(0,0,0);\n#endif\n}";
  1038. BABYLON.Effect.IncludesShadersStore['imageProcessingDeclaration'] = "#ifdef EXPOSURE\nuniform float exposureLinear;\n#endif\n#ifdef CONTRAST\nuniform float contrast;\n#endif\n#ifdef VIGNETTE\nuniform vec2 vInverseScreenSize;\nuniform vec4 vignetteSettings1;\nuniform vec4 vignetteSettings2;\n#endif\n#ifdef COLORCURVES\nuniform vec4 vCameraColorCurveNegative;\nuniform vec4 vCameraColorCurveNeutral;\nuniform vec4 vCameraColorCurvePositive;\n#endif\n#ifdef COLORGRADING\n#ifdef COLORGRADING3D\nuniform highp sampler3D txColorTransform;\n#else\nuniform sampler2D txColorTransform;\n#endif\nuniform vec4 colorTransformSettings;\n#endif";
  1039. BABYLON.Effect.IncludesShadersStore['imageProcessingFunctions'] = "#if defined(COLORGRADING) && !defined(COLORGRADING3D)\n\nvec3 sampleTexture3D(sampler2D colorTransform,vec3 color,vec2 sampler3dSetting)\n{\nfloat sliceSize=2.0*sampler3dSetting.x; \n#ifdef SAMPLER3DGREENDEPTH\nfloat sliceContinuous=(color.g-sampler3dSetting.x)*sampler3dSetting.y;\n#else\nfloat sliceContinuous=(color.b-sampler3dSetting.x)*sampler3dSetting.y;\n#endif\nfloat sliceInteger=floor(sliceContinuous);\n\n\nfloat sliceFraction=sliceContinuous-sliceInteger;\n#ifdef SAMPLER3DGREENDEPTH\nvec2 sliceUV=color.rb;\n#else\nvec2 sliceUV=color.rg;\n#endif\nsliceUV.x*=sliceSize;\nsliceUV.x+=sliceInteger*sliceSize;\nsliceUV=clamp(sliceUV,0.,1.);\nvec4 slice0Color=texture2D(colorTransform,sliceUV);\nsliceUV.x+=sliceSize;\nsliceUV=clamp(sliceUV,0.,1.);\nvec4 slice1Color=texture2D(colorTransform,sliceUV);\nvec3 result=mix(slice0Color.rgb,slice1Color.rgb,sliceFraction);\n#ifdef SAMPLER3DBGRMAP\ncolor.rgb=result.rgb;\n#else\ncolor.rgb=result.bgr;\n#endif\nreturn color;\n}\n#endif\nvec4 applyImageProcessing(vec4 result) {\n#ifdef EXPOSURE\nresult.rgb*=exposureLinear;\n#endif\n#ifdef VIGNETTE\n\nvec2 viewportXY=gl_FragCoord.xy*vInverseScreenSize;\nviewportXY=viewportXY*2.0-1.0;\nvec3 vignetteXY1=vec3(viewportXY*vignetteSettings1.xy+vignetteSettings1.zw,1.0);\nfloat vignetteTerm=dot(vignetteXY1,vignetteXY1);\nfloat vignette=pow(vignetteTerm,vignetteSettings2.w);\n\nvec3 vignetteColor=vignetteSettings2.rgb;\n#ifdef VIGNETTEBLENDMODEMULTIPLY\nvec3 vignetteColorMultiplier=mix(vignetteColor,vec3(1,1,1),vignette);\nresult.rgb*=vignetteColorMultiplier;\n#endif\n#ifdef VIGNETTEBLENDMODEOPAQUE\nresult.rgb=mix(vignetteColor,result.rgb,vignette);\n#endif\n#endif\n#ifdef TONEMAPPING\nconst float tonemappingCalibration=1.590579;\nresult.rgb=1.0-exp2(-tonemappingCalibration*result.rgb);\n#endif\n\nresult.rgb=toGammaSpace(result.rgb);\nresult.rgb=clamp(result.rgb,0.0,1.0);\n#ifdef CONTRAST\n\nvec3 resultHighContrast=applyEaseInOut(result.rgb);\nif (contrast<1.0) {\n\nresult.rgb=mix(vec3(0.5,0.5,0.5),result.rgb,contrast);\n} else {\n\nresult.rgb=mix(result.rgb,resultHighContrast,contrast-1.0);\n}\n#endif\n\n#ifdef COLORGRADING\nvec3 colorTransformInput=result.rgb*colorTransformSettings.xxx+colorTransformSettings.yyy;\n#ifdef COLORGRADING3D\nvec3 colorTransformOutput=texture(txColorTransform,colorTransformInput).rgb;\n#else\nvec3 colorTransformOutput=sampleTexture3D(txColorTransform,colorTransformInput,colorTransformSettings.yz).rgb;\n#endif\nresult.rgb=mix(result.rgb,colorTransformOutput,colorTransformSettings.www);\n#endif\n#ifdef COLORCURVES\n\nfloat luma=getLuminance(result.rgb);\nvec2 curveMix=clamp(vec2(luma*3.0-1.5,luma*-3.0+1.5),vec2(0.0),vec2(1.0));\nvec4 colorCurve=vCameraColorCurveNeutral+curveMix.x*vCameraColorCurvePositive-curveMix.y*vCameraColorCurveNegative;\nresult.rgb*=colorCurve.rgb;\nresult.rgb=mix(vec3(luma),result.rgb,colorCurve.a);\n#endif\nreturn result;\n}";
  1040. BABYLON.Effect.IncludesShadersStore['bumpFragmentFunctions'] = "#ifdef BUMP\n#if BUMPDIRECTUV == 1\n#define vBumpUV vMainUV1\n#elif BUMPDIRECTUV == 2\n#define vBumpUV vMainUV2\n#else\nvarying vec2 vBumpUV;\n#endif\nuniform sampler2D bumpSampler;\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\n#endif\n\nmat3 cotangent_frame(vec3 normal,vec3 p,vec2 uv)\n{\n\nuv=gl_FrontFacing ? uv : -uv;\n\nvec3 dp1=dFdx(p);\nvec3 dp2=dFdy(p);\nvec2 duv1=dFdx(uv);\nvec2 duv2=dFdy(uv);\n\nvec3 dp2perp=cross(dp2,normal);\nvec3 dp1perp=cross(normal,dp1);\nvec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;\nvec3 bitangent=dp2perp*duv1.y+dp1perp*duv2.y;\n\ntangent*=vTangentSpaceParams.x;\nbitangent*=vTangentSpaceParams.y;\n\nfloat invmax=inversesqrt(max(dot(tangent,tangent),dot(bitangent,bitangent)));\nreturn mat3(tangent*invmax,bitangent*invmax,normal);\n}\nvec3 perturbNormal(mat3 cotangentFrame,vec2 uv)\n{\nvec3 map=texture2D(bumpSampler,uv).xyz;\nmap=map*2.0-1.0;\n#ifdef NORMALXYSCALE\nmap=normalize(map*vec3(vBumpInfos.y,vBumpInfos.y,1.0));\n#endif\nreturn normalize(cotangentFrame*map);\n}\n#ifdef PARALLAX\nconst float minSamples=4.;\nconst float maxSamples=15.;\nconst int iMaxSamples=15;\n\nvec2 parallaxOcclusion(vec3 vViewDirCoT,vec3 vNormalCoT,vec2 texCoord,float parallaxScale) {\nfloat parallaxLimit=length(vViewDirCoT.xy)/vViewDirCoT.z;\nparallaxLimit*=parallaxScale;\nvec2 vOffsetDir=normalize(vViewDirCoT.xy);\nvec2 vMaxOffset=vOffsetDir*parallaxLimit;\nfloat numSamples=maxSamples+(dot(vViewDirCoT,vNormalCoT)*(minSamples-maxSamples));\nfloat stepSize=1.0/numSamples;\n\nfloat currRayHeight=1.0;\nvec2 vCurrOffset=vec2(0,0);\nvec2 vLastOffset=vec2(0,0);\nfloat lastSampledHeight=1.0;\nfloat currSampledHeight=1.0;\nfor (int i=0; i<iMaxSamples; i++)\n{\ncurrSampledHeight=texture2D(bumpSampler,vBumpUV+vCurrOffset).w;\n\nif (currSampledHeight>currRayHeight)\n{\nfloat delta1=currSampledHeight-currRayHeight;\nfloat delta2=(currRayHeight+stepSize)-lastSampledHeight;\nfloat ratio=delta1/(delta1+delta2);\nvCurrOffset=(ratio)* vLastOffset+(1.0-ratio)*vCurrOffset;\n\nbreak;\n}\nelse\n{\ncurrRayHeight-=stepSize;\nvLastOffset=vCurrOffset;\nvCurrOffset+=stepSize*vMaxOffset;\nlastSampledHeight=currSampledHeight;\n}\n}\nreturn vCurrOffset;\n}\nvec2 parallaxOffset(vec3 viewDir,float heightScale)\n{\n\nfloat height=texture2D(bumpSampler,vBumpUV).w;\nvec2 texCoordOffset=heightScale*viewDir.xy*height;\nreturn -texCoordOffset;\n}\n#endif\n#endif";
  1041. BABYLON.Effect.IncludesShadersStore['clipPlaneFragmentDeclaration'] = "#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif";
  1042. BABYLON.Effect.IncludesShadersStore['fogFragmentDeclaration'] = "#ifdef FOG\n#define FOGMODE_NONE 0.\n#define FOGMODE_EXP 1.\n#define FOGMODE_EXP2 2.\n#define FOGMODE_LINEAR 3.\n#define E 2.71828\nuniform vec4 vFogInfos;\nuniform vec3 vFogColor;\nvarying vec3 vFogDistance;\nfloat CalcFogFactor()\n{\nfloat fogCoeff=1.0;\nfloat fogStart=vFogInfos.y;\nfloat fogEnd=vFogInfos.z;\nfloat fogDensity=vFogInfos.w;\nfloat fogDistance=length(vFogDistance);\nif (FOGMODE_LINEAR == vFogInfos.x)\n{\nfogCoeff=(fogEnd-fogDistance)/(fogEnd-fogStart);\n}\nelse if (FOGMODE_EXP == vFogInfos.x)\n{\nfogCoeff=1.0/pow(E,fogDistance*fogDensity);\n}\nelse if (FOGMODE_EXP2 == vFogInfos.x)\n{\nfogCoeff=1.0/pow(E,fogDistance*fogDistance*fogDensity*fogDensity);\n}\nreturn clamp(fogCoeff,0.0,1.0);\n}\n#endif";
  1043. BABYLON.Effect.IncludesShadersStore['clipPlaneFragment'] = "#ifdef CLIPPLANE\nif (fClipDistance>0.0)\n{\ndiscard;\n}\n#endif";
  1044. BABYLON.Effect.IncludesShadersStore['bumpFragment'] = "vec2 uvOffset=vec2(0.0,0.0);\n#if defined(BUMP) || defined(PARALLAX)\n#ifdef NORMALXYSCALE\nfloat normalScale=1.0;\n#else \nfloat normalScale=vBumpInfos.y;\n#endif\n#if defined(TANGENT) && defined(NORMAL)\nmat3 TBN=vTBN;\n#else\nmat3 TBN=cotangent_frame(normalW*normalScale,vPositionW,vBumpUV);\n#endif\n#endif\n#ifdef PARALLAX\nmat3 invTBN=transposeMat3(TBN);\n#ifdef PARALLAXOCCLUSION\nuvOffset=parallaxOcclusion(invTBN*-viewDirectionW,invTBN*normalW,vBumpUV,vBumpInfos.z);\n#else\nuvOffset=parallaxOffset(invTBN*viewDirectionW,vBumpInfos.z);\n#endif\n#endif\n#ifdef BUMP\nnormalW=perturbNormal(TBN,vBumpUV+uvOffset);\n#endif";
  1045. BABYLON.Effect.IncludesShadersStore['lightFragment'] = "#ifdef LIGHT{X}\n#if defined(SHADOWONLY) || (defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X}) && defined(LIGHTMAPNOSPECULAR{X}))\n\n#else\n#ifdef PBR\n#ifdef SPOTLIGHT{X}\ninfo=computeSpotLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDirection,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,NdotL);\n#endif\n#ifdef HEMILIGHT{X}\ninfo=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightGround,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,NdotL);\n#endif\n#if defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\ninfo=computeLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR0,specularEnvironmentR90,NdotL);\n#endif\n#else\n#ifdef SPOTLIGHT{X}\ninfo=computeSpotLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDirection,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,glossiness);\n#endif\n#ifdef HEMILIGHT{X}\ninfo=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightGround,glossiness);\n#endif\n#if defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\ninfo=computeLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,glossiness);\n#endif\n#endif\n#endif\n#ifdef SHADOW{X}\n#ifdef SHADOWCLOSEESM{X}\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithCloseESMCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);\n#else\nshadow=computeShadowWithCloseESM(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.shadowsInfo.w);\n#endif\n#else\n#ifdef SHADOWESM{X}\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithESMCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);\n#else\nshadow=computeShadowWithESM(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.shadowsInfo.w);\n#endif\n#else \n#ifdef SHADOWPCF{X}\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowWithPCFCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nshadow=computeShadowWithPCF(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#else\n#if defined(SHADOWCUBE{X})\nshadow=computeShadowCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nshadow=computeShadow(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.w);\n#endif\n#endif\n#endif\n#endif\n#ifdef SHADOWONLY\n#ifndef SHADOWINUSE\n#define SHADOWINUSE\n#endif\nglobalShadow+=shadow;\nshadowLightCount+=1.0;\n#endif\n#else\nshadow=1.;\n#endif\n#ifndef SHADOWONLY\n#ifdef CUSTOMUSERLIGHTING\ndiffuseBase+=computeCustomDiffuseLighting(info,diffuseBase,shadow);\n#ifdef SPECULARTERM\nspecularBase+=computeCustomSpecularLighting(info,specularBase,shadow);\n#endif\n#elif defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X})\ndiffuseBase+=lightmapColor*shadow;\n#ifdef SPECULARTERM\n#ifndef LIGHTMAPNOSPECULAR{X}\nspecularBase+=info.specular*shadow*lightmapColor;\n#endif\n#endif\n#else\ndiffuseBase+=info.diffuse*shadow;\n#ifdef SPECULARTERM\nspecularBase+=info.specular*shadow;\n#endif\n#endif\n#endif\n#endif";
  1046. BABYLON.Effect.IncludesShadersStore['logDepthFragment'] = "#ifdef LOGARITHMICDEPTH\ngl_FragDepthEXT=log2(vFragmentDepth)*logarithmicDepthConstant*0.5;\n#endif";
  1047. BABYLON.Effect.IncludesShadersStore['fogFragment'] = "#ifdef FOG\nfloat fog=CalcFogFactor();\ncolor.rgb=fog*color.rgb+(1.0-fog)*vFogColor;\n#endif";
  1048. var AudioEngine = BABYLON.AudioEngine;
  1049. var Sound = BABYLON.Sound;
  1050. var SoundTrack = BABYLON.SoundTrack;
  1051. var Analyser = BABYLON.Analyser;
  1052. export { AudioEngine,Sound,SoundTrack,Analyser };