@babylonjs/post-processes 5.0.0-rc.0 → 5.0.0-rc.11
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.
- package/asciiArt/asciiArtPostProcess.d.ts +107 -106
- package/asciiArt/asciiArtPostProcess.js +206 -205
- package/asciiArt/asciiArtPostProcess.js.map +1 -1
- package/asciiArt/asciiart.fragment.d.ts +5 -5
- package/asciiArt/asciiart.fragment.js +8 -6
- package/asciiArt/asciiart.fragment.js.map +1 -1
- package/asciiArt/index.d.ts +1 -1
- package/asciiArt/index.js +1 -1
- package/asciiArt/index.js.map +1 -1
- package/digitalRain/digitalRainPostProcess.d.ts +107 -106
- package/digitalRain/digitalRainPostProcess.js +216 -215
- package/digitalRain/digitalRainPostProcess.js.map +1 -1
- package/digitalRain/digitalrain.fragment.d.ts +5 -5
- package/digitalRain/digitalrain.fragment.js +8 -6
- package/digitalRain/digitalrain.fragment.js.map +1 -1
- package/digitalRain/index.d.ts +1 -1
- package/digitalRain/index.js +1 -1
- package/digitalRain/index.js.map +1 -1
- package/index.d.ts +2 -2
- package/index.js +3 -2
- package/index.js.map +1 -1
- package/legacy/legacy-asciiArt.d.ts +1 -1
- package/legacy/legacy-asciiArt.js +13 -12
- package/legacy/legacy-asciiArt.js.map +1 -1
- package/legacy/legacy-digitalRain.d.ts +1 -1
- package/legacy/legacy-digitalRain.js +13 -12
- package/legacy/legacy-digitalRain.js.map +1 -1
- package/legacy/legacy.d.ts +1 -1
- package/legacy/legacy.js +14 -13
- package/legacy/legacy.js.map +1 -1
- package/package.json +21 -55
- package/readme.md +2 -2
@@ -1,216 +1,217 @@
|
|
1
|
-
import { __decorate, __extends } from "tslib";
|
2
|
-
import { serialize, SerializationHelper } from "@babylonjs/core/Misc/decorators.js";
|
3
|
-
import { Matrix } from "@babylonjs/core/Maths/math.vector.js";
|
4
|
-
import { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
|
5
|
-
import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
|
6
|
-
import { PostProcess } from "@babylonjs/core/PostProcesses/postProcess.js";
|
7
|
-
import "@babylonjs/core/Engines/Extensions/engine.dynamicTexture.js";
|
8
|
-
import "./digitalrain.fragment
|
9
|
-
/**
|
10
|
-
* DigitalRainFontTexture is the helper class used to easily create your digital rain font texture.
|
11
|
-
*
|
12
|
-
* It basically takes care rendering the font front the given font size to a texture.
|
13
|
-
* This is used later on in the postprocess.
|
14
|
-
*/
|
15
|
-
var DigitalRainFontTexture = /** @class */ (function (_super) {
|
16
|
-
__extends(DigitalRainFontTexture, _super);
|
17
|
-
/**
|
18
|
-
* Create a new instance of the Digital Rain FontTexture class
|
19
|
-
* @param name the name of the texture
|
20
|
-
* @param font the font to use, use the W3C CSS notation
|
21
|
-
* @param text the caracter set to use in the rendering.
|
22
|
-
* @param scene the scene that owns the texture
|
23
|
-
*/
|
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();
|
28
|
-
if (!scene) {
|
29
|
-
return _this;
|
30
|
-
}
|
31
|
-
_this.name = name;
|
32
|
-
_this._text == text;
|
33
|
-
_this._font == font;
|
34
|
-
_this.wrapU = Texture.CLAMP_ADDRESSMODE;
|
35
|
-
_this.wrapV = Texture.CLAMP_ADDRESSMODE;
|
36
|
-
// Get the font specific info.
|
37
|
-
var maxCharHeight = _this.
|
38
|
-
var maxCharWidth = _this.
|
39
|
-
_this._charSize = Math.max(maxCharHeight.height, maxCharWidth);
|
40
|
-
// 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);
|
43
|
-
// Create the texture that will store the font characters.
|
44
|
-
_this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);
|
45
|
-
//scene.getEngine().setclamp
|
46
|
-
var textureSize = _this.getSize();
|
47
|
-
// Create a canvas with the final size: the one matching the texture.
|
48
|
-
var canvas = document.createElement("canvas");
|
49
|
-
canvas.width = textureSize.width;
|
50
|
-
canvas.height = textureSize.height;
|
51
|
-
var context = canvas.getContext("2d");
|
52
|
-
context.textBaseline = "top";
|
53
|
-
context.font = font;
|
54
|
-
context.fillStyle = "white";
|
55
|
-
context.imageSmoothingEnabled = false;
|
56
|
-
// 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);
|
59
|
-
}
|
60
|
-
// Flush the text in the dynamic texture.
|
61
|
-
scene.getEngine().updateDynamicTexture(_this._texture, canvas, false, true);
|
62
|
-
return _this;
|
63
|
-
}
|
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
|
-
/**
|
75
|
-
* Gets the max char width of a font.
|
76
|
-
* @param font the font to use, use the W3C CSS notation
|
77
|
-
* @return the max char width
|
78
|
-
*/
|
79
|
-
DigitalRainFontTexture.prototype.
|
80
|
-
var fontDraw = document.createElement("canvas");
|
81
|
-
var ctx = fontDraw.getContext(
|
82
|
-
ctx.fillStyle =
|
83
|
-
ctx.font = font;
|
84
|
-
return ctx.measureText("W").width;
|
85
|
-
};
|
86
|
-
// More info here: https://videlais.com/2014/03/16/the-many-and-varied-problems-with-measuring-font-height-for-html5-canvas/
|
87
|
-
/**
|
88
|
-
* Gets the max char height of a font.
|
89
|
-
* @param font the font to use, use the W3C CSS notation
|
90
|
-
* @return the max char height
|
91
|
-
*/
|
92
|
-
DigitalRainFontTexture.prototype.
|
93
|
-
var fontDraw = document.createElement("canvas");
|
94
|
-
var ctx = fontDraw.getContext(
|
95
|
-
ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);
|
96
|
-
ctx.textBaseline =
|
97
|
-
ctx.fillStyle =
|
98
|
-
ctx.font = font;
|
99
|
-
ctx.fillText(
|
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;
|
106
|
-
if (pixels[index] === 0) {
|
107
|
-
if (column === fontDraw.width - 1 && start !== -1) {
|
108
|
-
end = row;
|
109
|
-
row = fontDraw.height;
|
110
|
-
break;
|
111
|
-
}
|
112
|
-
continue;
|
113
|
-
}
|
114
|
-
else {
|
115
|
-
if (start === -1) {
|
116
|
-
start = row;
|
117
|
-
}
|
118
|
-
break;
|
119
|
-
}
|
120
|
-
}
|
121
|
-
}
|
122
|
-
return { height:
|
123
|
-
};
|
124
|
-
/**
|
125
|
-
* Clones the current DigitalRainFontTexture.
|
126
|
-
* @return the clone of the texture.
|
127
|
-
*/
|
128
|
-
DigitalRainFontTexture.prototype.clone = function () {
|
129
|
-
return new DigitalRainFontTexture(this.name, this._font, this._text, this.getScene());
|
130
|
-
};
|
131
|
-
/**
|
132
|
-
* Parses a json object representing the texture and returns an instance of it.
|
133
|
-
* @param source the source JSON representation
|
134
|
-
* @param scene the scene to create the texture for
|
135
|
-
* @return the parsed texture
|
136
|
-
*/
|
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);
|
139
|
-
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 };
|
150
|
-
/**
|
151
|
-
* DigitalRainPostProcess helps rendering everithing in digital rain.
|
152
|
-
*
|
153
|
-
* Simmply add it to your scene and let the nerd that lives in you have fun.
|
154
|
-
* Example usage: var pp = new DigitalRainPostProcess("digitalRain", "20px Monospace", camera);
|
155
|
-
*/
|
156
|
-
var DigitalRainPostProcess = /** @class */ (function (_super) {
|
157
|
-
__extends(DigitalRainPostProcess, _super);
|
158
|
-
/**
|
159
|
-
* Instantiates a new Digital Rain Post Process.
|
160
|
-
* @param name the name to give to the postprocess
|
161
|
-
* @camera the camera to apply the post process to.
|
162
|
-
* @param
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
* This
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
* This
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
var
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
_this.
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
var
|
200
|
-
var
|
201
|
-
var
|
202
|
-
|
203
|
-
|
204
|
-
effect.
|
205
|
-
effect.setFloat4("
|
206
|
-
effect.
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
1
|
+
import { __decorate, __extends } from "tslib";
|
2
|
+
import { serialize, SerializationHelper } from "@babylonjs/core/Misc/decorators.js";
|
3
|
+
import { Matrix } from "@babylonjs/core/Maths/math.vector.js";
|
4
|
+
import { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
|
5
|
+
import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
|
6
|
+
import { PostProcess } from "@babylonjs/core/PostProcesses/postProcess.js";
|
7
|
+
import "@babylonjs/core/Engines/Extensions/engine.dynamicTexture.js";
|
8
|
+
import "./digitalrain.fragment";
|
9
|
+
/**
|
10
|
+
* DigitalRainFontTexture is the helper class used to easily create your digital rain font texture.
|
11
|
+
*
|
12
|
+
* It basically takes care rendering the font front the given font size to a texture.
|
13
|
+
* This is used later on in the postprocess.
|
14
|
+
*/
|
15
|
+
var DigitalRainFontTexture = /** @class */ (function (_super) {
|
16
|
+
__extends(DigitalRainFontTexture, _super);
|
17
|
+
/**
|
18
|
+
* Create a new instance of the Digital Rain FontTexture class
|
19
|
+
* @param name the name of the texture
|
20
|
+
* @param font the font to use, use the W3C CSS notation
|
21
|
+
* @param text the caracter set to use in the rendering.
|
22
|
+
* @param scene the scene that owns the texture
|
23
|
+
*/
|
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();
|
28
|
+
if (!scene) {
|
29
|
+
return _this;
|
30
|
+
}
|
31
|
+
_this.name = name;
|
32
|
+
_this._text == text;
|
33
|
+
_this._font == font;
|
34
|
+
_this.wrapU = Texture.CLAMP_ADDRESSMODE;
|
35
|
+
_this.wrapV = Texture.CLAMP_ADDRESSMODE;
|
36
|
+
// 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);
|
40
|
+
// 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);
|
43
|
+
// Create the texture that will store the font characters.
|
44
|
+
_this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);
|
45
|
+
//scene.getEngine().setclamp
|
46
|
+
var textureSize = _this.getSize();
|
47
|
+
// Create a canvas with the final size: the one matching the texture.
|
48
|
+
var canvas = document.createElement("canvas");
|
49
|
+
canvas.width = textureSize.width;
|
50
|
+
canvas.height = textureSize.height;
|
51
|
+
var context = canvas.getContext("2d");
|
52
|
+
context.textBaseline = "top";
|
53
|
+
context.font = font;
|
54
|
+
context.fillStyle = "white";
|
55
|
+
context.imageSmoothingEnabled = false;
|
56
|
+
// 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);
|
59
|
+
}
|
60
|
+
// Flush the text in the dynamic texture.
|
61
|
+
scene.getEngine().updateDynamicTexture(_this._texture, canvas, false, true);
|
62
|
+
return _this;
|
63
|
+
}
|
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
|
+
/**
|
75
|
+
* Gets the max char width of a font.
|
76
|
+
* @param font the font to use, use the W3C CSS notation
|
77
|
+
* @return the max char width
|
78
|
+
*/
|
79
|
+
DigitalRainFontTexture.prototype._getFontWidth = function (font) {
|
80
|
+
var fontDraw = document.createElement("canvas");
|
81
|
+
var ctx = fontDraw.getContext("2d");
|
82
|
+
ctx.fillStyle = "white";
|
83
|
+
ctx.font = font;
|
84
|
+
return ctx.measureText("W").width;
|
85
|
+
};
|
86
|
+
// More info here: https://videlais.com/2014/03/16/the-many-and-varied-problems-with-measuring-font-height-for-html5-canvas/
|
87
|
+
/**
|
88
|
+
* Gets the max char height of a font.
|
89
|
+
* @param font the font to use, use the W3C CSS notation
|
90
|
+
* @return the max char height
|
91
|
+
*/
|
92
|
+
DigitalRainFontTexture.prototype._getFontHeight = function (font) {
|
93
|
+
var fontDraw = document.createElement("canvas");
|
94
|
+
var ctx = fontDraw.getContext("2d");
|
95
|
+
ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);
|
96
|
+
ctx.textBaseline = "top";
|
97
|
+
ctx.fillStyle = "white";
|
98
|
+
ctx.font = font;
|
99
|
+
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;
|
106
|
+
if (pixels[index] === 0) {
|
107
|
+
if (column === fontDraw.width - 1 && start !== -1) {
|
108
|
+
end = row;
|
109
|
+
row = fontDraw.height;
|
110
|
+
break;
|
111
|
+
}
|
112
|
+
continue;
|
113
|
+
}
|
114
|
+
else {
|
115
|
+
if (start === -1) {
|
116
|
+
start = row;
|
117
|
+
}
|
118
|
+
break;
|
119
|
+
}
|
120
|
+
}
|
121
|
+
}
|
122
|
+
return { height: end - start + 1, offset: start - 1 };
|
123
|
+
};
|
124
|
+
/**
|
125
|
+
* Clones the current DigitalRainFontTexture.
|
126
|
+
* @return the clone of the texture.
|
127
|
+
*/
|
128
|
+
DigitalRainFontTexture.prototype.clone = function () {
|
129
|
+
return new DigitalRainFontTexture(this.name, this._font, this._text, this.getScene());
|
130
|
+
};
|
131
|
+
/**
|
132
|
+
* Parses a json object representing the texture and returns an instance of it.
|
133
|
+
* @param source the source JSON representation
|
134
|
+
* @param scene the scene to create the texture for
|
135
|
+
* @return the parsed texture
|
136
|
+
*/
|
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);
|
139
|
+
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 };
|
150
|
+
/**
|
151
|
+
* DigitalRainPostProcess helps rendering everithing in digital rain.
|
152
|
+
*
|
153
|
+
* Simmply add it to your scene and let the nerd that lives in you have fun.
|
154
|
+
* Example usage: var pp = new DigitalRainPostProcess("digitalRain", "20px Monospace", camera);
|
155
|
+
*/
|
156
|
+
var DigitalRainPostProcess = /** @class */ (function (_super) {
|
157
|
+
__extends(DigitalRainPostProcess, _super);
|
158
|
+
/**
|
159
|
+
* Instantiates a new Digital Rain Post Process.
|
160
|
+
* @param name the name to give to the postprocess
|
161
|
+
* @camera the camera to apply the post process to.
|
162
|
+
* @param camera
|
163
|
+
* @param options can either be the font name or an option object following the IDigitalRainPostProcessOptions format
|
164
|
+
*/
|
165
|
+
function DigitalRainPostProcess(name, camera, options) {
|
166
|
+
var _this = _super.call(this, name, "digitalrain", ["digitalRainFontInfos", "digitalRainOptions", "cosTimeZeroOne", "matrixSpeed"], ["digitalRainFont"], {
|
167
|
+
width: camera.getEngine().getRenderWidth(),
|
168
|
+
height: camera.getEngine().getRenderHeight(),
|
169
|
+
}, camera, Texture.TRILINEAR_SAMPLINGMODE, camera.getEngine(), true) || this;
|
170
|
+
/**
|
171
|
+
* This defines the amount you want to mix the "tile" or caracter space colored in the digital rain.
|
172
|
+
* This number is defined between 0 and 1;
|
173
|
+
*/
|
174
|
+
_this.mixToTile = 0;
|
175
|
+
/**
|
176
|
+
* This defines the amount you want to mix the normal rendering pass in the digital rain.
|
177
|
+
* This number is defined between 0 and 1;
|
178
|
+
*/
|
179
|
+
_this.mixToNormal = 0;
|
180
|
+
/**
|
181
|
+
* Speed of the effect
|
182
|
+
*/
|
183
|
+
_this.speed = 0.003;
|
184
|
+
// Default values.
|
185
|
+
var font = "15px Monospace";
|
186
|
+
var characterSet = "古池や蛙飛び込む水の音ふるいけやかわずとびこむみずのおと初しぐれ猿も小蓑をほしげ也はつしぐれさるもこみのをほしげなり江戸の雨何石呑んだ時鳥えどのあめなんごくのんだほととぎす";
|
187
|
+
// Use options.
|
188
|
+
if (options) {
|
189
|
+
if (typeof options === "string") {
|
190
|
+
font = options;
|
191
|
+
}
|
192
|
+
else {
|
193
|
+
font = options.font || font;
|
194
|
+
_this.mixToTile = options.mixToTile || _this.mixToTile;
|
195
|
+
_this.mixToNormal = options.mixToNormal || _this.mixToNormal;
|
196
|
+
}
|
197
|
+
}
|
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);
|
207
|
+
effect.setMatrix("matrixSpeed", matrix);
|
208
|
+
alpha += _this.speed;
|
209
|
+
cosTimeZeroOne = alpha;
|
210
|
+
effect.setFloat("cosTimeZeroOne", cosTimeZeroOne);
|
211
|
+
};
|
212
|
+
return _this;
|
213
|
+
}
|
214
|
+
return DigitalRainPostProcess;
|
215
|
+
}(PostProcess));
|
216
|
+
export { DigitalRainPostProcess };
|
216
217
|
//# sourceMappingURL=digitalRainPostProcess.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"digitalRainPostProcess.js","sourceRoot":"","sources":["../../../sourceES6/postProcessesLibrary/src/digitalRain/digitalRainPostProcess.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACjF,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAE3D,OAAO,EAAE,WAAW,EAAE,MAAM,gDAAgD,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,MAAM,4CAA4C,CAAC;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,2CAA2C,CAAC;AAExE,OAAO,0DAA0D,CAAC;AAClE,OAAO,wBAAwB,CAAC;AAEhC;;;;;GAKG;AACH;IAA4C,0CAAW;IAiBnD;;;;;;OAMG;IACH,gCAAY,IAAY,EAAE,IAAY,EAAE,IAAY,EAAE,KAA6B;QAA7B,sBAAA,EAAA,YAA6B;QAAnF,YACI,kBAAM,KAAK,CAAC,SA+Cf;QA7CG,KAAK,GAAG,KAAI,CAAC,QAAQ,EAAE,CAAC;QAExB,IAAI,CAAC,KAAK,EAAE;;SAEX;QAED,KAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,KAAI,CAAC,KAAK,IAAI,IAAI,CAAC;QACnB,KAAI,CAAC,KAAK,IAAI,IAAI,CAAC;QAEnB,KAAI,CAAC,KAAK,GAAG,OAAO,CAAC,iBAAiB,CAAC;QACvC,KAAI,CAAC,KAAK,GAAG,OAAO,CAAC,iBAAiB,CAAC;QAEvC,8BAA8B;QAC9B,IAAI,aAAa,GAAG,KAAI,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAC7C,IAAI,YAAY,GAAG,KAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QAE3C,KAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,MAAM,EAAE,YAAY,CAA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EAChB,KAAI,CAAC,SAAS,CAAC,CAAC;YAEpB,MAAM,CAAC,SAAS,CAAC,aAAa,EAC1B,MAAM,CAAC,CAAC;YAEZ,KAAK,IAAI,KAAI,CAAC,KAAK,CAAC;YACpB,cAAc,GAAG,KAAK,CAAC;YACvB,MAAM,CAAC,QAAQ,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;QACtD,CAAC,CAAC;;IACN,CAAC;IACL,6BAAC;AAAD,CAAC,AA/FD,CAA4C,WAAW,GA+FtD","sourcesContent":["import { Nullable } from \"@babylonjs/core/types\";\r\nimport { serialize, SerializationHelper } from \"@babylonjs/core/Misc/decorators\";\r\nimport { Matrix } from \"@babylonjs/core/Maths/math.vector\";\r\nimport { Camera } from \"@babylonjs/core/Cameras/camera\";\r\nimport { BaseTexture } from \"@babylonjs/core/Materials/Textures/baseTexture\";\r\nimport { Texture } from \"@babylonjs/core/Materials/Textures/texture\";\r\nimport { Effect } from \"@babylonjs/core/Materials/effect\";\r\nimport { PostProcess } from \"@babylonjs/core/PostProcesses/postProcess\";\r\nimport { Scene } from \"@babylonjs/core/scene\";\r\nimport \"@babylonjs/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\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 var maxCharHeight = this.getFontHeight(font);\r\n var 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 var textureWidth = this._charSize;\r\n var 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 var textureSize = this.getSize();\r\n\r\n // Create a canvas with the final size: the one matching the texture.\r\n var canvas = document.createElement(\"canvas\");\r\n canvas.width = textureSize.width;\r\n canvas.height = textureSize.height;\r\n var 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 (var 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 var fontDraw = document.createElement(\"canvas\");\r\n var 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 var fontDraw = document.createElement(\"canvas\");\r\n var 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 var pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;\r\n var start = -1;\r\n var end = -1;\r\n for (var row = 0; row < fontDraw.height; row++) {\r\n for (var column = 0; column < fontDraw.width; column++) {\r\n var 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 }\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 var texture = SerializationHelper.Parse(() => new DigitalRainFontTexture(source.name, source.font, source.text, scene),\r\n 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 /**\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 /**\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 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(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 // Default values.\r\n var font = \"15px Monospace\";\r\n var characterSet = \"古池や蛙飛び込む水の音ふるいけやかわずとびこむみずのおと初しぐれ猿も小蓑をほしげ也はつしぐれさるもこみのをほしげなり江戸の雨何石呑んだ時鳥えどのあめなんごくのんだほととぎす\";\r\n\r\n // Use options.\r\n if (options) {\r\n if (typeof (options) === \"string\") {\r\n font = <string>options;\r\n }\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 var textureSize = this._digitalRainFontTexture.getSize();\r\n\r\n var alpha = 0.0;\r\n var cosTimeZeroOne = 0.0;\r\n var matrix = Matrix.FromValues(\r\n Math.random(), Math.random(), Math.random(), Math.random(),\r\n Math.random(), Math.random(), Math.random(), Math.random(),\r\n Math.random(), Math.random(), Math.random(), Math.random(),\r\n Math.random(), Math.random(), Math.random(), 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\",\r\n this._digitalRainFontTexture.charSize,\r\n characterSet.length,\r\n textureSize.width,\r\n textureSize.height);\r\n\r\n effect.setFloat4(\"digitalRainOptions\",\r\n this.width,\r\n this.height,\r\n this.mixToNormal,\r\n this.mixToTile);\r\n\r\n effect.setMatrix(\"matrixSpeed\",\r\n 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+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"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,5 +1,5 @@
|
|
1
|
-
/** @hidden */
|
2
|
-
export declare
|
3
|
-
name: string;
|
4
|
-
shader: string;
|
5
|
-
};
|
1
|
+
/** @hidden */
|
2
|
+
export declare const digitalrainPixelShader: {
|
3
|
+
name: string;
|
4
|
+
shader: string;
|
5
|
+
};
|
@@ -1,7 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
var
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
// Do not edit.
|
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;}";
|
5
|
+
// Sideeffect
|
6
|
+
ShaderStore.ShadersStore[name] = shader;
|
7
|
+
/** @hidden */
|
8
|
+
export var digitalrainPixelShader = { name: name, shader: shader };
|
7
9
|
//# sourceMappingURL=digitalrain.fragment.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"digitalrain.fragment.js","sourceRoot":"","sources":["
|
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"]}
|
package/digitalRain/index.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export * from "./digitalRainPostProcess";
|
1
|
+
export * from "./digitalRainPostProcess";
|
package/digitalRain/index.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from "./digitalRainPostProcess
|
1
|
+
export * from "./digitalRainPostProcess";
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/digitalRain/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../lts/postProcesses/generated/digitalRain/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC","sourcesContent":["export * from \"./digitalRainPostProcess\";\r\n"]}
|
package/index.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
export * from "./asciiArt/index";
|
2
|
-
export * from "./digitalRain/index";
|
1
|
+
export * from "./asciiArt/index";
|
2
|
+
export * from "./digitalRain/index";
|
package/index.js
CHANGED
package/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../lts/postProcesses/generated/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC","sourcesContent":["/* eslint-disable import/no-internal-modules */\r\nexport * from \"./asciiArt/index\";\r\nexport * from \"./digitalRain/index\";\r\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
export * from "../asciiArt/index";
|
1
|
+
export * from "../asciiArt/index";
|