babylon.customMaterial.js 94 KB

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