babylon.terrainMaterial.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. }
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  16. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  17. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  18. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  19. return c > 3 && r && Object.defineProperty(target, key, r), r;
  20. };
  21. var BABYLON;
  22. (function (BABYLON) {
  23. var TerrainMaterialDefines = /** @class */ (function (_super) {
  24. __extends(TerrainMaterialDefines, _super);
  25. function TerrainMaterialDefines() {
  26. var _this = _super.call(this) || this;
  27. _this.DIFFUSE = false;
  28. _this.BUMP = false;
  29. _this.CLIPPLANE = false;
  30. _this.CLIPPLANE2 = false;
  31. _this.CLIPPLANE3 = false;
  32. _this.CLIPPLANE4 = false;
  33. _this.ALPHATEST = false;
  34. _this.DEPTHPREPASS = false;
  35. _this.POINTSIZE = false;
  36. _this.FOG = false;
  37. _this.SPECULARTERM = false;
  38. _this.NORMAL = false;
  39. _this.UV1 = false;
  40. _this.UV2 = false;
  41. _this.VERTEXCOLOR = false;
  42. _this.VERTEXALPHA = false;
  43. _this.NUM_BONE_INFLUENCERS = 0;
  44. _this.BonesPerMesh = 0;
  45. _this.INSTANCES = false;
  46. _this.rebuild();
  47. return _this;
  48. }
  49. return TerrainMaterialDefines;
  50. }(BABYLON.MaterialDefines));
  51. var TerrainMaterial = /** @class */ (function (_super) {
  52. __extends(TerrainMaterial, _super);
  53. function TerrainMaterial(name, scene) {
  54. var _this = _super.call(this, name, scene) || this;
  55. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  56. _this.specularColor = new BABYLON.Color3(0, 0, 0);
  57. _this.specularPower = 64;
  58. _this._disableLighting = false;
  59. _this._maxSimultaneousLights = 4;
  60. return _this;
  61. }
  62. TerrainMaterial.prototype.needAlphaBlending = function () {
  63. return (this.alpha < 1.0);
  64. };
  65. TerrainMaterial.prototype.needAlphaTesting = function () {
  66. return false;
  67. };
  68. TerrainMaterial.prototype.getAlphaTestTexture = function () {
  69. return null;
  70. };
  71. // Methods
  72. TerrainMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  73. if (this.isFrozen) {
  74. if (this._wasPreviouslyReady && subMesh.effect) {
  75. return true;
  76. }
  77. }
  78. if (!subMesh._materialDefines) {
  79. subMesh._materialDefines = new TerrainMaterialDefines();
  80. }
  81. var defines = subMesh._materialDefines;
  82. var scene = this.getScene();
  83. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  84. if (this._renderId === scene.getRenderId()) {
  85. return true;
  86. }
  87. }
  88. var engine = scene.getEngine();
  89. // Textures
  90. if (scene.texturesEnabled) {
  91. if (this.mixTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  92. if (!this.mixTexture.isReady()) {
  93. return false;
  94. }
  95. else {
  96. defines._needUVs = true;
  97. defines.DIFFUSE = true;
  98. }
  99. }
  100. if ((this.bumpTexture1 || this.bumpTexture2 || this.bumpTexture3) && BABYLON.StandardMaterial.BumpTextureEnabled) {
  101. defines._needUVs = true;
  102. defines._needNormals = true;
  103. defines.BUMP = true;
  104. }
  105. }
  106. // Misc.
  107. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  108. // Lights
  109. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  110. // Values that need to be evaluated on every frame
  111. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  112. // Attribs
  113. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  114. // Get correct effect
  115. if (defines.isDirty) {
  116. defines.markAsProcessed();
  117. scene.resetCachedMaterial();
  118. // Fallbacks
  119. var fallbacks = new BABYLON.EffectFallbacks();
  120. if (defines.FOG) {
  121. fallbacks.addFallback(1, "FOG");
  122. }
  123. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  124. if (defines.NUM_BONE_INFLUENCERS > 0) {
  125. fallbacks.addCPUSkinningFallback(0, mesh);
  126. }
  127. //Attributes
  128. var attribs = [BABYLON.VertexBuffer.PositionKind];
  129. if (defines.NORMAL) {
  130. attribs.push(BABYLON.VertexBuffer.NormalKind);
  131. }
  132. if (defines.UV1) {
  133. attribs.push(BABYLON.VertexBuffer.UVKind);
  134. }
  135. if (defines.UV2) {
  136. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  137. }
  138. if (defines.VERTEXCOLOR) {
  139. attribs.push(BABYLON.VertexBuffer.ColorKind);
  140. }
  141. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  142. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  143. // Legacy browser patch
  144. var shaderName = "terrain";
  145. var join = defines.toString();
  146. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor", "vSpecularColor",
  147. "vFogInfos", "vFogColor", "pointSize",
  148. "vTextureInfos",
  149. "mBones",
  150. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "textureMatrix",
  151. "diffuse1Infos", "diffuse2Infos", "diffuse3Infos"
  152. ];
  153. var samplers = ["textureSampler", "diffuse1Sampler", "diffuse2Sampler", "diffuse3Sampler",
  154. "bump1Sampler", "bump2Sampler", "bump3Sampler"
  155. ];
  156. var uniformBuffers = new Array();
  157. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  158. uniformsNames: uniforms,
  159. uniformBuffersNames: uniformBuffers,
  160. samplers: samplers,
  161. defines: defines,
  162. maxSimultaneousLights: this.maxSimultaneousLights
  163. });
  164. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  165. attributes: attribs,
  166. uniformsNames: uniforms,
  167. uniformBuffersNames: uniformBuffers,
  168. samplers: samplers,
  169. defines: join,
  170. fallbacks: fallbacks,
  171. onCompiled: this.onCompiled,
  172. onError: this.onError,
  173. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  174. }, engine), defines);
  175. }
  176. if (!subMesh.effect || !subMesh.effect.isReady()) {
  177. return false;
  178. }
  179. this._renderId = scene.getRenderId();
  180. this._wasPreviouslyReady = true;
  181. return true;
  182. };
  183. TerrainMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  184. var scene = this.getScene();
  185. var defines = subMesh._materialDefines;
  186. if (!defines) {
  187. return;
  188. }
  189. var effect = subMesh.effect;
  190. if (!effect) {
  191. return;
  192. }
  193. this._activeEffect = effect;
  194. // Matrices
  195. this.bindOnlyWorldMatrix(world);
  196. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  197. // Bones
  198. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  199. if (this._mustRebind(scene, effect)) {
  200. // Textures
  201. if (this.mixTexture) {
  202. this._activeEffect.setTexture("textureSampler", this._mixTexture);
  203. this._activeEffect.setFloat2("vTextureInfos", this._mixTexture.coordinatesIndex, this._mixTexture.level);
  204. this._activeEffect.setMatrix("textureMatrix", this._mixTexture.getTextureMatrix());
  205. if (BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  206. if (this._diffuseTexture1) {
  207. this._activeEffect.setTexture("diffuse1Sampler", this._diffuseTexture1);
  208. this._activeEffect.setFloat2("diffuse1Infos", this._diffuseTexture1.uScale, this._diffuseTexture1.vScale);
  209. }
  210. if (this._diffuseTexture2) {
  211. this._activeEffect.setTexture("diffuse2Sampler", this._diffuseTexture2);
  212. this._activeEffect.setFloat2("diffuse2Infos", this._diffuseTexture2.uScale, this._diffuseTexture2.vScale);
  213. }
  214. if (this._diffuseTexture3) {
  215. this._activeEffect.setTexture("diffuse3Sampler", this._diffuseTexture3);
  216. this._activeEffect.setFloat2("diffuse3Infos", this._diffuseTexture3.uScale, this._diffuseTexture3.vScale);
  217. }
  218. }
  219. if (BABYLON.StandardMaterial.BumpTextureEnabled && scene.getEngine().getCaps().standardDerivatives) {
  220. if (this._bumpTexture1) {
  221. this._activeEffect.setTexture("bump1Sampler", this._bumpTexture1);
  222. }
  223. if (this._bumpTexture2) {
  224. this._activeEffect.setTexture("bump2Sampler", this._bumpTexture2);
  225. }
  226. if (this._bumpTexture3) {
  227. this._activeEffect.setTexture("bump3Sampler", this._bumpTexture3);
  228. }
  229. }
  230. }
  231. // Clip plane
  232. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  233. // Point size
  234. if (this.pointsCloud) {
  235. this._activeEffect.setFloat("pointSize", this.pointSize);
  236. }
  237. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  238. }
  239. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  240. if (defines.SPECULARTERM) {
  241. this._activeEffect.setColor4("vSpecularColor", this.specularColor, this.specularPower);
  242. }
  243. if (scene.lightsEnabled && !this.disableLighting) {
  244. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  245. }
  246. // View
  247. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  248. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  249. }
  250. // Fog
  251. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  252. this._afterBind(mesh, this._activeEffect);
  253. };
  254. TerrainMaterial.prototype.getAnimatables = function () {
  255. var results = [];
  256. if (this.mixTexture && this.mixTexture.animations && this.mixTexture.animations.length > 0) {
  257. results.push(this.mixTexture);
  258. }
  259. return results;
  260. };
  261. TerrainMaterial.prototype.getActiveTextures = function () {
  262. var activeTextures = _super.prototype.getActiveTextures.call(this);
  263. if (this._mixTexture) {
  264. activeTextures.push(this._mixTexture);
  265. }
  266. if (this._diffuseTexture1) {
  267. activeTextures.push(this._diffuseTexture1);
  268. }
  269. if (this._diffuseTexture2) {
  270. activeTextures.push(this._diffuseTexture2);
  271. }
  272. if (this._diffuseTexture3) {
  273. activeTextures.push(this._diffuseTexture3);
  274. }
  275. if (this._bumpTexture1) {
  276. activeTextures.push(this._bumpTexture1);
  277. }
  278. if (this._bumpTexture2) {
  279. activeTextures.push(this._bumpTexture2);
  280. }
  281. if (this._bumpTexture3) {
  282. activeTextures.push(this._bumpTexture3);
  283. }
  284. return activeTextures;
  285. };
  286. TerrainMaterial.prototype.hasTexture = function (texture) {
  287. if (_super.prototype.hasTexture.call(this, texture)) {
  288. return true;
  289. }
  290. if (this._mixTexture === texture) {
  291. return true;
  292. }
  293. if (this._diffuseTexture1 === texture) {
  294. return true;
  295. }
  296. if (this._diffuseTexture2 === texture) {
  297. return true;
  298. }
  299. if (this._diffuseTexture3 === texture) {
  300. return true;
  301. }
  302. if (this._bumpTexture1 === texture) {
  303. return true;
  304. }
  305. if (this._bumpTexture2 === texture) {
  306. return true;
  307. }
  308. if (this._bumpTexture3 === texture) {
  309. return true;
  310. }
  311. return false;
  312. };
  313. TerrainMaterial.prototype.dispose = function (forceDisposeEffect) {
  314. if (this.mixTexture) {
  315. this.mixTexture.dispose();
  316. }
  317. _super.prototype.dispose.call(this, forceDisposeEffect);
  318. };
  319. TerrainMaterial.prototype.clone = function (name) {
  320. var _this = this;
  321. return BABYLON.SerializationHelper.Clone(function () { return new TerrainMaterial(name, _this.getScene()); }, this);
  322. };
  323. TerrainMaterial.prototype.serialize = function () {
  324. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  325. serializationObject.customType = "BABYLON.TerrainMaterial";
  326. return serializationObject;
  327. };
  328. TerrainMaterial.prototype.getClassName = function () {
  329. return "TerrainMaterial";
  330. };
  331. // Statics
  332. TerrainMaterial.Parse = function (source, scene, rootUrl) {
  333. return BABYLON.SerializationHelper.Parse(function () { return new TerrainMaterial(source.name, scene); }, source, scene, rootUrl);
  334. };
  335. __decorate([
  336. BABYLON.serializeAsTexture("mixTexture")
  337. ], TerrainMaterial.prototype, "_mixTexture", void 0);
  338. __decorate([
  339. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  340. ], TerrainMaterial.prototype, "mixTexture", void 0);
  341. __decorate([
  342. BABYLON.serializeAsTexture("diffuseTexture1")
  343. ], TerrainMaterial.prototype, "_diffuseTexture1", void 0);
  344. __decorate([
  345. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  346. ], TerrainMaterial.prototype, "diffuseTexture1", void 0);
  347. __decorate([
  348. BABYLON.serializeAsTexture("diffuseTexture2")
  349. ], TerrainMaterial.prototype, "_diffuseTexture2", void 0);
  350. __decorate([
  351. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  352. ], TerrainMaterial.prototype, "diffuseTexture2", void 0);
  353. __decorate([
  354. BABYLON.serializeAsTexture("diffuseTexture3")
  355. ], TerrainMaterial.prototype, "_diffuseTexture3", void 0);
  356. __decorate([
  357. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  358. ], TerrainMaterial.prototype, "diffuseTexture3", void 0);
  359. __decorate([
  360. BABYLON.serializeAsTexture("bumpTexture1")
  361. ], TerrainMaterial.prototype, "_bumpTexture1", void 0);
  362. __decorate([
  363. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  364. ], TerrainMaterial.prototype, "bumpTexture1", void 0);
  365. __decorate([
  366. BABYLON.serializeAsTexture("bumpTexture2")
  367. ], TerrainMaterial.prototype, "_bumpTexture2", void 0);
  368. __decorate([
  369. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  370. ], TerrainMaterial.prototype, "bumpTexture2", void 0);
  371. __decorate([
  372. BABYLON.serializeAsTexture("bumpTexture3")
  373. ], TerrainMaterial.prototype, "_bumpTexture3", void 0);
  374. __decorate([
  375. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  376. ], TerrainMaterial.prototype, "bumpTexture3", void 0);
  377. __decorate([
  378. BABYLON.serializeAsColor3()
  379. ], TerrainMaterial.prototype, "diffuseColor", void 0);
  380. __decorate([
  381. BABYLON.serializeAsColor3()
  382. ], TerrainMaterial.prototype, "specularColor", void 0);
  383. __decorate([
  384. BABYLON.serialize()
  385. ], TerrainMaterial.prototype, "specularPower", void 0);
  386. __decorate([
  387. BABYLON.serialize("disableLighting")
  388. ], TerrainMaterial.prototype, "_disableLighting", void 0);
  389. __decorate([
  390. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  391. ], TerrainMaterial.prototype, "disableLighting", void 0);
  392. __decorate([
  393. BABYLON.serialize("maxSimultaneousLights")
  394. ], TerrainMaterial.prototype, "_maxSimultaneousLights", void 0);
  395. __decorate([
  396. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  397. ], TerrainMaterial.prototype, "maxSimultaneousLights", void 0);
  398. return TerrainMaterial;
  399. }(BABYLON.PushMaterial));
  400. BABYLON.TerrainMaterial = TerrainMaterial;
  401. })(BABYLON || (BABYLON = {}));
  402. //# sourceMappingURL=babylon.terrainMaterial.js.map
  403. BABYLON.Effect.ShadersStore['terrainVertexShader'] = "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 DIFFUSE\nvarying vec2 vTextureUV;\nuniform mat4 textureMatrix;\nuniform vec2 vTextureInfos;\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<__decl__lightFragment>[0..maxSimultaneousLights]\nvoid main(void) {\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\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef DIFFUSE\nif (vTextureInfos.x == 0.)\n{\nvTextureUV=vec2(textureMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvTextureUV=vec2(textureMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  404. BABYLON.Effect.ShadersStore['terrainPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n#ifdef SPECULARTERM\nuniform vec4 vSpecularColor;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n#ifdef DIFFUSE\nvarying vec2 vTextureUV;\nuniform sampler2D textureSampler;\nuniform vec2 vTextureInfos;\nuniform sampler2D diffuse1Sampler;\nuniform sampler2D diffuse2Sampler;\nuniform sampler2D diffuse3Sampler;\nuniform vec2 diffuse1Infos;\nuniform vec2 diffuse2Infos;\nuniform vec2 diffuse3Infos;\n#endif\n#ifdef BUMP\nuniform sampler2D bump1Sampler;\nuniform sampler2D bump2Sampler;\nuniform sampler2D bump3Sampler;\n#endif\n\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n\n#include<fogFragmentDeclaration>\n\n#ifdef BUMP\n#extension GL_OES_standard_derivatives : enable\n\nmat3 cotangent_frame(vec3 normal,vec3 p,vec2 uv)\n{\n\nvec3 dp1=dFdx(p);\nvec3 dp2=dFdy(p);\nvec2 duv1=dFdx(uv);\nvec2 duv2=dFdy(uv);\n\nvec3 dp2perp=cross(dp2,normal);\nvec3 dp1perp=cross(normal,dp1);\nvec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;\nvec3 binormal=dp2perp*duv1.y+dp1perp*duv2.y;\n\nfloat invmax=inversesqrt(max(dot(tangent,tangent),dot(binormal,binormal)));\nreturn mat3(tangent*invmax,binormal*invmax,normal);\n}\nvec3 perturbNormal(vec3 viewDir,vec3 mixColor)\n{ \nvec3 bump1Color=texture2D(bump1Sampler,vTextureUV*diffuse1Infos).xyz;\nvec3 bump2Color=texture2D(bump2Sampler,vTextureUV*diffuse2Infos).xyz;\nvec3 bump3Color=texture2D(bump3Sampler,vTextureUV*diffuse3Infos).xyz;\nbump1Color.rgb*=mixColor.r;\nbump2Color.rgb=mix(bump1Color.rgb,bump2Color.rgb,mixColor.g);\nvec3 map=mix(bump2Color.rgb,bump3Color.rgb,mixColor.b);\nmap=map*255./127.-128./127.;\nmat3 TBN=cotangent_frame(vNormalW*vTextureInfos.y,-viewDir,vTextureUV);\nreturn normalize(TBN*map);\n}\n#endif\nvoid main(void) {\n\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=vec4(1.,1.,1.,1.);\nvec3 diffuseColor=vDiffuseColor.rgb;\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;\nvec3 specularColor=vSpecularColor.rgb;\n#else\nfloat glossiness=0.;\n#endif\n\nfloat alpha=vDiffuseColor.a;\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n#ifdef DIFFUSE\nbaseColor=texture2D(textureSampler,vTextureUV);\n#if defined(BUMP) && defined(DIFFUSE)\nnormalW=perturbNormal(viewDirectionW,baseColor.rgb);\n#endif\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vTextureInfos.y;\nvec4 diffuse1Color=texture2D(diffuse1Sampler,vTextureUV*diffuse1Infos);\nvec4 diffuse2Color=texture2D(diffuse2Sampler,vTextureUV*diffuse2Infos);\nvec4 diffuse3Color=texture2D(diffuse3Sampler,vTextureUV*diffuse3Infos);\ndiffuse1Color.rgb*=baseColor.r;\ndiffuse2Color.rgb=mix(diffuse1Color.rgb,diffuse2Color.rgb,baseColor.g);\nbaseColor.rgb=mix(diffuse2Color.rgb,diffuse3Color.rgb,baseColor.b);\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor*baseColor.rgb,0.0,1.0);\n\nvec4 color=vec4(finalDiffuse+finalSpecular,alpha);\n#include<fogFragment>\ngl_FragColor=color;\n}\n";