(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;odistortion_x-col_s*seed) {", "if(seed_x>0.){", "p.y = 1. - (p.y + distortion_y);", "}", "else {", "p.y = distortion_y;", "}", "}", "if(p.xdistortion_y-col_s*seed) {", "if(seed_y>0.){", "p.x=distortion_x;", "}", "else {", "p.x = 1. - (p.x + distortion_x);", "}", "}", "p.x+=normal.x*seed_x*(seed/5.);", "p.y+=normal.y*seed_y*(seed/5.);", //base from RGB shift shader "vec2 offset = amount * vec2( cos(angle), sin(angle));", "vec4 cr = texture2D(tDiffuse, p + offset);", "vec4 cga = texture2D(tDiffuse, p);", "vec4 cb = texture2D(tDiffuse, p - offset);", "gl_FragColor = vec4(cr.r, cga.g, cb.b, cga.a);", //add noise "vec4 snow = 200.*amount*vec4(rand(vec2(xs * seed,ys * seed*50.))*0.2);", "gl_FragColor = gl_FragColor+ snow;", "}", "else {", "gl_FragColor=texture2D (tDiffuse, vUv);", "}", "}"].join("\n") }; var GlitchPass = function (_WHS$Pass) { _inherits(GlitchPass, _WHS$Pass); function GlitchPass(name, dt_size) { _classCallCheck(this, GlitchPass); var _this = _possibleConstructorReturn(this, (GlitchPass.__proto__ || Object.getPrototypeOf(GlitchPass)).call(this, name)); if (DigitalGlitchShader === undefined) console.error("THREE.GlitchPass relies on DigitalGlitchShader"); var shader = DigitalGlitchShader; _this.uniforms = THREE.UniformsUtils.clone(shader.uniforms); if (dt_size == undefined) dt_size = 64; _this.uniforms["tDisp"].value = _this.generateHeightmap(dt_size); _this.material = new THREE.ShaderMaterial({ uniforms: _this.uniforms, vertexShader: shader.vertexShader, fragmentShader: shader.fragmentShader }); _this.camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1); _this.scene = new THREE.Scene(); _this.quad = new THREE.Mesh(new THREE.PlaneBufferGeometry(2, 2), null); _this.scene.add(_this.quad); _this.goWild = false; _this.curF = 0; _this.generateTrigger(); return _this; } _createClass(GlitchPass, [{ key: "render", value: function render(renderer, writeBuffer, readBuffer, delta, maskActive) { this.uniforms["tDiffuse"].value = readBuffer.texture; this.uniforms['seed'].value = Math.random(); //default seeding this.uniforms['byp'].value = 0; if (this.curF % this.randX == 0 || this.goWild == true) { this.uniforms['amount'].value = Math.random() / 30; this.uniforms['angle'].value = THREE.Math.randFloat(-Math.PI, Math.PI); this.uniforms['seed_x'].value = THREE.Math.randFloat(-1, 1); this.uniforms['seed_y'].value = THREE.Math.randFloat(-1, 1); this.uniforms['distortion_x'].value = THREE.Math.randFloat(0, 1); this.uniforms['distortion_y'].value = THREE.Math.randFloat(0, 1); this.curF = 0; this.generateTrigger(); } else if (this.curF % this.randX < this.randX / 5) { this.uniforms['amount'].value = Math.random() / 90; this.uniforms['angle'].value = THREE.Math.randFloat(-Math.PI, Math.PI); this.uniforms['distortion_x'].value = THREE.Math.randFloat(0, 1); this.uniforms['distortion_y'].value = THREE.Math.randFloat(0, 1); this.uniforms['seed_x'].value = THREE.Math.randFloat(-0.3, 0.3); this.uniforms['seed_y'].value = THREE.Math.randFloat(-0.3, 0.3); } else if (this.goWild == false) { this.uniforms['byp'].value = 1; } this.curF++; this.quad.material = this.material; if (this.renderToScreen) { renderer.render(this.scene, this.camera); } else { renderer.render(this.scene, this.camera, writeBuffer, this.clear); } } }, { key: "generateTrigger", value: function generateTrigger() { this.randX = THREE.Math.randInt(120, 240); } }, { key: "generateHeightmap", value: function generateHeightmap(dt_size) { var data_arr = new Float32Array(dt_size * dt_size * 3); var length = dt_size * dt_size; for (var i = 0; i < length; i++) { var val = THREE.Math.randFloat(0, 1); data_arr[i * 3 + 0] = val; data_arr[i * 3 + 1] = val; data_arr[i * 3 + 2] = val; } var texture = new THREE.DataTexture(data_arr, dt_size, dt_size, THREE.RGBFormat, THREE.FloatType); texture.needsUpdate = true; return texture; } }]); return GlitchPass; }(WHS.Pass); // ----------------------------------------------------------------------------- // Game class // ----------------------------------------------------------------------------- var Game = function () { function Game(options) { _classCallCheck(this, Game); this.options = options; this.world = new WHS.World(options.world); this.createPostProcessing(); this.createGeometry(); } _createClass(Game, [{ key: "createPostProcessing", value: function createPostProcessing() { this.postProcessor = new WHS.PostProcessor(this.options.postProcessor); this.world.setPostProcessor(this.postProcessor); this.postProcessor.createRenderPass(); this.postProcessor.createPass(function (composer) { var pass = new GlitchPass('Glitch'); pass.renderToScreen = true; composer.addPass(pass); }); } }, { key: "createGeometry", value: function createGeometry() { this.plane = new WHS.Plane(this.options.plane); this.plane.addTo(this.world); this.sphere = new WHS.Sphere(this.options.sphere); this.sphere.addTo(this.world); } }, { key: "start", value: function start() { this.world.start(); } }]); return Game; }(); // ----------------------------------------------------------------------------- // Application bootstrap // ----------------------------------------------------------------------------- var app = null; function bootstrap() { app.start(); } function configure() { return new Promise(function (resolve) { // some async config fetch could be done from here // ... // Create a Game instance with its conf app = new Game(conf); resolve(true); }); } configure().then(function () { return bootstrap(); }); },{}]},{},[1]);