babylon.normalMapProceduralTexture.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 BABYLON;
  13. (function (BABYLON) {
  14. var NormalMapProceduralTexture = /** @class */ (function (_super) {
  15. __extends(NormalMapProceduralTexture, _super);
  16. function NormalMapProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  17. var _this = _super.call(this, name, size, "normalMapProceduralTexture", scene, fallbackTexture, generateMipMaps) || this;
  18. _this.updateShaderUniforms();
  19. return _this;
  20. }
  21. NormalMapProceduralTexture.prototype.updateShaderUniforms = function () {
  22. this.setTexture("baseSampler", this._baseTexture);
  23. this.setFloat("size", this.getRenderSize());
  24. };
  25. NormalMapProceduralTexture.prototype.render = function (useCameraPostProcess) {
  26. _super.prototype.render.call(this, useCameraPostProcess);
  27. };
  28. NormalMapProceduralTexture.prototype.resize = function (size, generateMipMaps) {
  29. _super.prototype.resize.call(this, size, generateMipMaps);
  30. // We need to update the "size" uniform
  31. this.updateShaderUniforms();
  32. };
  33. Object.defineProperty(NormalMapProceduralTexture.prototype, "baseTexture", {
  34. get: function () {
  35. return this._baseTexture;
  36. },
  37. set: function (texture) {
  38. this._baseTexture = texture;
  39. this.updateShaderUniforms();
  40. },
  41. enumerable: true,
  42. configurable: true
  43. });
  44. return NormalMapProceduralTexture;
  45. }(BABYLON.ProceduralTexture));
  46. BABYLON.NormalMapProceduralTexture = NormalMapProceduralTexture;
  47. })(BABYLON || (BABYLON = {}));
  48. //# sourceMappingURL=babylon.normalMapProceduralTexture.js.map
  49. 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";