babylon.normalMapProceduralTexture.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. "use strict";
  2. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  3. var __extends = (this && this.__extends) || (function () {
  4. var 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 function (d, b) {
  8. extendStatics(d, b);
  9. function __() { this.constructor = d; }
  10. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  11. };
  12. })();
  13. var BABYLON;
  14. (function (BABYLON) {
  15. var NormalMapProceduralTexture = /** @class */ (function (_super) {
  16. __extends(NormalMapProceduralTexture, _super);
  17. function NormalMapProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  18. var _this = _super.call(this, name, size, "normalMapProceduralTexture", scene, fallbackTexture, generateMipMaps) || this;
  19. _this.updateShaderUniforms();
  20. return _this;
  21. }
  22. NormalMapProceduralTexture.prototype.updateShaderUniforms = function () {
  23. this.setTexture("baseSampler", this._baseTexture);
  24. this.setFloat("size", this.getRenderSize());
  25. };
  26. NormalMapProceduralTexture.prototype.render = function (useCameraPostProcess) {
  27. _super.prototype.render.call(this, useCameraPostProcess);
  28. };
  29. NormalMapProceduralTexture.prototype.resize = function (size, generateMipMaps) {
  30. _super.prototype.resize.call(this, size, generateMipMaps);
  31. // We need to update the "size" uniform
  32. this.updateShaderUniforms();
  33. };
  34. Object.defineProperty(NormalMapProceduralTexture.prototype, "baseTexture", {
  35. get: function () {
  36. return this._baseTexture;
  37. },
  38. set: function (texture) {
  39. this._baseTexture = texture;
  40. this.updateShaderUniforms();
  41. },
  42. enumerable: true,
  43. configurable: true
  44. });
  45. return NormalMapProceduralTexture;
  46. }(BABYLON.ProceduralTexture));
  47. BABYLON.NormalMapProceduralTexture = NormalMapProceduralTexture;
  48. })(BABYLON || (BABYLON = {}));
  49. //# sourceMappingURL=babylon.normalMapProceduralTexture.js.map
  50. BABYLON.Effect.ShadersStore['normalMapProceduralTexturePixelShader'] = "precision highp float;\n\nuniform sampler2D baseSampler;\nuniform float size;\n\nvarying vec2 vUV;\n\nconst vec3 LUMA_COEFFICIENT=vec3(0.2126,0.7152,0.0722);\nfloat lumaAtCoord(vec2 coord)\n{\nvec3 pixel=texture2D(baseSampler,coord).rgb;\nfloat luma=dot(pixel,LUMA_COEFFICIENT);\nreturn luma;\n}\nvoid main()\n{\nfloat lumaU0=lumaAtCoord(vUV+vec2(-1.0,0.0)/size);\nfloat lumaU1=lumaAtCoord(vUV+vec2( 1.0,0.0)/size);\nfloat lumaV0=lumaAtCoord(vUV+vec2( 0.0,-1.0)/size);\nfloat lumaV1=lumaAtCoord(vUV+vec2( 0.0,1.0)/size);\nvec2 slope=(vec2(lumaU0-lumaU1,lumaV0-lumaV1)+1.0)*0.5;\ngl_FragColor=vec4(slope,1.0,1.0);\n}\n";