babylon.pbrMaterial.js 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  3. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
  4. switch (arguments.length) {
  5. case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
  6. case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
  7. case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
  8. }
  9. };
  10. var BABYLON;
  11. (function (BABYLON) {
  12. var maxSimultaneousLights = 4;
  13. var PBRMaterialDefines = (function (_super) {
  14. __extends(PBRMaterialDefines, _super);
  15. function PBRMaterialDefines() {
  16. _super.call(this);
  17. this.ALBEDO = false;
  18. this.AMBIENT = false;
  19. this.OPACITY = false;
  20. this.OPACITYRGB = false;
  21. this.REFLECTION = false;
  22. this.EMISSIVE = false;
  23. this.REFLECTIVITY = false;
  24. this.BUMP = false;
  25. this.PARALLAX = false;
  26. this.PARALLAXOCCLUSION = false;
  27. this.SPECULAROVERALPHA = false;
  28. this.CLIPPLANE = false;
  29. this.ALPHATEST = false;
  30. this.ALPHAFROMALBEDO = false;
  31. this.POINTSIZE = false;
  32. this.FOG = false;
  33. this.LIGHT0 = false;
  34. this.LIGHT1 = false;
  35. this.LIGHT2 = false;
  36. this.LIGHT3 = false;
  37. this.SPOTLIGHT0 = false;
  38. this.SPOTLIGHT1 = false;
  39. this.SPOTLIGHT2 = false;
  40. this.SPOTLIGHT3 = false;
  41. this.HEMILIGHT0 = false;
  42. this.HEMILIGHT1 = false;
  43. this.HEMILIGHT2 = false;
  44. this.HEMILIGHT3 = false;
  45. this.POINTLIGHT0 = false;
  46. this.POINTLIGHT1 = false;
  47. this.POINTLIGHT2 = false;
  48. this.POINTLIGHT3 = false;
  49. this.DIRLIGHT0 = false;
  50. this.DIRLIGHT1 = false;
  51. this.DIRLIGHT2 = false;
  52. this.DIRLIGHT3 = false;
  53. this.SPECULARTERM = false;
  54. this.SHADOW0 = false;
  55. this.SHADOW1 = false;
  56. this.SHADOW2 = false;
  57. this.SHADOW3 = false;
  58. this.SHADOWS = false;
  59. this.SHADOWVSM0 = false;
  60. this.SHADOWVSM1 = false;
  61. this.SHADOWVSM2 = false;
  62. this.SHADOWVSM3 = false;
  63. this.SHADOWPCF0 = false;
  64. this.SHADOWPCF1 = false;
  65. this.SHADOWPCF2 = false;
  66. this.SHADOWPCF3 = false;
  67. this.OPACITYFRESNEL = false;
  68. this.EMISSIVEFRESNEL = false;
  69. this.FRESNEL = false;
  70. this.NORMAL = false;
  71. this.UV1 = false;
  72. this.UV2 = false;
  73. this.VERTEXCOLOR = false;
  74. this.VERTEXALPHA = false;
  75. this.NUM_BONE_INFLUENCERS = 0;
  76. this.BonesPerMesh = 0;
  77. this.INSTANCES = false;
  78. this.MICROSURFACEFROMREFLECTIVITYMAP = false;
  79. this.MICROSURFACEAUTOMATIC = false;
  80. this.EMISSIVEASILLUMINATION = false;
  81. this.LINKEMISSIVEWITHALBEDO = false;
  82. this.LIGHTMAP = false;
  83. this.USELIGHTMAPASSHADOWMAP = false;
  84. this.REFLECTIONMAP_3D = false;
  85. this.REFLECTIONMAP_SPHERICAL = false;
  86. this.REFLECTIONMAP_PLANAR = false;
  87. this.REFLECTIONMAP_CUBIC = false;
  88. this.REFLECTIONMAP_PROJECTION = false;
  89. this.REFLECTIONMAP_SKYBOX = false;
  90. this.REFLECTIONMAP_EXPLICIT = false;
  91. this.REFLECTIONMAP_EQUIRECTANGULAR = false;
  92. this.INVERTCUBICMAP = false;
  93. this.LOGARITHMICDEPTH = false;
  94. this.CAMERATONEMAP = false;
  95. this.CAMERACONTRAST = false;
  96. this.OVERLOADEDVALUES = false;
  97. this.OVERLOADEDSHADOWVALUES = false;
  98. this.USESPHERICALFROMREFLECTIONMAP = false;
  99. this.REFRACTION = false;
  100. this.REFRACTIONMAP_3D = false;
  101. this.LINKREFRACTIONTOTRANSPARENCY = false;
  102. this.REFRACTIONMAPINLINEARSPACE = false;
  103. this.LODBASEDMICROSFURACE = false;
  104. this.USEPHYSICALLIGHTFALLOFF = false;
  105. this.RADIANCEOVERALPHA = false;
  106. this.USEPMREMREFLECTION = false;
  107. this.USEPMREMREFRACTION = false;
  108. this._keys = Object.keys(this);
  109. }
  110. return PBRMaterialDefines;
  111. })(BABYLON.MaterialDefines);
  112. /**
  113. * The Physically based material of BJS.
  114. *
  115. * This offers the main features of a standard PBR material.
  116. * For more information, please refer to the documentation :
  117. * http://doc.babylonjs.com/extensions/Physically_Based_Rendering
  118. */
  119. var PBRMaterial = (function (_super) {
  120. __extends(PBRMaterial, _super);
  121. /**
  122. * Instantiates a new PBRMaterial instance.
  123. *
  124. * @param name The material name
  125. * @param scene The scene the material will be use in.
  126. */
  127. function PBRMaterial(name, scene) {
  128. var _this = this;
  129. _super.call(this, name, scene);
  130. /**
  131. * Intensity of the direct lights e.g. the four lights available in your scene.
  132. * This impacts both the direct diffuse and specular highlights.
  133. */
  134. this.directIntensity = 1.0;
  135. /**
  136. * Intensity of the emissive part of the material.
  137. * This helps controlling the emissive effect without modifying the emissive color.
  138. */
  139. this.emissiveIntensity = 1.0;
  140. /**
  141. * Intensity of the environment e.g. how much the environment will light the object
  142. * either through harmonics for rough material or through the refelction for shiny ones.
  143. */
  144. this.environmentIntensity = 1.0;
  145. /**
  146. * This is a special control allowing the reduction of the specular highlights coming from the
  147. * four lights of the scene. Those highlights may not be needed in full environment lighting.
  148. */
  149. this.specularIntensity = 1.0;
  150. this._lightingInfos = new BABYLON.Vector4(this.directIntensity, this.emissiveIntensity, this.environmentIntensity, this.specularIntensity);
  151. /**
  152. * Debug Control allowing disabling the bump map on this material.
  153. */
  154. this.disableBumpMap = false;
  155. /**
  156. * Debug Control helping enforcing or dropping the darkness of shadows.
  157. * 1.0 means the shadows have their normal darkness, 0.0 means the shadows are not visible.
  158. */
  159. this.overloadedShadowIntensity = 1.0;
  160. /**
  161. * Debug Control helping dropping the shading effect coming from the diffuse lighting.
  162. * 1.0 means the shade have their normal impact, 0.0 means no shading at all.
  163. */
  164. this.overloadedShadeIntensity = 1.0;
  165. this._overloadedShadowInfos = new BABYLON.Vector4(this.overloadedShadowIntensity, this.overloadedShadeIntensity, 0.0, 0.0);
  166. /**
  167. * The camera exposure used on this material.
  168. * This property is here and not in the camera to allow controlling exposure without full screen post process.
  169. * This corresponds to a photographic exposure.
  170. */
  171. this.cameraExposure = 1.0;
  172. /**
  173. * The camera contrast used on this material.
  174. * This property is here and not in the camera to allow controlling contrast without full screen post process.
  175. */
  176. this.cameraContrast = 1.0;
  177. this._cameraInfos = new BABYLON.Vector4(1.0, 1.0, 0.0, 0.0);
  178. this._microsurfaceTextureLods = new BABYLON.Vector2(0.0, 0.0);
  179. /**
  180. * Debug Control allowing to overload the ambient color.
  181. * This as to be use with the overloadedAmbientIntensity parameter.
  182. */
  183. this.overloadedAmbient = BABYLON.Color3.White();
  184. /**
  185. * Debug Control indicating how much the overloaded ambient color is used against the default one.
  186. */
  187. this.overloadedAmbientIntensity = 0.0;
  188. /**
  189. * Debug Control allowing to overload the albedo color.
  190. * This as to be use with the overloadedAlbedoIntensity parameter.
  191. */
  192. this.overloadedAlbedo = BABYLON.Color3.White();
  193. /**
  194. * Debug Control indicating how much the overloaded albedo color is used against the default one.
  195. */
  196. this.overloadedAlbedoIntensity = 0.0;
  197. /**
  198. * Debug Control allowing to overload the reflectivity color.
  199. * This as to be use with the overloadedReflectivityIntensity parameter.
  200. */
  201. this.overloadedReflectivity = BABYLON.Color3.White();
  202. /**
  203. * Debug Control indicating how much the overloaded reflectivity color is used against the default one.
  204. */
  205. this.overloadedReflectivityIntensity = 0.0;
  206. /**
  207. * Debug Control allowing to overload the emissive color.
  208. * This as to be use with the overloadedEmissiveIntensity parameter.
  209. */
  210. this.overloadedEmissive = BABYLON.Color3.White();
  211. /**
  212. * Debug Control indicating how much the overloaded emissive color is used against the default one.
  213. */
  214. this.overloadedEmissiveIntensity = 0.0;
  215. this._overloadedIntensity = new BABYLON.Vector4(this.overloadedAmbientIntensity, this.overloadedAlbedoIntensity, this.overloadedReflectivityIntensity, this.overloadedEmissiveIntensity);
  216. /**
  217. * Debug Control allowing to overload the reflection color.
  218. * This as to be use with the overloadedReflectionIntensity parameter.
  219. */
  220. this.overloadedReflection = BABYLON.Color3.White();
  221. /**
  222. * Debug Control indicating how much the overloaded reflection color is used against the default one.
  223. */
  224. this.overloadedReflectionIntensity = 0.0;
  225. /**
  226. * Debug Control allowing to overload the microsurface.
  227. * This as to be use with the overloadedMicroSurfaceIntensity parameter.
  228. */
  229. this.overloadedMicroSurface = 0.0;
  230. /**
  231. * Debug Control indicating how much the overloaded microsurface is used against the default one.
  232. */
  233. this.overloadedMicroSurfaceIntensity = 0.0;
  234. this._overloadedMicroSurface = new BABYLON.Vector3(this.overloadedMicroSurface, this.overloadedMicroSurfaceIntensity, this.overloadedReflectionIntensity);
  235. this.ambientColor = new BABYLON.Color3(0, 0, 0);
  236. /**
  237. * AKA Diffuse Color in other nomenclature.
  238. */
  239. this.albedoColor = new BABYLON.Color3(1, 1, 1);
  240. /**
  241. * AKA Specular Color in other nomenclature.
  242. */
  243. this.reflectivityColor = new BABYLON.Color3(1, 1, 1);
  244. this.reflectionColor = new BABYLON.Color3(0.5, 0.5, 0.5);
  245. this.emissiveColor = new BABYLON.Color3(0, 0, 0);
  246. /**
  247. * AKA Glossiness in other nomenclature.
  248. */
  249. this.microSurface = 0.9;
  250. /**
  251. * source material index of refraction (IOR)' / 'destination material IOR.
  252. */
  253. this.indexOfRefraction = 0.66;
  254. /**
  255. * Controls if refraction needs to be inverted on Y. This could be usefull for procedural texture.
  256. */
  257. this.invertRefractionY = false;
  258. /**
  259. * This parameters will make the material used its opacity to control how much it is refracting aginst not.
  260. * Materials half opaque for instance using refraction could benefit from this control.
  261. */
  262. this.linkRefractionWithTransparency = false;
  263. /**
  264. * The emissive and albedo are linked to never be more than one (Energy conservation).
  265. */
  266. this.linkEmissiveWithAlbedo = false;
  267. this.useLightmapAsShadowmap = false;
  268. /**
  269. * In this mode, the emissive informtaion will always be added to the lighting once.
  270. * A light for instance can be thought as emissive.
  271. */
  272. this.useEmissiveAsIllumination = false;
  273. /**
  274. * Secifies that the alpha is coming form the albedo channel alpha channel.
  275. */
  276. this.useAlphaFromAlbedoTexture = false;
  277. /**
  278. * Specifies that the material will keeps the specular highlights over a transparent surface (only the most limunous ones).
  279. * A car glass is a good exemple of that. When sun reflects on it you can not see what is behind.
  280. */
  281. this.useSpecularOverAlpha = true;
  282. /**
  283. * Specifies if the reflectivity texture contains the glossiness information in its alpha channel.
  284. */
  285. this.useMicroSurfaceFromReflectivityMapAlpha = false;
  286. /**
  287. * In case the reflectivity map does not contain the microsurface information in its alpha channel,
  288. * The material will try to infer what glossiness each pixel should be.
  289. */
  290. this.useAutoMicroSurfaceFromReflectivityMap = false;
  291. /**
  292. * Allows to work with scalar in linear mode. This is definitely a matter of preferences and tools used during
  293. * the creation of the material.
  294. */
  295. this.useScalarInLinearSpace = false;
  296. /**
  297. * BJS is using an harcoded light falloff based on a manually sets up range.
  298. * In PBR, one way to represents the fallof is to use the inverse squared root algorythm.
  299. * This parameter can help you switch back to the BJS mode in order to create scenes using both materials.
  300. */
  301. this.usePhysicalLightFalloff = true;
  302. /**
  303. * Specifies that the material will keeps the reflection highlights over a transparent surface (only the most limunous ones).
  304. * A car glass is a good exemple of that. When the street lights reflects on it you can not see what is behind.
  305. */
  306. this.useRadianceOverAlpha = true;
  307. /**
  308. * Allows using the bump map in parallax mode.
  309. */
  310. this.useParallax = false;
  311. /**
  312. * Allows using the bump map in parallax occlusion mode.
  313. */
  314. this.useParallaxOcclusion = false;
  315. /**
  316. * Controls the scale bias of the parallax mode.
  317. */
  318. this.parallaxScaleBias = 0.05;
  319. this.disableLighting = false;
  320. this._renderTargets = new BABYLON.SmartArray(16);
  321. this._worldViewProjectionMatrix = BABYLON.Matrix.Zero();
  322. this._globalAmbientColor = new BABYLON.Color3(0, 0, 0);
  323. this._tempColor = new BABYLON.Color3();
  324. this._defines = new PBRMaterialDefines();
  325. this._cachedDefines = new PBRMaterialDefines();
  326. this._myScene = null;
  327. this._myShadowGenerator = null;
  328. this._cachedDefines.BonesPerMesh = -1;
  329. this.getRenderTargetTextures = function () {
  330. _this._renderTargets.reset();
  331. if (_this.reflectionTexture && _this.reflectionTexture.isRenderTarget) {
  332. _this._renderTargets.push(_this.reflectionTexture);
  333. }
  334. if (_this.refractionTexture && _this.refractionTexture.isRenderTarget) {
  335. _this._renderTargets.push(_this.refractionTexture);
  336. }
  337. return _this._renderTargets;
  338. };
  339. }
  340. Object.defineProperty(PBRMaterial.prototype, "useLogarithmicDepth", {
  341. get: function () {
  342. return this._useLogarithmicDepth;
  343. },
  344. set: function (value) {
  345. this._useLogarithmicDepth = value && this.getScene().getEngine().getCaps().fragmentDepthSupported;
  346. },
  347. enumerable: true,
  348. configurable: true
  349. });
  350. PBRMaterial.prototype.needAlphaBlending = function () {
  351. if (this.linkRefractionWithTransparency) {
  352. return false;
  353. }
  354. return (this.alpha < 1.0) || (this.opacityTexture != null) || this._shouldUseAlphaFromAlbedoTexture() || this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled;
  355. };
  356. PBRMaterial.prototype.needAlphaTesting = function () {
  357. if (this.linkRefractionWithTransparency) {
  358. return false;
  359. }
  360. return this.albedoTexture != null && this.albedoTexture.hasAlpha;
  361. };
  362. PBRMaterial.prototype._shouldUseAlphaFromAlbedoTexture = function () {
  363. return this.albedoTexture != null && this.albedoTexture.hasAlpha && this.useAlphaFromAlbedoTexture;
  364. };
  365. PBRMaterial.prototype.getAlphaTestTexture = function () {
  366. return this.albedoTexture;
  367. };
  368. PBRMaterial.prototype._checkCache = function (scene, mesh, useInstances) {
  369. if (!mesh) {
  370. return true;
  371. }
  372. if (this._defines.INSTANCES !== useInstances) {
  373. return false;
  374. }
  375. if (mesh._materialDefines && mesh._materialDefines.isEqual(this._defines)) {
  376. return true;
  377. }
  378. return false;
  379. };
  380. PBRMaterial.prototype.convertColorToLinearSpaceToRef = function (color, ref) {
  381. PBRMaterial.convertColorToLinearSpaceToRef(color, ref, this.useScalarInLinearSpace);
  382. };
  383. PBRMaterial.convertColorToLinearSpaceToRef = function (color, ref, useScalarInLinear) {
  384. if (!useScalarInLinear) {
  385. color.toLinearSpaceToRef(ref);
  386. }
  387. else {
  388. ref.r = color.r;
  389. ref.g = color.g;
  390. ref.b = color.b;
  391. }
  392. };
  393. PBRMaterial.BindLights = function (scene, mesh, effect, defines, useScalarInLinearSpace) {
  394. var lightIndex = 0;
  395. var depthValuesAlreadySet = false;
  396. for (var index = 0; index < scene.lights.length; index++) {
  397. var light = scene.lights[index];
  398. if (!light.isEnabled()) {
  399. continue;
  400. }
  401. if (!light.canAffectMesh(mesh)) {
  402. continue;
  403. }
  404. this._lightRadiuses[lightIndex] = light.radius;
  405. BABYLON.MaterialHelper.BindLightProperties(light, effect, lightIndex);
  406. // GAMMA CORRECTION.
  407. this.convertColorToLinearSpaceToRef(light.diffuse, PBRMaterial._scaledAlbedo, useScalarInLinearSpace);
  408. PBRMaterial._scaledAlbedo.scaleToRef(light.intensity, PBRMaterial._scaledAlbedo);
  409. effect.setColor4("vLightDiffuse" + lightIndex, PBRMaterial._scaledAlbedo, light.range);
  410. if (defines["SPECULARTERM"]) {
  411. this.convertColorToLinearSpaceToRef(light.specular, PBRMaterial._scaledReflectivity, useScalarInLinearSpace);
  412. PBRMaterial._scaledReflectivity.scaleToRef(light.intensity, PBRMaterial._scaledReflectivity);
  413. effect.setColor3("vLightSpecular" + lightIndex, PBRMaterial._scaledReflectivity);
  414. }
  415. // Shadows
  416. if (scene.shadowsEnabled) {
  417. depthValuesAlreadySet = BABYLON.MaterialHelper.BindLightShadow(light, scene, mesh, lightIndex, effect, depthValuesAlreadySet);
  418. }
  419. lightIndex++;
  420. if (lightIndex === maxSimultaneousLights)
  421. break;
  422. }
  423. effect.setFloat4("vLightRadiuses", this._lightRadiuses[0], this._lightRadiuses[1], this._lightRadiuses[2], this._lightRadiuses[3]);
  424. };
  425. PBRMaterial.prototype.isReady = function (mesh, useInstances) {
  426. if (this.checkReadyOnlyOnce) {
  427. if (this._wasPreviouslyReady) {
  428. return true;
  429. }
  430. }
  431. var scene = this.getScene();
  432. if (!this.checkReadyOnEveryCall) {
  433. if (this._renderId === scene.getRenderId()) {
  434. if (this._checkCache(scene, mesh, useInstances)) {
  435. return true;
  436. }
  437. }
  438. }
  439. var engine = scene.getEngine();
  440. var needNormals = false;
  441. var needUVs = false;
  442. this._defines.reset();
  443. if (scene.texturesEnabled) {
  444. // Textures
  445. if (scene.texturesEnabled) {
  446. if (scene.getEngine().getCaps().textureLOD) {
  447. this._defines.LODBASEDMICROSFURACE = true;
  448. }
  449. if (this.albedoTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  450. if (!this.albedoTexture.isReady()) {
  451. return false;
  452. }
  453. else {
  454. needUVs = true;
  455. this._defines.ALBEDO = true;
  456. }
  457. }
  458. if (this.ambientTexture && BABYLON.StandardMaterial.AmbientTextureEnabled) {
  459. if (!this.ambientTexture.isReady()) {
  460. return false;
  461. }
  462. else {
  463. needUVs = true;
  464. this._defines.AMBIENT = true;
  465. }
  466. }
  467. if (this.opacityTexture && BABYLON.StandardMaterial.OpacityTextureEnabled) {
  468. if (!this.opacityTexture.isReady()) {
  469. return false;
  470. }
  471. else {
  472. needUVs = true;
  473. this._defines.OPACITY = true;
  474. if (this.opacityTexture.getAlphaFromRGB) {
  475. this._defines.OPACITYRGB = true;
  476. }
  477. }
  478. }
  479. if (this.reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  480. if (!this.reflectionTexture.isReady()) {
  481. return false;
  482. }
  483. else {
  484. needNormals = true;
  485. this._defines.REFLECTION = true;
  486. if (this.reflectionTexture.coordinatesMode === BABYLON.Texture.INVCUBIC_MODE) {
  487. this._defines.INVERTCUBICMAP = true;
  488. }
  489. this._defines.REFLECTIONMAP_3D = this.reflectionTexture.isCube;
  490. switch (this.reflectionTexture.coordinatesMode) {
  491. case BABYLON.Texture.CUBIC_MODE:
  492. case BABYLON.Texture.INVCUBIC_MODE:
  493. this._defines.REFLECTIONMAP_CUBIC = true;
  494. break;
  495. case BABYLON.Texture.EXPLICIT_MODE:
  496. this._defines.REFLECTIONMAP_EXPLICIT = true;
  497. break;
  498. case BABYLON.Texture.PLANAR_MODE:
  499. this._defines.REFLECTIONMAP_PLANAR = true;
  500. break;
  501. case BABYLON.Texture.PROJECTION_MODE:
  502. this._defines.REFLECTIONMAP_PROJECTION = true;
  503. break;
  504. case BABYLON.Texture.SKYBOX_MODE:
  505. this._defines.REFLECTIONMAP_SKYBOX = true;
  506. break;
  507. case BABYLON.Texture.SPHERICAL_MODE:
  508. this._defines.REFLECTIONMAP_SPHERICAL = true;
  509. break;
  510. case BABYLON.Texture.EQUIRECTANGULAR_MODE:
  511. this._defines.REFLECTIONMAP_EQUIRECTANGULAR = true;
  512. break;
  513. }
  514. if (this.reflectionTexture instanceof BABYLON.HDRCubeTexture && this.reflectionTexture) {
  515. this._defines.USESPHERICALFROMREFLECTIONMAP = true;
  516. needNormals = true;
  517. if (this.reflectionTexture.isPMREM) {
  518. this._defines.USEPMREMREFLECTION = true;
  519. }
  520. }
  521. }
  522. }
  523. if (this.lightmapTexture && BABYLON.StandardMaterial.LightmapTextureEnabled) {
  524. if (!this.lightmapTexture.isReady()) {
  525. return false;
  526. }
  527. else {
  528. needUVs = true;
  529. this._defines.LIGHTMAP = true;
  530. this._defines.USELIGHTMAPASSHADOWMAP = this.useLightmapAsShadowmap;
  531. }
  532. }
  533. if (this.emissiveTexture && BABYLON.StandardMaterial.EmissiveTextureEnabled) {
  534. if (!this.emissiveTexture.isReady()) {
  535. return false;
  536. }
  537. else {
  538. needUVs = true;
  539. this._defines.EMISSIVE = true;
  540. }
  541. }
  542. if (this.reflectivityTexture && BABYLON.StandardMaterial.SpecularTextureEnabled) {
  543. if (!this.reflectivityTexture.isReady()) {
  544. return false;
  545. }
  546. else {
  547. needUVs = true;
  548. this._defines.REFLECTIVITY = true;
  549. this._defines.MICROSURFACEFROMREFLECTIVITYMAP = this.useMicroSurfaceFromReflectivityMapAlpha;
  550. this._defines.MICROSURFACEAUTOMATIC = this.useAutoMicroSurfaceFromReflectivityMap;
  551. }
  552. }
  553. }
  554. if (scene.getEngine().getCaps().standardDerivatives && this.bumpTexture && BABYLON.StandardMaterial.BumpTextureEnabled && !this.disableBumpMap) {
  555. if (!this.bumpTexture.isReady()) {
  556. return false;
  557. }
  558. else {
  559. needUVs = true;
  560. this._defines.BUMP = true;
  561. if (this.useParallax) {
  562. this._defines.PARALLAX = true;
  563. if (this.useParallaxOcclusion) {
  564. this._defines.PARALLAXOCCLUSION = true;
  565. }
  566. }
  567. }
  568. }
  569. if (this.refractionTexture && BABYLON.StandardMaterial.RefractionTextureEnabled) {
  570. if (!this.refractionTexture.isReady()) {
  571. return false;
  572. }
  573. else {
  574. needUVs = true;
  575. this._defines.REFRACTION = true;
  576. this._defines.REFRACTIONMAP_3D = this.refractionTexture.isCube;
  577. if (this.linkRefractionWithTransparency) {
  578. this._defines.LINKREFRACTIONTOTRANSPARENCY = true;
  579. }
  580. if (this.refractionTexture instanceof BABYLON.HDRCubeTexture) {
  581. this._defines.REFRACTIONMAPINLINEARSPACE = true;
  582. if (this.refractionTexture.isPMREM) {
  583. this._defines.USEPMREMREFRACTION = true;
  584. }
  585. }
  586. }
  587. }
  588. }
  589. // Effect
  590. if (scene.clipPlane) {
  591. this._defines.CLIPPLANE = true;
  592. }
  593. if (engine.getAlphaTesting()) {
  594. this._defines.ALPHATEST = true;
  595. }
  596. if (this._shouldUseAlphaFromAlbedoTexture()) {
  597. this._defines.ALPHAFROMALBEDO = true;
  598. }
  599. if (this.useEmissiveAsIllumination) {
  600. this._defines.EMISSIVEASILLUMINATION = true;
  601. }
  602. if (this.linkEmissiveWithAlbedo) {
  603. this._defines.LINKEMISSIVEWITHALBEDO = true;
  604. }
  605. if (this.useLogarithmicDepth) {
  606. this._defines.LOGARITHMICDEPTH = true;
  607. }
  608. if (this.cameraContrast != 1) {
  609. this._defines.CAMERACONTRAST = true;
  610. }
  611. if (this.cameraExposure != 1) {
  612. this._defines.CAMERATONEMAP = true;
  613. }
  614. if (this.overloadedShadeIntensity != 1 ||
  615. this.overloadedShadowIntensity != 1) {
  616. this._defines.OVERLOADEDSHADOWVALUES = true;
  617. }
  618. if (this.overloadedMicroSurfaceIntensity > 0 ||
  619. this.overloadedEmissiveIntensity > 0 ||
  620. this.overloadedReflectivityIntensity > 0 ||
  621. this.overloadedAlbedoIntensity > 0 ||
  622. this.overloadedAmbientIntensity > 0 ||
  623. this.overloadedReflectionIntensity > 0) {
  624. this._defines.OVERLOADEDVALUES = true;
  625. }
  626. // Point size
  627. if (this.pointsCloud || scene.forcePointsCloud) {
  628. this._defines.POINTSIZE = true;
  629. }
  630. // Fog
  631. if (scene.fogEnabled && mesh && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled) {
  632. this._defines.FOG = true;
  633. }
  634. if (scene.lightsEnabled && !this.disableLighting) {
  635. needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines) || needNormals;
  636. }
  637. if (BABYLON.StandardMaterial.FresnelEnabled) {
  638. // Fresnel
  639. if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled ||
  640. this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {
  641. if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled) {
  642. this._defines.OPACITYFRESNEL = true;
  643. }
  644. if (this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {
  645. this._defines.EMISSIVEFRESNEL = true;
  646. }
  647. needNormals = true;
  648. this._defines.FRESNEL = true;
  649. }
  650. }
  651. if (this._defines.SPECULARTERM && this.useSpecularOverAlpha) {
  652. this._defines.SPECULAROVERALPHA = true;
  653. }
  654. if (this.usePhysicalLightFalloff) {
  655. this._defines.USEPHYSICALLIGHTFALLOFF = true;
  656. }
  657. if (this.useRadianceOverAlpha) {
  658. this._defines.RADIANCEOVERALPHA = true;
  659. }
  660. // Attribs
  661. if (mesh) {
  662. if (needNormals && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
  663. this._defines.NORMAL = true;
  664. }
  665. if (needUVs) {
  666. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
  667. this._defines.UV1 = true;
  668. }
  669. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind)) {
  670. this._defines.UV2 = true;
  671. }
  672. }
  673. if (mesh.useVertexColors && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind)) {
  674. this._defines.VERTEXCOLOR = true;
  675. if (mesh.hasVertexAlpha) {
  676. this._defines.VERTEXALPHA = true;
  677. }
  678. }
  679. if (mesh.useBones && mesh.computeBonesUsingShaders) {
  680. this._defines.NUM_BONE_INFLUENCERS = mesh.numBoneInfluencers;
  681. this._defines.BonesPerMesh = (mesh.skeleton.bones.length + 1);
  682. }
  683. // Instances
  684. if (useInstances) {
  685. this._defines.INSTANCES = true;
  686. }
  687. }
  688. // Get correct effect
  689. if (!this._defines.isEqual(this._cachedDefines)) {
  690. this._defines.cloneTo(this._cachedDefines);
  691. scene.resetCachedMaterial();
  692. // Fallbacks
  693. var fallbacks = new BABYLON.EffectFallbacks();
  694. if (this._defines.REFLECTION) {
  695. fallbacks.addFallback(0, "REFLECTION");
  696. }
  697. if (this._defines.REFRACTION) {
  698. fallbacks.addFallback(0, "REFRACTION");
  699. }
  700. if (this._defines.REFLECTIVITY) {
  701. fallbacks.addFallback(0, "REFLECTIVITY");
  702. }
  703. if (this._defines.BUMP) {
  704. fallbacks.addFallback(0, "BUMP");
  705. }
  706. if (this._defines.PARALLAX) {
  707. fallbacks.addFallback(1, "PARALLAX");
  708. }
  709. if (this._defines.PARALLAXOCCLUSION) {
  710. fallbacks.addFallback(0, "PARALLAXOCCLUSION");
  711. }
  712. if (this._defines.SPECULAROVERALPHA) {
  713. fallbacks.addFallback(0, "SPECULAROVERALPHA");
  714. }
  715. if (this._defines.FOG) {
  716. fallbacks.addFallback(1, "FOG");
  717. }
  718. if (this._defines.POINTSIZE) {
  719. fallbacks.addFallback(0, "POINTSIZE");
  720. }
  721. if (this._defines.LOGARITHMICDEPTH) {
  722. fallbacks.addFallback(0, "LOGARITHMICDEPTH");
  723. }
  724. BABYLON.MaterialHelper.HandleFallbacksForShadows(this._defines, fallbacks);
  725. if (this._defines.SPECULARTERM) {
  726. fallbacks.addFallback(0, "SPECULARTERM");
  727. }
  728. if (this._defines.OPACITYFRESNEL) {
  729. fallbacks.addFallback(1, "OPACITYFRESNEL");
  730. }
  731. if (this._defines.EMISSIVEFRESNEL) {
  732. fallbacks.addFallback(2, "EMISSIVEFRESNEL");
  733. }
  734. if (this._defines.FRESNEL) {
  735. fallbacks.addFallback(3, "FRESNEL");
  736. }
  737. if (this._defines.NUM_BONE_INFLUENCERS > 0) {
  738. fallbacks.addCPUSkinningFallback(0, mesh);
  739. }
  740. //Attributes
  741. var attribs = [BABYLON.VertexBuffer.PositionKind];
  742. if (this._defines.NORMAL) {
  743. attribs.push(BABYLON.VertexBuffer.NormalKind);
  744. }
  745. if (this._defines.UV1) {
  746. attribs.push(BABYLON.VertexBuffer.UVKind);
  747. }
  748. if (this._defines.UV2) {
  749. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  750. }
  751. if (this._defines.VERTEXCOLOR) {
  752. attribs.push(BABYLON.VertexBuffer.ColorKind);
  753. }
  754. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
  755. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, this._defines);
  756. // Legacy browser patch
  757. var shaderName = "pbr";
  758. if (!scene.getEngine().getCaps().standardDerivatives) {
  759. shaderName = "legacypbr";
  760. }
  761. var join = this._defines.toString();
  762. this._effect = scene.getEngine().createEffect(shaderName, attribs, ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vAlbedoColor", "vReflectivityColor", "vEmissiveColor", "vReflectionColor",
  763. "vLightData0", "vLightDiffuse0", "vLightSpecular0", "vLightDirection0", "vLightGround0", "lightMatrix0",
  764. "vLightData1", "vLightDiffuse1", "vLightSpecular1", "vLightDirection1", "vLightGround1", "lightMatrix1",
  765. "vLightData2", "vLightDiffuse2", "vLightSpecular2", "vLightDirection2", "vLightGround2", "lightMatrix2",
  766. "vLightData3", "vLightDiffuse3", "vLightSpecular3", "vLightDirection3", "vLightGround3", "lightMatrix3",
  767. "vFogInfos", "vFogColor", "pointSize",
  768. "vAlbedoInfos", "vAmbientInfos", "vOpacityInfos", "vReflectionInfos", "vEmissiveInfos", "vReflectivityInfos", "vBumpInfos", "vLightmapInfos", "vRefractionInfos",
  769. "mBones",
  770. "vClipPlane", "albedoMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "reflectivityMatrix", "bumpMatrix", "lightmapMatrix", "refractionMatrix",
  771. "shadowsInfo0", "shadowsInfo1", "shadowsInfo2", "shadowsInfo3", "depthValues",
  772. "opacityParts", "emissiveLeftColor", "emissiveRightColor",
  773. "vLightingIntensity", "vOverloadedShadowIntensity", "vOverloadedIntensity", "vCameraInfos", "vOverloadedAlbedo", "vOverloadedReflection", "vOverloadedReflectivity", "vOverloadedEmissive", "vOverloadedMicroSurface",
  774. "logarithmicDepthConstant",
  775. "vSphericalX", "vSphericalY", "vSphericalZ",
  776. "vSphericalXX", "vSphericalYY", "vSphericalZZ",
  777. "vSphericalXY", "vSphericalYZ", "vSphericalZX",
  778. "vMicrosurfaceTextureLods", "vLightRadiuses"
  779. ], ["albedoSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "reflectivitySampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler",
  780. "shadowSampler0", "shadowSampler1", "shadowSampler2", "shadowSampler3"
  781. ], join, fallbacks, this.onCompiled, this.onError);
  782. }
  783. if (!this._effect.isReady()) {
  784. return false;
  785. }
  786. this._renderId = scene.getRenderId();
  787. this._wasPreviouslyReady = true;
  788. if (mesh) {
  789. if (!mesh._materialDefines) {
  790. mesh._materialDefines = new PBRMaterialDefines();
  791. }
  792. this._defines.cloneTo(mesh._materialDefines);
  793. }
  794. return true;
  795. };
  796. PBRMaterial.prototype.unbind = function () {
  797. if (this.reflectionTexture && this.reflectionTexture.isRenderTarget) {
  798. this._effect.setTexture("reflection2DSampler", null);
  799. }
  800. if (this.refractionTexture && this.refractionTexture.isRenderTarget) {
  801. this._effect.setTexture("refraction2DSampler", null);
  802. }
  803. _super.prototype.unbind.call(this);
  804. };
  805. PBRMaterial.prototype.bindOnlyWorldMatrix = function (world) {
  806. this._effect.setMatrix("world", world);
  807. };
  808. PBRMaterial.prototype.bind = function (world, mesh) {
  809. this._myScene = this.getScene();
  810. // Matrices
  811. this.bindOnlyWorldMatrix(world);
  812. // Bones
  813. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._effect);
  814. if (this._myScene.getCachedMaterial() !== this) {
  815. this._effect.setMatrix("viewProjection", this._myScene.getTransformMatrix());
  816. if (BABYLON.StandardMaterial.FresnelEnabled) {
  817. if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled) {
  818. this._effect.setColor4("opacityParts", new BABYLON.Color3(this.opacityFresnelParameters.leftColor.toLuminance(), this.opacityFresnelParameters.rightColor.toLuminance(), this.opacityFresnelParameters.bias), this.opacityFresnelParameters.power);
  819. }
  820. if (this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {
  821. this._effect.setColor4("emissiveLeftColor", this.emissiveFresnelParameters.leftColor, this.emissiveFresnelParameters.power);
  822. this._effect.setColor4("emissiveRightColor", this.emissiveFresnelParameters.rightColor, this.emissiveFresnelParameters.bias);
  823. }
  824. }
  825. // Textures
  826. if (this._myScene.texturesEnabled) {
  827. if (this.albedoTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  828. this._effect.setTexture("albedoSampler", this.albedoTexture);
  829. this._effect.setFloat2("vAlbedoInfos", this.albedoTexture.coordinatesIndex, this.albedoTexture.level);
  830. this._effect.setMatrix("albedoMatrix", this.albedoTexture.getTextureMatrix());
  831. }
  832. if (this.ambientTexture && BABYLON.StandardMaterial.AmbientTextureEnabled) {
  833. this._effect.setTexture("ambientSampler", this.ambientTexture);
  834. this._effect.setFloat2("vAmbientInfos", this.ambientTexture.coordinatesIndex, this.ambientTexture.level);
  835. this._effect.setMatrix("ambientMatrix", this.ambientTexture.getTextureMatrix());
  836. }
  837. if (this.opacityTexture && BABYLON.StandardMaterial.OpacityTextureEnabled) {
  838. this._effect.setTexture("opacitySampler", this.opacityTexture);
  839. this._effect.setFloat2("vOpacityInfos", this.opacityTexture.coordinatesIndex, this.opacityTexture.level);
  840. this._effect.setMatrix("opacityMatrix", this.opacityTexture.getTextureMatrix());
  841. }
  842. if (this.reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  843. this._microsurfaceTextureLods.x = Math.round(Math.log(this.reflectionTexture.getSize().width) * Math.LOG2E);
  844. if (this.reflectionTexture.isCube) {
  845. this._effect.setTexture("reflectionCubeSampler", this.reflectionTexture);
  846. }
  847. else {
  848. this._effect.setTexture("reflection2DSampler", this.reflectionTexture);
  849. }
  850. this._effect.setMatrix("reflectionMatrix", this.reflectionTexture.getReflectionTextureMatrix());
  851. this._effect.setFloat2("vReflectionInfos", this.reflectionTexture.level, 0);
  852. if (this._defines.USESPHERICALFROMREFLECTIONMAP) {
  853. this._effect.setFloat3("vSphericalX", this.reflectionTexture.sphericalPolynomial.x.x, this.reflectionTexture.sphericalPolynomial.x.y, this.reflectionTexture.sphericalPolynomial.x.z);
  854. this._effect.setFloat3("vSphericalY", this.reflectionTexture.sphericalPolynomial.y.x, this.reflectionTexture.sphericalPolynomial.y.y, this.reflectionTexture.sphericalPolynomial.y.z);
  855. this._effect.setFloat3("vSphericalZ", this.reflectionTexture.sphericalPolynomial.z.x, this.reflectionTexture.sphericalPolynomial.z.y, this.reflectionTexture.sphericalPolynomial.z.z);
  856. this._effect.setFloat3("vSphericalXX", this.reflectionTexture.sphericalPolynomial.xx.x, this.reflectionTexture.sphericalPolynomial.xx.y, this.reflectionTexture.sphericalPolynomial.xx.z);
  857. this._effect.setFloat3("vSphericalYY", this.reflectionTexture.sphericalPolynomial.yy.x, this.reflectionTexture.sphericalPolynomial.yy.y, this.reflectionTexture.sphericalPolynomial.yy.z);
  858. this._effect.setFloat3("vSphericalZZ", this.reflectionTexture.sphericalPolynomial.zz.x, this.reflectionTexture.sphericalPolynomial.zz.y, this.reflectionTexture.sphericalPolynomial.zz.z);
  859. this._effect.setFloat3("vSphericalXY", this.reflectionTexture.sphericalPolynomial.xy.x, this.reflectionTexture.sphericalPolynomial.xy.y, this.reflectionTexture.sphericalPolynomial.xy.z);
  860. this._effect.setFloat3("vSphericalYZ", this.reflectionTexture.sphericalPolynomial.yz.x, this.reflectionTexture.sphericalPolynomial.yz.y, this.reflectionTexture.sphericalPolynomial.yz.z);
  861. this._effect.setFloat3("vSphericalZX", this.reflectionTexture.sphericalPolynomial.zx.x, this.reflectionTexture.sphericalPolynomial.zx.y, this.reflectionTexture.sphericalPolynomial.zx.z);
  862. }
  863. }
  864. if (this.emissiveTexture && BABYLON.StandardMaterial.EmissiveTextureEnabled) {
  865. this._effect.setTexture("emissiveSampler", this.emissiveTexture);
  866. this._effect.setFloat2("vEmissiveInfos", this.emissiveTexture.coordinatesIndex, this.emissiveTexture.level);
  867. this._effect.setMatrix("emissiveMatrix", this.emissiveTexture.getTextureMatrix());
  868. }
  869. if (this.lightmapTexture && BABYLON.StandardMaterial.LightmapTextureEnabled) {
  870. this._effect.setTexture("lightmapSampler", this.lightmapTexture);
  871. this._effect.setFloat2("vLightmapInfos", this.lightmapTexture.coordinatesIndex, this.lightmapTexture.level);
  872. this._effect.setMatrix("lightmapMatrix", this.lightmapTexture.getTextureMatrix());
  873. }
  874. if (this.reflectivityTexture && BABYLON.StandardMaterial.SpecularTextureEnabled) {
  875. this._effect.setTexture("reflectivitySampler", this.reflectivityTexture);
  876. this._effect.setFloat2("vReflectivityInfos", this.reflectivityTexture.coordinatesIndex, this.reflectivityTexture.level);
  877. this._effect.setMatrix("reflectivityMatrix", this.reflectivityTexture.getTextureMatrix());
  878. }
  879. if (this.bumpTexture && this._myScene.getEngine().getCaps().standardDerivatives && BABYLON.StandardMaterial.BumpTextureEnabled && !this.disableBumpMap) {
  880. this._effect.setTexture("bumpSampler", this.bumpTexture);
  881. this._effect.setFloat3("vBumpInfos", this.bumpTexture.coordinatesIndex, 1.0 / this.bumpTexture.level, this.parallaxScaleBias);
  882. this._effect.setMatrix("bumpMatrix", this.bumpTexture.getTextureMatrix());
  883. }
  884. if (this.refractionTexture && BABYLON.StandardMaterial.RefractionTextureEnabled) {
  885. this._microsurfaceTextureLods.y = Math.round(Math.log(this.refractionTexture.getSize().width) * Math.LOG2E);
  886. var depth = 1.0;
  887. if (this.refractionTexture.isCube) {
  888. this._effect.setTexture("refractionCubeSampler", this.refractionTexture);
  889. }
  890. else {
  891. this._effect.setTexture("refraction2DSampler", this.refractionTexture);
  892. this._effect.setMatrix("refractionMatrix", this.refractionTexture.getReflectionTextureMatrix());
  893. if (this.refractionTexture.depth) {
  894. depth = this.refractionTexture.depth;
  895. }
  896. }
  897. this._effect.setFloat4("vRefractionInfos", this.refractionTexture.level, this.indexOfRefraction, depth, this.invertRefractionY ? -1 : 1);
  898. }
  899. if ((this.reflectionTexture || this.refractionTexture)) {
  900. this._effect.setFloat2("vMicrosurfaceTextureLods", this._microsurfaceTextureLods.x, this._microsurfaceTextureLods.y);
  901. }
  902. }
  903. // Clip plane
  904. BABYLON.MaterialHelper.BindClipPlane(this._effect, this._myScene);
  905. // Point size
  906. if (this.pointsCloud) {
  907. this._effect.setFloat("pointSize", this.pointSize);
  908. }
  909. // Colors
  910. this._myScene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
  911. // GAMMA CORRECTION.
  912. this.convertColorToLinearSpaceToRef(this.reflectivityColor, PBRMaterial._scaledReflectivity);
  913. this._effect.setVector3("vEyePosition", this._myScene._mirroredCameraPosition ? this._myScene._mirroredCameraPosition : this._myScene.activeCamera.position);
  914. this._effect.setColor3("vAmbientColor", this._globalAmbientColor);
  915. this._effect.setColor4("vReflectivityColor", PBRMaterial._scaledReflectivity, this.microSurface);
  916. // GAMMA CORRECTION.
  917. this.convertColorToLinearSpaceToRef(this.emissiveColor, PBRMaterial._scaledEmissive);
  918. this._effect.setColor3("vEmissiveColor", PBRMaterial._scaledEmissive);
  919. // GAMMA CORRECTION.
  920. this.convertColorToLinearSpaceToRef(this.reflectionColor, PBRMaterial._scaledReflection);
  921. this._effect.setColor3("vReflectionColor", PBRMaterial._scaledReflection);
  922. }
  923. if (this._myScene.getCachedMaterial() !== this || !this.isFrozen) {
  924. // GAMMA CORRECTION.
  925. this.convertColorToLinearSpaceToRef(this.albedoColor, PBRMaterial._scaledAlbedo);
  926. this._effect.setColor4("vAlbedoColor", PBRMaterial._scaledAlbedo, this.alpha * mesh.visibility);
  927. // Lights
  928. if (this._myScene.lightsEnabled && !this.disableLighting) {
  929. PBRMaterial.BindLights(this._myScene, mesh, this._effect, this._defines, this.useScalarInLinearSpace);
  930. }
  931. // View
  932. if (this._myScene.fogEnabled && mesh.applyFog && this._myScene.fogMode !== BABYLON.Scene.FOGMODE_NONE || this.reflectionTexture) {
  933. this._effect.setMatrix("view", this._myScene.getViewMatrix());
  934. }
  935. // Fog
  936. BABYLON.MaterialHelper.BindFogParameters(this._myScene, mesh, this._effect);
  937. this._lightingInfos.x = this.directIntensity;
  938. this._lightingInfos.y = this.emissiveIntensity;
  939. this._lightingInfos.z = this.environmentIntensity;
  940. this._lightingInfos.w = this.specularIntensity;
  941. this._effect.setVector4("vLightingIntensity", this._lightingInfos);
  942. this._overloadedShadowInfos.x = this.overloadedShadowIntensity;
  943. this._overloadedShadowInfos.y = this.overloadedShadeIntensity;
  944. this._effect.setVector4("vOverloadedShadowIntensity", this._overloadedShadowInfos);
  945. this._cameraInfos.x = this.cameraExposure;
  946. this._cameraInfos.y = this.cameraContrast;
  947. this._effect.setVector4("vCameraInfos", this._cameraInfos);
  948. this._overloadedIntensity.x = this.overloadedAmbientIntensity;
  949. this._overloadedIntensity.y = this.overloadedAlbedoIntensity;
  950. this._overloadedIntensity.z = this.overloadedReflectivityIntensity;
  951. this._overloadedIntensity.w = this.overloadedEmissiveIntensity;
  952. this._effect.setVector4("vOverloadedIntensity", this._overloadedIntensity);
  953. this.convertColorToLinearSpaceToRef(this.overloadedAmbient, this._tempColor);
  954. this._effect.setColor3("vOverloadedAmbient", this._tempColor);
  955. this.convertColorToLinearSpaceToRef(this.overloadedAlbedo, this._tempColor);
  956. this._effect.setColor3("vOverloadedAlbedo", this._tempColor);
  957. this.convertColorToLinearSpaceToRef(this.overloadedReflectivity, this._tempColor);
  958. this._effect.setColor3("vOverloadedReflectivity", this._tempColor);
  959. this.convertColorToLinearSpaceToRef(this.overloadedEmissive, this._tempColor);
  960. this._effect.setColor3("vOverloadedEmissive", this._tempColor);
  961. this.convertColorToLinearSpaceToRef(this.overloadedReflection, this._tempColor);
  962. this._effect.setColor3("vOverloadedReflection", this._tempColor);
  963. this._overloadedMicroSurface.x = this.overloadedMicroSurface;
  964. this._overloadedMicroSurface.y = this.overloadedMicroSurfaceIntensity;
  965. this._overloadedMicroSurface.z = this.overloadedReflectionIntensity;
  966. this._effect.setVector3("vOverloadedMicroSurface", this._overloadedMicroSurface);
  967. // Log. depth
  968. BABYLON.MaterialHelper.BindLogDepth(this._defines, this._effect, this._myScene);
  969. }
  970. _super.prototype.bind.call(this, world, mesh);
  971. this._myScene = null;
  972. };
  973. PBRMaterial.prototype.getAnimatables = function () {
  974. var results = [];
  975. if (this.albedoTexture && this.albedoTexture.animations && this.albedoTexture.animations.length > 0) {
  976. results.push(this.albedoTexture);
  977. }
  978. if (this.ambientTexture && this.ambientTexture.animations && this.ambientTexture.animations.length > 0) {
  979. results.push(this.ambientTexture);
  980. }
  981. if (this.opacityTexture && this.opacityTexture.animations && this.opacityTexture.animations.length > 0) {
  982. results.push(this.opacityTexture);
  983. }
  984. if (this.reflectionTexture && this.reflectionTexture.animations && this.reflectionTexture.animations.length > 0) {
  985. results.push(this.reflectionTexture);
  986. }
  987. if (this.emissiveTexture && this.emissiveTexture.animations && this.emissiveTexture.animations.length > 0) {
  988. results.push(this.emissiveTexture);
  989. }
  990. if (this.reflectivityTexture && this.reflectivityTexture.animations && this.reflectivityTexture.animations.length > 0) {
  991. results.push(this.reflectivityTexture);
  992. }
  993. if (this.bumpTexture && this.bumpTexture.animations && this.bumpTexture.animations.length > 0) {
  994. results.push(this.bumpTexture);
  995. }
  996. if (this.lightmapTexture && this.lightmapTexture.animations && this.lightmapTexture.animations.length > 0) {
  997. results.push(this.lightmapTexture);
  998. }
  999. if (this.refractionTexture && this.refractionTexture.animations && this.refractionTexture.animations.length > 0) {
  1000. results.push(this.refractionTexture);
  1001. }
  1002. return results;
  1003. };
  1004. PBRMaterial.prototype.dispose = function (forceDisposeEffect) {
  1005. if (this.albedoTexture) {
  1006. this.albedoTexture.dispose();
  1007. }
  1008. if (this.ambientTexture) {
  1009. this.ambientTexture.dispose();
  1010. }
  1011. if (this.opacityTexture) {
  1012. this.opacityTexture.dispose();
  1013. }
  1014. if (this.reflectionTexture) {
  1015. this.reflectionTexture.dispose();
  1016. }
  1017. if (this.emissiveTexture) {
  1018. this.emissiveTexture.dispose();
  1019. }
  1020. if (this.reflectivityTexture) {
  1021. this.reflectivityTexture.dispose();
  1022. }
  1023. if (this.bumpTexture) {
  1024. this.bumpTexture.dispose();
  1025. }
  1026. if (this.lightmapTexture) {
  1027. this.lightmapTexture.dispose();
  1028. }
  1029. if (this.refractionTexture) {
  1030. this.refractionTexture.dispose();
  1031. }
  1032. _super.prototype.dispose.call(this, forceDisposeEffect);
  1033. };
  1034. PBRMaterial.prototype.clone = function (name) {
  1035. var _this = this;
  1036. return BABYLON.SerializationHelper.Clone(function () { return new PBRMaterial(name, _this.getScene()); }, this);
  1037. };
  1038. PBRMaterial.prototype.serialize = function () {
  1039. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  1040. serializationObject.customType = "BABYLON.PBRMaterial";
  1041. return serializationObject;
  1042. };
  1043. // Statics
  1044. PBRMaterial.Parse = function (source, scene, rootUrl) {
  1045. return BABYLON.SerializationHelper.Parse(function () { return new PBRMaterial(source.name, scene); }, source, scene, rootUrl);
  1046. };
  1047. PBRMaterial._scaledAlbedo = new BABYLON.Color3();
  1048. PBRMaterial._scaledReflectivity = new BABYLON.Color3();
  1049. PBRMaterial._scaledEmissive = new BABYLON.Color3();
  1050. PBRMaterial._scaledReflection = new BABYLON.Color3();
  1051. PBRMaterial._lightRadiuses = [1, 1, 1, 1];
  1052. __decorate([
  1053. BABYLON.serialize()
  1054. ], PBRMaterial.prototype, "directIntensity");
  1055. __decorate([
  1056. BABYLON.serialize()
  1057. ], PBRMaterial.prototype, "emissiveIntensity");
  1058. __decorate([
  1059. BABYLON.serialize()
  1060. ], PBRMaterial.prototype, "environmentIntensity");
  1061. __decorate([
  1062. BABYLON.serialize()
  1063. ], PBRMaterial.prototype, "specularIntensity");
  1064. __decorate([
  1065. BABYLON.serialize()
  1066. ], PBRMaterial.prototype, "disableBumpMap");
  1067. __decorate([
  1068. BABYLON.serialize()
  1069. ], PBRMaterial.prototype, "overloadedShadowIntensity");
  1070. __decorate([
  1071. BABYLON.serialize()
  1072. ], PBRMaterial.prototype, "overloadedShadeIntensity");
  1073. __decorate([
  1074. BABYLON.serialize()
  1075. ], PBRMaterial.prototype, "cameraExposure");
  1076. __decorate([
  1077. BABYLON.serialize()
  1078. ], PBRMaterial.prototype, "cameraContrast");
  1079. __decorate([
  1080. BABYLON.serializeAsColor3()
  1081. ], PBRMaterial.prototype, "overloadedAmbient");
  1082. __decorate([
  1083. BABYLON.serialize()
  1084. ], PBRMaterial.prototype, "overloadedAmbientIntensity");
  1085. __decorate([
  1086. BABYLON.serializeAsColor3()
  1087. ], PBRMaterial.prototype, "overloadedAlbedo");
  1088. __decorate([
  1089. BABYLON.serialize()
  1090. ], PBRMaterial.prototype, "overloadedAlbedoIntensity");
  1091. __decorate([
  1092. BABYLON.serializeAsColor3()
  1093. ], PBRMaterial.prototype, "overloadedReflectivity");
  1094. __decorate([
  1095. BABYLON.serialize()
  1096. ], PBRMaterial.prototype, "overloadedReflectivityIntensity");
  1097. __decorate([
  1098. BABYLON.serializeAsColor3()
  1099. ], PBRMaterial.prototype, "overloadedEmissive");
  1100. __decorate([
  1101. BABYLON.serialize()
  1102. ], PBRMaterial.prototype, "overloadedEmissiveIntensity");
  1103. __decorate([
  1104. BABYLON.serializeAsColor3()
  1105. ], PBRMaterial.prototype, "overloadedReflection");
  1106. __decorate([
  1107. BABYLON.serialize()
  1108. ], PBRMaterial.prototype, "overloadedReflectionIntensity");
  1109. __decorate([
  1110. BABYLON.serialize()
  1111. ], PBRMaterial.prototype, "overloadedMicroSurface");
  1112. __decorate([
  1113. BABYLON.serialize()
  1114. ], PBRMaterial.prototype, "overloadedMicroSurfaceIntensity");
  1115. __decorate([
  1116. BABYLON.serializeAsTexture()
  1117. ], PBRMaterial.prototype, "albedoTexture");
  1118. __decorate([
  1119. BABYLON.serializeAsTexture()
  1120. ], PBRMaterial.prototype, "ambientTexture");
  1121. __decorate([
  1122. BABYLON.serializeAsTexture()
  1123. ], PBRMaterial.prototype, "opacityTexture");
  1124. __decorate([
  1125. BABYLON.serializeAsTexture()
  1126. ], PBRMaterial.prototype, "reflectionTexture");
  1127. __decorate([
  1128. BABYLON.serializeAsTexture()
  1129. ], PBRMaterial.prototype, "emissiveTexture");
  1130. __decorate([
  1131. BABYLON.serializeAsTexture()
  1132. ], PBRMaterial.prototype, "reflectivityTexture");
  1133. __decorate([
  1134. BABYLON.serializeAsTexture()
  1135. ], PBRMaterial.prototype, "bumpTexture");
  1136. __decorate([
  1137. BABYLON.serializeAsTexture()
  1138. ], PBRMaterial.prototype, "lightmapTexture");
  1139. __decorate([
  1140. BABYLON.serializeAsTexture()
  1141. ], PBRMaterial.prototype, "refractionTexture");
  1142. __decorate([
  1143. BABYLON.serializeAsColor3("ambient")
  1144. ], PBRMaterial.prototype, "ambientColor");
  1145. __decorate([
  1146. BABYLON.serializeAsColor3("albedo")
  1147. ], PBRMaterial.prototype, "albedoColor");
  1148. __decorate([
  1149. BABYLON.serializeAsColor3("reflectivity")
  1150. ], PBRMaterial.prototype, "reflectivityColor");
  1151. __decorate([
  1152. BABYLON.serializeAsColor3("reflection")
  1153. ], PBRMaterial.prototype, "reflectionColor");
  1154. __decorate([
  1155. BABYLON.serializeAsColor3("emissivie")
  1156. ], PBRMaterial.prototype, "emissiveColor");
  1157. __decorate([
  1158. BABYLON.serialize()
  1159. ], PBRMaterial.prototype, "microSurface");
  1160. __decorate([
  1161. BABYLON.serialize()
  1162. ], PBRMaterial.prototype, "indexOfRefraction");
  1163. __decorate([
  1164. BABYLON.serialize()
  1165. ], PBRMaterial.prototype, "invertRefractionY");
  1166. __decorate([
  1167. BABYLON.serializeAsFresnelParameters()
  1168. ], PBRMaterial.prototype, "opacityFresnelParameters");
  1169. __decorate([
  1170. BABYLON.serializeAsFresnelParameters()
  1171. ], PBRMaterial.prototype, "emissiveFresnelParameters");
  1172. __decorate([
  1173. BABYLON.serialize()
  1174. ], PBRMaterial.prototype, "linkRefractionWithTransparency");
  1175. __decorate([
  1176. BABYLON.serialize()
  1177. ], PBRMaterial.prototype, "linkEmissiveWithAlbedo");
  1178. __decorate([
  1179. BABYLON.serialize()
  1180. ], PBRMaterial.prototype, "useLightmapAsShadowmap");
  1181. __decorate([
  1182. BABYLON.serialize()
  1183. ], PBRMaterial.prototype, "useEmissiveAsIllumination");
  1184. __decorate([
  1185. BABYLON.serialize()
  1186. ], PBRMaterial.prototype, "useAlphaFromAlbedoTexture");
  1187. __decorate([
  1188. BABYLON.serialize()
  1189. ], PBRMaterial.prototype, "useSpecularOverAlpha");
  1190. __decorate([
  1191. BABYLON.serialize()
  1192. ], PBRMaterial.prototype, "useMicroSurfaceFromReflectivityMapAlpha");
  1193. __decorate([
  1194. BABYLON.serialize()
  1195. ], PBRMaterial.prototype, "useAutoMicroSurfaceFromReflectivityMap");
  1196. __decorate([
  1197. BABYLON.serialize()
  1198. ], PBRMaterial.prototype, "useScalarInLinearSpace");
  1199. __decorate([
  1200. BABYLON.serialize()
  1201. ], PBRMaterial.prototype, "usePhysicalLightFalloff");
  1202. __decorate([
  1203. BABYLON.serialize()
  1204. ], PBRMaterial.prototype, "useRadianceOverAlpha");
  1205. __decorate([
  1206. BABYLON.serialize()
  1207. ], PBRMaterial.prototype, "useParallax");
  1208. __decorate([
  1209. BABYLON.serialize()
  1210. ], PBRMaterial.prototype, "useParallaxOcclusion");
  1211. __decorate([
  1212. BABYLON.serialize()
  1213. ], PBRMaterial.prototype, "parallaxScaleBias");
  1214. __decorate([
  1215. BABYLON.serialize()
  1216. ], PBRMaterial.prototype, "disableLighting");
  1217. Object.defineProperty(PBRMaterial.prototype, "useLogarithmicDepth",
  1218. __decorate([
  1219. BABYLON.serialize()
  1220. ], PBRMaterial.prototype, "useLogarithmicDepth", Object.getOwnPropertyDescriptor(PBRMaterial.prototype, "useLogarithmicDepth")));
  1221. return PBRMaterial;
  1222. })(BABYLON.Material);
  1223. BABYLON.PBRMaterial = PBRMaterial;
  1224. })(BABYLON || (BABYLON = {}));
  1225. BABYLON.Effect.ShadersStore['pbrVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\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>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef ALBEDO\nvarying vec2 vAlbedoUV;\nuniform mat4 albedoMatrix;\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform mat4 ambientMatrix;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY\nvarying vec2 vOpacityUV;\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nvarying vec2 vLightmapUV;\nuniform vec2 vLightmapInfos;\nuniform mat4 lightmapMatrix;\n#endif\n#if defined(REFLECTIVITY)\nvarying vec2 vReflectivityUV;\nuniform vec2 vReflectivityInfos;\nuniform mat4 reflectivityMatrix;\n#endif\n#ifdef BUMP\nvarying vec2 vBumpUV;\nuniform vec2 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<shadowsVertexDeclaration>\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR_FIXED\nvarying vec3 vDirectionW;\n#endif\n#include<logDepthDeclaration>\nvoid main(void) {\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=position;\n#endif \n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR_FIXED\nvDirectionW=normalize(vec3(finalWorld*vec4(position,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)\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 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<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n\n#include<logDepthVertex>\n}";
  1226. BABYLON.Effect.ShadersStore['pbrPixelShader'] = "#ifdef BUMP\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\n#define RECIPROCAL_PI2 0.15915494\n#define FRESNEL_MAXIMUM_ON_ROUGH 0.25\nuniform vec3 vEyePosition;\nuniform vec3 vAmbientColor;\nuniform vec3 vReflectionColor;\nuniform vec4 vAlbedoColor;\nuniform vec4 vLightRadiuses;\n\nuniform vec4 vLightingIntensity;\nuniform vec4 vCameraInfos;\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#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\n#if defined(REFLECTION) || defined(REFRACTION)\nuniform vec2 vMicrosurfaceTextureLods;\n#endif\n\nconst float kPi=3.1415926535897932384626433832795;\nconst float kRougnhessToAlphaScale=0.1;\nconst float kRougnhessToAlphaOffset=0.29248125;\n\nfloat Square(float value)\n{\nreturn value*value;\n}\nfloat getLuminance(vec3 color)\n{\nreturn clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);\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)\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,vec3(1.,1.,1.));\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\nfloat lightRoughness=lightRadius/lightDistance;\n\nfloat totalRoughness=clamp(lightRoughness+roughness,0.,1.);\nreturn totalRoughness;\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}\nvec3 toLinearSpace(vec3 color)\n{\nreturn vec3(pow(color.r,2.2),pow(color.g,2.2),pow(color.b,2.2));\n}\nvec3 toGammaSpace(vec3 color)\n{\nreturn vec3(pow(color.r,1.0/2.2),pow(color.g,1.0/2.2),pow(color.b,1.0/2.2));\n}\nfloat computeLightFalloff(vec3 lightOffset,float lightDistanceSquared,float range)\n{\n#ifdef USEPHYSICALLIGHTFALLOFF\nfloat lightDistanceFalloff=1.0/((lightDistanceSquared+0.0001));\nreturn lightDistanceFalloff;\n#else\nfloat lightFalloff=max(0.,1.0-length(lightOffset)/range);\nreturn lightFalloff;\n#endif\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\nuniform vec4 vReflectivityColor;\nuniform vec3 vEmissiveColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<lightFragmentDeclaration>[0]\n#include<lightFragmentDeclaration>[1]\n#include<lightFragmentDeclaration>[2]\n#include<lightFragmentDeclaration>[3]\n\n#ifdef ALBEDO\nvarying vec2 vAlbedoUV;\nuniform sampler2D albedoSampler;\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform sampler2D ambientSampler;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY \nvarying vec2 vOpacityUV;\nuniform sampler2D opacitySampler;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform vec2 vEmissiveInfos;\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\nvarying vec2 vLightmapUV;\nuniform vec2 vLightmapInfos;\nuniform sampler2D lightmapSampler;\n#endif\n#if defined(REFLECTIVITY)\nvarying vec2 vReflectivityUV;\nuniform vec2 vReflectivityInfos;\nuniform sampler2D reflectivitySampler;\n#endif\n\n#include<fresnelFunction>\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\nuniform samplerCube refractionCubeSampler;\n#else\nuniform sampler2D refraction2DSampler;\nuniform mat4 refractionMatrix;\n#endif\n#endif\n\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\n#ifdef REFLECTIONMAP_3D\nuniform samplerCube reflectionCubeSampler;\n#else\nuniform sampler2D reflection2DSampler;\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR_FIXED\nvarying vec3 vDirectionW;\n#endif\n#if defined(REFLECTIONMAP_PLANAR) || defined(REFLECTIONMAP_CUBIC) || defined(REFLECTIONMAP_PROJECTION)\nuniform mat4 reflectionMatrix;\n#endif\n#endif\n#include<reflectionFunction>\n#endif\n\n#ifdef SHADOWS\nfloat unpack(vec4 color)\n{\nconst vec4 bit_shift=vec4(1.0/(255.0*255.0*255.0),1.0/(255.0*255.0),1.0/255.0,1.0);\nreturn dot(color,bit_shift);\n}\n#if defined(POINTLIGHT0) || defined(POINTLIGHT1) || defined(POINTLIGHT2) || defined(POINTLIGHT3)\nuniform vec2 depthValues;\nfloat computeShadowCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float bias)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y =-directionToLight.y;\nfloat shadow=unpack(textureCube(shadowSampler,directionToLight))+bias;\nif (depth>shadow)\n{\n#ifdef OVERLOADEDSHADOWVALUES\nreturn mix(1.0,darkness,vOverloadedShadowIntensity.x);\n#else\nreturn darkness;\n#endif\n}\nreturn 1.0;\n}\nfloat computeShadowWithPCFCube(vec3 lightPosition,samplerCube shadowSampler,float mapSize,float bias,float darkness)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth-depthValues.x)/(depthValues.y-depthValues.x);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\nfloat visibility=1.;\nvec3 poissonDisk[4];\npoissonDisk[0]=vec3(-1.0,1.0,-1.0);\npoissonDisk[1]=vec3(1.0,-1.0,-1.0);\npoissonDisk[2]=vec3(-1.0,-1.0,-1.0);\npoissonDisk[3]=vec3(1.0,-1.0,1.0);\n\nfloat biasedDepth=depth-bias;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[1]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[2]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[3]*mapSize))<biasedDepth) visibility-=0.25;\n#ifdef OVERLOADEDSHADOWVALUES\nreturn min(1.0,mix(1.0,visibility+darkness,vOverloadedShadowIntensity.x));\n#else\nreturn min(1.0,visibility+darkness);\n#endif\n}\n#endif\n#if defined(SPOTLIGHT0) || defined(SPOTLIGHT1) || defined(SPOTLIGHT2) || defined(SPOTLIGHT3) || defined(DIRLIGHT0) || defined(DIRLIGHT1) || defined(DIRLIGHT2) || defined(DIRLIGHT3)\nfloat computeShadow(vec4 vPositionFromLight,sampler2D shadowSampler,float darkness,float bias)\n{\nvec3 depth=vPositionFromLight.xyz/vPositionFromLight.w;\ndepth=0.5*depth+vec3(0.5);\nvec2 uv=depth.xy;\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadow=unpack(texture2D(shadowSampler,uv))+bias;\nif (depth.z>shadow)\n{\n#ifdef OVERLOADEDSHADOWVALUES\nreturn mix(1.0,darkness,vOverloadedShadowIntensity.x);\n#else\nreturn darkness;\n#endif\n}\nreturn 1.;\n}\nfloat computeShadowWithPCF(vec4 vPositionFromLight,sampler2D shadowSampler,float mapSize,float bias,float darkness)\n{\nvec3 depth=vPositionFromLight.xyz/vPositionFromLight.w;\ndepth=0.5*depth+vec3(0.5);\nvec2 uv=depth.xy;\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat visibility=1.;\nvec2 poissonDisk[4];\npoissonDisk[0]=vec2(-0.94201624,-0.39906216);\npoissonDisk[1]=vec2(0.94558609,-0.76890725);\npoissonDisk[2]=vec2(-0.094184101,-0.92938870);\npoissonDisk[3]=vec2(0.34495938,0.29387760);\n\nfloat biasedDepth=depth.z-bias;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[0]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[1]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[2]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[3]*mapSize))<biasedDepth) visibility-=0.25;\n#ifdef OVERLOADEDSHADOWVALUES\nreturn min(1.0,mix(1.0,visibility+darkness,vOverloadedShadowIntensity.x));\n#else\nreturn min(1.0,visibility+darkness);\n#endif\n}\n\nfloat unpackHalf(vec2 color)\n{\nreturn color.x+(color.y/255.0);\n}\nfloat linstep(float low,float high,float v) {\nreturn clamp((v-low)/(high-low),0.0,1.0);\n}\nfloat ChebychevInequality(vec2 moments,float compare,float bias)\n{\nfloat p=smoothstep(compare-bias,compare,moments.x);\nfloat variance=max(moments.y-moments.x*moments.x,0.02);\nfloat d=compare-moments.x;\nfloat p_max=linstep(0.2,1.0,variance/(variance+d*d));\nreturn clamp(max(p,p_max),0.0,1.0);\n}\nfloat computeShadowWithVSM(vec4 vPositionFromLight,sampler2D shadowSampler,float bias,float darkness)\n{\nvec3 depth=vPositionFromLight.xyz/vPositionFromLight.w;\ndepth=0.5*depth+vec3(0.5);\nvec2 uv=depth.xy;\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0 || depth.z>=1.0)\n{\nreturn 1.0;\n}\nvec4 texel=texture2D(shadowSampler,uv);\nvec2 moments=vec2(unpackHalf(texel.xy),unpackHalf(texel.zw));\n#ifdef OVERLOADEDSHADOWVALUES\nreturn min(1.0,mix(1.0,1.0-ChebychevInequality(moments,depth.z,bias)+darkness,vOverloadedShadowIntensity.x));\n#else\nreturn min(1.0,1.0-ChebychevInequality(moments,depth.z,bias)+darkness);\n#endif\n}\n#endif\n#endif\n#include<bumpFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\n\n#include<fogFragmentDeclaration>\n\nstruct lightingInfo\n{\nvec3 diffuse;\n#ifdef SPECULARTERM\nvec3 specular;\n#endif\n};\nlightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float range,float roughness,float NdotV,float lightRadius,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=computeLightFalloff(lightOffset,lightDistanceSquared,range);\nlightDistance=sqrt(lightDistanceSquared);\nlightDirection=normalize(lightOffset);\n}\n\nelse\n{\nlightDistance=length(-lightData.xyz);\nlightDirection=normalize(-lightData.xyz);\n}\n\nroughness=adjustRoughnessFromLightProperties(roughness,lightRadius,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);\nresult.specular=specTerm*attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float range,float roughness,float NdotV,float lightRadius,out float NdotL) {\nlightingInfo result;\nvec3 lightOffset=lightData.xyz-vPositionW;\nvec3 lightVectorW=normalize(lightOffset);\n\nfloat cosAngle=max(0.000000000000001,dot(-lightDirection.xyz,lightVectorW));\nif (cosAngle>=lightDirection.w)\n{\ncosAngle=max(0.,pow(cosAngle,lightData.w));\n\nfloat lightDistanceSquared=dot(lightOffset,lightOffset);\nfloat attenuation=computeLightFalloff(lightOffset,lightDistanceSquared,range);\n\nattenuation*=cosAngle;\n\nfloat lightDistance=sqrt(lightDistanceSquared);\nroughness=adjustRoughnessFromLightProperties(roughness,lightRadius,lightDistance);\n\nvec3 H=normalize(viewDirectionW-lightDirection.xyz);\nNdotL=max(0.00000000001,dot(vNormal,-lightDirection.xyz));\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);\nresult.specular=specTerm*attenuation;\n#endif\nreturn result;\n}\nresult.diffuse=vec3(0.);\n#ifdef SPECULARTERM\nresult.specular=vec3(0.);\n#endif\nreturn result;\n}\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float roughness,float NdotV,float lightRadius,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);\nresult.specular=specTerm;\n#endif\nreturn result;\n}\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 surfaceAlbedo=vec4(1.,1.,1.,1.);\nvec3 surfaceAlbedoContribution=vAlbedoColor.rgb;\n\nfloat alpha=vAlbedoColor.a;\n#ifdef ALBEDO\nsurfaceAlbedo=texture2D(albedoSampler,vAlbedoUV);\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\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n#include<bumpFragment>\n\nvec3 ambientColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nambientColor=texture2D(ambientSampler,vAmbientUV).rgb*vAmbientInfos.y;\n#ifdef OVERLOADEDVALUES\nambientColor.rgb=mix(ambientColor.rgb,vOverloadedAmbient,vOverloadedIntensity.x);\n#endif\n#endif\n\nfloat microSurface=vReflectivityColor.a;\nvec3 surfaceReflectivityColor=vReflectivityColor.rgb;\n#ifdef OVERLOADEDVALUES\nsurfaceReflectivityColor.rgb=mix(surfaceReflectivityColor.rgb,vOverloadedReflectivity,vOverloadedIntensity.z);\n#endif\n#ifdef REFLECTIVITY\nvec4 surfaceReflectivityColorMap=texture2D(reflectivitySampler,vReflectivityUV);\nsurfaceReflectivityColor=surfaceReflectivityColorMap.rgb;\nsurfaceReflectivityColor=toLinearSpace(surfaceReflectivityColor);\n#ifdef OVERLOADEDVALUES\nsurfaceReflectivityColor=mix(surfaceReflectivityColor,vOverloadedReflectivity,vOverloadedIntensity.z);\n#endif\n#ifdef MICROSURFACEFROMREFLECTIVITYMAP\nmicroSurface=surfaceReflectivityColorMap.a;\n#else\n#ifdef MICROSURFACEAUTOMATIC\nmicroSurface=computeDefaultMicroSurface(microSurface,surfaceReflectivityColor);\n#endif\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.; \nfloat NdotL=-1.;\n#ifdef LIGHT0\n#ifndef SPECULARTERM\nvec3 vLightSpecular0=vec3(0.0);\n#endif\n#ifdef SPOTLIGHT0\nlightingInfo info=computeSpotLighting(viewDirectionW,normalW,vLightData0,vLightDirection0,vLightDiffuse0.rgb,vLightSpecular0,vLightDiffuse0.a,roughness,NdotV,vLightRadiuses[0],NdotL);\n#endif\n#ifdef HEMILIGHT0\nlightingInfo info=computeHemisphericLighting(viewDirectionW,normalW,vLightData0,vLightDiffuse0.rgb,vLightSpecular0,vLightGround0,roughness,NdotV,vLightRadiuses[0],NdotL);\n#endif\n#if defined(POINTLIGHT0) || defined(DIRLIGHT0)\nlightingInfo info=computeLighting(viewDirectionW,normalW,vLightData0,vLightDiffuse0.rgb,vLightSpecular0,vLightDiffuse0.a,roughness,NdotV,vLightRadiuses[0],NdotL);\n#endif\n#ifdef SHADOW0\n#ifdef SHADOWVSM0\nnotShadowLevel=computeShadowWithVSM(vPositionFromLight0,shadowSampler0,shadowsInfo0.z,shadowsInfo0.x);\n#else\n#ifdef SHADOWPCF0\n#if defined(POINTLIGHT0)\nnotShadowLevel=computeShadowWithPCFCube(vLightData0.xyz,shadowSampler0,shadowsInfo0.y,shadowsInfo0.z,shadowsInfo0.x);\n#else\nnotShadowLevel=computeShadowWithPCF(vPositionFromLight0,shadowSampler0,shadowsInfo0.y,shadowsInfo0.z,shadowsInfo0.x);\n#endif\n#else\n#if defined(POINTLIGHT0)\nnotShadowLevel=computeShadowCube(vLightData0.xyz,shadowSampler0,shadowsInfo0.x,shadowsInfo0.z);\n#else\nnotShadowLevel=computeShadow(vPositionFromLight0,shadowSampler0,shadowsInfo0.x,shadowsInfo0.z);\n#endif\n#endif\n#endif\n#else\nnotShadowLevel=1.;\n#endif\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#ifdef LIGHT1\n#ifndef SPECULARTERM\nvec3 vLightSpecular1=vec3(0.0);\n#endif\n#ifdef SPOTLIGHT1\ninfo=computeSpotLighting(viewDirectionW,normalW,vLightData1,vLightDirection1,vLightDiffuse1.rgb,vLightSpecular1,vLightDiffuse1.a,roughness,NdotV,vLightRadiuses[1],NdotL);\n#endif\n#ifdef HEMILIGHT1\ninfo=computeHemisphericLighting(viewDirectionW,normalW,vLightData1,vLightDiffuse1.rgb,vLightSpecular1,vLightGround1,roughness,NdotV,vLightRadiuses[1],NdotL);\n#endif\n#if defined(POINTLIGHT1) || defined(DIRLIGHT1)\ninfo=computeLighting(viewDirectionW,normalW,vLightData1,vLightDiffuse1.rgb,vLightSpecular1,vLightDiffuse1.a,roughness,NdotV,vLightRadiuses[1],NdotL);\n#endif\n#ifdef SHADOW1\n#ifdef SHADOWVSM1\nnotShadowLevel=computeShadowWithVSM(vPositionFromLight1,shadowSampler1,shadowsInfo1.z,shadowsInfo1.x);\n#else\n#ifdef SHADOWPCF1\n#if defined(POINTLIGHT1)\nnotShadowLevel=computeShadowWithPCFCube(vLightData1.xyz,shadowSampler1,shadowsInfo1.y,shadowsInfo1.z,shadowsInfo1.x);\n#else\nnotShadowLevel=computeShadowWithPCF(vPositionFromLight1,shadowSampler1,shadowsInfo1.y,shadowsInfo1.z,shadowsInfo1.x);\n#endif\n#else\n#if defined(POINTLIGHT1)\nnotShadowLevel=computeShadowCube(vLightData1.xyz,shadowSampler1,shadowsInfo1.x,shadowsInfo1.z);\n#else\nnotShadowLevel=computeShadow(vPositionFromLight1,shadowSampler1,shadowsInfo1.x,shadowsInfo1.z);\n#endif\n#endif\n#endif\n#else\nnotShadowLevel=1.;\n#endif\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#ifdef LIGHT2\n#ifndef SPECULARTERM\nvec3 vLightSpecular2=vec3(0.0);\n#endif\n#ifdef SPOTLIGHT2\ninfo=computeSpotLighting(viewDirectionW,normalW,vLightData2,vLightDirection2,vLightDiffuse2.rgb,vLightSpecular2,vLightDiffuse2.a,roughness,NdotV,vLightRadiuses[2],NdotL);\n#endif\n#ifdef HEMILIGHT2\ninfo=computeHemisphericLighting(viewDirectionW,normalW,vLightData2,vLightDiffuse2.rgb,vLightSpecular2,vLightGround2,roughness,NdotV,vLightRadiuses[2],NdotL);\n#endif\n#if defined(POINTLIGHT2) || defined(DIRLIGHT2)\ninfo=computeLighting(viewDirectionW,normalW,vLightData2,vLightDiffuse2.rgb,vLightSpecular2,vLightDiffuse2.a,roughness,NdotV,vLightRadiuses[2],NdotL);\n#endif\n#ifdef SHADOW2\n#ifdef SHADOWVSM2\nnotShadowLevel=computeShadowWithVSM(vPositionFromLight2,shadowSampler2,shadowsInfo2.z,shadowsInfo2.x);\n#else\n#ifdef SHADOWPCF2\n#if defined(POINTLIGHT2)\nnotShadowLevel=computeShadowWithPCFCube(vLightData2.xyz,shadowSampler2,shadowsInfo2.y,shadowsInfo2.z,shadowsInfo2.x);\n#else\nnotShadowLevel=computeShadowWithPCF(vPositionFromLight2,shadowSampler2,shadowsInfo2.y,shadowsInfo2.z,shadowsInfo2.x);\n#endif\n#else\n#if defined(POINTLIGHT2)\nnotShadowLevel=computeShadowCube(vLightData2.xyz,shadowSampler2,shadowsInfo2.x,shadowsInfo2.z);\n#else\nnotShadowLevel=computeShadow(vPositionFromLight2,shadowSampler2,shadowsInfo2.x,shadowsInfo2.z);\n#endif\n#endif \n#endif \n#else\nnotShadowLevel=1.;\n#endif\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#ifdef LIGHT3\n#ifndef SPECULARTERM\nvec3 vLightSpecular3=vec3(0.0);\n#endif\n#ifdef SPOTLIGHT3\ninfo=computeSpotLighting(viewDirectionW,normalW,vLightData3,vLightDirection3,vLightDiffuse3.rgb,vLightSpecular3,vLightDiffuse3.a,roughness,NdotV,vLightRadiuses[3],NdotL);\n#endif\n#ifdef HEMILIGHT3\ninfo=computeHemisphericLighting(viewDirectionW,normalW,vLightData3,vLightDiffuse3.rgb,vLightSpecular3,vLightGround3,roughness,NdotV,vLightRadiuses[3],NdotL);\n#endif\n#if defined(POINTLIGHT3) || defined(DIRLIGHT3)\ninfo=computeLighting(viewDirectionW,normalW,vLightData3,vLightDiffuse3.rgb,vLightSpecular3,vLightDiffuse3.a,roughness,NdotV,vLightRadiuses[3],NdotL);\n#endif\n#ifdef SHADOW3\n#ifdef SHADOWVSM3\nnotShadowLevel=computeShadowWithVSM(vPositionFromLight3,shadowSampler3,shadowsInfo3.z,shadowsInfo3.x);\n#else\n#ifdef SHADOWPCF3\n#if defined(POINTLIGHT3)\nnotShadowLevel=computeShadowWithPCFCube(vLightData3.xyz,shadowSampler3,shadowsInfo3.y,shadowsInfo3.z,shadowsInfo3.x);\n#else\nnotShadowLevel=computeShadowWithPCF(vPositionFromLight3,shadowSampler3,shadowsInfo3.y,shadowsInfo3.z,shadowsInfo3.x);\n#endif\n#else\n#if defined(POINTLIGHT3)\nnotShadowLevel=computeShadowCube(vLightData3.xyz,shadowSampler3,shadowsInfo3.x,shadowsInfo3.z);\n#else\nnotShadowLevel=computeShadow(vPositionFromLight3,shadowSampler3,shadowsInfo3.x,shadowsInfo3.z);\n#endif\n#endif \n#endif \n#else\nnotShadowLevel=1.;\n#endif\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#ifdef SPECULARTERM\nlightSpecularContribution*=vLightingIntensity.w;\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV);\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 (microSurface>0.5)\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 (microSurface>0.5)\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 specularEnvironmentR0=surfaceReflectivityColor.rgb;\nvec3 specularEnvironmentR90=vec3(1.0,1.0,1.0);\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\nfloat reflectance=max(max(surfaceReflectivityColor.r,surfaceReflectivityColor.g),surfaceReflectivityColor.b);\nsurfaceAlbedo.rgb=(1.-reflectance)*surfaceAlbedo.rgb;\nrefractance*=vLightingIntensity.z;\nenvironmentRadiance*=specularEnvironmentReflectance;\n\nvec3 surfaceEmissiveColor=vEmissiveColor;\n#ifdef EMISSIVE\nvec3 emissiveColorTex=texture2D(emissiveSampler,vEmissiveUV).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=max(lightDiffuseContribution*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=max(shadowedOnlyLightDiffuseContribution*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#endif\n#else\n#ifdef LINKEMISSIVEWITHALBEDO\nvec3 finalDiffuse=max((lightDiffuseContribution+surfaceEmissiveColor)*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=max((shadowedOnlyLightDiffuseContribution+surfaceEmissiveColor)*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#endif\n#else\nvec3 finalDiffuse=max(lightDiffuseContribution*surfaceAlbedoContribution+surfaceEmissiveColor+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=max(shadowedOnlyLightDiffuseContribution*surfaceAlbedoContribution+surfaceEmissiveColor+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#endif\n#endif\n#endif\n#ifdef OVERLOADEDSHADOWVALUES\nfinalDiffuse=mix(finalDiffuse,shadowedOnlyLightDiffuseContribution,(1.0-vOverloadedShadowIntensity.y));\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=lightSpecularContribution*surfaceReflectivityColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#ifdef SPECULAROVERALPHA\nalpha=clamp(alpha+getLuminance(finalSpecular),0.,1.);\n#endif\n#ifdef RADIANCEOVERALPHA\nalpha=clamp(alpha+getLuminance(environmentRadiance),0.,1.);\n#endif\n\n\n#ifdef EMISSIVEASILLUMINATION\nvec4 finalColor=vec4(finalDiffuse*ambientColor*vLightingIntensity.x+surfaceAlbedo.rgb*environmentIrradiance+finalSpecular*vLightingIntensity.x+environmentRadiance+surfaceEmissiveColor*vLightingIntensity.y+refractance,alpha);\n#else\nvec4 finalColor=vec4(finalDiffuse*ambientColor*vLightingIntensity.x+surfaceAlbedo.rgb*environmentIrradiance+finalSpecular*vLightingIntensity.x+environmentRadiance+refractance,alpha);\n#endif\n#ifdef LIGHTMAP\nvec3 lightmapColor=texture2D(lightmapSampler,vLightmapUV).rgb*vLightmapInfos.y;\n#ifdef USELIGHTMAPASSHADOWMAP\nfinalColor.rgb*=lightmapColor;\n#else\nfinalColor.rgb+=lightmapColor;\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#ifdef CAMERACONTRAST\nfinalColor=contrasts(finalColor);\n#endif\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n#include<logDepthFragment>\n#include<fogFragment>(color,finalColor)\ngl_FragColor=finalColor;\n}";
  1227. BABYLON.Effect.ShadersStore['legacypbrVertexShader'] = "precision mediump float;\n\nattribute vec3 position;\nattribute vec3 normal;\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\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef ALBEDO\nvarying vec2 vAlbedoUV;\nuniform mat4 albedoMatrix;\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform mat4 ambientMatrix;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY\nvarying vec2 vOpacityUV;\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n#if defined(REFLECTIVITY)\nvarying vec2 vReflectivityUV;\nuniform vec2 vReflectivityInfos;\nuniform mat4 reflectivityMatrix;\n#endif\n\nvarying vec3 vPositionW;\nvarying vec3 vNormalW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\nvoid main(void) {\nmat4 finalWorld=world;\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\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#if defined(REFLECTIVITY)\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#include<clipPlaneVertex>\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n}";
  1228. BABYLON.Effect.ShadersStore['legacypbrPixelShader'] = "precision mediump float;\n\n#define RECIPROCAL_PI2 0.15915494\n#define FRESNEL_MAXIMUM_ON_ROUGH 0.25\nuniform vec3 vEyePosition;\nuniform vec3 vAmbientColor;\nuniform vec4 vAlbedoColor;\nuniform vec3 vReflectionColor;\nuniform vec4 vLightRadiuses;\n\nuniform vec4 vLightingIntensity;\nuniform vec4 vCameraInfos;\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\nconst float kPi=3.1415926535897932384626433832795;\nconst float kRougnhessToAlphaScale=0.1;\nconst float kRougnhessToAlphaOffset=0.29248125;\n\nfloat Square(float value)\n{\nreturn value*value;\n}\nfloat getLuminance(vec3 color)\n{\nreturn clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);\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)\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,vec3(1.,1.,1.));\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\nfloat lightRoughness=lightRadius/lightDistance;\n\nfloat totalRoughness=clamp(lightRoughness+roughness,0.,1.);\nreturn totalRoughness;\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}\nvec3 toLinearSpace(vec3 color)\n{\nreturn vec3(pow(color.r,2.2),pow(color.g,2.2),pow(color.b,2.2));\n}\nvec3 toGammaSpace(vec3 color)\n{\nreturn vec3(pow(color.r,1.0/2.2),pow(color.g,1.0/2.2),pow(color.b,1.0/2.2));\n}\nfloat computeLightFalloff(vec3 lightOffset,float lightDistanceSquared,float range)\n{\n#ifdef USEPHYSICALLIGHTFALLOFF\nfloat lightDistanceFalloff=1.0/((lightDistanceSquared+0.0001));\nreturn lightDistanceFalloff;\n#else\nfloat lightFalloff=max(0.,1.0-length(lightOffset)/range);\nreturn lightFalloff;\n#endif\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\nuniform vec4 vReflectivityColor;\nuniform vec3 vEmissiveColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<lightFragmentDeclaration>[0]\n#include<lightFragmentDeclaration>[1]\n#include<lightFragmentDeclaration>[2]\n#include<lightFragmentDeclaration>[3]\n\n#ifdef ALBEDO\nvarying vec2 vAlbedoUV;\nuniform sampler2D albedoSampler;\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform sampler2D ambientSampler;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY \nvarying vec2 vOpacityUV;\nuniform sampler2D opacitySampler;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform vec2 vEmissiveInfos;\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\nvarying vec2 vLightmapUV;\nuniform vec2 vLightmapInfos;\nuniform sampler2D lightmapSampler;\n#endif\n#if defined(REFLECTIVITY)\nvarying vec2 vReflectivityUV;\nuniform vec2 vReflectivityInfos;\nuniform sampler2D reflectivitySampler;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\nstruct lightingInfo\n{\nvec3 diffuse;\n#ifdef SPECULARTERM\nvec3 specular;\n#endif\n};\nlightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float range,float roughness,float NdotV,float lightRadius,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=computeLightFalloff(lightOffset,lightDistanceSquared,range);\nlightDistance=sqrt(lightDistanceSquared);\nlightDirection=normalize(lightOffset);\n}\n\nelse\n{\nlightDistance=length(-lightData.xyz);\nlightDirection=normalize(-lightData.xyz);\n}\n\nroughness=adjustRoughnessFromLightProperties(roughness,lightRadius,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);\nresult.specular=specTerm*attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float range,float roughness,float NdotV,float lightRadius,out float NdotL) {\nlightingInfo result;\nvec3 lightOffset=lightData.xyz-vPositionW;\nvec3 lightVectorW=normalize(lightOffset);\n\nfloat cosAngle=max(0.000000000000001,dot(-lightDirection.xyz,lightVectorW));\nif (cosAngle>=lightDirection.w)\n{\ncosAngle=max(0.,pow(cosAngle,lightData.w));\n\nfloat lightDistanceSquared=dot(lightOffset,lightOffset);\nfloat attenuation=computeLightFalloff(lightOffset,lightDistanceSquared,range);\n\nattenuation*=cosAngle;\n\nfloat lightDistance=sqrt(lightDistanceSquared);\nroughness=adjustRoughnessFromLightProperties(roughness,lightRadius,lightDistance);\n\nvec3 H=normalize(viewDirectionW-lightDirection.xyz);\nNdotL=max(0.00000000001,dot(vNormal,-lightDirection.xyz));\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);\nresult.specular=specTerm*attenuation;\n#endif\nreturn result;\n}\nresult.diffuse=vec3(0.);\n#ifdef SPECULARTERM\nresult.specular=vec3(0.);\n#endif\nreturn result;\n}\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float roughness,float NdotV,float lightRadius,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);\nresult.specular=specTerm;\n#endif\nreturn result;\n}\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 surfaceAlbedo=vec4(1.,1.,1.,1.);\nvec3 surfaceAlbedoContribution=vAlbedoColor.rgb;\n\nfloat alpha=vAlbedoColor.a;\n#ifdef ALBEDO\nsurfaceAlbedo=texture2D(albedoSampler,vAlbedoUV);\nsurfaceAlbedo=vec4(toLinearSpace(surfaceAlbedo.rgb),surfaceAlbedo.a);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\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\nbaseColor.rgb*=vColor.rgb;\n#endif\n#ifdef OVERLOADEDVALUES\nsurfaceAlbedo.rgb=mix(surfaceAlbedo.rgb,vOverloadedAlbedo,vOverloadedIntensity.y);\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nvec3 ambientColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nambientColor=texture2D(ambientSampler,vAmbientUV).rgb*vAmbientInfos.y;\n#ifdef OVERLOADEDVALUES\nambientColor.rgb=mix(ambientColor.rgb,vOverloadedAmbient,vOverloadedIntensity.x);\n#endif\n#endif\n\nfloat microSurface=vReflectivityColor.a;\nvec3 surfaceReflectivityColor=vReflectivityColor.rgb;\n#ifdef OVERLOADEDVALUES\nsurfaceReflectivityColor.rgb=mix(surfaceReflectivityColor.rgb,vOverloadedReflectivity,vOverloadedIntensity.z);\n#endif\n#ifdef REFLECTIVITY\nvec4 surfaceReflectivityColorMap=texture2D(reflectivitySampler,vReflectivityUV);\nsurfaceReflectivityColor=surfaceReflectivityColorMap.rgb;\nsurfaceReflectivityColor=toLinearSpace(surfaceReflectivityColor);\n#ifdef OVERLOADEDVALUES\nsurfaceReflectivityColor=mix(surfaceReflectivityColor,vOverloadedReflectivity,vOverloadedIntensity.z);\n#endif\n#ifdef MICROSURFACEFROMREFLECTIVITYMAP\nmicroSurface=surfaceReflectivityColorMap.a;\n#else\n#ifdef MICROSURFACEAUTOMATIC\nmicroSurface=computeDefaultMicroSurface(microSurface,surfaceReflectivityColor);\n#endif\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.; \nfloat NdotL=-1.;\n#ifdef LIGHT0\n#ifndef SPECULARTERM\nvec3 vLightSpecular0=vec3(0.0);\n#endif\n#ifdef SPOTLIGHT0\nlightingInfo info=computeSpotLighting(viewDirectionW,normalW,vLightData0,vLightDirection0,vLightDiffuse0.rgb,vLightSpecular0,vLightDiffuse0.a,roughness,NdotV,vLightRadiuses[0],NdotL);\n#endif\n#ifdef HEMILIGHT0\nlightingInfo info=computeHemisphericLighting(viewDirectionW,normalW,vLightData0,vLightDiffuse0.rgb,vLightSpecular0,vLightGround0,roughness,NdotV,vLightRadiuses[0],NdotL);\n#endif\n#if defined(POINTLIGHT0) || defined(DIRLIGHT0)\nlightingInfo info=computeLighting(viewDirectionW,normalW,vLightData0,vLightDiffuse0.rgb,vLightSpecular0,vLightDiffuse0.a,roughness,NdotV,vLightRadiuses[0],NdotL);\n#endif\nnotShadowLevel=1.;\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#ifdef LIGHT1\n#ifndef SPECULARTERM\nvec3 vLightSpecular1=vec3(0.0);\n#endif\n#ifdef SPOTLIGHT1\ninfo=computeSpotLighting(viewDirectionW,normalW,vLightData1,vLightDirection1,vLightDiffuse1.rgb,vLightSpecular1,vLightDiffuse1.a,roughness,NdotV,vLightRadiuses[1],NdotL);\n#endif\n#ifdef HEMILIGHT1\ninfo=computeHemisphericLighting(viewDirectionW,normalW,vLightData1,vLightDiffuse1.rgb,vLightSpecular1,vLightGround1,roughness,NdotV,vLightRadiuses[1],NdotL);\n#endif\n#if defined(POINTLIGHT1) || defined(DIRLIGHT1)\ninfo=computeLighting(viewDirectionW,normalW,vLightData1,vLightDiffuse1.rgb,vLightSpecular1,vLightDiffuse1.a,roughness,NdotV,vLightRadiuses[1],NdotL);\n#endif\nnotShadowLevel=1.;\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#ifdef LIGHT2\n#ifndef SPECULARTERM\nvec3 vLightSpecular2=vec3(0.0);\n#endif\n#ifdef SPOTLIGHT2\ninfo=computeSpotLighting(viewDirectionW,normalW,vLightData2,vLightDirection2,vLightDiffuse2.rgb,vLightSpecular2,vLightDiffuse2.a,roughness,NdotV,vLightRadiuses[2],NdotL);\n#endif\n#ifdef HEMILIGHT2\ninfo=computeHemisphericLighting(viewDirectionW,normalW,vLightData2,vLightDiffuse2.rgb,vLightSpecular2,vLightGround2,roughness,NdotV,vLightRadiuses[2],NdotL);\n#endif\n#if defined(POINTLIGHT2) || defined(DIRLIGHT2)\ninfo=computeLighting(viewDirectionW,normalW,vLightData2,vLightDiffuse2.rgb,vLightSpecular2,vLightDiffuse2.a,roughness,NdotV,vLightRadiuses[2],NdotL);\n#endif\nnotShadowLevel=1.;\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#ifdef LIGHT3\n#ifndef SPECULARTERM\nvec3 vLightSpecular3=vec3(0.0);\n#endif\n#ifdef SPOTLIGHT3\ninfo=computeSpotLighting(viewDirectionW,normalW,vLightData3,vLightDirection3,vLightDiffuse3.rgb,vLightSpecular3,vLightDiffuse3.a,roughness,NdotV,vLightRadiuses[3],NdotL);\n#endif\n#ifdef HEMILIGHT3\ninfo=computeHemisphericLighting(viewDirectionW,normalW,vLightData3,vLightDiffuse3.rgb,vLightSpecular3,vLightGround3,roughness,NdotV,vLightRadiuses[3],NdotL);\n#endif\n#if defined(POINTLIGHT3) || defined(DIRLIGHT3)\ninfo=computeLighting(viewDirectionW,normalW,vLightData3,vLightDiffuse3.rgb,vLightSpecular3,vLightDiffuse3.a,roughness,NdotV,vLightRadiuses[3],NdotL);\n#endif\nnotShadowLevel=1.;\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#ifdef SPECULARTERM\nlightSpecularContribution*=vLightingIntensity.w;\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV);\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\nvec3 environmentRadiance=vReflectionColor.rgb;\nvec3 environmentIrradiance=vReflectionColor.rgb;\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 specularEnvironmentR0=surfaceReflectivityColor.rgb;\nvec3 specularEnvironmentR90=vec3(1.0,1.0,1.0);\nvec3 specularEnvironmentReflectance=FresnelSchlickEnvironmentGGX(clamp(NdotV,0.,1.),specularEnvironmentR0,specularEnvironmentR90,sqrt(microSurface));\n\nfloat reflectance=max(max(surfaceReflectivityColor.r,surfaceReflectivityColor.g),surfaceReflectivityColor.b);\nsurfaceAlbedo.rgb=(1.-reflectance)*surfaceAlbedo.rgb;\nenvironmentRadiance*=specularEnvironmentReflectance;\n\nvec3 surfaceEmissiveColor=vEmissiveColor;\n#ifdef EMISSIVE\nvec3 emissiveColorTex=texture2D(emissiveSampler,vEmissiveUV).rgb;\nsurfaceEmissiveColor=toLinearSpace(emissiveColorTex.rgb)*surfaceEmissiveColor*vEmissiveInfos.y;\n#endif\n#ifdef OVERLOADEDVALUES\nsurfaceEmissiveColor=mix(surfaceEmissiveColor,vOverloadedEmissive,vOverloadedIntensity.w);\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec3 finalDiffuse=max(lightDiffuseContribution*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=max(shadowedOnlyLightDiffuseContribution*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#endif\n#else\n#ifdef LINKEMISSIVEWITHALBEDO\nvec3 finalDiffuse=max((lightDiffuseContribution+surfaceEmissiveColor)*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=max((shadowedOnlyLightDiffuseContribution+surfaceEmissiveColor)*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#endif\n#else\nvec3 finalDiffuse=max(lightDiffuseContribution*surfaceAlbedoContribution+surfaceEmissiveColor+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=max(shadowedOnlyLightDiffuseContribution*surfaceAlbedoContribution+surfaceEmissiveColor+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#endif\n#endif\n#endif\n#ifdef OVERLOADEDSHADOWVALUES\nfinalDiffuse=mix(finalDiffuse,shadowedOnlyLightDiffuseContribution,(1.0-vOverloadedShadowIntensity.y));\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=lightSpecularContribution*surfaceReflectivityColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#ifdef SPECULAROVERALPHA\nalpha=clamp(alpha+getLuminance(finalSpecular),0.,1.);\n#endif\n#ifdef RADIANCEOVERALPHA\nalpha=clamp(alpha+getLuminance(environmentRadiance),0.,1.);\n#endif\n\n\n#ifdef EMISSIVEASILLUMINATION\nvec4 finalColor=vec4(finalDiffuse*ambientColor*vLightingIntensity.x+surfaceAlbedo.rgb*environmentIrradiance+finalSpecular*vLightingIntensity.x+environmentRadiance+surfaceEmissiveColor*vLightingIntensity.y,alpha);\n#else\nvec4 finalColor=vec4(finalDiffuse*ambientColor*vLightingIntensity.x+surfaceAlbedo.rgb*environmentIrradiance+finalSpecular*vLightingIntensity.x+environmentRadiance,alpha);\n#endif\nfinalColor=max(finalColor,0.0);\n#ifdef CAMERATONEMAP\nfinalColor.rgb=toneMaps(finalColor.rgb);\n#endif\nfinalColor.rgb=toGammaSpace(finalColor.rgb);\n#ifdef CAMERACONTRAST\nfinalColor=contrasts(finalColor);\n#endif\ngl_FragColor=finalColor;\n}";