babylon.shadowOnlyMaterial.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  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-shadowOnly.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. try {
  110. // This works if eval is allowed (see CSP)
  111. g = g || Function("return this")() || (1, eval)("this");
  112. } catch (e) {
  113. // This works if the window reference is available
  114. if (typeof window === "object") g = window;
  115. }
  116. // g can still be undefined, but nothing to do about it...
  117. // We return undefined, instead of nothing here, so it's
  118. // easier to handle this case. if(!global) { ...}
  119. module.exports = g;
  120. /***/ }),
  121. /***/ "./legacy/legacy-shadowOnly.ts":
  122. /*!*************************************!*\
  123. !*** ./legacy/legacy-shadowOnly.ts ***!
  124. \*************************************/
  125. /*! no static exports found */
  126. /***/ (function(module, exports, __webpack_require__) {
  127. "use strict";
  128. /* WEBPACK VAR INJECTION */(function(global) {
  129. function __export(m) {
  130. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  131. }
  132. Object.defineProperty(exports, "__esModule", { value: true });
  133. var MatLib = __webpack_require__(/*! ../src/shadowOnly/index */ "./src/shadowOnly/index.ts");
  134. /**
  135. * This is the entry point for the UMD module.
  136. * The entry point for a future ESM package should be index.ts
  137. */
  138. var globalObject = (typeof global !== 'undefined') ? global : ((typeof window !== 'undefined') ? window : undefined);
  139. if (typeof globalObject !== "undefined") {
  140. for (var key in MatLib) {
  141. globalObject.BABYLON[key] = MatLib[key];
  142. }
  143. }
  144. __export(__webpack_require__(/*! ../src/shadowOnly/index */ "./src/shadowOnly/index.ts"));
  145. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../node_modules/webpack/buildin/global.js */ "../node_modules/webpack/buildin/global.js")))
  146. /***/ }),
  147. /***/ "./src/shadowOnly/index.ts":
  148. /*!*********************************!*\
  149. !*** ./src/shadowOnly/index.ts ***!
  150. \*********************************/
  151. /*! no static exports found */
  152. /***/ (function(module, exports, __webpack_require__) {
  153. "use strict";
  154. function __export(m) {
  155. for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  156. }
  157. Object.defineProperty(exports, "__esModule", { value: true });
  158. __export(__webpack_require__(/*! ./shadowOnlyMaterial */ "./src/shadowOnly/shadowOnlyMaterial.ts"));
  159. /***/ }),
  160. /***/ "./src/shadowOnly/shadowOnly.fragment.ts":
  161. /*!***********************************************!*\
  162. !*** ./src/shadowOnly/shadowOnly.fragment.ts ***!
  163. \***********************************************/
  164. /*! no static exports found */
  165. /***/ (function(module, exports, __webpack_require__) {
  166. "use strict";
  167. Object.defineProperty(exports, "__esModule", { value: true });
  168. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  169. var name = 'shadowOnlyPixelShader';
  170. exports.name = name;
  171. var shader = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform float alpha;\nuniform vec3 shadowColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#include<lightFragment>[0..1]\n\nvec4 color=vec4(shadowColor,(1.0-clamp(shadow,0.,1.))*alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}";
  172. exports.shader = shader;
  173. babylonjs_1.Effect.ShadersStore[name] = shader;
  174. /***/ }),
  175. /***/ "./src/shadowOnly/shadowOnly.vertex.ts":
  176. /*!*********************************************!*\
  177. !*** ./src/shadowOnly/shadowOnly.vertex.ts ***!
  178. \*********************************************/
  179. /*! no static exports found */
  180. /***/ (function(module, exports, __webpack_require__) {
  181. "use strict";
  182. Object.defineProperty(exports, "__esModule", { value: true });
  183. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  184. var name = 'shadowOnlyVertexShader';
  185. exports.name = name;
  186. var shader = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  187. exports.shader = shader;
  188. babylonjs_1.Effect.ShadersStore[name] = shader;
  189. /***/ }),
  190. /***/ "./src/shadowOnly/shadowOnlyMaterial.ts":
  191. /*!**********************************************!*\
  192. !*** ./src/shadowOnly/shadowOnlyMaterial.ts ***!
  193. \**********************************************/
  194. /*! no static exports found */
  195. /***/ (function(module, exports, __webpack_require__) {
  196. "use strict";
  197. var __extends = (this && this.__extends) || (function () {
  198. var extendStatics = function (d, b) {
  199. extendStatics = Object.setPrototypeOf ||
  200. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  201. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  202. return extendStatics(d, b);
  203. }
  204. return function (d, b) {
  205. extendStatics(d, b);
  206. function __() { this.constructor = d; }
  207. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  208. };
  209. })();
  210. Object.defineProperty(exports, "__esModule", { value: true });
  211. var babylonjs_1 = __webpack_require__(/*! babylonjs */ "babylonjs");
  212. __webpack_require__(/*! ./shadowOnly.fragment */ "./src/shadowOnly/shadowOnly.fragment.ts");
  213. __webpack_require__(/*! ./shadowOnly.vertex */ "./src/shadowOnly/shadowOnly.vertex.ts");
  214. var ShadowOnlyMaterialDefines = /** @class */ (function (_super) {
  215. __extends(ShadowOnlyMaterialDefines, _super);
  216. function ShadowOnlyMaterialDefines() {
  217. var _this = _super.call(this) || this;
  218. _this.CLIPPLANE = false;
  219. _this.CLIPPLANE2 = false;
  220. _this.CLIPPLANE3 = false;
  221. _this.CLIPPLANE4 = false;
  222. _this.POINTSIZE = false;
  223. _this.FOG = false;
  224. _this.NORMAL = false;
  225. _this.NUM_BONE_INFLUENCERS = 0;
  226. _this.BonesPerMesh = 0;
  227. _this.INSTANCES = false;
  228. _this.rebuild();
  229. return _this;
  230. }
  231. return ShadowOnlyMaterialDefines;
  232. }(babylonjs_1.MaterialDefines));
  233. var ShadowOnlyMaterial = /** @class */ (function (_super) {
  234. __extends(ShadowOnlyMaterial, _super);
  235. function ShadowOnlyMaterial(name, scene) {
  236. var _this = _super.call(this, name, scene) || this;
  237. _this.shadowColor = BABYLON.Color3.Black();
  238. return _this;
  239. }
  240. ShadowOnlyMaterial.prototype.needAlphaBlending = function () {
  241. return true;
  242. };
  243. ShadowOnlyMaterial.prototype.needAlphaTesting = function () {
  244. return false;
  245. };
  246. ShadowOnlyMaterial.prototype.getAlphaTestTexture = function () {
  247. return null;
  248. };
  249. Object.defineProperty(ShadowOnlyMaterial.prototype, "activeLight", {
  250. get: function () {
  251. return this._activeLight;
  252. },
  253. set: function (light) {
  254. this._activeLight = light;
  255. },
  256. enumerable: true,
  257. configurable: true
  258. });
  259. // Methods
  260. ShadowOnlyMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  261. if (this.isFrozen) {
  262. if (this._wasPreviouslyReady && subMesh.effect) {
  263. return true;
  264. }
  265. }
  266. if (!subMesh._materialDefines) {
  267. subMesh._materialDefines = new ShadowOnlyMaterialDefines();
  268. }
  269. var defines = subMesh._materialDefines;
  270. var scene = this.getScene();
  271. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  272. if (this._renderId === scene.getRenderId()) {
  273. return true;
  274. }
  275. }
  276. var engine = scene.getEngine();
  277. // Ensure that active light is the first shadow light
  278. if (this._activeLight) {
  279. for (var _i = 0, _a = mesh._lightSources; _i < _a.length; _i++) {
  280. var light = _a[_i];
  281. if (light.shadowEnabled) {
  282. if (this._activeLight === light) {
  283. break; // We are good
  284. }
  285. var lightPosition = mesh._lightSources.indexOf(this._activeLight);
  286. if (lightPosition !== -1) {
  287. mesh._lightSources.splice(lightPosition, 1);
  288. mesh._lightSources.splice(0, 0, this._activeLight);
  289. }
  290. break;
  291. }
  292. }
  293. }
  294. babylonjs_1.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  295. babylonjs_1.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  296. defines._needNormals = babylonjs_1.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, 1);
  297. // Attribs
  298. babylonjs_1.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, false, true);
  299. // Get correct effect
  300. if (defines.isDirty) {
  301. defines.markAsProcessed();
  302. scene.resetCachedMaterial();
  303. // Fallbacks
  304. var fallbacks = new babylonjs_1.EffectFallbacks();
  305. if (defines.FOG) {
  306. fallbacks.addFallback(1, "FOG");
  307. }
  308. babylonjs_1.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, 1);
  309. if (defines.NUM_BONE_INFLUENCERS > 0) {
  310. fallbacks.addCPUSkinningFallback(0, mesh);
  311. }
  312. //Attributes
  313. var attribs = [babylonjs_1.VertexBuffer.PositionKind];
  314. if (defines.NORMAL) {
  315. attribs.push(babylonjs_1.VertexBuffer.NormalKind);
  316. }
  317. babylonjs_1.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  318. babylonjs_1.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  319. var shaderName = "shadowOnly";
  320. var join = defines.toString();
  321. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType",
  322. "vFogInfos", "vFogColor", "pointSize", "alpha", "shadowColor",
  323. "mBones",
  324. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4"
  325. ];
  326. var samplers = new Array();
  327. var uniformBuffers = new Array();
  328. babylonjs_1.MaterialHelper.PrepareUniformsAndSamplersList({
  329. uniformsNames: uniforms,
  330. uniformBuffersNames: uniformBuffers,
  331. samplers: samplers,
  332. defines: defines,
  333. maxSimultaneousLights: 1
  334. });
  335. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  336. attributes: attribs,
  337. uniformsNames: uniforms,
  338. uniformBuffersNames: uniformBuffers,
  339. samplers: samplers,
  340. defines: join,
  341. fallbacks: fallbacks,
  342. onCompiled: this.onCompiled,
  343. onError: this.onError,
  344. indexParameters: { maxSimultaneousLights: 1 }
  345. }, engine), defines);
  346. }
  347. if (!subMesh.effect || !subMesh.effect.isReady()) {
  348. return false;
  349. }
  350. this._renderId = scene.getRenderId();
  351. this._wasPreviouslyReady = true;
  352. return true;
  353. };
  354. ShadowOnlyMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  355. var scene = this.getScene();
  356. var defines = subMesh._materialDefines;
  357. if (!defines) {
  358. return;
  359. }
  360. var effect = subMesh.effect;
  361. if (!effect) {
  362. return;
  363. }
  364. this._activeEffect = effect;
  365. // Matrices
  366. this.bindOnlyWorldMatrix(world);
  367. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  368. // Bones
  369. babylonjs_1.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  370. if (this._mustRebind(scene, effect)) {
  371. // Clip plane
  372. babylonjs_1.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  373. // Point size
  374. if (this.pointsCloud) {
  375. this._activeEffect.setFloat("pointSize", this.pointSize);
  376. }
  377. this._activeEffect.setFloat("alpha", this.alpha);
  378. this._activeEffect.setColor3("shadowColor", this.shadowColor);
  379. babylonjs_1.MaterialHelper.BindEyePosition(effect, scene);
  380. }
  381. // Lights
  382. if (scene.lightsEnabled) {
  383. babylonjs_1.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, 1);
  384. }
  385. // View
  386. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== babylonjs_1.Scene.FOGMODE_NONE) {
  387. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  388. }
  389. // Fog
  390. babylonjs_1.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  391. this._afterBind(mesh, this._activeEffect);
  392. };
  393. ShadowOnlyMaterial.prototype.clone = function (name) {
  394. var _this = this;
  395. return babylonjs_1.SerializationHelper.Clone(function () { return new ShadowOnlyMaterial(name, _this.getScene()); }, this);
  396. };
  397. ShadowOnlyMaterial.prototype.serialize = function () {
  398. var serializationObject = babylonjs_1.SerializationHelper.Serialize(this);
  399. serializationObject.customType = "BABYLON.ShadowOnlyMaterial";
  400. return serializationObject;
  401. };
  402. ShadowOnlyMaterial.prototype.getClassName = function () {
  403. return "ShadowOnlyMaterial";
  404. };
  405. // Statics
  406. ShadowOnlyMaterial.Parse = function (source, scene, rootUrl) {
  407. return babylonjs_1.SerializationHelper.Parse(function () { return new ShadowOnlyMaterial(source.name, scene); }, source, scene, rootUrl);
  408. };
  409. return ShadowOnlyMaterial;
  410. }(babylonjs_1.PushMaterial));
  411. exports.ShadowOnlyMaterial = ShadowOnlyMaterial;
  412. /***/ }),
  413. /***/ "babylonjs":
  414. /*!****************************************************************************************************!*\
  415. !*** external {"root":"BABYLON","commonjs":"babylonjs","commonjs2":"babylonjs","amd":"babylonjs"} ***!
  416. \****************************************************************************************************/
  417. /*! no static exports found */
  418. /***/ (function(module, exports) {
  419. module.exports = __WEBPACK_EXTERNAL_MODULE_babylonjs__;
  420. /***/ })
  421. /******/ });
  422. });
  423. //# sourceMappingURL=babylon.shadowOnlyMaterial.js.map