es6.js 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = Object.setPrototypeOf ||
  3. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5. return function (d, b) {
  6. extendStatics(d, b);
  7. function __() { this.constructor = d; }
  8. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9. };
  10. })();
  11. import * as shaderMaterial from 'babylonjs/shaderMaterial/es6';
  12. var BABYLON;
  13. (function (BABYLON) {
  14. var OutlineRenderer = /** @class */ (function () {
  15. function OutlineRenderer(scene) {
  16. this.zOffset = 1;
  17. this._scene = scene;
  18. }
  19. OutlineRenderer.prototype.render = function (subMesh, batch, useOverlay) {
  20. var _this = this;
  21. if (useOverlay === void 0) { useOverlay = false; }
  22. var scene = this._scene;
  23. var engine = this._scene.getEngine();
  24. var hardwareInstancedRendering = (engine.getCaps().instancedArrays) && (batch.visibleInstances[subMesh._id] !== null) && (batch.visibleInstances[subMesh._id] !== undefined);
  25. if (!this.isReady(subMesh, hardwareInstancedRendering)) {
  26. return;
  27. }
  28. var mesh = subMesh.getRenderingMesh();
  29. var material = subMesh.getMaterial();
  30. if (!material || !scene.activeCamera) {
  31. return;
  32. }
  33. engine.enableEffect(this._effect);
  34. // Logarithmic depth
  35. if (material.useLogarithmicDepth) {
  36. this._effect.setFloat("logarithmicDepthConstant", 2.0 / (Math.log(scene.activeCamera.maxZ + 1.0) / Math.LN2));
  37. }
  38. this._effect.setFloat("offset", useOverlay ? 0 : mesh.outlineWidth);
  39. this._effect.setColor4("color", useOverlay ? mesh.overlayColor : mesh.outlineColor, useOverlay ? mesh.overlayAlpha : material.alpha);
  40. this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
  41. // Bones
  42. if (mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {
  43. this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
  44. }
  45. mesh._bind(subMesh, this._effect, BABYLON.Material.TriangleFillMode);
  46. // Alpha test
  47. if (material && material.needAlphaTesting()) {
  48. var alphaTexture = material.getAlphaTestTexture();
  49. if (alphaTexture) {
  50. this._effect.setTexture("diffuseSampler", alphaTexture);
  51. this._effect.setMatrix("diffuseMatrix", alphaTexture.getTextureMatrix());
  52. }
  53. }
  54. engine.setZOffset(-this.zOffset);
  55. mesh._processRendering(subMesh, this._effect, BABYLON.Material.TriangleFillMode, batch, hardwareInstancedRendering, function (isInstance, world) { _this._effect.setMatrix("world", world); });
  56. engine.setZOffset(0);
  57. };
  58. OutlineRenderer.prototype.isReady = function (subMesh, useInstances) {
  59. var defines = [];
  60. var attribs = [BABYLON.VertexBuffer.PositionKind, BABYLON.VertexBuffer.NormalKind];
  61. var mesh = subMesh.getMesh();
  62. var material = subMesh.getMaterial();
  63. if (material) {
  64. // Alpha test
  65. if (material.needAlphaTesting()) {
  66. defines.push("#define ALPHATEST");
  67. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
  68. attribs.push(BABYLON.VertexBuffer.UVKind);
  69. defines.push("#define UV1");
  70. }
  71. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind)) {
  72. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  73. defines.push("#define UV2");
  74. }
  75. }
  76. //Logarithmic depth
  77. if (material.useLogarithmicDepth) {
  78. defines.push("#define LOGARITHMICDEPTH");
  79. }
  80. }
  81. // Bones
  82. if (mesh.useBones && mesh.computeBonesUsingShaders) {
  83. attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
  84. attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
  85. if (mesh.numBoneInfluencers > 4) {
  86. attribs.push(BABYLON.VertexBuffer.MatricesIndicesExtraKind);
  87. attribs.push(BABYLON.VertexBuffer.MatricesWeightsExtraKind);
  88. }
  89. defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
  90. defines.push("#define BonesPerMesh " + (mesh.skeleton ? mesh.skeleton.bones.length + 1 : 0));
  91. }
  92. else {
  93. defines.push("#define NUM_BONE_INFLUENCERS 0");
  94. }
  95. // Instances
  96. if (useInstances) {
  97. defines.push("#define INSTANCES");
  98. attribs.push("world0");
  99. attribs.push("world1");
  100. attribs.push("world2");
  101. attribs.push("world3");
  102. }
  103. // Get correct effect
  104. var join = defines.join("\n");
  105. if (this._cachedDefines !== join) {
  106. this._cachedDefines = join;
  107. this._effect = this._scene.getEngine().createEffect("outline", attribs, ["world", "mBones", "viewProjection", "diffuseMatrix", "offset", "color", "logarithmicDepthConstant"], ["diffuseSampler"], join);
  108. }
  109. return this._effect.isReady();
  110. };
  111. return OutlineRenderer;
  112. }());
  113. BABYLON.OutlineRenderer = OutlineRenderer;
  114. })(BABYLON || (BABYLON = {}));
  115. //# sourceMappingURL=babylon.outlineRenderer.js.map
  116. var BABYLON;
  117. (function (BABYLON) {
  118. var FaceAdjacencies = /** @class */ (function () {
  119. function FaceAdjacencies() {
  120. this.edges = new Array();
  121. this.edgesConnectedCount = 0;
  122. }
  123. return FaceAdjacencies;
  124. }());
  125. var EdgesRenderer = /** @class */ (function () {
  126. // Beware when you use this class with complex objects as the adjacencies computation can be really long
  127. function EdgesRenderer(source, epsilon, checkVerticesInsteadOfIndices) {
  128. if (epsilon === void 0) { epsilon = 0.95; }
  129. if (checkVerticesInsteadOfIndices === void 0) { checkVerticesInsteadOfIndices = false; }
  130. this.edgesWidthScalerForOrthographic = 1000.0;
  131. this.edgesWidthScalerForPerspective = 50.0;
  132. this._linesPositions = new Array();
  133. this._linesNormals = new Array();
  134. this._linesIndices = new Array();
  135. this._buffers = {};
  136. this._checkVerticesInsteadOfIndices = false;
  137. this._source = source;
  138. this._checkVerticesInsteadOfIndices = checkVerticesInsteadOfIndices;
  139. this._epsilon = epsilon;
  140. this._prepareRessources();
  141. this._generateEdgesLines();
  142. }
  143. EdgesRenderer.prototype._prepareRessources = function () {
  144. if (this._lineShader) {
  145. return;
  146. }
  147. this._lineShader = new BABYLON.ShaderMaterial("lineShader", this._source.getScene(), "line", {
  148. attributes: ["position", "normal"],
  149. uniforms: ["worldViewProjection", "color", "width", "aspectRatio"]
  150. });
  151. this._lineShader.disableDepthWrite = true;
  152. this._lineShader.backFaceCulling = false;
  153. };
  154. EdgesRenderer.prototype._rebuild = function () {
  155. var buffer = this._buffers[BABYLON.VertexBuffer.PositionKind];
  156. if (buffer) {
  157. buffer._rebuild();
  158. }
  159. buffer = this._buffers[BABYLON.VertexBuffer.NormalKind];
  160. if (buffer) {
  161. buffer._rebuild();
  162. }
  163. var scene = this._source.getScene();
  164. var engine = scene.getEngine();
  165. this._ib = engine.createIndexBuffer(this._linesIndices);
  166. };
  167. EdgesRenderer.prototype.dispose = function () {
  168. var buffer = this._buffers[BABYLON.VertexBuffer.PositionKind];
  169. if (buffer) {
  170. buffer.dispose();
  171. this._buffers[BABYLON.VertexBuffer.PositionKind] = null;
  172. }
  173. buffer = this._buffers[BABYLON.VertexBuffer.NormalKind];
  174. if (buffer) {
  175. buffer.dispose();
  176. this._buffers[BABYLON.VertexBuffer.NormalKind] = null;
  177. }
  178. this._source.getScene().getEngine()._releaseBuffer(this._ib);
  179. this._lineShader.dispose();
  180. };
  181. EdgesRenderer.prototype._processEdgeForAdjacencies = function (pa, pb, p0, p1, p2) {
  182. if (pa === p0 && pb === p1 || pa === p1 && pb === p0) {
  183. return 0;
  184. }
  185. if (pa === p1 && pb === p2 || pa === p2 && pb === p1) {
  186. return 1;
  187. }
  188. if (pa === p2 && pb === p0 || pa === p0 && pb === p2) {
  189. return 2;
  190. }
  191. return -1;
  192. };
  193. EdgesRenderer.prototype._processEdgeForAdjacenciesWithVertices = function (pa, pb, p0, p1, p2) {
  194. if (pa.equalsWithEpsilon(p0) && pb.equalsWithEpsilon(p1) || pa.equalsWithEpsilon(p1) && pb.equalsWithEpsilon(p0)) {
  195. return 0;
  196. }
  197. if (pa.equalsWithEpsilon(p1) && pb.equalsWithEpsilon(p2) || pa.equalsWithEpsilon(p2) && pb.equalsWithEpsilon(p1)) {
  198. return 1;
  199. }
  200. if (pa.equalsWithEpsilon(p2) && pb.equalsWithEpsilon(p0) || pa.equalsWithEpsilon(p0) && pb.equalsWithEpsilon(p2)) {
  201. return 2;
  202. }
  203. return -1;
  204. };
  205. EdgesRenderer.prototype._checkEdge = function (faceIndex, edge, faceNormals, p0, p1) {
  206. var needToCreateLine;
  207. if (edge === undefined) {
  208. needToCreateLine = true;
  209. }
  210. else {
  211. var dotProduct = BABYLON.Vector3.Dot(faceNormals[faceIndex], faceNormals[edge]);
  212. needToCreateLine = dotProduct < this._epsilon;
  213. }
  214. if (needToCreateLine) {
  215. var offset = this._linesPositions.length / 3;
  216. var normal = p0.subtract(p1);
  217. normal.normalize();
  218. // Positions
  219. this._linesPositions.push(p0.x);
  220. this._linesPositions.push(p0.y);
  221. this._linesPositions.push(p0.z);
  222. this._linesPositions.push(p0.x);
  223. this._linesPositions.push(p0.y);
  224. this._linesPositions.push(p0.z);
  225. this._linesPositions.push(p1.x);
  226. this._linesPositions.push(p1.y);
  227. this._linesPositions.push(p1.z);
  228. this._linesPositions.push(p1.x);
  229. this._linesPositions.push(p1.y);
  230. this._linesPositions.push(p1.z);
  231. // Normals
  232. this._linesNormals.push(p1.x);
  233. this._linesNormals.push(p1.y);
  234. this._linesNormals.push(p1.z);
  235. this._linesNormals.push(-1);
  236. this._linesNormals.push(p1.x);
  237. this._linesNormals.push(p1.y);
  238. this._linesNormals.push(p1.z);
  239. this._linesNormals.push(1);
  240. this._linesNormals.push(p0.x);
  241. this._linesNormals.push(p0.y);
  242. this._linesNormals.push(p0.z);
  243. this._linesNormals.push(-1);
  244. this._linesNormals.push(p0.x);
  245. this._linesNormals.push(p0.y);
  246. this._linesNormals.push(p0.z);
  247. this._linesNormals.push(1);
  248. // Indices
  249. this._linesIndices.push(offset);
  250. this._linesIndices.push(offset + 1);
  251. this._linesIndices.push(offset + 2);
  252. this._linesIndices.push(offset);
  253. this._linesIndices.push(offset + 2);
  254. this._linesIndices.push(offset + 3);
  255. }
  256. };
  257. EdgesRenderer.prototype._generateEdgesLines = function () {
  258. var positions = this._source.getVerticesData(BABYLON.VertexBuffer.PositionKind);
  259. var indices = this._source.getIndices();
  260. if (!indices || !positions) {
  261. return;
  262. }
  263. // First let's find adjacencies
  264. var adjacencies = new Array();
  265. var faceNormals = new Array();
  266. var index;
  267. var faceAdjacencies;
  268. // Prepare faces
  269. for (index = 0; index < indices.length; index += 3) {
  270. faceAdjacencies = new FaceAdjacencies();
  271. var p0Index = indices[index];
  272. var p1Index = indices[index + 1];
  273. var p2Index = indices[index + 2];
  274. faceAdjacencies.p0 = new BABYLON.Vector3(positions[p0Index * 3], positions[p0Index * 3 + 1], positions[p0Index * 3 + 2]);
  275. faceAdjacencies.p1 = new BABYLON.Vector3(positions[p1Index * 3], positions[p1Index * 3 + 1], positions[p1Index * 3 + 2]);
  276. faceAdjacencies.p2 = new BABYLON.Vector3(positions[p2Index * 3], positions[p2Index * 3 + 1], positions[p2Index * 3 + 2]);
  277. var faceNormal = BABYLON.Vector3.Cross(faceAdjacencies.p1.subtract(faceAdjacencies.p0), faceAdjacencies.p2.subtract(faceAdjacencies.p1));
  278. faceNormal.normalize();
  279. faceNormals.push(faceNormal);
  280. adjacencies.push(faceAdjacencies);
  281. }
  282. // Scan
  283. for (index = 0; index < adjacencies.length; index++) {
  284. faceAdjacencies = adjacencies[index];
  285. for (var otherIndex = index + 1; otherIndex < adjacencies.length; otherIndex++) {
  286. var otherFaceAdjacencies = adjacencies[otherIndex];
  287. if (faceAdjacencies.edgesConnectedCount === 3) {
  288. break;
  289. }
  290. if (otherFaceAdjacencies.edgesConnectedCount === 3) {
  291. continue;
  292. }
  293. var otherP0 = indices[otherIndex * 3];
  294. var otherP1 = indices[otherIndex * 3 + 1];
  295. var otherP2 = indices[otherIndex * 3 + 2];
  296. for (var edgeIndex = 0; edgeIndex < 3; edgeIndex++) {
  297. var otherEdgeIndex = 0;
  298. if (faceAdjacencies.edges[edgeIndex] !== undefined) {
  299. continue;
  300. }
  301. switch (edgeIndex) {
  302. case 0:
  303. if (this._checkVerticesInsteadOfIndices) {
  304. otherEdgeIndex = this._processEdgeForAdjacenciesWithVertices(faceAdjacencies.p0, faceAdjacencies.p1, otherFaceAdjacencies.p0, otherFaceAdjacencies.p1, otherFaceAdjacencies.p2);
  305. }
  306. else {
  307. otherEdgeIndex = this._processEdgeForAdjacencies(indices[index * 3], indices[index * 3 + 1], otherP0, otherP1, otherP2);
  308. }
  309. break;
  310. case 1:
  311. if (this._checkVerticesInsteadOfIndices) {
  312. otherEdgeIndex = this._processEdgeForAdjacenciesWithVertices(faceAdjacencies.p1, faceAdjacencies.p2, otherFaceAdjacencies.p0, otherFaceAdjacencies.p1, otherFaceAdjacencies.p2);
  313. }
  314. else {
  315. otherEdgeIndex = this._processEdgeForAdjacencies(indices[index * 3 + 1], indices[index * 3 + 2], otherP0, otherP1, otherP2);
  316. }
  317. break;
  318. case 2:
  319. if (this._checkVerticesInsteadOfIndices) {
  320. otherEdgeIndex = this._processEdgeForAdjacenciesWithVertices(faceAdjacencies.p2, faceAdjacencies.p0, otherFaceAdjacencies.p0, otherFaceAdjacencies.p1, otherFaceAdjacencies.p2);
  321. }
  322. else {
  323. otherEdgeIndex = this._processEdgeForAdjacencies(indices[index * 3 + 2], indices[index * 3], otherP0, otherP1, otherP2);
  324. }
  325. break;
  326. }
  327. if (otherEdgeIndex === -1) {
  328. continue;
  329. }
  330. faceAdjacencies.edges[edgeIndex] = otherIndex;
  331. otherFaceAdjacencies.edges[otherEdgeIndex] = index;
  332. faceAdjacencies.edgesConnectedCount++;
  333. otherFaceAdjacencies.edgesConnectedCount++;
  334. if (faceAdjacencies.edgesConnectedCount === 3) {
  335. break;
  336. }
  337. }
  338. }
  339. }
  340. // Create lines
  341. for (index = 0; index < adjacencies.length; index++) {
  342. // We need a line when a face has no adjacency on a specific edge or if all the adjacencies has an angle greater than epsilon
  343. var current = adjacencies[index];
  344. this._checkEdge(index, current.edges[0], faceNormals, current.p0, current.p1);
  345. this._checkEdge(index, current.edges[1], faceNormals, current.p1, current.p2);
  346. this._checkEdge(index, current.edges[2], faceNormals, current.p2, current.p0);
  347. }
  348. // Merge into a single mesh
  349. var engine = this._source.getScene().getEngine();
  350. this._buffers[BABYLON.VertexBuffer.PositionKind] = new BABYLON.VertexBuffer(engine, this._linesPositions, BABYLON.VertexBuffer.PositionKind, false);
  351. this._buffers[BABYLON.VertexBuffer.NormalKind] = new BABYLON.VertexBuffer(engine, this._linesNormals, BABYLON.VertexBuffer.NormalKind, false, false, 4);
  352. this._ib = engine.createIndexBuffer(this._linesIndices);
  353. this._indicesCount = this._linesIndices.length;
  354. };
  355. EdgesRenderer.prototype.render = function () {
  356. var scene = this._source.getScene();
  357. if (!this._lineShader.isReady() || !scene.activeCamera) {
  358. return;
  359. }
  360. var engine = scene.getEngine();
  361. this._lineShader._preBind();
  362. // VBOs
  363. engine.bindBuffers(this._buffers, this._ib, this._lineShader.getEffect());
  364. scene.resetCachedMaterial();
  365. this._lineShader.setColor4("color", this._source.edgesColor);
  366. if (scene.activeCamera.mode === BABYLON.Camera.ORTHOGRAPHIC_CAMERA) {
  367. this._lineShader.setFloat("width", this._source.edgesWidth / this.edgesWidthScalerForOrthographic);
  368. }
  369. else {
  370. this._lineShader.setFloat("width", this._source.edgesWidth / this.edgesWidthScalerForPerspective);
  371. }
  372. this._lineShader.setFloat("aspectRatio", engine.getAspectRatio(scene.activeCamera));
  373. this._lineShader.bind(this._source.getWorldMatrix());
  374. // Draw order
  375. engine.drawElementsType(BABYLON.Material.TriangleFillMode, 0, this._indicesCount);
  376. this._lineShader.unbind();
  377. engine.setDepthWrite(true);
  378. };
  379. return EdgesRenderer;
  380. }());
  381. BABYLON.EdgesRenderer = EdgesRenderer;
  382. })(BABYLON || (BABYLON = {}));
  383. //# sourceMappingURL=babylon.edgesRenderer.js.map
  384. var BABYLON;
  385. (function (BABYLON) {
  386. /**
  387. * Special Glow Blur post process only blurring the alpha channel
  388. * It enforces keeping the most luminous color in the color channel.
  389. */
  390. var GlowBlurPostProcess = /** @class */ (function (_super) {
  391. __extends(GlowBlurPostProcess, _super);
  392. function GlowBlurPostProcess(name, direction, kernel, options, camera, samplingMode, engine, reusable) {
  393. if (samplingMode === void 0) { samplingMode = BABYLON.Texture.BILINEAR_SAMPLINGMODE; }
  394. var _this = _super.call(this, name, "glowBlurPostProcess", ["screenSize", "direction", "blurWidth"], null, options, camera, samplingMode, engine, reusable) || this;
  395. _this.direction = direction;
  396. _this.kernel = kernel;
  397. _this.onApplyObservable.add(function (effect) {
  398. effect.setFloat2("screenSize", _this.width, _this.height);
  399. effect.setVector2("direction", _this.direction);
  400. effect.setFloat("blurWidth", _this.kernel);
  401. });
  402. return _this;
  403. }
  404. return GlowBlurPostProcess;
  405. }(BABYLON.PostProcess));
  406. /**
  407. * The highlight layer Helps adding a glow effect around a mesh.
  408. *
  409. * Once instantiated in a scene, simply use the pushMesh or removeMesh method to add or remove
  410. * glowy meshes to your scene.
  411. *
  412. * !!! THIS REQUIRES AN ACTIVE STENCIL BUFFER ON THE CANVAS !!!
  413. */
  414. var HighlightLayer = /** @class */ (function () {
  415. /**
  416. * Instantiates a new highlight Layer and references it to the scene..
  417. * @param name The name of the layer
  418. * @param scene The scene to use the layer in
  419. * @param options Sets of none mandatory options to use with the layer (see IHighlightLayerOptions for more information)
  420. */
  421. function HighlightLayer(name, scene, options) {
  422. this.name = name;
  423. this._vertexBuffers = {};
  424. this._mainTextureDesiredSize = { width: 0, height: 0 };
  425. this._meshes = {};
  426. this._maxSize = 0;
  427. this._shouldRender = false;
  428. this._instanceGlowingMeshStencilReference = HighlightLayer.glowingMeshStencilReference++;
  429. this._excludedMeshes = {};
  430. /**
  431. * Specifies whether or not the inner glow is ACTIVE in the layer.
  432. */
  433. this.innerGlow = true;
  434. /**
  435. * Specifies whether or not the outer glow is ACTIVE in the layer.
  436. */
  437. this.outerGlow = true;
  438. /**
  439. * Specifies wether the highlight layer is enabled or not.
  440. */
  441. this.isEnabled = true;
  442. /**
  443. * An event triggered when the highlight layer has been disposed.
  444. * @type {BABYLON.Observable}
  445. */
  446. this.onDisposeObservable = new BABYLON.Observable();
  447. /**
  448. * An event triggered when the highlight layer is about rendering the main texture with the glowy parts.
  449. * @type {BABYLON.Observable}
  450. */
  451. this.onBeforeRenderMainTextureObservable = new BABYLON.Observable();
  452. /**
  453. * An event triggered when the highlight layer is being blurred.
  454. * @type {BABYLON.Observable}
  455. */
  456. this.onBeforeBlurObservable = new BABYLON.Observable();
  457. /**
  458. * An event triggered when the highlight layer has been blurred.
  459. * @type {BABYLON.Observable}
  460. */
  461. this.onAfterBlurObservable = new BABYLON.Observable();
  462. /**
  463. * An event triggered when the glowing blurred texture is being merged in the scene.
  464. * @type {BABYLON.Observable}
  465. */
  466. this.onBeforeComposeObservable = new BABYLON.Observable();
  467. /**
  468. * An event triggered when the glowing blurred texture has been merged in the scene.
  469. * @type {BABYLON.Observable}
  470. */
  471. this.onAfterComposeObservable = new BABYLON.Observable();
  472. /**
  473. * An event triggered when the highlight layer changes its size.
  474. * @type {BABYLON.Observable}
  475. */
  476. this.onSizeChangedObservable = new BABYLON.Observable();
  477. this._scene = scene || BABYLON.Engine.LastCreatedScene;
  478. var engine = scene.getEngine();
  479. this._engine = engine;
  480. this._maxSize = this._engine.getCaps().maxTextureSize;
  481. this._scene.highlightLayers.push(this);
  482. // Warn on stencil.
  483. if (!this._engine.isStencilEnable) {
  484. BABYLON.Tools.Warn("Rendering the Highlight Layer requires the stencil to be active on the canvas. var engine = new BABYLON.Engine(canvas, antialias, { stencil: true }");
  485. }
  486. // Adapt options
  487. this._options = options || {
  488. mainTextureRatio: 0.5,
  489. blurTextureSizeRatio: 0.5,
  490. blurHorizontalSize: 1.0,
  491. blurVerticalSize: 1.0,
  492. alphaBlendingMode: BABYLON.Engine.ALPHA_COMBINE,
  493. camera: null
  494. };
  495. this._options.mainTextureRatio = this._options.mainTextureRatio || 0.5;
  496. this._options.blurTextureSizeRatio = this._options.blurTextureSizeRatio || 1.0;
  497. this._options.blurHorizontalSize = this._options.blurHorizontalSize || 1;
  498. this._options.blurVerticalSize = this._options.blurVerticalSize || 1;
  499. this._options.alphaBlendingMode = this._options.alphaBlendingMode || BABYLON.Engine.ALPHA_COMBINE;
  500. // VBO
  501. var vertices = [];
  502. vertices.push(1, 1);
  503. vertices.push(-1, 1);
  504. vertices.push(-1, -1);
  505. vertices.push(1, -1);
  506. var vertexBuffer = new BABYLON.VertexBuffer(engine, vertices, BABYLON.VertexBuffer.PositionKind, false, false, 2);
  507. this._vertexBuffers[BABYLON.VertexBuffer.PositionKind] = vertexBuffer;
  508. this._createIndexBuffer();
  509. // Effect
  510. this._glowMapMergeEffect = engine.createEffect("glowMapMerge", [BABYLON.VertexBuffer.PositionKind], ["offset"], ["textureSampler"], "");
  511. // Render target
  512. this.setMainTextureSize();
  513. // Create Textures and post processes
  514. this.createTextureAndPostProcesses();
  515. }
  516. Object.defineProperty(HighlightLayer.prototype, "blurHorizontalSize", {
  517. /**
  518. * Gets the horizontal size of the blur.
  519. */
  520. get: function () {
  521. return this._horizontalBlurPostprocess.kernel;
  522. },
  523. /**
  524. * Specifies the horizontal size of the blur.
  525. */
  526. set: function (value) {
  527. this._horizontalBlurPostprocess.kernel = value;
  528. },
  529. enumerable: true,
  530. configurable: true
  531. });
  532. Object.defineProperty(HighlightLayer.prototype, "blurVerticalSize", {
  533. /**
  534. * Gets the vertical size of the blur.
  535. */
  536. get: function () {
  537. return this._verticalBlurPostprocess.kernel;
  538. },
  539. /**
  540. * Specifies the vertical size of the blur.
  541. */
  542. set: function (value) {
  543. this._verticalBlurPostprocess.kernel = value;
  544. },
  545. enumerable: true,
  546. configurable: true
  547. });
  548. Object.defineProperty(HighlightLayer.prototype, "camera", {
  549. /**
  550. * Gets the camera attached to the layer.
  551. */
  552. get: function () {
  553. return this._options.camera;
  554. },
  555. enumerable: true,
  556. configurable: true
  557. });
  558. HighlightLayer.prototype._createIndexBuffer = function () {
  559. var engine = this._scene.getEngine();
  560. // Indices
  561. var indices = [];
  562. indices.push(0);
  563. indices.push(1);
  564. indices.push(2);
  565. indices.push(0);
  566. indices.push(2);
  567. indices.push(3);
  568. this._indexBuffer = engine.createIndexBuffer(indices);
  569. };
  570. HighlightLayer.prototype._rebuild = function () {
  571. var vb = this._vertexBuffers[BABYLON.VertexBuffer.PositionKind];
  572. if (vb) {
  573. vb._rebuild();
  574. }
  575. this._createIndexBuffer();
  576. };
  577. /**
  578. * Creates the render target textures and post processes used in the highlight layer.
  579. */
  580. HighlightLayer.prototype.createTextureAndPostProcesses = function () {
  581. var _this = this;
  582. var blurTextureWidth = this._mainTextureDesiredSize.width * this._options.blurTextureSizeRatio;
  583. var blurTextureHeight = this._mainTextureDesiredSize.height * this._options.blurTextureSizeRatio;
  584. blurTextureWidth = this._engine.needPOTTextures ? BABYLON.Tools.GetExponentOfTwo(blurTextureWidth, this._maxSize) : blurTextureWidth;
  585. blurTextureHeight = this._engine.needPOTTextures ? BABYLON.Tools.GetExponentOfTwo(blurTextureHeight, this._maxSize) : blurTextureHeight;
  586. this._mainTexture = new BABYLON.RenderTargetTexture("HighlightLayerMainRTT", {
  587. width: this._mainTextureDesiredSize.width,
  588. height: this._mainTextureDesiredSize.height
  589. }, this._scene, false, true, BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT);
  590. this._mainTexture.activeCamera = this._options.camera;
  591. this._mainTexture.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
  592. this._mainTexture.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
  593. this._mainTexture.anisotropicFilteringLevel = 1;
  594. this._mainTexture.updateSamplingMode(BABYLON.Texture.BILINEAR_SAMPLINGMODE);
  595. this._mainTexture.renderParticles = false;
  596. this._mainTexture.renderList = null;
  597. this._mainTexture.ignoreCameraViewport = true;
  598. this._blurTexture = new BABYLON.RenderTargetTexture("HighlightLayerBlurRTT", {
  599. width: blurTextureWidth,
  600. height: blurTextureHeight
  601. }, this._scene, false, true, BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT);
  602. this._blurTexture.wrapU = BABYLON.Texture.CLAMP_ADDRESSMODE;
  603. this._blurTexture.wrapV = BABYLON.Texture.CLAMP_ADDRESSMODE;
  604. this._blurTexture.anisotropicFilteringLevel = 16;
  605. this._blurTexture.updateSamplingMode(BABYLON.Texture.TRILINEAR_SAMPLINGMODE);
  606. this._blurTexture.renderParticles = false;
  607. this._blurTexture.ignoreCameraViewport = true;
  608. this._downSamplePostprocess = new BABYLON.PassPostProcess("HighlightLayerPPP", this._options.blurTextureSizeRatio, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine());
  609. this._downSamplePostprocess.onApplyObservable.add(function (effect) {
  610. effect.setTexture("textureSampler", _this._mainTexture);
  611. });
  612. if (this._options.alphaBlendingMode === BABYLON.Engine.ALPHA_COMBINE) {
  613. this._horizontalBlurPostprocess = new GlowBlurPostProcess("HighlightLayerHBP", new BABYLON.Vector2(1.0, 0), this._options.blurHorizontalSize, 1, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine());
  614. this._horizontalBlurPostprocess.onApplyObservable.add(function (effect) {
  615. effect.setFloat2("screenSize", blurTextureWidth, blurTextureHeight);
  616. });
  617. this._verticalBlurPostprocess = new GlowBlurPostProcess("HighlightLayerVBP", new BABYLON.Vector2(0, 1.0), this._options.blurVerticalSize, 1, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine());
  618. this._verticalBlurPostprocess.onApplyObservable.add(function (effect) {
  619. effect.setFloat2("screenSize", blurTextureWidth, blurTextureHeight);
  620. });
  621. }
  622. else {
  623. this._horizontalBlurPostprocess = new BABYLON.BlurPostProcess("HighlightLayerHBP", new BABYLON.Vector2(1.0, 0), this._options.blurHorizontalSize, 1, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine());
  624. this._horizontalBlurPostprocess.onApplyObservable.add(function (effect) {
  625. effect.setFloat2("screenSize", blurTextureWidth, blurTextureHeight);
  626. });
  627. this._verticalBlurPostprocess = new BABYLON.BlurPostProcess("HighlightLayerVBP", new BABYLON.Vector2(0, 1.0), this._options.blurVerticalSize, 1, null, BABYLON.Texture.BILINEAR_SAMPLINGMODE, this._scene.getEngine());
  628. this._verticalBlurPostprocess.onApplyObservable.add(function (effect) {
  629. effect.setFloat2("screenSize", blurTextureWidth, blurTextureHeight);
  630. });
  631. }
  632. this._mainTexture.onAfterUnbindObservable.add(function () {
  633. _this.onBeforeBlurObservable.notifyObservers(_this);
  634. var internalTexture = _this._blurTexture.getInternalTexture();
  635. if (internalTexture) {
  636. _this._scene.postProcessManager.directRender([_this._downSamplePostprocess, _this._horizontalBlurPostprocess, _this._verticalBlurPostprocess], internalTexture, true);
  637. }
  638. _this.onAfterBlurObservable.notifyObservers(_this);
  639. });
  640. // Custom render function
  641. var renderSubMesh = function (subMesh) {
  642. if (!_this._meshes) {
  643. return;
  644. }
  645. var material = subMesh.getMaterial();
  646. var mesh = subMesh.getRenderingMesh();
  647. var scene = _this._scene;
  648. var engine = scene.getEngine();
  649. if (!material) {
  650. return;
  651. }
  652. // Do not block in blend mode.
  653. if (material.needAlphaBlendingForMesh(mesh)) {
  654. return;
  655. }
  656. // Culling
  657. engine.setState(material.backFaceCulling);
  658. // Managing instances
  659. var batch = mesh._getInstancesRenderList(subMesh._id);
  660. if (batch.mustReturn) {
  661. return;
  662. }
  663. // Excluded Mesh
  664. if (_this._excludedMeshes && _this._excludedMeshes[mesh.uniqueId]) {
  665. return;
  666. }
  667. ;
  668. var hardwareInstancedRendering = (engine.getCaps().instancedArrays) && (batch.visibleInstances[subMesh._id] !== null) && (batch.visibleInstances[subMesh._id] !== undefined);
  669. var highlightLayerMesh = _this._meshes[mesh.uniqueId];
  670. var emissiveTexture = null;
  671. if (highlightLayerMesh && highlightLayerMesh.glowEmissiveOnly && material) {
  672. emissiveTexture = material.emissiveTexture;
  673. }
  674. if (_this.isReady(subMesh, hardwareInstancedRendering, emissiveTexture)) {
  675. engine.enableEffect(_this._glowMapGenerationEffect);
  676. mesh._bind(subMesh, _this._glowMapGenerationEffect, BABYLON.Material.TriangleFillMode);
  677. _this._glowMapGenerationEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  678. if (highlightLayerMesh) {
  679. _this._glowMapGenerationEffect.setFloat4("color", highlightLayerMesh.color.r, highlightLayerMesh.color.g, highlightLayerMesh.color.b, 1.0);
  680. }
  681. else {
  682. _this._glowMapGenerationEffect.setFloat4("color", HighlightLayer.neutralColor.r, HighlightLayer.neutralColor.g, HighlightLayer.neutralColor.b, HighlightLayer.neutralColor.a);
  683. }
  684. // Alpha test
  685. if (material && material.needAlphaTesting()) {
  686. var alphaTexture = material.getAlphaTestTexture();
  687. if (alphaTexture) {
  688. _this._glowMapGenerationEffect.setTexture("diffuseSampler", alphaTexture);
  689. var textureMatrix = alphaTexture.getTextureMatrix();
  690. if (textureMatrix) {
  691. _this._glowMapGenerationEffect.setMatrix("diffuseMatrix", textureMatrix);
  692. }
  693. }
  694. }
  695. // Glow emissive only
  696. if (emissiveTexture) {
  697. _this._glowMapGenerationEffect.setTexture("emissiveSampler", emissiveTexture);
  698. _this._glowMapGenerationEffect.setMatrix("emissiveMatrix", emissiveTexture.getTextureMatrix());
  699. }
  700. // Bones
  701. if (mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {
  702. _this._glowMapGenerationEffect.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
  703. }
  704. // Draw
  705. mesh._processRendering(subMesh, _this._glowMapGenerationEffect, BABYLON.Material.TriangleFillMode, batch, hardwareInstancedRendering, function (isInstance, world) { return _this._glowMapGenerationEffect.setMatrix("world", world); });
  706. }
  707. else {
  708. // Need to reset refresh rate of the shadowMap
  709. _this._mainTexture.resetRefreshCounter();
  710. }
  711. };
  712. this._mainTexture.customRenderFunction = function (opaqueSubMeshes, alphaTestSubMeshes, transparentSubMeshes, depthOnlySubMeshes) {
  713. _this.onBeforeRenderMainTextureObservable.notifyObservers(_this);
  714. var index;
  715. var engine = _this._scene.getEngine();
  716. if (depthOnlySubMeshes.length) {
  717. engine.setColorWrite(false);
  718. for (index = 0; index < depthOnlySubMeshes.length; index++) {
  719. renderSubMesh(depthOnlySubMeshes.data[index]);
  720. }
  721. engine.setColorWrite(true);
  722. }
  723. for (index = 0; index < opaqueSubMeshes.length; index++) {
  724. renderSubMesh(opaqueSubMeshes.data[index]);
  725. }
  726. for (index = 0; index < alphaTestSubMeshes.length; index++) {
  727. renderSubMesh(alphaTestSubMeshes.data[index]);
  728. }
  729. for (index = 0; index < transparentSubMeshes.length; index++) {
  730. renderSubMesh(transparentSubMeshes.data[index]);
  731. }
  732. };
  733. this._mainTexture.onClearObservable.add(function (engine) {
  734. engine.clear(HighlightLayer.neutralColor, true, true, true);
  735. });
  736. };
  737. /**
  738. * Checks for the readiness of the element composing the layer.
  739. * @param subMesh the mesh to check for
  740. * @param useInstances specify wether or not to use instances to render the mesh
  741. * @param emissiveTexture the associated emissive texture used to generate the glow
  742. * @return true if ready otherwise, false
  743. */
  744. HighlightLayer.prototype.isReady = function (subMesh, useInstances, emissiveTexture) {
  745. var material = subMesh.getMaterial();
  746. if (!material) {
  747. return false;
  748. }
  749. if (!material.isReady(subMesh.getMesh(), useInstances)) {
  750. return false;
  751. }
  752. var defines = [];
  753. var attribs = [BABYLON.VertexBuffer.PositionKind];
  754. var mesh = subMesh.getMesh();
  755. var uv1 = false;
  756. var uv2 = false;
  757. // Alpha test
  758. if (material && material.needAlphaTesting()) {
  759. var alphaTexture = material.getAlphaTestTexture();
  760. if (alphaTexture) {
  761. defines.push("#define ALPHATEST");
  762. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind) &&
  763. alphaTexture.coordinatesIndex === 1) {
  764. defines.push("#define DIFFUSEUV2");
  765. uv2 = true;
  766. }
  767. else if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
  768. defines.push("#define DIFFUSEUV1");
  769. uv1 = true;
  770. }
  771. }
  772. }
  773. // Emissive
  774. if (emissiveTexture) {
  775. defines.push("#define EMISSIVE");
  776. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind) &&
  777. emissiveTexture.coordinatesIndex === 1) {
  778. defines.push("#define EMISSIVEUV2");
  779. uv2 = true;
  780. }
  781. else if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
  782. defines.push("#define EMISSIVEUV1");
  783. uv1 = true;
  784. }
  785. }
  786. if (uv1) {
  787. attribs.push(BABYLON.VertexBuffer.UVKind);
  788. defines.push("#define UV1");
  789. }
  790. if (uv2) {
  791. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  792. defines.push("#define UV2");
  793. }
  794. // Bones
  795. if (mesh.useBones && mesh.computeBonesUsingShaders) {
  796. attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
  797. attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
  798. if (mesh.numBoneInfluencers > 4) {
  799. attribs.push(BABYLON.VertexBuffer.MatricesIndicesExtraKind);
  800. attribs.push(BABYLON.VertexBuffer.MatricesWeightsExtraKind);
  801. }
  802. defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
  803. defines.push("#define BonesPerMesh " + (mesh.skeleton ? (mesh.skeleton.bones.length + 1) : 0));
  804. }
  805. else {
  806. defines.push("#define NUM_BONE_INFLUENCERS 0");
  807. }
  808. // Instances
  809. if (useInstances) {
  810. defines.push("#define INSTANCES");
  811. attribs.push("world0");
  812. attribs.push("world1");
  813. attribs.push("world2");
  814. attribs.push("world3");
  815. }
  816. // Get correct effect
  817. var join = defines.join("\n");
  818. if (this._cachedDefines !== join) {
  819. this._cachedDefines = join;
  820. this._glowMapGenerationEffect = this._scene.getEngine().createEffect("glowMapGeneration", attribs, ["world", "mBones", "viewProjection", "diffuseMatrix", "color", "emissiveMatrix"], ["diffuseSampler", "emissiveSampler"], join);
  821. }
  822. return this._glowMapGenerationEffect.isReady();
  823. };
  824. /**
  825. * Renders the glowing part of the scene by blending the blurred glowing meshes on top of the rendered scene.
  826. */
  827. HighlightLayer.prototype.render = function () {
  828. var currentEffect = this._glowMapMergeEffect;
  829. // Check
  830. if (!currentEffect.isReady() || !this._blurTexture.isReady())
  831. return;
  832. var engine = this._scene.getEngine();
  833. this.onBeforeComposeObservable.notifyObservers(this);
  834. // Render
  835. engine.enableEffect(currentEffect);
  836. engine.setState(false);
  837. // Cache
  838. var previousStencilBuffer = engine.getStencilBuffer();
  839. var previousStencilFunction = engine.getStencilFunction();
  840. var previousStencilMask = engine.getStencilMask();
  841. var previousStencilOperationPass = engine.getStencilOperationPass();
  842. var previousStencilOperationFail = engine.getStencilOperationFail();
  843. var previousStencilOperationDepthFail = engine.getStencilOperationDepthFail();
  844. var previousAlphaMode = engine.getAlphaMode();
  845. // Texture
  846. currentEffect.setTexture("textureSampler", this._blurTexture);
  847. // VBOs
  848. engine.bindBuffers(this._vertexBuffers, this._indexBuffer, currentEffect);
  849. // Stencil operations
  850. engine.setStencilOperationPass(BABYLON.Engine.REPLACE);
  851. engine.setStencilOperationFail(BABYLON.Engine.KEEP);
  852. engine.setStencilOperationDepthFail(BABYLON.Engine.KEEP);
  853. // Draw order
  854. engine.setAlphaMode(this._options.alphaBlendingMode);
  855. engine.setStencilMask(0x00);
  856. engine.setStencilBuffer(true);
  857. engine.setStencilFunctionReference(this._instanceGlowingMeshStencilReference);
  858. if (this.outerGlow) {
  859. currentEffect.setFloat("offset", 0);
  860. engine.setStencilFunction(BABYLON.Engine.NOTEQUAL);
  861. engine.drawElementsType(BABYLON.Material.TriangleFillMode, 0, 6);
  862. }
  863. if (this.innerGlow) {
  864. currentEffect.setFloat("offset", 1);
  865. engine.setStencilFunction(BABYLON.Engine.EQUAL);
  866. engine.drawElementsType(BABYLON.Material.TriangleFillMode, 0, 6);
  867. }
  868. // Restore Cache
  869. engine.setStencilFunction(previousStencilFunction);
  870. engine.setStencilMask(previousStencilMask);
  871. engine.setAlphaMode(previousAlphaMode);
  872. engine.setStencilBuffer(previousStencilBuffer);
  873. engine.setStencilOperationPass(previousStencilOperationPass);
  874. engine.setStencilOperationFail(previousStencilOperationFail);
  875. engine.setStencilOperationDepthFail(previousStencilOperationDepthFail);
  876. engine._stencilState.reset();
  877. this.onAfterComposeObservable.notifyObservers(this);
  878. // Handle size changes.
  879. var size = this._mainTexture.getSize();
  880. this.setMainTextureSize();
  881. if (size.width !== this._mainTextureDesiredSize.width || size.height !== this._mainTextureDesiredSize.height) {
  882. // Recreate RTT and post processes on size change.
  883. this.onSizeChangedObservable.notifyObservers(this);
  884. this.disposeTextureAndPostProcesses();
  885. this.createTextureAndPostProcesses();
  886. }
  887. };
  888. /**
  889. * Add a mesh in the exclusion list to prevent it to impact or being impacted by the highlight layer.
  890. * @param mesh The mesh to exclude from the highlight layer
  891. */
  892. HighlightLayer.prototype.addExcludedMesh = function (mesh) {
  893. if (!this._excludedMeshes) {
  894. return;
  895. }
  896. var meshExcluded = this._excludedMeshes[mesh.uniqueId];
  897. if (!meshExcluded) {
  898. this._excludedMeshes[mesh.uniqueId] = {
  899. mesh: mesh,
  900. beforeRender: mesh.onBeforeRenderObservable.add(function (mesh) {
  901. mesh.getEngine().setStencilBuffer(false);
  902. }),
  903. afterRender: mesh.onAfterRenderObservable.add(function (mesh) {
  904. mesh.getEngine().setStencilBuffer(true);
  905. }),
  906. };
  907. }
  908. };
  909. /**
  910. * Remove a mesh from the exclusion list to let it impact or being impacted by the highlight layer.
  911. * @param mesh The mesh to highlight
  912. */
  913. HighlightLayer.prototype.removeExcludedMesh = function (mesh) {
  914. if (!this._excludedMeshes) {
  915. return;
  916. }
  917. var meshExcluded = this._excludedMeshes[mesh.uniqueId];
  918. if (meshExcluded) {
  919. if (meshExcluded.beforeRender) {
  920. mesh.onBeforeRenderObservable.remove(meshExcluded.beforeRender);
  921. }
  922. if (meshExcluded.afterRender) {
  923. mesh.onAfterRenderObservable.remove(meshExcluded.afterRender);
  924. }
  925. }
  926. this._excludedMeshes[mesh.uniqueId] = null;
  927. };
  928. /**
  929. * Add a mesh in the highlight layer in order to make it glow with the chosen color.
  930. * @param mesh The mesh to highlight
  931. * @param color The color of the highlight
  932. * @param glowEmissiveOnly Extract the glow from the emissive texture
  933. */
  934. HighlightLayer.prototype.addMesh = function (mesh, color, glowEmissiveOnly) {
  935. var _this = this;
  936. if (glowEmissiveOnly === void 0) { glowEmissiveOnly = false; }
  937. if (!this._meshes) {
  938. return;
  939. }
  940. var meshHighlight = this._meshes[mesh.uniqueId];
  941. if (meshHighlight) {
  942. meshHighlight.color = color;
  943. }
  944. else {
  945. this._meshes[mesh.uniqueId] = {
  946. mesh: mesh,
  947. color: color,
  948. // Lambda required for capture due to Observable this context
  949. observerHighlight: mesh.onBeforeRenderObservable.add(function (mesh) {
  950. if (_this._excludedMeshes && _this._excludedMeshes[mesh.uniqueId]) {
  951. _this.defaultStencilReference(mesh);
  952. }
  953. else {
  954. mesh.getScene().getEngine().setStencilFunctionReference(_this._instanceGlowingMeshStencilReference);
  955. }
  956. }),
  957. observerDefault: mesh.onAfterRenderObservable.add(this.defaultStencilReference),
  958. glowEmissiveOnly: glowEmissiveOnly
  959. };
  960. }
  961. this._shouldRender = true;
  962. };
  963. /**
  964. * Remove a mesh from the highlight layer in order to make it stop glowing.
  965. * @param mesh The mesh to highlight
  966. */
  967. HighlightLayer.prototype.removeMesh = function (mesh) {
  968. if (!this._meshes) {
  969. return;
  970. }
  971. var meshHighlight = this._meshes[mesh.uniqueId];
  972. if (meshHighlight) {
  973. if (meshHighlight.observerHighlight) {
  974. mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
  975. }
  976. if (meshHighlight.observerDefault) {
  977. mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
  978. }
  979. delete this._meshes[mesh.uniqueId];
  980. }
  981. this._shouldRender = false;
  982. for (var meshHighlightToCheck in this._meshes) {
  983. if (this._meshes[meshHighlightToCheck]) {
  984. this._shouldRender = true;
  985. break;
  986. }
  987. }
  988. };
  989. /**
  990. * Returns true if the layer contains information to display, otherwise false.
  991. */
  992. HighlightLayer.prototype.shouldRender = function () {
  993. return this.isEnabled && this._shouldRender;
  994. };
  995. /**
  996. * Sets the main texture desired size which is the closest power of two
  997. * of the engine canvas size.
  998. */
  999. HighlightLayer.prototype.setMainTextureSize = function () {
  1000. if (this._options.mainTextureFixedSize) {
  1001. this._mainTextureDesiredSize.width = this._options.mainTextureFixedSize;
  1002. this._mainTextureDesiredSize.height = this._options.mainTextureFixedSize;
  1003. }
  1004. else {
  1005. this._mainTextureDesiredSize.width = this._engine.getRenderWidth() * this._options.mainTextureRatio;
  1006. this._mainTextureDesiredSize.height = this._engine.getRenderHeight() * this._options.mainTextureRatio;
  1007. this._mainTextureDesiredSize.width = this._engine.needPOTTextures ? BABYLON.Tools.GetExponentOfTwo(this._mainTextureDesiredSize.width, this._maxSize) : this._mainTextureDesiredSize.width;
  1008. this._mainTextureDesiredSize.height = this._engine.needPOTTextures ? BABYLON.Tools.GetExponentOfTwo(this._mainTextureDesiredSize.height, this._maxSize) : this._mainTextureDesiredSize.height;
  1009. }
  1010. };
  1011. /**
  1012. * Force the stencil to the normal expected value for none glowing parts
  1013. */
  1014. HighlightLayer.prototype.defaultStencilReference = function (mesh) {
  1015. mesh.getScene().getEngine().setStencilFunctionReference(HighlightLayer.normalMeshStencilReference);
  1016. };
  1017. /**
  1018. * Dispose only the render target textures and post process.
  1019. */
  1020. HighlightLayer.prototype.disposeTextureAndPostProcesses = function () {
  1021. this._blurTexture.dispose();
  1022. this._mainTexture.dispose();
  1023. this._downSamplePostprocess.dispose();
  1024. this._horizontalBlurPostprocess.dispose();
  1025. this._verticalBlurPostprocess.dispose();
  1026. };
  1027. /**
  1028. * Dispose the highlight layer and free resources.
  1029. */
  1030. HighlightLayer.prototype.dispose = function () {
  1031. var vertexBuffer = this._vertexBuffers[BABYLON.VertexBuffer.PositionKind];
  1032. if (vertexBuffer) {
  1033. vertexBuffer.dispose();
  1034. this._vertexBuffers[BABYLON.VertexBuffer.PositionKind] = null;
  1035. }
  1036. if (this._indexBuffer) {
  1037. this._scene.getEngine()._releaseBuffer(this._indexBuffer);
  1038. this._indexBuffer = null;
  1039. }
  1040. // Clean textures and post processes
  1041. this.disposeTextureAndPostProcesses();
  1042. if (this._meshes) {
  1043. // Clean mesh references
  1044. for (var id in this._meshes) {
  1045. var meshHighlight = this._meshes[id];
  1046. if (meshHighlight && meshHighlight.mesh) {
  1047. if (meshHighlight.observerHighlight) {
  1048. meshHighlight.mesh.onBeforeRenderObservable.remove(meshHighlight.observerHighlight);
  1049. }
  1050. if (meshHighlight.observerDefault) {
  1051. meshHighlight.mesh.onAfterRenderObservable.remove(meshHighlight.observerDefault);
  1052. }
  1053. }
  1054. }
  1055. this._meshes = null;
  1056. }
  1057. if (this._excludedMeshes) {
  1058. for (var id in this._excludedMeshes) {
  1059. var meshHighlight = this._excludedMeshes[id];
  1060. if (meshHighlight) {
  1061. if (meshHighlight.beforeRender) {
  1062. meshHighlight.mesh.onBeforeRenderObservable.remove(meshHighlight.beforeRender);
  1063. }
  1064. if (meshHighlight.afterRender) {
  1065. meshHighlight.mesh.onAfterRenderObservable.remove(meshHighlight.afterRender);
  1066. }
  1067. }
  1068. }
  1069. this._excludedMeshes = null;
  1070. }
  1071. // Remove from scene
  1072. var index = this._scene.highlightLayers.indexOf(this, 0);
  1073. if (index > -1) {
  1074. this._scene.highlightLayers.splice(index, 1);
  1075. }
  1076. // Callback
  1077. this.onDisposeObservable.notifyObservers(this);
  1078. this.onDisposeObservable.clear();
  1079. this.onBeforeRenderMainTextureObservable.clear();
  1080. this.onBeforeBlurObservable.clear();
  1081. this.onBeforeComposeObservable.clear();
  1082. this.onAfterComposeObservable.clear();
  1083. this.onSizeChangedObservable.clear();
  1084. };
  1085. /**
  1086. * The neutral color used during the preparation of the glow effect.
  1087. * This is black by default as the blend operation is a blend operation.
  1088. */
  1089. HighlightLayer.neutralColor = new BABYLON.Color4(0, 0, 0, 0);
  1090. /**
  1091. * Stencil value used for glowing meshes.
  1092. */
  1093. HighlightLayer.glowingMeshStencilReference = 0x02;
  1094. /**
  1095. * Stencil value used for the other meshes in the scene.
  1096. */
  1097. HighlightLayer.normalMeshStencilReference = 0x01;
  1098. return HighlightLayer;
  1099. }());
  1100. BABYLON.HighlightLayer = HighlightLayer;
  1101. })(BABYLON || (BABYLON = {}));
  1102. //# sourceMappingURL=babylon.highlightlayer.js.map
  1103. 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}";
  1104. 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}";
  1105. BABYLON.Effect.ShadersStore['glowBlurPostProcessPixelShader'] = "\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform vec2 screenSize;\nuniform vec2 direction;\nuniform float blurWidth;\n\nfloat getLuminance(vec3 color)\n{\nreturn dot(color,vec3(0.2126,0.7152,0.0722));\n}\nvoid main(void)\n{\nfloat weights[7];\nweights[0]=0.05;\nweights[1]=0.1;\nweights[2]=0.2;\nweights[3]=0.3;\nweights[4]=0.2;\nweights[5]=0.1;\nweights[6]=0.05;\nvec2 texelSize=vec2(1.0/screenSize.x,1.0/screenSize.y);\nvec2 texelStep=texelSize*direction*blurWidth;\nvec2 start=vUV-3.0*texelStep;\nvec4 baseColor=vec4(0.,0.,0.,0.);\nvec2 texelOffset=vec2(0.,0.);\nfor (int i=0; i<7; i++)\n{\n\nvec4 texel=texture2D(textureSampler,start+texelOffset);\nbaseColor.a+=texel.a*weights[i];\n\nfloat luminance=getLuminance(baseColor.rgb);\nfloat luminanceTexel=getLuminance(texel.rgb);\nfloat choice=step(luminanceTexel,luminance);\nbaseColor.rgb=choice*baseColor.rgb+(1.0-choice)*texel.rgb;\ntexelOffset+=texelStep;\n}\ngl_FragColor=baseColor;\n}";
  1106. BABYLON.Effect.ShadersStore['glowMapGenerationPixelShader'] = "#ifdef ALPHATEST\nvarying vec2 vUVDiffuse;\nuniform sampler2D diffuseSampler;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vUVEmissive;\nuniform sampler2D emissiveSampler;\n#endif\nuniform vec4 color;\nvoid main(void)\n{\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUVDiffuse).a<0.4)\ndiscard;\n#endif\n#ifdef EMISSIVE\ngl_FragColor=texture2D(emissiveSampler,vUVEmissive);\n#else\ngl_FragColor=color;\n#endif\n}";
  1107. BABYLON.Effect.ShadersStore['glowMapGenerationVertexShader'] = "\nattribute vec3 position;\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 viewProjection;\nvarying vec4 vPosition;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef ALPHATEST\nvarying vec2 vUVDiffuse;\nuniform mat4 diffuseMatrix;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vUVEmissive;\nuniform mat4 emissiveMatrix;\n#endif\nvoid main(void)\n{\n#include<instancesVertex>\n#include<bonesVertex>\n#ifdef CUBEMAP\nvPosition=finalWorld*vec4(position,1.0);\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\n#else\nvPosition=viewProjection*finalWorld*vec4(position,1.0);\ngl_Position=vPosition;\n#endif\n#ifdef ALPHATEST\n#ifdef DIFFUSEUV1\nvUVDiffuse=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef DIFFUSEUV2\nvUVDiffuse=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n#ifdef EMISSIVE\n#ifdef EMISSIVEUV1\nvUVEmissive=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef EMISSIVEUV2\nvUVEmissive=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n}";
  1108. BABYLON.Effect.ShadersStore['glowMapMergePixelShader'] = "\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\n\nuniform float offset;\nvoid main(void) {\nvec4 baseColor=texture2D(textureSampler,vUV);\nbaseColor.a=abs(offset-baseColor.a);\ngl_FragColor=baseColor;\n}";
  1109. BABYLON.Effect.ShadersStore['glowMapMergeVertexShader'] = "\nattribute vec2 position;\n\nvarying vec2 vUV;\nconst vec2 madd=vec2(0.5,0.5);\nvoid main(void) {\nvUV=position*madd+madd;\ngl_Position=vec4(position,0.0,1.0);\n}";
  1110. BABYLON.Effect.ShadersStore['lineVertexShader'] = "\nattribute vec3 position;\nattribute vec4 normal;\n\nuniform mat4 worldViewProjection;\nuniform float width;\nuniform float aspectRatio;\nvoid main(void) {\nvec4 viewPosition=worldViewProjection*vec4(position,1.0);\nvec4 viewPositionNext=worldViewProjection*vec4(normal.xyz,1.0);\nvec2 currentScreen=viewPosition.xy/viewPosition.w;\nvec2 nextScreen=viewPositionNext.xy/viewPositionNext.w;\ncurrentScreen.x*=aspectRatio;\nnextScreen.x*=aspectRatio;\nvec2 dir=normalize(nextScreen-currentScreen);\nvec2 normalDir=vec2(-dir.y,dir.x);\nnormalDir*=width/2.0;\nnormalDir.x/=aspectRatio;\nvec4 offset=vec4(normalDir*normal.w,0.0,0.0);\ngl_Position=viewPosition+offset;\n}";
  1111. BABYLON.Effect.ShadersStore['linePixelShader'] = "uniform vec4 color;\nvoid main(void) {\ngl_FragColor=color;\n}";
  1112. BABYLON.Effect.ShadersStore['outlineVertexShader'] = "\nattribute vec3 position;\nattribute vec3 normal;\n#include<bonesDeclaration>\n\nuniform float offset;\n#include<instancesDeclaration>\nuniform mat4 viewProjection;\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform mat4 diffuseMatrix;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#endif\n#include<logDepthDeclaration>\nvoid main(void)\n{\nvec3 offsetPosition=position+normal*offset;\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(offsetPosition,1.0);\n#ifdef ALPHATEST\n#ifdef UV1\nvUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n#endif\n#ifdef UV2\nvUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n#endif\n#endif\n#include<logDepthVertex>\n}\n";
  1113. BABYLON.Effect.ShadersStore['outlinePixelShader'] = "#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nuniform vec4 color;\n#ifdef ALPHATEST\nvarying vec2 vUV;\nuniform sampler2D diffuseSampler;\n#endif\n#include<logDepthDeclaration>\nvoid main(void) {\n#ifdef ALPHATEST\nif (texture2D(diffuseSampler,vUV).a<0.4)\ndiscard;\n#endif\n#include<logDepthFragment>\ngl_FragColor=color;\n}";
  1114. BABYLON.Effect.IncludesShadersStore['depthPrePass'] = "#ifdef DEPTHPREPASS\ngl_FragColor=vec4(0.,0.,0.,1.0);\nreturn;\n#endif";
  1115. 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";
  1116. 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";
  1117. BABYLON.Effect.IncludesShadersStore['pointCloudVertexDeclaration'] = "#ifdef POINTSIZE\nuniform float pointSize;\n#endif";
  1118. BABYLON.Effect.IncludesShadersStore['bumpVertexDeclaration'] = "#if defined(BUMP) || defined(PARALLAX)\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\n#endif\n#endif\n";
  1119. BABYLON.Effect.IncludesShadersStore['clipPlaneVertexDeclaration'] = "#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nvarying float fClipDistance;\n#endif";
  1120. BABYLON.Effect.IncludesShadersStore['fogVertexDeclaration'] = "#ifdef FOG\nvarying vec3 vFogDistance;\n#endif";
  1121. BABYLON.Effect.IncludesShadersStore['morphTargetsVertexGlobalDeclaration'] = "#ifdef MORPHTARGETS\nuniform float morphTargetInfluences[NUM_MORPH_INFLUENCERS];\n#endif";
  1122. 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";
  1123. BABYLON.Effect.IncludesShadersStore['logDepthDeclaration'] = "#ifdef LOGARITHMICDEPTH\nuniform float logarithmicDepthConstant;\nvarying float vFragmentDepth;\n#endif";
  1124. 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";
  1125. BABYLON.Effect.IncludesShadersStore['instancesVertex'] = "#ifdef INSTANCES\nmat4 finalWorld=mat4(world0,world1,world2,world3);\n#else\nmat4 finalWorld=world;\n#endif";
  1126. 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";
  1127. 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";
  1128. BABYLON.Effect.IncludesShadersStore['clipPlaneVertex'] = "#ifdef CLIPPLANE\nfClipDistance=dot(worldPos,vClipPlane);\n#endif";
  1129. BABYLON.Effect.IncludesShadersStore['fogVertex'] = "#ifdef FOG\nvFogDistance=(view*worldPos).xyz;\n#endif";
  1130. 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";
  1131. BABYLON.Effect.IncludesShadersStore['pointCloudVertex'] = "#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif";
  1132. BABYLON.Effect.IncludesShadersStore['logDepthVertex'] = "#ifdef LOGARITHMICDEPTH\nvFragmentDepth=1.0+gl_Position.w;\ngl_Position.z=log2(max(0.000001,vFragmentDepth))*logarithmicDepthConstant;\n#endif";
  1133. 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}";
  1134. 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";
  1135. 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";
  1136. 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";
  1137. 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";
  1138. 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";
  1139. 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};";
  1140. 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";
  1141. 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";
  1142. 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}";
  1143. 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";
  1144. 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}";
  1145. 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";
  1146. BABYLON.Effect.IncludesShadersStore['clipPlaneFragmentDeclaration'] = "#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif";
  1147. 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";
  1148. BABYLON.Effect.IncludesShadersStore['clipPlaneFragment'] = "#ifdef CLIPPLANE\nif (fClipDistance>0.0)\n{\ndiscard;\n}\n#endif";
  1149. 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";
  1150. 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";
  1151. BABYLON.Effect.IncludesShadersStore['logDepthFragment'] = "#ifdef LOGARITHMICDEPTH\ngl_FragDepthEXT=log2(vFragmentDepth)*logarithmicDepthConstant*0.5;\n#endif";
  1152. BABYLON.Effect.IncludesShadersStore['fogFragment'] = "#ifdef FOG\nfloat fog=CalcFogFactor();\ncolor.rgb=fog*color.rgb+(1.0-fog)*vFogColor;\n#endif";
  1153. var OutlineRenderer = BABYLON.OutlineRenderer;
  1154. var EdgesRenderer = BABYLON.EdgesRenderer;
  1155. var HighlightLayer = BABYLON.HighlightLayer;
  1156. export { OutlineRenderer,EdgesRenderer,HighlightLayer };