@babylonjs/post-processes 5.0.0-alpha.60 → 5.0.0-alpha.64
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/asciiart.fragment.js +1 -1
- package/asciiArt/asciiart.fragment.js.map +1 -1
- package/digitalRain/digitalRainPostProcess.d.ts +4 -0
- package/digitalRain/digitalRainPostProcess.js +5 -1
- package/digitalRain/digitalRainPostProcess.js.map +1 -1
- package/digitalRain/digitalrain.fragment.js +1 -1
- package/digitalRain/digitalrain.fragment.js.map +1 -1
- package/package.json +2 -2
@@ -1,6 +1,6 @@
|
|
1
1
|
import { ShaderStore } from "@babylonjs/core/Engines/shaderStore.js";
|
2
2
|
var name = 'asciiartPixelShader';
|
3
|
-
var shader = "\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D asciiArtFont;\n\nuniform vec4 asciiArtFontInfos;\nuniform vec4 asciiArtOptions;\n\nfloat getLuminance(vec3 color)\n{\nreturn clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);\n}\n\nvoid main(void)\n{\nfloat caracterSize=asciiArtFontInfos.x;\nfloat numChar=asciiArtFontInfos.y-1.0;\nfloat fontx=asciiArtFontInfos.z;\nfloat fonty=asciiArtFontInfos.w;\nfloat screenx=asciiArtOptions.x;\nfloat screeny=asciiArtOptions.y;\nfloat tileX=float(floor((gl_FragCoord.x)/caracterSize))*caracterSize/screenx;\nfloat tileY=float(floor((gl_FragCoord.y)/caracterSize))*caracterSize/screeny;\nvec2 tileUV=vec2(tileX,tileY);\nvec4 tileColor=texture2D(textureSampler,tileUV);\nvec4 baseColor=texture2D(textureSampler,vUV);\nfloat tileLuminance=getLuminance(tileColor.rgb);\nfloat offsetx=(float(floor(tileLuminance*numChar)))*caracterSize/fontx;\nfloat offsety=0.0;\nfloat x=float(mod(gl_FragCoord.x,caracterSize))/fontx;\nfloat y=float(mod(gl_FragCoord.y,caracterSize))/fonty;\nvec4 finalColor=texture2D(asciiArtFont,vec2(offsetx+x,offsety+(caracterSize/fonty-y)));\nfinalColor.rgb*=tileColor.rgb;\nfinalColor.a=1.0;\nfinalColor=mix(finalColor,tileColor,asciiArtOptions.w);\nfinalColor=mix(finalColor,baseColor,asciiArtOptions.z);\ngl_FragColor=finalColor;\n}";
|
3
|
+
var shader = "\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D asciiArtFont;\n\nuniform vec4 asciiArtFontInfos;\nuniform vec4 asciiArtOptions;\n\nfloat getLuminance(vec3 color)\n{\nreturn clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);\n}\n\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{\nfloat caracterSize=asciiArtFontInfos.x;\nfloat numChar=asciiArtFontInfos.y-1.0;\nfloat fontx=asciiArtFontInfos.z;\nfloat fonty=asciiArtFontInfos.w;\nfloat screenx=asciiArtOptions.x;\nfloat screeny=asciiArtOptions.y;\nfloat tileX=float(floor((gl_FragCoord.x)/caracterSize))*caracterSize/screenx;\nfloat tileY=float(floor((gl_FragCoord.y)/caracterSize))*caracterSize/screeny;\nvec2 tileUV=vec2(tileX,tileY);\nvec4 tileColor=texture2D(textureSampler,tileUV);\nvec4 baseColor=texture2D(textureSampler,vUV);\nfloat tileLuminance=getLuminance(tileColor.rgb);\nfloat offsetx=(float(floor(tileLuminance*numChar)))*caracterSize/fontx;\nfloat offsety=0.0;\nfloat x=float(mod(gl_FragCoord.x,caracterSize))/fontx;\nfloat y=float(mod(gl_FragCoord.y,caracterSize))/fonty;\nvec4 finalColor=texture2D(asciiArtFont,vec2(offsetx+x,offsety+(caracterSize/fonty-y)));\nfinalColor.rgb*=tileColor.rgb;\nfinalColor.a=1.0;\nfinalColor=mix(finalColor,tileColor,asciiArtOptions.w);\nfinalColor=mix(finalColor,baseColor,asciiArtOptions.z);\ngl_FragColor=finalColor;\n}";
|
4
4
|
ShaderStore.ShadersStore[name] = shader;
|
5
5
|
/** @hidden */
|
6
6
|
export var asciiartPixelShader = { name: name, shader: shader };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"asciiart.fragment.js","sourceRoot":"","sources":["../../../sourceES6/postProcessesLibrary/src/asciiArt/asciiart.fragment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAElE,IAAI,IAAI,GAAG,qBAAqB,CAAC;AACjC,IAAI,MAAM,GAAG,
|
1
|
+
{"version":3,"file":"asciiart.fragment.js","sourceRoot":"","sources":["../../../sourceES6/postProcessesLibrary/src/asciiArt/asciiart.fragment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAElE,IAAI,IAAI,GAAG,qBAAqB,CAAC;AACjC,IAAI,MAAM,GAAG,40CAsCX,CAAC;AAEH,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AACxC,cAAc;AACd,MAAM,CAAC,IAAI,mBAAmB,GAAG,EAAE,IAAI,MAAA,EAAE,MAAM,QAAA,EAAE,CAAC","sourcesContent":["import { ShaderStore } from \"@babylonjs/core/Engines/shaderStore\";\n\nlet name = 'asciiartPixelShader';\nlet shader = `\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D asciiArtFont;\n\nuniform vec4 asciiArtFontInfos;\nuniform vec4 asciiArtOptions;\n\nfloat getLuminance(vec3 color)\n{\nreturn clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);\n}\n\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{\nfloat caracterSize=asciiArtFontInfos.x;\nfloat numChar=asciiArtFontInfos.y-1.0;\nfloat fontx=asciiArtFontInfos.z;\nfloat fonty=asciiArtFontInfos.w;\nfloat screenx=asciiArtOptions.x;\nfloat screeny=asciiArtOptions.y;\nfloat tileX=float(floor((gl_FragCoord.x)/caracterSize))*caracterSize/screenx;\nfloat tileY=float(floor((gl_FragCoord.y)/caracterSize))*caracterSize/screeny;\nvec2 tileUV=vec2(tileX,tileY);\nvec4 tileColor=texture2D(textureSampler,tileUV);\nvec4 baseColor=texture2D(textureSampler,vUV);\nfloat tileLuminance=getLuminance(tileColor.rgb);\nfloat offsetx=(float(floor(tileLuminance*numChar)))*caracterSize/fontx;\nfloat offsety=0.0;\nfloat x=float(mod(gl_FragCoord.x,caracterSize))/fontx;\nfloat y=float(mod(gl_FragCoord.y,caracterSize))/fonty;\nvec4 finalColor=texture2D(asciiArtFont,vec2(offsetx+x,offsety+(caracterSize/fonty-y)));\nfinalColor.rgb*=tileColor.rgb;\nfinalColor.a=1.0;\nfinalColor=mix(finalColor,tileColor,asciiArtOptions.w);\nfinalColor=mix(finalColor,baseColor,asciiArtOptions.z);\ngl_FragColor=finalColor;\n}`;\n\nShaderStore.ShadersStore[name] = shader;\n/** @hidden */\nexport var asciiartPixelShader = { name, shader };\n"]}
|
@@ -91,6 +91,10 @@ export declare class DigitalRainPostProcess extends PostProcess {
|
|
91
91
|
* This number is defined between 0 and 1;
|
92
92
|
*/
|
93
93
|
mixToNormal: number;
|
94
|
+
/**
|
95
|
+
* Speed of the effect
|
96
|
+
*/
|
97
|
+
speed: number;
|
94
98
|
/**
|
95
99
|
* Instantiates a new Digital Rain Post Process.
|
96
100
|
* @param name the name to give to the postprocess
|
@@ -175,6 +175,10 @@ var DigitalRainPostProcess = /** @class */ (function (_super) {
|
|
175
175
|
* This number is defined between 0 and 1;
|
176
176
|
*/
|
177
177
|
_this.mixToNormal = 0;
|
178
|
+
/**
|
179
|
+
* Speed of the effect
|
180
|
+
*/
|
181
|
+
_this.speed = 0.003;
|
178
182
|
// Default values.
|
179
183
|
var font = "15px Monospace";
|
180
184
|
var characterSet = "古池や蛙飛び込む水の音ふるいけやかわずとびこむみずのおと初しぐれ猿も小蓑をほしげ也はつしぐれさるもこみのをほしげなり江戸の雨何石呑んだ時鳥えどのあめなんごくのんだほととぎす";
|
@@ -199,7 +203,7 @@ var DigitalRainPostProcess = /** @class */ (function (_super) {
|
|
199
203
|
effect.setFloat4("digitalRainFontInfos", _this._digitalRainFontTexture.charSize, characterSet.length, textureSize.width, textureSize.height);
|
200
204
|
effect.setFloat4("digitalRainOptions", _this.width, _this.height, _this.mixToNormal, _this.mixToTile);
|
201
205
|
effect.setMatrix("matrixSpeed", matrix);
|
202
|
-
alpha +=
|
206
|
+
alpha += _this.speed;
|
203
207
|
cosTimeZeroOne = alpha;
|
204
208
|
effect.setFloat('cosTimeZeroOne', cosTimeZeroOne);
|
205
209
|
};
|
@@ -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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,CAAC,SAAS,CAAC,sBAAsB,EACnC,KAAI,CAAC,uBAAuB,CAAC,QAAQ,EACrC,YAAY,CAAC,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,KAAK,CAAC;YACf,cAAc,GAAG,KAAK,CAAC;YACvB,MAAM,CAAC,QAAQ,CAAC,gBAAgB,EAAE,cAAc,CAAC,CAAC;QACtD,CAAC,CAAC;;IACN,CAAC;IACL,6BAAC;AAAD,CAAC,AA1FD,CAA4C,WAAW,GA0FtD","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 * 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 += 0.003;\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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,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,6 +1,6 @@
|
|
1
1
|
import { ShaderStore } from "@babylonjs/core/Engines/shaderStore.js";
|
2
2
|
var name = 'digitalrainPixelShader';
|
3
|
-
var shader = "\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D digitalRainFont;\n\nuniform vec4 digitalRainFontInfos;\nuniform vec4 digitalRainOptions;\nuniform mat4 matrixSpeed;\nuniform float cosTimeZeroOne;\n\nfloat getLuminance(vec3 color)\n{\nreturn clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);\n}\n\nvoid main(void)\n{\nfloat caracterSize=digitalRainFontInfos.x;\nfloat numChar=digitalRainFontInfos.y-1.0;\nfloat fontx=digitalRainFontInfos.z;\nfloat fonty=digitalRainFontInfos.w;\nfloat screenx=digitalRainOptions.x;\nfloat screeny=digitalRainOptions.y;\nfloat ratio=screeny/fonty;\nfloat columnx=float(floor((gl_FragCoord.x)/caracterSize));\nfloat tileX=float(floor((gl_FragCoord.x)/caracterSize))*caracterSize/screenx;\nfloat tileY=float(floor((gl_FragCoord.y)/caracterSize))*caracterSize/screeny;\nvec2 tileUV=vec2(tileX,tileY);\nvec4 tileColor=texture2D(textureSampler,tileUV);\nvec4 baseColor=texture2D(textureSampler,vUV);\nfloat tileLuminance=getLuminance(tileColor.rgb);\nint st=int(mod(columnx,4.0));\nfloat speed=cosTimeZeroOne*(sin(tileX*314.5)*0.5+0.6);\nfloat x=float(mod(gl_FragCoord.x,caracterSize))/fontx;\nfloat y=float(mod(speed+gl_FragCoord.y/screeny,1.0));\ny*=ratio;\nvec4 finalColor=texture2D(digitalRainFont,vec2(x,1.0-y));\nvec3 high=finalColor.rgb*(vec3(1.2,1.2,1.2)*pow(1.0-y,30.0));\nfinalColor.rgb*=vec3(pow(tileLuminance,5.0),pow(tileLuminance,1.5),pow(tileLuminance,3.0));\nfinalColor.rgb+=high;\nfinalColor.rgb=clamp(finalColor.rgb,0.,1.);\nfinalColor.a=1.0;\nfinalColor=mix(finalColor,tileColor,digitalRainOptions.w);\nfinalColor=mix(finalColor,baseColor,digitalRainOptions.z);\ngl_FragColor=finalColor;\n}";
|
3
|
+
var shader = "\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D digitalRainFont;\n\nuniform vec4 digitalRainFontInfos;\nuniform vec4 digitalRainOptions;\nuniform mat4 matrixSpeed;\nuniform float cosTimeZeroOne;\n\nfloat getLuminance(vec3 color)\n{\nreturn clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);\n}\n\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{\nfloat caracterSize=digitalRainFontInfos.x;\nfloat numChar=digitalRainFontInfos.y-1.0;\nfloat fontx=digitalRainFontInfos.z;\nfloat fonty=digitalRainFontInfos.w;\nfloat screenx=digitalRainOptions.x;\nfloat screeny=digitalRainOptions.y;\nfloat ratio=screeny/fonty;\nfloat columnx=float(floor((gl_FragCoord.x)/caracterSize));\nfloat tileX=float(floor((gl_FragCoord.x)/caracterSize))*caracterSize/screenx;\nfloat tileY=float(floor((gl_FragCoord.y)/caracterSize))*caracterSize/screeny;\nvec2 tileUV=vec2(tileX,tileY);\nvec4 tileColor=texture2D(textureSampler,tileUV);\nvec4 baseColor=texture2D(textureSampler,vUV);\nfloat tileLuminance=getLuminance(tileColor.rgb);\nint st=int(mod(columnx,4.0));\nfloat speed=cosTimeZeroOne*(sin(tileX*314.5)*0.5+0.6);\nfloat x=float(mod(gl_FragCoord.x,caracterSize))/fontx;\nfloat y=float(mod(speed+gl_FragCoord.y/screeny,1.0));\ny*=ratio;\nvec4 finalColor=texture2D(digitalRainFont,vec2(x,1.0-y));\nvec3 high=finalColor.rgb*(vec3(1.2,1.2,1.2)*pow(1.0-y,30.0));\nfinalColor.rgb*=vec3(pow(tileLuminance,5.0),pow(tileLuminance,1.5),pow(tileLuminance,3.0));\nfinalColor.rgb+=high;\nfinalColor.rgb=clamp(finalColor.rgb,0.,1.);\nfinalColor.a=1.0;\nfinalColor=mix(finalColor,tileColor,digitalRainOptions.w);\nfinalColor=mix(finalColor,baseColor,digitalRainOptions.z);\ngl_FragColor=finalColor;\n}";
|
4
4
|
ShaderStore.ShadersStore[name] = shader;
|
5
5
|
/** @hidden */
|
6
6
|
export var digitalrainPixelShader = { name: name, shader: shader };
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"digitalrain.fragment.js","sourceRoot":"","sources":["../../../sourceES6/postProcessesLibrary/src/digitalRain/digitalrain.fragment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAElE,IAAI,IAAI,GAAG,wBAAwB,CAAC;AACpC,IAAI,MAAM,GAAG,
|
1
|
+
{"version":3,"file":"digitalrain.fragment.js","sourceRoot":"","sources":["../../../sourceES6/postProcessesLibrary/src/digitalRain/digitalrain.fragment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAElE,IAAI,IAAI,GAAG,wBAAwB,CAAC;AACpC,IAAI,MAAM,GAAG,qqDA8CX,CAAC;AAEH,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AACxC,cAAc;AACd,MAAM,CAAC,IAAI,sBAAsB,GAAG,EAAE,IAAI,MAAA,EAAE,MAAM,QAAA,EAAE,CAAC","sourcesContent":["import { ShaderStore } from \"@babylonjs/core/Engines/shaderStore\";\n\nlet name = 'digitalrainPixelShader';\nlet shader = `\nvarying vec2 vUV;\nuniform sampler2D textureSampler;\nuniform sampler2D digitalRainFont;\n\nuniform vec4 digitalRainFontInfos;\nuniform vec4 digitalRainOptions;\nuniform mat4 matrixSpeed;\nuniform float cosTimeZeroOne;\n\nfloat getLuminance(vec3 color)\n{\nreturn clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);\n}\n\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void)\n{\nfloat caracterSize=digitalRainFontInfos.x;\nfloat numChar=digitalRainFontInfos.y-1.0;\nfloat fontx=digitalRainFontInfos.z;\nfloat fonty=digitalRainFontInfos.w;\nfloat screenx=digitalRainOptions.x;\nfloat screeny=digitalRainOptions.y;\nfloat ratio=screeny/fonty;\nfloat columnx=float(floor((gl_FragCoord.x)/caracterSize));\nfloat tileX=float(floor((gl_FragCoord.x)/caracterSize))*caracterSize/screenx;\nfloat tileY=float(floor((gl_FragCoord.y)/caracterSize))*caracterSize/screeny;\nvec2 tileUV=vec2(tileX,tileY);\nvec4 tileColor=texture2D(textureSampler,tileUV);\nvec4 baseColor=texture2D(textureSampler,vUV);\nfloat tileLuminance=getLuminance(tileColor.rgb);\nint st=int(mod(columnx,4.0));\nfloat speed=cosTimeZeroOne*(sin(tileX*314.5)*0.5+0.6);\nfloat x=float(mod(gl_FragCoord.x,caracterSize))/fontx;\nfloat y=float(mod(speed+gl_FragCoord.y/screeny,1.0));\ny*=ratio;\nvec4 finalColor=texture2D(digitalRainFont,vec2(x,1.0-y));\nvec3 high=finalColor.rgb*(vec3(1.2,1.2,1.2)*pow(1.0-y,30.0));\nfinalColor.rgb*=vec3(pow(tileLuminance,5.0),pow(tileLuminance,1.5),pow(tileLuminance,3.0));\nfinalColor.rgb+=high;\nfinalColor.rgb=clamp(finalColor.rgb,0.,1.);\nfinalColor.a=1.0;\nfinalColor=mix(finalColor,tileColor,digitalRainOptions.w);\nfinalColor=mix(finalColor,baseColor,digitalRainOptions.z);\ngl_FragColor=finalColor;\n}`;\n\nShaderStore.ShadersStore[name] = shader;\n/** @hidden */\nexport var digitalrainPixelShader = { name, shader };\n"]}
|
package/package.json
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
},
|
5
5
|
"name": "@babylonjs/post-processes",
|
6
6
|
"description": "The Babylon.js materials library is a collection of advanced materials to be used in a Babylon.js scene.",
|
7
|
-
"version": "5.0.0-alpha.
|
7
|
+
"version": "5.0.0-alpha.64",
|
8
8
|
"repository": {
|
9
9
|
"type": "git",
|
10
10
|
"url": "https://github.com/BabylonJS/Babylon.js.git"
|
@@ -53,7 +53,7 @@
|
|
53
53
|
],
|
54
54
|
"license": "Apache-2.0",
|
55
55
|
"dependencies": {
|
56
|
-
"@babylonjs/core": "5.0.0-alpha.
|
56
|
+
"@babylonjs/core": "5.0.0-alpha.64",
|
57
57
|
"tslib": "^2.3.1"
|
58
58
|
},
|
59
59
|
"engines": {
|