babylon.normalMapProceduralTexture.js 4.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 NormalMapProceduralTexture = /** @class */ (function (_super) {
  21. __extends(NormalMapProceduralTexture, _super);
  22. function NormalMapProceduralTexture(name, size, scene, fallbackTexture, generateMipMaps) {
  23. var _this = _super.call(this, name, size, "normalMapProceduralTexture", scene, fallbackTexture, generateMipMaps) || this;
  24. _this.updateShaderUniforms();
  25. return _this;
  26. }
  27. NormalMapProceduralTexture.prototype.updateShaderUniforms = function () {
  28. this.setTexture("baseSampler", this._baseTexture);
  29. this.setFloat("size", this.getRenderSize());
  30. };
  31. NormalMapProceduralTexture.prototype.render = function (useCameraPostProcess) {
  32. _super.prototype.render.call(this, useCameraPostProcess);
  33. };
  34. NormalMapProceduralTexture.prototype.resize = function (size, generateMipMaps) {
  35. _super.prototype.resize.call(this, size, generateMipMaps);
  36. // We need to update the "size" uniform
  37. this.updateShaderUniforms();
  38. };
  39. Object.defineProperty(NormalMapProceduralTexture.prototype, "baseTexture", {
  40. get: function () {
  41. return this._baseTexture;
  42. },
  43. set: function (texture) {
  44. this._baseTexture = texture;
  45. this.updateShaderUniforms();
  46. },
  47. enumerable: true,
  48. configurable: true
  49. });
  50. /**
  51. * Serializes this normal map procedural texture
  52. * @returns a serialized normal map procedural texture object
  53. */
  54. NormalMapProceduralTexture.prototype.serialize = function () {
  55. var serializationObject = BABYLON.SerializationHelper.Serialize(this, _super.prototype.serialize.call(this));
  56. serializationObject.customType = "BABYLON.NormalMapProceduralTexture";
  57. return serializationObject;
  58. };
  59. /**
  60. * Creates a Normal Map Procedural Texture from parsed normal map procedural texture data
  61. * @param parsedTexture defines parsed texture data
  62. * @param scene defines the current scene
  63. * @param rootUrl defines the root URL containing normal map procedural texture information
  64. * @returns a parsed Normal Map Procedural Texture
  65. */
  66. NormalMapProceduralTexture.Parse = function (parsedTexture, scene, rootUrl) {
  67. var texture = BABYLON.SerializationHelper.Parse(function () { return new NormalMapProceduralTexture(parsedTexture.name, parsedTexture._size, scene, undefined, parsedTexture._generateMipMaps); }, parsedTexture, scene, rootUrl);
  68. return texture;
  69. };
  70. __decorate([
  71. BABYLON.serializeAsTexture()
  72. ], NormalMapProceduralTexture.prototype, "baseTexture", null);
  73. return NormalMapProceduralTexture;
  74. }(BABYLON.ProceduralTexture));
  75. BABYLON.NormalMapProceduralTexture = NormalMapProceduralTexture;
  76. })(BABYLON || (BABYLON = {}));
  77. //# sourceMappingURL=babylon.normalMapProceduralTexture.js.map
  78. 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";