@onerjs/post-processes 8.23.1
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 -0
- package/asciiArt/asciiArtPostProcess.js +193 -0
- package/asciiArt/asciiArtPostProcess.js.map +1 -0
- package/asciiArt/asciiart.fragment.d.ts +5 -0
- package/asciiArt/asciiart.fragment.js +15 -0
- package/asciiArt/asciiart.fragment.js.map +1 -0
- package/asciiArt/index.d.ts +1 -0
- package/asciiArt/index.js +2 -0
- package/asciiArt/index.js.map +1 -0
- package/digitalRain/digitalRainPostProcess.d.ts +107 -0
- package/digitalRain/digitalRainPostProcess.js +203 -0
- package/digitalRain/digitalRainPostProcess.js.map +1 -0
- package/digitalRain/digitalrain.fragment.d.ts +5 -0
- package/digitalRain/digitalrain.fragment.js +16 -0
- package/digitalRain/digitalrain.fragment.js.map +1 -0
- package/digitalRain/index.d.ts +1 -0
- package/digitalRain/index.js +2 -0
- package/digitalRain/index.js.map +1 -0
- package/edgeDetection/edgeDetection.fragment.d.ts +5 -0
- package/edgeDetection/edgeDetection.fragment.js +19 -0
- package/edgeDetection/edgeDetection.fragment.js.map +1 -0
- package/edgeDetection/edgeDetectionPostProcess.d.ts +61 -0
- package/edgeDetection/edgeDetectionPostProcess.js +131 -0
- package/edgeDetection/edgeDetectionPostProcess.js.map +1 -0
- package/edgeDetection/index.d.ts +1 -0
- package/edgeDetection/index.js +2 -0
- package/edgeDetection/index.js.map +1 -0
- package/index.d.ts +3 -0
- package/index.js +5 -0
- package/index.js.map +1 -0
- package/legacy/legacy-asciiArt.d.ts +1 -0
- package/legacy/legacy-asciiArt.js +14 -0
- package/legacy/legacy-asciiArt.js.map +1 -0
- package/legacy/legacy-digitalRain.d.ts +1 -0
- package/legacy/legacy-digitalRain.js +14 -0
- package/legacy/legacy-digitalRain.js.map +1 -0
- package/legacy/legacy.d.ts +1 -0
- package/legacy/legacy.js +15 -0
- package/legacy/legacy.js.map +1 -0
- package/license.md +71 -0
- package/package.json +47 -0
- package/readme.md +31 -0
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { __decorate } from "@babylonjs/core/tslib.es6.js";
|
|
2
|
+
import { serialize } from "@babylonjs/core/Misc/decorators.js";
|
|
3
|
+
import { SerializationHelper } from "@babylonjs/core/Misc/decorators.serialization.js";
|
|
4
|
+
import { Matrix } from "@babylonjs/core/Maths/math.vector.js";
|
|
5
|
+
import { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
|
|
6
|
+
import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
|
|
7
|
+
import { PostProcess } from "@babylonjs/core/PostProcesses/postProcess.js";
|
|
8
|
+
import "@babylonjs/core/Engines/Extensions/engine.dynamicTexture.js";
|
|
9
|
+
import "./digitalrain.fragment.js";
|
|
10
|
+
/**
|
|
11
|
+
* DigitalRainFontTexture is the helper class used to easily create your digital rain font texture.
|
|
12
|
+
*
|
|
13
|
+
* It basically takes care rendering the font front the given font size to a texture.
|
|
14
|
+
* This is used later on in the postprocess.
|
|
15
|
+
*/
|
|
16
|
+
export class DigitalRainFontTexture extends BaseTexture {
|
|
17
|
+
/**
|
|
18
|
+
* Gets the size of one char in the texture (each char fits in size * size space in the texture).
|
|
19
|
+
*/
|
|
20
|
+
get charSize() {
|
|
21
|
+
return this._charSize;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create a new instance of the Digital Rain FontTexture class
|
|
25
|
+
* @param name the name of the texture
|
|
26
|
+
* @param font the font to use, use the W3C CSS notation
|
|
27
|
+
* @param text the caracter set to use in the rendering.
|
|
28
|
+
* @param scene the scene that owns the texture
|
|
29
|
+
*/
|
|
30
|
+
constructor(name, font, text, scene = null) {
|
|
31
|
+
super(scene);
|
|
32
|
+
scene = this.getScene();
|
|
33
|
+
if (!scene) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
this.name = name;
|
|
37
|
+
this._text == text;
|
|
38
|
+
this._font == font;
|
|
39
|
+
this.wrapU = Texture.CLAMP_ADDRESSMODE;
|
|
40
|
+
this.wrapV = Texture.CLAMP_ADDRESSMODE;
|
|
41
|
+
// Get the font specific info.
|
|
42
|
+
const maxCharHeight = this._getFontHeight(font);
|
|
43
|
+
const maxCharWidth = this._getFontWidth(font);
|
|
44
|
+
this._charSize = Math.max(maxCharHeight.height, maxCharWidth);
|
|
45
|
+
// This is an approximate size, but should always be able to fit at least the maxCharCount.
|
|
46
|
+
const textureWidth = this._charSize;
|
|
47
|
+
const textureHeight = Math.ceil(this._charSize * text.length);
|
|
48
|
+
// Create the texture that will store the font characters.
|
|
49
|
+
this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);
|
|
50
|
+
//scene.getEngine().setclamp
|
|
51
|
+
const textureSize = this.getSize();
|
|
52
|
+
// Create a canvas with the final size: the one matching the texture.
|
|
53
|
+
const canvas = document.createElement("canvas");
|
|
54
|
+
canvas.width = textureSize.width;
|
|
55
|
+
canvas.height = textureSize.height;
|
|
56
|
+
const context = canvas.getContext("2d");
|
|
57
|
+
context.textBaseline = "top";
|
|
58
|
+
context.font = font;
|
|
59
|
+
context.fillStyle = "white";
|
|
60
|
+
context.imageSmoothingEnabled = false;
|
|
61
|
+
// Sets the text in the texture.
|
|
62
|
+
for (let i = 0; i < text.length; i++) {
|
|
63
|
+
context.fillText(text[i], 0, i * this._charSize - maxCharHeight.offset);
|
|
64
|
+
}
|
|
65
|
+
// Flush the text in the dynamic texture.
|
|
66
|
+
scene.getEngine().updateDynamicTexture(this._texture, canvas, false, true);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Gets the max char width of a font.
|
|
70
|
+
* @param font the font to use, use the W3C CSS notation
|
|
71
|
+
* @returns the max char width
|
|
72
|
+
*/
|
|
73
|
+
_getFontWidth(font) {
|
|
74
|
+
const fontDraw = document.createElement("canvas");
|
|
75
|
+
const ctx = fontDraw.getContext("2d");
|
|
76
|
+
ctx.fillStyle = "white";
|
|
77
|
+
ctx.font = font;
|
|
78
|
+
return ctx.measureText("W").width;
|
|
79
|
+
}
|
|
80
|
+
// More info here: https://videlais.com/2014/03/16/the-many-and-varied-problems-with-measuring-font-height-for-html5-canvas/
|
|
81
|
+
/**
|
|
82
|
+
* Gets the max char height of a font.
|
|
83
|
+
* @param font the font to use, use the W3C CSS notation
|
|
84
|
+
* @returns the max char height
|
|
85
|
+
*/
|
|
86
|
+
_getFontHeight(font) {
|
|
87
|
+
const fontDraw = document.createElement("canvas");
|
|
88
|
+
const ctx = fontDraw.getContext("2d");
|
|
89
|
+
ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);
|
|
90
|
+
ctx.textBaseline = "top";
|
|
91
|
+
ctx.fillStyle = "white";
|
|
92
|
+
ctx.font = font;
|
|
93
|
+
ctx.fillText("jH|", 0, 0);
|
|
94
|
+
const pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;
|
|
95
|
+
let start = -1;
|
|
96
|
+
let end = -1;
|
|
97
|
+
for (let row = 0; row < fontDraw.height; row++) {
|
|
98
|
+
for (let column = 0; column < fontDraw.width; column++) {
|
|
99
|
+
const index = (row * fontDraw.width + column) * 4;
|
|
100
|
+
if (pixels[index] === 0) {
|
|
101
|
+
if (column === fontDraw.width - 1 && start !== -1) {
|
|
102
|
+
end = row;
|
|
103
|
+
row = fontDraw.height;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
if (start === -1) {
|
|
110
|
+
start = row;
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return { height: end - start + 1, offset: start - 1 };
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Clones the current DigitalRainFontTexture.
|
|
120
|
+
* @returns the clone of the texture.
|
|
121
|
+
*/
|
|
122
|
+
clone() {
|
|
123
|
+
return new DigitalRainFontTexture(this.name, this._font, this._text, this.getScene());
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Parses a json object representing the texture and returns an instance of it.
|
|
127
|
+
* @param source the source JSON representation
|
|
128
|
+
* @param scene the scene to create the texture for
|
|
129
|
+
* @returns the parsed texture
|
|
130
|
+
*/
|
|
131
|
+
static Parse(source, scene) {
|
|
132
|
+
const texture = SerializationHelper.Parse(() => new DigitalRainFontTexture(source.name, source.font, source.text, scene), source, scene, null);
|
|
133
|
+
return texture;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
__decorate([
|
|
137
|
+
serialize("font")
|
|
138
|
+
], DigitalRainFontTexture.prototype, "_font", void 0);
|
|
139
|
+
__decorate([
|
|
140
|
+
serialize("text")
|
|
141
|
+
], DigitalRainFontTexture.prototype, "_text", void 0);
|
|
142
|
+
/**
|
|
143
|
+
* DigitalRainPostProcess helps rendering everithing in digital rain.
|
|
144
|
+
*
|
|
145
|
+
* Simmply add it to your scene and let the nerd that lives in you have fun.
|
|
146
|
+
* Example usage: var pp = new DigitalRainPostProcess("digitalRain", "20px Monospace", camera);
|
|
147
|
+
*/
|
|
148
|
+
export class DigitalRainPostProcess extends PostProcess {
|
|
149
|
+
/**
|
|
150
|
+
* Instantiates a new Digital Rain Post Process.
|
|
151
|
+
* @param name the name to give to the postprocess
|
|
152
|
+
* @camera the camera to apply the post process to.
|
|
153
|
+
* @param camera
|
|
154
|
+
* @param options can either be the font name or an option object following the IDigitalRainPostProcessOptions format
|
|
155
|
+
*/
|
|
156
|
+
constructor(name, camera, options) {
|
|
157
|
+
super(name, "digitalrain", ["digitalRainFontInfos", "digitalRainOptions", "cosTimeZeroOne", "matrixSpeed"], ["digitalRainFont"], 1.0, camera, Texture.TRILINEAR_SAMPLINGMODE, undefined, true);
|
|
158
|
+
/**
|
|
159
|
+
* This defines the amount you want to mix the "tile" or caracter space colored in the digital rain.
|
|
160
|
+
* This number is defined between 0 and 1;
|
|
161
|
+
*/
|
|
162
|
+
this.mixToTile = 0;
|
|
163
|
+
/**
|
|
164
|
+
* This defines the amount you want to mix the normal rendering pass in the digital rain.
|
|
165
|
+
* This number is defined between 0 and 1;
|
|
166
|
+
*/
|
|
167
|
+
this.mixToNormal = 0;
|
|
168
|
+
/**
|
|
169
|
+
* Speed of the effect
|
|
170
|
+
*/
|
|
171
|
+
this.speed = 0.003;
|
|
172
|
+
// Default values.
|
|
173
|
+
let font = "15px Monospace";
|
|
174
|
+
const characterSet = "古池や蛙飛び込む水の音ふるいけやかわずとびこむみずのおと初しぐれ猿も小蓑をほしげ也はつしぐれさるもこみのをほしげなり江戸の雨何石呑んだ時鳥えどのあめなんごくのんだほととぎす";
|
|
175
|
+
// Use options.
|
|
176
|
+
if (options) {
|
|
177
|
+
if (typeof options === "string") {
|
|
178
|
+
font = options;
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
font = options.font || font;
|
|
182
|
+
this.mixToTile = options.mixToTile || this.mixToTile;
|
|
183
|
+
this.mixToNormal = options.mixToNormal || this.mixToNormal;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const scene = camera?.getScene() || null;
|
|
187
|
+
this._digitalRainFontTexture = new DigitalRainFontTexture(name, font, characterSet, scene);
|
|
188
|
+
const textureSize = this._digitalRainFontTexture.getSize();
|
|
189
|
+
let alpha = 0.0;
|
|
190
|
+
let cosTimeZeroOne = 0.0;
|
|
191
|
+
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());
|
|
192
|
+
this.onApply = (effect) => {
|
|
193
|
+
effect.setTexture("digitalRainFont", this._digitalRainFontTexture);
|
|
194
|
+
effect.setFloat4("digitalRainFontInfos", this._digitalRainFontTexture.charSize, characterSet.length, textureSize.width, textureSize.height);
|
|
195
|
+
effect.setFloat4("digitalRainOptions", this.width, this.height, this.mixToNormal, this.mixToTile);
|
|
196
|
+
effect.setMatrix("matrixSpeed", matrix);
|
|
197
|
+
alpha += this.speed;
|
|
198
|
+
cosTimeZeroOne = alpha;
|
|
199
|
+
effect.setFloat("cosTimeZeroOne", cosTimeZeroOne);
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=digitalRainPostProcess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"digitalRainPostProcess.js","sourceRoot":"","sources":["../../../../dev/postProcesses/src/digitalRain/digitalRainPostProcess.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,2CAA6B;AACjD,OAAO,EAAE,mBAAmB,EAAE,yDAA2C;AACzE,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;IASnD;;OAEG;IACH,IAAW,QAAQ;QACf,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAED;;;;;;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,CAAC;YACT,OAAO;QACX,CAAC;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;QACvC,IAAI,CAAC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AAC,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 } from \"core/Misc/decorators\";\r\nimport { SerializationHelper } from \"core/Misc/decorators.serialization\";\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 * @returns 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 * @returns 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 * @returns the clone of the texture.\r\n */\r\n public override 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 * @returns 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: Nullable<Camera>, options?: string | IDigitalRainPostProcessOptions) {\r\n super(\r\n name,\r\n \"digitalrain\",\r\n [\"digitalRainFontInfos\", \"digitalRainOptions\", \"cosTimeZeroOne\", \"matrixSpeed\"],\r\n [\"digitalRainFont\"],\r\n 1.0,\r\n camera,\r\n Texture.TRILINEAR_SAMPLINGMODE,\r\n undefined,\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 = options;\r\n } else {\r\n font = options.font || font;\r\n this.mixToTile = options.mixToTile || this.mixToTile;\r\n this.mixToNormal = options.mixToNormal || this.mixToNormal;\r\n }\r\n }\r\n\r\n const scene = camera?.getScene() || null;\r\n this._digitalRainFontTexture = new DigitalRainFontTexture(name, font, characterSet, scene);\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"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Do not edit.
|
|
2
|
+
import { ShaderStore } from "@babylonjs/core/Engines/shaderStore.js";
|
|
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;}`;
|
|
10
|
+
// Sideeffect
|
|
11
|
+
if (!ShaderStore.ShadersStore[name]) {
|
|
12
|
+
ShaderStore.ShadersStore[name] = shader;
|
|
13
|
+
}
|
|
14
|
+
/** @internal */
|
|
15
|
+
export const digitalrainPixelShader = { name, shader };
|
|
16
|
+
//# sourceMappingURL=digitalrain.fragment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"digitalrain.fragment.js","sourceRoot":"","sources":["../../../../dev/postProcesses/src/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,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;IAClC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAC5C,CAAC;AACD,gBAAgB;AAChB,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\nif (!ShaderStore.ShadersStore[name]) {\n ShaderStore.ShadersStore[name] = shader;\n}\n/** @internal */\nexport const digitalrainPixelShader = { name, shader };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./digitalRainPostProcess.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../dev/postProcesses/src/digitalRain/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAC","sourcesContent":["export * from \"./digitalRainPostProcess\";\r\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Do not edit.
|
|
2
|
+
import { ShaderStore } from "@babylonjs/core/Engines/shaderStore.js";
|
|
3
|
+
const name = "edgeDetectionPixelShader";
|
|
4
|
+
const shader = `precision highp float;varying vec2 vUV;uniform sampler2D textureSampler;uniform sampler2D normalSampler;uniform sampler2D depthSampler;uniform float width;uniform float height;uniform vec3 edgeColor;uniform float edgeIntensity;uniform float edgeWidth;uniform int renderMode;
|
|
5
|
+
vec3 boxBlur(sampler2D sampler,vec2 uv,vec2 texelSize) {vec3 result=vec3(0.0);for (int x=-1; x<=1; x++) {for (int y=-1; y<=1; y++) {vec2 offset=vec2(float(x),float(y))*texelSize;result+=texture2D(sampler,uv+offset).rgb;}}
|
|
6
|
+
return result/9.0;}
|
|
7
|
+
void main(void) {vec2 texelSize=vec2(1.0/width,1.0/height);vec3 originalColor=texture2D(textureSampler,vUV).rgb;if (renderMode==1 || renderMode==2 || renderMode==3) {if (length(originalColor)==0.0) {originalColor=vec3(1.0,1.0,1.0); }
|
|
8
|
+
if (originalColor.r==1.0 && originalColor.g==0.0 && originalColor.b==0.0) {originalColor=vec3(1.0,1.0,1.0); }}
|
|
9
|
+
vec3 normal=texture2D(normalSampler,vUV).rgb;float depth=texture2D(depthSampler,vUV).r;float edgeStrength=0.0;int range=int(edgeWidth*8.0);
|
|
10
|
+
for (int x=-range; x<=range; x++) {for (int y=-range; y<=range; y++) {if (x==0 && y==0) {continue;}
|
|
11
|
+
vec3 neighborNormal=texture2D(normalSampler,vUV+texelSize*vec2(float(x),float(y))).rgb;float neighborDepth=texture2D(depthSampler,vUV+texelSize*vec2(float(x),float(y))).r;float normalDiff=length(neighborNormal-normal);float depthDiff=abs(neighborDepth-depth);edgeStrength=max(edgeStrength,max(normalDiff,depthDiff));}}
|
|
12
|
+
edgeStrength=smoothstep(edgeWidth,edgeWidth+edgeIntensity,edgeStrength);vec3 finalColor=mix(originalColor,edgeColor,edgeStrength);gl_FragColor=vec4(finalColor,1.0);}`;
|
|
13
|
+
// Sideeffect
|
|
14
|
+
if (!ShaderStore.ShadersStore[name]) {
|
|
15
|
+
ShaderStore.ShadersStore[name] = shader;
|
|
16
|
+
}
|
|
17
|
+
/** @internal */
|
|
18
|
+
export const edgeDetectionPixelShader = { name, shader };
|
|
19
|
+
//# sourceMappingURL=edgeDetection.fragment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edgeDetection.fragment.js","sourceRoot":"","sources":["../../../../dev/postProcesses/src/edgeDetection/edgeDetection.fragment.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,+CAAiC;AAEvD,MAAM,IAAI,GAAG,0BAA0B,CAAC;AACxC,MAAM,MAAM,GAAG;;;;;;;;sKAQuJ,CAAC;AACvK,aAAa;AACb,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;IAClC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAC5C,CAAC;AACD,gBAAgB;AAChB,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"core/Engines/shaderStore\";\n\nconst name = \"edgeDetectionPixelShader\";\nconst shader = `precision highp float;varying vec2 vUV;uniform sampler2D textureSampler;uniform sampler2D normalSampler;uniform sampler2D depthSampler;uniform float width;uniform float height;uniform vec3 edgeColor;uniform float edgeIntensity;uniform float edgeWidth;uniform int renderMode; \nvec3 boxBlur(sampler2D sampler,vec2 uv,vec2 texelSize) {vec3 result=vec3(0.0);for (int x=-1; x<=1; x++) {for (int y=-1; y<=1; y++) {vec2 offset=vec2(float(x),float(y))*texelSize;result+=texture2D(sampler,uv+offset).rgb;}}\nreturn result/9.0;}\nvoid main(void) {vec2 texelSize=vec2(1.0/width,1.0/height);vec3 originalColor=texture2D(textureSampler,vUV).rgb;if (renderMode==1 || renderMode==2 || renderMode==3) {if (length(originalColor)==0.0) {originalColor=vec3(1.0,1.0,1.0); }\nif (originalColor.r==1.0 && originalColor.g==0.0 && originalColor.b==0.0) {originalColor=vec3(1.0,1.0,1.0); }}\nvec3 normal=texture2D(normalSampler,vUV).rgb;float depth=texture2D(depthSampler,vUV).r;float edgeStrength=0.0;int range=int(edgeWidth*8.0); \nfor (int x=-range; x<=range; x++) {for (int y=-range; y<=range; y++) {if (x==0 && y==0) {continue;}\nvec3 neighborNormal=texture2D(normalSampler,vUV+texelSize*vec2(float(x),float(y))).rgb;float neighborDepth=texture2D(depthSampler,vUV+texelSize*vec2(float(x),float(y))).r;float normalDiff=length(neighborNormal-normal);float depthDiff=abs(neighborDepth-depth);edgeStrength=max(edgeStrength,max(normalDiff,depthDiff));}}\nedgeStrength=smoothstep(edgeWidth,edgeWidth+edgeIntensity,edgeStrength);vec3 finalColor=mix(originalColor,edgeColor,edgeStrength);gl_FragColor=vec4(finalColor,1.0);}`;\n// Sideeffect\nif (!ShaderStore.ShadersStore[name]) {\n ShaderStore.ShadersStore[name] = shader;\n}\n/** @internal */\nexport const edgeDetectionPixelShader = { name, shader };\n"]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Nullable } from "@babylonjs/core/types.js";
|
|
2
|
+
import type { Camera } from "@babylonjs/core/Cameras/camera.js";
|
|
3
|
+
import type { PostProcessOptions } from "@babylonjs/core/PostProcesses/postProcess.js";
|
|
4
|
+
import { PostProcess } from "@babylonjs/core/PostProcesses/postProcess.js";
|
|
5
|
+
import "@babylonjs/core/Rendering/geometryBufferRendererSceneComponent.js";
|
|
6
|
+
import { Color3 } from "@babylonjs/core/Maths/math.color.js";
|
|
7
|
+
import type { Scene } from "@babylonjs/core/scene.js";
|
|
8
|
+
import "./edgeDetection.fragment.js";
|
|
9
|
+
/**
|
|
10
|
+
* The Edge Detection effect highlights the edges of objects in the scene like a toon.
|
|
11
|
+
* This can be used for stylized rendering, outlining, or visual effects that require edge enhancement.
|
|
12
|
+
*/
|
|
13
|
+
export declare class EdgeDetectionPostProcess extends PostProcess {
|
|
14
|
+
/**
|
|
15
|
+
* Defines the color of the detected edges.
|
|
16
|
+
*/
|
|
17
|
+
edgeColor: Color3;
|
|
18
|
+
/**
|
|
19
|
+
* Defines the intensity of the detected edges.
|
|
20
|
+
* Higher values result in more pronounced edges.
|
|
21
|
+
* default: 0.2 (min:0, max:1)
|
|
22
|
+
*/
|
|
23
|
+
edgeIntensity: number;
|
|
24
|
+
/**
|
|
25
|
+
* Defines the width of the detected edges.
|
|
26
|
+
* Higher values result in thicker edges.
|
|
27
|
+
* default: 0.2 (min:0.125, max:1)
|
|
28
|
+
*/
|
|
29
|
+
edgeWidth: number;
|
|
30
|
+
/**
|
|
31
|
+
* Defines the render mode.
|
|
32
|
+
* default: 0
|
|
33
|
+
* 0: general, 1: normal, 2: depth, 3: outline only
|
|
34
|
+
*/
|
|
35
|
+
renderMode: number;
|
|
36
|
+
private _geometryBufferRenderer;
|
|
37
|
+
/**
|
|
38
|
+
* Get the current class name of the current effect
|
|
39
|
+
* @returns "EdgeDetectionPostProcess"
|
|
40
|
+
*/
|
|
41
|
+
getClassName(): string;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new instance of EdgeDetectionPostProcess.
|
|
44
|
+
* @param name The name of the effect.
|
|
45
|
+
* @param scene The scene where the edge detection post-process will be applied.
|
|
46
|
+
* @param options The required width/height ratio or specific options for the post-process.
|
|
47
|
+
* @param camera The camera to apply the post-process to.
|
|
48
|
+
* @param samplingMode The sampling mode to be used when computing the pass. (default: TEXTURE_NEAREST_NEAREST)
|
|
49
|
+
* @param reusable If the post-process can be reused on the same frame. (default: false)
|
|
50
|
+
* @param textureType The type of textures used when performing the post-process. (default: TEXTURETYPE_HALF_FLOAT)
|
|
51
|
+
*/
|
|
52
|
+
constructor(name: string, scene: Scene, options: number | PostProcessOptions, camera: Nullable<Camera>, samplingMode?: number, reusable?: boolean, textureType?: number);
|
|
53
|
+
/**
|
|
54
|
+
* Support test.
|
|
55
|
+
*/
|
|
56
|
+
static get IsSupported(): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* @internal
|
|
59
|
+
*/
|
|
60
|
+
static _Parse(parsedPostProcess: any, targetCamera: Camera, scene: Scene, rootUrl: string): EdgeDetectionPostProcess;
|
|
61
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { __decorate } from "@babylonjs/core/tslib.es6.js";
|
|
2
|
+
import { Logger } from "@babylonjs/core/Misc/logger.js";
|
|
3
|
+
import { PostProcess } from "@babylonjs/core/PostProcesses/postProcess.js";
|
|
4
|
+
import { Constants } from "@babylonjs/core/Engines/constants.js";
|
|
5
|
+
import "@babylonjs/core/Rendering/geometryBufferRendererSceneComponent.js";
|
|
6
|
+
import { Color3 } from "@babylonjs/core/Maths/math.color.js";
|
|
7
|
+
import { serialize } from "@babylonjs/core/Misc/decorators.js";
|
|
8
|
+
import { SerializationHelper } from "@babylonjs/core/Misc/decorators.serialization.js";
|
|
9
|
+
import { RegisterClass } from "@babylonjs/core/Misc/typeStore.js";
|
|
10
|
+
import { EngineStore } from "@babylonjs/core/Engines/engineStore.js";
|
|
11
|
+
import { RenderTargetTexture } from "@babylonjs/core/Materials/Textures/renderTargetTexture.js";
|
|
12
|
+
import "./edgeDetection.fragment.js";
|
|
13
|
+
/**
|
|
14
|
+
* The Edge Detection effect highlights the edges of objects in the scene like a toon.
|
|
15
|
+
* This can be used for stylized rendering, outlining, or visual effects that require edge enhancement.
|
|
16
|
+
*/
|
|
17
|
+
export class EdgeDetectionPostProcess extends PostProcess {
|
|
18
|
+
/**
|
|
19
|
+
* Get the current class name of the current effect
|
|
20
|
+
* @returns "EdgeDetectionPostProcess"
|
|
21
|
+
*/
|
|
22
|
+
getClassName() {
|
|
23
|
+
return "EdgeDetectionPostProcess";
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new instance of EdgeDetectionPostProcess.
|
|
27
|
+
* @param name The name of the effect.
|
|
28
|
+
* @param scene The scene where the edge detection post-process will be applied.
|
|
29
|
+
* @param options The required width/height ratio or specific options for the post-process.
|
|
30
|
+
* @param camera The camera to apply the post-process to.
|
|
31
|
+
* @param samplingMode The sampling mode to be used when computing the pass. (default: TEXTURE_NEAREST_NEAREST)
|
|
32
|
+
* @param reusable If the post-process can be reused on the same frame. (default: false)
|
|
33
|
+
* @param textureType The type of textures used when performing the post-process. (default: TEXTURETYPE_HALF_FLOAT)
|
|
34
|
+
*/
|
|
35
|
+
constructor(name, scene, options, camera, samplingMode, reusable, textureType = Constants.TEXTURETYPE_UNSIGNED_BYTE) {
|
|
36
|
+
super(name, "edgeDetection", ["width", "height", "edgeColor", "edgeIntensity", "edgeWidth", "renderMode"], ["normalSampler", "depthSampler"], options, camera, samplingMode, scene.getEngine(), reusable, null, textureType);
|
|
37
|
+
/**
|
|
38
|
+
* Defines the color of the detected edges.
|
|
39
|
+
*/
|
|
40
|
+
this.edgeColor = new Color3(0, 0, 0);
|
|
41
|
+
/**
|
|
42
|
+
* Defines the intensity of the detected edges.
|
|
43
|
+
* Higher values result in more pronounced edges.
|
|
44
|
+
* default: 0.2 (min:0, max:1)
|
|
45
|
+
*/
|
|
46
|
+
this.edgeIntensity = 0.2;
|
|
47
|
+
/**
|
|
48
|
+
* Defines the width of the detected edges.
|
|
49
|
+
* Higher values result in thicker edges.
|
|
50
|
+
* default: 0.2 (min:0.125, max:1)
|
|
51
|
+
*/
|
|
52
|
+
this.edgeWidth = 0.2;
|
|
53
|
+
/**
|
|
54
|
+
* Defines the render mode.
|
|
55
|
+
* default: 0
|
|
56
|
+
* 0: general, 1: normal, 2: depth, 3: outline only
|
|
57
|
+
*/
|
|
58
|
+
this.renderMode = 0;
|
|
59
|
+
this._geometryBufferRenderer = scene.enableGeometryBufferRenderer();
|
|
60
|
+
if (!this._geometryBufferRenderer) {
|
|
61
|
+
// Geometry buffer renderer is not supported. So, work as a passthrough.
|
|
62
|
+
Logger.Error("Geometry Buffer Renderer support is required for this post-process.");
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const h1 = new RenderTargetTexture("h1", { width: this.width, height: this.height }, scene, {
|
|
66
|
+
samplingMode: Constants.TEXTURE_NEAREST_NEAREST,
|
|
67
|
+
generateMipMaps: false,
|
|
68
|
+
generateDepthBuffer: false,
|
|
69
|
+
type: Constants.TEXTURETYPE_HALF_FLOAT,
|
|
70
|
+
});
|
|
71
|
+
// Geometry buffer renderer is supported.
|
|
72
|
+
this.onApply = (effect) => {
|
|
73
|
+
effect.setFloat("width", this.width);
|
|
74
|
+
effect.setFloat("height", this.height);
|
|
75
|
+
effect.setFloat("edgeIntensity", this.edgeIntensity);
|
|
76
|
+
effect.setFloat("edgeWidth", this.edgeWidth);
|
|
77
|
+
effect.setColor3("edgeColor", this.edgeColor);
|
|
78
|
+
const normalTexture = this._geometryBufferRenderer.getGBuffer().textures[1];
|
|
79
|
+
const depthTexture = this._geometryBufferRenderer.getGBuffer().textures[0];
|
|
80
|
+
effect.setTexture("normalSampler", normalTexture);
|
|
81
|
+
effect.setTexture("depthSampler", depthTexture);
|
|
82
|
+
switch (this.renderMode) {
|
|
83
|
+
case 0:
|
|
84
|
+
break;
|
|
85
|
+
case 1:
|
|
86
|
+
effect.setTexture("textureSampler", this._geometryBufferRenderer.getGBuffer().textures[1]);
|
|
87
|
+
effect.setFloat("edgeWidth", 0);
|
|
88
|
+
break;
|
|
89
|
+
case 2:
|
|
90
|
+
effect.setTexture("textureSampler", this._geometryBufferRenderer.getGBuffer().textures[0]);
|
|
91
|
+
effect.setFloat("edgeWidth", 0);
|
|
92
|
+
break;
|
|
93
|
+
case 3:
|
|
94
|
+
effect.setTexture("textureSampler", h1);
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
effect.setInt("renderMode", this.renderMode);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Support test.
|
|
103
|
+
*/
|
|
104
|
+
static get IsSupported() {
|
|
105
|
+
const engine = EngineStore.LastCreatedEngine;
|
|
106
|
+
if (!engine) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
return engine.getCaps().drawBuffersExtension;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* @internal
|
|
113
|
+
*/
|
|
114
|
+
static _Parse(parsedPostProcess, targetCamera, scene, rootUrl) {
|
|
115
|
+
return SerializationHelper.Parse(() => new EdgeDetectionPostProcess(parsedPostProcess.name, scene, parsedPostProcess.options, targetCamera, parsedPostProcess.renderTargetSamplingMode, parsedPostProcess.textureType, parsedPostProcess.reusable), parsedPostProcess, scene, rootUrl);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
__decorate([
|
|
119
|
+
serialize()
|
|
120
|
+
], EdgeDetectionPostProcess.prototype, "edgeColor", void 0);
|
|
121
|
+
__decorate([
|
|
122
|
+
serialize()
|
|
123
|
+
], EdgeDetectionPostProcess.prototype, "edgeIntensity", void 0);
|
|
124
|
+
__decorate([
|
|
125
|
+
serialize()
|
|
126
|
+
], EdgeDetectionPostProcess.prototype, "edgeWidth", void 0);
|
|
127
|
+
__decorate([
|
|
128
|
+
serialize()
|
|
129
|
+
], EdgeDetectionPostProcess.prototype, "renderMode", void 0);
|
|
130
|
+
RegisterClass("BABYLON.EdgeDetectionPostProcess", EdgeDetectionPostProcess);
|
|
131
|
+
//# sourceMappingURL=edgeDetectionPostProcess.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edgeDetectionPostProcess.js","sourceRoot":"","sources":["../../../../dev/postProcesses/src/edgeDetection/edgeDetectionPostProcess.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,uCAAyB;AAI1C,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAC7D,OAAO,EAAE,SAAS,EAAE,6CAA+B;AACnD,2EAA6D;AAE7D,OAAO,EAAE,MAAM,EAAE,4CAA8B;AAC/C,OAAO,EAAE,SAAS,EAAE,2CAA6B;AACjD,OAAO,EAAE,mBAAmB,EAAE,yDAA2C;AACzE,OAAO,EAAE,aAAa,EAAE,0CAA4B;AACpD,OAAO,EAAE,WAAW,EAAE,+CAAiC;AACvD,OAAO,EAAE,mBAAmB,EAAE,kEAAoD;AAElF,OAAO,0BAA0B,CAAC;AAElC;;;GAGG;AACH,MAAM,OAAO,wBAAyB,SAAQ,WAAW;IAiCrD;;;OAGG;IACa,YAAY;QACxB,OAAO,0BAA0B,CAAC;IACtC,CAAC;IAED;;;;;;;;;OASG;IACH,YACI,IAAY,EACZ,KAAY,EACZ,OAAoC,EACpC,MAAwB,EACxB,YAAqB,EACrB,QAAkB,EAClB,cA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CAAC,YAAY,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;YACjD,CAAC,CAAC;QACN,CAAC;IACL,CAAC;IAED;;OAEG;IACI,MAAM,KAAK,WAAW;QACzB,MAAM,MAAM,GAAG,WAAW,CAAC,iBAAiB,CAAC;QAC7C,IAAI,CAAC,MAAM,EAAE,CAAC;YACV,OAAO,KAAK,CAAC;QACjB,CAAC;QAED,OAAO,MAAM,CAAC,OAAO,EAAE,CAAC,oBAAoB,CAAC;IACjD,CAAC;IAED;;OAEG;IACI,MAAM,CAAU,MAAM,CAAC,iBAAsB,EAAE,YAAoB,EAAE,KAAY,EAAE,OAAe;QACrG,OAAO,mBAAmB,CAAC,KAAK,CAC5B,GAAG,EAAE,CACD,IAAI,wBAAwB,CACxB,iBAAiB,CAAC,IAAI,EACtB,KAAK,EACL,iBAAiB,CAAC,OAAO,EACzB,YAAY,EACZ,iBAAiB,CAAC,wBAAwB,EAC1C,iBAAiB,CAAC,WAAW,EAC7B,iBAAiB,CAAC,QAAQ,CAC7B,EACL,iBAAiB,EACjB,KAAK,EACL,OAAO,CACV,CAAC;IACN,CAAC;CACJ;AApJU;IADN,SAAS,EAAE;2DACmC;AAQxC;IADN,SAAS,EAAE;+DACuB;AAQ5B;IADN,SAAS,EAAE;2DACmB;AAQxB;IADN,SAAS,EAAE;4DACkB;AA8HlC,aAAa,CAAC,kCAAkC,EAAE,wBAAwB,CAAC,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport type { Camera } from \"core/Cameras/camera\";\r\nimport type { Effect } from \"core/Materials/effect\";\r\nimport type { PostProcessOptions } from \"core/PostProcesses/postProcess\";\r\nimport { PostProcess } from \"core/PostProcesses/postProcess\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport \"core/Rendering/geometryBufferRendererSceneComponent\";\r\nimport type { GeometryBufferRenderer } from \"core/Rendering/geometryBufferRenderer\";\r\nimport { Color3 } from \"core/Maths/math.color\";\r\nimport { serialize } from \"core/Misc/decorators\";\r\nimport { SerializationHelper } from \"core/Misc/decorators.serialization\";\r\nimport { RegisterClass } from \"core/Misc/typeStore\";\r\nimport { EngineStore } from \"core/Engines/engineStore\";\r\nimport { RenderTargetTexture } from \"core/Materials/Textures/renderTargetTexture\";\r\nimport type { Scene } from \"core/scene\";\r\nimport \"./edgeDetection.fragment\";\r\n\r\n/**\r\n * The Edge Detection effect highlights the edges of objects in the scene like a toon.\r\n * This can be used for stylized rendering, outlining, or visual effects that require edge enhancement.\r\n */\r\nexport class EdgeDetectionPostProcess extends PostProcess {\r\n /**\r\n * Defines the color of the detected edges.\r\n */\r\n @serialize()\r\n public edgeColor: Color3 = new Color3(0, 0, 0);\r\n\r\n /**\r\n * Defines the intensity of the detected edges.\r\n * Higher values result in more pronounced edges.\r\n * default: 0.2 (min:0, max:1)\r\n */\r\n @serialize()\r\n public edgeIntensity: number = 0.2;\r\n\r\n /**\r\n * Defines the width of the detected edges.\r\n * Higher values result in thicker edges.\r\n * default: 0.2 (min:0.125, max:1)\r\n */\r\n @serialize()\r\n public edgeWidth: number = 0.2;\r\n\r\n /**\r\n * Defines the render mode.\r\n * default: 0\r\n * 0: general, 1: normal, 2: depth, 3: outline only\r\n */\r\n @serialize()\r\n public renderMode: number = 0;\r\n\r\n private _geometryBufferRenderer: Nullable<GeometryBufferRenderer>;\r\n\r\n /**\r\n * Get the current class name of the current effect\r\n * @returns \"EdgeDetectionPostProcess\"\r\n */\r\n public override getClassName(): string {\r\n return \"EdgeDetectionPostProcess\";\r\n }\r\n\r\n /**\r\n * Creates a new instance of EdgeDetectionPostProcess.\r\n * @param name The name of the effect.\r\n * @param scene The scene where the edge detection post-process will be applied.\r\n * @param options The required width/height ratio or specific options for the post-process.\r\n * @param camera The camera to apply the post-process to.\r\n * @param samplingMode The sampling mode to be used when computing the pass. (default: TEXTURE_NEAREST_NEAREST)\r\n * @param reusable If the post-process can be reused on the same frame. (default: false)\r\n * @param textureType The type of textures used when performing the post-process. (default: TEXTURETYPE_HALF_FLOAT)\r\n */\r\n constructor(\r\n name: string,\r\n scene: Scene,\r\n options: number | PostProcessOptions,\r\n camera: Nullable<Camera>,\r\n samplingMode?: number,\r\n reusable?: boolean,\r\n textureType: number = Constants.TEXTURETYPE_UNSIGNED_BYTE\r\n ) {\r\n super(\r\n name,\r\n \"edgeDetection\",\r\n [\"width\", \"height\", \"edgeColor\", \"edgeIntensity\", \"edgeWidth\", \"renderMode\"],\r\n [\"normalSampler\", \"depthSampler\"],\r\n options,\r\n camera,\r\n samplingMode,\r\n scene.getEngine(),\r\n reusable,\r\n null,\r\n textureType\r\n );\r\n\r\n this._geometryBufferRenderer = scene.enableGeometryBufferRenderer();\r\n\r\n if (!this._geometryBufferRenderer) {\r\n // Geometry buffer renderer is not supported. So, work as a passthrough.\r\n Logger.Error(\"Geometry Buffer Renderer support is required for this post-process.\");\r\n } else {\r\n const h1 = new RenderTargetTexture(\"h1\", { width: this.width, height: this.height }, scene, {\r\n samplingMode: Constants.TEXTURE_NEAREST_NEAREST,\r\n generateMipMaps: false,\r\n generateDepthBuffer: false,\r\n type: Constants.TEXTURETYPE_HALF_FLOAT,\r\n });\r\n\r\n // Geometry buffer renderer is supported.\r\n this.onApply = (effect: Effect) => {\r\n effect.setFloat(\"width\", this.width);\r\n effect.setFloat(\"height\", this.height);\r\n effect.setFloat(\"edgeIntensity\", this.edgeIntensity);\r\n effect.setFloat(\"edgeWidth\", this.edgeWidth);\r\n effect.setColor3(\"edgeColor\", this.edgeColor);\r\n\r\n const normalTexture = this._geometryBufferRenderer!.getGBuffer().textures[1];\r\n const depthTexture = this._geometryBufferRenderer!.getGBuffer().textures[0];\r\n\r\n effect.setTexture(\"normalSampler\", normalTexture);\r\n effect.setTexture(\"depthSampler\", depthTexture);\r\n\r\n switch (this.renderMode) {\r\n case 0:\r\n break;\r\n case 1:\r\n effect.setTexture(\"textureSampler\", this._geometryBufferRenderer!.getGBuffer().textures[1]);\r\n effect.setFloat(\"edgeWidth\", 0);\r\n break;\r\n case 2:\r\n effect.setTexture(\"textureSampler\", this._geometryBufferRenderer!.getGBuffer().textures[0]);\r\n effect.setFloat(\"edgeWidth\", 0);\r\n break;\r\n case 3:\r\n effect.setTexture(\"textureSampler\", h1);\r\n break;\r\n }\r\n effect.setInt(\"renderMode\", this.renderMode);\r\n };\r\n }\r\n }\r\n\r\n /**\r\n * Support test.\r\n */\r\n public static get IsSupported(): boolean {\r\n const engine = EngineStore.LastCreatedEngine;\r\n if (!engine) {\r\n return false;\r\n }\r\n\r\n return engine.getCaps().drawBuffersExtension;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public static override _Parse(parsedPostProcess: any, targetCamera: Camera, scene: Scene, rootUrl: string) {\r\n return SerializationHelper.Parse(\r\n () =>\r\n new EdgeDetectionPostProcess(\r\n parsedPostProcess.name,\r\n scene,\r\n parsedPostProcess.options,\r\n targetCamera,\r\n parsedPostProcess.renderTargetSamplingMode,\r\n parsedPostProcess.textureType,\r\n parsedPostProcess.reusable\r\n ),\r\n parsedPostProcess,\r\n scene,\r\n rootUrl\r\n );\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.EdgeDetectionPostProcess\", EdgeDetectionPostProcess);\r\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./edgeDetectionPostProcess.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../dev/postProcesses/src/edgeDetection/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAC","sourcesContent":["export * from \"./edgeDetectionPostProcess\";\r\n"]}
|
package/index.d.ts
ADDED
package/index.js
ADDED
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../dev/postProcesses/src/index.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-restricted-imports */\r\nexport * from \"./asciiArt/index\";\r\nexport * from \"./digitalRain/index\";\r\nexport * from \"./edgeDetection/index\";\r\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../asciiArt/index.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-restricted-imports */
|
|
2
|
+
import * as postProcessLibrary from "../asciiArt/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* This is the entry point for the UMD module.
|
|
5
|
+
* The entry point for a future ESM package should be index.ts
|
|
6
|
+
*/
|
|
7
|
+
const globalObject = typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : undefined;
|
|
8
|
+
if (typeof globalObject !== "undefined") {
|
|
9
|
+
for (const key in postProcessLibrary) {
|
|
10
|
+
globalObject.BABYLON[key] = postProcessLibrary[key];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export * from "../asciiArt/index.js";
|
|
14
|
+
//# sourceMappingURL=legacy-asciiArt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy-asciiArt.js","sourceRoot":"","sources":["../../../../lts/postProcesses/src/legacy/legacy-asciiArt.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,OAAO,KAAK,kBAAkB,6BAAsC;AAEpE;;;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,CAAC;IACtC,KAAK,MAAM,GAAG,IAAI,kBAAkB,EAAE,CAAC;QAC7B,YAAa,CAAC,OAAO,CAAC,GAAG,CAAC,GAAS,kBAAmB,CAAC,GAAG,CAAC,CAAC;IACtE,CAAC;AACL,CAAC;AAED,qCAA8C","sourcesContent":["/* eslint-disable @typescript-eslint/no-restricted-imports */\r\nimport * as postProcessLibrary from \"post-processes/asciiArt/index\";\r\n\r\n/**\r\n * This is the entry point for the UMD module.\r\n * The entry point for a future ESM package should be index.ts\r\n */\r\nconst globalObject = typeof global !== \"undefined\" ? global : typeof window !== \"undefined\" ? window : undefined;\r\nif (typeof globalObject !== \"undefined\") {\r\n for (const key in postProcessLibrary) {\r\n (<any>globalObject).BABYLON[key] = (<any>postProcessLibrary)[key];\r\n }\r\n}\r\n\r\nexport * from \"post-processes/asciiArt/index\";\r\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../digitalRain/index.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-restricted-imports */
|
|
2
|
+
import * as postProcessLibrary from "../digitalRain/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* This is the entry point for the UMD module.
|
|
5
|
+
* The entry point for a future ESM package should be index.ts
|
|
6
|
+
*/
|
|
7
|
+
const globalObject = typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : undefined;
|
|
8
|
+
if (typeof globalObject !== "undefined") {
|
|
9
|
+
for (const key in postProcessLibrary) {
|
|
10
|
+
globalObject.BABYLON[key] = postProcessLibrary[key];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export * from "../digitalRain/index.js";
|
|
14
|
+
//# sourceMappingURL=legacy-digitalRain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"legacy-digitalRain.js","sourceRoot":"","sources":["../../../../lts/postProcesses/src/legacy/legacy-digitalRain.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,OAAO,KAAK,kBAAkB,gCAAyC;AAEvE;;;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,CAAC;IACtC,KAAK,MAAM,GAAG,IAAI,kBAAkB,EAAE,CAAC;QAC7B,YAAa,CAAC,OAAO,CAAC,GAAG,CAAC,GAAS,kBAAmB,CAAC,GAAG,CAAC,CAAC;IACtE,CAAC;AACL,CAAC;AAED,wCAAiD","sourcesContent":["/* eslint-disable @typescript-eslint/no-restricted-imports */\r\nimport * as postProcessLibrary from \"post-processes/digitalRain/index\";\r\n\r\n/**\r\n * This is the entry point for the UMD module.\r\n * The entry point for a future ESM package should be index.ts\r\n */\r\nconst globalObject = typeof global !== \"undefined\" ? global : typeof window !== \"undefined\" ? window : undefined;\r\nif (typeof globalObject !== \"undefined\") {\r\n for (const key in postProcessLibrary) {\r\n (<any>globalObject).BABYLON[key] = (<any>postProcessLibrary)[key];\r\n }\r\n}\r\n\r\nexport * from \"post-processes/digitalRain/index\";\r\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "../index.js";
|