@babylonjs/post-processes 5.21.0 → 5.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { __decorate, __extends } from "tslib";
1
+ import { __decorate } from "@babylonjs/core/tslib.es6.js";
2
2
  import { serialize, SerializationHelper } from "@babylonjs/core/Misc/decorators.js";
3
3
  import { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
4
4
  import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
@@ -11,8 +11,7 @@ import "./asciiart.fragment.js";
11
11
  * It basically takes care rendering the font front the given font size to a texture.
12
12
  * This is used later on in the postprocess.
13
13
  */
14
- var AsciiArtFontTexture = /** @class */ (function (_super) {
15
- __extends(AsciiArtFontTexture, _super);
14
+ export class AsciiArtFontTexture extends BaseTexture {
16
15
  /**
17
16
  * Create a new instance of the Ascii Art FontTexture class
18
17
  * @param name the name of the texture
@@ -20,89 +19,83 @@ var AsciiArtFontTexture = /** @class */ (function (_super) {
20
19
  * @param text the caracter set to use in the rendering.
21
20
  * @param scene the scene that owns the texture
22
21
  */
23
- function AsciiArtFontTexture(name, font, text, scene) {
24
- if (scene === void 0) { scene = null; }
25
- var _this = _super.call(this, scene) || this;
26
- scene = _this.getScene();
22
+ constructor(name, font, text, scene = null) {
23
+ super(scene);
24
+ scene = this.getScene();
27
25
  if (!scene) {
28
- return _this;
26
+ return;
29
27
  }
30
- _this.name = name;
31
- _this._text == text;
32
- _this._font == font;
33
- _this.wrapU = Texture.CLAMP_ADDRESSMODE;
34
- _this.wrapV = Texture.CLAMP_ADDRESSMODE;
28
+ this.name = name;
29
+ this._text == text;
30
+ this._font == font;
31
+ this.wrapU = Texture.CLAMP_ADDRESSMODE;
32
+ this.wrapV = Texture.CLAMP_ADDRESSMODE;
35
33
  //this.anisotropicFilteringLevel = 1;
36
34
  // Get the font specific info.
37
- var maxCharHeight = _this._getFontHeight(font);
38
- var maxCharWidth = _this._getFontWidth(font);
39
- _this._charSize = Math.max(maxCharHeight.height, maxCharWidth);
35
+ const maxCharHeight = this._getFontHeight(font);
36
+ const maxCharWidth = this._getFontWidth(font);
37
+ this._charSize = Math.max(maxCharHeight.height, maxCharWidth);
40
38
  // This is an approximate size, but should always be able to fit at least the maxCharCount.
41
- var textureWidth = Math.ceil(_this._charSize * text.length);
42
- var textureHeight = _this._charSize;
39
+ const textureWidth = Math.ceil(this._charSize * text.length);
40
+ const textureHeight = this._charSize;
43
41
  // Create the texture that will store the font characters.
44
- _this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);
42
+ this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);
45
43
  //scene.getEngine().setclamp
46
- var textureSize = _this.getSize();
44
+ const textureSize = this.getSize();
47
45
  // Create a canvas with the final size: the one matching the texture.
48
- var canvas = document.createElement("canvas");
46
+ const canvas = document.createElement("canvas");
49
47
  canvas.width = textureSize.width;
50
48
  canvas.height = textureSize.height;
51
- var context = canvas.getContext("2d");
49
+ const context = canvas.getContext("2d");
52
50
  context.textBaseline = "top";
53
51
  context.font = font;
54
52
  context.fillStyle = "white";
55
53
  context.imageSmoothingEnabled = false;
56
54
  // Sets the text in the texture.
57
- for (var i = 0; i < text.length; i++) {
58
- context.fillText(text[i], i * _this._charSize, -maxCharHeight.offset);
55
+ for (let i = 0; i < text.length; i++) {
56
+ context.fillText(text[i], i * this._charSize, -maxCharHeight.offset);
59
57
  }
60
58
  // Flush the text in the dynamic texture.
61
- scene.getEngine().updateDynamicTexture(_this._texture, canvas, false, true);
62
- return _this;
59
+ scene.getEngine().updateDynamicTexture(this._texture, canvas, false, true);
60
+ }
61
+ /**
62
+ * Gets the size of one char in the texture (each char fits in size * size space in the texture).
63
+ */
64
+ get charSize() {
65
+ return this._charSize;
63
66
  }
64
- Object.defineProperty(AsciiArtFontTexture.prototype, "charSize", {
65
- /**
66
- * Gets the size of one char in the texture (each char fits in size * size space in the texture).
67
- */
68
- get: function () {
69
- return this._charSize;
70
- },
71
- enumerable: false,
72
- configurable: true
73
- });
74
67
  /**
75
68
  * Gets the max char width of a font.
76
69
  * @param font the font to use, use the W3C CSS notation
77
70
  * @return the max char width
78
71
  */
79
- AsciiArtFontTexture.prototype._getFontWidth = function (font) {
80
- var fontDraw = document.createElement("canvas");
81
- var ctx = fontDraw.getContext("2d");
72
+ _getFontWidth(font) {
73
+ const fontDraw = document.createElement("canvas");
74
+ const ctx = fontDraw.getContext("2d");
82
75
  ctx.fillStyle = "white";
83
76
  ctx.font = font;
84
77
  return ctx.measureText("W").width;
85
- };
78
+ }
86
79
  // More info here: https://videlais.com/2014/03/16/the-many-and-varied-problems-with-measuring-font-height-for-html5-canvas/
87
80
  /**
88
81
  * Gets the max char height of a font.
89
82
  * @param font the font to use, use the W3C CSS notation
90
83
  * @return the max char height
91
84
  */
92
- AsciiArtFontTexture.prototype._getFontHeight = function (font) {
93
- var fontDraw = document.createElement("canvas");
94
- var ctx = fontDraw.getContext("2d");
85
+ _getFontHeight(font) {
86
+ const fontDraw = document.createElement("canvas");
87
+ const ctx = fontDraw.getContext("2d");
95
88
  ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);
96
89
  ctx.textBaseline = "top";
97
90
  ctx.fillStyle = "white";
98
91
  ctx.font = font;
99
92
  ctx.fillText("jH|", 0, 0);
100
- var pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;
101
- var start = -1;
102
- var end = -1;
103
- for (var row = 0; row < fontDraw.height; row++) {
104
- for (var column = 0; column < fontDraw.width; column++) {
105
- var index = (row * fontDraw.width + column) * 4;
93
+ const pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;
94
+ let start = -1;
95
+ let end = -1;
96
+ for (let row = 0; row < fontDraw.height; row++) {
97
+ for (let column = 0; column < fontDraw.width; column++) {
98
+ const index = (row * fontDraw.width + column) * 4;
106
99
  if (pixels[index] === 0) {
107
100
  if (column === fontDraw.width - 1 && start !== -1) {
108
101
  end = row;
@@ -120,41 +113,38 @@ var AsciiArtFontTexture = /** @class */ (function (_super) {
120
113
  }
121
114
  }
122
115
  return { height: end - start + 1, offset: start - 1 };
123
- };
116
+ }
124
117
  /**
125
118
  * Clones the current AsciiArtTexture.
126
119
  * @return the clone of the texture.
127
120
  */
128
- AsciiArtFontTexture.prototype.clone = function () {
121
+ clone() {
129
122
  return new AsciiArtFontTexture(this.name, this._font, this._text, this.getScene());
130
- };
123
+ }
131
124
  /**
132
125
  * Parses a json object representing the texture and returns an instance of it.
133
126
  * @param source the source JSON representation
134
127
  * @param scene the scene to create the texture for
135
128
  * @return the parsed texture
136
129
  */
137
- AsciiArtFontTexture.Parse = function (source, scene) {
138
- var texture = SerializationHelper.Parse(function () { return new AsciiArtFontTexture(source.name, source.font, source.text, scene); }, source, scene, null);
130
+ static Parse(source, scene) {
131
+ const texture = SerializationHelper.Parse(() => new AsciiArtFontTexture(source.name, source.font, source.text, scene), source, scene, null);
139
132
  return texture;
140
- };
141
- __decorate([
142
- serialize("font")
143
- ], AsciiArtFontTexture.prototype, "_font", void 0);
144
- __decorate([
145
- serialize("text")
146
- ], AsciiArtFontTexture.prototype, "_text", void 0);
147
- return AsciiArtFontTexture;
148
- }(BaseTexture));
149
- export { AsciiArtFontTexture };
133
+ }
134
+ }
135
+ __decorate([
136
+ serialize("font")
137
+ ], AsciiArtFontTexture.prototype, "_font", void 0);
138
+ __decorate([
139
+ serialize("text")
140
+ ], AsciiArtFontTexture.prototype, "_text", void 0);
150
141
  /**
151
142
  * AsciiArtPostProcess helps rendering everithing in Ascii Art.
152
143
  *
153
144
  * Simmply add it to your scene and let the nerd that lives in you have fun.
154
145
  * Example usage: var pp = new AsciiArtPostProcess("myAscii", "20px Monospace", camera);
155
146
  */
156
- var AsciiArtPostProcess = /** @class */ (function (_super) {
157
- __extends(AsciiArtPostProcess, _super);
147
+ export class AsciiArtPostProcess extends PostProcess {
158
148
  /**
159
149
  * Instantiates a new Ascii Art Post Process.
160
150
  * @param name the name to give to the postprocess
@@ -162,24 +152,24 @@ var AsciiArtPostProcess = /** @class */ (function (_super) {
162
152
  * @param camera
163
153
  * @param options can either be the font name or an option object following the IAsciiArtPostProcessOptions format
164
154
  */
165
- function AsciiArtPostProcess(name, camera, options) {
166
- var _this = _super.call(this, name, "asciiart", ["asciiArtFontInfos", "asciiArtOptions"], ["asciiArtFont"], {
155
+ constructor(name, camera, options) {
156
+ super(name, "asciiart", ["asciiArtFontInfos", "asciiArtOptions"], ["asciiArtFont"], {
167
157
  width: camera.getEngine().getRenderWidth(),
168
158
  height: camera.getEngine().getRenderHeight(),
169
- }, camera, Texture.TRILINEAR_SAMPLINGMODE, camera.getEngine(), true) || this;
159
+ }, camera, Texture.TRILINEAR_SAMPLINGMODE, camera.getEngine(), true);
170
160
  /**
171
161
  * This defines the amount you want to mix the "tile" or caracter space colored in the ascii art.
172
162
  * This number is defined between 0 and 1;
173
163
  */
174
- _this.mixToTile = 0;
164
+ this.mixToTile = 0;
175
165
  /**
176
166
  * This defines the amount you want to mix the normal rendering pass in the ascii art.
177
167
  * This number is defined between 0 and 1;
178
168
  */
179
- _this.mixToNormal = 0;
169
+ this.mixToNormal = 0;
180
170
  // Default values.
181
- var font = "40px Monospace";
182
- var characterSet = " `-.'_:,\"=^;<+!*?/cL\\zrs7TivJtC{3F)Il(xZfY5S2eajo14[nuyE]P6V9kXpKwGhqAUbOd8#HRDB0$mgMW&Q%N@";
171
+ let font = "40px Monospace";
172
+ let characterSet = " `-.'_:,\"=^;<+!*?/cL\\zrs7TivJtC{3F)Il(xZfY5S2eajo14[nuyE]P6V9kXpKwGhqAUbOd8#HRDB0$mgMW&Q%N@";
183
173
  // Use options.
184
174
  if (options) {
185
175
  if (typeof options === "string") {
@@ -188,20 +178,17 @@ var AsciiArtPostProcess = /** @class */ (function (_super) {
188
178
  else {
189
179
  font = options.font || font;
190
180
  characterSet = options.characterSet || characterSet;
191
- _this.mixToTile = options.mixToTile || _this.mixToTile;
192
- _this.mixToNormal = options.mixToNormal || _this.mixToNormal;
181
+ this.mixToTile = options.mixToTile || this.mixToTile;
182
+ this.mixToNormal = options.mixToNormal || this.mixToNormal;
193
183
  }
194
184
  }
195
- _this._asciiArtFontTexture = new AsciiArtFontTexture(name, font, characterSet, camera.getScene());
196
- var textureSize = _this._asciiArtFontTexture.getSize();
197
- _this.onApply = function (effect) {
198
- effect.setTexture("asciiArtFont", _this._asciiArtFontTexture);
199
- effect.setFloat4("asciiArtFontInfos", _this._asciiArtFontTexture.charSize, characterSet.length, textureSize.width, textureSize.height);
200
- effect.setFloat4("asciiArtOptions", _this.width, _this.height, _this.mixToNormal, _this.mixToTile);
185
+ this._asciiArtFontTexture = new AsciiArtFontTexture(name, font, characterSet, camera.getScene());
186
+ const textureSize = this._asciiArtFontTexture.getSize();
187
+ this.onApply = (effect) => {
188
+ effect.setTexture("asciiArtFont", this._asciiArtFontTexture);
189
+ effect.setFloat4("asciiArtFontInfos", this._asciiArtFontTexture.charSize, characterSet.length, textureSize.width, textureSize.height);
190
+ effect.setFloat4("asciiArtOptions", this.width, this.height, this.mixToNormal, this.mixToTile);
201
191
  };
202
- return _this;
203
192
  }
204
- return AsciiArtPostProcess;
205
- }(PostProcess));
206
- export { AsciiArtPostProcess };
193
+ }
207
194
  //# sourceMappingURL=asciiArtPostProcess.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"asciiArtPostProcess.js","sourceRoot":"","sources":["../../../../../lts/postProcesses/generated/asciiArt/asciiArtPostProcess.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,2CAA6B;AAEtE,OAAO,EAAE,WAAW,EAAE,0DAA4C;AAClE,OAAO,EAAE,OAAO,EAAE,sDAAwC;AAE1D,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAE7D,qEAAuD;AACvD,OAAO,qBAAqB,CAAC;AAE7B;;;;;GAKG;AACH;IAAy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AE,KAAI,CAAC,KAAK,EAAE,KAAI,CAAC,MAAM,EAAE,KAAI,CAAC,WAAW,EAAE,KAAI,CAAC,SAAS,CAAC,CAAC;QACnG,CAAC,CAAC;;IACN,CAAC;IACL,0BAAC;AAAD,CAAC,AApED,CAAyC,WAAW,GAoEnD","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { serialize, SerializationHelper } from \"core/Misc/decorators\";\r\nimport type { Camera } from \"core/Cameras/camera\";\r\nimport { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport type { Effect } from \"core/Materials/effect\";\r\nimport { PostProcess } from \"core/PostProcesses/postProcess\";\r\nimport type { Scene } from \"core/scene\";\r\nimport \"core/Engines/Extensions/engine.dynamicTexture\";\r\nimport \"./asciiart.fragment\";\r\n\r\n/**\r\n * AsciiArtFontTexture is the helper class used to easily create your ascii art font texture.\r\n *\r\n * It basically takes care rendering the font front the given font size to a texture.\r\n * This is used later on in the postprocess.\r\n */\r\nexport class AsciiArtFontTexture extends BaseTexture {\r\n @serialize(\"font\")\r\n private _font: string;\r\n\r\n @serialize(\"text\")\r\n private _text: string;\r\n\r\n private _charSize: number;\r\n\r\n /**\r\n * Gets the size of one char in the texture (each char fits in size * size space in the texture).\r\n */\r\n public get charSize(): number {\r\n return this._charSize;\r\n }\r\n\r\n /**\r\n * Create a new instance of the Ascii Art FontTexture class\r\n * @param name the name of the texture\r\n * @param font the font to use, use the W3C CSS notation\r\n * @param text the caracter set to use in the rendering.\r\n * @param scene the scene that owns the texture\r\n */\r\n constructor(name: string, font: string, text: string, scene: Nullable<Scene> = null) {\r\n super(scene);\r\n\r\n scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n this.name = name;\r\n this._text == text;\r\n this._font == font;\r\n\r\n this.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n this.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n //this.anisotropicFilteringLevel = 1;\r\n\r\n // Get the font specific info.\r\n const maxCharHeight = this._getFontHeight(font);\r\n const maxCharWidth = this._getFontWidth(font);\r\n\r\n this._charSize = Math.max(maxCharHeight.height, maxCharWidth);\r\n\r\n // This is an approximate size, but should always be able to fit at least the maxCharCount.\r\n const textureWidth = Math.ceil(this._charSize * text.length);\r\n const textureHeight = this._charSize;\r\n\r\n // Create the texture that will store the font characters.\r\n this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);\r\n //scene.getEngine().setclamp\r\n const textureSize = this.getSize();\r\n\r\n // Create a canvas with the final size: the one matching the texture.\r\n const canvas = document.createElement(\"canvas\");\r\n canvas.width = textureSize.width;\r\n canvas.height = textureSize.height;\r\n const context = <CanvasRenderingContext2D>canvas.getContext(\"2d\");\r\n context.textBaseline = \"top\";\r\n context.font = font;\r\n context.fillStyle = \"white\";\r\n context.imageSmoothingEnabled = false;\r\n\r\n // Sets the text in the texture.\r\n for (let i = 0; i < text.length; i++) {\r\n context.fillText(text[i], i * this._charSize, -maxCharHeight.offset);\r\n }\r\n\r\n // Flush the text in the dynamic texture.\r\n\r\n scene.getEngine().updateDynamicTexture(this._texture, canvas, false, true);\r\n }\r\n\r\n /**\r\n * Gets the max char width of a font.\r\n * @param font the font to use, use the W3C CSS notation\r\n * @return the max char width\r\n */\r\n private _getFontWidth(font: string): number {\r\n const fontDraw = document.createElement(\"canvas\");\r\n const ctx = <CanvasRenderingContext2D>fontDraw.getContext(\"2d\");\r\n ctx.fillStyle = \"white\";\r\n ctx.font = font;\r\n\r\n return ctx.measureText(\"W\").width;\r\n }\r\n\r\n // More info here: https://videlais.com/2014/03/16/the-many-and-varied-problems-with-measuring-font-height-for-html5-canvas/\r\n /**\r\n * Gets the max char height of a font.\r\n * @param font the font to use, use the W3C CSS notation\r\n * @return the max char height\r\n */\r\n private _getFontHeight(font: string): { height: number; offset: number } {\r\n const fontDraw = document.createElement(\"canvas\");\r\n const ctx = <CanvasRenderingContext2D>fontDraw.getContext(\"2d\");\r\n ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);\r\n ctx.textBaseline = \"top\";\r\n ctx.fillStyle = \"white\";\r\n ctx.font = font;\r\n ctx.fillText(\"jH|\", 0, 0);\r\n const pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;\r\n let start = -1;\r\n let end = -1;\r\n for (let row = 0; row < fontDraw.height; row++) {\r\n for (let column = 0; column < fontDraw.width; column++) {\r\n const index = (row * fontDraw.width + column) * 4;\r\n if (pixels[index] === 0) {\r\n if (column === fontDraw.width - 1 && start !== -1) {\r\n end = row;\r\n row = fontDraw.height;\r\n break;\r\n }\r\n continue;\r\n } else {\r\n if (start === -1) {\r\n start = row;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n return { height: end - start + 1, offset: start - 1 };\r\n }\r\n\r\n /**\r\n * Clones the current AsciiArtTexture.\r\n * @return the clone of the texture.\r\n */\r\n public clone(): AsciiArtFontTexture {\r\n return new AsciiArtFontTexture(this.name, this._font, this._text, this.getScene());\r\n }\r\n\r\n /**\r\n * Parses a json object representing the texture and returns an instance of it.\r\n * @param source the source JSON representation\r\n * @param scene the scene to create the texture for\r\n * @return the parsed texture\r\n */\r\n public static Parse(source: any, scene: Scene): AsciiArtFontTexture {\r\n const texture = SerializationHelper.Parse(() => new AsciiArtFontTexture(source.name, source.font, source.text, scene), source, scene, null);\r\n\r\n return texture;\r\n }\r\n}\r\n\r\n/**\r\n * Option available in the Ascii Art Post Process.\r\n */\r\nexport interface IAsciiArtPostProcessOptions {\r\n /**\r\n * The font to use following the w3c font definition.\r\n */\r\n font?: string;\r\n\r\n /**\r\n * The character set to use in the postprocess.\r\n */\r\n characterSet?: string;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToTile?: number;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToNormal?: number;\r\n}\r\n\r\n/**\r\n * AsciiArtPostProcess helps rendering everithing in Ascii Art.\r\n *\r\n * Simmply add it to your scene and let the nerd that lives in you have fun.\r\n * Example usage: var pp = new AsciiArtPostProcess(\"myAscii\", \"20px Monospace\", camera);\r\n */\r\nexport class AsciiArtPostProcess extends PostProcess {\r\n /**\r\n * The font texture used to render the char in the post process.\r\n */\r\n private _asciiArtFontTexture: AsciiArtFontTexture;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToTile: number = 0;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToNormal: number = 0;\r\n\r\n /**\r\n * Instantiates a new Ascii Art Post Process.\r\n * @param name the name to give to the postprocess\r\n * @camera the camera to apply the post process to.\r\n * @param camera\r\n * @param options can either be the font name or an option object following the IAsciiArtPostProcessOptions format\r\n */\r\n constructor(name: string, camera: Camera, options?: string | IAsciiArtPostProcessOptions) {\r\n super(\r\n name,\r\n \"asciiart\",\r\n [\"asciiArtFontInfos\", \"asciiArtOptions\"],\r\n [\"asciiArtFont\"],\r\n {\r\n width: camera.getEngine().getRenderWidth(),\r\n height: camera.getEngine().getRenderHeight(),\r\n },\r\n camera,\r\n Texture.TRILINEAR_SAMPLINGMODE,\r\n camera.getEngine(),\r\n true\r\n );\r\n\r\n // Default values.\r\n let font = \"40px Monospace\";\r\n let characterSet = \" `-.'_:,\\\"=^;<+!*?/cL\\\\zrs7TivJtC{3F)Il(xZfY5S2eajo14[nuyE]P6V9kXpKwGhqAUbOd8#HRDB0$mgMW&Q%N@\";\r\n\r\n // Use options.\r\n if (options) {\r\n if (typeof options === \"string\") {\r\n font = <string>options;\r\n } else {\r\n font = (<IAsciiArtPostProcessOptions>options).font || font;\r\n characterSet = (<IAsciiArtPostProcessOptions>options).characterSet || characterSet;\r\n this.mixToTile = (<IAsciiArtPostProcessOptions>options).mixToTile || this.mixToTile;\r\n this.mixToNormal = (<IAsciiArtPostProcessOptions>options).mixToNormal || this.mixToNormal;\r\n }\r\n }\r\n\r\n this._asciiArtFontTexture = new AsciiArtFontTexture(name, font, characterSet, camera.getScene());\r\n const textureSize = this._asciiArtFontTexture.getSize();\r\n\r\n this.onApply = (effect: Effect) => {\r\n effect.setTexture(\"asciiArtFont\", this._asciiArtFontTexture);\r\n\r\n effect.setFloat4(\"asciiArtFontInfos\", this._asciiArtFontTexture.charSize, characterSet.length, textureSize.width, textureSize.height);\r\n\r\n effect.setFloat4(\"asciiArtOptions\", this.width, this.height, this.mixToNormal, this.mixToTile);\r\n };\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"asciiArtPostProcess.js","sourceRoot":"","sources":["../../../../../lts/postProcesses/generated/asciiArt/asciiArtPostProcess.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,2CAA6B;AAEtE,OAAO,EAAE,WAAW,EAAE,0DAA4C;AAClE,OAAO,EAAE,OAAO,EAAE,sDAAwC;AAE1D,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAE7D,qEAAuD;AACvD,OAAO,qBAAqB,CAAC;AAE7B;;;;;GAKG;AACH,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAgBhD;;;;;;OAMG;IACH,YAAY,IAAY,EAAE,IAAY,EAAE,IAAY,EAAE,QAAyB,IAAI;QAC/E,KAAK,CAAC,KAAK,CAAC,CAAC;QAEb,KAAK,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;QAExB,IAAI,CAAC,KAAK,EAAE;YACR,OAAO;SACV;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC;QACnB,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC;QAEnB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,iBAAiB,CAAC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,IAAI,YAAY,CAAC;gBACnF,IAAI,CAAC,SAAS,GAAiC,OAAQ,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC;gBACpF,IAAI,CAAC,WAAW,GAAiC,OAAQ,CAAC,WAAW,IAAI,IAAI,CAAC,WAAW,CAAC;aAC7F;SACJ;QAED,IAAI,CAAC,oBAAoB,GAAG,IAAI,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;QACjG,MAAM,WAAW,GAAG,IAAI,CAAC,oBAAoB,CAAC,OAAO,EAAE,CAAC;QAExD,IAAI,CAAC,OAAO,GAAG,CAAC,MAAc,EAAE,EAAE;YAC9B,MAAM,CAAC,UAAU,CAAC,cAAc,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;YAE7D,MAAM,CAAC,SAAS,CAAC,mBAAmB,EAAE,IAAI,CAAC,oBAAoB,CAAC,QAAQ,EAAE,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;YAEtI,MAAM,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACnG,CAAC,CAAC;IACN,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { serialize, SerializationHelper } from \"core/Misc/decorators\";\r\nimport type { Camera } from \"core/Cameras/camera\";\r\nimport { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport type { Effect } from \"core/Materials/effect\";\r\nimport { PostProcess } from \"core/PostProcesses/postProcess\";\r\nimport type { Scene } from \"core/scene\";\r\nimport \"core/Engines/Extensions/engine.dynamicTexture\";\r\nimport \"./asciiart.fragment\";\r\n\r\n/**\r\n * AsciiArtFontTexture is the helper class used to easily create your ascii art font texture.\r\n *\r\n * It basically takes care rendering the font front the given font size to a texture.\r\n * This is used later on in the postprocess.\r\n */\r\nexport class AsciiArtFontTexture extends BaseTexture {\r\n @serialize(\"font\")\r\n private _font: string;\r\n\r\n @serialize(\"text\")\r\n private _text: string;\r\n\r\n private _charSize: number;\r\n\r\n /**\r\n * Gets the size of one char in the texture (each char fits in size * size space in the texture).\r\n */\r\n public get charSize(): number {\r\n return this._charSize;\r\n }\r\n\r\n /**\r\n * Create a new instance of the Ascii Art FontTexture class\r\n * @param name the name of the texture\r\n * @param font the font to use, use the W3C CSS notation\r\n * @param text the caracter set to use in the rendering.\r\n * @param scene the scene that owns the texture\r\n */\r\n constructor(name: string, font: string, text: string, scene: Nullable<Scene> = null) {\r\n super(scene);\r\n\r\n scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n this.name = name;\r\n this._text == text;\r\n this._font == font;\r\n\r\n this.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n this.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n //this.anisotropicFilteringLevel = 1;\r\n\r\n // Get the font specific info.\r\n const maxCharHeight = this._getFontHeight(font);\r\n const maxCharWidth = this._getFontWidth(font);\r\n\r\n this._charSize = Math.max(maxCharHeight.height, maxCharWidth);\r\n\r\n // This is an approximate size, but should always be able to fit at least the maxCharCount.\r\n const textureWidth = Math.ceil(this._charSize * text.length);\r\n const textureHeight = this._charSize;\r\n\r\n // Create the texture that will store the font characters.\r\n this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);\r\n //scene.getEngine().setclamp\r\n const textureSize = this.getSize();\r\n\r\n // Create a canvas with the final size: the one matching the texture.\r\n const canvas = document.createElement(\"canvas\");\r\n canvas.width = textureSize.width;\r\n canvas.height = textureSize.height;\r\n const context = <CanvasRenderingContext2D>canvas.getContext(\"2d\");\r\n context.textBaseline = \"top\";\r\n context.font = font;\r\n context.fillStyle = \"white\";\r\n context.imageSmoothingEnabled = false;\r\n\r\n // Sets the text in the texture.\r\n for (let i = 0; i < text.length; i++) {\r\n context.fillText(text[i], i * this._charSize, -maxCharHeight.offset);\r\n }\r\n\r\n // Flush the text in the dynamic texture.\r\n\r\n scene.getEngine().updateDynamicTexture(this._texture, canvas, false, true);\r\n }\r\n\r\n /**\r\n * Gets the max char width of a font.\r\n * @param font the font to use, use the W3C CSS notation\r\n * @return the max char width\r\n */\r\n private _getFontWidth(font: string): number {\r\n const fontDraw = document.createElement(\"canvas\");\r\n const ctx = <CanvasRenderingContext2D>fontDraw.getContext(\"2d\");\r\n ctx.fillStyle = \"white\";\r\n ctx.font = font;\r\n\r\n return ctx.measureText(\"W\").width;\r\n }\r\n\r\n // More info here: https://videlais.com/2014/03/16/the-many-and-varied-problems-with-measuring-font-height-for-html5-canvas/\r\n /**\r\n * Gets the max char height of a font.\r\n * @param font the font to use, use the W3C CSS notation\r\n * @return the max char height\r\n */\r\n private _getFontHeight(font: string): { height: number; offset: number } {\r\n const fontDraw = document.createElement(\"canvas\");\r\n const ctx = <CanvasRenderingContext2D>fontDraw.getContext(\"2d\");\r\n ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);\r\n ctx.textBaseline = \"top\";\r\n ctx.fillStyle = \"white\";\r\n ctx.font = font;\r\n ctx.fillText(\"jH|\", 0, 0);\r\n const pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;\r\n let start = -1;\r\n let end = -1;\r\n for (let row = 0; row < fontDraw.height; row++) {\r\n for (let column = 0; column < fontDraw.width; column++) {\r\n const index = (row * fontDraw.width + column) * 4;\r\n if (pixels[index] === 0) {\r\n if (column === fontDraw.width - 1 && start !== -1) {\r\n end = row;\r\n row = fontDraw.height;\r\n break;\r\n }\r\n continue;\r\n } else {\r\n if (start === -1) {\r\n start = row;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n return { height: end - start + 1, offset: start - 1 };\r\n }\r\n\r\n /**\r\n * Clones the current AsciiArtTexture.\r\n * @return the clone of the texture.\r\n */\r\n public clone(): AsciiArtFontTexture {\r\n return new AsciiArtFontTexture(this.name, this._font, this._text, this.getScene());\r\n }\r\n\r\n /**\r\n * Parses a json object representing the texture and returns an instance of it.\r\n * @param source the source JSON representation\r\n * @param scene the scene to create the texture for\r\n * @return the parsed texture\r\n */\r\n public static Parse(source: any, scene: Scene): AsciiArtFontTexture {\r\n const texture = SerializationHelper.Parse(() => new AsciiArtFontTexture(source.name, source.font, source.text, scene), source, scene, null);\r\n\r\n return texture;\r\n }\r\n}\r\n\r\n/**\r\n * Option available in the Ascii Art Post Process.\r\n */\r\nexport interface IAsciiArtPostProcessOptions {\r\n /**\r\n * The font to use following the w3c font definition.\r\n */\r\n font?: string;\r\n\r\n /**\r\n * The character set to use in the postprocess.\r\n */\r\n characterSet?: string;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToTile?: number;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToNormal?: number;\r\n}\r\n\r\n/**\r\n * AsciiArtPostProcess helps rendering everithing in Ascii Art.\r\n *\r\n * Simmply add it to your scene and let the nerd that lives in you have fun.\r\n * Example usage: var pp = new AsciiArtPostProcess(\"myAscii\", \"20px Monospace\", camera);\r\n */\r\nexport class AsciiArtPostProcess extends PostProcess {\r\n /**\r\n * The font texture used to render the char in the post process.\r\n */\r\n private _asciiArtFontTexture: AsciiArtFontTexture;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToTile: number = 0;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToNormal: number = 0;\r\n\r\n /**\r\n * Instantiates a new Ascii Art Post Process.\r\n * @param name the name to give to the postprocess\r\n * @camera the camera to apply the post process to.\r\n * @param camera\r\n * @param options can either be the font name or an option object following the IAsciiArtPostProcessOptions format\r\n */\r\n constructor(name: string, camera: Camera, options?: string | IAsciiArtPostProcessOptions) {\r\n super(\r\n name,\r\n \"asciiart\",\r\n [\"asciiArtFontInfos\", \"asciiArtOptions\"],\r\n [\"asciiArtFont\"],\r\n {\r\n width: camera.getEngine().getRenderWidth(),\r\n height: camera.getEngine().getRenderHeight(),\r\n },\r\n camera,\r\n Texture.TRILINEAR_SAMPLINGMODE,\r\n camera.getEngine(),\r\n true\r\n );\r\n\r\n // Default values.\r\n let font = \"40px Monospace\";\r\n let characterSet = \" `-.'_:,\\\"=^;<+!*?/cL\\\\zrs7TivJtC{3F)Il(xZfY5S2eajo14[nuyE]P6V9kXpKwGhqAUbOd8#HRDB0$mgMW&Q%N@\";\r\n\r\n // Use options.\r\n if (options) {\r\n if (typeof options === \"string\") {\r\n font = <string>options;\r\n } else {\r\n font = (<IAsciiArtPostProcessOptions>options).font || font;\r\n characterSet = (<IAsciiArtPostProcessOptions>options).characterSet || characterSet;\r\n this.mixToTile = (<IAsciiArtPostProcessOptions>options).mixToTile || this.mixToTile;\r\n this.mixToNormal = (<IAsciiArtPostProcessOptions>options).mixToNormal || this.mixToNormal;\r\n }\r\n }\r\n\r\n this._asciiArtFontTexture = new AsciiArtFontTexture(name, font, characterSet, camera.getScene());\r\n const textureSize = this._asciiArtFontTexture.getSize();\r\n\r\n this.onApply = (effect: Effect) => {\r\n effect.setTexture(\"asciiArtFont\", this._asciiArtFontTexture);\r\n\r\n effect.setFloat4(\"asciiArtFontInfos\", this._asciiArtFontTexture.charSize, characterSet.length, textureSize.width, textureSize.height);\r\n\r\n effect.setFloat4(\"asciiArtOptions\", this.width, this.height, this.mixToNormal, this.mixToTile);\r\n };\r\n }\r\n}\r\n"]}
@@ -1,9 +1,13 @@
1
1
  // Do not edit.
2
2
  import { ShaderStore } from "@babylonjs/core/Engines/shaderStore.js";
3
- var name = "asciiartPixelShader";
4
- var shader = "varying vec2 vUV;uniform sampler2D textureSampler;uniform sampler2D asciiArtFont;uniform vec4 asciiArtFontInfos;uniform vec4 asciiArtOptions;float getLuminance(vec3 color)\n{return clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);}\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) \n{float caracterSize=asciiArtFontInfos.x;float numChar=asciiArtFontInfos.y-1.0;float fontx=asciiArtFontInfos.z;float fonty=asciiArtFontInfos.w;float screenx=asciiArtOptions.x;float screeny=asciiArtOptions.y;float tileX=float(floor((gl_FragCoord.x)/caracterSize))*caracterSize/screenx;float tileY=float(floor((gl_FragCoord.y)/caracterSize))*caracterSize/screeny;vec2 tileUV=vec2(tileX,tileY);vec4 tileColor=texture2D(textureSampler,tileUV);vec4 baseColor=texture2D(textureSampler,vUV);float tileLuminance=getLuminance(tileColor.rgb);float offsetx=(float(floor(tileLuminance*numChar)))*caracterSize/fontx;float offsety=0.0;float x=float(mod(gl_FragCoord.x,caracterSize))/fontx;float y=float(mod(gl_FragCoord.y,caracterSize))/fonty;vec4 finalColor= texture2D(asciiArtFont,vec2(offsetx+x,offsety+(caracterSize/fonty-y)));finalColor.rgb*=tileColor.rgb;finalColor.a=1.0;finalColor= mix(finalColor,tileColor,asciiArtOptions.w);finalColor= mix(finalColor,baseColor,asciiArtOptions.z);gl_FragColor=finalColor;}";
3
+ const name = "asciiartPixelShader";
4
+ const shader = `varying vec2 vUV;uniform sampler2D textureSampler;uniform sampler2D asciiArtFont;uniform vec4 asciiArtFontInfos;uniform vec4 asciiArtOptions;float getLuminance(vec3 color)
5
+ {return clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);}
6
+ #define CUSTOM_FRAGMENT_DEFINITIONS
7
+ void main(void)
8
+ {float caracterSize=asciiArtFontInfos.x;float numChar=asciiArtFontInfos.y-1.0;float fontx=asciiArtFontInfos.z;float fonty=asciiArtFontInfos.w;float screenx=asciiArtOptions.x;float screeny=asciiArtOptions.y;float tileX=float(floor((gl_FragCoord.x)/caracterSize))*caracterSize/screenx;float tileY=float(floor((gl_FragCoord.y)/caracterSize))*caracterSize/screeny;vec2 tileUV=vec2(tileX,tileY);vec4 tileColor=texture2D(textureSampler,tileUV);vec4 baseColor=texture2D(textureSampler,vUV);float tileLuminance=getLuminance(tileColor.rgb);float offsetx=(float(floor(tileLuminance*numChar)))*caracterSize/fontx;float offsety=0.0;float x=float(mod(gl_FragCoord.x,caracterSize))/fontx;float y=float(mod(gl_FragCoord.y,caracterSize))/fonty;vec4 finalColor= texture2D(asciiArtFont,vec2(offsetx+x,offsety+(caracterSize/fonty-y)));finalColor.rgb*=tileColor.rgb;finalColor.a=1.0;finalColor= mix(finalColor,tileColor,asciiArtOptions.w);finalColor= mix(finalColor,baseColor,asciiArtOptions.z);gl_FragColor=finalColor;}`;
5
9
  // Sideeffect
6
10
  ShaderStore.ShadersStore[name] = shader;
7
11
  /** @hidden */
8
- export var asciiartPixelShader = { name: name, shader: shader };
12
+ export const asciiartPixelShader = { name, shader };
9
13
  //# sourceMappingURL=asciiart.fragment.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"asciiart.fragment.js","sourceRoot":"","sources":["../../../../../lts/postProcesses/generated/asciiArt/asciiart.fragment.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,+CAAiC;AAEvD,IAAM,IAAI,GAAG,qBAAqB,CAAC;AACnC,IAAM,MAAM,GAAG,4wCAI09B,CAAC;AAC1+B,aAAa;AACb,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AACxC,cAAc;AACd,MAAM,CAAC,IAAM,mBAAmB,GAAG,EAAE,IAAI,MAAA,EAAE,MAAM,QAAA,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"core/Engines/shaderStore\";\n\nconst name = \"asciiartPixelShader\";\nconst shader = `varying vec2 vUV;uniform sampler2D textureSampler;uniform sampler2D asciiArtFont;uniform vec4 asciiArtFontInfos;uniform vec4 asciiArtOptions;float getLuminance(vec3 color)\n{return clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);}\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) \n{float caracterSize=asciiArtFontInfos.x;float numChar=asciiArtFontInfos.y-1.0;float fontx=asciiArtFontInfos.z;float fonty=asciiArtFontInfos.w;float screenx=asciiArtOptions.x;float screeny=asciiArtOptions.y;float tileX=float(floor((gl_FragCoord.x)/caracterSize))*caracterSize/screenx;float tileY=float(floor((gl_FragCoord.y)/caracterSize))*caracterSize/screeny;vec2 tileUV=vec2(tileX,tileY);vec4 tileColor=texture2D(textureSampler,tileUV);vec4 baseColor=texture2D(textureSampler,vUV);float tileLuminance=getLuminance(tileColor.rgb);float offsetx=(float(floor(tileLuminance*numChar)))*caracterSize/fontx;float offsety=0.0;float x=float(mod(gl_FragCoord.x,caracterSize))/fontx;float y=float(mod(gl_FragCoord.y,caracterSize))/fonty;vec4 finalColor= texture2D(asciiArtFont,vec2(offsetx+x,offsety+(caracterSize/fonty-y)));finalColor.rgb*=tileColor.rgb;finalColor.a=1.0;finalColor= mix(finalColor,tileColor,asciiArtOptions.w);finalColor= mix(finalColor,baseColor,asciiArtOptions.z);gl_FragColor=finalColor;}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @hidden */\nexport const asciiartPixelShader = { name, shader };\n"]}
1
+ {"version":3,"file":"asciiart.fragment.js","sourceRoot":"","sources":["../../../../../lts/postProcesses/generated/asciiArt/asciiart.fragment.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,+CAAiC;AAEvD,MAAM,IAAI,GAAG,qBAAqB,CAAC;AACnC,MAAM,MAAM,GAAG;;;;y+BAI09B,CAAC;AAC1+B,aAAa;AACb,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AACxC,cAAc;AACd,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"core/Engines/shaderStore\";\n\nconst name = \"asciiartPixelShader\";\nconst shader = `varying vec2 vUV;uniform sampler2D textureSampler;uniform sampler2D asciiArtFont;uniform vec4 asciiArtFontInfos;uniform vec4 asciiArtOptions;float getLuminance(vec3 color)\n{return clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);}\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) \n{float caracterSize=asciiArtFontInfos.x;float numChar=asciiArtFontInfos.y-1.0;float fontx=asciiArtFontInfos.z;float fonty=asciiArtFontInfos.w;float screenx=asciiArtOptions.x;float screeny=asciiArtOptions.y;float tileX=float(floor((gl_FragCoord.x)/caracterSize))*caracterSize/screenx;float tileY=float(floor((gl_FragCoord.y)/caracterSize))*caracterSize/screeny;vec2 tileUV=vec2(tileX,tileY);vec4 tileColor=texture2D(textureSampler,tileUV);vec4 baseColor=texture2D(textureSampler,vUV);float tileLuminance=getLuminance(tileColor.rgb);float offsetx=(float(floor(tileLuminance*numChar)))*caracterSize/fontx;float offsety=0.0;float x=float(mod(gl_FragCoord.x,caracterSize))/fontx;float y=float(mod(gl_FragCoord.y,caracterSize))/fonty;vec4 finalColor= texture2D(asciiArtFont,vec2(offsetx+x,offsety+(caracterSize/fonty-y)));finalColor.rgb*=tileColor.rgb;finalColor.a=1.0;finalColor= mix(finalColor,tileColor,asciiArtOptions.w);finalColor= mix(finalColor,baseColor,asciiArtOptions.z);gl_FragColor=finalColor;}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @hidden */\nexport const asciiartPixelShader = { name, shader };\n"]}
@@ -1,4 +1,4 @@
1
- import { __decorate, __extends } from "tslib";
1
+ import { __decorate } from "@babylonjs/core/tslib.es6.js";
2
2
  import { serialize, SerializationHelper } from "@babylonjs/core/Misc/decorators.js";
3
3
  import { Matrix } from "@babylonjs/core/Maths/math.vector.js";
4
4
  import { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
@@ -12,8 +12,7 @@ import "./digitalrain.fragment.js";
12
12
  * It basically takes care rendering the font front the given font size to a texture.
13
13
  * This is used later on in the postprocess.
14
14
  */
15
- var DigitalRainFontTexture = /** @class */ (function (_super) {
16
- __extends(DigitalRainFontTexture, _super);
15
+ export class DigitalRainFontTexture extends BaseTexture {
17
16
  /**
18
17
  * Create a new instance of the Digital Rain FontTexture class
19
18
  * @param name the name of the texture
@@ -21,88 +20,82 @@ var DigitalRainFontTexture = /** @class */ (function (_super) {
21
20
  * @param text the caracter set to use in the rendering.
22
21
  * @param scene the scene that owns the texture
23
22
  */
24
- function DigitalRainFontTexture(name, font, text, scene) {
25
- if (scene === void 0) { scene = null; }
26
- var _this = _super.call(this, scene) || this;
27
- scene = _this.getScene();
23
+ constructor(name, font, text, scene = null) {
24
+ super(scene);
25
+ scene = this.getScene();
28
26
  if (!scene) {
29
- return _this;
27
+ return;
30
28
  }
31
- _this.name = name;
32
- _this._text == text;
33
- _this._font == font;
34
- _this.wrapU = Texture.CLAMP_ADDRESSMODE;
35
- _this.wrapV = Texture.CLAMP_ADDRESSMODE;
29
+ this.name = name;
30
+ this._text == text;
31
+ this._font == font;
32
+ this.wrapU = Texture.CLAMP_ADDRESSMODE;
33
+ this.wrapV = Texture.CLAMP_ADDRESSMODE;
36
34
  // Get the font specific info.
37
- var maxCharHeight = _this._getFontHeight(font);
38
- var maxCharWidth = _this._getFontWidth(font);
39
- _this._charSize = Math.max(maxCharHeight.height, maxCharWidth);
35
+ const maxCharHeight = this._getFontHeight(font);
36
+ const maxCharWidth = this._getFontWidth(font);
37
+ this._charSize = Math.max(maxCharHeight.height, maxCharWidth);
40
38
  // This is an approximate size, but should always be able to fit at least the maxCharCount.
41
- var textureWidth = _this._charSize;
42
- var textureHeight = Math.ceil(_this._charSize * text.length);
39
+ const textureWidth = this._charSize;
40
+ const textureHeight = Math.ceil(this._charSize * text.length);
43
41
  // Create the texture that will store the font characters.
44
- _this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);
42
+ this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);
45
43
  //scene.getEngine().setclamp
46
- var textureSize = _this.getSize();
44
+ const textureSize = this.getSize();
47
45
  // Create a canvas with the final size: the one matching the texture.
48
- var canvas = document.createElement("canvas");
46
+ const canvas = document.createElement("canvas");
49
47
  canvas.width = textureSize.width;
50
48
  canvas.height = textureSize.height;
51
- var context = canvas.getContext("2d");
49
+ const context = canvas.getContext("2d");
52
50
  context.textBaseline = "top";
53
51
  context.font = font;
54
52
  context.fillStyle = "white";
55
53
  context.imageSmoothingEnabled = false;
56
54
  // Sets the text in the texture.
57
- for (var i = 0; i < text.length; i++) {
58
- context.fillText(text[i], 0, i * _this._charSize - maxCharHeight.offset);
55
+ for (let i = 0; i < text.length; i++) {
56
+ context.fillText(text[i], 0, i * this._charSize - maxCharHeight.offset);
59
57
  }
60
58
  // Flush the text in the dynamic texture.
61
- scene.getEngine().updateDynamicTexture(_this._texture, canvas, false, true);
62
- return _this;
59
+ scene.getEngine().updateDynamicTexture(this._texture, canvas, false, true);
60
+ }
61
+ /**
62
+ * Gets the size of one char in the texture (each char fits in size * size space in the texture).
63
+ */
64
+ get charSize() {
65
+ return this._charSize;
63
66
  }
64
- Object.defineProperty(DigitalRainFontTexture.prototype, "charSize", {
65
- /**
66
- * Gets the size of one char in the texture (each char fits in size * size space in the texture).
67
- */
68
- get: function () {
69
- return this._charSize;
70
- },
71
- enumerable: false,
72
- configurable: true
73
- });
74
67
  /**
75
68
  * Gets the max char width of a font.
76
69
  * @param font the font to use, use the W3C CSS notation
77
70
  * @return the max char width
78
71
  */
79
- DigitalRainFontTexture.prototype._getFontWidth = function (font) {
80
- var fontDraw = document.createElement("canvas");
81
- var ctx = fontDraw.getContext("2d");
72
+ _getFontWidth(font) {
73
+ const fontDraw = document.createElement("canvas");
74
+ const ctx = fontDraw.getContext("2d");
82
75
  ctx.fillStyle = "white";
83
76
  ctx.font = font;
84
77
  return ctx.measureText("W").width;
85
- };
78
+ }
86
79
  // More info here: https://videlais.com/2014/03/16/the-many-and-varied-problems-with-measuring-font-height-for-html5-canvas/
87
80
  /**
88
81
  * Gets the max char height of a font.
89
82
  * @param font the font to use, use the W3C CSS notation
90
83
  * @return the max char height
91
84
  */
92
- DigitalRainFontTexture.prototype._getFontHeight = function (font) {
93
- var fontDraw = document.createElement("canvas");
94
- var ctx = fontDraw.getContext("2d");
85
+ _getFontHeight(font) {
86
+ const fontDraw = document.createElement("canvas");
87
+ const ctx = fontDraw.getContext("2d");
95
88
  ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);
96
89
  ctx.textBaseline = "top";
97
90
  ctx.fillStyle = "white";
98
91
  ctx.font = font;
99
92
  ctx.fillText("jH|", 0, 0);
100
- var pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;
101
- var start = -1;
102
- var end = -1;
103
- for (var row = 0; row < fontDraw.height; row++) {
104
- for (var column = 0; column < fontDraw.width; column++) {
105
- var index = (row * fontDraw.width + column) * 4;
93
+ const pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;
94
+ let start = -1;
95
+ let end = -1;
96
+ for (let row = 0; row < fontDraw.height; row++) {
97
+ for (let column = 0; column < fontDraw.width; column++) {
98
+ const index = (row * fontDraw.width + column) * 4;
106
99
  if (pixels[index] === 0) {
107
100
  if (column === fontDraw.width - 1 && start !== -1) {
108
101
  end = row;
@@ -120,41 +113,38 @@ var DigitalRainFontTexture = /** @class */ (function (_super) {
120
113
  }
121
114
  }
122
115
  return { height: end - start + 1, offset: start - 1 };
123
- };
116
+ }
124
117
  /**
125
118
  * Clones the current DigitalRainFontTexture.
126
119
  * @return the clone of the texture.
127
120
  */
128
- DigitalRainFontTexture.prototype.clone = function () {
121
+ clone() {
129
122
  return new DigitalRainFontTexture(this.name, this._font, this._text, this.getScene());
130
- };
123
+ }
131
124
  /**
132
125
  * Parses a json object representing the texture and returns an instance of it.
133
126
  * @param source the source JSON representation
134
127
  * @param scene the scene to create the texture for
135
128
  * @return the parsed texture
136
129
  */
137
- DigitalRainFontTexture.Parse = function (source, scene) {
138
- var texture = SerializationHelper.Parse(function () { return new DigitalRainFontTexture(source.name, source.font, source.text, scene); }, source, scene, null);
130
+ static Parse(source, scene) {
131
+ const texture = SerializationHelper.Parse(() => new DigitalRainFontTexture(source.name, source.font, source.text, scene), source, scene, null);
139
132
  return texture;
140
- };
141
- __decorate([
142
- serialize("font")
143
- ], DigitalRainFontTexture.prototype, "_font", void 0);
144
- __decorate([
145
- serialize("text")
146
- ], DigitalRainFontTexture.prototype, "_text", void 0);
147
- return DigitalRainFontTexture;
148
- }(BaseTexture));
149
- export { DigitalRainFontTexture };
133
+ }
134
+ }
135
+ __decorate([
136
+ serialize("font")
137
+ ], DigitalRainFontTexture.prototype, "_font", void 0);
138
+ __decorate([
139
+ serialize("text")
140
+ ], DigitalRainFontTexture.prototype, "_text", void 0);
150
141
  /**
151
142
  * DigitalRainPostProcess helps rendering everithing in digital rain.
152
143
  *
153
144
  * Simmply add it to your scene and let the nerd that lives in you have fun.
154
145
  * Example usage: var pp = new DigitalRainPostProcess("digitalRain", "20px Monospace", camera);
155
146
  */
156
- var DigitalRainPostProcess = /** @class */ (function (_super) {
157
- __extends(DigitalRainPostProcess, _super);
147
+ export class DigitalRainPostProcess extends PostProcess {
158
148
  /**
159
149
  * Instantiates a new Digital Rain Post Process.
160
150
  * @param name the name to give to the postprocess
@@ -162,28 +152,28 @@ var DigitalRainPostProcess = /** @class */ (function (_super) {
162
152
  * @param camera
163
153
  * @param options can either be the font name or an option object following the IDigitalRainPostProcessOptions format
164
154
  */
165
- function DigitalRainPostProcess(name, camera, options) {
166
- var _this = _super.call(this, name, "digitalrain", ["digitalRainFontInfos", "digitalRainOptions", "cosTimeZeroOne", "matrixSpeed"], ["digitalRainFont"], {
155
+ constructor(name, camera, options) {
156
+ super(name, "digitalrain", ["digitalRainFontInfos", "digitalRainOptions", "cosTimeZeroOne", "matrixSpeed"], ["digitalRainFont"], {
167
157
  width: camera.getEngine().getRenderWidth(),
168
158
  height: camera.getEngine().getRenderHeight(),
169
- }, camera, Texture.TRILINEAR_SAMPLINGMODE, camera.getEngine(), true) || this;
159
+ }, camera, Texture.TRILINEAR_SAMPLINGMODE, camera.getEngine(), true);
170
160
  /**
171
161
  * This defines the amount you want to mix the "tile" or caracter space colored in the digital rain.
172
162
  * This number is defined between 0 and 1;
173
163
  */
174
- _this.mixToTile = 0;
164
+ this.mixToTile = 0;
175
165
  /**
176
166
  * This defines the amount you want to mix the normal rendering pass in the digital rain.
177
167
  * This number is defined between 0 and 1;
178
168
  */
179
- _this.mixToNormal = 0;
169
+ this.mixToNormal = 0;
180
170
  /**
181
171
  * Speed of the effect
182
172
  */
183
- _this.speed = 0.003;
173
+ this.speed = 0.003;
184
174
  // Default values.
185
- var font = "15px Monospace";
186
- var characterSet = "古池や蛙飛び込む水の音ふるいけやかわずとびこむみずのおと初しぐれ猿も小蓑をほしげ也はつしぐれさるもこみのをほしげなり江戸の雨何石呑んだ時鳥えどのあめなんごくのんだほととぎす";
175
+ let font = "15px Monospace";
176
+ const characterSet = "古池や蛙飛び込む水の音ふるいけやかわずとびこむみずのおと初しぐれ猿も小蓑をほしげ也はつしぐれさるもこみのをほしげなり江戸の雨何石呑んだ時鳥えどのあめなんごくのんだほととぎす";
187
177
  // Use options.
188
178
  if (options) {
189
179
  if (typeof options === "string") {
@@ -191,27 +181,24 @@ var DigitalRainPostProcess = /** @class */ (function (_super) {
191
181
  }
192
182
  else {
193
183
  font = options.font || font;
194
- _this.mixToTile = options.mixToTile || _this.mixToTile;
195
- _this.mixToNormal = options.mixToNormal || _this.mixToNormal;
184
+ this.mixToTile = options.mixToTile || this.mixToTile;
185
+ this.mixToNormal = options.mixToNormal || this.mixToNormal;
196
186
  }
197
187
  }
198
- _this._digitalRainFontTexture = new DigitalRainFontTexture(name, font, characterSet, camera.getScene());
199
- var textureSize = _this._digitalRainFontTexture.getSize();
200
- var alpha = 0.0;
201
- var cosTimeZeroOne = 0.0;
202
- var matrix = Matrix.FromValues(Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random());
203
- _this.onApply = function (effect) {
204
- effect.setTexture("digitalRainFont", _this._digitalRainFontTexture);
205
- effect.setFloat4("digitalRainFontInfos", _this._digitalRainFontTexture.charSize, characterSet.length, textureSize.width, textureSize.height);
206
- effect.setFloat4("digitalRainOptions", _this.width, _this.height, _this.mixToNormal, _this.mixToTile);
188
+ this._digitalRainFontTexture = new DigitalRainFontTexture(name, font, characterSet, camera.getScene());
189
+ const textureSize = this._digitalRainFontTexture.getSize();
190
+ let alpha = 0.0;
191
+ let cosTimeZeroOne = 0.0;
192
+ const matrix = Matrix.FromValues(Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random(), Math.random());
193
+ this.onApply = (effect) => {
194
+ effect.setTexture("digitalRainFont", this._digitalRainFontTexture);
195
+ effect.setFloat4("digitalRainFontInfos", this._digitalRainFontTexture.charSize, characterSet.length, textureSize.width, textureSize.height);
196
+ effect.setFloat4("digitalRainOptions", this.width, this.height, this.mixToNormal, this.mixToTile);
207
197
  effect.setMatrix("matrixSpeed", matrix);
208
- alpha += _this.speed;
198
+ alpha += this.speed;
209
199
  cosTimeZeroOne = alpha;
210
200
  effect.setFloat("cosTimeZeroOne", cosTimeZeroOne);
211
201
  };
212
- return _this;
213
202
  }
214
- return DigitalRainPostProcess;
215
- }(PostProcess));
216
- export { DigitalRainPostProcess };
203
+ }
217
204
  //# sourceMappingURL=digitalRainPostProcess.js.map
@@ -1 +1 @@
1
- {"version":3,"file":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AQ,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;QACtD,CAAC,CAAC;;IACN,CAAC;IACL,6BAAC;AAAD,CAAC,AApGD,CAA4C,WAAW,GAoGtD","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { serialize, SerializationHelper } from \"core/Misc/decorators\";\r\nimport { Matrix } from \"core/Maths/math.vector\";\r\nimport type { Camera } from \"core/Cameras/camera\";\r\nimport { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport type { Effect } from \"core/Materials/effect\";\r\nimport { PostProcess } from \"core/PostProcesses/postProcess\";\r\nimport type { Scene } from \"core/scene\";\r\nimport \"core/Engines/Extensions/engine.dynamicTexture\";\r\nimport \"./digitalrain.fragment\";\r\n\r\n/**\r\n * DigitalRainFontTexture is the helper class used to easily create your digital rain font texture.\r\n *\r\n * It basically takes care rendering the font front the given font size to a texture.\r\n * This is used later on in the postprocess.\r\n */\r\nexport class DigitalRainFontTexture extends BaseTexture {\r\n @serialize(\"font\")\r\n private _font: string;\r\n\r\n @serialize(\"text\")\r\n private _text: string;\r\n\r\n private _charSize: number;\r\n\r\n /**\r\n * Gets the size of one char in the texture (each char fits in size * size space in the texture).\r\n */\r\n public get charSize(): number {\r\n return this._charSize;\r\n }\r\n\r\n /**\r\n * Create a new instance of the Digital Rain FontTexture class\r\n * @param name the name of the texture\r\n * @param font the font to use, use the W3C CSS notation\r\n * @param text the caracter set to use in the rendering.\r\n * @param scene the scene that owns the texture\r\n */\r\n constructor(name: string, font: string, text: string, scene: Nullable<Scene> = null) {\r\n super(scene);\r\n\r\n scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n this.name = name;\r\n this._text == text;\r\n this._font == font;\r\n\r\n this.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n this.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n\r\n // Get the font specific info.\r\n const maxCharHeight = this._getFontHeight(font);\r\n const maxCharWidth = this._getFontWidth(font);\r\n\r\n this._charSize = Math.max(maxCharHeight.height, maxCharWidth);\r\n\r\n // This is an approximate size, but should always be able to fit at least the maxCharCount.\r\n const textureWidth = this._charSize;\r\n const textureHeight = Math.ceil(this._charSize * text.length);\r\n\r\n // Create the texture that will store the font characters.\r\n this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);\r\n //scene.getEngine().setclamp\r\n const textureSize = this.getSize();\r\n\r\n // Create a canvas with the final size: the one matching the texture.\r\n const canvas = document.createElement(\"canvas\");\r\n canvas.width = textureSize.width;\r\n canvas.height = textureSize.height;\r\n const context = <CanvasRenderingContext2D>canvas.getContext(\"2d\");\r\n context.textBaseline = \"top\";\r\n context.font = font;\r\n context.fillStyle = \"white\";\r\n context.imageSmoothingEnabled = false;\r\n\r\n // Sets the text in the texture.\r\n for (let i = 0; i < text.length; i++) {\r\n context.fillText(text[i], 0, i * this._charSize - maxCharHeight.offset);\r\n }\r\n\r\n // Flush the text in the dynamic texture.\r\n scene.getEngine().updateDynamicTexture(this._texture, canvas, false, true);\r\n }\r\n\r\n /**\r\n * Gets the max char width of a font.\r\n * @param font the font to use, use the W3C CSS notation\r\n * @return the max char width\r\n */\r\n private _getFontWidth(font: string): number {\r\n const fontDraw = document.createElement(\"canvas\");\r\n const ctx = <CanvasRenderingContext2D>fontDraw.getContext(\"2d\");\r\n ctx.fillStyle = \"white\";\r\n ctx.font = font;\r\n\r\n return ctx.measureText(\"W\").width;\r\n }\r\n\r\n // More info here: https://videlais.com/2014/03/16/the-many-and-varied-problems-with-measuring-font-height-for-html5-canvas/\r\n /**\r\n * Gets the max char height of a font.\r\n * @param font the font to use, use the W3C CSS notation\r\n * @return the max char height\r\n */\r\n private _getFontHeight(font: string): { height: number; offset: number } {\r\n const fontDraw = document.createElement(\"canvas\");\r\n const ctx = <CanvasRenderingContext2D>fontDraw.getContext(\"2d\");\r\n ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);\r\n ctx.textBaseline = \"top\";\r\n ctx.fillStyle = \"white\";\r\n ctx.font = font;\r\n ctx.fillText(\"jH|\", 0, 0);\r\n const pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;\r\n let start = -1;\r\n let end = -1;\r\n for (let row = 0; row < fontDraw.height; row++) {\r\n for (let column = 0; column < fontDraw.width; column++) {\r\n const index = (row * fontDraw.width + column) * 4;\r\n if (pixels[index] === 0) {\r\n if (column === fontDraw.width - 1 && start !== -1) {\r\n end = row;\r\n row = fontDraw.height;\r\n break;\r\n }\r\n continue;\r\n } else {\r\n if (start === -1) {\r\n start = row;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n return { height: end - start + 1, offset: start - 1 };\r\n }\r\n\r\n /**\r\n * Clones the current DigitalRainFontTexture.\r\n * @return the clone of the texture.\r\n */\r\n public clone(): DigitalRainFontTexture {\r\n return new DigitalRainFontTexture(this.name, this._font, this._text, this.getScene());\r\n }\r\n\r\n /**\r\n * Parses a json object representing the texture and returns an instance of it.\r\n * @param source the source JSON representation\r\n * @param scene the scene to create the texture for\r\n * @return the parsed texture\r\n */\r\n public static Parse(source: any, scene: Scene): DigitalRainFontTexture {\r\n const texture = SerializationHelper.Parse(() => new DigitalRainFontTexture(source.name, source.font, source.text, scene), source, scene, null);\r\n\r\n return texture;\r\n }\r\n}\r\n\r\n/**\r\n * Option available in the Digital Rain Post Process.\r\n */\r\nexport interface IDigitalRainPostProcessOptions {\r\n /**\r\n * The font to use following the w3c font definition.\r\n */\r\n font?: string;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the digital rain.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToTile?: number;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the digital rain.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToNormal?: number;\r\n}\r\n\r\n/**\r\n * DigitalRainPostProcess helps rendering everithing in digital rain.\r\n *\r\n * Simmply add it to your scene and let the nerd that lives in you have fun.\r\n * Example usage: var pp = new DigitalRainPostProcess(\"digitalRain\", \"20px Monospace\", camera);\r\n */\r\nexport class DigitalRainPostProcess extends PostProcess {\r\n /**\r\n * The font texture used to render the char in the post process.\r\n */\r\n private _digitalRainFontTexture: DigitalRainFontTexture;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the digital rain.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToTile: number = 0;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the digital rain.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToNormal: number = 0;\r\n\r\n /**\r\n * Speed of the effect\r\n */\r\n public speed: number = 0.003;\r\n\r\n /**\r\n * Instantiates a new Digital Rain Post Process.\r\n * @param name the name to give to the postprocess\r\n * @camera the camera to apply the post process to.\r\n * @param camera\r\n * @param options can either be the font name or an option object following the IDigitalRainPostProcessOptions format\r\n */\r\n constructor(name: string, camera: Camera, options?: string | IDigitalRainPostProcessOptions) {\r\n super(\r\n name,\r\n \"digitalrain\",\r\n [\"digitalRainFontInfos\", \"digitalRainOptions\", \"cosTimeZeroOne\", \"matrixSpeed\"],\r\n [\"digitalRainFont\"],\r\n {\r\n width: camera.getEngine().getRenderWidth(),\r\n height: camera.getEngine().getRenderHeight(),\r\n },\r\n camera,\r\n Texture.TRILINEAR_SAMPLINGMODE,\r\n camera.getEngine(),\r\n true\r\n );\r\n\r\n // Default values.\r\n let font = \"15px Monospace\";\r\n const characterSet =\r\n \"古池や蛙飛び込む水の音ふるいけやかわずとびこむみずのおと初しぐれ猿も小蓑をほしげ也はつしぐれさるもこみのをほしげなり江戸の雨何石呑んだ時鳥えどのあめなんごくのんだほととぎす\";\r\n\r\n // Use options.\r\n if (options) {\r\n if (typeof options === \"string\") {\r\n font = <string>options;\r\n } else {\r\n font = (<IDigitalRainPostProcessOptions>options).font || font;\r\n this.mixToTile = (<IDigitalRainPostProcessOptions>options).mixToTile || this.mixToTile;\r\n this.mixToNormal = (<IDigitalRainPostProcessOptions>options).mixToNormal || this.mixToNormal;\r\n }\r\n }\r\n\r\n this._digitalRainFontTexture = new DigitalRainFontTexture(name, font, characterSet, camera.getScene());\r\n const textureSize = this._digitalRainFontTexture.getSize();\r\n\r\n let alpha = 0.0;\r\n let cosTimeZeroOne = 0.0;\r\n const matrix = Matrix.FromValues(\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random()\r\n );\r\n\r\n this.onApply = (effect: Effect) => {\r\n effect.setTexture(\"digitalRainFont\", this._digitalRainFontTexture);\r\n\r\n effect.setFloat4(\"digitalRainFontInfos\", this._digitalRainFontTexture.charSize, characterSet.length, textureSize.width, textureSize.height);\r\n\r\n effect.setFloat4(\"digitalRainOptions\", this.width, this.height, this.mixToNormal, this.mixToTile);\r\n\r\n effect.setMatrix(\"matrixSpeed\", matrix);\r\n\r\n alpha += this.speed;\r\n cosTimeZeroOne = alpha;\r\n effect.setFloat(\"cosTimeZeroOne\", cosTimeZeroOne);\r\n };\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"digitalRainPostProcess.js","sourceRoot":"","sources":["../../../../../lts/postProcesses/generated/digitalRain/digitalRainPostProcess.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,2CAA6B;AACtE,OAAO,EAAE,MAAM,EAAE,6CAA+B;AAEhD,OAAO,EAAE,WAAW,EAAE,0DAA4C;AAClE,OAAO,EAAE,OAAO,EAAE,sDAAwC;AAE1D,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAE7D,qEAAuD;AACvD,OAAO,wBAAwB,CAAC;AAEhC;;;;;GAKG;AACH,MAAM,OAAO,sBAAuB,SAAQ,WAAW;IAgBnD;;;;;;OAMG;I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AE,EACb,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,CAChB,CAAC;QAEF,IAAI,CAAC,OAAO,GAAG,CAAC,MAAc,EAAE,EAAE;YAC9B,MAAM,CAAC,UAAU,CAAC,iBAAiB,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC;YAEnE,MAAM,CAAC,SAAS,CAAC,sBAAsB,EAAE,IAAI,CAAC,uBAAuB,CAAC,QAAQ,EAAE,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;YAE5I,MAAM,CAAC,SAAS,CAAC,oBAAoB,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;YAElG,MAAM,CAAC,SAAS,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;YAExC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC;YACpB,cAAc,GAAG,KAAK,CAAC;YACvB,MAAM,CAAC,QAAQ,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;QACtD,CAAC,CAAC;IACN,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { serialize, SerializationHelper } from \"core/Misc/decorators\";\r\nimport { Matrix } from \"core/Maths/math.vector\";\r\nimport type { Camera } from \"core/Cameras/camera\";\r\nimport { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport type { Effect } from \"core/Materials/effect\";\r\nimport { PostProcess } from \"core/PostProcesses/postProcess\";\r\nimport type { Scene } from \"core/scene\";\r\nimport \"core/Engines/Extensions/engine.dynamicTexture\";\r\nimport \"./digitalrain.fragment\";\r\n\r\n/**\r\n * DigitalRainFontTexture is the helper class used to easily create your digital rain font texture.\r\n *\r\n * It basically takes care rendering the font front the given font size to a texture.\r\n * This is used later on in the postprocess.\r\n */\r\nexport class DigitalRainFontTexture extends BaseTexture {\r\n @serialize(\"font\")\r\n private _font: string;\r\n\r\n @serialize(\"text\")\r\n private _text: string;\r\n\r\n private _charSize: number;\r\n\r\n /**\r\n * Gets the size of one char in the texture (each char fits in size * size space in the texture).\r\n */\r\n public get charSize(): number {\r\n return this._charSize;\r\n }\r\n\r\n /**\r\n * Create a new instance of the Digital Rain FontTexture class\r\n * @param name the name of the texture\r\n * @param font the font to use, use the W3C CSS notation\r\n * @param text the caracter set to use in the rendering.\r\n * @param scene the scene that owns the texture\r\n */\r\n constructor(name: string, font: string, text: string, scene: Nullable<Scene> = null) {\r\n super(scene);\r\n\r\n scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n this.name = name;\r\n this._text == text;\r\n this._font == font;\r\n\r\n this.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n this.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n\r\n // Get the font specific info.\r\n const maxCharHeight = this._getFontHeight(font);\r\n const maxCharWidth = this._getFontWidth(font);\r\n\r\n this._charSize = Math.max(maxCharHeight.height, maxCharWidth);\r\n\r\n // This is an approximate size, but should always be able to fit at least the maxCharCount.\r\n const textureWidth = this._charSize;\r\n const textureHeight = Math.ceil(this._charSize * text.length);\r\n\r\n // Create the texture that will store the font characters.\r\n this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);\r\n //scene.getEngine().setclamp\r\n const textureSize = this.getSize();\r\n\r\n // Create a canvas with the final size: the one matching the texture.\r\n const canvas = document.createElement(\"canvas\");\r\n canvas.width = textureSize.width;\r\n canvas.height = textureSize.height;\r\n const context = <CanvasRenderingContext2D>canvas.getContext(\"2d\");\r\n context.textBaseline = \"top\";\r\n context.font = font;\r\n context.fillStyle = \"white\";\r\n context.imageSmoothingEnabled = false;\r\n\r\n // Sets the text in the texture.\r\n for (let i = 0; i < text.length; i++) {\r\n context.fillText(text[i], 0, i * this._charSize - maxCharHeight.offset);\r\n }\r\n\r\n // Flush the text in the dynamic texture.\r\n scene.getEngine().updateDynamicTexture(this._texture, canvas, false, true);\r\n }\r\n\r\n /**\r\n * Gets the max char width of a font.\r\n * @param font the font to use, use the W3C CSS notation\r\n * @return the max char width\r\n */\r\n private _getFontWidth(font: string): number {\r\n const fontDraw = document.createElement(\"canvas\");\r\n const ctx = <CanvasRenderingContext2D>fontDraw.getContext(\"2d\");\r\n ctx.fillStyle = \"white\";\r\n ctx.font = font;\r\n\r\n return ctx.measureText(\"W\").width;\r\n }\r\n\r\n // More info here: https://videlais.com/2014/03/16/the-many-and-varied-problems-with-measuring-font-height-for-html5-canvas/\r\n /**\r\n * Gets the max char height of a font.\r\n * @param font the font to use, use the W3C CSS notation\r\n * @return the max char height\r\n */\r\n private _getFontHeight(font: string): { height: number; offset: number } {\r\n const fontDraw = document.createElement(\"canvas\");\r\n const ctx = <CanvasRenderingContext2D>fontDraw.getContext(\"2d\");\r\n ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);\r\n ctx.textBaseline = \"top\";\r\n ctx.fillStyle = \"white\";\r\n ctx.font = font;\r\n ctx.fillText(\"jH|\", 0, 0);\r\n const pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;\r\n let start = -1;\r\n let end = -1;\r\n for (let row = 0; row < fontDraw.height; row++) {\r\n for (let column = 0; column < fontDraw.width; column++) {\r\n const index = (row * fontDraw.width + column) * 4;\r\n if (pixels[index] === 0) {\r\n if (column === fontDraw.width - 1 && start !== -1) {\r\n end = row;\r\n row = fontDraw.height;\r\n break;\r\n }\r\n continue;\r\n } else {\r\n if (start === -1) {\r\n start = row;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n return { height: end - start + 1, offset: start - 1 };\r\n }\r\n\r\n /**\r\n * Clones the current DigitalRainFontTexture.\r\n * @return the clone of the texture.\r\n */\r\n public clone(): DigitalRainFontTexture {\r\n return new DigitalRainFontTexture(this.name, this._font, this._text, this.getScene());\r\n }\r\n\r\n /**\r\n * Parses a json object representing the texture and returns an instance of it.\r\n * @param source the source JSON representation\r\n * @param scene the scene to create the texture for\r\n * @return the parsed texture\r\n */\r\n public static Parse(source: any, scene: Scene): DigitalRainFontTexture {\r\n const texture = SerializationHelper.Parse(() => new DigitalRainFontTexture(source.name, source.font, source.text, scene), source, scene, null);\r\n\r\n return texture;\r\n }\r\n}\r\n\r\n/**\r\n * Option available in the Digital Rain Post Process.\r\n */\r\nexport interface IDigitalRainPostProcessOptions {\r\n /**\r\n * The font to use following the w3c font definition.\r\n */\r\n font?: string;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the digital rain.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToTile?: number;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the digital rain.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToNormal?: number;\r\n}\r\n\r\n/**\r\n * DigitalRainPostProcess helps rendering everithing in digital rain.\r\n *\r\n * Simmply add it to your scene and let the nerd that lives in you have fun.\r\n * Example usage: var pp = new DigitalRainPostProcess(\"digitalRain\", \"20px Monospace\", camera);\r\n */\r\nexport class DigitalRainPostProcess extends PostProcess {\r\n /**\r\n * The font texture used to render the char in the post process.\r\n */\r\n private _digitalRainFontTexture: DigitalRainFontTexture;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the digital rain.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToTile: number = 0;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the digital rain.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToNormal: number = 0;\r\n\r\n /**\r\n * Speed of the effect\r\n */\r\n public speed: number = 0.003;\r\n\r\n /**\r\n * Instantiates a new Digital Rain Post Process.\r\n * @param name the name to give to the postprocess\r\n * @camera the camera to apply the post process to.\r\n * @param camera\r\n * @param options can either be the font name or an option object following the IDigitalRainPostProcessOptions format\r\n */\r\n constructor(name: string, camera: Camera, options?: string | IDigitalRainPostProcessOptions) {\r\n super(\r\n name,\r\n \"digitalrain\",\r\n [\"digitalRainFontInfos\", \"digitalRainOptions\", \"cosTimeZeroOne\", \"matrixSpeed\"],\r\n [\"digitalRainFont\"],\r\n {\r\n width: camera.getEngine().getRenderWidth(),\r\n height: camera.getEngine().getRenderHeight(),\r\n },\r\n camera,\r\n Texture.TRILINEAR_SAMPLINGMODE,\r\n camera.getEngine(),\r\n true\r\n );\r\n\r\n // Default values.\r\n let font = \"15px Monospace\";\r\n const characterSet =\r\n \"古池や蛙飛び込む水の音ふるいけやかわずとびこむみずのおと初しぐれ猿も小蓑をほしげ也はつしぐれさるもこみのをほしげなり江戸の雨何石呑んだ時鳥えどのあめなんごくのんだほととぎす\";\r\n\r\n // Use options.\r\n if (options) {\r\n if (typeof options === \"string\") {\r\n font = <string>options;\r\n } else {\r\n font = (<IDigitalRainPostProcessOptions>options).font || font;\r\n this.mixToTile = (<IDigitalRainPostProcessOptions>options).mixToTile || this.mixToTile;\r\n this.mixToNormal = (<IDigitalRainPostProcessOptions>options).mixToNormal || this.mixToNormal;\r\n }\r\n }\r\n\r\n this._digitalRainFontTexture = new DigitalRainFontTexture(name, font, characterSet, camera.getScene());\r\n const textureSize = this._digitalRainFontTexture.getSize();\r\n\r\n let alpha = 0.0;\r\n let cosTimeZeroOne = 0.0;\r\n const matrix = Matrix.FromValues(\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random(),\r\n Math.random()\r\n );\r\n\r\n this.onApply = (effect: Effect) => {\r\n effect.setTexture(\"digitalRainFont\", this._digitalRainFontTexture);\r\n\r\n effect.setFloat4(\"digitalRainFontInfos\", this._digitalRainFontTexture.charSize, characterSet.length, textureSize.width, textureSize.height);\r\n\r\n effect.setFloat4(\"digitalRainOptions\", this.width, this.height, this.mixToNormal, this.mixToTile);\r\n\r\n effect.setMatrix(\"matrixSpeed\", matrix);\r\n\r\n alpha += this.speed;\r\n cosTimeZeroOne = alpha;\r\n effect.setFloat(\"cosTimeZeroOne\", cosTimeZeroOne);\r\n };\r\n }\r\n}\r\n"]}
@@ -1,9 +1,14 @@
1
1
  // Do not edit.
2
2
  import { ShaderStore } from "@babylonjs/core/Engines/shaderStore.js";
3
- var name = "digitalrainPixelShader";
4
- var shader = "varying vec2 vUV;uniform sampler2D textureSampler;uniform sampler2D digitalRainFont;uniform vec4 digitalRainFontInfos;uniform vec4 digitalRainOptions;uniform mat4 matrixSpeed;uniform float cosTimeZeroOne;float getLuminance(vec3 color)\n{return clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);}\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) \n{float caracterSize=digitalRainFontInfos.x;float numChar=digitalRainFontInfos.y-1.0;float fontx=digitalRainFontInfos.z;float fonty=digitalRainFontInfos.w;float screenx=digitalRainOptions.x;float screeny=digitalRainOptions.y;float ratio=screeny/fonty;float columnx=float(floor((gl_FragCoord.x)/caracterSize));float tileX=float(floor((gl_FragCoord.x)/caracterSize))*caracterSize/screenx;float tileY=float(floor((gl_FragCoord.y)/caracterSize))*caracterSize/screeny;vec2 tileUV=vec2(tileX,tileY);vec4 tileColor=texture2D(textureSampler,tileUV);vec4 baseColor=texture2D(textureSampler,vUV);float tileLuminance=getLuminance(tileColor.rgb);int st=int(mod(columnx,4.0));float speed=cosTimeZeroOne*(sin(tileX*314.5)*0.5+0.6); \nfloat x=float(mod(gl_FragCoord.x,caracterSize))/fontx;float y=float(mod(speed+gl_FragCoord.y/screeny,1.0));y*=ratio;vec4 finalColor= texture2D(digitalRainFont,vec2(x,1.0-y));vec3 high=finalColor.rgb*(vec3(1.2,1.2,1.2)*pow(1.0-y,30.0));finalColor.rgb*=vec3(pow(tileLuminance,5.0),pow(tileLuminance,1.5),pow(tileLuminance,3.0));finalColor.rgb+=high;finalColor.rgb=clamp(finalColor.rgb,0.,1.);finalColor.a=1.0;finalColor= mix(finalColor,tileColor,digitalRainOptions.w);finalColor= mix(finalColor,baseColor,digitalRainOptions.z);gl_FragColor=finalColor;}";
3
+ const name = "digitalrainPixelShader";
4
+ const shader = `varying vec2 vUV;uniform sampler2D textureSampler;uniform sampler2D digitalRainFont;uniform vec4 digitalRainFontInfos;uniform vec4 digitalRainOptions;uniform mat4 matrixSpeed;uniform float cosTimeZeroOne;float getLuminance(vec3 color)
5
+ {return clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);}
6
+ #define CUSTOM_FRAGMENT_DEFINITIONS
7
+ void main(void)
8
+ {float caracterSize=digitalRainFontInfos.x;float numChar=digitalRainFontInfos.y-1.0;float fontx=digitalRainFontInfos.z;float fonty=digitalRainFontInfos.w;float screenx=digitalRainOptions.x;float screeny=digitalRainOptions.y;float ratio=screeny/fonty;float columnx=float(floor((gl_FragCoord.x)/caracterSize));float tileX=float(floor((gl_FragCoord.x)/caracterSize))*caracterSize/screenx;float tileY=float(floor((gl_FragCoord.y)/caracterSize))*caracterSize/screeny;vec2 tileUV=vec2(tileX,tileY);vec4 tileColor=texture2D(textureSampler,tileUV);vec4 baseColor=texture2D(textureSampler,vUV);float tileLuminance=getLuminance(tileColor.rgb);int st=int(mod(columnx,4.0));float speed=cosTimeZeroOne*(sin(tileX*314.5)*0.5+0.6);
9
+ float x=float(mod(gl_FragCoord.x,caracterSize))/fontx;float y=float(mod(speed+gl_FragCoord.y/screeny,1.0));y*=ratio;vec4 finalColor= texture2D(digitalRainFont,vec2(x,1.0-y));vec3 high=finalColor.rgb*(vec3(1.2,1.2,1.2)*pow(1.0-y,30.0));finalColor.rgb*=vec3(pow(tileLuminance,5.0),pow(tileLuminance,1.5),pow(tileLuminance,3.0));finalColor.rgb+=high;finalColor.rgb=clamp(finalColor.rgb,0.,1.);finalColor.a=1.0;finalColor= mix(finalColor,tileColor,digitalRainOptions.w);finalColor= mix(finalColor,baseColor,digitalRainOptions.z);gl_FragColor=finalColor;}`;
5
10
  // Sideeffect
6
11
  ShaderStore.ShadersStore[name] = shader;
7
12
  /** @hidden */
8
- export var digitalrainPixelShader = { name: name, shader: shader };
13
+ export const digitalrainPixelShader = { name, shader };
9
14
  //# sourceMappingURL=digitalrain.fragment.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"digitalrain.fragment.js","sourceRoot":"","sources":["../../../../../lts/postProcesses/generated/digitalRain/digitalrain.fragment.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,+CAAiC;AAEvD,IAAM,IAAI,GAAG,wBAAwB,CAAC;AACtC,IAAM,MAAM,GAAG,wlDAKwhB,CAAC;AACxiB,aAAa;AACb,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AACxC,cAAc;AACd,MAAM,CAAC,IAAM,sBAAsB,GAAG,EAAE,IAAI,MAAA,EAAE,MAAM,QAAA,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"core/Engines/shaderStore\";\n\nconst name = \"digitalrainPixelShader\";\nconst shader = `varying vec2 vUV;uniform sampler2D textureSampler;uniform sampler2D digitalRainFont;uniform vec4 digitalRainFontInfos;uniform vec4 digitalRainOptions;uniform mat4 matrixSpeed;uniform float cosTimeZeroOne;float getLuminance(vec3 color)\n{return clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);}\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) \n{float caracterSize=digitalRainFontInfos.x;float numChar=digitalRainFontInfos.y-1.0;float fontx=digitalRainFontInfos.z;float fonty=digitalRainFontInfos.w;float screenx=digitalRainOptions.x;float screeny=digitalRainOptions.y;float ratio=screeny/fonty;float columnx=float(floor((gl_FragCoord.x)/caracterSize));float tileX=float(floor((gl_FragCoord.x)/caracterSize))*caracterSize/screenx;float tileY=float(floor((gl_FragCoord.y)/caracterSize))*caracterSize/screeny;vec2 tileUV=vec2(tileX,tileY);vec4 tileColor=texture2D(textureSampler,tileUV);vec4 baseColor=texture2D(textureSampler,vUV);float tileLuminance=getLuminance(tileColor.rgb);int st=int(mod(columnx,4.0));float speed=cosTimeZeroOne*(sin(tileX*314.5)*0.5+0.6); \nfloat x=float(mod(gl_FragCoord.x,caracterSize))/fontx;float y=float(mod(speed+gl_FragCoord.y/screeny,1.0));y*=ratio;vec4 finalColor= texture2D(digitalRainFont,vec2(x,1.0-y));vec3 high=finalColor.rgb*(vec3(1.2,1.2,1.2)*pow(1.0-y,30.0));finalColor.rgb*=vec3(pow(tileLuminance,5.0),pow(tileLuminance,1.5),pow(tileLuminance,3.0));finalColor.rgb+=high;finalColor.rgb=clamp(finalColor.rgb,0.,1.);finalColor.a=1.0;finalColor= mix(finalColor,tileColor,digitalRainOptions.w);finalColor= mix(finalColor,baseColor,digitalRainOptions.z);gl_FragColor=finalColor;}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @hidden */\nexport const digitalrainPixelShader = { name, shader };\n"]}
1
+ {"version":3,"file":"digitalrain.fragment.js","sourceRoot":"","sources":["../../../../../lts/postProcesses/generated/digitalRain/digitalrain.fragment.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,+CAAiC;AAEvD,MAAM,IAAI,GAAG,wBAAwB,CAAC;AACtC,MAAM,MAAM,GAAG;;;;;uiBAKwhB,CAAC;AACxiB,aAAa;AACb,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AACxC,cAAc;AACd,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"core/Engines/shaderStore\";\n\nconst name = \"digitalrainPixelShader\";\nconst shader = `varying vec2 vUV;uniform sampler2D textureSampler;uniform sampler2D digitalRainFont;uniform vec4 digitalRainFontInfos;uniform vec4 digitalRainOptions;uniform mat4 matrixSpeed;uniform float cosTimeZeroOne;float getLuminance(vec3 color)\n{return clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);}\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) \n{float caracterSize=digitalRainFontInfos.x;float numChar=digitalRainFontInfos.y-1.0;float fontx=digitalRainFontInfos.z;float fonty=digitalRainFontInfos.w;float screenx=digitalRainOptions.x;float screeny=digitalRainOptions.y;float ratio=screeny/fonty;float columnx=float(floor((gl_FragCoord.x)/caracterSize));float tileX=float(floor((gl_FragCoord.x)/caracterSize))*caracterSize/screenx;float tileY=float(floor((gl_FragCoord.y)/caracterSize))*caracterSize/screeny;vec2 tileUV=vec2(tileX,tileY);vec4 tileColor=texture2D(textureSampler,tileUV);vec4 baseColor=texture2D(textureSampler,vUV);float tileLuminance=getLuminance(tileColor.rgb);int st=int(mod(columnx,4.0));float speed=cosTimeZeroOne*(sin(tileX*314.5)*0.5+0.6); \nfloat x=float(mod(gl_FragCoord.x,caracterSize))/fontx;float y=float(mod(speed+gl_FragCoord.y/screeny,1.0));y*=ratio;vec4 finalColor= texture2D(digitalRainFont,vec2(x,1.0-y));vec3 high=finalColor.rgb*(vec3(1.2,1.2,1.2)*pow(1.0-y,30.0));finalColor.rgb*=vec3(pow(tileLuminance,5.0),pow(tileLuminance,1.5),pow(tileLuminance,3.0));finalColor.rgb+=high;finalColor.rgb=clamp(finalColor.rgb,0.,1.);finalColor.a=1.0;finalColor= mix(finalColor,tileColor,digitalRainOptions.w);finalColor= mix(finalColor,baseColor,digitalRainOptions.z);gl_FragColor=finalColor;}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @hidden */\nexport const digitalrainPixelShader = { name, shader };\n"]}
@@ -4,9 +4,9 @@ import * as postProcessLibrary from "../asciiArt/index.js";
4
4
  * This is the entry point for the UMD module.
5
5
  * The entry point for a future ESM package should be index.ts
6
6
  */
7
- var globalObject = typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : undefined;
7
+ const globalObject = typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : undefined;
8
8
  if (typeof globalObject !== "undefined") {
9
- for (var key in postProcessLibrary) {
9
+ for (const key in postProcessLibrary) {
10
10
  globalObject.BABYLON[key] = postProcessLibrary[key];
11
11
  }
12
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"legacy-asciiArt.js","sourceRoot":"","sources":["../../../../../lts/postProcesses/generated/legacy/legacy-asciiArt.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,KAAK,kBAAkB,MAAM,mBAAmB,CAAC;AACxD;;;GAGG;AACH,IAAM,YAAY,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACjH,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE;IACrC,KAAK,IAAM,GAAG,IAAI,kBAAkB,EAAE;QAC5B,YAAa,CAAC,OAAO,CAAC,GAAG,CAAC,GAAS,kBAAmB,CAAC,GAAG,CAAC,CAAC;KACrE;CACJ;AACD,cAAc,mBAAmB,CAAC","sourcesContent":["/* eslint-disable import/no-internal-modules */\nimport * as postProcessLibrary from \"../asciiArt/index\";\n/**\n * This is the entry point for the UMD module.\n * The entry point for a future ESM package should be index.ts\n */\nconst globalObject = typeof global !== \"undefined\" ? global : typeof window !== \"undefined\" ? window : undefined;\nif (typeof globalObject !== \"undefined\") {\n for (const key in postProcessLibrary) {\n (<any>globalObject).BABYLON[key] = (<any>postProcessLibrary)[key];\n }\n}\nexport * from \"../asciiArt/index\";\n"]}
1
+ {"version":3,"file":"legacy-asciiArt.js","sourceRoot":"","sources":["../../../../../lts/postProcesses/generated/legacy/legacy-asciiArt.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,KAAK,kBAAkB,MAAM,mBAAmB,CAAC;AACxD;;;GAGG;AACH,MAAM,YAAY,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACjH,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE;IACrC,KAAK,MAAM,GAAG,IAAI,kBAAkB,EAAE;QAC5B,YAAa,CAAC,OAAO,CAAC,GAAG,CAAC,GAAS,kBAAmB,CAAC,GAAG,CAAC,CAAC;KACrE;CACJ;AACD,cAAc,mBAAmB,CAAC","sourcesContent":["/* eslint-disable import/no-internal-modules */\nimport * as postProcessLibrary from \"../asciiArt/index\";\n/**\n * This is the entry point for the UMD module.\n * The entry point for a future ESM package should be index.ts\n */\nconst globalObject = typeof global !== \"undefined\" ? global : typeof window !== \"undefined\" ? window : undefined;\nif (typeof globalObject !== \"undefined\") {\n for (const key in postProcessLibrary) {\n (<any>globalObject).BABYLON[key] = (<any>postProcessLibrary)[key];\n }\n}\nexport * from \"../asciiArt/index\";\n"]}
@@ -4,9 +4,9 @@ import * as postProcessLibrary from "../digitalRain/index.js";
4
4
  * This is the entry point for the UMD module.
5
5
  * The entry point for a future ESM package should be index.ts
6
6
  */
7
- var globalObject = typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : undefined;
7
+ const globalObject = typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : undefined;
8
8
  if (typeof globalObject !== "undefined") {
9
- for (var key in postProcessLibrary) {
9
+ for (const key in postProcessLibrary) {
10
10
  globalObject.BABYLON[key] = postProcessLibrary[key];
11
11
  }
12
12
  }
@@ -1 +1 @@
1
- {"version":3,"file":"legacy-digitalRain.js","sourceRoot":"","sources":["../../../../../lts/postProcesses/generated/legacy/legacy-digitalRain.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,KAAK,kBAAkB,MAAM,sBAAsB,CAAC;AAC3D;;;GAGG;AACH,IAAM,YAAY,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACjH,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE;IACrC,KAAK,IAAM,GAAG,IAAI,kBAAkB,EAAE;QAC5B,YAAa,CAAC,OAAO,CAAC,GAAG,CAAC,GAAS,kBAAmB,CAAC,GAAG,CAAC,CAAC;KACrE;CACJ;AACD,cAAc,sBAAsB,CAAC","sourcesContent":["/* eslint-disable import/no-internal-modules */\nimport * as postProcessLibrary from \"../digitalRain/index\";\n/**\n * This is the entry point for the UMD module.\n * The entry point for a future ESM package should be index.ts\n */\nconst globalObject = typeof global !== \"undefined\" ? global : typeof window !== \"undefined\" ? window : undefined;\nif (typeof globalObject !== \"undefined\") {\n for (const key in postProcessLibrary) {\n (<any>globalObject).BABYLON[key] = (<any>postProcessLibrary)[key];\n }\n}\nexport * from \"../digitalRain/index\";\n"]}
1
+ {"version":3,"file":"legacy-digitalRain.js","sourceRoot":"","sources":["../../../../../lts/postProcesses/generated/legacy/legacy-digitalRain.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,KAAK,kBAAkB,MAAM,sBAAsB,CAAC;AAC3D;;;GAGG;AACH,MAAM,YAAY,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACjH,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE;IACrC,KAAK,MAAM,GAAG,IAAI,kBAAkB,EAAE;QAC5B,YAAa,CAAC,OAAO,CAAC,GAAG,CAAC,GAAS,kBAAmB,CAAC,GAAG,CAAC,CAAC;KACrE;CACJ;AACD,cAAc,sBAAsB,CAAC","sourcesContent":["/* eslint-disable import/no-internal-modules */\nimport * as postProcessLibrary from \"../digitalRain/index\";\n/**\n * This is the entry point for the UMD module.\n * The entry point for a future ESM package should be index.ts\n */\nconst globalObject = typeof global !== \"undefined\" ? global : typeof window !== \"undefined\" ? window : undefined;\nif (typeof globalObject !== \"undefined\") {\n for (const key in postProcessLibrary) {\n (<any>globalObject).BABYLON[key] = (<any>postProcessLibrary)[key];\n }\n}\nexport * from \"../digitalRain/index\";\n"]}
package/legacy/legacy.js CHANGED
@@ -5,9 +5,9 @@ import * as postProcessLibrary from "../index.js";
5
5
  * This is the entry point for the UMD module.
6
6
  * The entry point for a future ESM package should be index.ts
7
7
  */
8
- var globalObject = typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : undefined;
8
+ const globalObject = typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : undefined;
9
9
  if (typeof globalObject !== "undefined") {
10
- for (var key in postProcessLibrary) {
10
+ for (const key in postProcessLibrary) {
11
11
  globalObject.BABYLON[key] = postProcessLibrary[key];
12
12
  }
13
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"legacy.js","sourceRoot":"","sources":["../../../../../lts/postProcesses/generated/legacy/legacy.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,KAAK,kBAAkB,MAAM,UAAU,CAAC;AAC/C;;;;GAIG;AACH,IAAM,YAAY,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACjH,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE;IACrC,KAAK,IAAM,GAAG,IAAI,kBAAkB,EAAE;QAC5B,YAAa,CAAC,OAAO,CAAC,GAAG,CAAC,GAAS,kBAAmB,CAAC,GAAG,CAAC,CAAC;KACrE;CACJ;AACD,cAAc,UAAU,CAAC","sourcesContent":["/* eslint-disable import/no-internal-modules */\nimport * as postProcessLibrary from \"../index\";\n/**\n *\n * This is the entry point for the UMD module.\n * The entry point for a future ESM package should be index.ts\n */\nconst globalObject = typeof global !== \"undefined\" ? global : typeof window !== \"undefined\" ? window : undefined;\nif (typeof globalObject !== \"undefined\") {\n for (const key in postProcessLibrary) {\n (<any>globalObject).BABYLON[key] = (<any>postProcessLibrary)[key];\n }\n}\nexport * from \"../index\";\n"]}
1
+ {"version":3,"file":"legacy.js","sourceRoot":"","sources":["../../../../../lts/postProcesses/generated/legacy/legacy.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,KAAK,kBAAkB,MAAM,UAAU,CAAC;AAC/C;;;;GAIG;AACH,MAAM,YAAY,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACjH,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE;IACrC,KAAK,MAAM,GAAG,IAAI,kBAAkB,EAAE;QAC5B,YAAa,CAAC,OAAO,CAAC,GAAG,CAAC,GAAS,kBAAmB,CAAC,GAAG,CAAC,CAAC;KACrE;CACJ;AACD,cAAc,UAAU,CAAC","sourcesContent":["/* eslint-disable import/no-internal-modules */\nimport * as postProcessLibrary from \"../index\";\n/**\n *\n * This is the entry point for the UMD module.\n * The entry point for a future ESM package should be index.ts\n */\nconst globalObject = typeof global !== \"undefined\" ? global : typeof window !== \"undefined\" ? window : undefined;\nif (typeof globalObject !== \"undefined\") {\n for (const key in postProcessLibrary) {\n (<any>globalObject).BABYLON[key] = (<any>postProcessLibrary)[key];\n }\n}\nexport * from \"../index\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babylonjs/post-processes",
3
- "version": "5.21.0",
3
+ "version": "5.22.0",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
6
  "types": "index.d.ts",
@@ -18,11 +18,8 @@
18
18
  "postcompile": "build-tools -c add-js-to-es6",
19
19
  "prepublishOnly": "build-tools -c prepare-es6-build"
20
20
  },
21
- "dependencies": {
22
- "tslib": "^2.4.0"
23
- },
24
21
  "devDependencies": {
25
- "@babylonjs/core": "^5.21.0",
22
+ "@babylonjs/core": "^5.22.0",
26
23
  "@dev/build-tools": "^1.0.0",
27
24
  "@lts/post-processes": "^1.0.0",
28
25
  "rimraf": "^3.0.2",