index.js 108 KB

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