babylon.normalMapProceduralTexture.js 4.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. 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 extendStatics(d, b);
  8. }
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  16. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  17. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  18. 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;
  19. return c > 3 && r && Object.defineProperty(target, key, r), r;
  20. };
  21. var BABYLON;
  22. (function (BABYLON) {
  23. var NormalMapProceduralTexture = /** @class */ (function (_super) {
  24. __extends(NormalMapProceduralTexture, _super);
  25. function NormalMapProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  26. var _this = _super.call(this, name, size, "normalMapProceduralTexture", scene, fallbackTexture, generateMipMaps) || this;
  27. _this.updateShaderUniforms();
  28. return _this;
  29. }
  30. NormalMapProceduralTexture.prototype.updateShaderUniforms = function () {
  31. this.setTexture("baseSampler", this._baseTexture);
  32. this.setFloat("size", this.getRenderSize());
  33. };
  34. NormalMapProceduralTexture.prototype.render = function (useCameraPostProcess) {
  35. _super.prototype.render.call(this, useCameraPostProcess);
  36. };
  37. NormalMapProceduralTexture.prototype.resize = function (size, generateMipMaps) {
  38. _super.prototype.resize.call(this, size, generateMipMaps);
  39. // We need to update the "size" uniform
  40. this.updateShaderUniforms();
  41. };
  42. Object.defineProperty(NormalMapProceduralTexture.prototype, "baseTexture", {
  43. get: function () {
  44. return this._baseTexture;
  45. },
  46. set: function (texture) {
  47. this._baseTexture = texture;
  48. this.updateShaderUniforms();
  49. },
  50. enumerable: true,
  51. configurable: true
  52. });
  53. /**
  54. * Serializes this normal map procedural texture
  55. * @returns a serialized normal map procedural texture object
  56. */
  57. NormalMapProceduralTexture.prototype.serialize = function () {
  58. var serializationObject = BABYLON.SerializationHelper.Serialize(this, _super.prototype.serialize.call(this));
  59. serializationObject.customType = "BABYLON.NormalMapProceduralTexture";
  60. return serializationObject;
  61. };
  62. /**
  63. * Creates a Normal Map Procedural Texture from parsed normal map procedural texture data
  64. * @param parsedTexture defines parsed texture data
  65. * @param scene defines the current scene
  66. * @param rootUrl defines the root URL containing normal map procedural texture information
  67. * @returns a parsed Normal Map Procedural Texture
  68. */
  69. NormalMapProceduralTexture.Parse = function (parsedTexture, scene, rootUrl) {
  70. var texture = BABYLON.SerializationHelper.Parse(function () { return new NormalMapProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps); }, parsedTexture, scene, rootUrl);
  71. return texture;
  72. };
  73. __decorate([
  74. BABYLON.serializeAsTexture()
  75. ], NormalMapProceduralTexture.prototype, "baseTexture", null);
  76. return NormalMapProceduralTexture;
  77. }(BABYLON.ProceduralTexture));
  78. BABYLON.NormalMapProceduralTexture = NormalMapProceduralTexture;
  79. })(BABYLON || (BABYLON = {}));
  80. //# sourceMappingURL=babylon.normalMapProceduralTexture.js.map
  81. 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";