babylon.normalMapProceduralTexture.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. var __extends = (this && this.__extends) || function (d, b) {
  3. for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
  4. function __() { this.constructor = d; }
  5. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  6. };
  7. var BABYLON;
  8. (function (BABYLON) {
  9. var NormalMapProceduralTexture = (function (_super) {
  10. __extends(NormalMapProceduralTexture, _super);
  11. function NormalMapProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  12. var _this = _super.call(this, name, size, "normalMapProceduralTexture", scene, fallbackTexture, generateMipMaps) || this;
  13. _this.updateShaderUniforms();
  14. return _this;
  15. }
  16. NormalMapProceduralTexture.prototype.updateShaderUniforms = function () {
  17. this.setTexture("baseSampler", this._baseTexture);
  18. this.setFloat("size", this.getRenderSize());
  19. };
  20. NormalMapProceduralTexture.prototype.render = function (useCameraPostProcess) {
  21. _super.prototype.render.call(this, useCameraPostProcess);
  22. };
  23. NormalMapProceduralTexture.prototype.resize = function (size, generateMipMaps) {
  24. _super.prototype.resize.call(this, size, generateMipMaps);
  25. // We need to update the "size" uniform
  26. this.updateShaderUniforms();
  27. };
  28. Object.defineProperty(NormalMapProceduralTexture.prototype, "baseTexture", {
  29. get: function () {
  30. return this._baseTexture;
  31. },
  32. set: function (texture) {
  33. this._baseTexture = texture;
  34. this.updateShaderUniforms();
  35. },
  36. enumerable: true,
  37. configurable: true
  38. });
  39. return NormalMapProceduralTexture;
  40. }(BABYLON.ProceduralTexture));
  41. BABYLON.NormalMapProceduralTexture = NormalMapProceduralTexture;
  42. })(BABYLON || (BABYLON = {}));
  43. //# sourceMappingURL=babylon.normalMapProceduralTexture.js.map
  44. 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";