babylon.customMaterial.js 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = Object.setPrototypeOf ||
  4. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6. return function (d, b) {
  7. extendStatics(d, b);
  8. function __() { this.constructor = d; }
  9. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10. };
  11. })();
  12. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  13. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  14. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  15. 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;
  16. return c > 3 && r && Object.defineProperty(target, key, r), r;
  17. };
  18. var BABYLON;
  19. (function (BABYLON) {
  20. // old version of standard material updated every 3 months
  21. var StandardMaterialDefines_OldVer = /** @class */ (function (_super) {
  22. __extends(StandardMaterialDefines_OldVer, _super);
  23. function StandardMaterialDefines_OldVer() {
  24. var _this = _super.call(this) || this;
  25. _this.DIFFUSE = false;
  26. _this.AMBIENT = false;
  27. _this.OPACITY = false;
  28. _this.OPACITYRGB = false;
  29. _this.REFLECTION = false;
  30. _this.EMISSIVE = false;
  31. _this.SPECULAR = false;
  32. _this.BUMP = false;
  33. _this.PARALLAX = false;
  34. _this.PARALLAXOCCLUSION = false;
  35. _this.SPECULAROVERALPHA = false;
  36. _this.CLIPPLANE = false;
  37. _this.ALPHATEST = false;
  38. _this.ALPHAFROMDIFFUSE = false;
  39. _this.POINTSIZE = false;
  40. _this.FOG = false;
  41. _this.SPECULARTERM = false;
  42. _this.DIFFUSEFRESNEL = false;
  43. _this.OPACITYFRESNEL = false;
  44. _this.REFLECTIONFRESNEL = false;
  45. _this.REFRACTIONFRESNEL = false;
  46. _this.EMISSIVEFRESNEL = false;
  47. _this.FRESNEL = false;
  48. _this.NORMAL = false;
  49. _this.UV1 = false;
  50. _this.UV2 = false;
  51. _this.VERTEXCOLOR = false;
  52. _this.VERTEXALPHA = false;
  53. _this.NUM_BONE_INFLUENCERS = 0;
  54. _this.BonesPerMesh = 0;
  55. _this.INSTANCES = false;
  56. _this.GLOSSINESS = false;
  57. _this.ROUGHNESS = false;
  58. _this.EMISSIVEASILLUMINATION = false;
  59. _this.LINKEMISSIVEWITHDIFFUSE = false;
  60. _this.REFLECTIONFRESNELFROMSPECULAR = false;
  61. _this.LIGHTMAP = false;
  62. _this.USELIGHTMAPASSHADOWMAP = false;
  63. _this.REFLECTIONMAP_3D = false;
  64. _this.REFLECTIONMAP_SPHERICAL = false;
  65. _this.REFLECTIONMAP_PLANAR = false;
  66. _this.REFLECTIONMAP_CUBIC = false;
  67. _this.REFLECTIONMAP_PROJECTION = false;
  68. _this.REFLECTIONMAP_SKYBOX = false;
  69. _this.REFLECTIONMAP_EXPLICIT = false;
  70. _this.REFLECTIONMAP_EQUIRECTANGULAR = false;
  71. _this.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;
  72. _this.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false;
  73. _this.INVERTCUBICMAP = false;
  74. _this.LOGARITHMICDEPTH = false;
  75. _this.REFRACTION = false;
  76. _this.REFRACTIONMAP_3D = false;
  77. _this.REFLECTIONOVERALPHA = false;
  78. _this.INVERTNORMALMAPX = false;
  79. _this.INVERTNORMALMAPY = false;
  80. _this.TWOSIDEDLIGHTING = false;
  81. _this.SHADOWFLOAT = false;
  82. _this.MORPHTARGETS = false;
  83. _this.MORPHTARGETS_NORMAL = false;
  84. _this.MORPHTARGETS_TANGENT = false;
  85. _this.NUM_MORPH_INFLUENCERS = 0;
  86. _this.USERIGHTHANDEDSYSTEM = false;
  87. _this.IMAGEPROCESSING = false;
  88. _this.VIGNETTE = false;
  89. _this.VIGNETTEBLENDMODEMULTIPLY = false;
  90. _this.VIGNETTEBLENDMODEOPAQUE = false;
  91. _this.TONEMAPPING = false;
  92. _this.CONTRAST = false;
  93. _this.COLORCURVES = false;
  94. _this.COLORGRADING = false;
  95. _this.SAMPLER3DGREENDEPTH = false;
  96. _this.SAMPLER3DBGRMAP = false;
  97. _this.IMAGEPROCESSINGPOSTPROCESS = false;
  98. _this.EXPOSURE = false;
  99. _this.rebuild();
  100. return _this;
  101. }
  102. StandardMaterialDefines_OldVer.prototype.setReflectionMode = function (modeToEnable) {
  103. var modes = [
  104. "REFLECTIONMAP_CUBIC", "REFLECTIONMAP_EXPLICIT", "REFLECTIONMAP_PLANAR",
  105. "REFLECTIONMAP_PROJECTION", "REFLECTIONMAP_PROJECTION", "REFLECTIONMAP_SKYBOX",
  106. "REFLECTIONMAP_SPHERICAL", "REFLECTIONMAP_EQUIRECTANGULAR", "REFLECTIONMAP_EQUIRECTANGULAR_FIXED",
  107. "REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED"
  108. ];
  109. for (var _i = 0, modes_1 = modes; _i < modes_1.length; _i++) {
  110. var mode = modes_1[_i];
  111. this[mode] = (mode === modeToEnable);
  112. }
  113. };
  114. return StandardMaterialDefines_OldVer;
  115. }(BABYLON.MaterialDefines));
  116. BABYLON.StandardMaterialDefines_OldVer = StandardMaterialDefines_OldVer;
  117. var StandardMaterial_OldVer = /** @class */ (function (_super) {
  118. __extends(StandardMaterial_OldVer, _super);
  119. function StandardMaterial_OldVer(name, scene) {
  120. var _this = _super.call(this, name, scene) || this;
  121. _this.ambientColor = new BABYLON.Color3(0, 0, 0);
  122. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  123. _this.specularColor = new BABYLON.Color3(1, 1, 1);
  124. _this.emissiveColor = new BABYLON.Color3(0, 0, 0);
  125. _this.specularPower = 64;
  126. _this._useAlphaFromDiffuseTexture = false;
  127. _this._useEmissiveAsIllumination = false;
  128. _this._linkEmissiveWithDiffuse = false;
  129. _this._useSpecularOverAlpha = false;
  130. _this._useReflectionOverAlpha = false;
  131. _this._disableLighting = false;
  132. _this._useParallax = false;
  133. _this._useParallaxOcclusion = false;
  134. _this.parallaxScaleBias = 0.05;
  135. _this._roughness = 0;
  136. _this.indexOfRefraction = 0.98;
  137. _this.invertRefractionY = true;
  138. _this._useLightmapAsShadowmap = false;
  139. _this._useReflectionFresnelFromSpecular = false;
  140. _this._useGlossinessFromSpecularMapAlpha = false;
  141. _this._maxSimultaneousLights = 4;
  142. /**
  143. * If sets to true, x component of normal map value will invert (x = 1.0 - x).
  144. */
  145. _this._invertNormalMapX = false;
  146. /**
  147. * If sets to true, y component of normal map value will invert (y = 1.0 - y).
  148. */
  149. _this._invertNormalMapY = false;
  150. /**
  151. * If sets to true and backfaceCulling is false, normals will be flipped on the backside.
  152. */
  153. _this._twoSidedLighting = false;
  154. _this._renderTargets = new BABYLON.SmartArray(16);
  155. _this._worldViewProjectionMatrix = BABYLON.Matrix.Zero();
  156. _this._globalAmbientColor = new BABYLON.Color3(0, 0, 0);
  157. // Setup the default processing configuration to the scene.
  158. _this._attachImageProcessingConfiguration(null);
  159. _this.getRenderTargetTextures = function () {
  160. _this._renderTargets.reset();
  161. if (StandardMaterial_OldVer.ReflectionTextureEnabled && _this._reflectionTexture && _this._reflectionTexture.isRenderTarget) {
  162. _this._renderTargets.push(_this._reflectionTexture);
  163. }
  164. if (StandardMaterial_OldVer.RefractionTextureEnabled && _this._refractionTexture && _this._refractionTexture.isRenderTarget) {
  165. _this._renderTargets.push(_this._refractionTexture);
  166. }
  167. return _this._renderTargets;
  168. };
  169. return _this;
  170. }
  171. Object.defineProperty(StandardMaterial_OldVer.prototype, "imageProcessingConfiguration", {
  172. /**
  173. * Gets the image processing configuration used either in this material.
  174. */
  175. get: function () {
  176. return this._imageProcessingConfiguration;
  177. },
  178. /**
  179. * Sets the Default image processing configuration used either in the this material.
  180. *
  181. * If sets to null, the scene one is in use.
  182. */
  183. set: function (value) {
  184. this._attachImageProcessingConfiguration(value);
  185. // Ensure the effect will be rebuilt.
  186. this._markAllSubMeshesAsTexturesDirty();
  187. },
  188. enumerable: true,
  189. configurable: true
  190. });
  191. /**
  192. * Attaches a new image processing configuration to the Standard Material.
  193. * @param configuration
  194. */
  195. StandardMaterial_OldVer.prototype._attachImageProcessingConfiguration = function (configuration) {
  196. var _this = this;
  197. if (configuration === this._imageProcessingConfiguration) {
  198. return;
  199. }
  200. // Detaches observer.
  201. if (this._imageProcessingConfiguration && this._imageProcessingObserver) {
  202. this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);
  203. }
  204. // Pick the scene configuration if needed.
  205. if (!configuration) {
  206. this._imageProcessingConfiguration = this.getScene().imageProcessingConfiguration;
  207. }
  208. else {
  209. this._imageProcessingConfiguration = configuration;
  210. }
  211. // Attaches observer.
  212. this._imageProcessingObserver = this._imageProcessingConfiguration.onUpdateParameters.add(function (conf) {
  213. _this._markAllSubMeshesAsImageProcessingDirty();
  214. });
  215. };
  216. Object.defineProperty(StandardMaterial_OldVer.prototype, "cameraColorCurvesEnabled", {
  217. /**
  218. * Gets wether the color curves effect is enabled.
  219. */
  220. get: function () {
  221. return this.imageProcessingConfiguration.colorCurvesEnabled;
  222. },
  223. /**
  224. * Sets wether the color curves effect is enabled.
  225. */
  226. set: function (value) {
  227. this.imageProcessingConfiguration.colorCurvesEnabled = value;
  228. },
  229. enumerable: true,
  230. configurable: true
  231. });
  232. Object.defineProperty(StandardMaterial_OldVer.prototype, "cameraColorGradingEnabled", {
  233. /**
  234. * Gets wether the color grading effect is enabled.
  235. */
  236. get: function () {
  237. return this.imageProcessingConfiguration.colorGradingEnabled;
  238. },
  239. /**
  240. * Gets wether the color grading effect is enabled.
  241. */
  242. set: function (value) {
  243. this.imageProcessingConfiguration.colorGradingEnabled = value;
  244. },
  245. enumerable: true,
  246. configurable: true
  247. });
  248. Object.defineProperty(StandardMaterial_OldVer.prototype, "cameraToneMappingEnabled", {
  249. /**
  250. * Gets wether tonemapping is enabled or not.
  251. */
  252. get: function () {
  253. return this._imageProcessingConfiguration.toneMappingEnabled;
  254. },
  255. /**
  256. * Sets wether tonemapping is enabled or not
  257. */
  258. set: function (value) {
  259. this._imageProcessingConfiguration.toneMappingEnabled = value;
  260. },
  261. enumerable: true,
  262. configurable: true
  263. });
  264. ;
  265. ;
  266. Object.defineProperty(StandardMaterial_OldVer.prototype, "cameraExposure", {
  267. /**
  268. * The camera exposure used on this material.
  269. * This property is here and not in the camera to allow controlling exposure without full screen post process.
  270. * This corresponds to a photographic exposure.
  271. */
  272. get: function () {
  273. return this._imageProcessingConfiguration.exposure;
  274. },
  275. /**
  276. * The camera exposure used on this material.
  277. * This property is here and not in the camera to allow controlling exposure without full screen post process.
  278. * This corresponds to a photographic exposure.
  279. */
  280. set: function (value) {
  281. this._imageProcessingConfiguration.exposure = value;
  282. },
  283. enumerable: true,
  284. configurable: true
  285. });
  286. ;
  287. ;
  288. Object.defineProperty(StandardMaterial_OldVer.prototype, "cameraContrast", {
  289. /**
  290. * Gets The camera contrast used on this material.
  291. */
  292. get: function () {
  293. return this._imageProcessingConfiguration.contrast;
  294. },
  295. /**
  296. * Sets The camera contrast used on this material.
  297. */
  298. set: function (value) {
  299. this._imageProcessingConfiguration.contrast = value;
  300. },
  301. enumerable: true,
  302. configurable: true
  303. });
  304. Object.defineProperty(StandardMaterial_OldVer.prototype, "cameraColorGradingTexture", {
  305. /**
  306. * Gets the Color Grading 2D Lookup Texture.
  307. */
  308. get: function () {
  309. return this._imageProcessingConfiguration.colorGradingTexture;
  310. },
  311. /**
  312. * Sets the Color Grading 2D Lookup Texture.
  313. */
  314. set: function (value) {
  315. this._imageProcessingConfiguration.colorGradingTexture = value;
  316. },
  317. enumerable: true,
  318. configurable: true
  319. });
  320. StandardMaterial_OldVer.prototype.getClassName = function () {
  321. return "StandardMaterial_OldVer";
  322. };
  323. Object.defineProperty(StandardMaterial_OldVer.prototype, "useLogarithmicDepth", {
  324. get: function () {
  325. return this._useLogarithmicDepth;
  326. },
  327. set: function (value) {
  328. this._useLogarithmicDepth = value && this.getScene().getEngine().getCaps().fragmentDepthSupported;
  329. this._markAllSubMeshesAsMiscDirty();
  330. },
  331. enumerable: true,
  332. configurable: true
  333. });
  334. StandardMaterial_OldVer.prototype.needAlphaBlending = function () {
  335. return (this.alpha < 1.0) || (this._opacityTexture != null) || this._shouldUseAlphaFromDiffuseTexture() || this._opacityFresnelParameters && this._opacityFresnelParameters.isEnabled;
  336. };
  337. StandardMaterial_OldVer.prototype.needAlphaTesting = function () {
  338. return this._diffuseTexture != null && this._diffuseTexture.hasAlpha;
  339. };
  340. StandardMaterial_OldVer.prototype._shouldUseAlphaFromDiffuseTexture = function () {
  341. return this._diffuseTexture != null && this._diffuseTexture.hasAlpha && this._useAlphaFromDiffuseTexture;
  342. };
  343. StandardMaterial_OldVer.prototype.getAlphaTestTexture = function () {
  344. return this._diffuseTexture;
  345. };
  346. /**
  347. * Child classes can use it to update shaders
  348. */
  349. StandardMaterial_OldVer.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  350. if (this.isFrozen) {
  351. if (this._wasPreviouslyReady && subMesh.effect) {
  352. return true;
  353. }
  354. }
  355. if (!subMesh._materialDefines) {
  356. subMesh._materialDefines = new StandardMaterialDefines_OldVer();
  357. }
  358. var scene = this.getScene();
  359. var defines = subMesh._materialDefines;
  360. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  361. if (defines._renderId === scene.getRenderId()) {
  362. return true;
  363. }
  364. }
  365. var engine = scene.getEngine();
  366. // Lights
  367. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, true, this._maxSimultaneousLights, this._disableLighting);
  368. // Textures
  369. if (defines._areTexturesDirty) {
  370. defines._needUVs = false;
  371. if (scene.texturesEnabled) {
  372. if (this._diffuseTexture && StandardMaterial_OldVer.DiffuseTextureEnabled) {
  373. if (!this._diffuseTexture.isReadyOrNotBlocking()) {
  374. return false;
  375. }
  376. else {
  377. defines._needUVs = true;
  378. defines.DIFFUSE = true;
  379. }
  380. }
  381. else {
  382. defines.DIFFUSE = false;
  383. }
  384. if (this._ambientTexture && StandardMaterial_OldVer.AmbientTextureEnabled) {
  385. if (!this._ambientTexture.isReadyOrNotBlocking()) {
  386. return false;
  387. }
  388. else {
  389. defines._needUVs = true;
  390. defines.AMBIENT = true;
  391. }
  392. }
  393. else {
  394. defines.AMBIENT = false;
  395. }
  396. if (this._opacityTexture && StandardMaterial_OldVer.OpacityTextureEnabled) {
  397. if (!this._opacityTexture.isReadyOrNotBlocking()) {
  398. return false;
  399. }
  400. else {
  401. defines._needUVs = true;
  402. defines.OPACITY = true;
  403. defines.OPACITYRGB = this._opacityTexture.getAlphaFromRGB;
  404. }
  405. }
  406. else {
  407. defines.OPACITY = false;
  408. }
  409. if (this._reflectionTexture && StandardMaterial_OldVer.ReflectionTextureEnabled) {
  410. if (!this._reflectionTexture.isReadyOrNotBlocking()) {
  411. return false;
  412. }
  413. else {
  414. defines._needNormals = true;
  415. defines.REFLECTION = true;
  416. defines.ROUGHNESS = (this._roughness > 0);
  417. defines.REFLECTIONOVERALPHA = this._useReflectionOverAlpha;
  418. defines.INVERTCUBICMAP = (this._reflectionTexture.coordinatesMode === BABYLON.Texture.INVCUBIC_MODE);
  419. defines.REFLECTIONMAP_3D = this._reflectionTexture.isCube;
  420. switch (this._reflectionTexture.coordinatesMode) {
  421. case BABYLON.Texture.CUBIC_MODE:
  422. case BABYLON.Texture.INVCUBIC_MODE:
  423. defines.setReflectionMode("REFLECTIONMAP_CUBIC");
  424. break;
  425. case BABYLON.Texture.EXPLICIT_MODE:
  426. defines.setReflectionMode("REFLECTIONMAP_EXPLICIT");
  427. break;
  428. case BABYLON.Texture.PLANAR_MODE:
  429. defines.setReflectionMode("REFLECTIONMAP_PLANAR");
  430. break;
  431. case BABYLON.Texture.PROJECTION_MODE:
  432. defines.setReflectionMode("REFLECTIONMAP_PROJECTION");
  433. break;
  434. case BABYLON.Texture.SKYBOX_MODE:
  435. defines.setReflectionMode("REFLECTIONMAP_SKYBOX");
  436. break;
  437. case BABYLON.Texture.SPHERICAL_MODE:
  438. defines.setReflectionMode("REFLECTIONMAP_SPHERICAL");
  439. break;
  440. case BABYLON.Texture.EQUIRECTANGULAR_MODE:
  441. defines.setReflectionMode("REFLECTIONMAP_EQUIRECTANGULAR");
  442. break;
  443. case BABYLON.Texture.FIXED_EQUIRECTANGULAR_MODE:
  444. defines.setReflectionMode("REFLECTIONMAP_EQUIRECTANGULAR_FIXED");
  445. break;
  446. case BABYLON.Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE:
  447. defines.setReflectionMode("REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED");
  448. break;
  449. }
  450. }
  451. }
  452. else {
  453. defines.REFLECTION = false;
  454. }
  455. if (this._emissiveTexture && StandardMaterial_OldVer.EmissiveTextureEnabled) {
  456. if (!this._emissiveTexture.isReadyOrNotBlocking()) {
  457. return false;
  458. }
  459. else {
  460. defines._needUVs = true;
  461. defines.EMISSIVE = true;
  462. }
  463. }
  464. else {
  465. defines.EMISSIVE = false;
  466. }
  467. if (this._lightmapTexture && StandardMaterial_OldVer.LightmapTextureEnabled) {
  468. if (!this._lightmapTexture.isReadyOrNotBlocking()) {
  469. return false;
  470. }
  471. else {
  472. defines._needUVs = true;
  473. defines.LIGHTMAP = true;
  474. defines.USELIGHTMAPASSHADOWMAP = this._useLightmapAsShadowmap;
  475. }
  476. }
  477. else {
  478. defines.LIGHTMAP = false;
  479. }
  480. if (this._specularTexture && StandardMaterial_OldVer.SpecularTextureEnabled) {
  481. if (!this._specularTexture.isReadyOrNotBlocking()) {
  482. return false;
  483. }
  484. else {
  485. defines._needUVs = true;
  486. defines.SPECULAR = true;
  487. defines.GLOSSINESS = this._useGlossinessFromSpecularMapAlpha;
  488. }
  489. }
  490. else {
  491. defines.SPECULAR = false;
  492. }
  493. if (scene.getEngine().getCaps().standardDerivatives && this._bumpTexture && StandardMaterial_OldVer.BumpTextureEnabled) {
  494. // Bump texure can not be not blocking.
  495. if (!this._bumpTexture.isReady()) {
  496. return false;
  497. }
  498. else {
  499. defines._needUVs = true;
  500. defines.BUMP = true;
  501. defines.INVERTNORMALMAPX = this.invertNormalMapX;
  502. defines.INVERTNORMALMAPY = this.invertNormalMapY;
  503. defines.PARALLAX = this._useParallax;
  504. defines.PARALLAXOCCLUSION = this._useParallaxOcclusion;
  505. }
  506. }
  507. else {
  508. defines.BUMP = false;
  509. }
  510. if (this._refractionTexture && StandardMaterial_OldVer.RefractionTextureEnabled) {
  511. if (!this._refractionTexture.isReadyOrNotBlocking()) {
  512. return false;
  513. }
  514. else {
  515. defines._needUVs = true;
  516. defines.REFRACTION = true;
  517. defines.REFRACTIONMAP_3D = this._refractionTexture.isCube;
  518. }
  519. }
  520. else {
  521. defines.REFRACTION = false;
  522. }
  523. defines.TWOSIDEDLIGHTING = !this._backFaceCulling && this._twoSidedLighting;
  524. }
  525. else {
  526. defines.DIFFUSE = false;
  527. defines.AMBIENT = false;
  528. defines.OPACITY = false;
  529. defines.REFLECTION = false;
  530. defines.EMISSIVE = false;
  531. defines.LIGHTMAP = false;
  532. defines.BUMP = false;
  533. defines.REFRACTION = false;
  534. }
  535. defines.ALPHAFROMDIFFUSE = this._shouldUseAlphaFromDiffuseTexture();
  536. defines.EMISSIVEASILLUMINATION = this._useEmissiveAsIllumination;
  537. defines.LINKEMISSIVEWITHDIFFUSE = this._linkEmissiveWithDiffuse;
  538. defines.SPECULAROVERALPHA = this._useSpecularOverAlpha;
  539. }
  540. if (defines._areImageProcessingDirty) {
  541. if (!this._imageProcessingConfiguration.isReady()) {
  542. return false;
  543. }
  544. this._imageProcessingConfiguration.prepareDefines(defines);
  545. }
  546. if (defines._areFresnelDirty) {
  547. if (StandardMaterial_OldVer.FresnelEnabled) {
  548. // Fresnel
  549. if (this._diffuseFresnelParameters || this._opacityFresnelParameters ||
  550. this._emissiveFresnelParameters || this._refractionFresnelParameters ||
  551. this._reflectionFresnelParameters) {
  552. defines.DIFFUSEFRESNEL = (this._diffuseFresnelParameters && this._diffuseFresnelParameters.isEnabled);
  553. defines.OPACITYFRESNEL = (this._opacityFresnelParameters && this._opacityFresnelParameters.isEnabled);
  554. defines.REFLECTIONFRESNEL = (this._reflectionFresnelParameters && this._reflectionFresnelParameters.isEnabled);
  555. defines.REFLECTIONFRESNELFROMSPECULAR = this._useReflectionFresnelFromSpecular;
  556. defines.REFRACTIONFRESNEL = (this._refractionFresnelParameters && this._refractionFresnelParameters.isEnabled);
  557. defines.EMISSIVEFRESNEL = (this._emissiveFresnelParameters && this._emissiveFresnelParameters.isEnabled);
  558. defines._needNormals = true;
  559. defines.FRESNEL = true;
  560. }
  561. }
  562. else {
  563. defines.FRESNEL = false;
  564. }
  565. }
  566. // Misc.
  567. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, defines);
  568. // Attribs
  569. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true, true);
  570. // Values that need to be evaluated on every frame
  571. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
  572. if (scene._mirroredCameraPosition && defines.BUMP) {
  573. defines.INVERTNORMALMAPX = !this.invertNormalMapX;
  574. defines.INVERTNORMALMAPY = !this.invertNormalMapY;
  575. defines.markAsUnprocessed();
  576. }
  577. // Get correct effect
  578. if (defines.isDirty) {
  579. defines.markAsProcessed();
  580. scene.resetCachedMaterial();
  581. // Fallbacks
  582. var fallbacks = new BABYLON.EffectFallbacks();
  583. if (defines.REFLECTION) {
  584. fallbacks.addFallback(0, "REFLECTION");
  585. }
  586. if (defines.SPECULAR) {
  587. fallbacks.addFallback(0, "SPECULAR");
  588. }
  589. if (defines.BUMP) {
  590. fallbacks.addFallback(0, "BUMP");
  591. }
  592. if (defines.PARALLAX) {
  593. fallbacks.addFallback(1, "PARALLAX");
  594. }
  595. if (defines.PARALLAXOCCLUSION) {
  596. fallbacks.addFallback(0, "PARALLAXOCCLUSION");
  597. }
  598. if (defines.SPECULAROVERALPHA) {
  599. fallbacks.addFallback(0, "SPECULAROVERALPHA");
  600. }
  601. if (defines.FOG) {
  602. fallbacks.addFallback(1, "FOG");
  603. }
  604. if (defines.POINTSIZE) {
  605. fallbacks.addFallback(0, "POINTSIZE");
  606. }
  607. if (defines.LOGARITHMICDEPTH) {
  608. fallbacks.addFallback(0, "LOGARITHMICDEPTH");
  609. }
  610. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this._maxSimultaneousLights);
  611. if (defines.SPECULARTERM) {
  612. fallbacks.addFallback(0, "SPECULARTERM");
  613. }
  614. if (defines.DIFFUSEFRESNEL) {
  615. fallbacks.addFallback(1, "DIFFUSEFRESNEL");
  616. }
  617. if (defines.OPACITYFRESNEL) {
  618. fallbacks.addFallback(2, "OPACITYFRESNEL");
  619. }
  620. if (defines.REFLECTIONFRESNEL) {
  621. fallbacks.addFallback(3, "REFLECTIONFRESNEL");
  622. }
  623. if (defines.EMISSIVEFRESNEL) {
  624. fallbacks.addFallback(4, "EMISSIVEFRESNEL");
  625. }
  626. if (defines.FRESNEL) {
  627. fallbacks.addFallback(4, "FRESNEL");
  628. }
  629. //Attributes
  630. var attribs = [BABYLON.VertexBuffer.PositionKind];
  631. if (defines.NORMAL) {
  632. attribs.push(BABYLON.VertexBuffer.NormalKind);
  633. }
  634. if (defines.UV1) {
  635. attribs.push(BABYLON.VertexBuffer.UVKind);
  636. }
  637. if (defines.UV2) {
  638. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  639. }
  640. if (defines.VERTEXCOLOR) {
  641. attribs.push(BABYLON.VertexBuffer.ColorKind);
  642. }
  643. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  644. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  645. BABYLON.MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, defines);
  646. var shaderName = "default";
  647. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vDiffuseColor", "vSpecularColor", "vEmissiveColor",
  648. "vFogInfos", "vFogColor", "pointSize",
  649. "vDiffuseInfos", "vAmbientInfos", "vOpacityInfos", "vReflectionInfos", "vEmissiveInfos", "vSpecularInfos", "vBumpInfos", "vLightmapInfos", "vRefractionInfos",
  650. "mBones",
  651. "vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix", "lightmapMatrix", "refractionMatrix",
  652. "diffuseLeftColor", "diffuseRightColor", "opacityParts", "reflectionLeftColor", "reflectionRightColor", "emissiveLeftColor", "emissiveRightColor", "refractionLeftColor", "refractionRightColor",
  653. "logarithmicDepthConstant"
  654. ];
  655. var samplers = ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"];
  656. var uniformBuffers = ["Material", "Scene"];
  657. BABYLON.ImageProcessingConfiguration.PrepareUniforms(uniforms, defines);
  658. BABYLON.ImageProcessingConfiguration.PrepareSamplers(samplers, defines);
  659. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  660. uniformsNames: uniforms,
  661. uniformBuffersNames: uniformBuffers,
  662. samplers: samplers,
  663. defines: defines,
  664. maxSimultaneousLights: this._maxSimultaneousLights
  665. });
  666. if (this.customShaderNameResolve) {
  667. shaderName = this.customShaderNameResolve(shaderName, uniforms, uniformBuffers, samplers, defines);
  668. }
  669. var join = defines.toString();
  670. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  671. attributes: attribs,
  672. uniformsNames: uniforms,
  673. uniformBuffersNames: uniformBuffers,
  674. samplers: samplers,
  675. defines: join,
  676. fallbacks: fallbacks,
  677. onCompiled: this.onCompiled,
  678. onError: this.onError,
  679. indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights, maxSimultaneousMorphTargets: defines.NUM_MORPH_INFLUENCERS }
  680. }, engine), defines);
  681. this.buildUniformLayout();
  682. }
  683. if (!subMesh.effect.isReady()) {
  684. return false;
  685. }
  686. defines._renderId = scene.getRenderId();
  687. this._wasPreviouslyReady = true;
  688. return true;
  689. };
  690. StandardMaterial_OldVer.prototype.buildUniformLayout = function () {
  691. // Order is important !
  692. this._uniformBuffer.addUniform("diffuseLeftColor", 4);
  693. this._uniformBuffer.addUniform("diffuseRightColor", 4);
  694. this._uniformBuffer.addUniform("opacityParts", 4);
  695. this._uniformBuffer.addUniform("reflectionLeftColor", 4);
  696. this._uniformBuffer.addUniform("reflectionRightColor", 4);
  697. this._uniformBuffer.addUniform("refractionLeftColor", 4);
  698. this._uniformBuffer.addUniform("refractionRightColor", 4);
  699. this._uniformBuffer.addUniform("emissiveLeftColor", 4);
  700. this._uniformBuffer.addUniform("emissiveRightColor", 4);
  701. this._uniformBuffer.addUniform("vDiffuseInfos", 2);
  702. this._uniformBuffer.addUniform("vAmbientInfos", 2);
  703. this._uniformBuffer.addUniform("vOpacityInfos", 2);
  704. this._uniformBuffer.addUniform("vReflectionInfos", 2);
  705. this._uniformBuffer.addUniform("vEmissiveInfos", 2);
  706. this._uniformBuffer.addUniform("vLightmapInfos", 2);
  707. this._uniformBuffer.addUniform("vSpecularInfos", 2);
  708. this._uniformBuffer.addUniform("vBumpInfos", 3);
  709. this._uniformBuffer.addUniform("diffuseMatrix", 16);
  710. this._uniformBuffer.addUniform("ambientMatrix", 16);
  711. this._uniformBuffer.addUniform("opacityMatrix", 16);
  712. this._uniformBuffer.addUniform("reflectionMatrix", 16);
  713. this._uniformBuffer.addUniform("emissiveMatrix", 16);
  714. this._uniformBuffer.addUniform("lightmapMatrix", 16);
  715. this._uniformBuffer.addUniform("specularMatrix", 16);
  716. this._uniformBuffer.addUniform("bumpMatrix", 16);
  717. this._uniformBuffer.addUniform("refractionMatrix", 16);
  718. this._uniformBuffer.addUniform("vRefractionInfos", 4);
  719. this._uniformBuffer.addUniform("vSpecularColor", 4);
  720. this._uniformBuffer.addUniform("vEmissiveColor", 3);
  721. this._uniformBuffer.addUniform("vDiffuseColor", 4);
  722. this._uniformBuffer.addUniform("pointSize", 1);
  723. this._uniformBuffer.create();
  724. };
  725. StandardMaterial_OldVer.prototype.unbind = function () {
  726. if (this._activeEffect) {
  727. if (this._reflectionTexture && this._reflectionTexture.isRenderTarget) {
  728. this._activeEffect.setTexture("reflection2DSampler", null);
  729. }
  730. if (this._refractionTexture && this._refractionTexture.isRenderTarget) {
  731. this._activeEffect.setTexture("refraction2DSampler", null);
  732. }
  733. }
  734. _super.prototype.unbind.call(this);
  735. };
  736. StandardMaterial_OldVer.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  737. var scene = this.getScene();
  738. var defines = subMesh._materialDefines;
  739. if (!defines) {
  740. return;
  741. }
  742. var effect = subMesh.effect;
  743. this._activeEffect = effect;
  744. // Matrices
  745. this.bindOnlyWorldMatrix(world);
  746. // Bones
  747. BABYLON.MaterialHelper.BindBonesParameters(mesh, effect);
  748. if (this._mustRebind(scene, effect, mesh.visibility)) {
  749. this._uniformBuffer.bindToEffect(effect, "Material");
  750. this.bindViewProjection(effect);
  751. if (!this._uniformBuffer.useUbo || !this.isFrozen || !this._uniformBuffer.isSync) {
  752. if (StandardMaterial_OldVer.FresnelEnabled && defines.FRESNEL) {
  753. // Fresnel
  754. if (this.diffuseFresnelParameters && this.diffuseFresnelParameters.isEnabled) {
  755. this._uniformBuffer.updateColor4("diffuseLeftColor", this.diffuseFresnelParameters.leftColor, this.diffuseFresnelParameters.power);
  756. this._uniformBuffer.updateColor4("diffuseRightColor", this.diffuseFresnelParameters.rightColor, this.diffuseFresnelParameters.bias);
  757. }
  758. if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled) {
  759. this._uniformBuffer.updateColor4("opacityParts", new BABYLON.Color3(this.opacityFresnelParameters.leftColor.toLuminance(), this.opacityFresnelParameters.rightColor.toLuminance(), this.opacityFresnelParameters.bias), this.opacityFresnelParameters.power);
  760. }
  761. if (this.reflectionFresnelParameters && this.reflectionFresnelParameters.isEnabled) {
  762. this._uniformBuffer.updateColor4("reflectionLeftColor", this.reflectionFresnelParameters.leftColor, this.reflectionFresnelParameters.power);
  763. this._uniformBuffer.updateColor4("reflectionRightColor", this.reflectionFresnelParameters.rightColor, this.reflectionFresnelParameters.bias);
  764. }
  765. if (this.refractionFresnelParameters && this.refractionFresnelParameters.isEnabled) {
  766. this._uniformBuffer.updateColor4("refractionLeftColor", this.refractionFresnelParameters.leftColor, this.refractionFresnelParameters.power);
  767. this._uniformBuffer.updateColor4("refractionRightColor", this.refractionFresnelParameters.rightColor, this.refractionFresnelParameters.bias);
  768. }
  769. if (this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {
  770. this._uniformBuffer.updateColor4("emissiveLeftColor", this.emissiveFresnelParameters.leftColor, this.emissiveFresnelParameters.power);
  771. this._uniformBuffer.updateColor4("emissiveRightColor", this.emissiveFresnelParameters.rightColor, this.emissiveFresnelParameters.bias);
  772. }
  773. }
  774. // Textures
  775. if (scene.texturesEnabled) {
  776. if (this._diffuseTexture && StandardMaterial_OldVer.DiffuseTextureEnabled) {
  777. this._uniformBuffer.updateFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  778. this._uniformBuffer.updateMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  779. }
  780. if (this._ambientTexture && StandardMaterial_OldVer.AmbientTextureEnabled) {
  781. this._uniformBuffer.updateFloat2("vAmbientInfos", this._ambientTexture.coordinatesIndex, this._ambientTexture.level);
  782. this._uniformBuffer.updateMatrix("ambientMatrix", this._ambientTexture.getTextureMatrix());
  783. }
  784. if (this._opacityTexture && StandardMaterial_OldVer.OpacityTextureEnabled) {
  785. this._uniformBuffer.updateFloat2("vOpacityInfos", this._opacityTexture.coordinatesIndex, this._opacityTexture.level);
  786. this._uniformBuffer.updateMatrix("opacityMatrix", this._opacityTexture.getTextureMatrix());
  787. }
  788. if (this._reflectionTexture && StandardMaterial_OldVer.ReflectionTextureEnabled) {
  789. this._uniformBuffer.updateFloat2("vReflectionInfos", this._reflectionTexture.level, this.roughness);
  790. this._uniformBuffer.updateMatrix("reflectionMatrix", this._reflectionTexture.getReflectionTextureMatrix());
  791. }
  792. if (this._emissiveTexture && StandardMaterial_OldVer.EmissiveTextureEnabled) {
  793. this._uniformBuffer.updateFloat2("vEmissiveInfos", this._emissiveTexture.coordinatesIndex, this._emissiveTexture.level);
  794. this._uniformBuffer.updateMatrix("emissiveMatrix", this._emissiveTexture.getTextureMatrix());
  795. }
  796. if (this._lightmapTexture && StandardMaterial_OldVer.LightmapTextureEnabled) {
  797. this._uniformBuffer.updateFloat2("vLightmapInfos", this._lightmapTexture.coordinatesIndex, this._lightmapTexture.level);
  798. this._uniformBuffer.updateMatrix("lightmapMatrix", this._lightmapTexture.getTextureMatrix());
  799. }
  800. if (this._specularTexture && StandardMaterial_OldVer.SpecularTextureEnabled) {
  801. this._uniformBuffer.updateFloat2("vSpecularInfos", this._specularTexture.coordinatesIndex, this._specularTexture.level);
  802. this._uniformBuffer.updateMatrix("specularMatrix", this._specularTexture.getTextureMatrix());
  803. }
  804. if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial_OldVer.BumpTextureEnabled) {
  805. this._uniformBuffer.updateFloat3("vBumpInfos", this._bumpTexture.coordinatesIndex, 1.0 / this._bumpTexture.level, this.parallaxScaleBias);
  806. this._uniformBuffer.updateMatrix("bumpMatrix", this._bumpTexture.getTextureMatrix());
  807. }
  808. if (this._refractionTexture && StandardMaterial_OldVer.RefractionTextureEnabled) {
  809. var depth = 1.0;
  810. if (!this._refractionTexture.isCube) {
  811. this._uniformBuffer.updateMatrix("refractionMatrix", this._refractionTexture.getReflectionTextureMatrix());
  812. if (this._refractionTexture.depth) {
  813. depth = this._refractionTexture.depth;
  814. }
  815. }
  816. this._uniformBuffer.updateFloat4("vRefractionInfos", this._refractionTexture.level, this.indexOfRefraction, depth, this.invertRefractionY ? -1 : 1);
  817. }
  818. }
  819. // Point size
  820. if (this.pointsCloud) {
  821. this._uniformBuffer.updateFloat("pointSize", this.pointSize);
  822. }
  823. if (defines.SPECULARTERM) {
  824. this._uniformBuffer.updateColor4("vSpecularColor", this.specularColor, this.specularPower);
  825. }
  826. this._uniformBuffer.updateColor3("vEmissiveColor", this.emissiveColor);
  827. // Diffuse
  828. this._uniformBuffer.updateColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  829. }
  830. // Textures
  831. if (scene.texturesEnabled) {
  832. if (this._diffuseTexture && StandardMaterial_OldVer.DiffuseTextureEnabled) {
  833. effect.setTexture("diffuseSampler", this._diffuseTexture);
  834. }
  835. if (this._ambientTexture && StandardMaterial_OldVer.AmbientTextureEnabled) {
  836. effect.setTexture("ambientSampler", this._ambientTexture);
  837. }
  838. if (this._opacityTexture && StandardMaterial_OldVer.OpacityTextureEnabled) {
  839. effect.setTexture("opacitySampler", this._opacityTexture);
  840. }
  841. if (this._reflectionTexture && StandardMaterial_OldVer.ReflectionTextureEnabled) {
  842. if (this._reflectionTexture.isCube) {
  843. effect.setTexture("reflectionCubeSampler", this._reflectionTexture);
  844. }
  845. else {
  846. effect.setTexture("reflection2DSampler", this._reflectionTexture);
  847. }
  848. }
  849. if (this._emissiveTexture && StandardMaterial_OldVer.EmissiveTextureEnabled) {
  850. effect.setTexture("emissiveSampler", this._emissiveTexture);
  851. }
  852. if (this._lightmapTexture && StandardMaterial_OldVer.LightmapTextureEnabled) {
  853. effect.setTexture("lightmapSampler", this._lightmapTexture);
  854. }
  855. if (this._specularTexture && StandardMaterial_OldVer.SpecularTextureEnabled) {
  856. effect.setTexture("specularSampler", this._specularTexture);
  857. }
  858. if (this._bumpTexture && scene.getEngine().getCaps().standardDerivatives && StandardMaterial_OldVer.BumpTextureEnabled) {
  859. effect.setTexture("bumpSampler", this._bumpTexture);
  860. }
  861. if (this._refractionTexture && StandardMaterial_OldVer.RefractionTextureEnabled) {
  862. var depth = 1.0;
  863. if (this._refractionTexture.isCube) {
  864. effect.setTexture("refractionCubeSampler", this._refractionTexture);
  865. }
  866. else {
  867. effect.setTexture("refraction2DSampler", this._refractionTexture);
  868. }
  869. }
  870. }
  871. // Clip plane
  872. BABYLON.MaterialHelper.BindClipPlane(effect, scene);
  873. // Colors
  874. scene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
  875. effect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
  876. effect.setColor3("vAmbientColor", this._globalAmbientColor);
  877. }
  878. if (this._mustRebind(scene, effect) || !this.isFrozen) {
  879. // Lights
  880. if (scene.lightsEnabled && !this._disableLighting) {
  881. BABYLON.MaterialHelper.BindLights(scene, mesh, effect, defines, this._maxSimultaneousLights);
  882. }
  883. // View
  884. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE || this._reflectionTexture || this._refractionTexture) {
  885. this.bindView(effect);
  886. }
  887. // Fog
  888. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, effect);
  889. // Morph targets
  890. if (defines.NUM_MORPH_INFLUENCERS) {
  891. BABYLON.MaterialHelper.BindMorphTargetParameters(mesh, effect);
  892. }
  893. // Log. depth
  894. BABYLON.MaterialHelper.BindLogDepth(defines, effect, scene);
  895. // image processing
  896. this._imageProcessingConfiguration.bind(this._activeEffect);
  897. }
  898. this._uniformBuffer.update();
  899. this._afterBind(mesh, this._activeEffect);
  900. };
  901. StandardMaterial_OldVer.prototype.getAnimatables = function () {
  902. var results = [];
  903. if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
  904. results.push(this._diffuseTexture);
  905. }
  906. if (this._ambientTexture && this._ambientTexture.animations && this._ambientTexture.animations.length > 0) {
  907. results.push(this._ambientTexture);
  908. }
  909. if (this._opacityTexture && this._opacityTexture.animations && this._opacityTexture.animations.length > 0) {
  910. results.push(this._opacityTexture);
  911. }
  912. if (this._reflectionTexture && this._reflectionTexture.animations && this._reflectionTexture.animations.length > 0) {
  913. results.push(this._reflectionTexture);
  914. }
  915. if (this._emissiveTexture && this._emissiveTexture.animations && this._emissiveTexture.animations.length > 0) {
  916. results.push(this._emissiveTexture);
  917. }
  918. if (this._specularTexture && this._specularTexture.animations && this._specularTexture.animations.length > 0) {
  919. results.push(this._specularTexture);
  920. }
  921. if (this._bumpTexture && this._bumpTexture.animations && this._bumpTexture.animations.length > 0) {
  922. results.push(this._bumpTexture);
  923. }
  924. if (this._lightmapTexture && this._lightmapTexture.animations && this._lightmapTexture.animations.length > 0) {
  925. results.push(this._lightmapTexture);
  926. }
  927. if (this._refractionTexture && this._refractionTexture.animations && this._refractionTexture.animations.length > 0) {
  928. results.push(this._refractionTexture);
  929. }
  930. return results;
  931. };
  932. StandardMaterial_OldVer.prototype.getActiveTextures = function () {
  933. var activeTextures = _super.prototype.getActiveTextures.call(this);
  934. if (this._diffuseTexture) {
  935. activeTextures.push(this._diffuseTexture);
  936. }
  937. if (this._ambientTexture) {
  938. activeTextures.push(this._ambientTexture);
  939. }
  940. if (this._opacityTexture) {
  941. activeTextures.push(this._opacityTexture);
  942. }
  943. if (this._reflectionTexture) {
  944. activeTextures.push(this._reflectionTexture);
  945. }
  946. if (this._emissiveTexture) {
  947. activeTextures.push(this._emissiveTexture);
  948. }
  949. if (this._specularTexture) {
  950. activeTextures.push(this._specularTexture);
  951. }
  952. if (this._bumpTexture) {
  953. activeTextures.push(this._bumpTexture);
  954. }
  955. if (this._lightmapTexture) {
  956. activeTextures.push(this._lightmapTexture);
  957. }
  958. if (this._refractionTexture) {
  959. activeTextures.push(this._refractionTexture);
  960. }
  961. return activeTextures;
  962. };
  963. StandardMaterial_OldVer.prototype.dispose = function (forceDisposeEffect, forceDisposeTextures) {
  964. if (forceDisposeTextures) {
  965. if (this._diffuseTexture) {
  966. this._diffuseTexture.dispose();
  967. }
  968. if (this._ambientTexture) {
  969. this._ambientTexture.dispose();
  970. }
  971. if (this._opacityTexture) {
  972. this._opacityTexture.dispose();
  973. }
  974. if (this._reflectionTexture) {
  975. this._reflectionTexture.dispose();
  976. }
  977. if (this._emissiveTexture) {
  978. this._emissiveTexture.dispose();
  979. }
  980. if (this._specularTexture) {
  981. this._specularTexture.dispose();
  982. }
  983. if (this._bumpTexture) {
  984. this._bumpTexture.dispose();
  985. }
  986. if (this._lightmapTexture) {
  987. this._lightmapTexture.dispose();
  988. }
  989. if (this._refractionTexture) {
  990. this._refractionTexture.dispose();
  991. }
  992. }
  993. if (this._imageProcessingConfiguration && this._imageProcessingObserver) {
  994. this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);
  995. }
  996. _super.prototype.dispose.call(this, forceDisposeEffect, forceDisposeTextures);
  997. };
  998. StandardMaterial_OldVer.prototype.clone = function (name) {
  999. var _this = this;
  1000. var result = BABYLON.SerializationHelper.Clone(function () { return new StandardMaterial_OldVer(name, _this.getScene()); }, this);
  1001. result.name = name;
  1002. result.id = name;
  1003. return result;
  1004. };
  1005. StandardMaterial_OldVer.prototype.serialize = function () {
  1006. return BABYLON.SerializationHelper.Serialize(this);
  1007. };
  1008. // Statics
  1009. StandardMaterial_OldVer.Parse = function (source, scene, rootUrl) {
  1010. return BABYLON.SerializationHelper.Parse(function () { return new StandardMaterial_OldVer(source.name, scene); }, source, scene, rootUrl);
  1011. };
  1012. Object.defineProperty(StandardMaterial_OldVer, "DiffuseTextureEnabled", {
  1013. get: function () {
  1014. return StandardMaterial_OldVer._DiffuseTextureEnabled;
  1015. },
  1016. set: function (value) {
  1017. if (StandardMaterial_OldVer._DiffuseTextureEnabled === value) {
  1018. return;
  1019. }
  1020. StandardMaterial_OldVer._DiffuseTextureEnabled = value;
  1021. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  1022. },
  1023. enumerable: true,
  1024. configurable: true
  1025. });
  1026. Object.defineProperty(StandardMaterial_OldVer, "AmbientTextureEnabled", {
  1027. get: function () {
  1028. return StandardMaterial_OldVer._AmbientTextureEnabled;
  1029. },
  1030. set: function (value) {
  1031. if (StandardMaterial_OldVer._AmbientTextureEnabled === value) {
  1032. return;
  1033. }
  1034. StandardMaterial_OldVer._AmbientTextureEnabled = value;
  1035. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  1036. },
  1037. enumerable: true,
  1038. configurable: true
  1039. });
  1040. Object.defineProperty(StandardMaterial_OldVer, "OpacityTextureEnabled", {
  1041. get: function () {
  1042. return StandardMaterial_OldVer._OpacityTextureEnabled;
  1043. },
  1044. set: function (value) {
  1045. if (StandardMaterial_OldVer._OpacityTextureEnabled === value) {
  1046. return;
  1047. }
  1048. StandardMaterial_OldVer._OpacityTextureEnabled = value;
  1049. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  1050. },
  1051. enumerable: true,
  1052. configurable: true
  1053. });
  1054. Object.defineProperty(StandardMaterial_OldVer, "ReflectionTextureEnabled", {
  1055. get: function () {
  1056. return StandardMaterial_OldVer._ReflectionTextureEnabled;
  1057. },
  1058. set: function (value) {
  1059. if (StandardMaterial_OldVer._ReflectionTextureEnabled === value) {
  1060. return;
  1061. }
  1062. StandardMaterial_OldVer._ReflectionTextureEnabled = value;
  1063. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  1064. },
  1065. enumerable: true,
  1066. configurable: true
  1067. });
  1068. Object.defineProperty(StandardMaterial_OldVer, "EmissiveTextureEnabled", {
  1069. get: function () {
  1070. return StandardMaterial_OldVer._EmissiveTextureEnabled;
  1071. },
  1072. set: function (value) {
  1073. if (StandardMaterial_OldVer._EmissiveTextureEnabled === value) {
  1074. return;
  1075. }
  1076. StandardMaterial_OldVer._EmissiveTextureEnabled = value;
  1077. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  1078. },
  1079. enumerable: true,
  1080. configurable: true
  1081. });
  1082. Object.defineProperty(StandardMaterial_OldVer, "SpecularTextureEnabled", {
  1083. get: function () {
  1084. return StandardMaterial_OldVer._SpecularTextureEnabled;
  1085. },
  1086. set: function (value) {
  1087. if (StandardMaterial_OldVer._SpecularTextureEnabled === value) {
  1088. return;
  1089. }
  1090. StandardMaterial_OldVer._SpecularTextureEnabled = value;
  1091. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  1092. },
  1093. enumerable: true,
  1094. configurable: true
  1095. });
  1096. Object.defineProperty(StandardMaterial_OldVer, "BumpTextureEnabled", {
  1097. get: function () {
  1098. return StandardMaterial_OldVer._BumpTextureEnabled;
  1099. },
  1100. set: function (value) {
  1101. if (StandardMaterial_OldVer._BumpTextureEnabled === value) {
  1102. return;
  1103. }
  1104. StandardMaterial_OldVer._BumpTextureEnabled = value;
  1105. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  1106. },
  1107. enumerable: true,
  1108. configurable: true
  1109. });
  1110. Object.defineProperty(StandardMaterial_OldVer, "LightmapTextureEnabled", {
  1111. get: function () {
  1112. return StandardMaterial_OldVer._LightmapTextureEnabled;
  1113. },
  1114. set: function (value) {
  1115. if (StandardMaterial_OldVer._LightmapTextureEnabled === value) {
  1116. return;
  1117. }
  1118. StandardMaterial_OldVer._LightmapTextureEnabled = value;
  1119. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  1120. },
  1121. enumerable: true,
  1122. configurable: true
  1123. });
  1124. Object.defineProperty(StandardMaterial_OldVer, "RefractionTextureEnabled", {
  1125. get: function () {
  1126. return StandardMaterial_OldVer._RefractionTextureEnabled;
  1127. },
  1128. set: function (value) {
  1129. if (StandardMaterial_OldVer._RefractionTextureEnabled === value) {
  1130. return;
  1131. }
  1132. StandardMaterial_OldVer._RefractionTextureEnabled = value;
  1133. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  1134. },
  1135. enumerable: true,
  1136. configurable: true
  1137. });
  1138. Object.defineProperty(StandardMaterial_OldVer, "ColorGradingTextureEnabled", {
  1139. get: function () {
  1140. return StandardMaterial_OldVer._ColorGradingTextureEnabled;
  1141. },
  1142. set: function (value) {
  1143. if (StandardMaterial_OldVer._ColorGradingTextureEnabled === value) {
  1144. return;
  1145. }
  1146. StandardMaterial_OldVer._ColorGradingTextureEnabled = value;
  1147. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.TextureDirtyFlag);
  1148. },
  1149. enumerable: true,
  1150. configurable: true
  1151. });
  1152. Object.defineProperty(StandardMaterial_OldVer, "FresnelEnabled", {
  1153. get: function () {
  1154. return StandardMaterial_OldVer._FresnelEnabled;
  1155. },
  1156. set: function (value) {
  1157. if (StandardMaterial_OldVer._FresnelEnabled === value) {
  1158. return;
  1159. }
  1160. StandardMaterial_OldVer._FresnelEnabled = value;
  1161. BABYLON.Engine.MarkAllMaterialsAsDirty(BABYLON.Material.FresnelDirtyFlag);
  1162. },
  1163. enumerable: true,
  1164. configurable: true
  1165. });
  1166. // Flags used to enable or disable a type of texture for all Standard Materials
  1167. StandardMaterial_OldVer._DiffuseTextureEnabled = true;
  1168. StandardMaterial_OldVer._AmbientTextureEnabled = true;
  1169. StandardMaterial_OldVer._OpacityTextureEnabled = true;
  1170. StandardMaterial_OldVer._ReflectionTextureEnabled = true;
  1171. StandardMaterial_OldVer._EmissiveTextureEnabled = true;
  1172. StandardMaterial_OldVer._SpecularTextureEnabled = true;
  1173. StandardMaterial_OldVer._BumpTextureEnabled = true;
  1174. StandardMaterial_OldVer._LightmapTextureEnabled = true;
  1175. StandardMaterial_OldVer._RefractionTextureEnabled = true;
  1176. StandardMaterial_OldVer._ColorGradingTextureEnabled = true;
  1177. StandardMaterial_OldVer._FresnelEnabled = true;
  1178. __decorate([
  1179. BABYLON.serializeAsTexture("diffuseTexture")
  1180. ], StandardMaterial_OldVer.prototype, "_diffuseTexture", void 0);
  1181. __decorate([
  1182. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1183. ], StandardMaterial_OldVer.prototype, "diffuseTexture", void 0);
  1184. __decorate([
  1185. BABYLON.serializeAsTexture("ambientTexture")
  1186. ], StandardMaterial_OldVer.prototype, "_ambientTexture", void 0);
  1187. __decorate([
  1188. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1189. ], StandardMaterial_OldVer.prototype, "ambientTexture", void 0);
  1190. __decorate([
  1191. BABYLON.serializeAsTexture("opacityTexture")
  1192. ], StandardMaterial_OldVer.prototype, "_opacityTexture", void 0);
  1193. __decorate([
  1194. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1195. ], StandardMaterial_OldVer.prototype, "opacityTexture", void 0);
  1196. __decorate([
  1197. BABYLON.serializeAsTexture("reflectionTexture")
  1198. ], StandardMaterial_OldVer.prototype, "_reflectionTexture", void 0);
  1199. __decorate([
  1200. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1201. ], StandardMaterial_OldVer.prototype, "reflectionTexture", void 0);
  1202. __decorate([
  1203. BABYLON.serializeAsTexture("emissiveTexture")
  1204. ], StandardMaterial_OldVer.prototype, "_emissiveTexture", void 0);
  1205. __decorate([
  1206. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1207. ], StandardMaterial_OldVer.prototype, "emissiveTexture", void 0);
  1208. __decorate([
  1209. BABYLON.serializeAsTexture("specularTexture")
  1210. ], StandardMaterial_OldVer.prototype, "_specularTexture", void 0);
  1211. __decorate([
  1212. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1213. ], StandardMaterial_OldVer.prototype, "specularTexture", void 0);
  1214. __decorate([
  1215. BABYLON.serializeAsTexture("bumpTexture")
  1216. ], StandardMaterial_OldVer.prototype, "_bumpTexture", void 0);
  1217. __decorate([
  1218. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1219. ], StandardMaterial_OldVer.prototype, "bumpTexture", void 0);
  1220. __decorate([
  1221. BABYLON.serializeAsTexture("lightmapTexture")
  1222. ], StandardMaterial_OldVer.prototype, "_lightmapTexture", void 0);
  1223. __decorate([
  1224. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1225. ], StandardMaterial_OldVer.prototype, "lightmapTexture", void 0);
  1226. __decorate([
  1227. BABYLON.serializeAsTexture("refractionTexture")
  1228. ], StandardMaterial_OldVer.prototype, "_refractionTexture", void 0);
  1229. __decorate([
  1230. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1231. ], StandardMaterial_OldVer.prototype, "refractionTexture", void 0);
  1232. __decorate([
  1233. BABYLON.serializeAsColor3("ambient")
  1234. ], StandardMaterial_OldVer.prototype, "ambientColor", void 0);
  1235. __decorate([
  1236. BABYLON.serializeAsColor3("diffuse")
  1237. ], StandardMaterial_OldVer.prototype, "diffuseColor", void 0);
  1238. __decorate([
  1239. BABYLON.serializeAsColor3("specular")
  1240. ], StandardMaterial_OldVer.prototype, "specularColor", void 0);
  1241. __decorate([
  1242. BABYLON.serializeAsColor3("emissive")
  1243. ], StandardMaterial_OldVer.prototype, "emissiveColor", void 0);
  1244. __decorate([
  1245. BABYLON.serialize()
  1246. ], StandardMaterial_OldVer.prototype, "specularPower", void 0);
  1247. __decorate([
  1248. BABYLON.serialize("useAlphaFromDiffuseTexture")
  1249. ], StandardMaterial_OldVer.prototype, "_useAlphaFromDiffuseTexture", void 0);
  1250. __decorate([
  1251. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1252. ], StandardMaterial_OldVer.prototype, "useAlphaFromDiffuseTexture", void 0);
  1253. __decorate([
  1254. BABYLON.serialize("useEmissiveAsIllumination")
  1255. ], StandardMaterial_OldVer.prototype, "_useEmissiveAsIllumination", void 0);
  1256. __decorate([
  1257. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1258. ], StandardMaterial_OldVer.prototype, "useEmissiveAsIllumination", void 0);
  1259. __decorate([
  1260. BABYLON.serialize("linkEmissiveWithDiffuse")
  1261. ], StandardMaterial_OldVer.prototype, "_linkEmissiveWithDiffuse", void 0);
  1262. __decorate([
  1263. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1264. ], StandardMaterial_OldVer.prototype, "linkEmissiveWithDiffuse", void 0);
  1265. __decorate([
  1266. BABYLON.serialize("useSpecularOverAlpha")
  1267. ], StandardMaterial_OldVer.prototype, "_useSpecularOverAlpha", void 0);
  1268. __decorate([
  1269. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1270. ], StandardMaterial_OldVer.prototype, "useSpecularOverAlpha", void 0);
  1271. __decorate([
  1272. BABYLON.serialize("useReflectionOverAlpha")
  1273. ], StandardMaterial_OldVer.prototype, "_useReflectionOverAlpha", void 0);
  1274. __decorate([
  1275. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1276. ], StandardMaterial_OldVer.prototype, "useReflectionOverAlpha", void 0);
  1277. __decorate([
  1278. BABYLON.serialize("disableLighting")
  1279. ], StandardMaterial_OldVer.prototype, "_disableLighting", void 0);
  1280. __decorate([
  1281. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1282. ], StandardMaterial_OldVer.prototype, "disableLighting", void 0);
  1283. __decorate([
  1284. BABYLON.serialize("useParallax")
  1285. ], StandardMaterial_OldVer.prototype, "_useParallax", void 0);
  1286. __decorate([
  1287. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1288. ], StandardMaterial_OldVer.prototype, "useParallax", void 0);
  1289. __decorate([
  1290. BABYLON.serialize("useParallaxOcclusion")
  1291. ], StandardMaterial_OldVer.prototype, "_useParallaxOcclusion", void 0);
  1292. __decorate([
  1293. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1294. ], StandardMaterial_OldVer.prototype, "useParallaxOcclusion", void 0);
  1295. __decorate([
  1296. BABYLON.serialize()
  1297. ], StandardMaterial_OldVer.prototype, "parallaxScaleBias", void 0);
  1298. __decorate([
  1299. BABYLON.serialize("roughness")
  1300. ], StandardMaterial_OldVer.prototype, "_roughness", void 0);
  1301. __decorate([
  1302. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1303. ], StandardMaterial_OldVer.prototype, "roughness", void 0);
  1304. __decorate([
  1305. BABYLON.serialize()
  1306. ], StandardMaterial_OldVer.prototype, "indexOfRefraction", void 0);
  1307. __decorate([
  1308. BABYLON.serialize()
  1309. ], StandardMaterial_OldVer.prototype, "invertRefractionY", void 0);
  1310. __decorate([
  1311. BABYLON.serialize("useLightmapAsShadowmap")
  1312. ], StandardMaterial_OldVer.prototype, "_useLightmapAsShadowmap", void 0);
  1313. __decorate([
  1314. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1315. ], StandardMaterial_OldVer.prototype, "useLightmapAsShadowmap", void 0);
  1316. __decorate([
  1317. BABYLON.serializeAsFresnelParameters("diffuseFresnelParameters")
  1318. ], StandardMaterial_OldVer.prototype, "_diffuseFresnelParameters", void 0);
  1319. __decorate([
  1320. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  1321. ], StandardMaterial_OldVer.prototype, "diffuseFresnelParameters", void 0);
  1322. __decorate([
  1323. BABYLON.serializeAsFresnelParameters("opacityFresnelParameters")
  1324. ], StandardMaterial_OldVer.prototype, "_opacityFresnelParameters", void 0);
  1325. __decorate([
  1326. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  1327. ], StandardMaterial_OldVer.prototype, "opacityFresnelParameters", void 0);
  1328. __decorate([
  1329. BABYLON.serializeAsFresnelParameters("reflectionFresnelParameters")
  1330. ], StandardMaterial_OldVer.prototype, "_reflectionFresnelParameters", void 0);
  1331. __decorate([
  1332. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  1333. ], StandardMaterial_OldVer.prototype, "reflectionFresnelParameters", void 0);
  1334. __decorate([
  1335. BABYLON.serializeAsFresnelParameters("refractionFresnelParameters")
  1336. ], StandardMaterial_OldVer.prototype, "_refractionFresnelParameters", void 0);
  1337. __decorate([
  1338. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  1339. ], StandardMaterial_OldVer.prototype, "refractionFresnelParameters", void 0);
  1340. __decorate([
  1341. BABYLON.serializeAsFresnelParameters("emissiveFresnelParameters")
  1342. ], StandardMaterial_OldVer.prototype, "_emissiveFresnelParameters", void 0);
  1343. __decorate([
  1344. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  1345. ], StandardMaterial_OldVer.prototype, "emissiveFresnelParameters", void 0);
  1346. __decorate([
  1347. BABYLON.serialize("useReflectionFresnelFromSpecular")
  1348. ], StandardMaterial_OldVer.prototype, "_useReflectionFresnelFromSpecular", void 0);
  1349. __decorate([
  1350. BABYLON.expandToProperty("_markAllSubMeshesAsFresnelDirty")
  1351. ], StandardMaterial_OldVer.prototype, "useReflectionFresnelFromSpecular", void 0);
  1352. __decorate([
  1353. BABYLON.serialize("useGlossinessFromSpecularMapAlpha")
  1354. ], StandardMaterial_OldVer.prototype, "_useGlossinessFromSpecularMapAlpha", void 0);
  1355. __decorate([
  1356. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1357. ], StandardMaterial_OldVer.prototype, "useGlossinessFromSpecularMapAlpha", void 0);
  1358. __decorate([
  1359. BABYLON.serialize("maxSimultaneousLights")
  1360. ], StandardMaterial_OldVer.prototype, "_maxSimultaneousLights", void 0);
  1361. __decorate([
  1362. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  1363. ], StandardMaterial_OldVer.prototype, "maxSimultaneousLights", void 0);
  1364. __decorate([
  1365. BABYLON.serialize("invertNormalMapX")
  1366. ], StandardMaterial_OldVer.prototype, "_invertNormalMapX", void 0);
  1367. __decorate([
  1368. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1369. ], StandardMaterial_OldVer.prototype, "invertNormalMapX", void 0);
  1370. __decorate([
  1371. BABYLON.serialize("invertNormalMapY")
  1372. ], StandardMaterial_OldVer.prototype, "_invertNormalMapY", void 0);
  1373. __decorate([
  1374. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1375. ], StandardMaterial_OldVer.prototype, "invertNormalMapY", void 0);
  1376. __decorate([
  1377. BABYLON.serialize("twoSidedLighting")
  1378. ], StandardMaterial_OldVer.prototype, "_twoSidedLighting", void 0);
  1379. __decorate([
  1380. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  1381. ], StandardMaterial_OldVer.prototype, "twoSidedLighting", void 0);
  1382. __decorate([
  1383. BABYLON.serialize()
  1384. ], StandardMaterial_OldVer.prototype, "useLogarithmicDepth", null);
  1385. return StandardMaterial_OldVer;
  1386. }(BABYLON.PushMaterial));
  1387. BABYLON.StandardMaterial_OldVer = StandardMaterial_OldVer;
  1388. var CustomShaderStructure = /** @class */ (function () {
  1389. function CustomShaderStructure() {
  1390. }
  1391. return CustomShaderStructure;
  1392. }());
  1393. BABYLON.CustomShaderStructure = CustomShaderStructure;
  1394. var ShaderSpecialParts = /** @class */ (function () {
  1395. function ShaderSpecialParts() {
  1396. }
  1397. return ShaderSpecialParts;
  1398. }());
  1399. BABYLON.ShaderSpecialParts = ShaderSpecialParts;
  1400. var ShaderForVer3_0 = /** @class */ (function (_super) {
  1401. __extends(ShaderForVer3_0, _super);
  1402. function ShaderForVer3_0() {
  1403. var _this = _super.call(this) || this;
  1404. _this.VertexStore = "";
  1405. _this.FragmentStore = "#include<__decl__defaultFragment>\n\
  1406. #[Fragment_Begin]\n\
  1407. #extension GL_OES_standard_derivatives : enable\n\
  1408. #ifdef LOGARITHMICDEPTH\n\
  1409. #extension GL_EXT_frag_depth : enable\n\
  1410. #endif\n\
  1411. \n\
  1412. #define RECIPROCAL_PI2 0.15915494\n\
  1413. uniform vec3 vEyePosition;\n\
  1414. uniform vec3 vAmbientColor;\n\
  1415. \n\
  1416. varying vec3 vPositionW;\n\
  1417. #ifdef NORMAL\n\
  1418. varying vec3 vNormalW_helper;\n\
  1419. varying vec3 localNormal;\n\
  1420. varying vec3 localPosition;\n\
  1421. vec3 vNormalW;\n\
  1422. #endif\n\
  1423. #ifdef VERTEXCOLOR\n\
  1424. varying vec4 vColor;\n\
  1425. #endif\n\
  1426. \n\
  1427. #include<helperFunctions>\n\
  1428. \n\
  1429. #include<__decl__lightFragment>[0..maxSimultaneousLights]\n\
  1430. #include<lightsFragmentFunctions>\n\
  1431. #include<shadowsFragmentFunctions>\n\
  1432. \n\
  1433. #ifdef DIFFUSE\n\
  1434. varying vec2 vDiffuseUV;\n\
  1435. uniform sampler2D diffuseSampler;\n\
  1436. #endif\n\
  1437. #ifdef AMBIENT\n\
  1438. varying vec2 vAmbientUV;\n\
  1439. uniform sampler2D ambientSampler;\n\
  1440. #endif\n\
  1441. #ifdef OPACITY\n\
  1442. varying vec2 vOpacityUV;\n\
  1443. uniform sampler2D opacitySampler;\n\
  1444. #endif\n\
  1445. #ifdef EMISSIVE\n\
  1446. varying vec2 vEmissiveUV;\n\
  1447. uniform sampler2D emissiveSampler;\n\
  1448. #endif\n\
  1449. #ifdef LIGHTMAP\n\
  1450. varying vec2 vLightmapUV;\n\
  1451. uniform sampler2D lightmapSampler;\n\
  1452. #endif\n\
  1453. #ifdef REFRACTION\n\
  1454. #ifdef REFRACTIONMAP_3D\n\
  1455. uniform samplerCube refractionCubeSampler;\n\
  1456. #else\n\
  1457. uniform sampler2D refraction2DSampler;\n\
  1458. #endif\n\
  1459. #endif\n\
  1460. #if defined(SPECULAR) && defined(SPECULARTERM)\n\
  1461. varying vec2 vSpecularUV;\n\
  1462. uniform sampler2D specularSampler;\n\
  1463. #endif\n\
  1464. \n\
  1465. #include<fresnelFunction>\n\
  1466. \n\
  1467. #ifdef REFLECTION\n\
  1468. #ifdef REFLECTIONMAP_3D\n\
  1469. uniform samplerCube reflectionCubeSampler;\n\
  1470. #else\n\
  1471. uniform sampler2D reflection2DSampler;\n\
  1472. #endif\n\
  1473. #ifdef REFLECTIONMAP_SKYBOX\n\
  1474. varying vec3 vPositionUVW;\n\
  1475. #else\n\
  1476. #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\n\
  1477. varying vec3 vDirectionW;\n\
  1478. #endif\n\
  1479. #endif\n\
  1480. #include<reflectionFunction>\n\
  1481. #endif\n\
  1482. #include<imageProcessingDeclaration>\n\
  1483. #include<imageProcessingFunctions>\n\
  1484. \n\
  1485. #include<bumpFragmentFunctions>\n\
  1486. #include<clipPlaneFragmentDeclaration>\n\
  1487. #include<logDepthDeclaration>\n\
  1488. #include<fogFragmentDeclaration>\n\
  1489. \n\
  1490. #[Fragment_Definitions]\n\
  1491. \n\
  1492. void main(void) {\n\
  1493. \n\
  1494. vNormalW = vNormalW_helper;\n\
  1495. #[Fragment_MainBegin]\n\
  1496. \n\
  1497. #include<clipPlaneFragment>\n\
  1498. vec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\
  1499. \n\
  1500. vec4 baseColor=vec4(1.,1.,1.,1.);\n\
  1501. vec3 diffuseColor=vDiffuseColor.rgb;\n\
  1502. #[Fragment_Custom_Diffuse]\n\
  1503. \n\
  1504. float alpha=vDiffuseColor.a;\n\
  1505. #[Fragment_Custom_Alpha]\n\
  1506. \n\
  1507. #ifdef NORMAL\n\
  1508. vec3 normalW=normalize(vNormalW);\n\
  1509. #else\n\
  1510. vec3 normalW=vec3(1.0,1.0,1.0);\n\
  1511. #endif\n\
  1512. #include<bumpFragment>\n\
  1513. #ifdef TWOSIDEDLIGHTING\n\
  1514. normalW=gl_FrontFacing ? normalW : -normalW;\n\
  1515. #endif\n\
  1516. #ifdef DIFFUSE\n\
  1517. baseColor=texture2D(diffuseSampler,vDiffuseUV+uvOffset);\n\
  1518. #ifdef ALPHATEST\n\
  1519. if (baseColor.a<0.4)\n\
  1520. discard;\n\
  1521. #endif\n\
  1522. #ifdef ALPHAFROMDIFFUSE\n\
  1523. alpha*=baseColor.a;\n\
  1524. #endif\n\
  1525. baseColor.rgb*=vDiffuseInfos.y;\n\
  1526. #endif\n\
  1527. #ifdef VERTEXCOLOR\n\
  1528. baseColor.rgb*=vColor.rgb;\n\
  1529. #endif\n\
  1530. \n\
  1531. vec3 baseAmbientColor=vec3(1.,1.,1.);\n\
  1532. #ifdef AMBIENT\n\
  1533. baseAmbientColor=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;\n\
  1534. #endif\n\
  1535. \n\
  1536. #ifdef SPECULARTERM\n\
  1537. float glossiness=vSpecularColor.a;\n\
  1538. vec3 specularColor=vSpecularColor.rgb;\n\
  1539. #ifdef SPECULAR\n\
  1540. vec4 specularMapColor=texture2D(specularSampler,vSpecularUV+uvOffset);\n\
  1541. specularColor=specularMapColor.rgb;\n\
  1542. #ifdef GLOSSINESS\n\
  1543. glossiness=glossiness*specularMapColor.a;\n\
  1544. #endif\n\
  1545. #endif\n\
  1546. #else\n\
  1547. float glossiness=0.;\n\
  1548. #endif\n\
  1549. \n\
  1550. vec3 diffuseBase=vec3(0.,0.,0.);\n\
  1551. lightingInfo info;\n\
  1552. #ifdef SPECULARTERM\n\
  1553. vec3 specularBase=vec3(0.,0.,0.);\n\
  1554. #endif\n\
  1555. float shadow=1.;\n\
  1556. #ifdef LIGHTMAP\n\
  1557. vec3 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset).rgb*vLightmapInfos.y;\n\
  1558. #endif\n\
  1559. #include<lightFragment>[0..maxSimultaneousLights]\n\
  1560. \n\
  1561. vec3 refractionColor=vec3(0.,0.,0.);\n\
  1562. #ifdef REFRACTION\n\
  1563. vec3 refractionVector=normalize(refract(-viewDirectionW,normalW,vRefractionInfos.y));\n\
  1564. #ifdef REFRACTIONMAP_3D\n\
  1565. refractionVector.y=refractionVector.y*vRefractionInfos.w;\n\
  1566. if (dot(refractionVector,viewDirectionW)<1.0)\n\
  1567. {\n\
  1568. refractionColor=textureCube(refractionCubeSampler,refractionVector).rgb*vRefractionInfos.x;\n\
  1569. }\n\
  1570. #else\n\
  1571. vec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));\n\
  1572. vec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;\n\
  1573. refractionCoords.y=1.0-refractionCoords.y;\n\
  1574. refractionColor=texture2D(refraction2DSampler,refractionCoords).rgb*vRefractionInfos.x;\n\
  1575. #endif\n\
  1576. #endif\n\
  1577. \n\
  1578. vec3 reflectionColor=vec3(0.,0.,0.);\n\
  1579. #ifdef REFLECTION\n\
  1580. vec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n\
  1581. #ifdef REFLECTIONMAP_3D\n\
  1582. #ifdef ROUGHNESS\n\
  1583. float bias=vReflectionInfos.y;\n\
  1584. #ifdef SPECULARTERM\n\
  1585. #ifdef SPECULAR\n\
  1586. #ifdef GLOSSINESS\n\
  1587. bias*=(1.0-specularMapColor.a);\n\
  1588. #endif\n\
  1589. #endif\n\
  1590. #endif\n\
  1591. reflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW,bias).rgb*vReflectionInfos.x;\n\
  1592. #else\n\
  1593. reflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW).rgb*vReflectionInfos.x;\n\
  1594. #endif\n\
  1595. #else\n\
  1596. vec2 coords=vReflectionUVW.xy;\n\
  1597. #ifdef REFLECTIONMAP_PROJECTION\n\
  1598. coords/=vReflectionUVW.z;\n\
  1599. #endif\n\
  1600. coords.y=1.0-coords.y;\n\
  1601. reflectionColor=texture2D(reflection2DSampler,coords).rgb*vReflectionInfos.x;\n\
  1602. #endif\n\
  1603. #ifdef REFLECTIONFRESNEL\n\
  1604. float reflectionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,reflectionRightColor.a,reflectionLeftColor.a);\n\
  1605. #ifdef REFLECTIONFRESNELFROMSPECULAR\n\
  1606. #ifdef SPECULARTERM\n\
  1607. reflectionColor*=specularColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n\
  1608. #else\n\
  1609. reflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n\
  1610. #endif\n\
  1611. #else\n\
  1612. reflectionColor*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n\
  1613. #endif\n\
  1614. #endif\n\
  1615. #endif\n\
  1616. #ifdef REFRACTIONFRESNEL\n\
  1617. float refractionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,refractionRightColor.a,refractionLeftColor.a);\n\
  1618. refractionColor*=refractionLeftColor.rgb*(1.0-refractionFresnelTerm)+refractionFresnelTerm*refractionRightColor.rgb;\n\
  1619. #endif\n\
  1620. #ifdef OPACITY\n\
  1621. vec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n\
  1622. #ifdef OPACITYRGB\n\
  1623. opacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);\n\
  1624. alpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n\
  1625. #else\n\
  1626. alpha*=opacityMap.a*vOpacityInfos.y;\n\
  1627. #endif\n\
  1628. #endif\n\
  1629. #ifdef VERTEXALPHA\n\
  1630. alpha*=vColor.a;\n\
  1631. #endif\n\
  1632. #ifdef OPACITYFRESNEL\n\
  1633. float opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);\n\
  1634. alpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;\n\
  1635. #endif\n\
  1636. \n\
  1637. vec3 emissiveColor=vEmissiveColor;\n\
  1638. #ifdef EMISSIVE\n\
  1639. emissiveColor+=texture2D(emissiveSampler,vEmissiveUV+uvOffset).rgb*vEmissiveInfos.y;\n\
  1640. #endif\n\
  1641. #ifdef EMISSIVEFRESNEL\n\
  1642. float emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);\n\
  1643. emissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;\n\
  1644. #endif\n\
  1645. \n\
  1646. #ifdef DIFFUSEFRESNEL\n\
  1647. float diffuseFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,diffuseRightColor.a,diffuseLeftColor.a);\n\
  1648. diffuseBase*=diffuseLeftColor.rgb*(1.0-diffuseFresnelTerm)+diffuseFresnelTerm*diffuseRightColor.rgb;\n\
  1649. #endif\n\
  1650. \n\
  1651. #ifdef EMISSIVEASILLUMINATION\n\
  1652. vec3 finalDiffuse=clamp(diffuseBase*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n\
  1653. #else\n\
  1654. #ifdef LINKEMISSIVEWITHDIFFUSE\n\
  1655. vec3 finalDiffuse=clamp((diffuseBase+emissiveColor)*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n\
  1656. #else\n\
  1657. vec3 finalDiffuse=clamp(diffuseBase*diffuseColor+emissiveColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n\
  1658. #endif\n\
  1659. #endif\n\
  1660. #ifdef SPECULARTERM\n\
  1661. vec3 finalSpecular=specularBase*specularColor;\n\
  1662. #ifdef SPECULAROVERALPHA\n\
  1663. alpha=clamp(alpha+dot(finalSpecular,vec3(0.3,0.59,0.11)),0.,1.);\n\
  1664. #endif\n\
  1665. #else\n\
  1666. vec3 finalSpecular=vec3(0.0);\n\
  1667. #endif\n\
  1668. #ifdef REFLECTIONOVERALPHA\n\
  1669. alpha=clamp(alpha+dot(reflectionColor,vec3(0.3,0.59,0.11)),0.,1.);\n\
  1670. #endif\n\
  1671. \n\
  1672. #ifdef EMISSIVEASILLUMINATION\n\
  1673. vec4 color=vec4(clamp(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+emissiveColor+refractionColor,0.0,1.0),alpha);\n\
  1674. #else\n\
  1675. vec4 color=vec4(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor+refractionColor,alpha);\n\
  1676. #endif\n\
  1677. \n\
  1678. #ifdef LIGHTMAP\n\
  1679. #ifndef LIGHTMAPEXCLUDED\n\
  1680. #ifdef USELIGHTMAPASSHADOWMAP\n\
  1681. color.rgb*=lightmapColor;\n\
  1682. #else\n\
  1683. color.rgb+=lightmapColor;\n\
  1684. #endif\n\
  1685. #endif\n\
  1686. #endif\n\
  1687. #include<logDepthFragment>\n\
  1688. #include<fogFragment>\n\
  1689. \n\
  1690. // Apply image processing if relevant. As this applies in linear space, \n\
  1691. // We first move from gamma to linear.\n\
  1692. #ifdef IMAGEPROCESSINGPOSTPROCESS\n\
  1693. color.rgb = toLinearSpace(color.rgb);\n\
  1694. #else\n\
  1695. #ifdef IMAGEPROCESSING\n\
  1696. color.rgb = toLinearSpace(color.rgb);\n\
  1697. color = applyImageProcessing(color);\n\
  1698. #endif\n\
  1699. #endif\n\
  1700. \n\
  1701. #[Fragment_Before_FragColor]\n\
  1702. gl_FragColor=color;\n\
  1703. }";
  1704. _this.VertexStore = "#include<__decl__defaultVertex>\n\
  1705. \n\
  1706. #[Vertex_Begin]\n\
  1707. \n\
  1708. attribute vec3 position;\n\
  1709. #ifdef NORMAL\n\
  1710. attribute vec3 normal;\n\
  1711. #endif\n\
  1712. #ifdef TANGENT\n\
  1713. attribute vec4 tangent;\n\
  1714. #endif\n\
  1715. #ifdef UV1\n\
  1716. attribute vec2 uv;\n\
  1717. #endif\n\
  1718. #ifdef UV2\n\
  1719. attribute vec2 uv2;\n\
  1720. #endif\n\
  1721. #ifdef VERTEXCOLOR\n\
  1722. attribute vec4 color;\n\
  1723. #endif\n\
  1724. #include<bonesDeclaration>\n\
  1725. \n\
  1726. #include<instancesDeclaration>\n\
  1727. #ifdef DIFFUSE\n\
  1728. varying vec2 vDiffuseUV;\n\
  1729. #endif\n\
  1730. #ifdef AMBIENT\n\
  1731. varying vec2 vAmbientUV;\n\
  1732. #endif\n\
  1733. #ifdef OPACITY\n\
  1734. varying vec2 vOpacityUV;\n\
  1735. #endif\n\
  1736. #ifdef EMISSIVE\n\
  1737. varying vec2 vEmissiveUV;\n\
  1738. #endif\n\
  1739. #ifdef LIGHTMAP\n\
  1740. varying vec2 vLightmapUV;\n\
  1741. #endif\n\
  1742. #if defined(SPECULAR) && defined(SPECULARTERM)\n\
  1743. varying vec2 vSpecularUV;\n\
  1744. #endif\n\
  1745. #ifdef BUMP\n\
  1746. varying vec2 vBumpUV;\n\
  1747. #endif\n\
  1748. \n\
  1749. varying vec3 localPosition;\n\
  1750. varying vec3 vPositionW;\n\
  1751. #ifdef NORMAL\n\
  1752. varying vec3 vNormalW_helper;\n\
  1753. varying vec3 localNormal;\n\
  1754. #endif\n\
  1755. #ifdef VERTEXCOLOR\n\
  1756. varying vec4 vColor;\n\
  1757. #endif\n\
  1758. #include<bumpVertexDeclaration>\n\
  1759. #include<clipPlaneVertexDeclaration>\n\
  1760. #include<fogVertexDeclaration>\n\
  1761. #include<__decl__lightFragment>[0..maxSimultaneousLights]\n\
  1762. #include<morphTargetsVertexGlobalDeclaration>\n\
  1763. #include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]\n\
  1764. #ifdef REFLECTIONMAP_SKYBOX\n\
  1765. varying vec3 vPositionUVW;\n\
  1766. #endif\n\
  1767. #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\n\
  1768. varying vec3 vDirectionW;\n\
  1769. #endif\n\
  1770. #include<logDepthDeclaration>\n\
  1771. \n\
  1772. #[Vertex_Definitions]\n\
  1773. \n\
  1774. void main(void) {\n\
  1775. \n\
  1776. #[Vertex_MainBegin]\n\
  1777. \n\
  1778. vec3 positionUpdated=position;\n\
  1779. #ifdef NORMAL \n\
  1780. vec3 normalUpdated=normal;\n\
  1781. #endif\n\
  1782. #ifdef TANGENT\n\
  1783. vec4 tangentUpdated=tangent;\n\
  1784. #endif\n\
  1785. #include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]\n\
  1786. #ifdef REFLECTIONMAP_SKYBOX\n\
  1787. vPositionUVW=positionUpdated;\n\
  1788. #endif \n\
  1789. #include<instancesVertex>\n\
  1790. #include<bonesVertex>\n\
  1791. \n\
  1792. localPosition = positionUpdated;\n\
  1793. #[Vertex_Before_PositionUpdated]\n\
  1794. \n\
  1795. gl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);\n\
  1796. vec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\n\
  1797. vPositionW=vec3(worldPos);\n\
  1798. #ifdef NORMAL\n\
  1799. \n\
  1800. #[Vertex_Before_NormalUpdated]\n\
  1801. \n\
  1802. localNormal = normalUpdated;\n\
  1803. vNormalW_helper=normalize(vec3(finalWorld*vec4(normalUpdated,0.0)));\n\
  1804. #endif\n\
  1805. #if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\n\
  1806. vDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,0.0)));\n\
  1807. #endif\n\
  1808. \n\
  1809. #ifndef UV1\n\
  1810. vec2 uv=vec2(0.,0.);\n\
  1811. #endif\n\
  1812. #ifndef UV2\n\
  1813. vec2 uv2=vec2(0.,0.);\n\
  1814. #endif\n\
  1815. #ifdef DIFFUSE\n\
  1816. if (vDiffuseInfos.x == 0.)\n\
  1817. {\n\
  1818. vDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n\
  1819. }\n\
  1820. else\n\
  1821. {\n\
  1822. vDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n\
  1823. }\n\
  1824. #endif\n\
  1825. #ifdef AMBIENT\n\
  1826. if (vAmbientInfos.x == 0.)\n\
  1827. {\n\
  1828. vAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));\n\
  1829. }\n\
  1830. else\n\
  1831. {\n\
  1832. vAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));\n\
  1833. }\n\
  1834. #endif\n\
  1835. #ifdef OPACITY\n\
  1836. if (vOpacityInfos.x == 0.)\n\
  1837. {\n\
  1838. vOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n\
  1839. }\n\
  1840. else\n\
  1841. {\n\
  1842. vOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n\
  1843. }\n\
  1844. #endif\n\
  1845. #ifdef EMISSIVE\n\
  1846. if (vEmissiveInfos.x == 0.)\n\
  1847. {\n\
  1848. vEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n\
  1849. }\n\
  1850. else\n\
  1851. {\n\
  1852. vEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n\
  1853. }\n\
  1854. #endif\n\
  1855. #ifdef LIGHTMAP\n\
  1856. if (vLightmapInfos.x == 0.)\n\
  1857. {\n\
  1858. vLightmapUV=vec2(lightmapMatrix*vec4(uv,1.0,0.0));\n\
  1859. }\n\
  1860. else\n\
  1861. {\n\
  1862. vLightmapUV=vec2(lightmapMatrix*vec4(uv2,1.0,0.0));\n\
  1863. }\n\
  1864. #endif\n\
  1865. #if defined(SPECULAR) && defined(SPECULARTERM)\n\
  1866. if (vSpecularInfos.x == 0.)\n\
  1867. {\n\
  1868. vSpecularUV=vec2(specularMatrix*vec4(uv,1.0,0.0));\n\
  1869. }\n\
  1870. else\n\
  1871. {\n\
  1872. vSpecularUV=vec2(specularMatrix*vec4(uv2,1.0,0.0));\n\
  1873. }\n\
  1874. #endif\n\
  1875. #ifdef BUMP\n\
  1876. if (vBumpInfos.x == 0.)\n\
  1877. {\n\
  1878. vBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));\n\
  1879. }\n\
  1880. else\n\
  1881. {\n\
  1882. vBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));\n\
  1883. }\n\
  1884. #endif\n\
  1885. #include<bumpVertex>\n\
  1886. #include<clipPlaneVertex>\n\
  1887. #include<fogVertex>\n\
  1888. #include<shadowsVertex>[0..maxSimultaneousLights]\n\
  1889. #ifdef VERTEXCOLOR\n\
  1890. \n\
  1891. vColor=color;\n\
  1892. #endif\n\
  1893. #include<pointCloudVertex>\n\
  1894. #include<logDepthVertex>\n\
  1895. }";
  1896. return _this;
  1897. }
  1898. return ShaderForVer3_0;
  1899. }(CustomShaderStructure));
  1900. BABYLON.ShaderForVer3_0 = ShaderForVer3_0;
  1901. var StandardShaderVersions = /** @class */ (function () {
  1902. function StandardShaderVersions() {
  1903. }
  1904. return StandardShaderVersions;
  1905. }());
  1906. BABYLON.StandardShaderVersions = StandardShaderVersions;
  1907. var CustomMaterial = /** @class */ (function (_super) {
  1908. __extends(CustomMaterial, _super);
  1909. function CustomMaterial(name, scene) {
  1910. var _this = _super.call(this, name, scene) || this;
  1911. _this.CustomParts = new ShaderSpecialParts();
  1912. _this.customShaderNameResolve = _this.Builder;
  1913. _this.SelectVersion("3.0.0");
  1914. return _this;
  1915. }
  1916. CustomMaterial.prototype.AttachAfterBind = function (mesh, effect) {
  1917. for (var el in this._newUniformInstances) {
  1918. var ea = el.toString().split('-');
  1919. if (ea[0] == 'vec2')
  1920. effect.setVector2(ea[1], this._newUniformInstances[el]);
  1921. else if (ea[0] == 'vec3')
  1922. effect.setVector3(ea[1], this._newUniformInstances[el]);
  1923. else if (ea[0] == 'vec4')
  1924. effect.setVector4(ea[1], this._newUniformInstances[el]);
  1925. else if (ea[0] == 'mat4')
  1926. effect.setMatrix(ea[1], this._newUniformInstances[el]);
  1927. else if (ea[0] == 'float')
  1928. effect.setFloat(ea[1], this._newUniformInstances[el]);
  1929. }
  1930. for (var el in this._newSamplerInstances) {
  1931. var ea = el.toString().split('-');
  1932. if (ea[0] == 'sampler2D' && this._newSamplerInstances[el].isReady && this._newSamplerInstances[el].isReady())
  1933. effect.setTexture(ea[1], this._newSamplerInstances[el]);
  1934. }
  1935. };
  1936. CustomMaterial.prototype.ReviewUniform = function (name, arr) {
  1937. if (name == "uniform") {
  1938. for (var ind in this._newUniforms)
  1939. if (this._customUniform[ind].indexOf('sampler') == -1)
  1940. arr.push(this._newUniforms[ind]);
  1941. }
  1942. if (name == "sampler") {
  1943. for (var ind in this._newUniforms)
  1944. if (this._customUniform[ind].indexOf('sampler') != -1)
  1945. arr.push(this._newUniforms[ind]);
  1946. }
  1947. return arr;
  1948. };
  1949. CustomMaterial.prototype.Builder = function (shaderName, uniforms, uniformBuffers, samplers, defines) {
  1950. if (this._isCreatedShader)
  1951. return this._createdShaderName;
  1952. this._isCreatedShader = false;
  1953. CustomMaterial.ShaderIndexer++;
  1954. var name = name + "custom_" + CustomMaterial.ShaderIndexer;
  1955. this.ReviewUniform("uniform", uniforms);
  1956. this.ReviewUniform("sampler", samplers);
  1957. var fn_afterBind = this._afterBind;
  1958. this._afterBind = function (m, e) {
  1959. this.AttachAfterBind(m, e);
  1960. try {
  1961. fn_afterBind(m, e);
  1962. }
  1963. catch (e) { }
  1964. ;
  1965. };
  1966. BABYLON.Effect.ShadersStore[name + "VertexShader"] = this.ShaderVersion.VertexStore
  1967. .replace('#[Vertex_Begin]', (this.CustomParts.Vertex_Begin ? this.CustomParts.Vertex_Begin : ""))
  1968. .replace('#[Vertex_Definitions]', (this._customUniform ? this._customUniform.join("\n") : "") + (this.CustomParts.Vertex_Definitions ? this.CustomParts.Vertex_Definitions : ""))
  1969. .replace('#[Vertex_MainBegin]', (this.CustomParts.Vertex_MainBegin ? this.CustomParts.Vertex_MainBegin : ""))
  1970. .replace('#[Vertex_Before_PositionUpdated]', (this.CustomParts.Vertex_Before_PositionUpdated ? this.CustomParts.Vertex_Before_PositionUpdated : ""))
  1971. .replace('#[Vertex_Before_NormalUpdated]', (this.CustomParts.Vertex_Before_NormalUpdated ? this.CustomParts.Vertex_Before_NormalUpdated : ""));
  1972. BABYLON.Effect.ShadersStore[name + "PixelShader"] = this.ShaderVersion.FragmentStore
  1973. .replace('#[Fragment_Begin]', (this.CustomParts.Fragment_Begin ? this.CustomParts.Fragment_Begin : ""))
  1974. .replace('#[Fragment_MainBegin]', (this.CustomParts.Fragment_MainBegin ? this.CustomParts.Fragment_MainBegin : ""))
  1975. .replace('#[Fragment_Definitions]', (this._customUniform ? this._customUniform.join("\n") : "") + (this.CustomParts.Fragment_Definitions ? this.CustomParts.Fragment_Definitions : ""))
  1976. .replace('#[Fragment_Custom_Diffuse]', (this.CustomParts.Fragment_Custom_Diffuse ? this.CustomParts.Fragment_Custom_Diffuse : ""))
  1977. .replace('#[Fragment_Custom_Alpha]', (this.CustomParts.Fragment_Custom_Alpha ? this.CustomParts.Fragment_Custom_Alpha : ""))
  1978. .replace('#[Fragment_Before_FragColor]', (this.CustomParts.Fragment_Before_FragColor ? this.CustomParts.Fragment_Before_FragColor : ""));
  1979. this._isCreatedShader = true;
  1980. this._createdShaderName = name;
  1981. return name;
  1982. };
  1983. CustomMaterial.prototype.SelectVersion = function (ver) {
  1984. switch (ver) {
  1985. case "3.0.0":
  1986. this.ShaderVersion = new ShaderForVer3_0();
  1987. break;
  1988. }
  1989. };
  1990. CustomMaterial.prototype.AddUniform = function (name, kind, param) {
  1991. if (!this._customUniform) {
  1992. this._customUniform = new Array();
  1993. this._newUniforms = new Array();
  1994. this._newSamplerInstances = new Array();
  1995. this._newUniformInstances = new Array();
  1996. }
  1997. if (param) {
  1998. if (kind.indexOf("sampler") == -1) {
  1999. this._newUniformInstances[kind + "-" + name] = param;
  2000. }
  2001. else {
  2002. this._newSamplerInstances[kind + "-" + name] = param;
  2003. }
  2004. }
  2005. this._customUniform.push("uniform " + kind + " " + name + ";");
  2006. this._newUniforms.push(name);
  2007. return this;
  2008. };
  2009. CustomMaterial.prototype.Fragment_Begin = function (shaderPart) {
  2010. this.CustomParts.Fragment_Begin = shaderPart;
  2011. return this;
  2012. };
  2013. CustomMaterial.prototype.Fragment_Definitions = function (shaderPart) {
  2014. this.CustomParts.Fragment_Definitions = shaderPart;
  2015. return this;
  2016. };
  2017. CustomMaterial.prototype.Fragment_MainBegin = function (shaderPart) {
  2018. this.CustomParts.Fragment_MainBegin = shaderPart;
  2019. return this;
  2020. };
  2021. CustomMaterial.prototype.Fragment_Custom_Diffuse = function (shaderPart) {
  2022. this.CustomParts.Fragment_Custom_Diffuse = shaderPart.replace("result", "diffuseColor");
  2023. return this;
  2024. };
  2025. CustomMaterial.prototype.Fragment_Custom_Alpha = function (shaderPart) {
  2026. this.CustomParts.Fragment_Custom_Alpha = shaderPart.replace("result", "alpha");
  2027. return this;
  2028. };
  2029. CustomMaterial.prototype.Fragment_Before_FragColor = function (shaderPart) {
  2030. this.CustomParts.Fragment_Before_FragColor = shaderPart.replace("result", "color");
  2031. return this;
  2032. };
  2033. CustomMaterial.prototype.Vertex_Begin = function (shaderPart) {
  2034. this.CustomParts.Vertex_Begin = shaderPart;
  2035. return this;
  2036. };
  2037. CustomMaterial.prototype.Vertex_Definitions = function (shaderPart) {
  2038. this.CustomParts.Vertex_Definitions = shaderPart;
  2039. return this;
  2040. };
  2041. CustomMaterial.prototype.Vertex_MainBegin = function (shaderPart) {
  2042. this.CustomParts.Vertex_MainBegin = shaderPart;
  2043. return this;
  2044. };
  2045. CustomMaterial.prototype.Vertex_Before_PositionUpdated = function (shaderPart) {
  2046. this.CustomParts.Vertex_Before_PositionUpdated = shaderPart.replace("result", "positionUpdated");
  2047. return this;
  2048. };
  2049. CustomMaterial.prototype.Vertex_Before_NormalUpdated = function (shaderPart) {
  2050. this.CustomParts.Vertex_Before_NormalUpdated = shaderPart.replace("result", "normalUpdated");
  2051. return this;
  2052. };
  2053. CustomMaterial.ShaderIndexer = 1;
  2054. return CustomMaterial;
  2055. }(StandardMaterial_OldVer));
  2056. BABYLON.CustomMaterial = CustomMaterial;
  2057. })(BABYLON || (BABYLON = {}));
  2058. //# sourceMappingURL=babylon.customMaterial.js.map