babylon.fireMaterial.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. var BABYLON;
  3. (function (BABYLON) {
  4. var maxSimultaneousLights = 4;
  5. var FireMaterialDefines = (function (_super) {
  6. __extends(FireMaterialDefines, _super);
  7. function FireMaterialDefines() {
  8. _super.call(this);
  9. this.DIFFUSE = false;
  10. this.CLIPPLANE = false;
  11. this.ALPHATEST = false;
  12. this.POINTSIZE = false;
  13. this.FOG = false;
  14. this.UV1 = false;
  15. this.NORMAL = false;
  16. this.VERTEXCOLOR = false;
  17. this.VERTEXALPHA = false;
  18. this.BONES = false;
  19. this.BONES4 = false;
  20. this.BonesPerMesh = 0;
  21. this.INSTANCES = false;
  22. this._keys = Object.keys(this);
  23. }
  24. return FireMaterialDefines;
  25. })(BABYLON.MaterialDefines);
  26. var FireMaterial = (function (_super) {
  27. __extends(FireMaterial, _super);
  28. function FireMaterial(name, scene) {
  29. _super.call(this, name, scene);
  30. this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  31. this.disableLighting = false;
  32. this.speed = 1.0;
  33. this._scaledDiffuse = new BABYLON.Color3();
  34. this._defines = new FireMaterialDefines();
  35. this._cachedDefines = new FireMaterialDefines();
  36. this._lastTime = 0;
  37. this._cachedDefines.BonesPerMesh = -1;
  38. }
  39. FireMaterial.prototype.needAlphaBlending = function () {
  40. return (this.alpha < 1.0);
  41. };
  42. FireMaterial.prototype.needAlphaTesting = function () {
  43. return false;
  44. };
  45. FireMaterial.prototype.getAlphaTestTexture = function () {
  46. return null;
  47. };
  48. // Methods
  49. FireMaterial.prototype._checkCache = function (scene, mesh, useInstances) {
  50. if (!mesh) {
  51. return true;
  52. }
  53. if (this._defines.INSTANCES !== useInstances) {
  54. return false;
  55. }
  56. if (mesh._materialDefines && mesh._materialDefines.isEqual(this._defines)) {
  57. return true;
  58. }
  59. return false;
  60. };
  61. FireMaterial.prototype.isReady = function (mesh, useInstances) {
  62. if (this.checkReadyOnlyOnce) {
  63. if (this._wasPreviouslyReady) {
  64. return true;
  65. }
  66. }
  67. var scene = this.getScene();
  68. if (!this.checkReadyOnEveryCall) {
  69. if (this._renderId === scene.getRenderId()) {
  70. if (this._checkCache(scene, mesh, useInstances)) {
  71. return true;
  72. }
  73. }
  74. }
  75. var engine = scene.getEngine();
  76. var needNormals = false;
  77. var needUVs = false;
  78. this._defines.reset();
  79. // Textures
  80. if (scene.texturesEnabled) {
  81. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  82. if (!this.diffuseTexture.isReady()) {
  83. return false;
  84. }
  85. else {
  86. needUVs = true;
  87. this._defines.DIFFUSE = true;
  88. }
  89. }
  90. }
  91. // Effect
  92. if (scene.clipPlane) {
  93. this._defines.CLIPPLANE = true;
  94. }
  95. this._defines.ALPHATEST = true;
  96. // Point size
  97. if (this.pointsCloud || scene.forcePointsCloud) {
  98. this._defines.POINTSIZE = true;
  99. }
  100. // Fog
  101. if (scene.fogEnabled && mesh && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled) {
  102. this._defines.FOG = true;
  103. }
  104. // Attribs
  105. if (mesh) {
  106. if (needNormals && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
  107. this._defines.NORMAL = true;
  108. }
  109. if (needUVs) {
  110. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
  111. this._defines.UV1 = true;
  112. }
  113. }
  114. if (mesh.useVertexColors && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind)) {
  115. this._defines.VERTEXCOLOR = true;
  116. if (mesh.hasVertexAlpha) {
  117. this._defines.VERTEXALPHA = true;
  118. }
  119. }
  120. if (mesh.useBones && mesh.computeBonesUsingShaders) {
  121. this._defines.BONES = true;
  122. this._defines.BonesPerMesh = (mesh.skeleton.bones.length + 1);
  123. this._defines.BONES4 = true;
  124. }
  125. // Instances
  126. if (useInstances) {
  127. this._defines.INSTANCES = true;
  128. }
  129. }
  130. // Get correct effect
  131. if (!this._defines.isEqual(this._cachedDefines)) {
  132. this._defines.cloneTo(this._cachedDefines);
  133. scene.resetCachedMaterial();
  134. // Fallbacks
  135. var fallbacks = new BABYLON.EffectFallbacks();
  136. if (this._defines.FOG) {
  137. fallbacks.addFallback(1, "FOG");
  138. }
  139. if (this._defines.BONES4) {
  140. fallbacks.addFallback(0, "BONES4");
  141. }
  142. //Attributes
  143. var attribs = [BABYLON.VertexBuffer.PositionKind];
  144. if (this._defines.NORMAL) {
  145. attribs.push(BABYLON.VertexBuffer.NormalKind);
  146. }
  147. if (this._defines.UV1) {
  148. attribs.push(BABYLON.VertexBuffer.UVKind);
  149. }
  150. if (this._defines.VERTEXCOLOR) {
  151. attribs.push(BABYLON.VertexBuffer.ColorKind);
  152. }
  153. if (this._defines.BONES) {
  154. attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
  155. attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
  156. }
  157. if (this._defines.INSTANCES) {
  158. attribs.push("world0");
  159. attribs.push("world1");
  160. attribs.push("world2");
  161. attribs.push("world3");
  162. }
  163. // Legacy browser patch
  164. var shaderName = "fire";
  165. var join = this._defines.toString();
  166. this._effect = scene.getEngine().createEffect(shaderName, attribs, ["world", "view", "viewProjection", "vEyePosition",
  167. "vFogInfos", "vFogColor", "pointSize",
  168. "vDiffuseInfos",
  169. "mBones",
  170. "vClipPlane", "diffuseMatrix",
  171. // Fire
  172. "time", "speed"
  173. ], ["diffuseSampler",
  174. // Fire
  175. "distortionSampler", "opacitySampler"
  176. ], join, fallbacks, this.onCompiled, this.onError);
  177. }
  178. if (!this._effect.isReady()) {
  179. return false;
  180. }
  181. this._renderId = scene.getRenderId();
  182. this._wasPreviouslyReady = true;
  183. if (mesh) {
  184. if (!mesh._materialDefines) {
  185. mesh._materialDefines = new FireMaterialDefines();
  186. }
  187. this._defines.cloneTo(mesh._materialDefines);
  188. }
  189. return true;
  190. };
  191. FireMaterial.prototype.bindOnlyWorldMatrix = function (world) {
  192. this._effect.setMatrix("world", world);
  193. };
  194. FireMaterial.prototype.bind = function (world, mesh) {
  195. var scene = this.getScene();
  196. // Matrices
  197. this.bindOnlyWorldMatrix(world);
  198. this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
  199. // Bones
  200. if (mesh && mesh.useBones && mesh.computeBonesUsingShaders) {
  201. this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
  202. }
  203. if (scene.getCachedMaterial() !== this) {
  204. // Textures
  205. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  206. this._effect.setTexture("diffuseSampler", this.diffuseTexture);
  207. this._effect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
  208. this._effect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
  209. this._effect.setTexture("distortionSampler", this.distortionTexture);
  210. this._effect.setTexture("opacitySampler", this.opacityTexture);
  211. }
  212. // Clip plane
  213. if (scene.clipPlane) {
  214. var clipPlane = scene.clipPlane;
  215. this._effect.setFloat4("vClipPlane", clipPlane.normal.x, clipPlane.normal.y, clipPlane.normal.z, clipPlane.d);
  216. }
  217. // Point size
  218. if (this.pointsCloud) {
  219. this._effect.setFloat("pointSize", this.pointSize);
  220. }
  221. this._effect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
  222. }
  223. this._effect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
  224. // View
  225. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  226. this._effect.setMatrix("view", scene.getViewMatrix());
  227. }
  228. // Fog
  229. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  230. this._effect.setFloat4("vFogInfos", scene.fogMode, scene.fogStart, scene.fogEnd, scene.fogDensity);
  231. this._effect.setColor3("vFogColor", scene.fogColor);
  232. }
  233. // Time
  234. this._lastTime += scene.getEngine().getDeltaTime();
  235. this._effect.setFloat("time", this._lastTime);
  236. // Speed
  237. this._effect.setFloat("speed", this.speed);
  238. _super.prototype.bind.call(this, world, mesh);
  239. };
  240. FireMaterial.prototype.getAnimatables = function () {
  241. var results = [];
  242. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  243. results.push(this.diffuseTexture);
  244. }
  245. if (this.distortionTexture && this.distortionTexture.animations && this.distortionTexture.animations.length > 0) {
  246. results.push(this.distortionTexture);
  247. }
  248. if (this.opacityTexture && this.opacityTexture.animations && this.opacityTexture.animations.length > 0) {
  249. results.push(this.opacityTexture);
  250. }
  251. return results;
  252. };
  253. FireMaterial.prototype.dispose = function (forceDisposeEffect) {
  254. if (this.diffuseTexture) {
  255. this.diffuseTexture.dispose();
  256. }
  257. if (this.distortionTexture) {
  258. this.distortionTexture.dispose();
  259. }
  260. _super.prototype.dispose.call(this, forceDisposeEffect);
  261. };
  262. FireMaterial.prototype.clone = function (name) {
  263. var newMaterial = new FireMaterial(name, this.getScene());
  264. // Base material
  265. this.copyTo(newMaterial);
  266. // Fire material
  267. if (this.diffuseTexture && this.diffuseTexture.clone) {
  268. newMaterial.diffuseTexture = this.diffuseTexture.clone();
  269. }
  270. if (this.distortionTexture && this.distortionTexture.clone) {
  271. newMaterial.distortionTexture = this.distortionTexture.clone();
  272. }
  273. if (this.opacityTexture && this.opacityTexture.clone) {
  274. newMaterial.opacityTexture = this.opacityTexture.clone();
  275. }
  276. newMaterial.diffuseColor = this.diffuseColor.clone();
  277. return newMaterial;
  278. };
  279. FireMaterial.prototype.serialize = function () {
  280. var serializationObject = _super.prototype.serialize.call(this);
  281. serializationObject.customType = "BABYLON.FireMaterial";
  282. serializationObject.diffuseColor = this.diffuseColor.asArray();
  283. serializationObject.speed = this.speed;
  284. serializationObject.disableLighting = this.disableLighting;
  285. if (this.diffuseTexture) {
  286. serializationObject.diffuseTexture = this.diffuseTexture.serialize();
  287. }
  288. if (this.distortionTexture) {
  289. serializationObject.distortionTexture = this.distortionTexture.serialize();
  290. }
  291. if (this.opacityTexture) {
  292. serializationObject.opacityTexture = this.opacityTexture.serialize();
  293. }
  294. return serializationObject;
  295. };
  296. FireMaterial.Parse = function (source, scene, rootUrl) {
  297. var material = new FireMaterial(source.name, scene);
  298. material.diffuseColor = BABYLON.Color3.FromArray(source.diffuseColor);
  299. material.speed = source.speed;
  300. material.disableLighting = source.disableLighting;
  301. material.alpha = source.alpha;
  302. material.id = source.id;
  303. BABYLON.Tags.AddTagsTo(material, source.tags);
  304. material.backFaceCulling = source.backFaceCulling;
  305. material.wireframe = source.wireframe;
  306. if (source.diffuseTexture) {
  307. material.diffuseTexture = BABYLON.Texture.Parse(source.diffuseTexture, scene, rootUrl);
  308. }
  309. if (source.distortionTexture) {
  310. material.distortionTexture = BABYLON.Texture.Parse(source.distortionTexture, scene, rootUrl);
  311. }
  312. if (source.opacityTexture) {
  313. material.opacityTexture = BABYLON.Texture.Parse(source.opacityTexture, scene, rootUrl);
  314. }
  315. if (source.checkReadyOnlyOnce) {
  316. material.checkReadyOnlyOnce = source.checkReadyOnlyOnce;
  317. }
  318. return material;
  319. };
  320. return FireMaterial;
  321. })(BABYLON.Material);
  322. BABYLON.FireMaterial = FireMaterial;
  323. })(BABYLON || (BABYLON = {}));
  324. BABYLON.Effect.ShadersStore['fireVertexShader'] = "precision highp float;\r\n\r\n// Attributes\r\nattribute vec3 position;\r\n#ifdef NORMAL\r\nattribute vec3 normal;\r\n#endif\r\n#ifdef UV1\r\nattribute vec2 uv;\r\n#endif\r\n#ifdef UV2\r\nattribute vec2 uv2;\r\n#endif\r\n#ifdef VERTEXCOLOR\r\nattribute vec4 color;\r\n#endif\r\n#ifdef BONES\r\nattribute vec4 matricesIndices;\r\nattribute vec4 matricesWeights;\r\n#endif\r\n\r\n// Uniforms\r\n\r\n#ifdef INSTANCES\r\nattribute vec4 world0;\r\nattribute vec4 world1;\r\nattribute vec4 world2;\r\nattribute vec4 world3;\r\n#else\r\nuniform mat4 world;\r\n#endif\r\n\r\nuniform mat4 view;\r\nuniform mat4 viewProjection;\r\n\r\n#ifdef DIFFUSE\r\nvarying vec2 vDiffuseUV;\r\n#endif\r\n\r\n#ifdef BONES\r\nuniform mat4 mBones[BonesPerMesh];\r\n#endif\r\n\r\n#ifdef POINTSIZE\r\nuniform float pointSize;\r\n#endif\r\n\r\n// Output\r\nvarying vec3 vPositionW;\r\n#ifdef NORMAL\r\nvarying vec3 vNormalW;\r\n#endif\r\n\r\n#ifdef VERTEXCOLOR\r\nvarying vec4 vColor;\r\n#endif\r\n\r\n#ifdef CLIPPLANE\r\nuniform vec4 vClipPlane;\r\nvarying float fClipDistance;\r\n#endif\r\n\r\n#ifdef FOG\r\nvarying float fFogDistance;\r\n#endif\r\n\r\n// Fire\r\nuniform float time;\r\nuniform float speed;\r\n\r\nvarying vec2 vDistortionCoords1;\r\nvarying vec2 vDistortionCoords2;\r\nvarying vec2 vDistortionCoords3;\r\n\r\nvoid main(void) {\r\n\tmat4 finalWorld;\r\n\r\n#ifdef INSTANCES\r\n\tfinalWorld = mat4(world0, world1, world2, world3);\r\n#else\r\n\tfinalWorld = world;\r\n#endif\r\n\r\n#ifdef BONES\r\n\tmat4 m0 = mBones[int(matricesIndices.x)] * matricesWeights.x;\r\n\tmat4 m1 = mBones[int(matricesIndices.y)] * matricesWeights.y;\r\n\tmat4 m2 = mBones[int(matricesIndices.z)] * matricesWeights.z;\r\n\r\n#ifdef BONES4\r\n\tmat4 m3 = mBones[int(matricesIndices.w)] * matricesWeights.w;\r\n\tfinalWorld = finalWorld * (m0 + m1 + m2 + m3);\r\n#else\r\n\tfinalWorld = finalWorld * (m0 + m1 + m2);\r\n#endif \r\n\r\n#endif\r\n\tgl_Position = viewProjection * finalWorld * vec4(position, 1.0);\r\n\r\n\tvec4 worldPos = finalWorld * vec4(position, 1.0);\r\n\tvPositionW = vec3(worldPos);\r\n\r\n#ifdef NORMAL\r\n\tvNormalW = normalize(vec3(finalWorld * vec4(normal, 0.0)));\r\n#endif\r\n\r\n\t// Texture coordinates\r\n#ifdef DIFFUSE\r\n\tvDiffuseUV = uv;\r\n\tvDiffuseUV.y -= 0.2;\r\n#endif\r\n\r\n\t// Clip plane\r\n#ifdef CLIPPLANE\r\n\tfClipDistance = dot(worldPos, vClipPlane);\r\n#endif\r\n\r\n\t// Fog\r\n#ifdef FOG\r\n\tfFogDistance = (view * worldPos).z;\r\n#endif\r\n\r\n\t// Vertex color\r\n#ifdef VERTEXCOLOR\r\n\tvColor = color;\r\n#endif\r\n\r\n\t// Point size\r\n#ifdef POINTSIZE\r\n\tgl_PointSize = pointSize;\r\n#endif\r\n\r\n\t// Fire\r\n\tvec3 layerSpeed = vec3(-0.2, -0.52, -0.1) * speed;\r\n\t\r\n\tvDistortionCoords1.x = uv.x;\r\n\tvDistortionCoords1.y = uv.y + layerSpeed.x * time / 1000.0;\r\n\t\r\n\tvDistortionCoords2.x = uv.x;\r\n\tvDistortionCoords2.y = uv.y + layerSpeed.y * time / 1000.0;\r\n\t\r\n\tvDistortionCoords3.x = uv.x;\r\n\tvDistortionCoords3.y = uv.y + layerSpeed.z * time / 1000.0;\r\n}\r\n";
  325. BABYLON.Effect.ShadersStore['firePixelShader'] = "precision highp float;\r\n\r\n// Constants\r\nuniform vec3 vEyePosition;\r\n\r\n// Input\r\nvarying vec3 vPositionW;\r\n\r\n#ifdef NORMAL\r\nvarying vec3 vNormalW;\r\n#endif\r\n\r\n#ifdef VERTEXCOLOR\r\nvarying vec4 vColor;\r\n#endif\r\n\r\n// Samplers\r\n#ifdef DIFFUSE\r\nvarying vec2 vDiffuseUV;\r\nuniform sampler2D diffuseSampler;\r\nuniform vec2 vDiffuseInfos;\r\n#endif\r\n\r\n// Fire\r\nuniform sampler2D distortionSampler;\r\nuniform sampler2D opacitySampler;\r\n\r\nvarying vec2 vDistortionCoords1;\r\nvarying vec2 vDistortionCoords2;\r\nvarying vec2 vDistortionCoords3;\r\n\r\n#ifdef CLIPPLANE\r\nvarying float fClipDistance;\r\n#endif\r\n\r\n// Fog\r\n#ifdef FOG\r\n\r\n#define FOGMODE_NONE 0.\r\n#define FOGMODE_EXP 1.\r\n#define FOGMODE_EXP2 2.\r\n#define FOGMODE_LINEAR 3.\r\n#define E 2.71828\r\n\r\nuniform vec4 vFogInfos;\r\nuniform vec3 vFogColor;\r\nvarying float fFogDistance;\r\n\r\nfloat CalcFogFactor()\r\n{\r\n\tfloat fogCoeff = 1.0;\r\n\tfloat fogStart = vFogInfos.y;\r\n\tfloat fogEnd = vFogInfos.z;\r\n\tfloat fogDensity = vFogInfos.w;\r\n\r\n\tif (FOGMODE_LINEAR == vFogInfos.x)\r\n\t{\r\n\t\tfogCoeff = (fogEnd - fFogDistance) / (fogEnd - fogStart);\r\n\t}\r\n\telse if (FOGMODE_EXP == vFogInfos.x)\r\n\t{\r\n\t\tfogCoeff = 1.0 / pow(E, fFogDistance * fogDensity);\r\n\t}\r\n\telse if (FOGMODE_EXP2 == vFogInfos.x)\r\n\t{\r\n\t\tfogCoeff = 1.0 / pow(E, fFogDistance * fFogDistance * fogDensity * fogDensity);\r\n\t}\r\n\r\n\treturn clamp(fogCoeff, 0.0, 1.0);\r\n}\r\n#endif\r\n\r\nvec4 bx2(vec4 x)\r\n{\r\n return vec4(2.0) * x - vec4(1.0);\r\n}\r\n\r\nvoid main(void) {\r\n\t// Clip plane\r\n#ifdef CLIPPLANE\r\n\tif (fClipDistance > 0.0)\r\n\t\tdiscard;\r\n#endif\r\n\r\n\tvec3 viewDirectionW = normalize(vEyePosition - vPositionW);\r\n\r\n\t// Base color\r\n\tvec4 baseColor = vec4(1., 1., 1., 1.);\r\n\r\n\t// Alpha\r\n\tfloat alpha = 1.0;\r\n\r\n#ifdef DIFFUSE\r\n\t// Fire\r\n\tconst float distortionAmount0 = 0.092;\r\n\tconst float distortionAmount1 = 0.092;\r\n\tconst float distortionAmount2 = 0.092;\r\n\t\r\n\tvec2 heightAttenuation = vec2(0.3, 0.39);\r\n\t\r\n\tvec4 noise0 = texture2D(distortionSampler, vDistortionCoords1);\r\n\tvec4 noise1 = texture2D(distortionSampler, vDistortionCoords2);\r\n\tvec4 noise2 = texture2D(distortionSampler, vDistortionCoords3);\r\n\t\r\n\tvec4 noiseSum = bx2(noise0) * distortionAmount0 + bx2(noise1) * distortionAmount1 + bx2(noise2) * distortionAmount2;\r\n\t\r\n\tvec4 perturbedBaseCoords = vec4(vDiffuseUV, 0.0, 1.0) + noiseSum * (vDiffuseUV.y * heightAttenuation.x + heightAttenuation.y);\r\n\t\r\n\tvec4 opacityColor = texture2D(opacitySampler, perturbedBaseCoords.xy);\r\n\t\r\n#ifdef ALPHATEST\r\n\tif (opacityColor.r < 0.1)\r\n\t\tdiscard;\r\n#endif\r\n\t\r\n\tbaseColor = texture2D(diffuseSampler, perturbedBaseCoords.xy) * 2.0;\r\n\tbaseColor *= opacityColor;\r\n\r\n\tbaseColor.rgb *= vDiffuseInfos.y;\r\n#endif\r\n\r\n#ifdef VERTEXCOLOR\r\n\tbaseColor.rgb *= vColor.rgb;\r\n#endif\r\n\r\n\t// Bump\r\n#ifdef NORMAL\r\n\tvec3 normalW = normalize(vNormalW);\r\n#else\r\n\tvec3 normalW = vec3(1.0, 1.0, 1.0);\r\n#endif\r\n\r\n\t// Lighting\r\n\tvec3 diffuseBase = vec3(1.0, 1.0, 1.0);\r\n\r\n#ifdef VERTEXALPHA\r\n\talpha *= vColor.a;\r\n#endif\r\n\r\n\t// Composition\r\n\tvec4 color = vec4(baseColor.rgb, alpha);\r\n\r\n#ifdef FOG\r\n\tfloat fog = CalcFogFactor();\r\n\tcolor.rgb = fog * color.rgb + (1.0 - fog) * vFogColor;\r\n#endif\r\n\r\n\tgl_FragColor = color;\r\n}";