babylon.terrainMaterial.js 24 KB

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