babylon.skyMaterial.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("babylonjs"));
  4. else if(typeof define === 'function' && define.amd)
  5. define("babylonjs-materials", ["babylonjs"], factory);
  6. else if(typeof exports === 'object')
  7. exports["babylonjs-materials"] = factory(require("babylonjs"));
  8. else
  9. root["MATLIB"] = factory(root["BABYLON"]);
  10. })(window, function(__WEBPACK_EXTERNAL_MODULE_babylonjs__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = "./legacy/legacy-sky.ts");
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "../node_modules/webpack/buildin/global.js":
  99. /*!*************************************************!*\
  100. !*** ../node_modules/webpack/buildin/global.js ***!
  101. \*************************************************/
  102. /*! no static exports found */
  103. /***/ (function(module, exports) {
  104. var g;
  105. // This works in non-strict mode
  106. g = (function() {
  107. return this;
  108. })();
  109. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  110. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  111. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  112. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  113. return c > 3 && r && Object.defineProperty(target, key, r), r;
  114. };
  115. var BABYLON;
  116. (function (BABYLON) {
  117. /** @hidden */
  118. var SkyMaterialDefines = /** @class */ (function (_super) {
  119. __extends(SkyMaterialDefines, _super);
  120. function SkyMaterialDefines() {
  121. var _this = _super.call(this) || this;
  122. _this.CLIPPLANE = false;
  123. _this.CLIPPLANE2 = false;
  124. _this.CLIPPLANE3 = false;
  125. _this.CLIPPLANE4 = false;
  126. _this.POINTSIZE = false;
  127. _this.FOG = false;
  128. _this.VERTEXCOLOR = false;
  129. _this.VERTEXALPHA = false;
  130. _this.rebuild();
  131. return _this;
  132. }
  133. return SkyMaterialDefines;
  134. }(BABYLON.MaterialDefines));
  135. /**
  136. * This is the sky material which allows to create dynamic and texture free effects for skyboxes.
  137. * @see https://doc.babylonjs.com/extensions/sky
  138. */
  139. var SkyMaterial = /** @class */ (function (_super) {
  140. __extends(SkyMaterial, _super);
  141. /**
  142. * Instantiates a new sky material.
  143. * This material allows to create dynamic and texture free
  144. * effects for skyboxes by taking care of the atmosphere state.
  145. * @see https://doc.babylonjs.com/extensions/sky
  146. * @param name Define the name of the material in the scene
  147. * @param scene Define the scene the material belong to
  148. */
  149. function SkyMaterial(name, scene) {
  150. var _this = _super.call(this, name, scene) || this;
  151. /**
  152. * Defines the overall luminance of sky in interval ]0, 1[.
  153. */
  154. _this.luminance = 1.0;
  155. /**
  156. * Defines the amount (scattering) of haze as opposed to molecules in atmosphere.
  157. */
  158. _this.turbidity = 10.0;
  159. /**
  160. * Defines the sky appearance (light intensity).
  161. */
  162. _this.rayleigh = 2.0;
  163. /**
  164. * Defines the mieCoefficient in interval [0, 0.1] which affects the property .mieDirectionalG.
  165. */
  166. _this.mieCoefficient = 0.005;
  167. /**
  168. * Defines the amount of haze particles following the Mie scattering theory.
  169. */
  170. _this.mieDirectionalG = 0.8;
  171. /**
  172. * Defines the distance of the sun according to the active scene camera.
  173. */
  174. _this.distance = 500;
  175. /**
  176. * Defines the sun inclination, in interval [-0.5, 0.5]. When the inclination is not 0, the sun is said
  177. * "inclined".
  178. */
  179. _this.inclination = 0.49;
  180. /**
  181. * Defines the solar azimuth in interval [0, 1]. The azimuth is the angle in the horizontal plan between
  182. * an object direction and a reference direction.
  183. */
  184. _this.azimuth = 0.25;
  185. /**
  186. * Defines the sun position in the sky on (x,y,z). If the property .useSunPosition is set to false, then
  187. * the property is overriden by the inclination and the azimuth and can be read at any moment.
  188. */
  189. _this.sunPosition = new BABYLON.Vector3(0, 100, 0);
  190. /**
  191. * Defines if the sun position should be computed (inclination and azimuth) according to the given
  192. * .sunPosition property.
  193. */
  194. _this.useSunPosition = false;
  195. /**
  196. * Defines an offset vector used to get a horizon offset.
  197. * @example skyMaterial.cameraOffset.y = camera.globalPosition.y // Set horizon relative to 0 on the Y axis
  198. */
  199. _this.cameraOffset = BABYLON.Vector3.Zero();
  200. _this._cameraPosition = BABYLON.Vector3.Zero();
  201. return _this;
  202. }
  203. /**
  204. * Specifies if the material will require alpha blending
  205. * @returns a boolean specifying if alpha blending is needed
  206. */
  207. SkyMaterial.prototype.needAlphaBlending = function () {
  208. return (this.alpha < 1.0);
  209. };
  210. /**
  211. * Specifies if this material should be rendered in alpha test mode
  212. * @returns false as the sky material doesn't need alpha testing.
  213. */
  214. SkyMaterial.prototype.needAlphaTesting = function () {
  215. return false;
  216. };
  217. /**
  218. * Get the texture used for alpha test purpose.
  219. * @returns null as the sky material has no texture.
  220. */
  221. SkyMaterial.prototype.getAlphaTestTexture = function () {
  222. return null;
  223. };
  224. /**
  225. * Get if the submesh is ready to be used and all its information available.
  226. * Child classes can use it to update shaders
  227. * @param mesh defines the mesh to check
  228. * @param subMesh defines which submesh to check
  229. * @param useInstances specifies that instances should be used
  230. * @returns a boolean indicating that the submesh is ready or not
  231. */
  232. SkyMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  233. if (this.isFrozen) {
  234. if (this._wasPreviouslyReady && subMesh.effect) {
  235. return true;
  236. }
  237. }
  238. if (!subMesh._materialDefines) {
  239. subMesh._materialDefines = new SkyMaterialDefines();
  240. }
  241. var defines = subMesh._materialDefines;
  242. var scene = this.getScene();
  243. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  244. if (this._renderId === scene.getRenderId()) {
  245. return true;
  246. }
  247. }
  248. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, false, defines);
  249. // Attribs
  250. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, false);
  251. // Get correct effect
  252. if (defines.isDirty) {
  253. defines.markAsProcessed();
  254. scene.resetCachedMaterial();
  255. // Fallbacks
  256. var fallbacks = new BABYLON.EffectFallbacks();
  257. if (defines.FOG) {
  258. fallbacks.addFallback(1, "FOG");
  259. }
  260. //Attributes
  261. var attribs = [BABYLON.VertexBuffer.PositionKind];
  262. if (defines.VERTEXCOLOR) {
  263. attribs.push(BABYLON.VertexBuffer.ColorKind);
  264. }
  265. var shaderName = "sky";
  266. var join = defines.toString();
  267. subMesh.setEffect(scene.getEngine().createEffect(shaderName, attribs, ["world", "viewProjection", "view",
  268. "vFogInfos", "vFogColor", "pointSize", "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4",
  269. "luminance", "turbidity", "rayleigh", "mieCoefficient", "mieDirectionalG", "sunPosition",
  270. "cameraPosition", "cameraOffset"
  271. ], [], join, fallbacks, this.onCompiled, this.onError), defines);
  272. }
  273. if (!subMesh.effect || !subMesh.effect.isReady()) {
  274. return false;
  275. }
  276. this._renderId = scene.getRenderId();
  277. this._wasPreviouslyReady = true;
  278. return true;
  279. };
  280. /**
  281. * Binds the submesh to this material by preparing the effect and shader to draw
  282. * @param world defines the world transformation matrix
  283. * @param mesh defines the mesh containing the submesh
  284. * @param subMesh defines the submesh to bind the material to
  285. */
  286. SkyMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  287. var scene = this.getScene();
  288. var defines = subMesh._materialDefines;
  289. if (!defines) {
  290. return;
  291. }
  292. var effect = subMesh.effect;
  293. if (!effect) {
  294. return;
  295. }
  296. this._activeEffect = effect;
  297. // Matrices
  298. this.bindOnlyWorldMatrix(world);
  299. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  300. if (this._mustRebind(scene, effect)) {
  301. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  302. // Point size
  303. if (this.pointsCloud) {
  304. this._activeEffect.setFloat("pointSize", this.pointSize);
  305. }
  306. }
  307. // View
  308. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  309. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  310. }
  311. // Fog
  312. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  313. // Sky
  314. var camera = scene.activeCamera;
  315. if (camera) {
  316. var cameraWorldMatrix = camera.getWorldMatrix();
  317. this._cameraPosition.x = cameraWorldMatrix.m[12];
  318. this._cameraPosition.y = cameraWorldMatrix.m[13];
  319. this._cameraPosition.z = cameraWorldMatrix.m[14];
  320. this._activeEffect.setVector3("cameraPosition", this._cameraPosition);
  321. }
  322. this._activeEffect.setVector3("cameraOffset", this.cameraOffset);
  323. if (this.luminance > 0) {
  324. this._activeEffect.setFloat("luminance", this.luminance);
  325. }
  326. this._activeEffect.setFloat("turbidity", this.turbidity);
  327. this._activeEffect.setFloat("rayleigh", this.rayleigh);
  328. this._activeEffect.setFloat("mieCoefficient", this.mieCoefficient);
  329. this._activeEffect.setFloat("mieDirectionalG", this.mieDirectionalG);
  330. if (!this.useSunPosition) {
  331. var theta = Math.PI * (this.inclination - 0.5);
  332. var phi = 2 * Math.PI * (this.azimuth - 0.5);
  333. this.sunPosition.x = this.distance * Math.cos(phi);
  334. this.sunPosition.y = this.distance * Math.sin(phi) * Math.sin(theta);
  335. this.sunPosition.z = this.distance * Math.sin(phi) * Math.cos(theta);
  336. }
  337. this._activeEffect.setVector3("sunPosition", this.sunPosition);
  338. this._afterBind(mesh, this._activeEffect);
  339. };
  340. /**
  341. * Get the list of animatables in the material.
  342. * @returns the list of animatables object used in the material
  343. */
  344. SkyMaterial.prototype.getAnimatables = function () {
  345. return [];
  346. };
  347. /**
  348. * Disposes the material
  349. * @param forceDisposeEffect specifies if effects should be forcefully disposed
  350. */
  351. SkyMaterial.prototype.dispose = function (forceDisposeEffect) {
  352. _super.prototype.dispose.call(this, forceDisposeEffect);
  353. };
  354. /**
  355. * Makes a duplicate of the material, and gives it a new name
  356. * @param name defines the new name for the duplicated material
  357. * @returns the cloned material
  358. */
  359. SkyMaterial.prototype.clone = function (name) {
  360. var _this = this;
  361. return BABYLON.SerializationHelper.Clone(function () { return new SkyMaterial(name, _this.getScene()); }, this);
  362. };
  363. /**
  364. * Serializes this material in a JSON representation
  365. * @returns the serialized material object
  366. */
  367. SkyMaterial.prototype.serialize = function () {
  368. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  369. serializationObject.customType = "BABYLON.SkyMaterial";
  370. return serializationObject;
  371. };
  372. /**
  373. * Gets the current class name of the material e.g. "SkyMaterial"
  374. * Mainly use in serialization.
  375. * @returns the class name
  376. */
  377. SkyMaterial.prototype.getClassName = function () {
  378. return "SkyMaterial";
  379. };
  380. /**
  381. * Creates a sky material from parsed material data
  382. * @param source defines the JSON representation of the material
  383. * @param scene defines the hosting scene
  384. * @param rootUrl defines the root URL to use to load textures and relative dependencies
  385. * @returns a new sky material
  386. */
  387. SkyMaterial.Parse = function (source, scene, rootUrl) {
  388. return BABYLON.SerializationHelper.Parse(function () { return new SkyMaterial(source.name, scene); }, source, scene, rootUrl);
  389. };
  390. __decorate([
  391. BABYLON.serialize()
  392. ], SkyMaterial.prototype, "luminance", void 0);
  393. __decorate([
  394. BABYLON.serialize()
  395. ], SkyMaterial.prototype, "turbidity", void 0);
  396. __decorate([
  397. BABYLON.serialize()
  398. ], SkyMaterial.prototype, "rayleigh", void 0);
  399. __decorate([
  400. BABYLON.serialize()
  401. ], SkyMaterial.prototype, "mieCoefficient", void 0);
  402. __decorate([
  403. BABYLON.serialize()
  404. ], SkyMaterial.prototype, "mieDirectionalG", void 0);
  405. __decorate([
  406. BABYLON.serialize()
  407. ], SkyMaterial.prototype, "distance", void 0);
  408. __decorate([
  409. BABYLON.serialize()
  410. ], SkyMaterial.prototype, "inclination", void 0);
  411. __decorate([
  412. BABYLON.serialize()
  413. ], SkyMaterial.prototype, "azimuth", void 0);
  414. __decorate([
  415. BABYLON.serializeAsVector3()
  416. ], SkyMaterial.prototype, "sunPosition", void 0);
  417. __decorate([
  418. BABYLON.serialize()
  419. ], SkyMaterial.prototype, "useSunPosition", void 0);
  420. __decorate([
  421. BABYLON.serialize()
  422. ], SkyMaterial.prototype, "cameraOffset", void 0);
  423. return SkyMaterial;
  424. }(BABYLON.PushMaterial));
  425. BABYLON.SkyMaterial = SkyMaterial;
  426. })(BABYLON || (BABYLON = {}));
  427. //# sourceMappingURL=babylon.skyMaterial.js.map
  428. BABYLON.Effect.ShadersStore['skyVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\nvoid main(void) {\ngl_Position=viewProjection*world*vec4(position,1.0);\nvec4 worldPos=world*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  429. BABYLON.Effect.ShadersStore['skyPixelShader'] = "precision highp float;\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\nuniform vec3 cameraPosition;\nuniform vec3 cameraOffset;\nuniform float luminance;\nuniform float turbidity;\nuniform float rayleigh;\nuniform float mieCoefficient;\nuniform float mieDirectionalG;\nuniform vec3 sunPosition;\n\n#include<fogFragmentDeclaration>\n\nconst float e=2.71828182845904523536028747135266249775724709369995957;\nconst float pi=3.141592653589793238462643383279502884197169;\nconst float n=1.0003;\nconst float N=2.545E25;\nconst float pn=0.035;\nconst vec3 lambda=vec3(680E-9,550E-9,450E-9);\nconst vec3 K=vec3(0.686,0.678,0.666);\nconst float v=4.0;\nconst float rayleighZenithLength=8.4E3;\nconst float mieZenithLength=1.25E3;\nconst vec3 up=vec3(0.0,1.0,0.0);\nconst float EE=1000.0;\nconst float sunAngularDiameterCos=0.999956676946448443553574619906976478926848692873900859324;\nconst float cutoffAngle=pi/1.95;\nconst float steepness=1.5;\nvec3 totalRayleigh(vec3 lambda)\n{\nreturn (8.0*pow(pi,3.0)*pow(pow(n,2.0)-1.0,2.0)*(6.0+3.0*pn))/(3.0*N*pow(lambda,vec3(4.0))*(6.0-7.0*pn));\n}\nvec3 simplifiedRayleigh()\n{\nreturn 0.0005/vec3(94,40,18);\n}\nfloat rayleighPhase(float cosTheta)\n{ \nreturn (3.0/(16.0*pi))*(1.0+pow(cosTheta,2.0));\n}\nvec3 totalMie(vec3 lambda,vec3 K,float T)\n{\nfloat c=(0.2*T )*10E-18;\nreturn 0.434*c*pi*pow((2.0*pi)/lambda,vec3(v-2.0))*K;\n}\nfloat hgPhase(float cosTheta,float g)\n{\nreturn (1.0/(4.0*pi))*((1.0-pow(g,2.0))/pow(1.0-2.0*g*cosTheta+pow(g,2.0),1.5));\n}\nfloat sunIntensity(float zenithAngleCos)\n{\nreturn EE*max(0.0,1.0-exp((-(cutoffAngle-acos(zenithAngleCos))/steepness)));\n}\nfloat A=0.15;\nfloat B=0.50;\nfloat C=0.10;\nfloat D=0.20;\nfloat EEE=0.02;\nfloat F=0.30;\nfloat W=1000.0;\nvec3 Uncharted2Tonemap(vec3 x)\n{\nreturn ((x*(A*x+C*B)+D*EEE)/(x*(A*x+B)+D*F))-EEE/F;\n}\nvoid main(void) {\n\n#include<clipPlaneFragment>\n\nfloat sunfade=1.0-clamp(1.0-exp((sunPosition.y/450000.0)),0.0,1.0);\nfloat rayleighCoefficient=rayleigh-(1.0*(1.0-sunfade));\nvec3 sunDirection=normalize(sunPosition);\nfloat sunE=sunIntensity(dot(sunDirection,up));\nvec3 betaR=simplifiedRayleigh()*rayleighCoefficient;\nvec3 betaM=totalMie(lambda,K,turbidity)*mieCoefficient;\nfloat zenithAngle=acos(max(0.0,dot(up,normalize(vPositionW-cameraPosition+cameraOffset))));\nfloat sR=rayleighZenithLength/(cos(zenithAngle)+0.15*pow(93.885-((zenithAngle*180.0)/pi),-1.253));\nfloat sM=mieZenithLength/(cos(zenithAngle)+0.15*pow(93.885-((zenithAngle*180.0)/pi),-1.253));\nvec3 Fex=exp(-(betaR*sR+betaM*sM));\nfloat cosTheta=dot(normalize(vPositionW-cameraPosition),sunDirection);\nfloat rPhase=rayleighPhase(cosTheta*0.5+0.5);\nvec3 betaRTheta=betaR*rPhase;\nfloat mPhase=hgPhase(cosTheta,mieDirectionalG);\nvec3 betaMTheta=betaM*mPhase;\nvec3 Lin=pow(sunE*((betaRTheta+betaMTheta)/(betaR+betaM))*(1.0-Fex),vec3(1.5));\nLin*=mix(vec3(1.0),pow(sunE*((betaRTheta+betaMTheta)/(betaR+betaM))*Fex,vec3(1.0/2.0)),clamp(pow(1.0-dot(up,sunDirection),5.0),0.0,1.0));\nvec3 direction=normalize(vPositionW-cameraPosition);\nfloat theta=acos(direction.y);\nfloat phi=atan(direction.z,direction.x);\nvec2 uv=vec2(phi,theta)/vec2(2.0*pi,pi)+vec2(0.5,0.0);\nvec3 L0=vec3(0.1)*Fex;\nfloat sundisk=smoothstep(sunAngularDiameterCos,sunAngularDiameterCos+0.00002,cosTheta);\nL0+=(sunE*19000.0*Fex)*sundisk;\nvec3 whiteScale=1.0/Uncharted2Tonemap(vec3(W));\nvec3 texColor=(Lin+L0);\ntexColor*=0.04 ;\ntexColor+=vec3(0.0,0.001,0.0025)*0.3;\nfloat g_fMaxLuminance=1.0;\nfloat fLumScaled=0.1/luminance; \nfloat fLumCompressed=(fLumScaled*(1.0+(fLumScaled/(g_fMaxLuminance*g_fMaxLuminance))))/(1.0+fLumScaled); \nfloat ExposureBias=fLumCompressed;\nvec3 curr=Uncharted2Tonemap((log2(2.0/pow(luminance,4.0)))*texColor);\n\n\n\nvec3 retColor=curr*whiteScale;\n\n\nfloat alpha=1.0;\n#ifdef VERTEXCOLOR\nretColor.rgb*=vColor.rgb;\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n\nvec4 color=clamp(vec4(retColor.rgb,alpha),0.0,1.0);\n\n#include<fogFragment>\ngl_FragColor=color;\n}\n";