(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("babylonjs")); else if(typeof define === 'function' && define.amd) define("babylonjs-materials", ["babylonjs"], factory); else if(typeof exports === 'object') exports["babylonjs-materials"] = factory(require("babylonjs")); else root["MATLIB"] = factory(root["BABYLON"]); })(window, function(__WEBPACK_EXTERNAL_MODULE_babylonjs__) { return /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = "./legacy/legacy-sky.ts"); /******/ }) /************************************************************************/ /******/ ({ /***/ "../Tools/Gulp/node_modules/webpack/buildin/global.js": /*!************************************************************!*\ !*** ../Tools/Gulp/node_modules/webpack/buildin/global.js ***! \************************************************************/ /*! no static exports found */ /***/ (function(module, exports) { var g; // This works in non-strict mode g = (function() { return this; })(); try { // This works if eval is allowed (see CSP) g = g || Function("return this")() || (1, eval)("this"); } catch (e) { // This works if the window reference is available if (typeof window === "object") g = window; } // g can still be undefined, but nothing to do about it... // We return undefined, instead of nothing here, so it's // easier to handle this case. if(!global) { ...} module.exports = g; /***/ }), /***/ "./legacy/legacy-sky.ts": /*!******************************!*\ !*** ./legacy/legacy-sky.ts ***! \******************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; /* WEBPACK VAR INJECTION */(function(global) { function __export(m) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } Object.defineProperty(exports, "__esModule", { value: true }); var MatLib = __webpack_require__(/*! ../src/sky */ "./src/sky/index.ts"); /** * This is the entry point for the UMD module. * The entry point for a future ESM package should be index.ts */ var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined); if (typeof globalObject !== "undefined") { for (var key in MatLib) { globalObject.BABYLON[key] = MatLib[key]; } } __export(__webpack_require__(/*! ../src/sky */ "./src/sky/index.ts")); /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../Tools/Gulp/node_modules/webpack/buildin/global.js */ "../Tools/Gulp/node_modules/webpack/buildin/global.js"))) /***/ }), /***/ "./src/sky/index.ts": /*!**************************!*\ !*** ./src/sky/index.ts ***! \**************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; function __export(m) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } Object.defineProperty(exports, "__esModule", { value: true }); __export(__webpack_require__(/*! ./skyMaterial */ "./src/sky/skyMaterial.ts")); /***/ }), /***/ "./src/sky/sky.fragment.fx": /*!*********************************!*\ !*** ./src/sky/sky.fragment.fx ***! \*********************************/ /*! no static exports found */ /***/ (function(module, exports) { module.exports = "precision highp float;\n\nvarying vec3 vPositionW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include\n\nuniform vec3 cameraPosition;\nuniform float luminance;\nuniform float turbidity;\nuniform float rayleigh;\nuniform float mieCoefficient;\nuniform float mieDirectionalG;\nuniform vec3 sunPosition;\n\n#include\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\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))));\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\ngl_FragColor=color;\n}\n" /***/ }), /***/ "./src/sky/sky.vertex.fx": /*!*******************************!*\ !*** ./src/sky/sky.vertex.fx ***! \*******************************/ /*! no static exports found */ /***/ (function(module, exports) { module.exports = "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\n#include\nvoid main(void) {\ngl_Position=viewProjection*world*vec4(position,1.0);\nvec4 worldPos=world*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n\n#include\n\n#include\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n" /***/ }), /***/ "./src/sky/skyMaterial.ts": /*!********************************!*\ !*** ./src/sky/skyMaterial.ts ***! \********************************/ /*! no static exports found */ /***/ (function(module, exports, __webpack_require__) { "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); } return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); 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; return c > 3 && r && Object.defineProperty(target, key, r), r; }; Object.defineProperty(exports, "__esModule", { value: true }); var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs"); babylonjs_1.Effect.ShadersStore["skyPixelShader"] = __webpack_require__(/*! ./sky.fragment.fx */ "./src/sky/sky.fragment.fx"); babylonjs_1.Effect.ShadersStore["skyVertexShader"] = __webpack_require__(/*! ./sky.vertex.fx */ "./src/sky/sky.vertex.fx"); var SkyMaterialDefines = /** @class */ (function (_super) { __extends(SkyMaterialDefines, _super); function SkyMaterialDefines() { var _this = _super.call(this) || this; _this.CLIPPLANE = false; _this.CLIPPLANE2 = false; _this.CLIPPLANE3 = false; _this.CLIPPLANE4 = false; _this.POINTSIZE = false; _this.FOG = false; _this.VERTEXCOLOR = false; _this.VERTEXALPHA = false; _this.rebuild(); return _this; } return SkyMaterialDefines; }(babylonjs_1.MaterialDefines)); var SkyMaterial = /** @class */ (function (_super) { __extends(SkyMaterial, _super); function SkyMaterial(name, scene) { var _this = _super.call(this, name, scene) || this; // Public members _this.luminance = 1.0; _this.turbidity = 10.0; _this.rayleigh = 2.0; _this.mieCoefficient = 0.005; _this.mieDirectionalG = 0.8; _this.distance = 500; _this.inclination = 0.49; _this.azimuth = 0.25; _this.sunPosition = new babylonjs_1.Vector3(0, 100, 0); _this.useSunPosition = false; // Private members _this._cameraPosition = babylonjs_1.Vector3.Zero(); return _this; } SkyMaterial.prototype.needAlphaBlending = function () { return (this.alpha < 1.0); }; SkyMaterial.prototype.needAlphaTesting = function () { return false; }; SkyMaterial.prototype.getAlphaTestTexture = function () { return null; }; // Methods SkyMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) { if (this.isFrozen) { if (this._wasPreviouslyReady && subMesh.effect) { return true; } } if (!subMesh._materialDefines) { subMesh._materialDefines = new SkyMaterialDefines(); } var defines = subMesh._materialDefines; var scene = this.getScene(); if (!this.checkReadyOnEveryCall && subMesh.effect) { if (this._renderId === scene.getRenderId()) { return true; } } babylonjs_1.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, false, defines); // Attribs babylonjs_1.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, false); // Get correct effect if (defines.isDirty) { defines.markAsProcessed(); scene.resetCachedMaterial(); // Fallbacks var fallbacks = new babylonjs_1.EffectFallbacks(); if (defines.FOG) { fallbacks.addFallback(1, "FOG"); } //Attributes var attribs = [babylonjs_1.VertexBuffer.PositionKind]; if (defines.VERTEXCOLOR) { attribs.push(babylonjs_1.VertexBuffer.ColorKind); } var shaderName = "sky"; var join = defines.toString(); subMesh.setEffect(scene.getEngine().createEffect(shaderName, attribs, ["world", "viewProjection", "view", "vFogInfos", "vFogColor", "pointSize", "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "luminance", "turbidity", "rayleigh", "mieCoefficient", "mieDirectionalG", "sunPosition", "cameraPosition" ], [], join, fallbacks, this.onCompiled, this.onError), defines); } if (!subMesh.effect || !subMesh.effect.isReady()) { return false; } this._renderId = scene.getRenderId(); this._wasPreviouslyReady = true; return true; }; SkyMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) { var scene = this.getScene(); var defines = subMesh._materialDefines; if (!defines) { return; } var effect = subMesh.effect; if (!effect) { return; } this._activeEffect = effect; // Matrices this.bindOnlyWorldMatrix(world); this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix()); if (this._mustRebind(scene, effect)) { BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene); // Point size if (this.pointsCloud) { this._activeEffect.setFloat("pointSize", this.pointSize); } } // View if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== babylonjs_1.Scene.FOGMODE_NONE) { this._activeEffect.setMatrix("view", scene.getViewMatrix()); } // Fog babylonjs_1.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect); // Sky var camera = scene.activeCamera; if (camera) { var cameraWorldMatrix = camera.getWorldMatrix(); this._cameraPosition.x = cameraWorldMatrix.m[12]; this._cameraPosition.y = cameraWorldMatrix.m[13]; this._cameraPosition.z = cameraWorldMatrix.m[14]; this._activeEffect.setVector3("cameraPosition", this._cameraPosition); } if (this.luminance > 0) { this._activeEffect.setFloat("luminance", this.luminance); } this._activeEffect.setFloat("turbidity", this.turbidity); this._activeEffect.setFloat("rayleigh", this.rayleigh); this._activeEffect.setFloat("mieCoefficient", this.mieCoefficient); this._activeEffect.setFloat("mieDirectionalG", this.mieDirectionalG); if (!this.useSunPosition) { var theta = Math.PI * (this.inclination - 0.5); var phi = 2 * Math.PI * (this.azimuth - 0.5); this.sunPosition.x = this.distance * Math.cos(phi); this.sunPosition.y = this.distance * Math.sin(phi) * Math.sin(theta); this.sunPosition.z = this.distance * Math.sin(phi) * Math.cos(theta); } this._activeEffect.setVector3("sunPosition", this.sunPosition); this._afterBind(mesh, this._activeEffect); }; SkyMaterial.prototype.getAnimatables = function () { return []; }; SkyMaterial.prototype.dispose = function (forceDisposeEffect) { _super.prototype.dispose.call(this, forceDisposeEffect); }; SkyMaterial.prototype.clone = function (name) { var _this = this; return babylonjs_1.SerializationHelper.Clone(function () { return new SkyMaterial(name, _this.getScene()); }, this); }; SkyMaterial.prototype.serialize = function () { var serializationObject = babylonjs_1.SerializationHelper.Serialize(this); serializationObject.customType = "BABYLON.SkyMaterial"; return serializationObject; }; SkyMaterial.prototype.getClassName = function () { return "SkyMaterial"; }; // Statics SkyMaterial.Parse = function (source, scene, rootUrl) { return babylonjs_1.SerializationHelper.Parse(function () { return new SkyMaterial(source.name, scene); }, source, scene, rootUrl); }; __decorate([ babylonjs_1.serialize() ], SkyMaterial.prototype, "luminance", void 0); __decorate([ babylonjs_1.serialize() ], SkyMaterial.prototype, "turbidity", void 0); __decorate([ babylonjs_1.serialize() ], SkyMaterial.prototype, "rayleigh", void 0); __decorate([ babylonjs_1.serialize() ], SkyMaterial.prototype, "mieCoefficient", void 0); __decorate([ babylonjs_1.serialize() ], SkyMaterial.prototype, "mieDirectionalG", void 0); __decorate([ babylonjs_1.serialize() ], SkyMaterial.prototype, "distance", void 0); __decorate([ babylonjs_1.serialize() ], SkyMaterial.prototype, "inclination", void 0); __decorate([ babylonjs_1.serialize() ], SkyMaterial.prototype, "azimuth", void 0); __decorate([ babylonjs_1.serializeAsVector3() ], SkyMaterial.prototype, "sunPosition", void 0); __decorate([ babylonjs_1.serialize() ], SkyMaterial.prototype, "useSunPosition", void 0); return SkyMaterial; }(babylonjs_1.PushMaterial)); exports.SkyMaterial = SkyMaterial; /***/ }), /***/ "babylonjs": /*!****************************************************************************************************!*\ !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***! \****************************************************************************************************/ /*! no static exports found */ /***/ (function(module, exports) { module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs__; /***/ }) /******/ }); }); //# sourceMappingURL=babylon.skyMaterial.js.map