@onerjs/post-processes 8.25.2 → 8.25.4
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 -6
- package/asciiArt/asciiArtPostProcess.js +7 -7
- package/asciiArt/asciiArtPostProcess.js.map +1 -1
- package/asciiArt/asciiart.fragment.js +1 -1
- package/asciiArt/asciiart.fragment.js.map +1 -1
- package/digitalRain/digitalRainPostProcess.d.ts +6 -6
- package/digitalRain/digitalRainPostProcess.js +8 -8
- package/digitalRain/digitalRainPostProcess.js.map +1 -1
- package/digitalRain/digitalrain.fragment.js +1 -1
- package/digitalRain/digitalrain.fragment.js.map +1 -1
- package/edgeDetection/edgeDetection.fragment.js +1 -1
- package/edgeDetection/edgeDetection.fragment.js.map +1 -1
- package/edgeDetection/edgeDetectionPostProcess.d.ts +7 -7
- package/edgeDetection/edgeDetectionPostProcess.js +11 -11
- package/edgeDetection/edgeDetectionPostProcess.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { Nullable } from "@
|
|
2
|
-
import type { Camera } from "@
|
|
3
|
-
import { BaseTexture } from "@
|
|
4
|
-
import { PostProcess } from "@
|
|
5
|
-
import type { Scene } from "@
|
|
6
|
-
import "@
|
|
1
|
+
import type { Nullable } from "@onerjs/core/types.js";
|
|
2
|
+
import type { Camera } from "@onerjs/core/Cameras/camera.js";
|
|
3
|
+
import { BaseTexture } from "@onerjs/core/Materials/Textures/baseTexture.js";
|
|
4
|
+
import { PostProcess } from "@onerjs/core/PostProcesses/postProcess.js";
|
|
5
|
+
import type { Scene } from "@onerjs/core/scene.js";
|
|
6
|
+
import "@onerjs/core/Engines/Extensions/engine.dynamicTexture.js";
|
|
7
7
|
import "./asciiart.fragment.js";
|
|
8
8
|
/**
|
|
9
9
|
* AsciiArtFontTexture is the helper class used to easily create your ascii art font texture.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { __decorate } from "@
|
|
2
|
-
import { serialize } from "@
|
|
3
|
-
import { SerializationHelper } from "@
|
|
4
|
-
import { BaseTexture } from "@
|
|
5
|
-
import { Texture } from "@
|
|
6
|
-
import { PostProcess } from "@
|
|
7
|
-
import "@
|
|
1
|
+
import { __decorate } from "@onerjs/core/tslib.es6.js";
|
|
2
|
+
import { serialize } from "@onerjs/core/Misc/decorators.js";
|
|
3
|
+
import { SerializationHelper } from "@onerjs/core/Misc/decorators.serialization.js";
|
|
4
|
+
import { BaseTexture } from "@onerjs/core/Materials/Textures/baseTexture.js";
|
|
5
|
+
import { Texture } from "@onerjs/core/Materials/Textures/texture.js";
|
|
6
|
+
import { PostProcess } from "@onerjs/core/PostProcesses/postProcess.js";
|
|
7
|
+
import "@onerjs/core/Engines/Extensions/engine.dynamicTexture.js";
|
|
8
8
|
import "./asciiart.fragment.js";
|
|
9
9
|
/**
|
|
10
10
|
* AsciiArtFontTexture is the helper class used to easily create your ascii art font texture.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asciiArtPostProcess.js","sourceRoot":"","sources":["../../../../dev/postProcesses/src/asciiArt/asciiArtPostProcess.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,2CAA6B;AACjD,OAAO,EAAE,mBAAmB,EAAE,yDAA2C;AAEzE,OAAO,EAAE,WAAW,EAAE,0DAA4C;AAClE,OAAO,EAAE,OAAO,EAAE,sDAAwC;AAE1D,OAAO,EAAE,WAAW,EAAE,qDAAuC;AAE7D,qEAAuD;AACvD,OAAO,qBAAqB,CAAC;AAE7B;;;;;GAKG;AACH,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAShD;;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,CAA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O,KAAK,QAAQ,EAAE,CAAC;gBAC9B,IAAI,GAAG,OAAO,CAAC;YACnB,CAAC;iBAAM,CAAC;gBACJ,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC;gBAC5B,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,YAAY,CAAC;gBACpD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,CAAC;gBACrD,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,IAAI,CAAC,WAAW,CAAC;YAC/D,CAAC;QACL,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,EAAE,QAAQ,EAAE,IAAI,IAAI,CAAC,MAAM,CAAC;QAChD,IAAI,CAAC,oBAAoB,GAAG,IAAI,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;QACrF,MAAM,WAAW,GAAG,IAAI,CAAC,oBAAoB,CAAC,OAAO,EAAE,CAAC;QAExD,IAAI,CAAC,OAAO,GAAG,CAAC,MAAc,EAAE,EAAE;YAC9B,MAAM,CAAC,UAAU,CAAC,cAAc,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;YAE7D,MAAM,CAAC,SAAS,CAAC,mBAAmB,EAAE,IAAI,CAAC,oBAAoB,CAAC,QAAQ,EAAE,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;YAEtI,MAAM,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACnG,CAAC,CAAC;IACN,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { serialize } from \"core/Misc/decorators\";\r\nimport { SerializationHelper } from \"core/Misc/decorators.serialization\";\r\nimport type { Camera } from \"core/Cameras/camera\";\r\nimport { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport type { Effect } from \"core/Materials/effect\";\r\nimport { PostProcess } from \"core/PostProcesses/postProcess\";\r\nimport type { Scene } from \"core/scene\";\r\nimport \"core/Engines/Extensions/engine.dynamicTexture\";\r\nimport \"./asciiart.fragment\";\r\n\r\n/**\r\n * AsciiArtFontTexture is the helper class used to easily create your ascii art font texture.\r\n *\r\n * It basically takes care rendering the font front the given font size to a texture.\r\n * This is used later on in the postprocess.\r\n */\r\nexport class AsciiArtFontTexture extends BaseTexture {\r\n @serialize(\"font\")\r\n private _font: string;\r\n\r\n @serialize(\"text\")\r\n private _text: string;\r\n\r\n private _charSize: number;\r\n\r\n /**\r\n * Gets the size of one char in the texture (each char fits in size * size space in the texture).\r\n */\r\n public get charSize(): number {\r\n return this._charSize;\r\n }\r\n\r\n /**\r\n * Create a new instance of the Ascii Art FontTexture class\r\n * @param name the name of the texture\r\n * @param font the font to use, use the W3C CSS notation\r\n * @param text the caracter set to use in the rendering.\r\n * @param scene the scene that owns the texture\r\n */\r\n constructor(name: string, font: string, text: string, scene: Nullable<Scene> = null) {\r\n super(scene);\r\n\r\n scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n this.name = name;\r\n this._text == text;\r\n this._font == font;\r\n\r\n this.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n this.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n //this.anisotropicFilteringLevel = 1;\r\n\r\n // Get the font specific info.\r\n const maxCharHeight = this._getFontHeight(font);\r\n const maxCharWidth = this._getFontWidth(font);\r\n\r\n this._charSize = Math.max(maxCharHeight.height, maxCharWidth);\r\n\r\n // This is an approximate size, but should always be able to fit at least the maxCharCount.\r\n const textureWidth = Math.ceil(this._charSize * text.length);\r\n const textureHeight = this._charSize;\r\n\r\n // Create the texture that will store the font characters.\r\n this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);\r\n //scene.getEngine().setclamp\r\n const textureSize = this.getSize();\r\n\r\n // Create a canvas with the final size: the one matching the texture.\r\n const canvas = document.createElement(\"canvas\");\r\n canvas.width = textureSize.width;\r\n canvas.height = textureSize.height;\r\n const context = <CanvasRenderingContext2D>canvas.getContext(\"2d\");\r\n context.textBaseline = \"top\";\r\n context.font = font;\r\n context.fillStyle = \"white\";\r\n context.imageSmoothingEnabled = false;\r\n\r\n // Sets the text in the texture.\r\n for (let i = 0; i < text.length; i++) {\r\n context.fillText(text[i], i * this._charSize, -maxCharHeight.offset);\r\n }\r\n\r\n // Flush the text in the dynamic texture.\r\n\r\n scene.getEngine().updateDynamicTexture(this._texture, canvas, false, true);\r\n }\r\n\r\n /**\r\n * Gets the max char width of a font.\r\n * @param font the font to use, use the W3C CSS notation\r\n * @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 AsciiArtTexture.\r\n * @returns the clone of the texture.\r\n */\r\n public override 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 * @returns the parsed texture\r\n */\r\n public static Parse(source: any, scene: Scene): AsciiArtFontTexture {\r\n const texture = SerializationHelper.Parse(() => new AsciiArtFontTexture(source.name, source.font, source.text, scene), source, scene, null);\r\n\r\n return texture;\r\n }\r\n}\r\n\r\n/**\r\n * Option available in the Ascii Art Post Process.\r\n */\r\nexport interface IAsciiArtPostProcessOptions {\r\n /**\r\n * The font to use following the w3c font definition.\r\n */\r\n font?: string;\r\n\r\n /**\r\n * The character set to use in the postprocess.\r\n */\r\n characterSet?: string;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToTile?: number;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToNormal?: number;\r\n}\r\n\r\n/**\r\n * AsciiArtPostProcess helps rendering everithing in Ascii Art.\r\n *\r\n * Simmply add it to your scene and let the nerd that lives in you have fun.\r\n * Example usage: var pp = new AsciiArtPostProcess(\"myAscii\", \"20px Monospace\", camera);\r\n */\r\nexport class AsciiArtPostProcess extends PostProcess {\r\n /**\r\n * The font texture used to render the char in the post process.\r\n */\r\n private _asciiArtFontTexture: AsciiArtFontTexture;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToTile: number = 0;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToNormal: number = 0;\r\n\r\n /**\r\n * Instantiates a new Ascii Art Post Process.\r\n * @param name the name to give to the postprocess\r\n * @camera the camera to apply the post process to.\r\n * @param camera\r\n * @param options can either be the font name or an option object following the IAsciiArtPostProcessOptions format\r\n */\r\n constructor(name: string, camera: Nullable<Camera>, options?: string | IAsciiArtPostProcessOptions) {\r\n super(name, \"asciiart\", [\"asciiArtFontInfos\", \"asciiArtOptions\"], [\"asciiArtFont\"], 1, camera, Texture.TRILINEAR_SAMPLINGMODE, undefined, true);\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 = options;\r\n } else {\r\n font = options.font || font;\r\n characterSet = options.characterSet || characterSet;\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() || this._scene;\r\n this._asciiArtFontTexture = new AsciiArtFontTexture(name, font, characterSet, scene);\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 }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AO,EAAE,CAAC;QAExD,IAAI,CAAC,OAAO,GAAG,CAAC,MAAc,EAAE,EAAE;YAC9B,MAAM,CAAC,UAAU,CAAC,cAAc,EAAE,IAAI,CAAC,oBAAoB,CAAC,CAAC;YAE7D,MAAM,CAAC,SAAS,CAAC,mBAAmB,EAAE,IAAI,CAAC,oBAAoB,CAAC,QAAQ,EAAE,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;YAEtI,MAAM,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;QACnG,CAAC,CAAC;IACN,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { serialize } from \"core/Misc/decorators\";\r\nimport { SerializationHelper } from \"core/Misc/decorators.serialization\";\r\nimport type { Camera } from \"core/Cameras/camera\";\r\nimport { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { Texture } from \"core/Materials/Textures/texture\";\r\nimport type { Effect } from \"core/Materials/effect\";\r\nimport { PostProcess } from \"core/PostProcesses/postProcess\";\r\nimport type { Scene } from \"core/scene\";\r\nimport \"core/Engines/Extensions/engine.dynamicTexture\";\r\nimport \"./asciiart.fragment\";\r\n\r\n/**\r\n * AsciiArtFontTexture is the helper class used to easily create your ascii art font texture.\r\n *\r\n * It basically takes care rendering the font front the given font size to a texture.\r\n * This is used later on in the postprocess.\r\n */\r\nexport class AsciiArtFontTexture extends BaseTexture {\r\n @serialize(\"font\")\r\n private _font: string;\r\n\r\n @serialize(\"text\")\r\n private _text: string;\r\n\r\n private _charSize: number;\r\n\r\n /**\r\n * Gets the size of one char in the texture (each char fits in size * size space in the texture).\r\n */\r\n public get charSize(): number {\r\n return this._charSize;\r\n }\r\n\r\n /**\r\n * Create a new instance of the Ascii Art FontTexture class\r\n * @param name the name of the texture\r\n * @param font the font to use, use the W3C CSS notation\r\n * @param text the caracter set to use in the rendering.\r\n * @param scene the scene that owns the texture\r\n */\r\n constructor(name: string, font: string, text: string, scene: Nullable<Scene> = null) {\r\n super(scene);\r\n\r\n scene = this.getScene();\r\n\r\n if (!scene) {\r\n return;\r\n }\r\n\r\n this.name = name;\r\n this._text == text;\r\n this._font == font;\r\n\r\n this.wrapU = Texture.CLAMP_ADDRESSMODE;\r\n this.wrapV = Texture.CLAMP_ADDRESSMODE;\r\n //this.anisotropicFilteringLevel = 1;\r\n\r\n // Get the font specific info.\r\n const maxCharHeight = this._getFontHeight(font);\r\n const maxCharWidth = this._getFontWidth(font);\r\n\r\n this._charSize = Math.max(maxCharHeight.height, maxCharWidth);\r\n\r\n // This is an approximate size, but should always be able to fit at least the maxCharCount.\r\n const textureWidth = Math.ceil(this._charSize * text.length);\r\n const textureHeight = this._charSize;\r\n\r\n // Create the texture that will store the font characters.\r\n this._texture = scene.getEngine().createDynamicTexture(textureWidth, textureHeight, false, Texture.NEAREST_SAMPLINGMODE);\r\n //scene.getEngine().setclamp\r\n const textureSize = this.getSize();\r\n\r\n // Create a canvas with the final size: the one matching the texture.\r\n const canvas = document.createElement(\"canvas\");\r\n canvas.width = textureSize.width;\r\n canvas.height = textureSize.height;\r\n const context = <CanvasRenderingContext2D>canvas.getContext(\"2d\");\r\n context.textBaseline = \"top\";\r\n context.font = font;\r\n context.fillStyle = \"white\";\r\n context.imageSmoothingEnabled = false;\r\n\r\n // Sets the text in the texture.\r\n for (let i = 0; i < text.length; i++) {\r\n context.fillText(text[i], i * this._charSize, -maxCharHeight.offset);\r\n }\r\n\r\n // Flush the text in the dynamic texture.\r\n\r\n scene.getEngine().updateDynamicTexture(this._texture, canvas, false, true);\r\n }\r\n\r\n /**\r\n * Gets the max char width of a font.\r\n * @param font the font to use, use the W3C CSS notation\r\n * @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 AsciiArtTexture.\r\n * @returns the clone of the texture.\r\n */\r\n public override 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 * @returns the parsed texture\r\n */\r\n public static Parse(source: any, scene: Scene): AsciiArtFontTexture {\r\n const texture = SerializationHelper.Parse(() => new AsciiArtFontTexture(source.name, source.font, source.text, scene), source, scene, null);\r\n\r\n return texture;\r\n }\r\n}\r\n\r\n/**\r\n * Option available in the Ascii Art Post Process.\r\n */\r\nexport interface IAsciiArtPostProcessOptions {\r\n /**\r\n * The font to use following the w3c font definition.\r\n */\r\n font?: string;\r\n\r\n /**\r\n * The character set to use in the postprocess.\r\n */\r\n characterSet?: string;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToTile?: number;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n mixToNormal?: number;\r\n}\r\n\r\n/**\r\n * AsciiArtPostProcess helps rendering everithing in Ascii Art.\r\n *\r\n * Simmply add it to your scene and let the nerd that lives in you have fun.\r\n * Example usage: var pp = new AsciiArtPostProcess(\"myAscii\", \"20px Monospace\", camera);\r\n */\r\nexport class AsciiArtPostProcess extends PostProcess {\r\n /**\r\n * The font texture used to render the char in the post process.\r\n */\r\n private _asciiArtFontTexture: AsciiArtFontTexture;\r\n\r\n /**\r\n * This defines the amount you want to mix the \"tile\" or caracter space colored in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToTile: number = 0;\r\n\r\n /**\r\n * This defines the amount you want to mix the normal rendering pass in the ascii art.\r\n * This number is defined between 0 and 1;\r\n */\r\n public mixToNormal: number = 0;\r\n\r\n /**\r\n * Instantiates a new Ascii Art Post Process.\r\n * @param name the name to give to the postprocess\r\n * @camera the camera to apply the post process to.\r\n * @param camera\r\n * @param options can either be the font name or an option object following the IAsciiArtPostProcessOptions format\r\n */\r\n constructor(name: string, camera: Nullable<Camera>, options?: string | IAsciiArtPostProcessOptions) {\r\n super(name, \"asciiart\", [\"asciiArtFontInfos\", \"asciiArtOptions\"], [\"asciiArtFont\"], 1, camera, Texture.TRILINEAR_SAMPLINGMODE, undefined, true);\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 = options;\r\n } else {\r\n font = options.font || font;\r\n characterSet = options.characterSet || characterSet;\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() || this._scene;\r\n this._asciiArtFontTexture = new AsciiArtFontTexture(name, font, characterSet, scene);\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,5 +1,5 @@
|
|
|
1
1
|
// Do not edit.
|
|
2
|
-
import { ShaderStore } from "@
|
|
2
|
+
import { ShaderStore } from "@onerjs/core/Engines/shaderStore.js";
|
|
3
3
|
const name = "asciiartPixelShader";
|
|
4
4
|
const shader = `varying vec2 vUV;uniform sampler2D textureSampler;uniform sampler2D asciiArtFont;uniform vec4 asciiArtFontInfos;uniform vec4 asciiArtOptions;float getLuminance(vec3 color)
|
|
5
5
|
{return clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asciiart.fragment.js","sourceRoot":"","sources":["../../../../dev/postProcesses/src/asciiArt/asciiart.fragment.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE
|
|
1
|
+
{"version":3,"file":"asciiart.fragment.js","sourceRoot":"","sources":["../../../../dev/postProcesses/src/asciiArt/asciiart.fragment.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,4CAAiC;AAEvD,MAAM,IAAI,GAAG,qBAAqB,CAAC;AACnC,MAAM,MAAM,GAAG;;;;y+BAI09B,CAAC;AAC1+B,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,mBAAmB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"core/Engines/shaderStore\";\n\nconst name = \"asciiartPixelShader\";\nconst shader = `varying vec2 vUV;uniform sampler2D textureSampler;uniform sampler2D asciiArtFont;uniform vec4 asciiArtFontInfos;uniform vec4 asciiArtOptions;float getLuminance(vec3 color)\n{return clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);}\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) \n{float caracterSize=asciiArtFontInfos.x;float numChar=asciiArtFontInfos.y-1.0;float fontx=asciiArtFontInfos.z;float fonty=asciiArtFontInfos.w;float screenx=asciiArtOptions.x;float screeny=asciiArtOptions.y;float tileX=float(floor((gl_FragCoord.x)/caracterSize))*caracterSize/screenx;float tileY=float(floor((gl_FragCoord.y)/caracterSize))*caracterSize/screeny;vec2 tileUV=vec2(tileX,tileY);vec4 tileColor=texture2D(textureSampler,tileUV);vec4 baseColor=texture2D(textureSampler,vUV);float tileLuminance=getLuminance(tileColor.rgb);float offsetx=(float(floor(tileLuminance*numChar)))*caracterSize/fontx;float offsety=0.0;float x=float(mod(gl_FragCoord.x,caracterSize))/fontx;float y=float(mod(gl_FragCoord.y,caracterSize))/fonty;vec4 finalColor= texture2D(asciiArtFont,vec2(offsetx+x,offsety+(caracterSize/fonty-y)));finalColor.rgb*=tileColor.rgb;finalColor.a=1.0;finalColor= mix(finalColor,tileColor,asciiArtOptions.w);finalColor= mix(finalColor,baseColor,asciiArtOptions.z);gl_FragColor=finalColor;}`;\n// Sideeffect\nif (!ShaderStore.ShadersStore[name]) {\n ShaderStore.ShadersStore[name] = shader;\n}\n/** @internal */\nexport const asciiartPixelShader = { name, shader };\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { Nullable } from "@
|
|
2
|
-
import type { Camera } from "@
|
|
3
|
-
import { BaseTexture } from "@
|
|
4
|
-
import { PostProcess } from "@
|
|
5
|
-
import type { Scene } from "@
|
|
6
|
-
import "@
|
|
1
|
+
import type { Nullable } from "@onerjs/core/types.js";
|
|
2
|
+
import type { Camera } from "@onerjs/core/Cameras/camera.js";
|
|
3
|
+
import { BaseTexture } from "@onerjs/core/Materials/Textures/baseTexture.js";
|
|
4
|
+
import { PostProcess } from "@onerjs/core/PostProcesses/postProcess.js";
|
|
5
|
+
import type { Scene } from "@onerjs/core/scene.js";
|
|
6
|
+
import "@onerjs/core/Engines/Extensions/engine.dynamicTexture.js";
|
|
7
7
|
import "./digitalrain.fragment.js";
|
|
8
8
|
/**
|
|
9
9
|
* DigitalRainFontTexture is the helper class used to easily create your digital rain font texture.
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { __decorate } from "@
|
|
2
|
-
import { serialize } from "@
|
|
3
|
-
import { SerializationHelper } from "@
|
|
4
|
-
import { Matrix } from "@
|
|
5
|
-
import { BaseTexture } from "@
|
|
6
|
-
import { Texture } from "@
|
|
7
|
-
import { PostProcess } from "@
|
|
8
|
-
import "@
|
|
1
|
+
import { __decorate } from "@onerjs/core/tslib.es6.js";
|
|
2
|
+
import { serialize } from "@onerjs/core/Misc/decorators.js";
|
|
3
|
+
import { SerializationHelper } from "@onerjs/core/Misc/decorators.serialization.js";
|
|
4
|
+
import { Matrix } from "@onerjs/core/Maths/math.vector.js";
|
|
5
|
+
import { BaseTexture } from "@onerjs/core/Materials/Textures/baseTexture.js";
|
|
6
|
+
import { Texture } from "@onerjs/core/Materials/Textures/texture.js";
|
|
7
|
+
import { PostProcess } from "@onerjs/core/PostProcesses/postProcess.js";
|
|
8
|
+
import "@onerjs/core/Engines/Extensions/engine.dynamicTexture.js";
|
|
9
9
|
import "./digitalrain.fragment.js";
|
|
10
10
|
/**
|
|
11
11
|
* DigitalRainFontTexture is the helper class used to easily create your digital rain font texture.
|
|
@@ -1 +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,KAAK,GAAG,OAAO,C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AAI,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"]}
|
|
1
|
+
{"version":3,"file":"digitalRainPostProcess.js","sourceRoot":"","sources":["../../../../dev/postProcesses/src/digitalRain/digitalRainPostProcess.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,wCAA6B;AACjD,OAAO,EAAE,mBAAmB,EAAE,sDAA2C;AACzE,OAAO,EAAE,MAAM,EAAE,0CAA+B;AAEhD,OAAO,EAAE,WAAW,EAAE,uDAA4C;AAClE,OAAO,EAAE,OAAO,EAAE,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IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,EACb,IAAI,CAAC,MAAM,EAAE,CAChB,CAAC;QAEF,IAAI,CAAC,OAAO,GAAG,CAAC,MAAc,EAAE,EAAE;YAC9B,MAAM,CAAC,UAAU,CAAC,iBAAiB,EAAE,IAAI,CAAC,uBAAuB,CAAC,CAAC;YAEnE,MAAM,CAAC,SAAS,CAAC,sBAAsB,EAAE,IAAI,CAAC,uBAAuB,CAAC,QAAQ,EAAE,YAAY,CAAC,MAAM,EAAE,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;YAE5I,MAAM,CAAC,SAAS,CAAC,oBAAoB,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;YAElG,MAAM,CAAC,SAAS,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;YAExC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC;YACpB,cAAc,GAAG,KAAK,CAAC;YACvB,MAAM,CAAC,QAAQ,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;QACtD,CAAC,CAAC;IACN,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport { serialize } 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"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Do not edit.
|
|
2
|
-
import { ShaderStore } from "@
|
|
2
|
+
import { ShaderStore } from "@onerjs/core/Engines/shaderStore.js";
|
|
3
3
|
const name = "digitalrainPixelShader";
|
|
4
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
5
|
{return clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);}
|
|
@@ -1 +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
|
|
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,4CAAiC;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"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// Do not edit.
|
|
2
|
-
import { ShaderStore } from "@
|
|
2
|
+
import { ShaderStore } from "@onerjs/core/Engines/shaderStore.js";
|
|
3
3
|
const name = "edgeDetectionPixelShader";
|
|
4
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
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;}}
|
|
@@ -1 +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
|
|
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,4CAAiC;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"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { Nullable } from "@
|
|
2
|
-
import type { Camera } from "@
|
|
3
|
-
import type { PostProcessOptions } from "@
|
|
4
|
-
import { PostProcess } from "@
|
|
5
|
-
import "@
|
|
6
|
-
import { Color3 } from "@
|
|
7
|
-
import type { Scene } from "@
|
|
1
|
+
import type { Nullable } from "@onerjs/core/types.js";
|
|
2
|
+
import type { Camera } from "@onerjs/core/Cameras/camera.js";
|
|
3
|
+
import type { PostProcessOptions } from "@onerjs/core/PostProcesses/postProcess.js";
|
|
4
|
+
import { PostProcess } from "@onerjs/core/PostProcesses/postProcess.js";
|
|
5
|
+
import "@onerjs/core/Rendering/geometryBufferRendererSceneComponent.js";
|
|
6
|
+
import { Color3 } from "@onerjs/core/Maths/math.color.js";
|
|
7
|
+
import type { Scene } from "@onerjs/core/scene.js";
|
|
8
8
|
import "./edgeDetection.fragment.js";
|
|
9
9
|
/**
|
|
10
10
|
* The Edge Detection effect highlights the edges of objects in the scene like a toon.
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { __decorate } from "@
|
|
2
|
-
import { Logger } from "@
|
|
3
|
-
import { PostProcess } from "@
|
|
4
|
-
import { Constants } from "@
|
|
5
|
-
import "@
|
|
6
|
-
import { Color3 } from "@
|
|
7
|
-
import { serialize } from "@
|
|
8
|
-
import { SerializationHelper } from "@
|
|
9
|
-
import { RegisterClass } from "@
|
|
10
|
-
import { EngineStore } from "@
|
|
11
|
-
import { RenderTargetTexture } from "@
|
|
1
|
+
import { __decorate } from "@onerjs/core/tslib.es6.js";
|
|
2
|
+
import { Logger } from "@onerjs/core/Misc/logger.js";
|
|
3
|
+
import { PostProcess } from "@onerjs/core/PostProcesses/postProcess.js";
|
|
4
|
+
import { Constants } from "@onerjs/core/Engines/constants.js";
|
|
5
|
+
import "@onerjs/core/Rendering/geometryBufferRendererSceneComponent.js";
|
|
6
|
+
import { Color3 } from "@onerjs/core/Maths/math.color.js";
|
|
7
|
+
import { serialize } from "@onerjs/core/Misc/decorators.js";
|
|
8
|
+
import { SerializationHelper } from "@onerjs/core/Misc/decorators.serialization.js";
|
|
9
|
+
import { RegisterClass } from "@onerjs/core/Misc/typeStore.js";
|
|
10
|
+
import { EngineStore } from "@onerjs/core/Engines/engineStore.js";
|
|
11
|
+
import { RenderTargetTexture } from "@onerjs/core/Materials/Textures/renderTargetTexture.js";
|
|
12
12
|
import "./edgeDetection.fragment.js";
|
|
13
13
|
/**
|
|
14
14
|
* The Edge Detection effect highlights the edges of objects in the scene like a toon.
|
|
@@ -1 +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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AM,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"]}
|
|
1
|
+
{"version":3,"file":"edgeDetectionPostProcess.js","sourceRoot":"","sources":["../../../../dev/postProcesses/src/edgeDetection/edgeDetectionPostProcess.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,oCAAyB;AAI1C,OAAO,EAAE,WAAW,EAAE,kDAAuC;AAC7D,OAAO,EAAE,SAAS,EAAE,0CAA+B;AACnD,wEAA6D;AAE7D,OAAO,EAAE,MAAM,EAAE,yCAA8B;AAC/C,OAAO,EAAE,SAAS,EAAE,wCAA6B;AACjD,OAAO,EAAE,mBAAmB,EAAE,sDAA2C;AACzE,OAAO,EAAE,aAAa,EAAE,uCAA4B;AACpD,OAAO,EAAE,WAAW,EAAE,4CAAiC;AACvD,OAAO,E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AAC,uBAAwB,CAAC,UAAU,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;wBAC5F,MAAM,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;wBAChC,MAAM;oBACV,KAAK,CAAC;wBACF,MAAM,CAAC,UAAU,CAAC,gBAAgB,EAAE,EAAE,CAAC,CAAC;wBACxC,MAAM;gBACd,CAAC;gBACD,MAAM,CAAC,MAAM,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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onerjs/post-processes",
|
|
3
|
-
"version": "8.25.
|
|
3
|
+
"version": "8.25.4",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"module": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"postcompile": "build-tools -c add-js-to-es6"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@onerjs/core": "^8.25.
|
|
21
|
+
"@onerjs/core": "^8.25.4",
|
|
22
22
|
"@dev/build-tools": "^1.0.0",
|
|
23
23
|
"@lts/post-processes": "^1.0.0"
|
|
24
24
|
},
|