@babylonjs/post-processes 5.0.0-beta.6 → 5.0.0-beta.8-snapshot
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 +6 -5
- package/asciiArt/asciiArtPostProcess.js +11 -10
- package/asciiArt/asciiArtPostProcess.js.map +1 -1
- package/asciiArt/asciiart.fragment.d.ts +1 -1
- package/asciiArt/asciiart.fragment.js +4 -2
- package/asciiArt/asciiart.fragment.js.map +1 -1
- package/asciiArt/index.js.map +1 -1
- package/digitalRain/digitalRainPostProcess.d.ts +6 -5
- package/digitalRain/digitalRainPostProcess.js +12 -11
- package/digitalRain/digitalRainPostProcess.js.map +1 -1
- package/digitalRain/digitalrain.fragment.d.ts +1 -1
- package/digitalRain/digitalrain.fragment.js +4 -2
- package/digitalRain/digitalrain.fragment.js.map +1 -1
- package/digitalRain/index.js.map +1 -1
- package/index.js.map +1 -1
- package/legacy/legacy-asciiArt.d.ts +1 -1
- package/legacy/legacy-asciiArt.js +3 -3
- package/legacy/legacy-asciiArt.js.map +1 -1
- package/legacy/legacy-digitalRain.d.ts +1 -1
- package/legacy/legacy-digitalRain.js +3 -3
- package/legacy/legacy-digitalRain.js.map +1 -1
- package/legacy/legacy.d.ts +1 -1
- package/legacy/legacy.js +3 -3
- package/legacy/legacy.js.map +1 -1
- package/package.json +21 -56
- package/readme.md +0 -31
@@ -1,8 +1,9 @@
|
|
1
|
-
import { Nullable } from "@babylonjs/core/types";
|
2
|
-
import { Camera } from "@babylonjs/core/Cameras/camera";
|
3
|
-
import { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture";
|
4
|
-
import { PostProcess } from "@babylonjs/core/PostProcesses/postProcess";
|
5
|
-
import { Scene } from "@babylonjs/core/scene";
|
1
|
+
import { Nullable } from "@babylonjs/core/types.js";
|
2
|
+
import { Camera } from "@babylonjs/core/Cameras/camera.js";
|
3
|
+
import { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
|
4
|
+
import { PostProcess } from "@babylonjs/core/PostProcesses/postProcess.js";
|
5
|
+
import { Scene } from "@babylonjs/core/scene.js";
|
6
|
+
import "@babylonjs/core/Engines/Extensions/engine.dynamicTexture.js";
|
6
7
|
import "./asciiart.fragment";
|
7
8
|
/**
|
8
9
|
* AsciiArtFontTexture is the helper class used to easily create your ascii art font texture.
|
@@ -3,6 +3,7 @@ import { serialize, SerializationHelper } from "@babylonjs/core/Misc/decorators.
|
|
3
3
|
import { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
|
4
4
|
import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
|
5
5
|
import { PostProcess } from "@babylonjs/core/PostProcesses/postProcess.js";
|
6
|
+
import "@babylonjs/core/Engines/Extensions/engine.dynamicTexture.js";
|
6
7
|
import "./asciiart.fragment.js";
|
7
8
|
/**
|
8
9
|
* AsciiArtFontTexture is the helper class used to easily create your ascii art font texture.
|
@@ -77,8 +78,8 @@ var AsciiArtFontTexture = /** @class */ (function (_super) {
|
|
77
78
|
*/
|
78
79
|
AsciiArtFontTexture.prototype.getFontWidth = function (font) {
|
79
80
|
var fontDraw = document.createElement("canvas");
|
80
|
-
var ctx = fontDraw.getContext(
|
81
|
-
ctx.fillStyle =
|
81
|
+
var ctx = fontDraw.getContext("2d");
|
82
|
+
ctx.fillStyle = "white";
|
82
83
|
ctx.font = font;
|
83
84
|
return ctx.measureText("W").width;
|
84
85
|
};
|
@@ -90,12 +91,12 @@ var AsciiArtFontTexture = /** @class */ (function (_super) {
|
|
90
91
|
*/
|
91
92
|
AsciiArtFontTexture.prototype.getFontHeight = function (font) {
|
92
93
|
var fontDraw = document.createElement("canvas");
|
93
|
-
var ctx = fontDraw.getContext(
|
94
|
+
var ctx = fontDraw.getContext("2d");
|
94
95
|
ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);
|
95
|
-
ctx.textBaseline =
|
96
|
-
ctx.fillStyle =
|
96
|
+
ctx.textBaseline = "top";
|
97
|
+
ctx.fillStyle = "white";
|
97
98
|
ctx.font = font;
|
98
|
-
ctx.fillText(
|
99
|
+
ctx.fillText("jH|", 0, 0);
|
99
100
|
var pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;
|
100
101
|
var start = -1;
|
101
102
|
var end = -1;
|
@@ -118,7 +119,7 @@ var AsciiArtFontTexture = /** @class */ (function (_super) {
|
|
118
119
|
}
|
119
120
|
}
|
120
121
|
}
|
121
|
-
return { height:
|
122
|
+
return { height: end - start + 1, offset: start - 1 };
|
122
123
|
};
|
123
124
|
/**
|
124
125
|
* Clones the current AsciiArtTexture.
|
@@ -161,9 +162,9 @@ var AsciiArtPostProcess = /** @class */ (function (_super) {
|
|
161
162
|
* @param options can either be the font name or an option object following the IAsciiArtPostProcessOptions format
|
162
163
|
*/
|
163
164
|
function AsciiArtPostProcess(name, camera, options) {
|
164
|
-
var _this = _super.call(this, name,
|
165
|
+
var _this = _super.call(this, name, "asciiart", ["asciiArtFontInfos", "asciiArtOptions"], ["asciiArtFont"], {
|
165
166
|
width: camera.getEngine().getRenderWidth(),
|
166
|
-
height: camera.getEngine().getRenderHeight()
|
167
|
+
height: camera.getEngine().getRenderHeight(),
|
167
168
|
}, camera, Texture.TRILINEAR_SAMPLINGMODE, camera.getEngine(), true) || this;
|
168
169
|
/**
|
169
170
|
* This defines the amount you want to mix the "tile" or caracter space colored in the ascii art.
|
@@ -180,7 +181,7 @@ var AsciiArtPostProcess = /** @class */ (function (_super) {
|
|
180
181
|
var characterSet = " `-.'_:,\"=^;<+!*?/cL\\zrs7TivJtC{3F)Il(xZfY5S2eajo14[nuyE]P6V9kXpKwGhqAUbOd8#HRDB0$mgMW&Q%N@";
|
181
182
|
// Use options.
|
182
183
|
if (options) {
|
183
|
-
if (typeof
|
184
|
+
if (typeof options === "string") {
|
184
185
|
font = options;
|
185
186
|
}
|
186
187
|
else {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"asciiArtP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AAI,WAAW,GAAG,KAAI,CAAC,oBAAoB,CAAC,OAAO,EAAE,CAAC;QAEtD,KAAI,CAAC,OAAO,GAAG,UAAC,MAAc;YAC1B,MAAM,CAAC,UAAU,CAAC,cAAc,EAAE,KAAI,CAAC,oBAAoB,CAAC,CAAC;YAE7D,MAAM,CAAC,SAAS,CAAC,mBAAmB,EAChC,KAAI,CAAC,oBAAoB,CAAC,QAAQ,EAClC,YAAY,CAAC,MAAM,EACnB,WAAW,CAAC,KAAK,EACjB,WAAW,CAAC,MAAM,CAAC,CAAC;YAExB,MAAM,CAAC,SAAS,CAAC,iBAAiB,EAC9B,KAAI,CAAC,KAAK,EACV,KAAI,CAAC,MAAM,EACX,KAAI,CAAC,WAAW,EAChB,KAAI,CAAC,SAAS,CAAC,CAAC;QACxB,CAAC,CAAC;;IACN,CAAC;IACL,0BAAC;AAAD,CAAC,AA3ED,CAAyC,WAAW,GA2EnD","sourcesContent":["import { Nullable } from \"@babylonjs/core/types\";\r\nimport { serialize, SerializationHelper } from \"@babylonjs/core/Misc/decorators\";\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\n\r\nimport \"./asciiart.fragment\";\r\n\r\n/**\r\n * AsciiArtFontTexture is the helper class used to easily create your ascii art font texture.\r\n *\r\n * It basically takes care rendering the font front the given font size to a texture.\r\n * This is used later on in the postprocess.\r\n */\r\nexport class AsciiArtFontTexture extends BaseTexture {\r\n\r\n @serialize(\"font\")\r\n private _font: string;\r\n\r\n @serialize(\"text\")\r\n private _text: string;\r\n\r\n private _charSize: number;\r\n\r\n /**\r\n * Gets the size of one char in the texture (each char fits in size * size space in the texture).\r\n */\r\n public get charSize(): number {\r\n return this._charSize;\r\n }\r\n\r\n /**\r\n * Create a new instance of the Ascii Art FontTexture class\r\n * @param name the name of the texture\r\n * @param font the font to use, use the W3C CSS notation\r\n * @param text the caracter set to use in the rendering.\r\n * @param scene the scene that owns the texture\r\n */\r\n constructor(name: string, font: string, text: string, scene: Nullable<Scene> = null) {\r\n super(scene);\r\n\r\n scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n this.name = name;\r\n this._text == text;\r\n this._font == font;\r\n\r\n this.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n this.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n //this.anisotropicFilteringLevel = 1;\r\n\r\n // Get the font specific info.\r\n 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 = Math.ceil(this._charSize * text.length);\r\n var textureHeight = this._charSize;\r\n\r\n // Create the texture that will store the font characters.\r\n this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);\r\n //scene.getEngine().setclamp\r\n 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], i * this._charSize, -maxCharHeight.offset);\r\n }\r\n\r\n // Flush the text in the dynamic texture.\r\n\r\n scene.getEngine().updateDynamicTexture(this._texture, canvas, false, true);\r\n }\r\n\r\n /**\r\n * Gets the max char width of a font.\r\n * @param font the font to use, use the W3C CSS notation\r\n * @return the max char width\r\n */\r\n private getFontWidth(font: string): number {\r\n 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 AsciiArtTexture.\r\n * @return the clone of the texture.\r\n */\r\n public clone(): AsciiArtFontTexture {\r\n return new AsciiArtFontTexture(this.name, this._font, this._text, this.getScene());\r\n }\r\n\r\n /**\r\n * Parses a json object representing the texture and returns an instance of it.\r\n * @param source the source JSON representation\r\n * @param scene the scene to create the texture for\r\n * @return the parsed texture\r\n */\r\n public static Parse(source: any, scene: Scene): AsciiArtFontTexture {\r\n var texture = SerializationHelper.Parse(() => new AsciiArtFontTexture(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 Ascii Art Post Process.\r\n */\r\nexport interface IAsciiArtPostProcessOptions {\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 * The character set to use in the postprocess.\r\n */\r\n characterSet?: string;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToTile?: number;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToNormal?: number;\r\n}\r\n\r\n/**\r\n * AsciiArtPostProcess helps rendering everithing in Ascii Art.\r\n *\r\n * Simmply add it to your scene and let the nerd that lives in you have fun.\r\n * Example usage: var pp = new AsciiArtPostProcess(\"myAscii\", \"20px Monospace\", camera);\r\n */\r\nexport class AsciiArtPostProcess extends PostProcess {\r\n\r\n /**\r\n * The font texture used to render the char in the post process.\r\n */\r\n private _asciiArtFontTexture: AsciiArtFontTexture;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToTile: number = 0;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToNormal: number = 0;\r\n\r\n /**\r\n * Instantiates a new Ascii Art Post Process.\r\n * @param name the name to give to the postprocess\r\n * @camera the camera to apply the post process to.\r\n * @param options can either be the font name or an option object following the IAsciiArtPostProcessOptions format\r\n */\r\n constructor(name: string, camera: Camera, options?: string | IAsciiArtPostProcessOptions) {\r\n super(name,\r\n 'asciiart',\r\n ['asciiArtFontInfos', 'asciiArtOptions'],\r\n ['asciiArtFont'],\r\n {\r\n width: camera.getEngine().getRenderWidth(),\r\n height: camera.getEngine().getRenderHeight()\r\n },\r\n camera,\r\n Texture.TRILINEAR_SAMPLINGMODE,\r\n camera.getEngine(),\r\n true);\r\n\r\n // Default values.\r\n var font = \"40px Monospace\";\r\n var characterSet = \" `-.'_:,\\\"=^;<+!*?/cL\\\\zrs7TivJtC{3F)Il(xZfY5S2eajo14[nuyE]P6V9kXpKwGhqAUbOd8#HRDB0$mgMW&Q%N@\";\r\n\r\n // Use options.\r\n if (options) {\r\n if (typeof (options) === \"string\") {\r\n font = <string>options;\r\n }\r\n else {\r\n font = (<IAsciiArtPostProcessOptions>options).font || font;\r\n characterSet = (<IAsciiArtPostProcessOptions>options).characterSet || characterSet;\r\n this.mixToTile = (<IAsciiArtPostProcessOptions>options).mixToTile || this.mixToTile;\r\n this.mixToNormal = (<IAsciiArtPostProcessOptions>options).mixToNormal || this.mixToNormal;\r\n }\r\n }\r\n\r\n this._asciiArtFontTexture = new AsciiArtFontTexture(name, font, characterSet, camera.getScene());\r\n var textureSize = this._asciiArtFontTexture.getSize();\r\n\r\n this.onApply = (effect: Effect) => {\r\n effect.setTexture(\"asciiArtFont\", this._asciiArtFontTexture);\r\n\r\n effect.setFloat4(\"asciiArtFontInfos\",\r\n this._asciiArtFontTexture.charSize,\r\n characterSet.length,\r\n textureSize.width,\r\n textureSize.height);\r\n\r\n effect.setFloat4(\"asciiArtOptions\",\r\n this.width,\r\n this.height,\r\n this.mixToNormal,\r\n this.mixToTile);\r\n };\r\n }\r\n}\r\n"]}
|
1
|
+
{"version":3,"file":"asciiArtPostProcess.js","sourceRoot":"","sources":["../../../../../lts/postProcesses/generated/asciiArt/asciiArtPostProcess.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,2CAA6B;AAEtE,OAAO,EAAE,WAAW,EAAE,0DAA4C;AAClE,OAAO,EAAE,OAAO,EAAE,sDAAwC;AAE1D,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAE7D,qEAAuD;AACvD,OAAO,qBAAqB,CAAC;AAE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SAAS,CAAC,iBAAiB,EAAE,KAAI,CAAC,KAAK,EAAE,KAAI,CAAC,MAAM,EAAE,KAAI,CAAC,WAAW,EAAE,KAAI,CAAC,SAAS,CAAC,CAAC;QACnG,CAAC,CAAC;;IACN,CAAC;IACL,0BAAC;AAAD,CAAC,AAnED,CAAyC,WAAW,GAmEnD","sourcesContent":["import { Nullable } from \"core/types\";\r\nimport { serialize, SerializationHelper } from \"core/Misc/decorators\";\r\nimport { Camera } from \"core/Cameras/camera\";\r\nimport { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport { Effect } from \"core/Materials/effect\";\r\nimport { PostProcess } from \"core/PostProcesses/postProcess\";\r\nimport { Scene } from \"core/scene\";\r\nimport \"core/Engines/Extensions/engine.dynamicTexture\";\r\nimport \"./asciiart.fragment\";\r\n\r\n/**\r\n * AsciiArtFontTexture is the helper class used to easily create your ascii art font texture.\r\n *\r\n * It basically takes care rendering the font front the given font size to a texture.\r\n * This is used later on in the postprocess.\r\n */\r\nexport class AsciiArtFontTexture extends BaseTexture {\r\n @serialize(\"font\")\r\n private _font: string;\r\n\r\n @serialize(\"text\")\r\n private _text: string;\r\n\r\n private _charSize: number;\r\n\r\n /**\r\n * Gets the size of one char in the texture (each char fits in size * size space in the texture).\r\n */\r\n public get charSize(): number {\r\n return this._charSize;\r\n }\r\n\r\n /**\r\n * Create a new instance of the Ascii Art FontTexture class\r\n * @param name the name of the texture\r\n * @param font the font to use, use the W3C CSS notation\r\n * @param text the caracter set to use in the rendering.\r\n * @param scene the scene that owns the texture\r\n */\r\n constructor(name: string, font: string, text: string, scene: Nullable<Scene> = null) {\r\n super(scene);\r\n\r\n scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n this.name = name;\r\n this._text == text;\r\n this._font == font;\r\n\r\n this.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n this.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n //this.anisotropicFilteringLevel = 1;\r\n\r\n // Get the font specific info.\r\n const maxCharHeight = this.getFontHeight(font);\r\n const maxCharWidth = this.getFontWidth(font);\r\n\r\n this._charSize = Math.max(maxCharHeight.height, maxCharWidth);\r\n\r\n // This is an approximate size, but should always be able to fit at least the maxCharCount.\r\n const textureWidth = Math.ceil(this._charSize * text.length);\r\n const textureHeight = this._charSize;\r\n\r\n // Create the texture that will store the font characters.\r\n this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);\r\n //scene.getEngine().setclamp\r\n const textureSize = this.getSize();\r\n\r\n // Create a canvas with the final size: the one matching the texture.\r\n const canvas = document.createElement(\"canvas\");\r\n canvas.width = textureSize.width;\r\n canvas.height = textureSize.height;\r\n const context = <CanvasRenderingContext2D>canvas.getContext(\"2d\");\r\n context.textBaseline = \"top\";\r\n context.font = font;\r\n context.fillStyle = \"white\";\r\n context.imageSmoothingEnabled = false;\r\n\r\n // Sets the text in the texture.\r\n for (let i = 0; i < text.length; i++) {\r\n context.fillText(text[i], i * this._charSize, -maxCharHeight.offset);\r\n }\r\n\r\n // Flush the text in the dynamic texture.\r\n\r\n scene.getEngine().updateDynamicTexture(this._texture, canvas, false, true);\r\n }\r\n\r\n /**\r\n * Gets the max char width of a font.\r\n * @param font the font to use, use the W3C CSS notation\r\n * @return the max char width\r\n */\r\n private getFontWidth(font: string): number {\r\n const fontDraw = document.createElement(\"canvas\");\r\n const ctx = <CanvasRenderingContext2D>fontDraw.getContext(\"2d\");\r\n ctx.fillStyle = \"white\";\r\n ctx.font = font;\r\n\r\n return ctx.measureText(\"W\").width;\r\n }\r\n\r\n // More info here: https://videlais.com/2014/03/16/the-many-and-varied-problems-with-measuring-font-height-for-html5-canvas/\r\n /**\r\n * Gets the max char height of a font.\r\n * @param font the font to use, use the W3C CSS notation\r\n * @return the max char height\r\n */\r\n private getFontHeight(font: string): { height: number; offset: number } {\r\n const fontDraw = document.createElement(\"canvas\");\r\n const ctx = <CanvasRenderingContext2D>fontDraw.getContext(\"2d\");\r\n ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);\r\n ctx.textBaseline = \"top\";\r\n ctx.fillStyle = \"white\";\r\n ctx.font = font;\r\n ctx.fillText(\"jH|\", 0, 0);\r\n const pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;\r\n let start = -1;\r\n let end = -1;\r\n for (let row = 0; row < fontDraw.height; row++) {\r\n for (let column = 0; column < fontDraw.width; column++) {\r\n const index = (row * fontDraw.width + column) * 4;\r\n if (pixels[index] === 0) {\r\n if (column === fontDraw.width - 1 && start !== -1) {\r\n end = row;\r\n row = fontDraw.height;\r\n break;\r\n }\r\n continue;\r\n } else {\r\n if (start === -1) {\r\n start = row;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n return { height: end - start + 1, offset: start - 1 };\r\n }\r\n\r\n /**\r\n * Clones the current AsciiArtTexture.\r\n * @return the clone of the texture.\r\n */\r\n public clone(): AsciiArtFontTexture {\r\n return new AsciiArtFontTexture(this.name, this._font, this._text, this.getScene());\r\n }\r\n\r\n /**\r\n * Parses a json object representing the texture and returns an instance of it.\r\n * @param source the source JSON representation\r\n * @param scene the scene to create the texture for\r\n * @return the parsed texture\r\n */\r\n public static Parse(source: any, scene: Scene): AsciiArtFontTexture {\r\n const texture = SerializationHelper.Parse(() => new AsciiArtFontTexture(source.name, source.font, source.text, scene), source, scene, null);\r\n\r\n return texture;\r\n }\r\n}\r\n\r\n/**\r\n * Option available in the Ascii Art Post Process.\r\n */\r\nexport interface IAsciiArtPostProcessOptions {\r\n /**\r\n * The font to use following the w3c font definition.\r\n */\r\n font?: string;\r\n\r\n /**\r\n * The character set to use in the postprocess.\r\n */\r\n characterSet?: string;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToTile?: number;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToNormal?: number;\r\n}\r\n\r\n/**\r\n * AsciiArtPostProcess helps rendering everithing in Ascii Art.\r\n *\r\n * Simmply add it to your scene and let the nerd that lives in you have fun.\r\n * Example usage: var pp = new AsciiArtPostProcess(\"myAscii\", \"20px Monospace\", camera);\r\n */\r\nexport class AsciiArtPostProcess extends PostProcess {\r\n /**\r\n * The font texture used to render the char in the post process.\r\n */\r\n private _asciiArtFontTexture: AsciiArtFontTexture;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToTile: number = 0;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToNormal: number = 0;\r\n\r\n /**\r\n * Instantiates a new Ascii Art Post Process.\r\n * @param name the name to give to the postprocess\r\n * @camera the camera to apply the post process to.\r\n * @param options can either be the font name or an option object following the IAsciiArtPostProcessOptions format\r\n */\r\n constructor(name: string, camera: Camera, options?: string | IAsciiArtPostProcessOptions) {\r\n super(\r\n name,\r\n \"asciiart\",\r\n [\"asciiArtFontInfos\", \"asciiArtOptions\"],\r\n [\"asciiArtFont\"],\r\n {\r\n width: camera.getEngine().getRenderWidth(),\r\n height: camera.getEngine().getRenderHeight(),\r\n },\r\n camera,\r\n Texture.TRILINEAR_SAMPLINGMODE,\r\n camera.getEngine(),\r\n true\r\n );\r\n\r\n // Default values.\r\n let font = \"40px Monospace\";\r\n let characterSet = \" `-.'_:,\\\"=^;<+!*?/cL\\\\zrs7TivJtC{3F)Il(xZfY5S2eajo14[nuyE]P6V9kXpKwGhqAUbOd8#HRDB0$mgMW&Q%N@\";\r\n\r\n // Use options.\r\n if (options) {\r\n if (typeof options === \"string\") {\r\n font = <string>options;\r\n } else {\r\n font = (<IAsciiArtPostProcessOptions>options).font || font;\r\n characterSet = (<IAsciiArtPostProcessOptions>options).characterSet || characterSet;\r\n this.mixToTile = (<IAsciiArtPostProcessOptions>options).mixToTile || this.mixToTile;\r\n this.mixToNormal = (<IAsciiArtPostProcessOptions>options).mixToNormal || this.mixToNormal;\r\n }\r\n }\r\n\r\n this._asciiArtFontTexture = new AsciiArtFontTexture(name, font, characterSet, camera.getScene());\r\n const textureSize = this._asciiArtFontTexture.getSize();\r\n\r\n this.onApply = (effect: Effect) => {\r\n effect.setTexture(\"asciiArtFont\", this._asciiArtFontTexture);\r\n\r\n effect.setFloat4(\"asciiArtFontInfos\", this._asciiArtFontTexture.charSize, characterSet.length, textureSize.width, textureSize.height);\r\n\r\n effect.setFloat4(\"asciiArtOptions\", this.width, this.height, this.mixToNormal, this.mixToTile);\r\n };\r\n }\r\n}\r\n"]}
|
@@ -1,6 +1,8 @@
|
|
1
|
+
// Do not edit.
|
1
2
|
import { ShaderStore } from "@babylonjs/core/Engines/shaderStore.js";
|
2
|
-
var name =
|
3
|
-
var shader = "
|
3
|
+
var name = "asciiartPixelShader";
|
4
|
+
var shader = "varying vec2 vUV;uniform sampler2D textureSampler;uniform sampler2D asciiArtFont;uniform vec4 asciiArtFontInfos;uniform vec4 asciiArtOptions;float getLuminance(vec3 color)\n{return clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);}\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) \n{float caracterSize=asciiArtFontInfos.x;float numChar=asciiArtFontInfos.y-1.0;float fontx=asciiArtFontInfos.z;float fonty=asciiArtFontInfos.w;float screenx=asciiArtOptions.x;float screeny=asciiArtOptions.y;float tileX=float(floor((gl_FragCoord.x)/caracterSize))*caracterSize/screenx;float tileY=float(floor((gl_FragCoord.y)/caracterSize))*caracterSize/screeny;vec2 tileUV=vec2(tileX,tileY);vec4 tileColor=texture2D(textureSampler,tileUV);vec4 baseColor=texture2D(textureSampler,vUV);float tileLuminance=getLuminance(tileColor.rgb);float offsetx=(float(floor(tileLuminance*numChar)))*caracterSize/fontx;float offsety=0.0;float x=float(mod(gl_FragCoord.x,caracterSize))/fontx;float y=float(mod(gl_FragCoord.y,caracterSize))/fonty;vec4 finalColor= texture2D(asciiArtFont,vec2(offsetx+x,offsety+(caracterSize/fonty-y)));finalColor.rgb*=tileColor.rgb;finalColor.a=1.0;finalColor= mix(finalColor,tileColor,asciiArtOptions.w);finalColor= mix(finalColor,baseColor,asciiArtOptions.z);gl_FragColor=finalColor;}";
|
5
|
+
// Sideeffect
|
4
6
|
ShaderStore.ShadersStore[name] = shader;
|
5
7
|
/** @hidden */
|
6
8
|
export var asciiartPixelShader = { name: name, shader: shader };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"asciiart.fragment.js","sourceRoot":"","sources":["
|
1
|
+
{"version":3,"file":"asciiart.fragment.js","sourceRoot":"","sources":["../../../../../lts/postProcesses/generated/asciiArt/asciiart.fragment.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,+CAAiC;AAEvD,IAAM,IAAI,GAAG,qBAAqB,CAAC;AACnC,IAAM,MAAM,GAAG,4wCAI09B,CAAC;AAC1+B,aAAa;AACb,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AACxC,cAAc;AACd,MAAM,CAAC,IAAM,mBAAmB,GAAG,EAAE,IAAI,MAAA,EAAE,MAAM,QAAA,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"core/Engines/shaderStore\";\n\nconst name = \"asciiartPixelShader\";\nconst shader = `varying vec2 vUV;uniform sampler2D textureSampler;uniform sampler2D asciiArtFont;uniform vec4 asciiArtFontInfos;uniform vec4 asciiArtOptions;float getLuminance(vec3 color)\n{return clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);}\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) \n{float caracterSize=asciiArtFontInfos.x;float numChar=asciiArtFontInfos.y-1.0;float fontx=asciiArtFontInfos.z;float fonty=asciiArtFontInfos.w;float screenx=asciiArtOptions.x;float screeny=asciiArtOptions.y;float tileX=float(floor((gl_FragCoord.x)/caracterSize))*caracterSize/screenx;float tileY=float(floor((gl_FragCoord.y)/caracterSize))*caracterSize/screeny;vec2 tileUV=vec2(tileX,tileY);vec4 tileColor=texture2D(textureSampler,tileUV);vec4 baseColor=texture2D(textureSampler,vUV);float tileLuminance=getLuminance(tileColor.rgb);float offsetx=(float(floor(tileLuminance*numChar)))*caracterSize/fontx;float offsety=0.0;float x=float(mod(gl_FragCoord.x,caracterSize))/fontx;float y=float(mod(gl_FragCoord.y,caracterSize))/fonty;vec4 finalColor= texture2D(asciiArtFont,vec2(offsetx+x,offsety+(caracterSize/fonty-y)));finalColor.rgb*=tileColor.rgb;finalColor.a=1.0;finalColor= mix(finalColor,tileColor,asciiArtOptions.w);finalColor= mix(finalColor,baseColor,asciiArtOptions.z);gl_FragColor=finalColor;}`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @hidden */\nexport const asciiartPixelShader = { name, shader };\n"]}
|
package/asciiArt/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/asciiArt/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC","sourcesContent":["export * from \"./asciiArtPostProcess\";\r\n"]}
|
@@ -1,8 +1,9 @@
|
|
1
|
-
import { Nullable } from "@babylonjs/core/types";
|
2
|
-
import { Camera } from "@babylonjs/core/Cameras/camera";
|
3
|
-
import { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture";
|
4
|
-
import { PostProcess } from "@babylonjs/core/PostProcesses/postProcess";
|
5
|
-
import { Scene } from "@babylonjs/core/scene";
|
1
|
+
import { Nullable } from "@babylonjs/core/types.js";
|
2
|
+
import { Camera } from "@babylonjs/core/Cameras/camera.js";
|
3
|
+
import { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
|
4
|
+
import { PostProcess } from "@babylonjs/core/PostProcesses/postProcess.js";
|
5
|
+
import { Scene } from "@babylonjs/core/scene.js";
|
6
|
+
import "@babylonjs/core/Engines/Extensions/engine.dynamicTexture.js";
|
6
7
|
import "./digitalrain.fragment";
|
7
8
|
/**
|
8
9
|
* DigitalRainFontTexture is the helper class used to easily create your digital rain font texture.
|
@@ -4,6 +4,7 @@ import { Matrix } from "@babylonjs/core/Maths/math.vector.js";
|
|
4
4
|
import { BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
|
5
5
|
import { Texture } from "@babylonjs/core/Materials/Textures/texture.js";
|
6
6
|
import { PostProcess } from "@babylonjs/core/PostProcesses/postProcess.js";
|
7
|
+
import "@babylonjs/core/Engines/Extensions/engine.dynamicTexture.js";
|
7
8
|
import "./digitalrain.fragment.js";
|
8
9
|
/**
|
9
10
|
* DigitalRainFontTexture is the helper class used to easily create your digital rain font texture.
|
@@ -77,8 +78,8 @@ var DigitalRainFontTexture = /** @class */ (function (_super) {
|
|
77
78
|
*/
|
78
79
|
DigitalRainFontTexture.prototype.getFontWidth = function (font) {
|
79
80
|
var fontDraw = document.createElement("canvas");
|
80
|
-
var ctx = fontDraw.getContext(
|
81
|
-
ctx.fillStyle =
|
81
|
+
var ctx = fontDraw.getContext("2d");
|
82
|
+
ctx.fillStyle = "white";
|
82
83
|
ctx.font = font;
|
83
84
|
return ctx.measureText("W").width;
|
84
85
|
};
|
@@ -90,12 +91,12 @@ var DigitalRainFontTexture = /** @class */ (function (_super) {
|
|
90
91
|
*/
|
91
92
|
DigitalRainFontTexture.prototype.getFontHeight = function (font) {
|
92
93
|
var fontDraw = document.createElement("canvas");
|
93
|
-
var ctx = fontDraw.getContext(
|
94
|
+
var ctx = fontDraw.getContext("2d");
|
94
95
|
ctx.fillRect(0, 0, fontDraw.width, fontDraw.height);
|
95
|
-
ctx.textBaseline =
|
96
|
-
ctx.fillStyle =
|
96
|
+
ctx.textBaseline = "top";
|
97
|
+
ctx.fillStyle = "white";
|
97
98
|
ctx.font = font;
|
98
|
-
ctx.fillText(
|
99
|
+
ctx.fillText("jH|", 0, 0);
|
99
100
|
var pixels = ctx.getImageData(0, 0, fontDraw.width, fontDraw.height).data;
|
100
101
|
var start = -1;
|
101
102
|
var end = -1;
|
@@ -118,7 +119,7 @@ var DigitalRainFontTexture = /** @class */ (function (_super) {
|
|
118
119
|
}
|
119
120
|
}
|
120
121
|
}
|
121
|
-
return { height:
|
122
|
+
return { height: end - start + 1, offset: start - 1 };
|
122
123
|
};
|
123
124
|
/**
|
124
125
|
* Clones the current DigitalRainFontTexture.
|
@@ -161,9 +162,9 @@ var DigitalRainPostProcess = /** @class */ (function (_super) {
|
|
161
162
|
* @param options can either be the font name or an option object following the IDigitalRainPostProcessOptions format
|
162
163
|
*/
|
163
164
|
function DigitalRainPostProcess(name, camera, options) {
|
164
|
-
var _this = _super.call(this, name,
|
165
|
+
var _this = _super.call(this, name, "digitalrain", ["digitalRainFontInfos", "digitalRainOptions", "cosTimeZeroOne", "matrixSpeed"], ["digitalRainFont"], {
|
165
166
|
width: camera.getEngine().getRenderWidth(),
|
166
|
-
height: camera.getEngine().getRenderHeight()
|
167
|
+
height: camera.getEngine().getRenderHeight(),
|
167
168
|
}, camera, Texture.TRILINEAR_SAMPLINGMODE, camera.getEngine(), true) || this;
|
168
169
|
/**
|
169
170
|
* This defines the amount you want to mix the "tile" or caracter space colored in the digital rain.
|
@@ -184,7 +185,7 @@ var DigitalRainPostProcess = /** @class */ (function (_super) {
|
|
184
185
|
var characterSet = "古池や蛙飛び込む水の音ふるいけやかわずとびこむみずのおと初しぐれ猿も小蓑をほしげ也はつしぐれさるもこみのをほしげなり江戸の雨何石呑んだ時鳥えどのあめなんごくのんだほととぎす";
|
185
186
|
// Use options.
|
186
187
|
if (options) {
|
187
|
-
if (typeof
|
188
|
+
if (typeof options === "string") {
|
188
189
|
font = options;
|
189
190
|
}
|
190
191
|
else {
|
@@ -205,7 +206,7 @@ var DigitalRainPostProcess = /** @class */ (function (_super) {
|
|
205
206
|
effect.setMatrix("matrixSpeed", matrix);
|
206
207
|
alpha += _this.speed;
|
207
208
|
cosTimeZeroOne = alpha;
|
208
|
-
effect.setFloat(
|
209
|
+
effect.setFloat("cosTimeZeroOne", cosTimeZeroOne);
|
209
210
|
};
|
210
211
|
return _this;
|
211
212
|
}
|
@@ -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;AAGxE,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,CA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AC,MAAM,EACnB,WAAW,CAAC,KAAK,EACjB,WAAW,CAAC,MAAM,CAAC,CAAC;YAExB,MAAM,CAAC,SAAS,CAAC,oBAAoB,EACjC,KAAI,CAAC,KAAK,EACV,KAAI,CAAC,MAAM,EACX,KAAI,CAAC,WAAW,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\n\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/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QACtD,CAAC,CAAC;;IACN,CAAC;IACL,6BAAC;AAAD,CAAC,AAnGD,CAA4C,WAAW,GAmGtD","sourcesContent":["import { Nullable } from \"core/types\";\r\nimport { serialize, SerializationHelper } from \"core/Misc/decorators\";\r\nimport { Matrix } from \"core/Maths/math.vector\";\r\nimport { Camera } from \"core/Cameras/camera\";\r\nimport { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport { Effect } from \"core/Materials/effect\";\r\nimport { PostProcess } from \"core/PostProcesses/postProcess\";\r\nimport { 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 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,6 +1,8 @@
|
|
1
|
+
// Do not edit.
|
1
2
|
import { ShaderStore } from "@babylonjs/core/Engines/shaderStore.js";
|
2
|
-
var name =
|
3
|
-
var shader = "
|
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
|
4
6
|
ShaderStore.ShadersStore[name] = shader;
|
5
7
|
/** @hidden */
|
6
8
|
export var digitalrainPixelShader = { name: name, shader: shader };
|
@@ -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.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.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,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC","sourcesContent":["export * from \"./asciiArt/index\";\r\nexport * from \"./digitalRain/index\";\r\n"]}
|
@@ -1 +1 @@
|
|
1
|
-
export * from "
|
1
|
+
export * from "./asciiArt/index.js";
|
@@ -1,13 +1,13 @@
|
|
1
|
-
import * as postProcessLibrary from "
|
1
|
+
import * as postProcessLibrary from "./asciiArt/index.js";
|
2
2
|
/**
|
3
3
|
* This is the entry point for the UMD module.
|
4
4
|
* The entry point for a future ESM package should be index.ts
|
5
5
|
*/
|
6
|
-
var globalObject =
|
6
|
+
var globalObject = typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : undefined;
|
7
7
|
if (typeof globalObject !== "undefined") {
|
8
8
|
for (var key in postProcessLibrary) {
|
9
9
|
globalObject.BABYLON[key] = postProcessLibrary[key];
|
10
10
|
}
|
11
11
|
}
|
12
|
-
export * from "
|
12
|
+
export * from "./asciiArt/index.js";
|
13
13
|
//# sourceMappingURL=legacy-asciiArt.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"legacy-asciiArt.js","sourceRoot":"","sources":["
|
1
|
+
{"version":3,"file":"legacy-asciiArt.js","sourceRoot":"","sources":["../../../../../lts/postProcesses/generated/legacy/legacy-asciiArt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,kBAAkB,4BAAsC;AAEpE;;;GAGG;AACH,IAAM,YAAY,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACjH,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE;IACrC,KAAK,IAAM,GAAG,IAAI,kBAAkB,EAAE;QAC5B,YAAa,CAAC,OAAO,CAAC,GAAG,CAAC,GAAS,kBAAmB,CAAC,GAAG,CAAC,CAAC;KACrE;CACJ;AAED,oCAA8C","sourcesContent":["import * 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"]}
|
@@ -1 +1 @@
|
|
1
|
-
export * from "
|
1
|
+
export * from "./digitalRain/index.js";
|
@@ -1,13 +1,13 @@
|
|
1
|
-
import * as postProcessLibrary from "
|
1
|
+
import * as postProcessLibrary from "./digitalRain/index.js";
|
2
2
|
/**
|
3
3
|
* This is the entry point for the UMD module.
|
4
4
|
* The entry point for a future ESM package should be index.ts
|
5
5
|
*/
|
6
|
-
var globalObject =
|
6
|
+
var globalObject = typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : undefined;
|
7
7
|
if (typeof globalObject !== "undefined") {
|
8
8
|
for (var key in postProcessLibrary) {
|
9
9
|
globalObject.BABYLON[key] = postProcessLibrary[key];
|
10
10
|
}
|
11
11
|
}
|
12
|
-
export * from "
|
12
|
+
export * from "./digitalRain/index.js";
|
13
13
|
//# sourceMappingURL=legacy-digitalRain.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"legacy-digitalRain.js","sourceRoot":"","sources":["
|
1
|
+
{"version":3,"file":"legacy-digitalRain.js","sourceRoot":"","sources":["../../../../../lts/postProcesses/generated/legacy/legacy-digitalRain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,kBAAkB,+BAAyC;AAEvE;;;GAGG;AACH,IAAM,YAAY,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACjH,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE;IACrC,KAAK,IAAM,GAAG,IAAI,kBAAkB,EAAE;QAC5B,YAAa,CAAC,OAAO,CAAC,GAAG,CAAC,GAAS,kBAAmB,CAAC,GAAG,CAAC,CAAC;KACrE;CACJ;AAED,uCAAiD","sourcesContent":["import * 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"]}
|
package/legacy/legacy.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export * from "
|
1
|
+
export * from "./index.js";
|
package/legacy/legacy.js
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
import * as postProcessLibrary from "
|
1
|
+
import * as postProcessLibrary from "./index.js";
|
2
2
|
/**
|
3
3
|
*
|
4
4
|
* This is the entry point for the UMD module.
|
5
5
|
* The entry point for a future ESM package should be index.ts
|
6
6
|
*/
|
7
|
-
var globalObject =
|
7
|
+
var globalObject = typeof global !== "undefined" ? global : typeof window !== "undefined" ? window : undefined;
|
8
8
|
if (typeof globalObject !== "undefined") {
|
9
9
|
for (var key in postProcessLibrary) {
|
10
10
|
globalObject.BABYLON[key] = postProcessLibrary[key];
|
11
11
|
}
|
12
12
|
}
|
13
|
-
export * from "
|
13
|
+
export * from "./index.js";
|
14
14
|
//# sourceMappingURL=legacy.js.map
|
package/legacy/legacy.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"legacy.js","sourceRoot":"","sources":["
|
1
|
+
{"version":3,"file":"legacy.js","sourceRoot":"","sources":["../../../../../lts/postProcesses/generated/legacy/legacy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,kBAAkB,mBAA6B;AAE3D;;;;GAIG;AACH,IAAM,YAAY,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACjH,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE;IACrC,KAAK,IAAM,GAAG,IAAI,kBAAkB,EAAE;QAC5B,YAAa,CAAC,OAAO,CAAC,GAAG,CAAC,GAAS,kBAAmB,CAAC,GAAG,CAAC,CAAC;KACrE;CACJ;AAED,2BAAqC","sourcesContent":["import * as postProcessLibrary from \"post-processes/index\";\r\n\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/index\";\r\n"]}
|
package/package.json
CHANGED
@@ -1,65 +1,30 @@
|
|
1
1
|
{
|
2
|
-
"author": {
|
3
|
-
"name": "David CATUHE"
|
4
|
-
},
|
5
2
|
"name": "@babylonjs/post-processes",
|
6
|
-
"
|
7
|
-
"version": "5.0.0-beta.6",
|
8
|
-
"repository": {
|
9
|
-
"type": "git",
|
10
|
-
"url": "https://github.com/BabylonJS/Babylon.js.git"
|
11
|
-
},
|
3
|
+
"version": "5.0.0-beta.8-snapshot",
|
12
4
|
"main": "index.js",
|
5
|
+
"module": "index.js",
|
6
|
+
"types": "index.d.ts",
|
13
7
|
"files": [
|
14
|
-
"
|
15
|
-
"
|
16
|
-
"
|
17
|
-
"asciiArt/asciiArtPostProcess.d.ts",
|
18
|
-
"asciiArt/asciiArtPostProcess.js",
|
19
|
-
"asciiArt/asciiArtPostProcess.js.map",
|
20
|
-
"asciiArt/index.d.ts",
|
21
|
-
"asciiArt/index.js",
|
22
|
-
"asciiArt/index.js.map",
|
23
|
-
"digitalRain/digitalrain.fragment.d.ts",
|
24
|
-
"digitalRain/digitalrain.fragment.js",
|
25
|
-
"digitalRain/digitalrain.fragment.js.map",
|
26
|
-
"digitalRain/digitalRainPostProcess.d.ts",
|
27
|
-
"digitalRain/digitalRainPostProcess.js",
|
28
|
-
"digitalRain/digitalRainPostProcess.js.map",
|
29
|
-
"digitalRain/index.d.ts",
|
30
|
-
"digitalRain/index.js",
|
31
|
-
"digitalRain/index.js.map",
|
32
|
-
"index.d.ts",
|
33
|
-
"index.js",
|
34
|
-
"index.js.map",
|
35
|
-
"legacy/legacy-asciiArt.d.ts",
|
36
|
-
"legacy/legacy-asciiArt.js",
|
37
|
-
"legacy/legacy-asciiArt.js.map",
|
38
|
-
"legacy/legacy-digitalRain.d.ts",
|
39
|
-
"legacy/legacy-digitalRain.js",
|
40
|
-
"legacy/legacy-digitalRain.js.map",
|
41
|
-
"legacy/legacy.d.ts",
|
42
|
-
"legacy/legacy.js",
|
43
|
-
"legacy/legacy.js.map",
|
44
|
-
"readme.md"
|
8
|
+
"**/*.js",
|
9
|
+
"**/*.d.ts",
|
10
|
+
"**/*.map"
|
45
11
|
],
|
46
|
-
"
|
47
|
-
|
48
|
-
"
|
49
|
-
"
|
50
|
-
"
|
51
|
-
"
|
52
|
-
|
53
|
-
],
|
54
|
-
"license": "Apache-2.0",
|
12
|
+
"scripts": {
|
13
|
+
"build": "npm run clean && npm run compile",
|
14
|
+
"clean": "rimraf dist && rimraf *.tsbuildinfo && rimraf \"./**/*.!(json|build.json)\"",
|
15
|
+
"compile": "tsc -b tsconfig.build.json",
|
16
|
+
"postcompile": "build-tools -c add-js-to-es6 --path ./dist/**/*.js",
|
17
|
+
"prepublishOnly": "build-tools -c prepare-es6-build"
|
18
|
+
},
|
55
19
|
"dependencies": {
|
56
|
-
"@babylonjs/core": "5.0.0-beta.
|
20
|
+
"@babylonjs/core": "^5.0.0-beta.8-snapshot",
|
57
21
|
"tslib": "^2.3.1"
|
58
22
|
},
|
59
|
-
"
|
60
|
-
"
|
23
|
+
"devDependencies": {
|
24
|
+
"@dev/build-tools": "^5.0.0-beta.8-snapshot",
|
25
|
+
"@lts/post-processes": "^5.0.0-beta.8-snapshot",
|
26
|
+
"rimraf": "^3.0.2",
|
27
|
+
"typescript": "^4.4.4"
|
61
28
|
},
|
62
|
-
"
|
63
|
-
|
64
|
-
"type": "module"
|
65
|
-
}
|
29
|
+
"sideEffects": true
|
30
|
+
}
|
package/readme.md
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
Babylon.js Post Processes Library
|
2
|
-
=====================
|
3
|
-
|
4
|
-
For usage documentation please visit http://doc.babylonjs.com/extensions and choose "post process library".
|
5
|
-
|
6
|
-
# Installation instructions
|
7
|
-
|
8
|
-
To install using npm :
|
9
|
-
|
10
|
-
```
|
11
|
-
npm install --save @babylonjs/core @babylonjs/post-processes
|
12
|
-
```
|
13
|
-
|
14
|
-
# How to use
|
15
|
-
|
16
|
-
Afterwards it can be imported to the your project using:
|
17
|
-
|
18
|
-
```
|
19
|
-
import { AsciiArtPostProcess } from '@babylonjs/post-processes/asciiArt';
|
20
|
-
```
|
21
|
-
|
22
|
-
And used as usual:
|
23
|
-
|
24
|
-
```
|
25
|
-
// Some awesome code
|
26
|
-
// Creates the post process
|
27
|
-
let postProcess = new AsciiArtPostProcess("AsciiArt", camera);
|
28
|
-
// Some more awesome code
|
29
|
-
```
|
30
|
-
|
31
|
-
For more information you can have a look at our [our ES6 dedicated documentation](https://doc.babylonjs.com/features/es6_support).
|