babylon.customMaterial.js 94 KB

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