Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Neon.Client {
- export class ShaderHelper {
- private static _instance: ShaderHelper;
- game: Phaser.Game;
- shaderTV: Phaser.Filter;
- constructor(game: Phaser.Game) {
- this.game = game;
- var tvFragment = [
- "#ifdef GL_ES",
- "precision highp float;",
- "#endif",
- "uniform vec2 resolution;",
- "uniform float time;",
- "uniform sampler2D iChannel0;",
- "float rand(vec2 co) {",
- "return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);",
- "}",
- "void main(void) ",
- "{",
- "vec2 q = gl_FragCoord.xy / resolution.xy;",
- "vec2 uv = 0.5 + (q - 0.5) * (0.98 + 0.006 * sin(0.9 * time));",
- "vec3 oricol = texture2D(iChannel0, vec2(q.x, 1.0 - q.y)).xyz;",
- "vec3 col;",
- "oricol.r = texture2D(iChannel0, vec2(uv.x + 0.003, uv.y)).x;",
- "oricol.g = texture2D(iChannel0, vec2(uv.x + 0.000, uv.y)).y;",
- "oricol.b = texture2D(iChannel0, vec2(uv.x - 0.003, uv.y)).z;",
- "oricol *= 0.6 + 0.4 * 16.0 * uv.x * uv.y * (1.0 - uv.x) * (1.0 - uv.y);",
- "oricol *= vec3(0.7, 0.8, 0.85);",
- "oricol *= 0.8 + 0.2 * sin(10.0 * time + uv.y * 200.0);",
- "oricol *= 1.0 - 0.07 * rand(vec2(time, tan(time)));",
- "gl_FragColor = vec4(oricol, 0.5);",
- "}"
- ];
- this.shaderTV = new Phaser.Filter(this.game, null, tvFragment);
- this.shaderTV.setResolution(640, 360);
- this.game.stage.filters = [this.shaderTV];
- ShaderHelper._instance = this;
- }
- update() {
- this.shaderTV.update();
- }
- public static init(game: Phaser.Game) {
- if (ShaderHelper._instance == null)
- ShaderHelper._instance = new ShaderHelper(game);
- }
- public static getInstance() {
- return ShaderHelper._instance;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement