babylon.customMaterial.js 94 KB

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