babylon.legacyPbrMaterial.js 121 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525
  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. var LegacyPBRMaterialDefines = (function (_super) {
  21. __extends(LegacyPBRMaterialDefines, _super);
  22. function LegacyPBRMaterialDefines() {
  23. var _this = _super.call(this) || this;
  24. _this.ALBEDO = false;
  25. _this.AMBIENT = false;
  26. _this.AMBIENTINGRAYSCALE = false;
  27. _this.OPACITY = false;
  28. _this.OPACITYRGB = false;
  29. _this.REFLECTION = false;
  30. _this.EMISSIVE = false;
  31. _this.REFLECTIVITY = 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.ALPHAFROMALBEDO = false;
  39. _this.POINTSIZE = false;
  40. _this.FOG = false;
  41. _this.SPECULARTERM = false;
  42. _this.OPACITYFRESNEL = false;
  43. _this.EMISSIVEFRESNEL = false;
  44. _this.FRESNEL = false;
  45. _this.NORMAL = false;
  46. _this.TANGENT = false;
  47. _this.UV1 = false;
  48. _this.UV2 = false;
  49. _this.VERTEXCOLOR = false;
  50. _this.VERTEXALPHA = false;
  51. _this.NUM_BONE_INFLUENCERS = 0;
  52. _this.BonesPerMesh = 0;
  53. _this.INSTANCES = false;
  54. _this.MICROSURFACEFROMREFLECTIVITYMAP = false;
  55. _this.MICROSURFACEAUTOMATIC = false;
  56. _this.EMISSIVEASILLUMINATION = false;
  57. _this.LINKEMISSIVEWITHALBEDO = false;
  58. _this.LIGHTMAP = false;
  59. _this.USELIGHTMAPASSHADOWMAP = false;
  60. _this.REFLECTIONMAP_3D = false;
  61. _this.REFLECTIONMAP_SPHERICAL = false;
  62. _this.REFLECTIONMAP_PLANAR = false;
  63. _this.REFLECTIONMAP_CUBIC = false;
  64. _this.REFLECTIONMAP_PROJECTION = false;
  65. _this.REFLECTIONMAP_SKYBOX = false;
  66. _this.REFLECTIONMAP_EXPLICIT = false;
  67. _this.REFLECTIONMAP_EQUIRECTANGULAR = false;
  68. _this.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;
  69. _this.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false;
  70. _this.INVERTCUBICMAP = false;
  71. _this.LOGARITHMICDEPTH = false;
  72. _this.CAMERATONEMAP = false;
  73. _this.CAMERACONTRAST = false;
  74. _this.CAMERACOLORGRADING = false;
  75. _this.CAMERACOLORCURVES = false;
  76. _this.OVERLOADEDVALUES = false;
  77. _this.OVERLOADEDSHADOWVALUES = false;
  78. _this.USESPHERICALFROMREFLECTIONMAP = false;
  79. _this.REFRACTION = false;
  80. _this.REFRACTIONMAP_3D = false;
  81. _this.LINKREFRACTIONTOTRANSPARENCY = false;
  82. _this.REFRACTIONMAPINLINEARSPACE = false;
  83. _this.LODBASEDMICROSFURACE = false;
  84. _this.USEPHYSICALLIGHTFALLOFF = false;
  85. _this.RADIANCEOVERALPHA = false;
  86. _this.USEPMREMREFLECTION = false;
  87. _this.USEPMREMREFRACTION = false;
  88. _this.TWOSIDEDLIGHTING = false;
  89. _this.SHADOWFLOAT = false;
  90. _this.METALLICWORKFLOW = false;
  91. _this.METALLICMAP = false;
  92. _this.ROUGHNESSSTOREINMETALMAPALPHA = false;
  93. _this.ROUGHNESSSTOREINMETALMAPGREEN = false;
  94. _this.METALLNESSSTOREINMETALMAPBLUE = false;
  95. _this.AOSTOREINMETALMAPRED = false;
  96. _this.MICROSURFACEMAP = false;
  97. _this.MORPHTARGETS = false;
  98. _this.MORPHTARGETS_NORMAL = false;
  99. _this.MORPHTARGETS_TANGENT = false;
  100. _this.NUM_MORPH_INFLUENCERS = 0;
  101. _this.rebuild();
  102. return _this;
  103. }
  104. return LegacyPBRMaterialDefines;
  105. }(BABYLON.MaterialDefines));
  106. /**
  107. * The Physically based material of BJS.
  108. *
  109. * This offers the main features of a standard PBR material.
  110. * For more information, please refer to the documentation :
  111. * http://doc.babylonjs.com/extensions/Physically_Based_Rendering
  112. */
  113. var LegacyPBRMaterial = (function (_super) {
  114. __extends(LegacyPBRMaterial, _super);
  115. /**
  116. * Instantiates a new PBRMaterial instance.
  117. *
  118. * @param name The material name
  119. * @param scene The scene the material will be use in.
  120. */
  121. function LegacyPBRMaterial(name, scene) {
  122. var _this = _super.call(this, name, scene) || this;
  123. /**
  124. * Intensity of the direct lights e.g. the four lights available in your scene.
  125. * This impacts both the direct diffuse and specular highlights.
  126. */
  127. _this.directIntensity = 1.0;
  128. /**
  129. * Intensity of the emissive part of the material.
  130. * This helps controlling the emissive effect without modifying the emissive color.
  131. */
  132. _this.emissiveIntensity = 1.0;
  133. /**
  134. * Intensity of the environment e.g. how much the environment will light the object
  135. * either through harmonics for rough material or through the refelction for shiny ones.
  136. */
  137. _this.environmentIntensity = 1.0;
  138. /**
  139. * This is a special control allowing the reduction of the specular highlights coming from the
  140. * four lights of the scene. Those highlights may not be needed in full environment lighting.
  141. */
  142. _this.specularIntensity = 1.0;
  143. _this._lightingInfos = new BABYLON.Vector4(_this.directIntensity, _this.emissiveIntensity, _this.environmentIntensity, _this.specularIntensity);
  144. /**
  145. * Debug Control allowing disabling the bump map on this material.
  146. */
  147. _this.disableBumpMap = false;
  148. /**
  149. * Debug Control helping enforcing or dropping the darkness of shadows.
  150. * 1.0 means the shadows have their normal darkness, 0.0 means the shadows are not visible.
  151. */
  152. _this.overloadedShadowIntensity = 1.0;
  153. /**
  154. * Debug Control helping dropping the shading effect coming from the diffuse lighting.
  155. * 1.0 means the shade have their normal impact, 0.0 means no shading at all.
  156. */
  157. _this.overloadedShadeIntensity = 1.0;
  158. _this._overloadedShadowInfos = new BABYLON.Vector4(_this.overloadedShadowIntensity, _this.overloadedShadeIntensity, 0.0, 0.0);
  159. /**
  160. * The camera exposure used on this material.
  161. * This property is here and not in the camera to allow controlling exposure without full screen post process.
  162. * This corresponds to a photographic exposure.
  163. */
  164. _this.cameraExposure = 1.0;
  165. /**
  166. * The camera contrast used on this material.
  167. * This property is here and not in the camera to allow controlling contrast without full screen post process.
  168. */
  169. _this.cameraContrast = 1.0;
  170. /**
  171. * Color Grading 2D Lookup Texture.
  172. * This allows special effects like sepia, black and white to sixties rendering style.
  173. */
  174. _this.cameraColorGradingTexture = null;
  175. /**
  176. * The color grading curves provide additional color adjustmnent that is applied after any color grading transform (3D LUT).
  177. * They allow basic adjustment of saturation and small exposure adjustments, along with color filter tinting to provide white balance adjustment or more stylistic effects.
  178. * These are similar to controls found in many professional imaging or colorist software. The global controls are applied to the entire image. For advanced tuning, extra controls are provided to adjust the shadow, midtone and highlight areas of the image;
  179. * corresponding to low luminance, medium luminance, and high luminance areas respectively.
  180. */
  181. _this.cameraColorCurves = null;
  182. _this._cameraInfos = new BABYLON.Vector4(1.0, 1.0, 0.0, 0.0);
  183. _this._microsurfaceTextureLods = new BABYLON.Vector2(0.0, 0.0);
  184. /**
  185. * Debug Control allowing to overload the ambient color.
  186. * This as to be use with the overloadedAmbientIntensity parameter.
  187. */
  188. _this.overloadedAmbient = BABYLON.Color3.White();
  189. /**
  190. * Debug Control indicating how much the overloaded ambient color is used against the default one.
  191. */
  192. _this.overloadedAmbientIntensity = 0.0;
  193. /**
  194. * Debug Control allowing to overload the albedo color.
  195. * This as to be use with the overloadedAlbedoIntensity parameter.
  196. */
  197. _this.overloadedAlbedo = BABYLON.Color3.White();
  198. /**
  199. * Debug Control indicating how much the overloaded albedo color is used against the default one.
  200. */
  201. _this.overloadedAlbedoIntensity = 0.0;
  202. /**
  203. * Debug Control allowing to overload the reflectivity color.
  204. * This as to be use with the overloadedReflectivityIntensity parameter.
  205. */
  206. _this.overloadedReflectivity = new BABYLON.Color3(0.0, 0.0, 0.0);
  207. /**
  208. * Debug Control indicating how much the overloaded reflectivity color is used against the default one.
  209. */
  210. _this.overloadedReflectivityIntensity = 0.0;
  211. /**
  212. * Debug Control allowing to overload the emissive color.
  213. * This as to be use with the overloadedEmissiveIntensity parameter.
  214. */
  215. _this.overloadedEmissive = BABYLON.Color3.White();
  216. /**
  217. * Debug Control indicating how much the overloaded emissive color is used against the default one.
  218. */
  219. _this.overloadedEmissiveIntensity = 0.0;
  220. _this._overloadedIntensity = new BABYLON.Vector4(_this.overloadedAmbientIntensity, _this.overloadedAlbedoIntensity, _this.overloadedReflectivityIntensity, _this.overloadedEmissiveIntensity);
  221. /**
  222. * Debug Control allowing to overload the reflection color.
  223. * This as to be use with the overloadedReflectionIntensity parameter.
  224. */
  225. _this.overloadedReflection = BABYLON.Color3.White();
  226. /**
  227. * Debug Control indicating how much the overloaded reflection color is used against the default one.
  228. */
  229. _this.overloadedReflectionIntensity = 0.0;
  230. /**
  231. * Debug Control allowing to overload the microsurface.
  232. * This as to be use with the overloadedMicroSurfaceIntensity parameter.
  233. */
  234. _this.overloadedMicroSurface = 0.0;
  235. /**
  236. * Debug Control indicating how much the overloaded microsurface is used against the default one.
  237. */
  238. _this.overloadedMicroSurfaceIntensity = 0.0;
  239. _this._overloadedMicroSurface = new BABYLON.Vector3(_this.overloadedMicroSurface, _this.overloadedMicroSurfaceIntensity, _this.overloadedReflectionIntensity);
  240. /**
  241. * AKA Occlusion Texture Intensity in other nomenclature.
  242. */
  243. _this.ambientTextureStrength = 1.0;
  244. _this.ambientColor = new BABYLON.Color3(0, 0, 0);
  245. /**
  246. * AKA Diffuse Color in other nomenclature.
  247. */
  248. _this.albedoColor = new BABYLON.Color3(1, 1, 1);
  249. /**
  250. * AKA Specular Color in other nomenclature.
  251. */
  252. _this.reflectivityColor = new BABYLON.Color3(1, 1, 1);
  253. _this.reflectionColor = new BABYLON.Color3(0.0, 0.0, 0.0);
  254. _this.emissiveColor = new BABYLON.Color3(0, 0, 0);
  255. /**
  256. * AKA Glossiness in other nomenclature.
  257. */
  258. _this.microSurface = 0.9;
  259. /**
  260. * source material index of refraction (IOR)' / 'destination material IOR.
  261. */
  262. _this.indexOfRefraction = 0.66;
  263. /**
  264. * Controls if refraction needs to be inverted on Y. This could be usefull for procedural texture.
  265. */
  266. _this.invertRefractionY = false;
  267. /**
  268. * This parameters will make the material used its opacity to control how much it is refracting aginst not.
  269. * Materials half opaque for instance using refraction could benefit from this control.
  270. */
  271. _this.linkRefractionWithTransparency = false;
  272. /**
  273. * The emissive and albedo are linked to never be more than one (Energy conservation).
  274. */
  275. _this.linkEmissiveWithAlbedo = false;
  276. _this.useLightmapAsShadowmap = false;
  277. /**
  278. * In this mode, the emissive informtaion will always be added to the lighting once.
  279. * A light for instance can be thought as emissive.
  280. */
  281. _this.useEmissiveAsIllumination = false;
  282. /**
  283. * Secifies that the alpha is coming form the albedo channel alpha channel.
  284. */
  285. _this.useAlphaFromAlbedoTexture = false;
  286. /**
  287. * Specifies that the material will keeps the specular highlights over a transparent surface (only the most limunous ones).
  288. * A car glass is a good exemple of that. When sun reflects on it you can not see what is behind.
  289. */
  290. _this.useSpecularOverAlpha = true;
  291. /**
  292. * Specifies if the reflectivity texture contains the glossiness information in its alpha channel.
  293. */
  294. _this.useMicroSurfaceFromReflectivityMapAlpha = false;
  295. /**
  296. * Specifies if the metallic texture contains the roughness information in its alpha channel.
  297. */
  298. _this.useRoughnessFromMetallicTextureAlpha = true;
  299. /**
  300. * Specifies if the metallic texture contains the roughness information in its green channel.
  301. */
  302. _this.useRoughnessFromMetallicTextureGreen = false;
  303. /**
  304. * Specifies if the metallic texture contains the metallness information in its blue channel.
  305. */
  306. _this.useMetallnessFromMetallicTextureBlue = false;
  307. /**
  308. * Specifies if the metallic texture contains the ambient occlusion information in its red channel.
  309. */
  310. _this.useAmbientOcclusionFromMetallicTextureRed = false;
  311. /**
  312. * Specifies if the ambient texture contains the ambient occlusion information in its red channel only.
  313. */
  314. _this.useAmbientInGrayScale = false;
  315. /**
  316. * In case the reflectivity map does not contain the microsurface information in its alpha channel,
  317. * The material will try to infer what glossiness each pixel should be.
  318. */
  319. _this.useAutoMicroSurfaceFromReflectivityMap = false;
  320. /**
  321. * Allows to work with scalar in linear mode. This is definitely a matter of preferences and tools used during
  322. * the creation of the material.
  323. */
  324. _this.useScalarInLinearSpace = false;
  325. /**
  326. * BJS is using an harcoded light falloff based on a manually sets up range.
  327. * In PBR, one way to represents the fallof is to use the inverse squared root algorythm.
  328. * This parameter can help you switch back to the BJS mode in order to create scenes using both materials.
  329. */
  330. _this.usePhysicalLightFalloff = true;
  331. /**
  332. * Specifies that the material will keeps the reflection highlights over a transparent surface (only the most limunous ones).
  333. * A car glass is a good exemple of that. When the street lights reflects on it you can not see what is behind.
  334. */
  335. _this.useRadianceOverAlpha = true;
  336. /**
  337. * Allows using the bump map in parallax mode.
  338. */
  339. _this.useParallax = false;
  340. /**
  341. * Allows using the bump map in parallax occlusion mode.
  342. */
  343. _this.useParallaxOcclusion = false;
  344. /**
  345. * Controls the scale bias of the parallax mode.
  346. */
  347. _this.parallaxScaleBias = 0.05;
  348. /**
  349. * If sets to true, disables all the lights affecting the material.
  350. */
  351. _this.disableLighting = false;
  352. /**
  353. * Number of Simultaneous lights allowed on the material.
  354. */
  355. _this.maxSimultaneousLights = 4;
  356. /**
  357. * If sets to true, x component of normal map value will invert (x = 1.0 - x).
  358. */
  359. _this.invertNormalMapX = false;
  360. /**
  361. * If sets to true, y component of normal map value will invert (y = 1.0 - y).
  362. */
  363. _this.invertNormalMapY = false;
  364. /**
  365. * If sets to true and backfaceCulling is false, normals will be flipped on the backside.
  366. */
  367. _this.twoSidedLighting = false;
  368. _this._renderTargets = new BABYLON.SmartArray(16);
  369. _this._globalAmbientColor = new BABYLON.Color3(0, 0, 0);
  370. _this._tempColor = new BABYLON.Color3();
  371. _this._defines = new LegacyPBRMaterialDefines();
  372. _this._cachedDefines = new LegacyPBRMaterialDefines();
  373. _this._myScene = null;
  374. _this._cachedDefines.BonesPerMesh = -1;
  375. _this.getRenderTargetTextures = function () {
  376. _this._renderTargets.reset();
  377. if (BABYLON.StandardMaterial.ReflectionTextureEnabled && _this.reflectionTexture && _this.reflectionTexture.isRenderTarget) {
  378. _this._renderTargets.push(_this.reflectionTexture);
  379. }
  380. if (BABYLON.StandardMaterial.RefractionTextureEnabled && _this.refractionTexture && _this.refractionTexture.isRenderTarget) {
  381. _this._renderTargets.push(_this.refractionTexture);
  382. }
  383. return _this._renderTargets;
  384. };
  385. return _this;
  386. }
  387. LegacyPBRMaterial.prototype.getClassName = function () {
  388. return "LegacyPBRMaterial";
  389. };
  390. Object.defineProperty(LegacyPBRMaterial.prototype, "useLogarithmicDepth", {
  391. get: function () {
  392. return this._useLogarithmicDepth;
  393. },
  394. set: function (value) {
  395. this._useLogarithmicDepth = value && this.getScene().getEngine().getCaps().fragmentDepthSupported;
  396. },
  397. enumerable: true,
  398. configurable: true
  399. });
  400. LegacyPBRMaterial.prototype.needAlphaBlending = function () {
  401. if (this.linkRefractionWithTransparency) {
  402. return false;
  403. }
  404. return (this.alpha < 1.0) || (this.opacityTexture != null) || this._shouldUseAlphaFromAlbedoTexture() || this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled;
  405. };
  406. LegacyPBRMaterial.prototype.needAlphaTesting = function () {
  407. if (this.linkRefractionWithTransparency) {
  408. return false;
  409. }
  410. return this.albedoTexture != null && this.albedoTexture.hasAlpha;
  411. };
  412. LegacyPBRMaterial.prototype._shouldUseAlphaFromAlbedoTexture = function () {
  413. return this.albedoTexture != null && this.albedoTexture.hasAlpha && this.useAlphaFromAlbedoTexture;
  414. };
  415. LegacyPBRMaterial.prototype.getAlphaTestTexture = function () {
  416. return this.albedoTexture;
  417. };
  418. LegacyPBRMaterial.prototype._checkCache = function (scene, mesh, useInstances) {
  419. if (!mesh) {
  420. return true;
  421. }
  422. if (this._defines.INSTANCES !== useInstances) {
  423. return false;
  424. }
  425. return false;
  426. };
  427. LegacyPBRMaterial.prototype.convertColorToLinearSpaceToRef = function (color, ref) {
  428. LegacyPBRMaterial.convertColorToLinearSpaceToRef(color, ref, this.useScalarInLinearSpace);
  429. };
  430. LegacyPBRMaterial.convertColorToLinearSpaceToRef = function (color, ref, useScalarInLinear) {
  431. if (!useScalarInLinear) {
  432. color.toLinearSpaceToRef(ref);
  433. }
  434. else {
  435. ref.r = color.r;
  436. ref.g = color.g;
  437. ref.b = color.b;
  438. }
  439. };
  440. LegacyPBRMaterial.BindLights = function (scene, mesh, effect, defines, useScalarInLinearSpace, maxSimultaneousLights, usePhysicalLightFalloff) {
  441. var lightIndex = 0;
  442. for (var _i = 0, _a = mesh._lightSources; _i < _a.length; _i++) {
  443. var light = _a[_i];
  444. var useUbo = light._uniformBuffer.useUbo;
  445. light._uniformBuffer.bindToEffect(effect, "Light" + lightIndex);
  446. BABYLON.MaterialHelper.BindLightProperties(light, effect, lightIndex);
  447. // GAMMA CORRECTION.
  448. this.convertColorToLinearSpaceToRef(light.diffuse, LegacyPBRMaterial._scaledAlbedo, useScalarInLinearSpace);
  449. LegacyPBRMaterial._scaledAlbedo.scaleToRef(light.intensity, LegacyPBRMaterial._scaledAlbedo);
  450. light._uniformBuffer.updateColor4(useUbo ? "vLightDiffuse" : "vLightDiffuse" + lightIndex, LegacyPBRMaterial._scaledAlbedo, usePhysicalLightFalloff ? light.radius : light.range);
  451. if (defines["SPECULARTERM"]) {
  452. this.convertColorToLinearSpaceToRef(light.specular, LegacyPBRMaterial._scaledReflectivity, useScalarInLinearSpace);
  453. LegacyPBRMaterial._scaledReflectivity.scaleToRef(light.intensity, LegacyPBRMaterial._scaledReflectivity);
  454. light._uniformBuffer.updateColor3(useUbo ? "vLightSpecular" : "vLightSpecular" + lightIndex, LegacyPBRMaterial._scaledReflectivity);
  455. }
  456. // Shadows
  457. if (scene.shadowsEnabled) {
  458. BABYLON.MaterialHelper.BindLightShadow(light, scene, mesh, lightIndex + "", effect);
  459. }
  460. light._uniformBuffer.update();
  461. lightIndex++;
  462. if (lightIndex === maxSimultaneousLights)
  463. break;
  464. }
  465. };
  466. LegacyPBRMaterial.prototype.isReady = function (mesh, useInstances) {
  467. var _this = this;
  468. if (this.isFrozen) {
  469. if (this._wasPreviouslyReady) {
  470. return true;
  471. }
  472. }
  473. var scene = this.getScene();
  474. var engine = scene.getEngine();
  475. var needUVs = false;
  476. this._defines.reset();
  477. if (scene.lightsEnabled && !this.disableLighting) {
  478. BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines, true, this.maxSimultaneousLights);
  479. }
  480. if (!this.checkReadyOnEveryCall) {
  481. if (this._renderId === scene.getRenderId()) {
  482. if (this._checkCache(scene, mesh, useInstances)) {
  483. return true;
  484. }
  485. }
  486. }
  487. if (scene.texturesEnabled) {
  488. if (scene.getEngine().getCaps().textureLOD) {
  489. this._defines.LODBASEDMICROSFURACE = true;
  490. }
  491. if (this.albedoTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  492. if (!this.albedoTexture.isReady()) {
  493. return false;
  494. }
  495. needUVs = true;
  496. this._defines.ALBEDO = true;
  497. }
  498. if (this.ambientTexture && BABYLON.StandardMaterial.AmbientTextureEnabled) {
  499. if (!this.ambientTexture.isReady()) {
  500. return false;
  501. }
  502. needUVs = true;
  503. this._defines.AMBIENT = true;
  504. this._defines.AMBIENTINGRAYSCALE = this.useAmbientInGrayScale;
  505. }
  506. if (this.opacityTexture && BABYLON.StandardMaterial.OpacityTextureEnabled) {
  507. if (!this.opacityTexture.isReady()) {
  508. return false;
  509. }
  510. needUVs = true;
  511. this._defines.OPACITY = true;
  512. if (this.opacityTexture.getAlphaFromRGB) {
  513. this._defines.OPACITYRGB = true;
  514. }
  515. }
  516. if (this.reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  517. if (!this.reflectionTexture.isReady()) {
  518. return false;
  519. }
  520. this._defines.REFLECTION = true;
  521. if (this.reflectionTexture.coordinatesMode === BABYLON.Texture.INVCUBIC_MODE) {
  522. this._defines.INVERTCUBICMAP = true;
  523. }
  524. this._defines.REFLECTIONMAP_3D = this.reflectionTexture.isCube;
  525. switch (this.reflectionTexture.coordinatesMode) {
  526. case BABYLON.Texture.CUBIC_MODE:
  527. case BABYLON.Texture.INVCUBIC_MODE:
  528. this._defines.REFLECTIONMAP_CUBIC = true;
  529. break;
  530. case BABYLON.Texture.EXPLICIT_MODE:
  531. this._defines.REFLECTIONMAP_EXPLICIT = true;
  532. break;
  533. case BABYLON.Texture.PLANAR_MODE:
  534. this._defines.REFLECTIONMAP_PLANAR = true;
  535. break;
  536. case BABYLON.Texture.PROJECTION_MODE:
  537. this._defines.REFLECTIONMAP_PROJECTION = true;
  538. break;
  539. case BABYLON.Texture.SKYBOX_MODE:
  540. this._defines.REFLECTIONMAP_SKYBOX = true;
  541. break;
  542. case BABYLON.Texture.SPHERICAL_MODE:
  543. this._defines.REFLECTIONMAP_SPHERICAL = true;
  544. break;
  545. case BABYLON.Texture.EQUIRECTANGULAR_MODE:
  546. this._defines.REFLECTIONMAP_EQUIRECTANGULAR = true;
  547. break;
  548. case BABYLON.Texture.FIXED_EQUIRECTANGULAR_MODE:
  549. this._defines.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = true;
  550. break;
  551. case BABYLON.Texture.FIXED_EQUIRECTANGULAR_MIRRORED_MODE:
  552. this._defines.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = true;
  553. break;
  554. }
  555. if (this.reflectionTexture instanceof BABYLON.HDRCubeTexture && this.reflectionTexture) {
  556. this._defines.USESPHERICALFROMREFLECTIONMAP = true;
  557. if (this.reflectionTexture.isPMREM) {
  558. this._defines.USEPMREMREFLECTION = true;
  559. }
  560. }
  561. }
  562. if (this.lightmapTexture && BABYLON.StandardMaterial.LightmapTextureEnabled) {
  563. if (!this.lightmapTexture.isReady()) {
  564. return false;
  565. }
  566. needUVs = true;
  567. this._defines.LIGHTMAP = true;
  568. this._defines.USELIGHTMAPASSHADOWMAP = this.useLightmapAsShadowmap;
  569. }
  570. if (this.emissiveTexture && BABYLON.StandardMaterial.EmissiveTextureEnabled) {
  571. if (!this.emissiveTexture.isReady()) {
  572. return false;
  573. }
  574. needUVs = true;
  575. this._defines.EMISSIVE = true;
  576. }
  577. if (BABYLON.StandardMaterial.SpecularTextureEnabled) {
  578. if (this.metallicTexture) {
  579. if (!this.metallicTexture.isReady()) {
  580. return false;
  581. }
  582. needUVs = true;
  583. this._defines.METALLICWORKFLOW = true;
  584. this._defines.METALLICMAP = true;
  585. this._defines.ROUGHNESSSTOREINMETALMAPALPHA = this.useRoughnessFromMetallicTextureAlpha;
  586. this._defines.ROUGHNESSSTOREINMETALMAPGREEN = !this.useRoughnessFromMetallicTextureAlpha && this.useRoughnessFromMetallicTextureGreen;
  587. this._defines.METALLNESSSTOREINMETALMAPBLUE = this.useMetallnessFromMetallicTextureBlue;
  588. this._defines.AOSTOREINMETALMAPRED = this.useAmbientOcclusionFromMetallicTextureRed;
  589. }
  590. else if (this.reflectivityTexture) {
  591. if (!this.reflectivityTexture.isReady()) {
  592. return false;
  593. }
  594. needUVs = true;
  595. this._defines.REFLECTIVITY = true;
  596. this._defines.MICROSURFACEFROMREFLECTIVITYMAP = this.useMicroSurfaceFromReflectivityMapAlpha;
  597. this._defines.MICROSURFACEAUTOMATIC = this.useAutoMicroSurfaceFromReflectivityMap;
  598. }
  599. if (this.microSurfaceTexture) {
  600. if (!this.microSurfaceTexture.isReady()) {
  601. return false;
  602. }
  603. needUVs = true;
  604. this._defines.MICROSURFACEMAP = true;
  605. }
  606. }
  607. if (scene.getEngine().getCaps().standardDerivatives && this.bumpTexture && BABYLON.StandardMaterial.BumpTextureEnabled && !this.disableBumpMap) {
  608. if (!this.bumpTexture.isReady()) {
  609. return false;
  610. }
  611. needUVs = true;
  612. this._defines.BUMP = true;
  613. if (this.useParallax && this.albedoTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  614. this._defines.PARALLAX = true;
  615. if (this.useParallaxOcclusion) {
  616. this._defines.PARALLAXOCCLUSION = true;
  617. }
  618. }
  619. }
  620. if (this.refractionTexture && BABYLON.StandardMaterial.RefractionTextureEnabled) {
  621. if (!this.refractionTexture.isReady()) {
  622. return false;
  623. }
  624. needUVs = true;
  625. this._defines.REFRACTION = true;
  626. this._defines.REFRACTIONMAP_3D = this.refractionTexture.isCube;
  627. if (this.linkRefractionWithTransparency) {
  628. this._defines.LINKREFRACTIONTOTRANSPARENCY = true;
  629. }
  630. if (this.refractionTexture instanceof BABYLON.HDRCubeTexture) {
  631. this._defines.REFRACTIONMAPINLINEARSPACE = true;
  632. if (this.refractionTexture.isPMREM) {
  633. this._defines.USEPMREMREFRACTION = true;
  634. }
  635. }
  636. }
  637. if (this.cameraColorGradingTexture && BABYLON.StandardMaterial.ColorGradingTextureEnabled) {
  638. if (!this.cameraColorGradingTexture.isReady()) {
  639. return false;
  640. }
  641. this._defines.CAMERACOLORGRADING = true;
  642. }
  643. if (!this.backFaceCulling && this.twoSidedLighting) {
  644. this._defines.TWOSIDEDLIGHTING = true;
  645. }
  646. }
  647. // Effect
  648. if (scene.clipPlane) {
  649. this._defines.CLIPPLANE = true;
  650. }
  651. if (engine.getAlphaTesting()) {
  652. this._defines.ALPHATEST = true;
  653. }
  654. if (this._shouldUseAlphaFromAlbedoTexture()) {
  655. this._defines.ALPHAFROMALBEDO = true;
  656. }
  657. if (this.useEmissiveAsIllumination) {
  658. this._defines.EMISSIVEASILLUMINATION = true;
  659. }
  660. if (this.linkEmissiveWithAlbedo) {
  661. this._defines.LINKEMISSIVEWITHALBEDO = true;
  662. }
  663. if (this.useLogarithmicDepth) {
  664. this._defines.LOGARITHMICDEPTH = true;
  665. }
  666. if (this.cameraContrast != 1) {
  667. this._defines.CAMERACONTRAST = true;
  668. }
  669. if (this.cameraExposure != 1) {
  670. this._defines.CAMERATONEMAP = true;
  671. }
  672. if (this.cameraColorCurves) {
  673. this._defines.CAMERACOLORCURVES = true;
  674. }
  675. if (this.overloadedShadeIntensity != 1 ||
  676. this.overloadedShadowIntensity != 1) {
  677. this._defines.OVERLOADEDSHADOWVALUES = true;
  678. }
  679. if (this.overloadedMicroSurfaceIntensity > 0 ||
  680. this.overloadedEmissiveIntensity > 0 ||
  681. this.overloadedReflectivityIntensity > 0 ||
  682. this.overloadedAlbedoIntensity > 0 ||
  683. this.overloadedAmbientIntensity > 0 ||
  684. this.overloadedReflectionIntensity > 0) {
  685. this._defines.OVERLOADEDVALUES = true;
  686. }
  687. // Point size
  688. if (this.pointsCloud || scene.forcePointsCloud) {
  689. this._defines.POINTSIZE = true;
  690. }
  691. // Fog
  692. if (scene.fogEnabled && mesh && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled) {
  693. this._defines.FOG = true;
  694. }
  695. if (BABYLON.StandardMaterial.FresnelEnabled) {
  696. // Fresnel
  697. if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled ||
  698. this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {
  699. if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled) {
  700. this._defines.OPACITYFRESNEL = true;
  701. }
  702. if (this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {
  703. this._defines.EMISSIVEFRESNEL = true;
  704. }
  705. this._defines.FRESNEL = true;
  706. }
  707. }
  708. if (this._defines.SPECULARTERM && this.useSpecularOverAlpha) {
  709. this._defines.SPECULAROVERALPHA = true;
  710. }
  711. if (this.usePhysicalLightFalloff) {
  712. this._defines.USEPHYSICALLIGHTFALLOFF = true;
  713. }
  714. if (this.useRadianceOverAlpha) {
  715. this._defines.RADIANCEOVERALPHA = true;
  716. }
  717. if ((this.metallic !== undefined && this.metallic !== null) || (this.roughness !== undefined && this.roughness !== null)) {
  718. this._defines.METALLICWORKFLOW = true;
  719. }
  720. // Attribs
  721. if (mesh) {
  722. if (!scene.getEngine().getCaps().standardDerivatives && !mesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
  723. mesh.createNormals(true);
  724. BABYLON.Tools.Warn("PBRMaterial: Normals have been created for the mesh: " + mesh.name);
  725. }
  726. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
  727. this._defines.NORMAL = true;
  728. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.TangentKind)) {
  729. this._defines.TANGENT = true;
  730. }
  731. }
  732. if (needUVs) {
  733. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
  734. this._defines.UV1 = true;
  735. }
  736. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind)) {
  737. this._defines.UV2 = true;
  738. }
  739. }
  740. if (mesh.useVertexColors && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind)) {
  741. this._defines.VERTEXCOLOR = true;
  742. if (mesh.hasVertexAlpha) {
  743. this._defines.VERTEXALPHA = true;
  744. }
  745. }
  746. if (mesh.useBones && mesh.computeBonesUsingShaders) {
  747. this._defines.NUM_BONE_INFLUENCERS = mesh.numBoneInfluencers;
  748. this._defines.BonesPerMesh = (mesh.skeleton.bones.length + 1);
  749. }
  750. // Instances
  751. if (useInstances) {
  752. this._defines.INSTANCES = true;
  753. }
  754. if (mesh.morphTargetManager) {
  755. var manager = mesh.morphTargetManager;
  756. this._defines.MORPHTARGETS_TANGENT = manager.supportsTangents && this._defines.TANGENT;
  757. this._defines.MORPHTARGETS_NORMAL = manager.supportsNormals && this._defines.NORMAL;
  758. this._defines.MORPHTARGETS = (manager.numInfluencers > 0);
  759. this._defines.NUM_MORPH_INFLUENCERS = manager.numInfluencers;
  760. }
  761. }
  762. // Get correct effect
  763. if (!this._defines.isEqual(this._cachedDefines)) {
  764. this._defines.cloneTo(this._cachedDefines);
  765. scene.resetCachedMaterial();
  766. // Fallbacks
  767. var fallbacks = new BABYLON.EffectFallbacks();
  768. if (this._defines.REFLECTION) {
  769. fallbacks.addFallback(0, "REFLECTION");
  770. }
  771. if (this._defines.REFRACTION) {
  772. fallbacks.addFallback(0, "REFRACTION");
  773. }
  774. if (this._defines.REFLECTIVITY) {
  775. fallbacks.addFallback(0, "REFLECTIVITY");
  776. }
  777. if (this._defines.BUMP) {
  778. fallbacks.addFallback(0, "BUMP");
  779. }
  780. if (this._defines.PARALLAX) {
  781. fallbacks.addFallback(1, "PARALLAX");
  782. }
  783. if (this._defines.PARALLAXOCCLUSION) {
  784. fallbacks.addFallback(0, "PARALLAXOCCLUSION");
  785. }
  786. if (this._defines.SPECULAROVERALPHA) {
  787. fallbacks.addFallback(0, "SPECULAROVERALPHA");
  788. }
  789. if (this._defines.FOG) {
  790. fallbacks.addFallback(1, "FOG");
  791. }
  792. if (this._defines.POINTSIZE) {
  793. fallbacks.addFallback(0, "POINTSIZE");
  794. }
  795. if (this._defines.LOGARITHMICDEPTH) {
  796. fallbacks.addFallback(0, "LOGARITHMICDEPTH");
  797. }
  798. BABYLON.MaterialHelper.HandleFallbacksForShadows(this._defines, fallbacks, this.maxSimultaneousLights);
  799. if (this._defines.SPECULARTERM) {
  800. fallbacks.addFallback(0, "SPECULARTERM");
  801. }
  802. if (this._defines.OPACITYFRESNEL) {
  803. fallbacks.addFallback(1, "OPACITYFRESNEL");
  804. }
  805. if (this._defines.EMISSIVEFRESNEL) {
  806. fallbacks.addFallback(2, "EMISSIVEFRESNEL");
  807. }
  808. if (this._defines.FRESNEL) {
  809. fallbacks.addFallback(3, "FRESNEL");
  810. }
  811. if (this._defines.NUM_BONE_INFLUENCERS > 0) {
  812. fallbacks.addCPUSkinningFallback(0, mesh);
  813. }
  814. //Attributes
  815. var attribs = [BABYLON.VertexBuffer.PositionKind];
  816. if (this._defines.NORMAL) {
  817. attribs.push(BABYLON.VertexBuffer.NormalKind);
  818. }
  819. if (this._defines.TANGENT) {
  820. attribs.push(BABYLON.VertexBuffer.TangentKind);
  821. }
  822. if (this._defines.UV1) {
  823. attribs.push(BABYLON.VertexBuffer.UVKind);
  824. }
  825. if (this._defines.UV2) {
  826. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  827. }
  828. if (this._defines.VERTEXCOLOR) {
  829. attribs.push(BABYLON.VertexBuffer.ColorKind);
  830. }
  831. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
  832. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, this._defines);
  833. BABYLON.MaterialHelper.PrepareAttributesForMorphTargets(attribs, mesh, this._defines);
  834. // Legacy browser patch
  835. var join = this._defines.toString();
  836. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vAlbedoColor", "vReflectivityColor", "vEmissiveColor", "vReflectionColor",
  837. "vFogInfos", "vFogColor", "pointSize",
  838. "vAlbedoInfos", "vAmbientInfos", "vOpacityInfos", "vReflectionInfos", "vEmissiveInfos", "vReflectivityInfos", "vMicroSurfaceSamplerInfos", "vBumpInfos", "vLightmapInfos", "vRefractionInfos",
  839. "mBones",
  840. "vClipPlane", "albedoMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "reflectivityMatrix", "microSurfaceSamplerMatrix", "bumpMatrix", "lightmapMatrix", "refractionMatrix",
  841. "opacityParts", "emissiveLeftColor", "emissiveRightColor",
  842. "vLightingIntensity", "vOverloadedShadowIntensity", "vOverloadedIntensity", "vOverloadedAlbedo", "vOverloadedReflection", "vOverloadedReflectivity", "vOverloadedEmissive", "vOverloadedMicroSurface",
  843. "logarithmicDepthConstant",
  844. "vSphericalX", "vSphericalY", "vSphericalZ",
  845. "vSphericalXX", "vSphericalYY", "vSphericalZZ",
  846. "vSphericalXY", "vSphericalYZ", "vSphericalZX",
  847. "vMicrosurfaceTextureLods",
  848. "vCameraInfos", "vTangentSpaceParams"
  849. ];
  850. var samplers = ["albedoSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "reflectivitySampler", "microSurfaceSampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler"];
  851. var uniformBuffers = ["Material", "Scene"];
  852. if (this._defines.CAMERACOLORCURVES) {
  853. BABYLON.ColorCurves.PrepareUniforms(uniforms);
  854. }
  855. if (this._defines.CAMERACOLORGRADING) {
  856. uniforms.push("vCameraColorGradingInfos", "vCameraColorGradingScaleOffset");
  857. samplers.push("cameraColorGrading2DSampler");
  858. }
  859. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  860. uniformsNames: uniforms,
  861. uniformBuffersNames: uniformBuffers,
  862. samplers: samplers,
  863. defines: this._defines,
  864. maxSimultaneousLights: this.maxSimultaneousLights
  865. });
  866. var onCompiled = function (effect) {
  867. if (_this.onCompiled) {
  868. _this.onCompiled(effect);
  869. }
  870. _this.bindSceneUniformBuffer(effect, scene.getSceneUniformBuffer());
  871. };
  872. this._effect = scene.getEngine().createEffect("legacyPbr", {
  873. attributes: attribs,
  874. uniformsNames: uniforms,
  875. uniformBuffersNames: uniformBuffers,
  876. samplers: samplers,
  877. defines: join,
  878. fallbacks: fallbacks,
  879. onCompiled: onCompiled,
  880. onError: this.onError,
  881. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights, maxSimultaneousMorphTargets: this._defines.NUM_MORPH_INFLUENCERS }
  882. }, engine);
  883. this.buildUniformLayout();
  884. }
  885. if (!this._effect.isReady()) {
  886. return false;
  887. }
  888. this._renderId = scene.getRenderId();
  889. this._wasPreviouslyReady = true;
  890. return true;
  891. };
  892. LegacyPBRMaterial.prototype.buildUniformLayout = function () {
  893. // Order is important !
  894. this._uniformBuffer.addUniform("vAlbedoInfos", 2);
  895. this._uniformBuffer.addUniform("vAmbientInfos", 3);
  896. this._uniformBuffer.addUniform("vOpacityInfos", 2);
  897. this._uniformBuffer.addUniform("vEmissiveInfos", 2);
  898. this._uniformBuffer.addUniform("vLightmapInfos", 2);
  899. this._uniformBuffer.addUniform("vReflectivityInfos", 3);
  900. this._uniformBuffer.addUniform("vMicroSurfaceSamplerInfos", 2);
  901. this._uniformBuffer.addUniform("vRefractionInfos", 4);
  902. this._uniformBuffer.addUniform("vReflectionInfos", 2);
  903. this._uniformBuffer.addUniform("vBumpInfos", 3);
  904. this._uniformBuffer.addUniform("albedoMatrix", 16);
  905. this._uniformBuffer.addUniform("ambientMatrix", 16);
  906. this._uniformBuffer.addUniform("opacityMatrix", 16);
  907. this._uniformBuffer.addUniform("emissiveMatrix", 16);
  908. this._uniformBuffer.addUniform("lightmapMatrix", 16);
  909. this._uniformBuffer.addUniform("reflectivityMatrix", 16);
  910. this._uniformBuffer.addUniform("microSurfaceSamplerMatrix", 16);
  911. this._uniformBuffer.addUniform("bumpMatrix", 16);
  912. this._uniformBuffer.addUniform("vTangentSpaceParams", 2);
  913. this._uniformBuffer.addUniform("refractionMatrix", 16);
  914. this._uniformBuffer.addUniform("reflectionMatrix", 16);
  915. this._uniformBuffer.addUniform("vReflectionColor", 3);
  916. this._uniformBuffer.addUniform("vAlbedoColor", 4);
  917. this._uniformBuffer.addUniform("vLightingIntensity", 4);
  918. this._uniformBuffer.addUniform("vMicrosurfaceTextureLods", 2);
  919. this._uniformBuffer.addUniform("vReflectivityColor", 4);
  920. this._uniformBuffer.addUniform("vEmissiveColor", 3);
  921. this._uniformBuffer.addUniform("opacityParts", 4);
  922. this._uniformBuffer.addUniform("emissiveLeftColor", 4);
  923. this._uniformBuffer.addUniform("emissiveRightColor", 4);
  924. this._uniformBuffer.addUniform("vOverloadedIntensity", 4);
  925. this._uniformBuffer.addUniform("vOverloadedAmbient", 3);
  926. this._uniformBuffer.addUniform("vOverloadedAlbedo", 3);
  927. this._uniformBuffer.addUniform("vOverloadedReflectivity", 3);
  928. this._uniformBuffer.addUniform("vOverloadedEmissive", 3);
  929. this._uniformBuffer.addUniform("vOverloadedReflection", 3);
  930. this._uniformBuffer.addUniform("vOverloadedMicroSurface", 3);
  931. this._uniformBuffer.addUniform("vOverloadedShadowIntensity", 4);
  932. this._uniformBuffer.addUniform("pointSize", 1);
  933. this._uniformBuffer.create();
  934. };
  935. LegacyPBRMaterial.prototype.unbind = function () {
  936. if (this.reflectionTexture && this.reflectionTexture.isRenderTarget) {
  937. this._uniformBuffer.setTexture("reflection2DSampler", null);
  938. }
  939. if (this.refractionTexture && this.refractionTexture.isRenderTarget) {
  940. this._uniformBuffer.setTexture("refraction2DSampler", null);
  941. }
  942. _super.prototype.unbind.call(this);
  943. };
  944. LegacyPBRMaterial.prototype.bindOnlyWorldMatrix = function (world) {
  945. this._effect.setMatrix("world", world);
  946. };
  947. LegacyPBRMaterial.prototype.bind = function (world, mesh) {
  948. this._myScene = this.getScene();
  949. var effect = this._effect;
  950. // Matrices
  951. this.bindOnlyWorldMatrix(world);
  952. // Bones
  953. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._effect);
  954. if (this._myScene.getCachedMaterial() !== this) {
  955. this._uniformBuffer.bindToEffect(effect, "Material");
  956. this.bindViewProjection(effect);
  957. if (!this._uniformBuffer.useUbo || !this.isFrozen || !this._uniformBuffer.isSync) {
  958. // Fresnel
  959. if (BABYLON.StandardMaterial.FresnelEnabled) {
  960. if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled) {
  961. this._uniformBuffer.updateColor4("opacityParts", new BABYLON.Color3(this.opacityFresnelParameters.leftColor.toLuminance(), this.opacityFresnelParameters.rightColor.toLuminance(), this.opacityFresnelParameters.bias), this.opacityFresnelParameters.power);
  962. }
  963. if (this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {
  964. this._uniformBuffer.updateColor4("emissiveLeftColor", this.emissiveFresnelParameters.leftColor, this.emissiveFresnelParameters.power);
  965. this._uniformBuffer.updateColor4("emissiveRightColor", this.emissiveFresnelParameters.rightColor, this.emissiveFresnelParameters.bias);
  966. }
  967. }
  968. // Texture uniforms
  969. if (this._myScene.texturesEnabled) {
  970. if (this.albedoTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  971. this._uniformBuffer.updateFloat2("vAlbedoInfos", this.albedoTexture.coordinatesIndex, this.albedoTexture.level);
  972. this._uniformBuffer.updateMatrix("albedoMatrix", this.albedoTexture.getTextureMatrix());
  973. }
  974. if (this.ambientTexture && BABYLON.StandardMaterial.AmbientTextureEnabled) {
  975. this._uniformBuffer.updateFloat3("vAmbientInfos", this.ambientTexture.coordinatesIndex, this.ambientTexture.level, this.ambientTextureStrength);
  976. this._uniformBuffer.updateMatrix("ambientMatrix", this.ambientTexture.getTextureMatrix());
  977. }
  978. if (this.opacityTexture && BABYLON.StandardMaterial.OpacityTextureEnabled) {
  979. this._uniformBuffer.updateFloat2("vOpacityInfos", this.opacityTexture.coordinatesIndex, this.opacityTexture.level);
  980. this._uniformBuffer.updateMatrix("opacityMatrix", this.opacityTexture.getTextureMatrix());
  981. }
  982. if (this.reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  983. this._microsurfaceTextureLods.x = Math.round(Math.log(this.reflectionTexture.getSize().width) * Math.LOG2E);
  984. this._uniformBuffer.updateMatrix("reflectionMatrix", this.reflectionTexture.getReflectionTextureMatrix());
  985. this._uniformBuffer.updateFloat2("vReflectionInfos", this.reflectionTexture.level, 0);
  986. if (this._defines.USESPHERICALFROMREFLECTIONMAP) {
  987. var polynomials = this.reflectionTexture.sphericalPolynomial;
  988. this._effect.setFloat3("vSphericalX", polynomials.x.x, polynomials.x.y, polynomials.x.z);
  989. this._effect.setFloat3("vSphericalY", polynomials.y.x, polynomials.y.y, polynomials.y.z);
  990. this._effect.setFloat3("vSphericalZ", polynomials.z.x, polynomials.z.y, polynomials.z.z);
  991. this._effect.setFloat3("vSphericalXX_ZZ", polynomials.xx.x - polynomials.zz.x, polynomials.xx.y - polynomials.zz.y, polynomials.xx.z - polynomials.zz.z);
  992. this._effect.setFloat3("vSphericalYY_ZZ", polynomials.yy.x - polynomials.zz.x, polynomials.yy.y - polynomials.zz.y, polynomials.yy.z - polynomials.zz.z);
  993. this._effect.setFloat3("vSphericalZZ", polynomials.zz.x, polynomials.zz.y, polynomials.zz.z);
  994. this._effect.setFloat3("vSphericalXY", polynomials.xy.x, polynomials.xy.y, polynomials.xy.z);
  995. this._effect.setFloat3("vSphericalYZ", polynomials.yz.x, polynomials.yz.y, polynomials.yz.z);
  996. this._effect.setFloat3("vSphericalZX", polynomials.zx.x, polynomials.zx.y, polynomials.zx.z);
  997. }
  998. }
  999. if (this.emissiveTexture && BABYLON.StandardMaterial.EmissiveTextureEnabled) {
  1000. this._uniformBuffer.updateFloat2("vEmissiveInfos", this.emissiveTexture.coordinatesIndex, this.emissiveTexture.level);
  1001. this._uniformBuffer.updateMatrix("emissiveMatrix", this.emissiveTexture.getTextureMatrix());
  1002. }
  1003. if (this.lightmapTexture && BABYLON.StandardMaterial.LightmapTextureEnabled) {
  1004. this._uniformBuffer.updateFloat2("vLightmapInfos", this.lightmapTexture.coordinatesIndex, this.lightmapTexture.level);
  1005. this._uniformBuffer.updateMatrix("lightmapMatrix", this.lightmapTexture.getTextureMatrix());
  1006. }
  1007. if (BABYLON.StandardMaterial.SpecularTextureEnabled) {
  1008. if (this.metallicTexture) {
  1009. this._uniformBuffer.updateFloat3("vReflectivityInfos", this.metallicTexture.coordinatesIndex, this.metallicTexture.level, this.ambientTextureStrength);
  1010. this._uniformBuffer.updateMatrix("reflectivityMatrix", this.metallicTexture.getTextureMatrix());
  1011. }
  1012. else if (this.reflectivityTexture) {
  1013. this._uniformBuffer.updateFloat3("vReflectivityInfos", this.reflectivityTexture.coordinatesIndex, this.reflectivityTexture.level, 1.0);
  1014. this._uniformBuffer.updateMatrix("reflectivityMatrix", this.reflectivityTexture.getTextureMatrix());
  1015. }
  1016. if (this.microSurfaceTexture) {
  1017. this._uniformBuffer.updateFloat2("vMicroSurfaceSamplerInfos", this.microSurfaceTexture.coordinatesIndex, this.microSurfaceTexture.level);
  1018. this._uniformBuffer.updateMatrix("microSurfaceSamplerMatrix", this.microSurfaceTexture.getTextureMatrix());
  1019. }
  1020. }
  1021. if (this.bumpTexture && this._myScene.getEngine().getCaps().standardDerivatives && BABYLON.StandardMaterial.BumpTextureEnabled && !this.disableBumpMap) {
  1022. this._uniformBuffer.updateFloat3("vBumpInfos", this.bumpTexture.coordinatesIndex, 1.0 / this.bumpTexture.level, this.parallaxScaleBias);
  1023. this._uniformBuffer.updateMatrix("bumpMatrix", this.bumpTexture.getTextureMatrix());
  1024. if (this._myScene._mirroredCameraPosition) {
  1025. this._uniformBuffer.updateFloat2("vTangentSpaceParams", this.invertNormalMapX ? 1.0 : -1.0, this.invertNormalMapY ? 1.0 : -1.0);
  1026. }
  1027. else {
  1028. this._uniformBuffer.updateFloat2("vTangentSpaceParams", this.invertNormalMapX ? -1.0 : 1.0, this.invertNormalMapY ? -1.0 : 1.0);
  1029. }
  1030. }
  1031. if (this.refractionTexture && BABYLON.StandardMaterial.RefractionTextureEnabled) {
  1032. this._microsurfaceTextureLods.y = Math.round(Math.log(this.refractionTexture.getSize().width) * Math.LOG2E);
  1033. var depth = 1.0;
  1034. if (!this.refractionTexture.isCube) {
  1035. this._uniformBuffer.updateMatrix("refractionMatrix", this.refractionTexture.getReflectionTextureMatrix());
  1036. if (this.refractionTexture.depth) {
  1037. depth = this.refractionTexture.depth;
  1038. }
  1039. }
  1040. this._uniformBuffer.updateFloat4("vRefractionInfos", this.refractionTexture.level, this.indexOfRefraction, depth, this.invertRefractionY ? -1 : 1);
  1041. }
  1042. if ((this.reflectionTexture || this.refractionTexture)) {
  1043. this._uniformBuffer.updateFloat2("vMicrosurfaceTextureLods", this._microsurfaceTextureLods.x, this._microsurfaceTextureLods.y);
  1044. }
  1045. }
  1046. // Point size
  1047. if (this.pointsCloud) {
  1048. this._uniformBuffer.updateFloat("pointSize", this.pointSize);
  1049. }
  1050. // Colors
  1051. if (this._defines.METALLICWORKFLOW) {
  1052. LegacyPBRMaterial._scaledReflectivity.r = (this.metallic === undefined || this.metallic === null) ? 1 : this.metallic;
  1053. LegacyPBRMaterial._scaledReflectivity.g = (this.roughness === undefined || this.roughness === null) ? 1 : this.roughness;
  1054. this._uniformBuffer.updateColor4("vReflectivityColor", LegacyPBRMaterial._scaledReflectivity, 0);
  1055. }
  1056. else {
  1057. // GAMMA CORRECTION.
  1058. this.convertColorToLinearSpaceToRef(this.reflectivityColor, LegacyPBRMaterial._scaledReflectivity);
  1059. this._uniformBuffer.updateColor4("vReflectivityColor", LegacyPBRMaterial._scaledReflectivity, this.microSurface);
  1060. }
  1061. // GAMMA CORRECTION.
  1062. this.convertColorToLinearSpaceToRef(this.emissiveColor, LegacyPBRMaterial._scaledEmissive);
  1063. this._uniformBuffer.updateColor3("vEmissiveColor", LegacyPBRMaterial._scaledEmissive);
  1064. // GAMMA CORRECTION.
  1065. this.convertColorToLinearSpaceToRef(this.reflectionColor, LegacyPBRMaterial._scaledReflection);
  1066. this._uniformBuffer.updateColor3("vReflectionColor", LegacyPBRMaterial._scaledReflection);
  1067. // GAMMA CORRECTION.
  1068. this.convertColorToLinearSpaceToRef(this.albedoColor, LegacyPBRMaterial._scaledAlbedo);
  1069. this._uniformBuffer.updateColor4("vAlbedoColor", LegacyPBRMaterial._scaledAlbedo, this.alpha * mesh.visibility);
  1070. // Misc
  1071. this._lightingInfos.x = this.directIntensity;
  1072. this._lightingInfos.y = this.emissiveIntensity;
  1073. this._lightingInfos.z = this.environmentIntensity;
  1074. this._lightingInfos.w = this.specularIntensity;
  1075. this._uniformBuffer.updateVector4("vLightingIntensity", this._lightingInfos);
  1076. // Overloaded params
  1077. this._overloadedShadowInfos.x = this.overloadedShadowIntensity;
  1078. this._overloadedShadowInfos.y = this.overloadedShadeIntensity;
  1079. this._uniformBuffer.updateVector4("vOverloadedShadowIntensity", this._overloadedShadowInfos);
  1080. this._overloadedIntensity.x = this.overloadedAmbientIntensity;
  1081. this._overloadedIntensity.y = this.overloadedAlbedoIntensity;
  1082. this._overloadedIntensity.z = this.overloadedReflectivityIntensity;
  1083. this._overloadedIntensity.w = this.overloadedEmissiveIntensity;
  1084. this._uniformBuffer.updateVector4("vOverloadedIntensity", this._overloadedIntensity);
  1085. this._uniformBuffer.updateColor3("vOverloadedAmbient", this.overloadedAmbient);
  1086. this.convertColorToLinearSpaceToRef(this.overloadedAlbedo, this._tempColor);
  1087. this._uniformBuffer.updateColor3("vOverloadedAlbedo", this._tempColor);
  1088. this.convertColorToLinearSpaceToRef(this.overloadedReflectivity, this._tempColor);
  1089. this._uniformBuffer.updateColor3("vOverloadedReflectivity", this._tempColor);
  1090. this.convertColorToLinearSpaceToRef(this.overloadedEmissive, this._tempColor);
  1091. this._uniformBuffer.updateColor3("vOverloadedEmissive", this._tempColor);
  1092. this.convertColorToLinearSpaceToRef(this.overloadedReflection, this._tempColor);
  1093. this._uniformBuffer.updateColor3("vOverloadedReflection", this._tempColor);
  1094. this._overloadedMicroSurface.x = this.overloadedMicroSurface;
  1095. this._overloadedMicroSurface.y = this.overloadedMicroSurfaceIntensity;
  1096. this._overloadedMicroSurface.z = this.overloadedReflectionIntensity;
  1097. this._uniformBuffer.updateVector3("vOverloadedMicroSurface", this._overloadedMicroSurface);
  1098. }
  1099. // Textures
  1100. if (this._myScene.texturesEnabled) {
  1101. if (this.albedoTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  1102. this._uniformBuffer.setTexture("albedoSampler", this.albedoTexture);
  1103. }
  1104. if (this.ambientTexture && BABYLON.StandardMaterial.AmbientTextureEnabled) {
  1105. this._uniformBuffer.setTexture("ambientSampler", this.ambientTexture);
  1106. }
  1107. if (this.opacityTexture && BABYLON.StandardMaterial.OpacityTextureEnabled) {
  1108. this._uniformBuffer.setTexture("opacitySampler", this.opacityTexture);
  1109. }
  1110. if (this.reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  1111. if (this.reflectionTexture.isCube) {
  1112. this._uniformBuffer.setTexture("reflectionCubeSampler", this.reflectionTexture);
  1113. }
  1114. else {
  1115. this._uniformBuffer.setTexture("reflection2DSampler", this.reflectionTexture);
  1116. }
  1117. }
  1118. if (this.emissiveTexture && BABYLON.StandardMaterial.EmissiveTextureEnabled) {
  1119. this._uniformBuffer.setTexture("emissiveSampler", this.emissiveTexture);
  1120. }
  1121. if (this.lightmapTexture && BABYLON.StandardMaterial.LightmapTextureEnabled) {
  1122. this._uniformBuffer.setTexture("lightmapSampler", this.lightmapTexture);
  1123. }
  1124. if (BABYLON.StandardMaterial.SpecularTextureEnabled) {
  1125. if (this.metallicTexture) {
  1126. this._uniformBuffer.setTexture("reflectivitySampler", this.metallicTexture);
  1127. }
  1128. else if (this.reflectivityTexture) {
  1129. this._uniformBuffer.setTexture("reflectivitySampler", this.reflectivityTexture);
  1130. }
  1131. if (this.microSurfaceTexture) {
  1132. this._uniformBuffer.setTexture("microSurfaceSampler", this.microSurfaceTexture);
  1133. }
  1134. }
  1135. if (this.bumpTexture && this._myScene.getEngine().getCaps().standardDerivatives && BABYLON.StandardMaterial.BumpTextureEnabled && !this.disableBumpMap) {
  1136. this._uniformBuffer.setTexture("bumpSampler", this.bumpTexture);
  1137. }
  1138. if (this.refractionTexture && BABYLON.StandardMaterial.RefractionTextureEnabled) {
  1139. if (this.refractionTexture.isCube) {
  1140. this._uniformBuffer.setTexture("refractionCubeSampler", this.refractionTexture);
  1141. }
  1142. else {
  1143. this._uniformBuffer.setTexture("refraction2DSampler", this.refractionTexture);
  1144. }
  1145. }
  1146. if (this.cameraColorGradingTexture && BABYLON.StandardMaterial.ColorGradingTextureEnabled) {
  1147. this._effect.setTexture("cameraColorGrading2DSampler", this.cameraColorGradingTexture);
  1148. var x = this.cameraColorGradingTexture.level; // Texture Level
  1149. var y = this.cameraColorGradingTexture.getSize().height; // Texture Size example with 8
  1150. var z = y - 1.0; // SizeMinusOne 8 - 1
  1151. var w = 1 / y; // Space of 1 slice 1 / 8
  1152. this._effect.setFloat4("vCameraColorGradingInfos", x, y, z, w);
  1153. var slicePixelSizeU = w / y; // Space of 1 pixel in U direction, e.g. 1/64
  1154. var slicePixelSizeV = w; // Space of 1 pixel in V direction, e.g. 1/8 // Space of 1 pixel in V direction, e.g. 1/8
  1155. var x2 = z * slicePixelSizeU; // Extent of lookup range in U for a single slice so that range corresponds to (size-1) texels, for example 7/64
  1156. var y2 = z / y; // Extent of lookup range in V for a single slice so that range corresponds to (size-1) texels, for example 7/8
  1157. var z2 = 0.5 * slicePixelSizeU; // Offset of lookup range in U to align sample position with texel centre, for example 0.5/64
  1158. var w2 = 0.5 * slicePixelSizeV; // Offset of lookup range in V to align sample position with texel centre, for example 0.5/8
  1159. this._effect.setFloat4("vCameraColorGradingScaleOffset", x2, y2, z2, w2);
  1160. }
  1161. }
  1162. // Clip plane
  1163. BABYLON.MaterialHelper.BindClipPlane(this._effect, this._myScene);
  1164. // Colors
  1165. this._myScene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
  1166. effect.setVector3("vEyePosition", this._myScene._mirroredCameraPosition ? this._myScene._mirroredCameraPosition : this._myScene.activeCamera.position);
  1167. effect.setColor3("vAmbientColor", this._globalAmbientColor);
  1168. }
  1169. if (this._myScene.getCachedMaterial() !== this || !this.isFrozen) {
  1170. // Lights
  1171. if (this._myScene.lightsEnabled && !this.disableLighting) {
  1172. LegacyPBRMaterial.BindLights(this._myScene, mesh, this._effect, this._defines, this.useScalarInLinearSpace, this.maxSimultaneousLights, this.usePhysicalLightFalloff);
  1173. }
  1174. // View
  1175. if (this._myScene.fogEnabled && mesh.applyFog && this._myScene.fogMode !== BABYLON.Scene.FOGMODE_NONE || this.reflectionTexture) {
  1176. this.bindView(effect);
  1177. }
  1178. // Fog
  1179. BABYLON.MaterialHelper.BindFogParameters(this._myScene, mesh, this._effect);
  1180. // Morph targets
  1181. if (this._defines.NUM_MORPH_INFLUENCERS) {
  1182. BABYLON.MaterialHelper.BindMorphTargetParameters(mesh, this._effect);
  1183. }
  1184. this._cameraInfos.x = this.cameraExposure;
  1185. this._cameraInfos.y = this.cameraContrast;
  1186. effect.setVector4("vCameraInfos", this._cameraInfos);
  1187. if (this.cameraColorCurves) {
  1188. BABYLON.ColorCurves.Bind(this.cameraColorCurves, this._effect);
  1189. }
  1190. // Log. depth
  1191. BABYLON.MaterialHelper.BindLogDepth(this._defines, this._effect, this._myScene);
  1192. }
  1193. this._uniformBuffer.update();
  1194. this._afterBind(mesh);
  1195. this._myScene = null;
  1196. };
  1197. LegacyPBRMaterial.prototype.getAnimatables = function () {
  1198. var results = [];
  1199. if (this.albedoTexture && this.albedoTexture.animations && this.albedoTexture.animations.length > 0) {
  1200. results.push(this.albedoTexture);
  1201. }
  1202. if (this.ambientTexture && this.ambientTexture.animations && this.ambientTexture.animations.length > 0) {
  1203. results.push(this.ambientTexture);
  1204. }
  1205. if (this.opacityTexture && this.opacityTexture.animations && this.opacityTexture.animations.length > 0) {
  1206. results.push(this.opacityTexture);
  1207. }
  1208. if (this.reflectionTexture && this.reflectionTexture.animations && this.reflectionTexture.animations.length > 0) {
  1209. results.push(this.reflectionTexture);
  1210. }
  1211. if (this.emissiveTexture && this.emissiveTexture.animations && this.emissiveTexture.animations.length > 0) {
  1212. results.push(this.emissiveTexture);
  1213. }
  1214. if (this.metallicTexture && this.metallicTexture.animations && this.metallicTexture.animations.length > 0) {
  1215. results.push(this.metallicTexture);
  1216. }
  1217. else if (this.reflectivityTexture && this.reflectivityTexture.animations && this.reflectivityTexture.animations.length > 0) {
  1218. results.push(this.reflectivityTexture);
  1219. }
  1220. if (this.bumpTexture && this.bumpTexture.animations && this.bumpTexture.animations.length > 0) {
  1221. results.push(this.bumpTexture);
  1222. }
  1223. if (this.lightmapTexture && this.lightmapTexture.animations && this.lightmapTexture.animations.length > 0) {
  1224. results.push(this.lightmapTexture);
  1225. }
  1226. if (this.refractionTexture && this.refractionTexture.animations && this.refractionTexture.animations.length > 0) {
  1227. results.push(this.refractionTexture);
  1228. }
  1229. if (this.cameraColorGradingTexture && this.cameraColorGradingTexture.animations && this.cameraColorGradingTexture.animations.length > 0) {
  1230. results.push(this.cameraColorGradingTexture);
  1231. }
  1232. return results;
  1233. };
  1234. LegacyPBRMaterial.prototype.dispose = function (forceDisposeEffect, forceDisposeTextures) {
  1235. if (forceDisposeTextures) {
  1236. if (this.albedoTexture) {
  1237. this.albedoTexture.dispose();
  1238. }
  1239. if (this.ambientTexture) {
  1240. this.ambientTexture.dispose();
  1241. }
  1242. if (this.opacityTexture) {
  1243. this.opacityTexture.dispose();
  1244. }
  1245. if (this.reflectionTexture) {
  1246. this.reflectionTexture.dispose();
  1247. }
  1248. if (this.emissiveTexture) {
  1249. this.emissiveTexture.dispose();
  1250. }
  1251. if (this.metallicTexture) {
  1252. this.metallicTexture.dispose();
  1253. }
  1254. if (this.reflectivityTexture) {
  1255. this.reflectivityTexture.dispose();
  1256. }
  1257. if (this.bumpTexture) {
  1258. this.bumpTexture.dispose();
  1259. }
  1260. if (this.lightmapTexture) {
  1261. this.lightmapTexture.dispose();
  1262. }
  1263. if (this.refractionTexture) {
  1264. this.refractionTexture.dispose();
  1265. }
  1266. if (this.cameraColorGradingTexture) {
  1267. this.cameraColorGradingTexture.dispose();
  1268. }
  1269. }
  1270. this._renderTargets.dispose();
  1271. _super.prototype.dispose.call(this, forceDisposeEffect, forceDisposeTextures);
  1272. };
  1273. LegacyPBRMaterial.prototype.clone = function (name) {
  1274. var _this = this;
  1275. return BABYLON.SerializationHelper.Clone(function () { return new LegacyPBRMaterial(name, _this.getScene()); }, this);
  1276. };
  1277. LegacyPBRMaterial.prototype.serialize = function () {
  1278. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  1279. serializationObject.customType = "BABYLON.LegacyPBRMaterial";
  1280. return serializationObject;
  1281. };
  1282. // Statics
  1283. LegacyPBRMaterial.Parse = function (source, scene, rootUrl) {
  1284. return BABYLON.SerializationHelper.Parse(function () { return new LegacyPBRMaterial(source.name, scene); }, source, scene, rootUrl);
  1285. };
  1286. LegacyPBRMaterial._scaledAlbedo = new BABYLON.Color3();
  1287. LegacyPBRMaterial._scaledReflectivity = new BABYLON.Color3();
  1288. LegacyPBRMaterial._scaledEmissive = new BABYLON.Color3();
  1289. LegacyPBRMaterial._scaledReflection = new BABYLON.Color3();
  1290. __decorate([
  1291. BABYLON.serialize()
  1292. ], LegacyPBRMaterial.prototype, "directIntensity", void 0);
  1293. __decorate([
  1294. BABYLON.serialize()
  1295. ], LegacyPBRMaterial.prototype, "emissiveIntensity", void 0);
  1296. __decorate([
  1297. BABYLON.serialize()
  1298. ], LegacyPBRMaterial.prototype, "environmentIntensity", void 0);
  1299. __decorate([
  1300. BABYLON.serialize()
  1301. ], LegacyPBRMaterial.prototype, "specularIntensity", void 0);
  1302. __decorate([
  1303. BABYLON.serialize()
  1304. ], LegacyPBRMaterial.prototype, "disableBumpMap", void 0);
  1305. __decorate([
  1306. BABYLON.serialize()
  1307. ], LegacyPBRMaterial.prototype, "overloadedShadowIntensity", void 0);
  1308. __decorate([
  1309. BABYLON.serialize()
  1310. ], LegacyPBRMaterial.prototype, "overloadedShadeIntensity", void 0);
  1311. __decorate([
  1312. BABYLON.serialize()
  1313. ], LegacyPBRMaterial.prototype, "cameraExposure", void 0);
  1314. __decorate([
  1315. BABYLON.serialize()
  1316. ], LegacyPBRMaterial.prototype, "cameraContrast", void 0);
  1317. __decorate([
  1318. BABYLON.serializeAsTexture()
  1319. ], LegacyPBRMaterial.prototype, "cameraColorGradingTexture", void 0);
  1320. __decorate([
  1321. BABYLON.serializeAsColorCurves()
  1322. ], LegacyPBRMaterial.prototype, "cameraColorCurves", void 0);
  1323. __decorate([
  1324. BABYLON.serializeAsColor3()
  1325. ], LegacyPBRMaterial.prototype, "overloadedAmbient", void 0);
  1326. __decorate([
  1327. BABYLON.serialize()
  1328. ], LegacyPBRMaterial.prototype, "overloadedAmbientIntensity", void 0);
  1329. __decorate([
  1330. BABYLON.serializeAsColor3()
  1331. ], LegacyPBRMaterial.prototype, "overloadedAlbedo", void 0);
  1332. __decorate([
  1333. BABYLON.serialize()
  1334. ], LegacyPBRMaterial.prototype, "overloadedAlbedoIntensity", void 0);
  1335. __decorate([
  1336. BABYLON.serializeAsColor3()
  1337. ], LegacyPBRMaterial.prototype, "overloadedReflectivity", void 0);
  1338. __decorate([
  1339. BABYLON.serialize()
  1340. ], LegacyPBRMaterial.prototype, "overloadedReflectivityIntensity", void 0);
  1341. __decorate([
  1342. BABYLON.serializeAsColor3()
  1343. ], LegacyPBRMaterial.prototype, "overloadedEmissive", void 0);
  1344. __decorate([
  1345. BABYLON.serialize()
  1346. ], LegacyPBRMaterial.prototype, "overloadedEmissiveIntensity", void 0);
  1347. __decorate([
  1348. BABYLON.serializeAsColor3()
  1349. ], LegacyPBRMaterial.prototype, "overloadedReflection", void 0);
  1350. __decorate([
  1351. BABYLON.serialize()
  1352. ], LegacyPBRMaterial.prototype, "overloadedReflectionIntensity", void 0);
  1353. __decorate([
  1354. BABYLON.serialize()
  1355. ], LegacyPBRMaterial.prototype, "overloadedMicroSurface", void 0);
  1356. __decorate([
  1357. BABYLON.serialize()
  1358. ], LegacyPBRMaterial.prototype, "overloadedMicroSurfaceIntensity", void 0);
  1359. __decorate([
  1360. BABYLON.serializeAsTexture()
  1361. ], LegacyPBRMaterial.prototype, "albedoTexture", void 0);
  1362. __decorate([
  1363. BABYLON.serializeAsTexture()
  1364. ], LegacyPBRMaterial.prototype, "ambientTexture", void 0);
  1365. __decorate([
  1366. BABYLON.serialize()
  1367. ], LegacyPBRMaterial.prototype, "ambientTextureStrength", void 0);
  1368. __decorate([
  1369. BABYLON.serializeAsTexture()
  1370. ], LegacyPBRMaterial.prototype, "opacityTexture", void 0);
  1371. __decorate([
  1372. BABYLON.serializeAsTexture()
  1373. ], LegacyPBRMaterial.prototype, "reflectionTexture", void 0);
  1374. __decorate([
  1375. BABYLON.serializeAsTexture()
  1376. ], LegacyPBRMaterial.prototype, "emissiveTexture", void 0);
  1377. __decorate([
  1378. BABYLON.serializeAsTexture()
  1379. ], LegacyPBRMaterial.prototype, "reflectivityTexture", void 0);
  1380. __decorate([
  1381. BABYLON.serializeAsTexture()
  1382. ], LegacyPBRMaterial.prototype, "metallicTexture", void 0);
  1383. __decorate([
  1384. BABYLON.serialize()
  1385. ], LegacyPBRMaterial.prototype, "metallic", void 0);
  1386. __decorate([
  1387. BABYLON.serialize()
  1388. ], LegacyPBRMaterial.prototype, "roughness", void 0);
  1389. __decorate([
  1390. BABYLON.serializeAsTexture()
  1391. ], LegacyPBRMaterial.prototype, "microSurfaceTexture", void 0);
  1392. __decorate([
  1393. BABYLON.serializeAsTexture()
  1394. ], LegacyPBRMaterial.prototype, "bumpTexture", void 0);
  1395. __decorate([
  1396. BABYLON.serializeAsTexture()
  1397. ], LegacyPBRMaterial.prototype, "lightmapTexture", void 0);
  1398. __decorate([
  1399. BABYLON.serializeAsTexture()
  1400. ], LegacyPBRMaterial.prototype, "refractionTexture", void 0);
  1401. __decorate([
  1402. BABYLON.serializeAsColor3("ambient")
  1403. ], LegacyPBRMaterial.prototype, "ambientColor", void 0);
  1404. __decorate([
  1405. BABYLON.serializeAsColor3("albedo")
  1406. ], LegacyPBRMaterial.prototype, "albedoColor", void 0);
  1407. __decorate([
  1408. BABYLON.serializeAsColor3("reflectivity")
  1409. ], LegacyPBRMaterial.prototype, "reflectivityColor", void 0);
  1410. __decorate([
  1411. BABYLON.serializeAsColor3("reflection")
  1412. ], LegacyPBRMaterial.prototype, "reflectionColor", void 0);
  1413. __decorate([
  1414. BABYLON.serializeAsColor3("emissive")
  1415. ], LegacyPBRMaterial.prototype, "emissiveColor", void 0);
  1416. __decorate([
  1417. BABYLON.serialize()
  1418. ], LegacyPBRMaterial.prototype, "microSurface", void 0);
  1419. __decorate([
  1420. BABYLON.serialize()
  1421. ], LegacyPBRMaterial.prototype, "indexOfRefraction", void 0);
  1422. __decorate([
  1423. BABYLON.serialize()
  1424. ], LegacyPBRMaterial.prototype, "invertRefractionY", void 0);
  1425. __decorate([
  1426. BABYLON.serializeAsFresnelParameters()
  1427. ], LegacyPBRMaterial.prototype, "opacityFresnelParameters", void 0);
  1428. __decorate([
  1429. BABYLON.serializeAsFresnelParameters()
  1430. ], LegacyPBRMaterial.prototype, "emissiveFresnelParameters", void 0);
  1431. __decorate([
  1432. BABYLON.serialize()
  1433. ], LegacyPBRMaterial.prototype, "linkRefractionWithTransparency", void 0);
  1434. __decorate([
  1435. BABYLON.serialize()
  1436. ], LegacyPBRMaterial.prototype, "linkEmissiveWithAlbedo", void 0);
  1437. __decorate([
  1438. BABYLON.serialize()
  1439. ], LegacyPBRMaterial.prototype, "useLightmapAsShadowmap", void 0);
  1440. __decorate([
  1441. BABYLON.serialize()
  1442. ], LegacyPBRMaterial.prototype, "useEmissiveAsIllumination", void 0);
  1443. __decorate([
  1444. BABYLON.serialize()
  1445. ], LegacyPBRMaterial.prototype, "useAlphaFromAlbedoTexture", void 0);
  1446. __decorate([
  1447. BABYLON.serialize()
  1448. ], LegacyPBRMaterial.prototype, "useSpecularOverAlpha", void 0);
  1449. __decorate([
  1450. BABYLON.serialize()
  1451. ], LegacyPBRMaterial.prototype, "useMicroSurfaceFromReflectivityMapAlpha", void 0);
  1452. __decorate([
  1453. BABYLON.serialize()
  1454. ], LegacyPBRMaterial.prototype, "useRoughnessFromMetallicTextureAlpha", void 0);
  1455. __decorate([
  1456. BABYLON.serialize()
  1457. ], LegacyPBRMaterial.prototype, "useRoughnessFromMetallicTextureGreen", void 0);
  1458. __decorate([
  1459. BABYLON.serialize()
  1460. ], LegacyPBRMaterial.prototype, "useMetallnessFromMetallicTextureBlue", void 0);
  1461. __decorate([
  1462. BABYLON.serialize()
  1463. ], LegacyPBRMaterial.prototype, "useAmbientOcclusionFromMetallicTextureRed", void 0);
  1464. __decorate([
  1465. BABYLON.serialize()
  1466. ], LegacyPBRMaterial.prototype, "useAmbientInGrayScale", void 0);
  1467. __decorate([
  1468. BABYLON.serialize()
  1469. ], LegacyPBRMaterial.prototype, "useAutoMicroSurfaceFromReflectivityMap", void 0);
  1470. __decorate([
  1471. BABYLON.serialize()
  1472. ], LegacyPBRMaterial.prototype, "useScalarInLinearSpace", void 0);
  1473. __decorate([
  1474. BABYLON.serialize()
  1475. ], LegacyPBRMaterial.prototype, "usePhysicalLightFalloff", void 0);
  1476. __decorate([
  1477. BABYLON.serialize()
  1478. ], LegacyPBRMaterial.prototype, "useRadianceOverAlpha", void 0);
  1479. __decorate([
  1480. BABYLON.serialize()
  1481. ], LegacyPBRMaterial.prototype, "useParallax", void 0);
  1482. __decorate([
  1483. BABYLON.serialize()
  1484. ], LegacyPBRMaterial.prototype, "useParallaxOcclusion", void 0);
  1485. __decorate([
  1486. BABYLON.serialize()
  1487. ], LegacyPBRMaterial.prototype, "parallaxScaleBias", void 0);
  1488. __decorate([
  1489. BABYLON.serialize()
  1490. ], LegacyPBRMaterial.prototype, "disableLighting", void 0);
  1491. __decorate([
  1492. BABYLON.serialize()
  1493. ], LegacyPBRMaterial.prototype, "maxSimultaneousLights", void 0);
  1494. __decorate([
  1495. BABYLON.serialize()
  1496. ], LegacyPBRMaterial.prototype, "invertNormalMapX", void 0);
  1497. __decorate([
  1498. BABYLON.serialize()
  1499. ], LegacyPBRMaterial.prototype, "invertNormalMapY", void 0);
  1500. __decorate([
  1501. BABYLON.serialize()
  1502. ], LegacyPBRMaterial.prototype, "twoSidedLighting", void 0);
  1503. __decorate([
  1504. BABYLON.serialize()
  1505. ], LegacyPBRMaterial.prototype, "useLogarithmicDepth", null);
  1506. return LegacyPBRMaterial;
  1507. }(BABYLON.Material));
  1508. BABYLON.LegacyPBRMaterial = LegacyPBRMaterial;
  1509. })(BABYLON || (BABYLON = {}));
  1510. //# sourceMappingURL=babylon.legacyPBRMaterial.js.map
  1511. BABYLON.Effect.ShadersStore['legacyPbrVertexShader'] = "precision highp float;\n#include<__decl__legacyPbrVertex>\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef TANGENT\nattribute vec4 tangent;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\n#ifdef ALBEDO\nvarying vec2 vAlbedoUV;\n#endif\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\n#endif\n#ifdef OPACITY\nvarying vec2 vOpacityUV;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\n#endif\n#ifdef LIGHTMAP\nvarying vec2 vLightmapUV;\n#endif\n#if defined(REFLECTIVITY) || defined(METALLICWORKFLOW) \nvarying vec2 vReflectivityUV;\n#endif\n#ifdef MICROSURFACEMAP\nvarying vec2 vMicroSurfaceSamplerUV;\n#endif\n#ifdef BUMP\nvarying vec2 vBumpUV;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<bumpVertexDeclaration>\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<morphTargetsVertexGlobalDeclaration>\n#include<morphTargetsVertexDeclaration>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#include<logDepthDeclaration>\nvoid main(void) {\nvec3 positionUpdated=position;\n#ifdef NORMAL\nvec3 normalUpdated=normal;\n#endif\n#ifdef TANGENT\nvec4 tangentUpdated=tangent;\n#endif\n#include<morphTargetsVertex>[0..maxSimultaneousMorphTargets]\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=positionUpdated;\n#endif \n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(positionUpdated,1.0);\nvec4 worldPos=finalWorld*vec4(positionUpdated,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normalUpdated,0.0)));\n#endif\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvDirectionW=normalize(vec3(finalWorld*vec4(positionUpdated,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef ALBEDO\nif (vAlbedoInfos.x == 0.)\n{\nvAlbedoUV=vec2(albedoMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAlbedoUV=vec2(albedoMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef AMBIENT\nif (vAmbientInfos.x == 0.)\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef OPACITY\nif (vOpacityInfos.x == 0.)\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef EMISSIVE\nif (vEmissiveInfos.x == 0.)\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef LIGHTMAP\nif (vLightmapInfos.x == 0.)\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(REFLECTIVITY) || defined(METALLICWORKFLOW) \nif (vReflectivityInfos.x == 0.)\n{\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef MICROSURFACEMAP\nif (vMicroSurfaceSamplerInfos.x == 0.)\n{\nvMicroSurfaceSamplerUV=vec2(microSurfaceSamplerMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvMicroSurfaceSamplerUV=vec2(microSurfaceSamplerMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef BUMP\nif (vBumpInfos.x == 0.)\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include<bumpVertex>\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n\n#include<logDepthVertex>\n}";
  1512. BABYLON.Effect.ShadersStore['legacyPbrPixelShader'] = "#if defined(BUMP)|| !defined(NORMAL)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#ifdef LODBASEDMICROSFURACE\n#extension GL_EXT_shader_texture_lod : enable\n#endif\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nprecision highp float;\n#include<__decl__legacyPbrFragment>\nuniform vec3 vEyePosition;\nuniform vec3 vAmbientColor;\nuniform vec4 vCameraInfos;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n#ifdef ALBEDO\nvarying vec2 vAlbedoUV;\nuniform sampler2D albedoSampler;\n#endif\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform sampler2D ambientSampler;\n#endif\n#ifdef OPACITY \nvarying vec2 vOpacityUV;\nuniform sampler2D opacitySampler;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\nvarying vec2 vLightmapUV;\nuniform sampler2D lightmapSampler;\n#endif\n#if defined(REFLECTIVITY) || defined(METALLICWORKFLOW) \nvarying vec2 vReflectivityUV;\nuniform sampler2D reflectivitySampler;\n#endif\n#ifdef MICROSURFACEMAP\nvarying vec2 vMicroSurfaceSamplerUV;\nuniform sampler2D microSurfaceSampler;\n#endif\n\n#include<fresnelFunction>\n\n#ifdef REFRACTION\n#ifdef REFRACTIONMAP_3D\nuniform samplerCube refractionCubeSampler;\n#else\nuniform sampler2D refraction2DSampler;\n#endif\n#endif\n\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\nuniform samplerCube reflectionCubeSampler;\n#else\nuniform sampler2D reflection2DSampler;\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include<reflectionFunction>\n#endif\n#ifdef CAMERACOLORGRADING\n#include<legacyColorGradingDefinition>\n#endif\n#ifdef CAMERACOLORCURVES\n#include<legacyColorCurvesDefinition>\n#endif\n\n#include<shadowsFragmentFunctions>\n#include<legacyPbrFunctions>\n#ifdef CAMERACOLORGRADING\n#include<legacyColorGrading>\n#endif\n#ifdef CAMERACOLORCURVES\n#include<legacyColorCurves>\n#endif\n#include<legacyPbrLightFunctions>\n#include<bumpFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\n\n#include<fogFragmentDeclaration>\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=normalize(cross(dFdx(vPositionW),dFdy(vPositionW)));\n#endif\n#include<bumpFragment>\n#ifdef TWOSIDEDLIGHTING\nnormalW=gl_FrontFacing ? normalW : -normalW;\n#endif\n\nvec4 surfaceAlbedo=vec4(1.,1.,1.,1.);\nvec3 surfaceAlbedoContribution=vAlbedoColor.rgb;\n\nfloat alpha=vAlbedoColor.a;\n#ifdef ALBEDO\nsurfaceAlbedo=texture2D(albedoSampler,vAlbedoUV+uvOffset);\nsurfaceAlbedo=vec4(toLinearSpace(surfaceAlbedo.rgb),surfaceAlbedo.a);\n#ifndef LINKREFRACTIONTOTRANSPARENCY\n#ifdef ALPHATEST\nif (surfaceAlbedo.a<0.4)\ndiscard;\n#endif\n#endif\n#ifdef ALPHAFROMALBEDO\nalpha*=surfaceAlbedo.a;\n#endif\nsurfaceAlbedo.rgb*=vAlbedoInfos.y;\n#else\n\nsurfaceAlbedo.rgb=surfaceAlbedoContribution;\nsurfaceAlbedoContribution=vec3(1.,1.,1.);\n#endif\n#ifdef VERTEXCOLOR\nsurfaceAlbedo.rgb*=vColor.rgb;\n#endif\n#ifdef OVERLOADEDVALUES\nsurfaceAlbedo.rgb=mix(surfaceAlbedo.rgb,vOverloadedAlbedo,vOverloadedIntensity.y);\n#endif\n\nvec3 ambientOcclusionColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nvec3 ambientOcclusionColorMap=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;\n#ifdef AMBIENTINGRAYSCALE \nambientOcclusionColorMap=vec3(ambientOcclusionColorMap.r,ambientOcclusionColorMap.r,ambientOcclusionColorMap.r);\n#endif\nambientOcclusionColor=mix(ambientOcclusionColor,ambientOcclusionColorMap,vAmbientInfos.z);\n#ifdef OVERLOADEDVALUES\nambientOcclusionColor.rgb=mix(ambientOcclusionColor.rgb,vOverloadedAmbient,vOverloadedIntensity.x);\n#endif\n#endif\n\nfloat microSurface=vReflectivityColor.a;\nvec3 surfaceReflectivityColor=vReflectivityColor.rgb;\n#ifdef REFLECTIVITY\nvec4 surfaceReflectivityColorMap=texture2D(reflectivitySampler,vReflectivityUV+uvOffset);\nsurfaceReflectivityColor=surfaceReflectivityColorMap.rgb;\nsurfaceReflectivityColor=toLinearSpace(surfaceReflectivityColor);\nsurfaceReflectivityColor*=vReflectivityInfos.y;\n#ifdef OVERLOADEDVALUES\nsurfaceReflectivityColor=mix(surfaceReflectivityColor,vOverloadedReflectivity,vOverloadedIntensity.z);\n#endif\n#ifdef MICROSURFACEFROMREFLECTIVITYMAP\nmicroSurface=surfaceReflectivityColorMap.a*vReflectivityInfos.z;\n#else\n#ifdef MICROSURFACEAUTOMATIC\nmicroSurface=computeDefaultMicroSurface(microSurface,surfaceReflectivityColor);\n#endif\n#endif\n#else\n#ifdef OVERLOADEDVALUES\nsurfaceReflectivityColor=mix(surfaceReflectivityColor,vOverloadedReflectivity,vOverloadedIntensity.z);\n#endif\n#endif\n#ifdef METALLICWORKFLOW\nvec2 metallicRoughness=surfaceReflectivityColor.rg;\n#ifdef METALLICMAP\nvec4 surfaceMetallicColorMap=texture2D(reflectivitySampler,vReflectivityUV+uvOffset);\n#ifdef AOSTOREINMETALMAPRED \nvec3 aoStoreInMetalMap=vec3(surfaceMetallicColorMap.r,surfaceMetallicColorMap.r,surfaceMetallicColorMap.r);\nambientOcclusionColor=mix(ambientOcclusionColor,aoStoreInMetalMap,vReflectivityInfos.z);\n#endif\n#ifdef METALLNESSSTOREINMETALMAPBLUE\nmetallicRoughness.r*=surfaceMetallicColorMap.b;\n#else\nmetallicRoughness.r*=surfaceMetallicColorMap.r;\n#endif\n#ifdef ROUGHNESSSTOREINMETALMAPALPHA\nmetallicRoughness.g*=surfaceMetallicColorMap.a;\n#else\n#ifdef ROUGHNESSSTOREINMETALMAPGREEN\nmetallicRoughness.g*=surfaceMetallicColorMap.g;\n#endif\n#endif\n#endif\n#ifdef MICROSURFACEMAP\nvec4 microSurfaceTexel=texture2D(microSurfaceSampler,vMicroSurfaceSamplerUV+uvOffset)*vMicroSurfaceSamplerInfos.y;\nmetallicRoughness.g*=microSurfaceTexel.r;\n#endif\n\nmicroSurface=1.0-metallicRoughness.g;\n\nvec3 baseColor=surfaceAlbedo.rgb;\n\n\nconst vec3 DefaultSpecularReflectanceDielectric=vec3(0.04,0.04,0.04);\n\nsurfaceAlbedo.rgb=mix(baseColor.rgb*(1.0-DefaultSpecularReflectanceDielectric.r),vec3(0.,0.,0.),metallicRoughness.r);\n\nsurfaceReflectivityColor=mix(DefaultSpecularReflectanceDielectric,baseColor,metallicRoughness.r);\n#ifdef OVERLOADEDVALUES\nsurfaceReflectivityColor=mix(surfaceReflectivityColor,vOverloadedReflectivity,vOverloadedIntensity.z);\n#endif\n#else\n#ifdef MICROSURFACEMAP\nvec4 microSurfaceTexel=texture2D(microSurfaceSampler,vMicroSurfaceSamplerUV+uvOffset)*vMicroSurfaceSamplerInfos.y;\nmicroSurface=microSurfaceTexel.r;\n#endif\n#endif\n#ifdef OVERLOADEDVALUES\nmicroSurface=mix(microSurface,vOverloadedMicroSurface.x,vOverloadedMicroSurface.y);\n#endif\n\nfloat NdotV=max(0.00000000001,dot(normalW,viewDirectionW));\n\nmicroSurface=clamp(microSurface,0.,1.)*0.98;\n\nfloat roughness=clamp(1.-microSurface,0.000001,1.0);\n\nvec3 lightDiffuseContribution=vec3(0.,0.,0.);\n#ifdef OVERLOADEDSHADOWVALUES\nvec3 shadowedOnlyLightDiffuseContribution=vec3(1.,1.,1.);\n#endif\n#ifdef SPECULARTERM\nvec3 lightSpecularContribution=vec3(0.,0.,0.);\n#endif\nfloat notShadowLevel=1.; \n#ifdef LIGHTMAP\nvec3 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset).rgb*vLightmapInfos.y;\n#endif\nfloat NdotL=-1.;\nlightingInfo info;\n\nfloat reflectance=max(max(surfaceReflectivityColor.r,surfaceReflectivityColor.g),surfaceReflectivityColor.b);\n\n\nfloat reflectance90=clamp(reflectance*25.0,0.0,1.0);\nvec3 specularEnvironmentR0=surfaceReflectivityColor.rgb;\nvec3 specularEnvironmentR90=vec3(1.0,1.0,1.0)*reflectance90;\n#include<legacyPbrLightFunctionsCall>[0..maxSimultaneousLights]\n#ifdef SPECULARTERM\nlightSpecularContribution*=vLightingIntensity.w;\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n#ifdef OPACITYRGB\nopacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);\nalpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n#else\nalpha*=opacityMap.a*vOpacityInfos.y;\n#endif\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef OPACITYFRESNEL\nfloat opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);\nalpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;\n#endif\n\nvec3 surfaceRefractionColor=vec3(0.,0.,0.);\n\n#ifdef LODBASEDMICROSFURACE\nfloat alphaG=convertRoughnessToAverageSlope(roughness);\n#endif\n#ifdef REFRACTION\nvec3 refractionVector=refract(-viewDirectionW,normalW,vRefractionInfos.y);\n#ifdef LODBASEDMICROSFURACE\n#ifdef USEPMREMREFRACTION\nfloat lodRefraction=getMipMapIndexFromAverageSlopeWithPMREM(vMicrosurfaceTextureLods.y,alphaG);\n#else\nfloat lodRefraction=getMipMapIndexFromAverageSlope(vMicrosurfaceTextureLods.y,alphaG);\n#endif\n#else\nfloat biasRefraction=(vMicrosurfaceTextureLods.y+2.)*(1.0-microSurface);\n#endif\n#ifdef REFRACTIONMAP_3D\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;\nif (dot(refractionVector,viewDirectionW)<1.0)\n{\n#ifdef LODBASEDMICROSFURACE\n#ifdef USEPMREMREFRACTION\n\nif ((vMicrosurfaceTextureLods.y-lodRefraction)>4.0)\n{\n\nfloat scaleRefraction=1.-exp2(lodRefraction)/exp2(vMicrosurfaceTextureLods.y); \nfloat maxRefraction=max(max(abs(refractionVector.x),abs(refractionVector.y)),abs(refractionVector.z));\nif (abs(refractionVector.x) != maxRefraction) refractionVector.x*=scaleRefraction;\nif (abs(refractionVector.y) != maxRefraction) refractionVector.y*=scaleRefraction;\nif (abs(refractionVector.z) != maxRefraction) refractionVector.z*=scaleRefraction;\n}\n#endif\nsurfaceRefractionColor=textureCubeLodEXT(refractionCubeSampler,refractionVector,lodRefraction).rgb*vRefractionInfos.x;\n#else\nsurfaceRefractionColor=textureCube(refractionCubeSampler,refractionVector,biasRefraction).rgb*vRefractionInfos.x;\n#endif\n}\n#ifndef REFRACTIONMAPINLINEARSPACE\nsurfaceRefractionColor=toLinearSpace(surfaceRefractionColor.rgb);\n#endif\n#else\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));\nvec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;\nrefractionCoords.y=1.0-refractionCoords.y;\n#ifdef LODBASEDMICROSFURACE\nsurfaceRefractionColor=texture2DLodEXT(refraction2DSampler,refractionCoords,lodRefraction).rgb*vRefractionInfos.x;\n#else\nsurfaceRefractionColor=texture2D(refraction2DSampler,refractionCoords,biasRefraction).rgb*vRefractionInfos.x;\n#endif \nsurfaceRefractionColor=toLinearSpace(surfaceRefractionColor.rgb);\n#endif\n#endif\n\nvec3 environmentRadiance=vReflectionColor.rgb;\nvec3 environmentIrradiance=vReflectionColor.rgb;\n#ifdef REFLECTION\nvec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef LODBASEDMICROSFURACE\n#ifdef USEPMREMREFLECTION\nfloat lodReflection=getMipMapIndexFromAverageSlopeWithPMREM(vMicrosurfaceTextureLods.x,alphaG);\n#else\nfloat lodReflection=getMipMapIndexFromAverageSlope(vMicrosurfaceTextureLods.x,alphaG);\n#endif\n#else\nfloat biasReflection=(vMicrosurfaceTextureLods.x+2.)*(1.0-microSurface);\n#endif\n#ifdef REFLECTIONMAP_3D\n#ifdef LODBASEDMICROSFURACE\n#ifdef USEPMREMREFLECTION\n\nif ((vMicrosurfaceTextureLods.y-lodReflection)>4.0)\n{\n\nfloat scaleReflection=1.-exp2(lodReflection)/exp2(vMicrosurfaceTextureLods.x); \nfloat maxReflection=max(max(abs(vReflectionUVW.x),abs(vReflectionUVW.y)),abs(vReflectionUVW.z));\nif (abs(vReflectionUVW.x) != maxReflection) vReflectionUVW.x*=scaleReflection;\nif (abs(vReflectionUVW.y) != maxReflection) vReflectionUVW.y*=scaleReflection;\nif (abs(vReflectionUVW.z) != maxReflection) vReflectionUVW.z*=scaleReflection;\n}\n#endif\nenvironmentRadiance=textureCubeLodEXT(reflectionCubeSampler,vReflectionUVW,lodReflection).rgb*vReflectionInfos.x;\n#else\nenvironmentRadiance=textureCube(reflectionCubeSampler,vReflectionUVW,biasReflection).rgb*vReflectionInfos.x;\n#endif\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#ifndef REFLECTIONMAP_SKYBOX\nvec3 normalEnvironmentSpace=(reflectionMatrix*vec4(normalW,1)).xyz;\nenvironmentIrradiance=EnvironmentIrradiance(normalEnvironmentSpace);\n#endif\n#else\nenvironmentRadiance=toLinearSpace(environmentRadiance.rgb);\nenvironmentIrradiance=textureCube(reflectionCubeSampler,normalW,20.).rgb*vReflectionInfos.x;\nenvironmentIrradiance=toLinearSpace(environmentIrradiance.rgb);\nenvironmentIrradiance*=0.2; \n#endif\n#else\nvec2 coords=vReflectionUVW.xy;\n#ifdef REFLECTIONMAP_PROJECTION\ncoords/=vReflectionUVW.z;\n#endif\ncoords.y=1.0-coords.y;\n#ifdef LODBASEDMICROSFURACE\nenvironmentRadiance=texture2DLodEXT(reflection2DSampler,coords,lodReflection).rgb*vReflectionInfos.x;\n#else\nenvironmentRadiance=texture2D(reflection2DSampler,coords,biasReflection).rgb*vReflectionInfos.x;\n#endif\nenvironmentRadiance=toLinearSpace(environmentRadiance.rgb);\nenvironmentIrradiance=texture2D(reflection2DSampler,coords,20.).rgb*vReflectionInfos.x;\nenvironmentIrradiance=toLinearSpace(environmentIrradiance.rgb);\n#endif\n#endif\n#ifdef OVERLOADEDVALUES\nenvironmentIrradiance=mix(environmentIrradiance,vOverloadedReflection,vOverloadedMicroSurface.z);\nenvironmentRadiance=mix(environmentRadiance,vOverloadedReflection,vOverloadedMicroSurface.z);\n#endif\nenvironmentRadiance*=vLightingIntensity.z;\nenvironmentIrradiance*=vLightingIntensity.z;\n\nvec3 specularEnvironmentReflectance=FresnelSchlickEnvironmentGGX(clamp(NdotV,0.,1.),specularEnvironmentR0,specularEnvironmentR90,sqrt(microSurface));\n\nvec3 refractance=vec3(0.0,0.0,0.0);\n#ifdef REFRACTION\nvec3 transmission=vec3(1.0,1.0,1.0);\n#ifdef LINKREFRACTIONTOTRANSPARENCY\n\ntransmission*=(1.0-alpha);\n\n\nvec3 mixedAlbedo=surfaceAlbedoContribution.rgb*surfaceAlbedo.rgb;\nfloat maxChannel=max(max(mixedAlbedo.r,mixedAlbedo.g),mixedAlbedo.b);\nvec3 tint=clamp(maxChannel*mixedAlbedo,0.0,1.0);\n\nsurfaceAlbedoContribution*=alpha;\n\nenvironmentIrradiance*=alpha;\n\nsurfaceRefractionColor*=tint;\n\nalpha=1.0;\n#endif\n\nvec3 bounceSpecularEnvironmentReflectance=(2.0*specularEnvironmentReflectance)/(1.0+specularEnvironmentReflectance);\nspecularEnvironmentReflectance=mix(bounceSpecularEnvironmentReflectance,specularEnvironmentReflectance,alpha);\n\ntransmission*=1.0-specularEnvironmentReflectance;\n\nrefractance=surfaceRefractionColor*transmission;\n#endif\n\nsurfaceAlbedo.rgb=(1.-reflectance)*surfaceAlbedo.rgb;\nrefractance*=vLightingIntensity.z;\nenvironmentRadiance*=specularEnvironmentReflectance;\n\nvec3 surfaceEmissiveColor=vEmissiveColor;\n#ifdef EMISSIVE\nvec3 emissiveColorTex=texture2D(emissiveSampler,vEmissiveUV+uvOffset).rgb;\nsurfaceEmissiveColor=toLinearSpace(emissiveColorTex.rgb)*surfaceEmissiveColor*vEmissiveInfos.y;\n#endif\n#ifdef OVERLOADEDVALUES\nsurfaceEmissiveColor=mix(surfaceEmissiveColor,vOverloadedEmissive,vOverloadedIntensity.w);\n#endif\n#ifdef EMISSIVEFRESNEL\nfloat emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);\nsurfaceEmissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec3 finalDiffuse=lightDiffuseContribution*surfaceAlbedoContribution;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=shadowedOnlyLightDiffuseContribution*surfaceAlbedoContribution;\n#endif\n#else\n#ifdef LINKEMISSIVEWITHALBEDO\nvec3 finalDiffuse=(lightDiffuseContribution+surfaceEmissiveColor)*surfaceAlbedoContribution;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=(shadowedOnlyLightDiffuseContribution+surfaceEmissiveColor)*surfaceAlbedoContribution;\n#endif\n#else\nvec3 finalDiffuse=lightDiffuseContribution*surfaceAlbedoContribution+surfaceEmissiveColor;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=shadowedOnlyLightDiffuseContribution*surfaceAlbedoContribution+surfaceEmissiveColor;\n#endif\n#endif\n#endif\nfinalDiffuse.rgb+=vAmbientColor;\nfinalDiffuse*=surfaceAlbedo.rgb;\nfinalDiffuse=max(finalDiffuse,0.0);\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution+=vAmbientColor;\nshadowedOnlyLightDiffuseContribution*=surfaceAlbedo.rgb;\nshadowedOnlyLightDiffuseContribution=max(shadowedOnlyLightDiffuseContribution,0.0);\nfinalDiffuse=mix(finalDiffuse,shadowedOnlyLightDiffuseContribution,(1.0-vOverloadedShadowIntensity.y));\n#endif\nfinalDiffuse=(finalDiffuse*vLightingIntensity.x+surfaceAlbedo.rgb*environmentIrradiance)*ambientOcclusionColor;\n#ifdef SPECULARTERM\nvec3 finalSpecular=lightSpecularContribution*surfaceReflectivityColor;\n#ifdef SPECULAROVERALPHA\nalpha=clamp(alpha+getLuminance(finalSpecular),0.,1.);\n#endif\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#ifdef RADIANCEOVERALPHA\nalpha=clamp(alpha+getLuminance(environmentRadiance),0.,1.);\n#endif\n\n\nvec4 finalColor=vec4(finalDiffuse+finalSpecular*vLightingIntensity.x+environmentRadiance+refractance,alpha);\n#ifdef EMISSIVEASILLUMINATION\nfinalColor.rgb+=(surfaceEmissiveColor*vLightingIntensity.y);\n#endif\n#ifdef LIGHTMAP\n#ifndef LIGHTMAPEXCLUDED\n#ifdef USELIGHTMAPASSHADOWMAP\nfinalColor.rgb*=lightmapColor;\n#else\nfinalColor.rgb+=lightmapColor;\n#endif\n#endif\n#endif\nfinalColor=max(finalColor,0.0);\n#ifdef CAMERATONEMAP\nfinalColor.rgb=toneMaps(finalColor.rgb);\n#endif\nfinalColor.rgb=toGammaSpace(finalColor.rgb);\n#include<logDepthFragment>\n#include<fogFragment>(color,finalColor)\n#ifdef CAMERACONTRAST\nfinalColor=contrasts(finalColor);\n#endif\nfinalColor.rgb=clamp(finalColor.rgb,0.,1.);\n#ifdef CAMERACOLORGRADING\nfinalColor=colorGrades(finalColor);\n#endif\n#ifdef CAMERACOLORCURVES\nfinalColor.rgb=applyColorCurves(finalColor.rgb);\n#endif\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\ngl_FragColor=finalColor;\n}";
  1513. BABYLON.Effect.IncludesShadersStore['legacyPbrFragmentDeclaration'] = "uniform vec3 vReflectionColor;\nuniform vec4 vAlbedoColor;\n\nuniform vec4 vLightingIntensity;\n#ifdef OVERLOADEDVALUES\nuniform vec4 vOverloadedIntensity;\nuniform vec3 vOverloadedAmbient;\nuniform vec3 vOverloadedAlbedo;\nuniform vec3 vOverloadedReflectivity;\nuniform vec3 vOverloadedEmissive;\nuniform vec3 vOverloadedReflection;\nuniform vec3 vOverloadedMicroSurface;\n#endif\n#ifdef OVERLOADEDSHADOWVALUES\nuniform vec4 vOverloadedShadowIntensity;\n#endif\n#if defined(REFLECTION) || defined(REFRACTION)\nuniform vec2 vMicrosurfaceTextureLods;\n#endif\nuniform vec4 vReflectivityColor;\nuniform vec3 vEmissiveColor;\n\n#ifdef ALBEDO\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nuniform vec3 vAmbientInfos;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform vec2 vTangentSpaceParams;\n#endif\n#ifdef OPACITY \nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\n#endif\n#if defined(REFLECTIVITY) || defined(METALLICWORKFLOW) \nuniform vec3 vReflectivityInfos;\n#endif\n#ifdef MICROSURFACEMAP\nuniform vec2 vMicroSurfaceSamplerInfos;\n#endif\n#ifdef OPACITYFRESNEL\nuniform vec4 opacityParts;\n#endif\n#ifdef EMISSIVEFRESNEL\nuniform vec4 emissiveLeftColor;\nuniform vec4 emissiveRightColor;\n#endif\n\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION)\nuniform mat4 view;\n#endif\n\n#ifdef REFRACTION\nuniform vec4 vRefractionInfos;\n#ifdef REFRACTIONMAP_3D\n#else\nuniform mat4 refractionMatrix;\n#endif\n#endif\n\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\n#ifdef REFLECTIONMAP_SKYBOX\n#else\n#if defined(REFLECTIONMAP_PLANAR) || defined(REFLECTIONMAP_CUBIC) || defined(REFLECTIONMAP_PROJECTION)\nuniform mat4 reflectionMatrix;\n#endif\n#endif\n#endif";
  1514. BABYLON.Effect.IncludesShadersStore['legacyPbrFunctions'] = "\n#define RECIPROCAL_PI2 0.15915494\n#define FRESNEL_MAXIMUM_ON_ROUGH 0.25\n\nconst float kPi=3.1415926535897932384626433832795;\nconst float kRougnhessToAlphaScale=0.1;\nconst float kRougnhessToAlphaOffset=0.29248125;\nfloat Square(float value)\n{\nreturn value*value;\n}\nfloat convertRoughnessToAverageSlope(float roughness)\n{\n\nconst float kMinimumVariance=0.0005;\nfloat alphaG=Square(roughness)+kMinimumVariance;\nreturn alphaG;\n}\n\nfloat getMipMapIndexFromAverageSlope(float maxMipLevel,float alpha)\n{\n\n\n\n\n\n\n\nfloat mip=kRougnhessToAlphaOffset+maxMipLevel+(maxMipLevel*kRougnhessToAlphaScale*log2(alpha));\nreturn clamp(mip,0.,maxMipLevel);\n}\nfloat getMipMapIndexFromAverageSlopeWithPMREM(float maxMipLevel,float alphaG)\n{\nfloat specularPower=clamp(2./alphaG-2.,0.000001,2048.);\n\nreturn clamp(- 0.5*log2(specularPower)+5.5,0.,maxMipLevel);\n}\n\nfloat smithVisibilityG1_TrowbridgeReitzGGX(float dot,float alphaG)\n{\nfloat tanSquared=(1.0-dot*dot)/(dot*dot);\nreturn 2.0/(1.0+sqrt(1.0+alphaG*alphaG*tanSquared));\n}\nfloat smithVisibilityG_TrowbridgeReitzGGX_Walter(float NdotL,float NdotV,float alphaG)\n{\nreturn smithVisibilityG1_TrowbridgeReitzGGX(NdotL,alphaG)*smithVisibilityG1_TrowbridgeReitzGGX(NdotV,alphaG);\n}\n\n\nfloat normalDistributionFunction_TrowbridgeReitzGGX(float NdotH,float alphaG)\n{\n\n\n\nfloat a2=Square(alphaG);\nfloat d=NdotH*NdotH*(a2-1.0)+1.0;\nreturn a2/(kPi*d*d);\n}\nvec3 fresnelSchlickGGX(float VdotH,vec3 reflectance0,vec3 reflectance90)\n{\nreturn reflectance0+(reflectance90-reflectance0)*pow(clamp(1.0-VdotH,0.,1.),5.0);\n}\nvec3 FresnelSchlickEnvironmentGGX(float VdotN,vec3 reflectance0,vec3 reflectance90,float smoothness)\n{\n\nfloat weight=mix(FRESNEL_MAXIMUM_ON_ROUGH,1.0,smoothness);\nreturn reflectance0+weight*(reflectance90-reflectance0)*pow(clamp(1.0-VdotN,0.,1.),5.0);\n}\n\nvec3 computeSpecularTerm(float NdotH,float NdotL,float NdotV,float VdotH,float roughness,vec3 specularColor,vec3 reflectance90)\n{\nfloat alphaG=convertRoughnessToAverageSlope(roughness);\nfloat distribution=normalDistributionFunction_TrowbridgeReitzGGX(NdotH,alphaG);\nfloat visibility=smithVisibilityG_TrowbridgeReitzGGX_Walter(NdotL,NdotV,alphaG);\nvisibility/=(4.0*NdotL*NdotV); \nvec3 fresnel=fresnelSchlickGGX(VdotH,specularColor,reflectance90);\nfloat specTerm=max(0.,visibility*distribution)*NdotL;\nreturn fresnel*specTerm*kPi; \n}\nfloat computeDiffuseTerm(float NdotL,float NdotV,float VdotH,float roughness)\n{\n\n\nfloat diffuseFresnelNV=pow(clamp(1.0-NdotL,0.000001,1.),5.0);\nfloat diffuseFresnelNL=pow(clamp(1.0-NdotV,0.000001,1.),5.0);\nfloat diffuseFresnel90=0.5+2.0*VdotH*VdotH*roughness;\nfloat diffuseFresnelTerm =\n(1.0+(diffuseFresnel90-1.0)*diffuseFresnelNL) *\n(1.0+(diffuseFresnel90-1.0)*diffuseFresnelNV);\nreturn diffuseFresnelTerm*NdotL;\n\n\n}\nfloat adjustRoughnessFromLightProperties(float roughness,float lightRadius,float lightDistance)\n{\n#ifdef USEPHYSICALLIGHTFALLOFF\n\nfloat lightRoughness=lightRadius/lightDistance;\n\nfloat totalRoughness=clamp(lightRoughness+roughness,0.,1.);\nreturn totalRoughness;\n#else\nreturn roughness;\n#endif\n}\nfloat computeDefaultMicroSurface(float microSurface,vec3 reflectivityColor)\n{\nfloat kReflectivityNoAlphaWorkflow_SmoothnessMax=0.95;\nfloat reflectivityLuminance=getLuminance(reflectivityColor);\nfloat reflectivityLuma=sqrt(reflectivityLuminance);\nmicroSurface=reflectivityLuma*kReflectivityNoAlphaWorkflow_SmoothnessMax;\nreturn microSurface;\n}\n#ifdef CAMERATONEMAP\nvec3 toneMaps(vec3 color)\n{\ncolor=max(color,0.0);\n\ncolor.rgb=color.rgb*vCameraInfos.x;\nfloat tuning=1.5; \n\n\nvec3 tonemapped=1.0-exp2(-color.rgb*tuning); \ncolor.rgb=mix(color.rgb,tonemapped,1.0);\nreturn color;\n}\n#endif\n#ifdef CAMERACONTRAST\nvec4 contrasts(vec4 color)\n{\ncolor=clamp(color,0.0,1.0);\nvec3 resultHighContrast=color.rgb*color.rgb*(3.0-2.0*color.rgb);\nfloat contrast=vCameraInfos.y;\nif (contrast<1.0)\n{\n\ncolor.rgb=mix(vec3(0.5,0.5,0.5),color.rgb,contrast);\n}\nelse\n{\n\ncolor.rgb=mix(color.rgb,resultHighContrast,contrast-1.0);\n}\nreturn color;\n}\n#endif\n#ifdef USESPHERICALFROMREFLECTIONMAP\nuniform vec3 vSphericalX;\nuniform vec3 vSphericalY;\nuniform vec3 vSphericalZ;\nuniform vec3 vSphericalXX;\nuniform vec3 vSphericalYY;\nuniform vec3 vSphericalZZ;\nuniform vec3 vSphericalXY;\nuniform vec3 vSphericalYZ;\nuniform vec3 vSphericalZX;\nvec3 EnvironmentIrradiance(vec3 normal)\n{\n\n\n\nvec3 result =\nvSphericalX*normal.x +\nvSphericalY*normal.y +\nvSphericalZ*normal.z +\nvSphericalXX*normal.x*normal.x +\nvSphericalYY*normal.y*normal.y +\nvSphericalZZ*normal.z*normal.z +\nvSphericalYZ*normal.y*normal.z +\nvSphericalZX*normal.z*normal.x +\nvSphericalXY*normal.x*normal.y;\nreturn result.rgb;\n}\n#endif";
  1515. BABYLON.Effect.IncludesShadersStore['legacyPbrLightFunctions'] = "\nstruct lightingInfo\n{\nvec3 diffuse;\n#ifdef SPECULARTERM\nvec3 specular;\n#endif\n};\nfloat computeDistanceLightFalloff(vec3 lightOffset,float lightDistanceSquared,float range)\n{ \n#ifdef USEPHYSICALLIGHTFALLOFF\nfloat lightDistanceFalloff=1.0/((lightDistanceSquared+0.0001));\n#else\nfloat lightDistanceFalloff=max(0.,1.0-length(lightOffset)/range);\n#endif\nreturn lightDistanceFalloff;\n}\nfloat computeDirectionalLightFalloff(vec3 lightDirection,vec3 directionToLightCenterW,float lightAngle,float exponent)\n{\nfloat falloff=0.0;\n#ifdef USEPHYSICALLIGHTFALLOFF\nfloat cosHalfAngle=cos(lightAngle*0.5);\nconst float kMinusLog2ConeAngleIntensityRatio=6.64385618977; \n\n\n\n\n\nfloat concentrationKappa=kMinusLog2ConeAngleIntensityRatio/(1.0-cosHalfAngle);\n\n\nvec4 lightDirectionSpreadSG=vec4(-lightDirection*concentrationKappa,-concentrationKappa);\nfalloff=exp2(dot(vec4(directionToLightCenterW,1.0),lightDirectionSpreadSG));\n#else\nfloat cosAngle=max(0.000000000000001,dot(-lightDirection,directionToLightCenterW));\nif (cosAngle>=lightAngle)\n{\nfalloff=max(0.,pow(cosAngle,exponent));\n}\n#endif\nreturn falloff;\n}\nlightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float rangeRadius,float roughness,float NdotV,vec3 reflectance90,out float NdotL) {\nlightingInfo result;\nvec3 lightDirection;\nfloat attenuation=1.0;\nfloat lightDistance;\n\nif (lightData.w == 0.)\n{\nvec3 lightOffset=lightData.xyz-vPositionW;\nfloat lightDistanceSquared=dot(lightOffset,lightOffset);\nattenuation=computeDistanceLightFalloff(lightOffset,lightDistanceSquared,rangeRadius);\nlightDistance=sqrt(lightDistanceSquared);\nlightDirection=normalize(lightOffset);\n}\n\nelse\n{\nlightDistance=length(-lightData.xyz);\nlightDirection=normalize(-lightData.xyz);\n}\n\nroughness=adjustRoughnessFromLightProperties(roughness,rangeRadius,lightDistance);\n\nvec3 H=normalize(viewDirectionW+lightDirection);\nNdotL=max(0.00000000001,dot(vNormal,lightDirection));\nfloat VdotH=clamp(0.00000000001,1.0,dot(viewDirectionW,H));\nfloat diffuseTerm=computeDiffuseTerm(NdotL,NdotV,VdotH,roughness);\nresult.diffuse=diffuseTerm*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nfloat NdotH=max(0.00000000001,dot(vNormal,H));\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,specularColor,reflectance90);\nresult.specular=specTerm*attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float rangeRadius,float roughness,float NdotV,vec3 reflectance90,out float NdotL) {\nlightingInfo result;\nvec3 lightOffset=lightData.xyz-vPositionW;\nvec3 directionToLightCenterW=normalize(lightOffset);\n\nfloat lightDistanceSquared=dot(lightOffset,lightOffset);\nfloat attenuation=computeDistanceLightFalloff(lightOffset,lightDistanceSquared,rangeRadius);\n\nfloat directionalAttenuation=computeDirectionalLightFalloff(lightDirection.xyz,directionToLightCenterW,lightDirection.w,lightData.w);\nattenuation*=directionalAttenuation;\n\nfloat lightDistance=sqrt(lightDistanceSquared);\nroughness=adjustRoughnessFromLightProperties(roughness,rangeRadius,lightDistance);\n\nvec3 H=normalize(viewDirectionW+directionToLightCenterW);\nNdotL=max(0.00000000001,dot(vNormal,directionToLightCenterW));\nfloat VdotH=clamp(dot(viewDirectionW,H),0.00000000001,1.0);\nfloat diffuseTerm=computeDiffuseTerm(NdotL,NdotV,VdotH,roughness);\nresult.diffuse=diffuseTerm*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nfloat NdotH=max(0.00000000001,dot(vNormal,H));\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,specularColor,reflectance90);\nresult.specular=specTerm*attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float roughness,float NdotV,vec3 reflectance90,out float NdotL) {\nlightingInfo result;\n\n\n\nNdotL=dot(vNormal,lightData.xyz)*0.5+0.5;\nresult.diffuse=mix(groundColor,diffuseColor,NdotL);\n#ifdef SPECULARTERM\n\nvec3 lightVectorW=normalize(lightData.xyz);\nvec3 H=normalize(viewDirectionW+lightVectorW);\nfloat NdotH=max(0.00000000001,dot(vNormal,H));\nNdotL=max(0.00000000001,NdotL);\nfloat VdotH=clamp(0.00000000001,1.0,dot(viewDirectionW,H));\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,specularColor,reflectance90);\nresult.specular=specTerm;\n#endif\nreturn result;\n}";
  1516. BABYLON.Effect.IncludesShadersStore['legacyPbrLightFunctionsCall'] = "#ifdef LIGHT{X}\n#if defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X}) && defined(LIGHTMAPNOSPECULAR{X})\n\n#else\n#ifdef SPOTLIGHT{X}\ninfo=computeSpotLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDirection,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR90,NdotL);\n#endif\n#ifdef HEMILIGHT{X}\ninfo=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightGround,roughness,NdotV,specularEnvironmentR90,NdotL);\n#endif\n#if defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})\ninfo=computeLighting(viewDirectionW,normalW,light{X}.vLightData,light{X}.vLightDiffuse.rgb,light{X}.vLightSpecular,light{X}.vLightDiffuse.a,roughness,NdotV,specularEnvironmentR90,NdotL);\n#endif\n#endif\n#ifdef SHADOW{X}\n#ifdef SHADOWESM{X}\n#if defined(SHADOWCUBE{X})\nnotShadowLevel=computeShadowWithESMCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,light{X}.depthValues);\n#else\nnotShadowLevel=computeShadowWithESM(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,light{X}.shadowsInfo.z,0.0);\n#endif\n#else\n#ifdef SHADOWPCF{X}\n#if defined(SHADOWCUBE{X})\nnotShadowLevel=computeShadowWithPCFCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nnotShadowLevel=computeShadowWithPCF(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.y,light{X}.shadowsInfo.x,0.0);\n#endif\n#else\n#if defined(SHADOWCUBE{X})\nnotShadowLevel=computeShadowCube(light{X}.vLightData.xyz,shadowSampler{X},light{X}.shadowsInfo.x,light{X}.depthValues);\n#else\nnotShadowLevel=computeShadow(vPositionFromLight{X},vDepthMetric{X},shadowSampler{X},light{X}.shadowsInfo.x,0.0);\n#endif\n#endif\n#endif\n#else\nnotShadowLevel=1.;\n#endif\n#if defined(LIGHTMAP) && defined(LIGHTMAPEXCLUDED{X})\nlightDiffuseContribution+=lightmapColor*notShadowLevel;\n#ifdef SPECULARTERM\n#ifndef LIGHTMAPNOSPECULAR{X}\nlightSpecularContribution+=info.specular*notShadowLevel*lightmapColor;\n#endif\n#endif\n#else\nlightDiffuseContribution+=info.diffuse*notShadowLevel;\n#ifdef OVERLOADEDSHADOWVALUES\nif (NdotL<0.000000000011)\n{\nnotShadowLevel=1.;\n}\nshadowedOnlyLightDiffuseContribution*=notShadowLevel;\n#endif\n#ifdef SPECULARTERM\nlightSpecularContribution+=info.specular*notShadowLevel;\n#endif\n#endif\n#endif";
  1517. BABYLON.Effect.IncludesShadersStore['legacyPbrUboDeclaration'] = "layout(std140,column_major) uniform;\nuniform Material\n{\nuniform vec2 vAlbedoInfos;\nuniform vec3 vAmbientInfos;\nuniform vec2 vOpacityInfos;\nuniform vec2 vEmissiveInfos;\nuniform vec2 vLightmapInfos;\nuniform vec3 vReflectivityInfos;\nuniform vec2 vMicroSurfaceSamplerInfos;\nuniform vec4 vRefractionInfos;\nuniform vec2 vReflectionInfos;\nuniform vec3 vBumpInfos;\nuniform mat4 albedoMatrix;\nuniform mat4 ambientMatrix;\nuniform mat4 opacityMatrix;\nuniform mat4 emissiveMatrix;\nuniform mat4 lightmapMatrix;\nuniform mat4 reflectivityMatrix;\nuniform mat4 microSurfaceSamplerMatrix;\nuniform mat4 bumpMatrix;\nuniform vec2 vTangentSpaceParams;\nuniform mat4 refractionMatrix;\nuniform mat4 reflectionMatrix;\nuniform vec3 vReflectionColor;\nuniform vec4 vAlbedoColor;\nuniform vec4 vLightingIntensity;\nuniform vec2 vMicrosurfaceTextureLods;\nuniform vec4 vReflectivityColor;\nuniform vec3 vEmissiveColor;\nuniform vec4 opacityParts;\nuniform vec4 emissiveLeftColor;\nuniform vec4 emissiveRightColor;\nuniform vec4 vOverloadedIntensity;\nuniform vec3 vOverloadedAmbient;\nuniform vec3 vOverloadedAlbedo;\nuniform vec3 vOverloadedReflectivity;\nuniform vec3 vOverloadedEmissive;\nuniform vec3 vOverloadedReflection;\nuniform vec3 vOverloadedMicroSurface;\nuniform vec4 vOverloadedShadowIntensity;\nuniform float pointSize;\n};\nuniform Scene {\nmat4 viewProjection;\nmat4 view;\n};";
  1518. BABYLON.Effect.IncludesShadersStore['legacyPbrVertexDeclaration'] = "uniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef ALBEDO\nuniform mat4 albedoMatrix;\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nuniform mat4 ambientMatrix;\nuniform vec3 vAmbientInfos;\n#endif\n#ifdef OPACITY\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nuniform vec2 vLightmapInfos;\nuniform mat4 lightmapMatrix;\n#endif\n#if defined(REFLECTIVITY) || defined(METALLICWORKFLOW) \nuniform vec3 vReflectivityInfos;\nuniform mat4 reflectivityMatrix;\n#endif\n#ifdef MICROSURFACEMAP\nuniform vec2 vMicroSurfaceSamplerInfos;\nuniform mat4 microSurfaceSamplerMatrix;\n#endif\n#ifdef BUMP\nuniform vec3 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n";
  1519. BABYLON.Effect.IncludesShadersStore['legacyColorCurves'] = "const vec3 HDTVRec709_RGBLuminanceCoefficients=vec3(0.2126,0.7152,0.0722);\nvec3 applyColorCurves(vec3 original) {\nvec3 result=original;\n\n\n\nfloat luma=dot(result.rgb,HDTVRec709_RGBLuminanceCoefficients);\nvec2 curveMix=clamp(vec2(luma*3.0-1.5,luma*-3.0+1.5),vec2(0.0,0.0),vec2(1.0,1.0));\nvec4 colorCurve=vCameraColorCurveNeutral+curveMix.x*vCameraColorCurvePositive-curveMix.y*vCameraColorCurveNegative;\nresult.rgb*=colorCurve.rgb;\nresult.rgb=mix(vec3(luma,luma,luma),result.rgb,colorCurve.a);\nreturn result;\n}";
  1520. BABYLON.Effect.IncludesShadersStore['legacyColorCurvesDefinition'] = "uniform vec4 vCameraColorCurveNeutral;\nuniform vec4 vCameraColorCurvePositive;\nuniform vec4 vCameraColorCurveNegative;";
  1521. BABYLON.Effect.IncludesShadersStore['legacyColorGrading'] = "vec4 colorGrades(vec4 color) \n{ \n\nfloat sliceContinuous=color.z*vCameraColorGradingInfos.z;\nfloat sliceInteger=floor(sliceContinuous);\n\n\nfloat sliceFraction=sliceContinuous-sliceInteger; \n\nvec2 sliceUV=color.xy*vCameraColorGradingScaleOffset.xy+vCameraColorGradingScaleOffset.zw;\n\n\nsliceUV.x+=sliceInteger*vCameraColorGradingInfos.w;\nvec4 slice0Color=texture2D(cameraColorGrading2DSampler,sliceUV);\nsliceUV.x+=vCameraColorGradingInfos.w;\nvec4 slice1Color=texture2D(cameraColorGrading2DSampler,sliceUV);\nvec3 result=mix(slice0Color.rgb,slice1Color.rgb,sliceFraction);\ncolor.rgb=mix(color.rgb,result,vCameraColorGradingInfos.x);\nreturn color;\n}";
  1522. BABYLON.Effect.IncludesShadersStore['legacyColorGradingDefinition'] = "uniform sampler2D cameraColorGrading2DSampler;\nuniform vec4 vCameraColorGradingInfos;\nuniform vec4 vCameraColorGradingScaleOffset;";