babylon.customMaterial.js 94 KB

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