Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Neon.Client {
  2.  
  3.     export class ShaderHelper {
  4.  
  5.         private static _instance: ShaderHelper;
  6.  
  7.         game: Phaser.Game;
  8.  
  9.         shaderTV: Phaser.Filter;
  10.  
  11.         constructor(game: Phaser.Game) {
  12.             this.game = game;
  13.  
  14.             var tvFragment = [
  15.                 "#ifdef GL_ES",
  16.                 "precision highp float;",
  17.                 "#endif",
  18.  
  19.                 "uniform vec2 resolution;",
  20.                 "uniform float time;",
  21.                 "uniform sampler2D iChannel0;",
  22.                 "float rand(vec2 co) {",
  23.                 "return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);",
  24.                 "}",
  25.                 "void main(void) ",
  26.                 "{",
  27.                 "vec2 q = gl_FragCoord.xy / resolution.xy;",
  28.                 "vec2 uv = 0.5 + (q - 0.5) * (0.98 + 0.006 * sin(0.9 * time));",
  29.                 "vec3 oricol = texture2D(iChannel0, vec2(q.x, 1.0 - q.y)).xyz;",
  30.                 "vec3 col;",
  31.                 "oricol.r = texture2D(iChannel0, vec2(uv.x + 0.003, uv.y)).x;",
  32.                 "oricol.g = texture2D(iChannel0, vec2(uv.x + 0.000, uv.y)).y;",
  33.                 "oricol.b = texture2D(iChannel0, vec2(uv.x - 0.003, uv.y)).z;",
  34.                 "oricol *= 0.6 + 0.4 * 16.0 * uv.x * uv.y * (1.0 - uv.x) * (1.0 - uv.y);",
  35.                 "oricol *= vec3(0.7, 0.8, 0.85);",
  36.                 "oricol *= 0.8 + 0.2 * sin(10.0 * time + uv.y * 200.0);",
  37.                 "oricol *= 1.0 - 0.07 * rand(vec2(time, tan(time)));",
  38.                 "gl_FragColor = vec4(oricol, 0.5);",
  39.                 "}"
  40.             ];
  41.  
  42.             this.shaderTV = new Phaser.Filter(this.game, null, tvFragment);
  43.             this.shaderTV.setResolution(640, 360);
  44.  
  45.             this.game.stage.filters = [this.shaderTV];
  46.  
  47.             ShaderHelper._instance = this;
  48.         }
  49.  
  50.         update() {
  51.             this.shaderTV.update();
  52.         }
  53.  
  54.         public static init(game: Phaser.Game) {
  55.             if (ShaderHelper._instance == null)
  56.                 ShaderHelper._instance = new ShaderHelper(game);
  57.         }
  58.  
  59.         public static getInstance() {
  60.             return ShaderHelper._instance;
  61.         }
  62.  
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement