babylon.customMaterial.js 93 KB

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