index.js 101 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143
  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/core');
  15. if(BABYLON !== BABYLON0) __extends(BABYLON, BABYLON0);
  16. var BABYLON;
  17. (function (BABYLON) {
  18. var SphericalPolynomial = /** @class */ (function () {
  19. function SphericalPolynomial() {
  20. this.x = BABYLON.Vector3.Zero();
  21. this.y = BABYLON.Vector3.Zero();
  22. this.z = BABYLON.Vector3.Zero();
  23. this.xx = BABYLON.Vector3.Zero();
  24. this.yy = BABYLON.Vector3.Zero();
  25. this.zz = BABYLON.Vector3.Zero();
  26. this.xy = BABYLON.Vector3.Zero();
  27. this.yz = BABYLON.Vector3.Zero();
  28. this.zx = BABYLON.Vector3.Zero();
  29. }
  30. SphericalPolynomial.prototype.addAmbient = function (color) {
  31. var colorVector = new BABYLON.Vector3(color.r, color.g, color.b);
  32. this.xx = this.xx.add(colorVector);
  33. this.yy = this.yy.add(colorVector);
  34. this.zz = this.zz.add(colorVector);
  35. };
  36. SphericalPolynomial.getSphericalPolynomialFromHarmonics = function (harmonics) {
  37. var result = new SphericalPolynomial();
  38. result.x = harmonics.L11.scale(1.02333);
  39. result.y = harmonics.L1_1.scale(1.02333);
  40. result.z = harmonics.L10.scale(1.02333);
  41. result.xx = harmonics.L00.scale(0.886277).subtract(harmonics.L20.scale(0.247708)).add(harmonics.L22.scale(0.429043));
  42. result.yy = harmonics.L00.scale(0.886277).subtract(harmonics.L20.scale(0.247708)).subtract(harmonics.L22.scale(0.429043));
  43. result.zz = harmonics.L00.scale(0.886277).add(harmonics.L20.scale(0.495417));
  44. result.yz = harmonics.L2_1.scale(0.858086);
  45. result.zx = harmonics.L21.scale(0.858086);
  46. result.xy = harmonics.L2_2.scale(0.858086);
  47. result.scale(1.0 / Math.PI);
  48. return result;
  49. };
  50. SphericalPolynomial.prototype.scale = function (scale) {
  51. this.x = this.x.scale(scale);
  52. this.y = this.y.scale(scale);
  53. this.z = this.z.scale(scale);
  54. this.xx = this.xx.scale(scale);
  55. this.yy = this.yy.scale(scale);
  56. this.zz = this.zz.scale(scale);
  57. this.yz = this.yz.scale(scale);
  58. this.zx = this.zx.scale(scale);
  59. this.xy = this.xy.scale(scale);
  60. };
  61. return SphericalPolynomial;
  62. }());
  63. BABYLON.SphericalPolynomial = SphericalPolynomial;
  64. var SphericalHarmonics = /** @class */ (function () {
  65. function SphericalHarmonics() {
  66. this.L00 = BABYLON.Vector3.Zero();
  67. this.L1_1 = BABYLON.Vector3.Zero();
  68. this.L10 = BABYLON.Vector3.Zero();
  69. this.L11 = BABYLON.Vector3.Zero();
  70. this.L2_2 = BABYLON.Vector3.Zero();
  71. this.L2_1 = BABYLON.Vector3.Zero();
  72. this.L20 = BABYLON.Vector3.Zero();
  73. this.L21 = BABYLON.Vector3.Zero();
  74. this.L22 = BABYLON.Vector3.Zero();
  75. }
  76. SphericalHarmonics.prototype.addLight = function (direction, color, deltaSolidAngle) {
  77. var colorVector = new BABYLON.Vector3(color.r, color.g, color.b);
  78. var c = colorVector.scale(deltaSolidAngle);
  79. this.L00 = this.L00.add(c.scale(0.282095));
  80. this.L1_1 = this.L1_1.add(c.scale(0.488603 * direction.y));
  81. this.L10 = this.L10.add(c.scale(0.488603 * direction.z));
  82. this.L11 = this.L11.add(c.scale(0.488603 * direction.x));
  83. this.L2_2 = this.L2_2.add(c.scale(1.092548 * direction.x * direction.y));
  84. this.L2_1 = this.L2_1.add(c.scale(1.092548 * direction.y * direction.z));
  85. this.L21 = this.L21.add(c.scale(1.092548 * direction.x * direction.z));
  86. this.L20 = this.L20.add(c.scale(0.315392 * (3.0 * direction.z * direction.z - 1.0)));
  87. this.L22 = this.L22.add(c.scale(0.546274 * (direction.x * direction.x - direction.y * direction.y)));
  88. };
  89. SphericalHarmonics.prototype.scale = function (scale) {
  90. this.L00 = this.L00.scale(scale);
  91. this.L1_1 = this.L1_1.scale(scale);
  92. this.L10 = this.L10.scale(scale);
  93. this.L11 = this.L11.scale(scale);
  94. this.L2_2 = this.L2_2.scale(scale);
  95. this.L2_1 = this.L2_1.scale(scale);
  96. this.L20 = this.L20.scale(scale);
  97. this.L21 = this.L21.scale(scale);
  98. this.L22 = this.L22.scale(scale);
  99. };
  100. SphericalHarmonics.prototype.convertIncidentRadianceToIrradiance = function () {
  101. // Convert from incident radiance (Li) to irradiance (E) by applying convolution with the cosine-weighted hemisphere.
  102. //
  103. // E_lm = A_l * L_lm
  104. //
  105. // In spherical harmonics this convolution amounts to scaling factors for each frequency band.
  106. // This corresponds to equation 5 in "An Efficient Representation for Irradiance Environment Maps", where
  107. // the scaling factors are given in equation 9.
  108. // Constant (Band 0)
  109. this.L00 = this.L00.scale(3.141593);
  110. // Linear (Band 1)
  111. this.L1_1 = this.L1_1.scale(2.094395);
  112. this.L10 = this.L10.scale(2.094395);
  113. this.L11 = this.L11.scale(2.094395);
  114. // Quadratic (Band 2)
  115. this.L2_2 = this.L2_2.scale(0.785398);
  116. this.L2_1 = this.L2_1.scale(0.785398);
  117. this.L20 = this.L20.scale(0.785398);
  118. this.L21 = this.L21.scale(0.785398);
  119. this.L22 = this.L22.scale(0.785398);
  120. };
  121. SphericalHarmonics.prototype.convertIrradianceToLambertianRadiance = function () {
  122. // Convert from irradiance to outgoing radiance for Lambertian BDRF, suitable for efficient shader evaluation.
  123. // L = (1/pi) * E * rho
  124. //
  125. // This is done by an additional scale by 1/pi, so is a fairly trivial operation but important conceptually.
  126. this.scale(1.0 / Math.PI);
  127. // The resultant SH now represents outgoing radiance, so includes the Lambert 1/pi normalisation factor but without albedo (rho) applied
  128. // (The pixel shader must apply albedo after texture fetches, etc).
  129. };
  130. SphericalHarmonics.getsphericalHarmonicsFromPolynomial = function (polynomial) {
  131. var result = new SphericalHarmonics();
  132. result.L00 = polynomial.xx.scale(0.376127).add(polynomial.yy.scale(0.376127)).add(polynomial.zz.scale(0.376126));
  133. result.L1_1 = polynomial.y.scale(0.977204);
  134. result.L10 = polynomial.z.scale(0.977204);
  135. result.L11 = polynomial.x.scale(0.977204);
  136. result.L2_2 = polynomial.xy.scale(1.16538);
  137. result.L2_1 = polynomial.yz.scale(1.16538);
  138. result.L20 = polynomial.zz.scale(1.34567).subtract(polynomial.xx.scale(0.672834)).subtract(polynomial.yy.scale(0.672834));
  139. result.L21 = polynomial.zx.scale(1.16538);
  140. result.L22 = polynomial.xx.scale(1.16538).subtract(polynomial.yy.scale(1.16538));
  141. result.scale(Math.PI);
  142. return result;
  143. };
  144. return SphericalHarmonics;
  145. }());
  146. BABYLON.SphericalHarmonics = SphericalHarmonics;
  147. })(BABYLON || (BABYLON = {}));
  148. //# sourceMappingURL=babylon.sphericalPolynomial.js.map
  149. var BABYLON;
  150. (function (BABYLON) {
  151. var FileFaceOrientation = /** @class */ (function () {
  152. function FileFaceOrientation(name, worldAxisForNormal, worldAxisForFileX, worldAxisForFileY) {
  153. this.name = name;
  154. this.worldAxisForNormal = worldAxisForNormal;
  155. this.worldAxisForFileX = worldAxisForFileX;
  156. this.worldAxisForFileY = worldAxisForFileY;
  157. }
  158. return FileFaceOrientation;
  159. }());
  160. ;
  161. /**
  162. * Helper class dealing with the extraction of spherical polynomial dataArray
  163. * from a cube map.
  164. */
  165. var CubeMapToSphericalPolynomialTools = /** @class */ (function () {
  166. function CubeMapToSphericalPolynomialTools() {
  167. }
  168. /**
  169. * Converts a texture to the according Spherical Polynomial data.
  170. * This extracts the first 3 orders only as they are the only one used in the lighting.
  171. *
  172. * @param texture The texture to extract the information from.
  173. * @return The Spherical Polynomial data.
  174. */
  175. CubeMapToSphericalPolynomialTools.ConvertCubeMapTextureToSphericalPolynomial = function (texture) {
  176. if (!texture.isCube) {
  177. // Only supports cube Textures currently.
  178. return null;
  179. }
  180. var size = texture.getSize().width;
  181. var right = texture.readPixels(0);
  182. var left = texture.readPixels(1);
  183. var up;
  184. var down;
  185. if (texture.isRenderTarget) {
  186. up = texture.readPixels(3);
  187. down = texture.readPixels(2);
  188. }
  189. else {
  190. up = texture.readPixels(2);
  191. down = texture.readPixels(3);
  192. }
  193. var front = texture.readPixels(4);
  194. var back = texture.readPixels(5);
  195. var gammaSpace = texture.gammaSpace;
  196. // Always read as RGBA.
  197. var format = BABYLON.Engine.TEXTUREFORMAT_RGBA;
  198. var type = BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT;
  199. if (texture.textureType && texture.textureType !== BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT) {
  200. type = BABYLON.Engine.TEXTURETYPE_FLOAT;
  201. }
  202. var cubeInfo = {
  203. size: size,
  204. right: right,
  205. left: left,
  206. up: up,
  207. down: down,
  208. front: front,
  209. back: back,
  210. format: format,
  211. type: type,
  212. gammaSpace: gammaSpace,
  213. };
  214. return this.ConvertCubeMapToSphericalPolynomial(cubeInfo);
  215. };
  216. /**
  217. * Converts a cubemap to the according Spherical Polynomial data.
  218. * This extracts the first 3 orders only as they are the only one used in the lighting.
  219. *
  220. * @param cubeInfo The Cube map to extract the information from.
  221. * @return The Spherical Polynomial data.
  222. */
  223. CubeMapToSphericalPolynomialTools.ConvertCubeMapToSphericalPolynomial = function (cubeInfo) {
  224. var sphericalHarmonics = new BABYLON.SphericalHarmonics();
  225. var totalSolidAngle = 0.0;
  226. // The (u,v) range is [-1,+1], so the distance between each texel is 2/Size.
  227. var du = 2.0 / cubeInfo.size;
  228. var dv = du;
  229. // The (u,v) of the first texel is half a texel from the corner (-1,-1).
  230. var minUV = du * 0.5 - 1.0;
  231. for (var faceIndex = 0; faceIndex < 6; faceIndex++) {
  232. var fileFace = this.FileFaces[faceIndex];
  233. var dataArray = cubeInfo[fileFace.name];
  234. var v = minUV;
  235. // TODO: we could perform the summation directly into a SphericalPolynomial (SP), which is more efficient than SphericalHarmonic (SH).
  236. // This is possible because during the summation we do not need the SH-specific properties, e.g. orthogonality.
  237. // Because SP is still linear, so summation is fine in that basis.
  238. var stride = cubeInfo.format === BABYLON.Engine.TEXTUREFORMAT_RGBA ? 4 : 3;
  239. for (var y = 0; y < cubeInfo.size; y++) {
  240. var u = minUV;
  241. for (var x = 0; x < cubeInfo.size; x++) {
  242. // World direction (not normalised)
  243. var worldDirection = fileFace.worldAxisForFileX.scale(u).add(fileFace.worldAxisForFileY.scale(v)).add(fileFace.worldAxisForNormal);
  244. worldDirection.normalize();
  245. var deltaSolidAngle = Math.pow(1.0 + u * u + v * v, -3.0 / 2.0);
  246. var r = dataArray[(y * cubeInfo.size * stride) + (x * stride) + 0];
  247. var g = dataArray[(y * cubeInfo.size * stride) + (x * stride) + 1];
  248. var b = dataArray[(y * cubeInfo.size * stride) + (x * stride) + 2];
  249. // Handle Integer types.
  250. if (cubeInfo.type === BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT) {
  251. r /= 255;
  252. g /= 255;
  253. b /= 255;
  254. }
  255. // Handle Gamma space textures.
  256. if (cubeInfo.gammaSpace) {
  257. r = Math.pow(BABYLON.Scalar.Clamp(r), BABYLON.ToLinearSpace);
  258. g = Math.pow(BABYLON.Scalar.Clamp(g), BABYLON.ToLinearSpace);
  259. b = Math.pow(BABYLON.Scalar.Clamp(b), BABYLON.ToLinearSpace);
  260. }
  261. var color = new BABYLON.Color3(r, g, b);
  262. sphericalHarmonics.addLight(worldDirection, color, deltaSolidAngle);
  263. totalSolidAngle += deltaSolidAngle;
  264. u += du;
  265. }
  266. v += dv;
  267. }
  268. }
  269. // Solid angle for entire sphere is 4*pi
  270. var sphereSolidAngle = 4.0 * Math.PI;
  271. // Adjust the solid angle to allow for how many faces we processed.
  272. var facesProcessed = 6.0;
  273. var expectedSolidAngle = sphereSolidAngle * facesProcessed / 6.0;
  274. // Adjust the harmonics so that the accumulated solid angle matches the expected solid angle.
  275. // This is needed because the numerical integration over the cube uses a
  276. // small angle approximation of solid angle for each texel (see deltaSolidAngle),
  277. // and also to compensate for accumulative error due to float precision in the summation.
  278. var correctionFactor = expectedSolidAngle / totalSolidAngle;
  279. sphericalHarmonics.scale(correctionFactor);
  280. sphericalHarmonics.convertIncidentRadianceToIrradiance();
  281. sphericalHarmonics.convertIrradianceToLambertianRadiance();
  282. return BABYLON.SphericalPolynomial.getSphericalPolynomialFromHarmonics(sphericalHarmonics);
  283. };
  284. CubeMapToSphericalPolynomialTools.FileFaces = [
  285. new FileFaceOrientation("right", new BABYLON.Vector3(1, 0, 0), new BABYLON.Vector3(0, 0, -1), new BABYLON.Vector3(0, -1, 0)),
  286. new FileFaceOrientation("left", new BABYLON.Vector3(-1, 0, 0), new BABYLON.Vector3(0, 0, 1), new BABYLON.Vector3(0, -1, 0)),
  287. new FileFaceOrientation("up", new BABYLON.Vector3(0, 1, 0), new BABYLON.Vector3(1, 0, 0), new BABYLON.Vector3(0, 0, 1)),
  288. new FileFaceOrientation("down", new BABYLON.Vector3(0, -1, 0), new BABYLON.Vector3(1, 0, 0), new BABYLON.Vector3(0, 0, -1)),
  289. new FileFaceOrientation("front", new BABYLON.Vector3(0, 0, 1), new BABYLON.Vector3(1, 0, 0), new BABYLON.Vector3(0, -1, 0)),
  290. new FileFaceOrientation("back", new BABYLON.Vector3(0, 0, -1), new BABYLON.Vector3(-1, 0, 0), new BABYLON.Vector3(0, -1, 0)) // -Z bottom
  291. ];
  292. return CubeMapToSphericalPolynomialTools;
  293. }());
  294. BABYLON.CubeMapToSphericalPolynomialTools = CubeMapToSphericalPolynomialTools;
  295. })(BABYLON || (BABYLON = {}));
  296. //# sourceMappingURL=babylon.cubemapToSphericalPolynomial.js.map
  297. 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}";
  298. 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}";
  299. var BABYLON;
  300. (function (BABYLON) {
  301. /**
  302. * Helper class usefull to convert panorama picture to their cubemap representation in 6 faces.
  303. */
  304. var PanoramaToCubeMapTools = /** @class */ (function () {
  305. function PanoramaToCubeMapTools() {
  306. }
  307. /**
  308. * Converts a panorma stored in RGB right to left up to down format into a cubemap (6 faces).
  309. *
  310. * @param float32Array The source data.
  311. * @param inputWidth The width of the input panorama.
  312. * @param inputhHeight The height of the input panorama.
  313. * @param size The willing size of the generated cubemap (each faces will be size * size pixels)
  314. * @return The cubemap data
  315. */
  316. PanoramaToCubeMapTools.ConvertPanoramaToCubemap = function (float32Array, inputWidth, inputHeight, size) {
  317. if (!float32Array) {
  318. throw "ConvertPanoramaToCubemap: input cannot be null";
  319. }
  320. if (float32Array.length != inputWidth * inputHeight * 3) {
  321. throw "ConvertPanoramaToCubemap: input size is wrong";
  322. }
  323. var textureFront = this.CreateCubemapTexture(size, this.FACE_FRONT, float32Array, inputWidth, inputHeight);
  324. var textureBack = this.CreateCubemapTexture(size, this.FACE_BACK, float32Array, inputWidth, inputHeight);
  325. var textureLeft = this.CreateCubemapTexture(size, this.FACE_LEFT, float32Array, inputWidth, inputHeight);
  326. var textureRight = this.CreateCubemapTexture(size, this.FACE_RIGHT, float32Array, inputWidth, inputHeight);
  327. var textureUp = this.CreateCubemapTexture(size, this.FACE_UP, float32Array, inputWidth, inputHeight);
  328. var textureDown = this.CreateCubemapTexture(size, this.FACE_DOWN, float32Array, inputWidth, inputHeight);
  329. return {
  330. front: textureFront,
  331. back: textureBack,
  332. left: textureLeft,
  333. right: textureRight,
  334. up: textureUp,
  335. down: textureDown,
  336. size: size,
  337. type: BABYLON.Engine.TEXTURETYPE_FLOAT,
  338. format: BABYLON.Engine.TEXTUREFORMAT_RGB,
  339. gammaSpace: false,
  340. };
  341. };
  342. PanoramaToCubeMapTools.CreateCubemapTexture = function (texSize, faceData, float32Array, inputWidth, inputHeight) {
  343. var buffer = new ArrayBuffer(texSize * texSize * 4 * 3);
  344. var textureArray = new Float32Array(buffer);
  345. var rotDX1 = faceData[1].subtract(faceData[0]).scale(1 / texSize);
  346. var rotDX2 = faceData[3].subtract(faceData[2]).scale(1 / texSize);
  347. var dy = 1 / texSize;
  348. var fy = 0;
  349. for (var y = 0; y < texSize; y++) {
  350. var xv1 = faceData[0];
  351. var xv2 = faceData[2];
  352. for (var x = 0; x < texSize; x++) {
  353. var v = xv2.subtract(xv1).scale(fy).add(xv1);
  354. v.normalize();
  355. var color = this.CalcProjectionSpherical(v, float32Array, inputWidth, inputHeight);
  356. // 3 channels per pixels
  357. textureArray[y * texSize * 3 + (x * 3) + 0] = color.r;
  358. textureArray[y * texSize * 3 + (x * 3) + 1] = color.g;
  359. textureArray[y * texSize * 3 + (x * 3) + 2] = color.b;
  360. xv1 = xv1.add(rotDX1);
  361. xv2 = xv2.add(rotDX2);
  362. }
  363. fy += dy;
  364. }
  365. return textureArray;
  366. };
  367. PanoramaToCubeMapTools.CalcProjectionSpherical = function (vDir, float32Array, inputWidth, inputHeight) {
  368. var theta = Math.atan2(vDir.z, vDir.x);
  369. var phi = Math.acos(vDir.y);
  370. while (theta < -Math.PI)
  371. theta += 2 * Math.PI;
  372. while (theta > Math.PI)
  373. theta -= 2 * Math.PI;
  374. var dx = theta / Math.PI;
  375. var dy = phi / Math.PI;
  376. // recenter.
  377. dx = dx * 0.5 + 0.5;
  378. var px = Math.round(dx * inputWidth);
  379. if (px < 0)
  380. px = 0;
  381. else if (px >= inputWidth)
  382. px = inputWidth - 1;
  383. var py = Math.round(dy * inputHeight);
  384. if (py < 0)
  385. py = 0;
  386. else if (py >= inputHeight)
  387. py = inputHeight - 1;
  388. var inputY = (inputHeight - py - 1);
  389. var r = float32Array[inputY * inputWidth * 3 + (px * 3) + 0];
  390. var g = float32Array[inputY * inputWidth * 3 + (px * 3) + 1];
  391. var b = float32Array[inputY * inputWidth * 3 + (px * 3) + 2];
  392. return {
  393. r: r,
  394. g: g,
  395. b: b
  396. };
  397. };
  398. PanoramaToCubeMapTools.FACE_FRONT = [
  399. new BABYLON.Vector3(-1.0, -1.0, -1.0),
  400. new BABYLON.Vector3(1.0, -1.0, -1.0),
  401. new BABYLON.Vector3(-1.0, 1.0, -1.0),
  402. new BABYLON.Vector3(1.0, 1.0, -1.0)
  403. ];
  404. PanoramaToCubeMapTools.FACE_BACK = [
  405. new BABYLON.Vector3(1.0, -1.0, 1.0),
  406. new BABYLON.Vector3(-1.0, -1.0, 1.0),
  407. new BABYLON.Vector3(1.0, 1.0, 1.0),
  408. new BABYLON.Vector3(-1.0, 1.0, 1.0)
  409. ];
  410. PanoramaToCubeMapTools.FACE_RIGHT = [
  411. new BABYLON.Vector3(1.0, -1.0, -1.0),
  412. new BABYLON.Vector3(1.0, -1.0, 1.0),
  413. new BABYLON.Vector3(1.0, 1.0, -1.0),
  414. new BABYLON.Vector3(1.0, 1.0, 1.0)
  415. ];
  416. PanoramaToCubeMapTools.FACE_LEFT = [
  417. new BABYLON.Vector3(-1.0, -1.0, 1.0),
  418. new BABYLON.Vector3(-1.0, -1.0, -1.0),
  419. new BABYLON.Vector3(-1.0, 1.0, 1.0),
  420. new BABYLON.Vector3(-1.0, 1.0, -1.0)
  421. ];
  422. PanoramaToCubeMapTools.FACE_DOWN = [
  423. new BABYLON.Vector3(-1.0, 1.0, -1.0),
  424. new BABYLON.Vector3(1.0, 1.0, -1.0),
  425. new BABYLON.Vector3(-1.0, 1.0, 1.0),
  426. new BABYLON.Vector3(1.0, 1.0, 1.0)
  427. ];
  428. PanoramaToCubeMapTools.FACE_UP = [
  429. new BABYLON.Vector3(-1.0, -1.0, 1.0),
  430. new BABYLON.Vector3(1.0, -1.0, 1.0),
  431. new BABYLON.Vector3(-1.0, -1.0, -1.0),
  432. new BABYLON.Vector3(1.0, -1.0, -1.0)
  433. ];
  434. return PanoramaToCubeMapTools;
  435. }());
  436. BABYLON.PanoramaToCubeMapTools = PanoramaToCubeMapTools;
  437. })(BABYLON || (BABYLON = {}));
  438. //# sourceMappingURL=babylon.panoramaToCubemap.js.map
  439. var BABYLON;
  440. (function (BABYLON) {
  441. ;
  442. /**
  443. * This groups tools to convert HDR texture to native colors array.
  444. */
  445. var HDRTools = /** @class */ (function () {
  446. function HDRTools() {
  447. }
  448. HDRTools.Ldexp = function (mantissa, exponent) {
  449. if (exponent > 1023) {
  450. return mantissa * Math.pow(2, 1023) * Math.pow(2, exponent - 1023);
  451. }
  452. if (exponent < -1074) {
  453. return mantissa * Math.pow(2, -1074) * Math.pow(2, exponent + 1074);
  454. }
  455. return mantissa * Math.pow(2, exponent);
  456. };
  457. HDRTools.Rgbe2float = function (float32array, red, green, blue, exponent, index) {
  458. if (exponent > 0) {
  459. exponent = this.Ldexp(1.0, exponent - (128 + 8));
  460. float32array[index + 0] = red * exponent;
  461. float32array[index + 1] = green * exponent;
  462. float32array[index + 2] = blue * exponent;
  463. }
  464. else {
  465. float32array[index + 0] = 0;
  466. float32array[index + 1] = 0;
  467. float32array[index + 2] = 0;
  468. }
  469. };
  470. HDRTools.readStringLine = function (uint8array, startIndex) {
  471. var line = "";
  472. var character = "";
  473. for (var i = startIndex; i < uint8array.length - startIndex; i++) {
  474. character = String.fromCharCode(uint8array[i]);
  475. if (character == "\n") {
  476. break;
  477. }
  478. line += character;
  479. }
  480. return line;
  481. };
  482. /**
  483. * Reads header information from an RGBE texture stored in a native array.
  484. * More information on this format are available here:
  485. * https://en.wikipedia.org/wiki/RGBE_image_format
  486. *
  487. * @param uint8array The binary file stored in native array.
  488. * @return The header information.
  489. */
  490. HDRTools.RGBE_ReadHeader = function (uint8array) {
  491. var height = 0;
  492. var width = 0;
  493. var line = this.readStringLine(uint8array, 0);
  494. if (line[0] != '#' || line[1] != '?') {
  495. throw "Bad HDR Format.";
  496. }
  497. var endOfHeader = false;
  498. var findFormat = false;
  499. var lineIndex = 0;
  500. do {
  501. lineIndex += (line.length + 1);
  502. line = this.readStringLine(uint8array, lineIndex);
  503. if (line == "FORMAT=32-bit_rle_rgbe") {
  504. findFormat = true;
  505. }
  506. else if (line.length == 0) {
  507. endOfHeader = true;
  508. }
  509. } while (!endOfHeader);
  510. if (!findFormat) {
  511. throw "HDR Bad header format, unsupported FORMAT";
  512. }
  513. lineIndex += (line.length + 1);
  514. line = this.readStringLine(uint8array, lineIndex);
  515. var sizeRegexp = /^\-Y (.*) \+X (.*)$/g;
  516. var match = sizeRegexp.exec(line);
  517. // TODO. Support +Y and -X if needed.
  518. if (!match || match.length < 3) {
  519. throw "HDR Bad header format, no size";
  520. }
  521. width = parseInt(match[2]);
  522. height = parseInt(match[1]);
  523. if (width < 8 || width > 0x7fff) {
  524. throw "HDR Bad header format, unsupported size";
  525. }
  526. lineIndex += (line.length + 1);
  527. return {
  528. height: height,
  529. width: width,
  530. dataPosition: lineIndex
  531. };
  532. };
  533. /**
  534. * Returns the cubemap information (each faces texture data) extracted from an RGBE texture.
  535. * This RGBE texture needs to store the information as a panorama.
  536. *
  537. * More information on this format are available here:
  538. * https://en.wikipedia.org/wiki/RGBE_image_format
  539. *
  540. * @param buffer The binary file stored in an array buffer.
  541. * @param size The expected size of the extracted cubemap.
  542. * @return The Cube Map information.
  543. */
  544. HDRTools.GetCubeMapTextureData = function (buffer, size) {
  545. var uint8array = new Uint8Array(buffer);
  546. var hdrInfo = this.RGBE_ReadHeader(uint8array);
  547. var data = this.RGBE_ReadPixels_RLE(uint8array, hdrInfo);
  548. var cubeMapData = BABYLON.PanoramaToCubeMapTools.ConvertPanoramaToCubemap(data, hdrInfo.width, hdrInfo.height, size);
  549. return cubeMapData;
  550. };
  551. /**
  552. * Returns the pixels data extracted from an RGBE texture.
  553. * This pixels will be stored left to right up to down in the R G B order in one array.
  554. *
  555. * More information on this format are available here:
  556. * https://en.wikipedia.org/wiki/RGBE_image_format
  557. *
  558. * @param uint8array The binary file stored in an array buffer.
  559. * @param hdrInfo The header information of the file.
  560. * @return The pixels data in RGB right to left up to down order.
  561. */
  562. HDRTools.RGBE_ReadPixels = function (uint8array, hdrInfo) {
  563. // Keep for multi format supports.
  564. return this.RGBE_ReadPixels_RLE(uint8array, hdrInfo);
  565. };
  566. HDRTools.RGBE_ReadPixels_RLE = function (uint8array, hdrInfo) {
  567. var num_scanlines = hdrInfo.height;
  568. var scanline_width = hdrInfo.width;
  569. var a, b, c, d, count;
  570. var dataIndex = hdrInfo.dataPosition;
  571. var index = 0, endIndex = 0, i = 0;
  572. var scanLineArrayBuffer = new ArrayBuffer(scanline_width * 4); // four channel R G B E
  573. var scanLineArray = new Uint8Array(scanLineArrayBuffer);
  574. // 3 channels of 4 bytes per pixel in float.
  575. var resultBuffer = new ArrayBuffer(hdrInfo.width * hdrInfo.height * 4 * 3);
  576. var resultArray = new Float32Array(resultBuffer);
  577. // read in each successive scanline
  578. while (num_scanlines > 0) {
  579. a = uint8array[dataIndex++];
  580. b = uint8array[dataIndex++];
  581. c = uint8array[dataIndex++];
  582. d = uint8array[dataIndex++];
  583. if (a != 2 || b != 2 || (c & 0x80)) {
  584. // this file is not run length encoded
  585. throw "HDR Bad header format, not RLE";
  586. }
  587. if (((c << 8) | d) != scanline_width) {
  588. throw "HDR Bad header format, wrong scan line width";
  589. }
  590. index = 0;
  591. // read each of the four channels for the scanline into the buffer
  592. for (i = 0; i < 4; i++) {
  593. endIndex = (i + 1) * scanline_width;
  594. while (index < endIndex) {
  595. a = uint8array[dataIndex++];
  596. b = uint8array[dataIndex++];
  597. if (a > 128) {
  598. // a run of the same value
  599. count = a - 128;
  600. if ((count == 0) || (count > endIndex - index)) {
  601. throw "HDR Bad Format, bad scanline data (run)";
  602. }
  603. while (count-- > 0) {
  604. scanLineArray[index++] = b;
  605. }
  606. }
  607. else {
  608. // a non-run
  609. count = a;
  610. if ((count == 0) || (count > endIndex - index)) {
  611. throw "HDR Bad Format, bad scanline data (non-run)";
  612. }
  613. scanLineArray[index++] = b;
  614. if (--count > 0) {
  615. for (var j = 0; j < count; j++) {
  616. scanLineArray[index++] = uint8array[dataIndex++];
  617. }
  618. }
  619. }
  620. }
  621. }
  622. // now convert data from buffer into floats
  623. for (i = 0; i < scanline_width; i++) {
  624. a = scanLineArray[i];
  625. b = scanLineArray[i + scanline_width];
  626. c = scanLineArray[i + 2 * scanline_width];
  627. d = scanLineArray[i + 3 * scanline_width];
  628. this.Rgbe2float(resultArray, a, b, c, d, (hdrInfo.height - num_scanlines) * scanline_width * 3 + i * 3);
  629. }
  630. num_scanlines--;
  631. }
  632. return resultArray;
  633. };
  634. return HDRTools;
  635. }());
  636. BABYLON.HDRTools = HDRTools;
  637. })(BABYLON || (BABYLON = {}));
  638. //# sourceMappingURL=babylon.hdr.js.map
  639. var BABYLON;
  640. (function (BABYLON) {
  641. /**
  642. * This represents a texture coming from an HDR input.
  643. *
  644. * The only supported format is currently panorama picture stored in RGBE format.
  645. * Example of such files can be found on HDRLib: http://hdrlib.com/
  646. */
  647. var HDRCubeTexture = /** @class */ (function (_super) {
  648. __extends(HDRCubeTexture, _super);
  649. /**
  650. * Instantiates an HDRTexture from the following parameters.
  651. *
  652. * @param url The location of the HDR raw data (Panorama stored in RGBE format)
  653. * @param scene The scene the texture will be used in
  654. * @param size The cubemap desired size (the more it increases the longer the generation will be) If the size is omitted this implies you are using a preprocessed cubemap.
  655. * @param noMipmap Forces to not generate the mipmap if true
  656. * @param generateHarmonics Specifies wether you want to extract the polynomial harmonics during the generation process
  657. * @param useInGammaSpace Specifies if the texture will be use in gamma or linear space (the PBR material requires those texture in linear space, but the standard material would require them in Gamma space)
  658. * @param usePMREMGenerator Specifies wether or not to generate the CubeMap through CubeMapGen to avoid seams issue at run time.
  659. */
  660. function HDRCubeTexture(url, scene, size, noMipmap, generateHarmonics, useInGammaSpace, usePMREMGenerator, onLoad, onError) {
  661. if (noMipmap === void 0) { noMipmap = false; }
  662. if (generateHarmonics === void 0) { generateHarmonics = true; }
  663. if (useInGammaSpace === void 0) { useInGammaSpace = false; }
  664. if (usePMREMGenerator === void 0) { usePMREMGenerator = false; }
  665. if (onLoad === void 0) { onLoad = null; }
  666. if (onError === void 0) { onError = null; }
  667. var _this = _super.call(this, scene) || this;
  668. _this._useInGammaSpace = false;
  669. _this._generateHarmonics = true;
  670. _this._isBABYLONPreprocessed = false;
  671. _this._onLoad = null;
  672. _this._onError = null;
  673. /**
  674. * The texture coordinates mode. As this texture is stored in a cube format, please modify carefully.
  675. */
  676. _this.coordinatesMode = BABYLON.Texture.CUBIC_MODE;
  677. /**
  678. * Specifies wether the texture has been generated through the PMREMGenerator tool.
  679. * This is usefull at run time to apply the good shader.
  680. */
  681. _this.isPMREM = false;
  682. _this._isBlocking = true;
  683. if (!url) {
  684. return _this;
  685. }
  686. _this.name = url;
  687. _this.url = url;
  688. _this.hasAlpha = false;
  689. _this.isCube = true;
  690. _this._textureMatrix = BABYLON.Matrix.Identity();
  691. _this._onLoad = onLoad;
  692. _this._onError = onError;
  693. _this.gammaSpace = false;
  694. var caps = scene.getEngine().getCaps();
  695. if (size) {
  696. _this._isBABYLONPreprocessed = false;
  697. _this._noMipmap = noMipmap;
  698. _this._size = size;
  699. _this._useInGammaSpace = useInGammaSpace;
  700. _this._usePMREMGenerator = usePMREMGenerator &&
  701. caps.textureLOD &&
  702. caps.textureFloat &&
  703. !_this._useInGammaSpace;
  704. }
  705. else {
  706. _this._isBABYLONPreprocessed = true;
  707. _this._noMipmap = false;
  708. _this._useInGammaSpace = false;
  709. _this._usePMREMGenerator = caps.textureLOD && caps.textureFloat &&
  710. !_this._useInGammaSpace;
  711. }
  712. _this.isPMREM = _this._usePMREMGenerator;
  713. _this._texture = _this._getFromCache(url, _this._noMipmap);
  714. if (!_this._texture) {
  715. if (!scene.useDelayedTextureLoading) {
  716. _this.loadTexture();
  717. }
  718. else {
  719. _this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_NOTLOADED;
  720. }
  721. }
  722. return _this;
  723. }
  724. Object.defineProperty(HDRCubeTexture.prototype, "isBlocking", {
  725. /**
  726. * Gets wether or not the texture is blocking during loading.
  727. */
  728. get: function () {
  729. return this._isBlocking;
  730. },
  731. /**
  732. * Sets wether or not the texture is blocking during loading.
  733. */
  734. set: function (value) {
  735. this._isBlocking = value;
  736. },
  737. enumerable: true,
  738. configurable: true
  739. });
  740. /**
  741. * Occurs when the file is a preprocessed .babylon.hdr file.
  742. */
  743. HDRCubeTexture.prototype.loadBabylonTexture = function () {
  744. var _this = this;
  745. var mipLevels = 0;
  746. var floatArrayView = null;
  747. var scene = this.getScene();
  748. var mipmapGenerator = (!this._useInGammaSpace && scene && scene.getEngine().getCaps().textureFloat) ? function (data) {
  749. var mips = new Array();
  750. if (!floatArrayView) {
  751. return mips;
  752. }
  753. var startIndex = 30;
  754. for (var level = 0; level < mipLevels; level++) {
  755. mips.push([]);
  756. // Fill each pixel of the mip level.
  757. var faceSize = Math.pow(_this._size >> level, 2) * 3;
  758. for (var faceIndex = 0; faceIndex < 6; faceIndex++) {
  759. var faceData = floatArrayView.subarray(startIndex, startIndex + faceSize);
  760. mips[level].push(faceData);
  761. startIndex += faceSize;
  762. }
  763. }
  764. return mips;
  765. } : null;
  766. var callback = function (buffer) {
  767. var scene = _this.getScene();
  768. if (!scene) {
  769. return null;
  770. }
  771. // Create Native Array Views
  772. var intArrayView = new Int32Array(buffer);
  773. floatArrayView = new Float32Array(buffer);
  774. // Fill header.
  775. var version = intArrayView[0]; // Version 1. (MAy be use in case of format changes for backward compaibility)
  776. _this._size = intArrayView[1]; // CubeMap max mip face size.
  777. // Update Texture Information.
  778. if (!_this._texture) {
  779. return null;
  780. }
  781. _this._texture.updateSize(_this._size, _this._size);
  782. // Fill polynomial information.
  783. var sphericalPolynomial = new BABYLON.SphericalPolynomial();
  784. sphericalPolynomial.x.copyFromFloats(floatArrayView[2], floatArrayView[3], floatArrayView[4]);
  785. sphericalPolynomial.y.copyFromFloats(floatArrayView[5], floatArrayView[6], floatArrayView[7]);
  786. sphericalPolynomial.z.copyFromFloats(floatArrayView[8], floatArrayView[9], floatArrayView[10]);
  787. sphericalPolynomial.xx.copyFromFloats(floatArrayView[11], floatArrayView[12], floatArrayView[13]);
  788. sphericalPolynomial.yy.copyFromFloats(floatArrayView[14], floatArrayView[15], floatArrayView[16]);
  789. sphericalPolynomial.zz.copyFromFloats(floatArrayView[17], floatArrayView[18], floatArrayView[19]);
  790. sphericalPolynomial.xy.copyFromFloats(floatArrayView[20], floatArrayView[21], floatArrayView[22]);
  791. sphericalPolynomial.yz.copyFromFloats(floatArrayView[23], floatArrayView[24], floatArrayView[25]);
  792. sphericalPolynomial.zx.copyFromFloats(floatArrayView[26], floatArrayView[27], floatArrayView[28]);
  793. _this.sphericalPolynomial = sphericalPolynomial;
  794. // Fill pixel data.
  795. mipLevels = intArrayView[29]; // Number of mip levels.
  796. var startIndex = 30;
  797. var data = [];
  798. var faceSize = Math.pow(_this._size, 2) * 3;
  799. for (var faceIndex = 0; faceIndex < 6; faceIndex++) {
  800. data.push(floatArrayView.subarray(startIndex, startIndex + faceSize));
  801. startIndex += faceSize;
  802. }
  803. var results = [];
  804. var byteArray = null;
  805. // Push each faces.
  806. for (var k = 0; k < 6; k++) {
  807. var dataFace = null;
  808. // To be deprecated.
  809. if (version === 1) {
  810. var j = ([0, 2, 4, 1, 3, 5])[k]; // Transforms +X+Y+Z... to +X-X+Y-Y...
  811. dataFace = data[j];
  812. }
  813. // If special cases.
  814. if (!mipmapGenerator && dataFace) {
  815. if (!scene.getEngine().getCaps().textureFloat) {
  816. // 3 channels of 1 bytes per pixel in bytes.
  817. var byteBuffer = new ArrayBuffer(faceSize);
  818. byteArray = new Uint8Array(byteBuffer);
  819. }
  820. for (var i = 0; i < _this._size * _this._size; i++) {
  821. // Put in gamma space if requested.
  822. if (_this._useInGammaSpace) {
  823. dataFace[(i * 3) + 0] = Math.pow(dataFace[(i * 3) + 0], BABYLON.ToGammaSpace);
  824. dataFace[(i * 3) + 1] = Math.pow(dataFace[(i * 3) + 1], BABYLON.ToGammaSpace);
  825. dataFace[(i * 3) + 2] = Math.pow(dataFace[(i * 3) + 2], BABYLON.ToGammaSpace);
  826. }
  827. // Convert to int texture for fallback.
  828. if (byteArray) {
  829. var r = Math.max(dataFace[(i * 3) + 0] * 255, 0);
  830. var g = Math.max(dataFace[(i * 3) + 1] * 255, 0);
  831. var b = Math.max(dataFace[(i * 3) + 2] * 255, 0);
  832. // May use luminance instead if the result is not accurate.
  833. var max = Math.max(Math.max(r, g), b);
  834. if (max > 255) {
  835. var scale = 255 / max;
  836. r *= scale;
  837. g *= scale;
  838. b *= scale;
  839. }
  840. byteArray[(i * 3) + 0] = r;
  841. byteArray[(i * 3) + 1] = g;
  842. byteArray[(i * 3) + 2] = b;
  843. }
  844. }
  845. }
  846. // Fill the array accordingly.
  847. if (byteArray) {
  848. results.push(byteArray);
  849. }
  850. else {
  851. results.push(dataFace);
  852. }
  853. }
  854. return results;
  855. };
  856. if (scene) {
  857. this._texture = scene.getEngine().createRawCubeTextureFromUrl(this.url, scene, this._size, BABYLON.Engine.TEXTUREFORMAT_RGB, scene.getEngine().getCaps().textureFloat ? BABYLON.Engine.TEXTURETYPE_FLOAT : BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT, this._noMipmap, callback, mipmapGenerator, this._onLoad, this._onError);
  858. }
  859. };
  860. /**
  861. * Occurs when the file is raw .hdr file.
  862. */
  863. HDRCubeTexture.prototype.loadHDRTexture = function () {
  864. var _this = this;
  865. var callback = function (buffer) {
  866. var scene = _this.getScene();
  867. if (!scene) {
  868. return null;
  869. }
  870. // Extract the raw linear data.
  871. var data = BABYLON.HDRTools.GetCubeMapTextureData(buffer, _this._size);
  872. // Generate harmonics if needed.
  873. if (_this._generateHarmonics) {
  874. var sphericalPolynomial = BABYLON.CubeMapToSphericalPolynomialTools.ConvertCubeMapToSphericalPolynomial(data);
  875. _this.sphericalPolynomial = sphericalPolynomial;
  876. }
  877. var results = [];
  878. var byteArray = null;
  879. // Push each faces.
  880. for (var j = 0; j < 6; j++) {
  881. // Create uintarray fallback.
  882. if (!scene.getEngine().getCaps().textureFloat) {
  883. // 3 channels of 1 bytes per pixel in bytes.
  884. var byteBuffer = new ArrayBuffer(_this._size * _this._size * 3);
  885. byteArray = new Uint8Array(byteBuffer);
  886. }
  887. var dataFace = (data[HDRCubeTexture._facesMapping[j]]);
  888. // If special cases.
  889. if (_this._useInGammaSpace || byteArray) {
  890. for (var i = 0; i < _this._size * _this._size; i++) {
  891. // Put in gamma space if requested.
  892. if (_this._useInGammaSpace) {
  893. dataFace[(i * 3) + 0] = Math.pow(dataFace[(i * 3) + 0], BABYLON.ToGammaSpace);
  894. dataFace[(i * 3) + 1] = Math.pow(dataFace[(i * 3) + 1], BABYLON.ToGammaSpace);
  895. dataFace[(i * 3) + 2] = Math.pow(dataFace[(i * 3) + 2], BABYLON.ToGammaSpace);
  896. }
  897. // Convert to int texture for fallback.
  898. if (byteArray) {
  899. var r = Math.max(dataFace[(i * 3) + 0] * 255, 0);
  900. var g = Math.max(dataFace[(i * 3) + 1] * 255, 0);
  901. var b = Math.max(dataFace[(i * 3) + 2] * 255, 0);
  902. // May use luminance instead if the result is not accurate.
  903. var max = Math.max(Math.max(r, g), b);
  904. if (max > 255) {
  905. var scale = 255 / max;
  906. r *= scale;
  907. g *= scale;
  908. b *= scale;
  909. }
  910. byteArray[(i * 3) + 0] = r;
  911. byteArray[(i * 3) + 1] = g;
  912. byteArray[(i * 3) + 2] = b;
  913. }
  914. }
  915. }
  916. if (byteArray) {
  917. results.push(byteArray);
  918. }
  919. else {
  920. results.push(dataFace);
  921. }
  922. }
  923. return results;
  924. };
  925. var mipmapGenerator = null;
  926. // TODO. Implement In code PMREM Generator following the LYS toolset generation.
  927. // if (!this._noMipmap &&
  928. // this._usePMREMGenerator) {
  929. // mipmapGenerator = (data: ArrayBufferView[]) => {
  930. // // Custom setup of the generator matching with the PBR shader values.
  931. // var generator = new BABYLON.PMREMGenerator(data,
  932. // this._size,
  933. // this._size,
  934. // 0,
  935. // 3,
  936. // this.getScene().getEngine().getCaps().textureFloat,
  937. // 2048,
  938. // 0.25,
  939. // false,
  940. // true);
  941. // return generator.filterCubeMap();
  942. // };
  943. // }
  944. var scene = this.getScene();
  945. if (scene) {
  946. this._texture = scene.getEngine().createRawCubeTextureFromUrl(this.url, scene, this._size, BABYLON.Engine.TEXTUREFORMAT_RGB, scene.getEngine().getCaps().textureFloat ? BABYLON.Engine.TEXTURETYPE_FLOAT : BABYLON.Engine.TEXTURETYPE_UNSIGNED_INT, this._noMipmap, callback, mipmapGenerator, this._onLoad, this._onError);
  947. }
  948. };
  949. /**
  950. * Starts the loading process of the texture.
  951. */
  952. HDRCubeTexture.prototype.loadTexture = function () {
  953. if (this._isBABYLONPreprocessed) {
  954. this.loadBabylonTexture();
  955. }
  956. else {
  957. this.loadHDRTexture();
  958. }
  959. };
  960. HDRCubeTexture.prototype.clone = function () {
  961. var scene = this.getScene();
  962. if (!scene) {
  963. return this;
  964. }
  965. var size = (this._isBABYLONPreprocessed ? null : this._size);
  966. var newTexture = new HDRCubeTexture(this.url, scene, size, this._noMipmap, this._generateHarmonics, this._useInGammaSpace, this._usePMREMGenerator);
  967. // Base texture
  968. newTexture.level = this.level;
  969. newTexture.wrapU = this.wrapU;
  970. newTexture.wrapV = this.wrapV;
  971. newTexture.coordinatesIndex = this.coordinatesIndex;
  972. newTexture.coordinatesMode = this.coordinatesMode;
  973. return newTexture;
  974. };
  975. // Methods
  976. HDRCubeTexture.prototype.delayLoad = function () {
  977. if (this.delayLoadState !== BABYLON.Engine.DELAYLOADSTATE_NOTLOADED) {
  978. return;
  979. }
  980. this.delayLoadState = BABYLON.Engine.DELAYLOADSTATE_LOADED;
  981. this._texture = this._getFromCache(this.url, this._noMipmap);
  982. if (!this._texture) {
  983. this.loadTexture();
  984. }
  985. };
  986. HDRCubeTexture.prototype.getReflectionTextureMatrix = function () {
  987. return this._textureMatrix;
  988. };
  989. HDRCubeTexture.prototype.setReflectionTextureMatrix = function (value) {
  990. this._textureMatrix = value;
  991. };
  992. HDRCubeTexture.Parse = function (parsedTexture, scene, rootUrl) {
  993. var texture = null;
  994. if (parsedTexture.name && !parsedTexture.isRenderTarget) {
  995. var size = parsedTexture.isBABYLONPreprocessed ? null : parsedTexture.size;
  996. texture = new HDRCubeTexture(rootUrl + parsedTexture.name, scene, size, parsedTexture.noMipmap, parsedTexture.generateHarmonics, parsedTexture.useInGammaSpace, parsedTexture.usePMREMGenerator);
  997. texture.name = parsedTexture.name;
  998. texture.hasAlpha = parsedTexture.hasAlpha;
  999. texture.level = parsedTexture.level;
  1000. texture.coordinatesMode = parsedTexture.coordinatesMode;
  1001. texture.isBlocking = parsedTexture.isBlocking;
  1002. }
  1003. return texture;
  1004. };
  1005. HDRCubeTexture.prototype.serialize = function () {
  1006. if (!this.name) {
  1007. return null;
  1008. }
  1009. var serializationObject = {};
  1010. serializationObject.name = this.name;
  1011. serializationObject.hasAlpha = this.hasAlpha;
  1012. serializationObject.isCube = true;
  1013. serializationObject.level = this.level;
  1014. serializationObject.size = this._size;
  1015. serializationObject.coordinatesMode = this.coordinatesMode;
  1016. serializationObject.useInGammaSpace = this._useInGammaSpace;
  1017. serializationObject.generateHarmonics = this._generateHarmonics;
  1018. serializationObject.usePMREMGenerator = this._usePMREMGenerator;
  1019. serializationObject.isBABYLONPreprocessed = this._isBABYLONPreprocessed;
  1020. serializationObject.customType = "BABYLON.HDRCubeTexture";
  1021. serializationObject.noMipmap = this._noMipmap;
  1022. serializationObject.isBlocking = this._isBlocking;
  1023. return serializationObject;
  1024. };
  1025. /**
  1026. * Saves as a file the data contained in the texture in a binary format.
  1027. * This can be used to prevent the long loading tie associated with creating the seamless texture as well
  1028. * as the spherical used in the lighting.
  1029. * @param url The HDR file url.
  1030. * @param size The size of the texture data to generate (one of the cubemap face desired width).
  1031. * @param onError Method called if any error happens during download.
  1032. * @return The packed binary data.
  1033. */
  1034. HDRCubeTexture.generateBabylonHDROnDisk = function (url, size, onError) {
  1035. if (onError === void 0) { onError = null; }
  1036. var callback = function (buffer) {
  1037. var data = new Blob([buffer], { type: 'application/octet-stream' });
  1038. // Returns a URL you can use as a href.
  1039. var objUrl = window.URL.createObjectURL(data);
  1040. // Simulates a link to it and click to dowload.
  1041. var a = document.createElement("a");
  1042. document.body.appendChild(a);
  1043. a.style.display = "none";
  1044. a.href = objUrl;
  1045. a.download = "envmap.babylon.hdr";
  1046. a.click();
  1047. };
  1048. HDRCubeTexture.generateBabylonHDR(url, size, callback, onError);
  1049. };
  1050. /**
  1051. * Serializes the data contained in the texture in a binary format.
  1052. * This can be used to prevent the long loading tie associated with creating the seamless texture as well
  1053. * as the spherical used in the lighting.
  1054. * @param url The HDR file url.
  1055. * @param size The size of the texture data to generate (one of the cubemap face desired width).
  1056. * @param onError Method called if any error happens during download.
  1057. * @return The packed binary data.
  1058. */
  1059. HDRCubeTexture.generateBabylonHDR = function (url, size, callback, onError) {
  1060. if (onError === void 0) { onError = null; }
  1061. // Needs the url tho create the texture.
  1062. if (!url) {
  1063. return;
  1064. }
  1065. // Check Power of two size.
  1066. if (!BABYLON.Tools.IsExponentOfTwo(size)) {
  1067. return;
  1068. }
  1069. // Coming Back in 3.x.
  1070. BABYLON.Tools.Error("Generation of Babylon HDR is coming back in 3.2.");
  1071. };
  1072. HDRCubeTexture._facesMapping = [
  1073. "right",
  1074. "left",
  1075. "up",
  1076. "down",
  1077. "front",
  1078. "back"
  1079. ];
  1080. return HDRCubeTexture;
  1081. }(BABYLON.BaseTexture));
  1082. BABYLON.HDRCubeTexture = HDRCubeTexture;
  1083. })(BABYLON || (BABYLON = {}));
  1084. //# sourceMappingURL=babylon.hdrCubeTexture.js.map
  1085. BABYLON.Effect.IncludesShadersStore['depthPrePass'] = "#ifdef DEPTHPREPASS\ngl_FragColor=vec4(0.,0.,0.,1.0);\nreturn;\n#endif";
  1086. 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";
  1087. 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";
  1088. BABYLON.Effect.IncludesShadersStore['pointCloudVertexDeclaration'] = "#ifdef POINTSIZE\nuniform float pointSize;\n#endif";
  1089. BABYLON.Effect.IncludesShadersStore['bumpVertexDeclaration'] = "#if defined(BUMP) || defined(PARALLAX)\n#if defined(TANGENT) && defined(NORMAL) \nvarying mat3 vTBN;\n#endif\n#endif\n";
  1090. BABYLON.Effect.IncludesShadersStore['clipPlaneVertexDeclaration'] = "#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nvarying float fClipDistance;\n#endif";
  1091. BABYLON.Effect.IncludesShadersStore['fogVertexDeclaration'] = "#ifdef FOG\nvarying vec3 vFogDistance;\n#endif";
  1092. BABYLON.Effect.IncludesShadersStore['morphTargetsVertexGlobalDeclaration'] = "#ifdef MORPHTARGETS\nuniform float morphTargetInfluences[NUM_MORPH_INFLUENCERS];\n#endif";
  1093. 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";
  1094. BABYLON.Effect.IncludesShadersStore['logDepthDeclaration'] = "#ifdef LOGARITHMICDEPTH\nuniform float logarithmicDepthConstant;\nvarying float vFragmentDepth;\n#endif";
  1095. 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";
  1096. BABYLON.Effect.IncludesShadersStore['instancesVertex'] = "#ifdef INSTANCES\nmat4 finalWorld=mat4(world0,world1,world2,world3);\n#else\nmat4 finalWorld=world;\n#endif";
  1097. 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";
  1098. 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";
  1099. BABYLON.Effect.IncludesShadersStore['clipPlaneVertex'] = "#ifdef CLIPPLANE\nfClipDistance=dot(worldPos,vClipPlane);\n#endif";
  1100. BABYLON.Effect.IncludesShadersStore['fogVertex'] = "#ifdef FOG\nvFogDistance=(view*worldPos).xyz;\n#endif";
  1101. 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";
  1102. BABYLON.Effect.IncludesShadersStore['pointCloudVertex'] = "#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif";
  1103. BABYLON.Effect.IncludesShadersStore['logDepthVertex'] = "#ifdef LOGARITHMICDEPTH\nvFragmentDepth=1.0+gl_Position.w;\ngl_Position.z=log2(max(0.000001,vFragmentDepth))*logarithmicDepthConstant;\n#endif";
  1104. 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}";
  1105. 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";
  1106. 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";
  1107. 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";
  1108. 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";
  1109. 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";
  1110. 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};";
  1111. 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";
  1112. 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";
  1113. 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}";
  1114. 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";
  1115. 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}";
  1116. 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";
  1117. BABYLON.Effect.IncludesShadersStore['clipPlaneFragmentDeclaration'] = "#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif";
  1118. 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";
  1119. BABYLON.Effect.IncludesShadersStore['clipPlaneFragment'] = "#ifdef CLIPPLANE\nif (fClipDistance>0.0)\n{\ndiscard;\n}\n#endif";
  1120. 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";
  1121. 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";
  1122. BABYLON.Effect.IncludesShadersStore['logDepthFragment'] = "#ifdef LOGARITHMICDEPTH\ngl_FragDepthEXT=log2(vFragmentDepth)*logarithmicDepthConstant*0.5;\n#endif";
  1123. BABYLON.Effect.IncludesShadersStore['fogFragment'] = "#ifdef FOG\nfloat fog=CalcFogFactor();\ncolor.rgb=fog*color.rgb+(1.0-fog)*vFogColor;\n#endif";
  1124. (function() {
  1125. var EXPORTS = {};EXPORTS['SphericalPolynomial'] = BABYLON['SphericalPolynomial'];EXPORTS['SphericalHarmonics'] = BABYLON['SphericalHarmonics'];EXPORTS['CubeMapToSphericalPolynomialTools'] = BABYLON['CubeMapToSphericalPolynomialTools'];EXPORTS['PanoramaToCubeMapTools'] = BABYLON['PanoramaToCubeMapTools'];EXPORTS['HDRTools'] = BABYLON['HDRTools'];EXPORTS['reprocessed'] = BABYLON['reprocessed'];EXPORTS['reprocessed'] = BABYLON['reprocessed'];EXPORTS['reprocessed'] = BABYLON['reprocessed'];EXPORTS['reprocessed'] = BABYLON['reprocessed'];EXPORTS['HDRCubeTexture'] = BABYLON['HDRCubeTexture'];
  1126. globalObject["BABYLON"] = globalObject["BABYLON"] || BABYLON;
  1127. module.exports = EXPORTS;
  1128. })();
  1129. }