babylon.furMaterial.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  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 FurMaterialDefines = (function (_super) {
  21. __extends(FurMaterialDefines, _super);
  22. function FurMaterialDefines() {
  23. var _this = _super.call(this) || this;
  24. _this.DIFFUSE = false;
  25. _this.HEIGHTMAP = false;
  26. _this.CLIPPLANE = false;
  27. _this.ALPHATEST = false;
  28. _this.DEPTHPREPASS = false;
  29. _this.POINTSIZE = false;
  30. _this.FOG = false;
  31. _this.NORMAL = false;
  32. _this.UV1 = false;
  33. _this.UV2 = false;
  34. _this.VERTEXCOLOR = false;
  35. _this.VERTEXALPHA = false;
  36. _this.NUM_BONE_INFLUENCERS = 0;
  37. _this.BonesPerMesh = 0;
  38. _this.INSTANCES = false;
  39. _this.HIGHLEVEL = false;
  40. _this.rebuild();
  41. return _this;
  42. }
  43. return FurMaterialDefines;
  44. }(BABYLON.MaterialDefines));
  45. var FurMaterial = (function (_super) {
  46. __extends(FurMaterial, _super);
  47. function FurMaterial(name, scene) {
  48. var _this = _super.call(this, name, scene) || this;
  49. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  50. _this.furLength = 1;
  51. _this.furAngle = 0;
  52. _this.furColor = new BABYLON.Color3(0.44, 0.21, 0.02);
  53. _this.furOffset = 0.0;
  54. _this.furSpacing = 12;
  55. _this.furGravity = new BABYLON.Vector3(0, 0, 0);
  56. _this.furSpeed = 100;
  57. _this.furDensity = 20;
  58. _this._disableLighting = false;
  59. _this._maxSimultaneousLights = 4;
  60. _this.highLevelFur = true;
  61. _this._furTime = 0;
  62. return _this;
  63. }
  64. Object.defineProperty(FurMaterial.prototype, "furTime", {
  65. get: function () {
  66. return this._furTime;
  67. },
  68. set: function (furTime) {
  69. this._furTime = furTime;
  70. },
  71. enumerable: true,
  72. configurable: true
  73. });
  74. FurMaterial.prototype.needAlphaBlending = function () {
  75. return (this.alpha < 1.0);
  76. };
  77. FurMaterial.prototype.needAlphaTesting = function () {
  78. return false;
  79. };
  80. FurMaterial.prototype.getAlphaTestTexture = function () {
  81. return null;
  82. };
  83. FurMaterial.prototype.updateFur = function () {
  84. for (var i = 1; i < this._meshes.length; i++) {
  85. var offsetFur = this._meshes[i].material;
  86. offsetFur.furLength = this.furLength;
  87. offsetFur.furAngle = this.furAngle;
  88. offsetFur.furGravity = this.furGravity;
  89. offsetFur.furSpacing = this.furSpacing;
  90. offsetFur.furSpeed = this.furSpeed;
  91. offsetFur.furColor = this.furColor;
  92. offsetFur.diffuseTexture = this.diffuseTexture;
  93. offsetFur.furTexture = this.furTexture;
  94. offsetFur.highLevelFur = this.highLevelFur;
  95. offsetFur.furTime = this.furTime;
  96. offsetFur.furDensity = this.furDensity;
  97. }
  98. };
  99. // Methods
  100. FurMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  101. if (this.isFrozen) {
  102. if (this._wasPreviouslyReady && subMesh.effect) {
  103. return true;
  104. }
  105. }
  106. if (!subMesh._materialDefines) {
  107. subMesh._materialDefines = new FurMaterialDefines();
  108. }
  109. var defines = subMesh._materialDefines;
  110. var scene = this.getScene();
  111. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  112. if (this._renderId === scene.getRenderId()) {
  113. return true;
  114. }
  115. }
  116. var engine = scene.getEngine();
  117. // Textures
  118. if (defines._areTexturesDirty) {
  119. if (scene.texturesEnabled) {
  120. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  121. if (!this.diffuseTexture.isReady()) {
  122. return false;
  123. }
  124. else {
  125. defines._needUVs = true;
  126. defines.DIFFUSE = true;
  127. }
  128. }
  129. if (this.heightTexture && engine.getCaps().maxVertexTextureImageUnits) {
  130. if (!this.heightTexture.isReady()) {
  131. return false;
  132. }
  133. else {
  134. defines._needUVs = true;
  135. defines.HEIGHTMAP = true;
  136. }
  137. }
  138. }
  139. }
  140. // High level
  141. if (this.highLevelFur !== defines.HIGHLEVEL) {
  142. defines.HIGHLEVEL = true;
  143. defines.markAsUnprocessed();
  144. }
  145. // Misc.
  146. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, defines);
  147. // Lights
  148. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  149. // Values that need to be evaluated on every frame
  150. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances);
  151. // Attribs
  152. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  153. // Get correct effect
  154. if (defines.isDirty) {
  155. defines.markAsProcessed();
  156. scene.resetCachedMaterial();
  157. // Fallbacks
  158. var fallbacks = new BABYLON.EffectFallbacks();
  159. if (defines.FOG) {
  160. fallbacks.addFallback(1, "FOG");
  161. }
  162. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  163. if (defines.NUM_BONE_INFLUENCERS > 0) {
  164. fallbacks.addCPUSkinningFallback(0, mesh);
  165. }
  166. //Attributes
  167. var attribs = [BABYLON.VertexBuffer.PositionKind];
  168. if (defines.NORMAL) {
  169. attribs.push(BABYLON.VertexBuffer.NormalKind);
  170. }
  171. if (defines.UV1) {
  172. attribs.push(BABYLON.VertexBuffer.UVKind);
  173. }
  174. if (defines.UV2) {
  175. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  176. }
  177. if (defines.VERTEXCOLOR) {
  178. attribs.push(BABYLON.VertexBuffer.ColorKind);
  179. }
  180. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  181. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  182. // Legacy browser patch
  183. var shaderName = "fur";
  184. var join = defines.toString();
  185. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  186. "vFogInfos", "vFogColor", "pointSize",
  187. "vDiffuseInfos",
  188. "mBones",
  189. "vClipPlane", "diffuseMatrix",
  190. "furLength", "furAngle", "furColor", "furOffset", "furGravity", "furTime", "furSpacing", "furDensity"
  191. ];
  192. var samplers = ["diffuseSampler",
  193. "heightTexture", "furTexture"
  194. ];
  195. var uniformBuffers = new Array();
  196. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  197. uniformsNames: uniforms,
  198. uniformBuffersNames: uniformBuffers,
  199. samplers: samplers,
  200. defines: defines,
  201. maxSimultaneousLights: this.maxSimultaneousLights
  202. });
  203. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  204. attributes: attribs,
  205. uniformsNames: uniforms,
  206. uniformBuffersNames: uniformBuffers,
  207. samplers: samplers,
  208. defines: join,
  209. fallbacks: fallbacks,
  210. onCompiled: this.onCompiled,
  211. onError: this.onError,
  212. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  213. }, engine), defines);
  214. }
  215. if (!subMesh.effect.isReady()) {
  216. return false;
  217. }
  218. this._renderId = scene.getRenderId();
  219. this._wasPreviouslyReady = true;
  220. return true;
  221. };
  222. FurMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  223. var scene = this.getScene();
  224. var defines = subMesh._materialDefines;
  225. if (!defines) {
  226. return;
  227. }
  228. var effect = subMesh.effect;
  229. this._activeEffect = effect;
  230. // Matrices
  231. this.bindOnlyWorldMatrix(world);
  232. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  233. // Bones
  234. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  235. if (scene.getCachedMaterial() !== this) {
  236. // Textures
  237. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  238. this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
  239. this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  240. this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  241. }
  242. if (this._heightTexture) {
  243. this._activeEffect.setTexture("heightTexture", this._heightTexture);
  244. }
  245. // Clip plane
  246. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  247. // Point size
  248. if (this.pointsCloud) {
  249. this._activeEffect.setFloat("pointSize", this.pointSize);
  250. }
  251. this._activeEffect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
  252. }
  253. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  254. if (scene.lightsEnabled && !this.disableLighting) {
  255. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  256. }
  257. // View
  258. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  259. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  260. }
  261. // Fog
  262. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  263. this._activeEffect.setFloat("furLength", this.furLength);
  264. this._activeEffect.setFloat("furAngle", this.furAngle);
  265. this._activeEffect.setColor4("furColor", this.furColor, 1.0);
  266. if (this.highLevelFur) {
  267. this._activeEffect.setVector3("furGravity", this.furGravity);
  268. this._activeEffect.setFloat("furOffset", this.furOffset);
  269. this._activeEffect.setFloat("furSpacing", this.furSpacing);
  270. this._activeEffect.setFloat("furDensity", this.furDensity);
  271. this._furTime += this.getScene().getEngine().getDeltaTime() / this.furSpeed;
  272. this._activeEffect.setFloat("furTime", this._furTime);
  273. this._activeEffect.setTexture("furTexture", this.furTexture);
  274. }
  275. this._afterBind(mesh, this._activeEffect);
  276. };
  277. FurMaterial.prototype.getAnimatables = function () {
  278. var results = [];
  279. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  280. results.push(this.diffuseTexture);
  281. }
  282. if (this.heightTexture && this.heightTexture.animations && this.heightTexture.animations.length > 0) {
  283. results.push(this.heightTexture);
  284. }
  285. return results;
  286. };
  287. FurMaterial.prototype.getActiveTextures = function () {
  288. var activeTextures = _super.prototype.getActiveTextures.call(this);
  289. if (this._diffuseTexture) {
  290. activeTextures.push(this._diffuseTexture);
  291. }
  292. if (this._heightTexture) {
  293. activeTextures.push(this._heightTexture);
  294. }
  295. return activeTextures;
  296. };
  297. FurMaterial.prototype.hasTexture = function (texture) {
  298. if (_super.prototype.hasTexture.call(this, texture)) {
  299. return true;
  300. }
  301. if (this.diffuseTexture === texture) {
  302. return true;
  303. }
  304. if (this._heightTexture === texture) {
  305. return true;
  306. }
  307. return false;
  308. };
  309. FurMaterial.prototype.dispose = function (forceDisposeEffect) {
  310. if (this.diffuseTexture) {
  311. this.diffuseTexture.dispose();
  312. }
  313. if (this._meshes) {
  314. for (var i = 1; i < this._meshes.length; i++) {
  315. this._meshes[i].material.dispose(forceDisposeEffect);
  316. this._meshes[i].dispose();
  317. }
  318. }
  319. _super.prototype.dispose.call(this, forceDisposeEffect);
  320. };
  321. FurMaterial.prototype.clone = function (name) {
  322. var _this = this;
  323. return BABYLON.SerializationHelper.Clone(function () { return new FurMaterial(name, _this.getScene()); }, this);
  324. };
  325. FurMaterial.prototype.serialize = function () {
  326. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  327. serializationObject.customType = "BABYLON.FurMaterial";
  328. if (this._meshes) {
  329. serializationObject.sourceMeshName = this._meshes[0].name;
  330. serializationObject.quality = this._meshes.length;
  331. }
  332. return serializationObject;
  333. };
  334. FurMaterial.prototype.getClassName = function () {
  335. return "FurMaterial";
  336. };
  337. // Statics
  338. FurMaterial.Parse = function (source, scene, rootUrl) {
  339. var material = BABYLON.SerializationHelper.Parse(function () { return new FurMaterial(source.name, scene); }, source, scene, rootUrl);
  340. if (source.sourceMeshName && material.highLevelFur) {
  341. scene.executeWhenReady(function () {
  342. var sourceMesh = scene.getMeshByName(source.sourceMeshName);
  343. if (sourceMesh) {
  344. var furTexture = FurMaterial.GenerateTexture("Fur Texture", scene);
  345. material.furTexture = furTexture;
  346. FurMaterial.FurifyMesh(sourceMesh, source.quality);
  347. }
  348. });
  349. }
  350. return material;
  351. };
  352. FurMaterial.GenerateTexture = function (name, scene) {
  353. // Generate fur textures
  354. var texture = new BABYLON.DynamicTexture("FurTexture " + name, 256, scene, true);
  355. var context = texture.getContext();
  356. for (var i = 0; i < 20000; ++i) {
  357. context.fillStyle = "rgba(255, " + Math.floor(Math.random() * 255) + ", " + Math.floor(Math.random() * 255) + ", 1)";
  358. context.fillRect((Math.random() * texture.getSize().width), (Math.random() * texture.getSize().height), 2, 2);
  359. }
  360. texture.update(false);
  361. texture.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
  362. texture.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
  363. return texture;
  364. };
  365. // Creates and returns an array of meshes used as shells for the Fur Material
  366. // that can be disposed later in your code
  367. // The quality is in interval [0, 100]
  368. FurMaterial.FurifyMesh = function (sourceMesh, quality) {
  369. var meshes = [sourceMesh];
  370. var mat = sourceMesh.material;
  371. var i;
  372. if (!(mat instanceof FurMaterial)) {
  373. throw "The material of the source mesh must be a Fur Material";
  374. }
  375. for (i = 1; i < quality; i++) {
  376. var offsetFur = new BABYLON.FurMaterial(mat.name + i, sourceMesh.getScene());
  377. sourceMesh.getScene().materials.pop();
  378. BABYLON.Tags.EnableFor(offsetFur);
  379. BABYLON.Tags.AddTagsTo(offsetFur, "furShellMaterial");
  380. offsetFur.furLength = mat.furLength;
  381. offsetFur.furAngle = mat.furAngle;
  382. offsetFur.furGravity = mat.furGravity;
  383. offsetFur.furSpacing = mat.furSpacing;
  384. offsetFur.furSpeed = mat.furSpeed;
  385. offsetFur.furColor = mat.furColor;
  386. offsetFur.diffuseTexture = mat.diffuseTexture;
  387. offsetFur.furOffset = i / quality;
  388. offsetFur.furTexture = mat.furTexture;
  389. offsetFur.highLevelFur = mat.highLevelFur;
  390. offsetFur.furTime = mat.furTime;
  391. offsetFur.furDensity = mat.furDensity;
  392. var offsetMesh = sourceMesh.clone(sourceMesh.name + i);
  393. offsetMesh.material = offsetFur;
  394. offsetMesh.skeleton = sourceMesh.skeleton;
  395. offsetMesh.position = BABYLON.Vector3.Zero();
  396. meshes.push(offsetMesh);
  397. }
  398. for (i = 1; i < meshes.length; i++) {
  399. meshes[i].parent = sourceMesh;
  400. }
  401. sourceMesh.material._meshes = meshes;
  402. return meshes;
  403. };
  404. __decorate([
  405. BABYLON.serializeAsTexture("diffuseTexture")
  406. ], FurMaterial.prototype, "_diffuseTexture", void 0);
  407. __decorate([
  408. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  409. ], FurMaterial.prototype, "diffuseTexture", void 0);
  410. __decorate([
  411. BABYLON.serializeAsTexture("heightTexture")
  412. ], FurMaterial.prototype, "_heightTexture", void 0);
  413. __decorate([
  414. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  415. ], FurMaterial.prototype, "heightTexture", void 0);
  416. __decorate([
  417. BABYLON.serializeAsColor3()
  418. ], FurMaterial.prototype, "diffuseColor", void 0);
  419. __decorate([
  420. BABYLON.serialize()
  421. ], FurMaterial.prototype, "furLength", void 0);
  422. __decorate([
  423. BABYLON.serialize()
  424. ], FurMaterial.prototype, "furAngle", void 0);
  425. __decorate([
  426. BABYLON.serializeAsColor3()
  427. ], FurMaterial.prototype, "furColor", void 0);
  428. __decorate([
  429. BABYLON.serialize()
  430. ], FurMaterial.prototype, "furOffset", void 0);
  431. __decorate([
  432. BABYLON.serialize()
  433. ], FurMaterial.prototype, "furSpacing", void 0);
  434. __decorate([
  435. BABYLON.serializeAsVector3()
  436. ], FurMaterial.prototype, "furGravity", void 0);
  437. __decorate([
  438. BABYLON.serialize()
  439. ], FurMaterial.prototype, "furSpeed", void 0);
  440. __decorate([
  441. BABYLON.serialize()
  442. ], FurMaterial.prototype, "furDensity", void 0);
  443. __decorate([
  444. BABYLON.serialize("disableLighting")
  445. ], FurMaterial.prototype, "_disableLighting", void 0);
  446. __decorate([
  447. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  448. ], FurMaterial.prototype, "disableLighting", void 0);
  449. __decorate([
  450. BABYLON.serialize("maxSimultaneousLights")
  451. ], FurMaterial.prototype, "_maxSimultaneousLights", void 0);
  452. __decorate([
  453. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  454. ], FurMaterial.prototype, "maxSimultaneousLights", void 0);
  455. __decorate([
  456. BABYLON.serialize()
  457. ], FurMaterial.prototype, "highLevelFur", void 0);
  458. __decorate([
  459. BABYLON.serialize()
  460. ], FurMaterial.prototype, "furTime", null);
  461. return FurMaterial;
  462. }(BABYLON.PushMaterial));
  463. BABYLON.FurMaterial = FurMaterial;
  464. })(BABYLON || (BABYLON = {}));
  465. //# sourceMappingURL=babylon.furMaterial.js.map
  466. BABYLON.Effect.ShadersStore['furVertexShader'] = "precision highp 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 float furLength;\nuniform float furAngle;\n#ifdef HIGHLEVEL\nuniform float furOffset;\nuniform vec3 furGravity;\nuniform float furTime;\nuniform float furSpacing;\nuniform float furDensity;\n#endif\n#ifdef HEIGHTMAP\nuniform sampler2D heightTexture;\n#endif\n#ifdef HIGHLEVEL\nvarying vec2 vFurUV;\n#endif\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\nvarying float vfur_length;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\nfloat Rand(vec3 rv) {\nfloat x=dot(rv,vec3(12.9898,78.233,24.65487));\nreturn fract(sin(x)*43758.5453);\n}\nvoid main(void) {\n#include<instancesVertex>\n#include<bonesVertex>\n\nfloat r=Rand(position);\n#ifdef HEIGHTMAP\n#if __VERSION__>100\nvfur_length=furLength*texture(heightTexture,uv).x;\n#else\nvfur_length=furLength*texture2D(heightTexture,uv).r;\n#endif\n#else \nvfur_length=(furLength*r);\n#endif\nvec3 tangent1=vec3(normal.y,-normal.x,0);\nvec3 tangent2=vec3(-normal.z,0,normal.x);\nr=Rand(tangent1*r);\nfloat J=(2.0+4.0*r);\nr=Rand(tangent2*r);\nfloat K=(2.0+2.0*r);\ntangent1=tangent1*J+tangent2*K;\ntangent1=normalize(tangent1);\nvec3 newPosition=position+normal*vfur_length*cos(furAngle)+tangent1*vfur_length*sin(furAngle);\n#ifdef HIGHLEVEL\n\nvec3 forceDirection=vec3(0.0,0.0,0.0);\nforceDirection.x=sin(furTime+position.x*0.05)*0.2;\nforceDirection.y=cos(furTime*0.7+position.y*0.04)*0.2;\nforceDirection.z=sin(furTime*0.7+position.z*0.04)*0.2;\nvec3 displacement=vec3(0.0,0.0,0.0);\ndisplacement=furGravity+forceDirection;\nfloat displacementFactor=pow(furOffset,3.0);\nvec3 aNormal=normal;\naNormal.xyz+=displacement*displacementFactor;\nnewPosition=vec3(newPosition.x,newPosition.y,newPosition.z)+(normalize(aNormal)*furOffset*furSpacing);\n#endif\n#ifdef NORMAL\n#ifdef HIGHLEVEL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0))*aNormal);\n#else\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n#endif\n\ngl_Position=viewProjection*finalWorld*vec4(newPosition,1.0);\nvec4 worldPos=finalWorld*vec4(newPosition,1.0);\nvPositionW=vec3(worldPos);\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 (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#ifdef HIGHLEVEL\nvFurUV=vDiffuseUV*furDensity;\n#endif\n#else\n#ifdef HIGHLEVEL\nvFurUV=uv*furDensity;\n#endif\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";
  467. BABYLON.Effect.ShadersStore['furPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nuniform vec4 furColor;\nuniform float furLength;\nvarying vec3 vPositionW;\nvarying float vfur_length;\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 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n\n#ifdef HIGHLEVEL\nuniform float furOffset;\nuniform sampler2D furTexture;\nvarying vec2 vFurUV;\n#endif\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<fogFragmentDeclaration>\n#include<clipPlaneFragmentDeclaration>\nfloat Rand(vec3 rv) {\nfloat x=dot(rv,vec3(12.9898,78.233,24.65487));\nreturn fract(sin(x)*43758.5453);\n}\nvoid main(void) {\n\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=furColor;\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef DIFFUSE\nbaseColor*=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#include<depthPrePass>\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n#ifdef HIGHLEVEL\n\nvec4 furTextureColor=texture2D(furTexture,vec2(vFurUV.x,vFurUV.y));\nif (furTextureColor.a<=0.0 || furTextureColor.g<furOffset) {\ndiscard;\n}\nfloat occlusion=mix(0.0,furTextureColor.b*1.2,furOffset);\nbaseColor=vec4(baseColor.xyz*occlusion,1.1-furOffset);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase.rgb*baseColor.rgb,0.0,1.0);\n\n#ifdef HIGHLEVEL\nvec4 color=vec4(finalDiffuse,alpha);\n#else\nfloat r=vfur_length/furLength*0.5;\nvec4 color=vec4(finalDiffuse*(0.5+r),alpha);\n#endif\n#include<fogFragment>\ngl_FragColor=color;\n}";