From f6de53c5ed8d8011d518ef3ad7d9e0dff0fe7efd Mon Sep 17 00:00:00 2001 From: Jeena Date: Thu, 3 Jul 2014 23:09:09 +0200 Subject: [PATCH] first draft of opengl filter --- app/Game/Client/View/Views/PixiView.js | 72 +++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 1 deletion(-) diff --git a/app/Game/Client/View/Views/PixiView.js b/app/Game/Client/View/Views/PixiView.js index d35b18a..83a4c32 100755 --- a/app/Game/Client/View/Views/PixiView.js +++ b/app/Game/Client/View/Views/PixiView.js @@ -185,6 +185,76 @@ function (Parent, DomController, PIXI, Settings, Nc) { grayFilter.gray = 0.85; this.infoFilters = [blurFilter, grayFilter]; + + var ColorMatrixFilter = function() + { + PIXI.AbstractFilter.call( this ); + + this.passes = [this]; + + // set the uniforms + this.uniforms = { + matrix: {type: 'mat4', value: [1,0,0,0, + 0,1,0,0, + 0,0,1,0, + 0,0,0,1]}, + gray: {type: '1f', value: 1}, + shirtColor: {type: '4fv', value: [1,1,1,1]} + }; + + this.fragmentSrc = [ + 'precision mediump float;', + 'varying vec2 vTextureCoord;', + 'varying vec4 vColor;', + 'uniform float invert;', + 'uniform mat4 matrix;', + 'uniform sampler2D uSampler;', + 'uniform float gray;', + 'uniform vec4 shirtColor;', + + 'void main(void) {', + ' vec4 pixel = texture2D(uSampler, vTextureCoord);', + ' vec3 min_color = vec3(49.0/256.0, 64.0/256.0, 39.0/256.0);', + ' vec3 max_color = vec3(106.0/256.0, 131.0/256.0, 90.0/256.0);', + ' if(pixel.x >= min_color.x && pixel.y >= min_color.y && pixel.z >= min_color.z', + ' &&', + ' pixel.x <= max_color.x && pixel.y <= max_color.y && pixel.z <= max_color.z) {', + ' pixel.rgb = mix(pixel.rgb, vec3(0.2126*pixel.r + 0.7152*pixel.g + 0.0722*pixel.b), gray);', + ' pixel = pixel * shirtColor;', + ' }', + ' gl_FragColor = pixel;', + + // ' gl_FragColor = texture2D(uSampler, vTextureCoord) * matrix;', + // ' gl_FragColor = gl_FragColor;', + '}' + ]; + }; + + ColorMatrixFilter.prototype = Object.create( PIXI.AbstractFilter.prototype ); + ColorMatrixFilter.prototype.constructor = ColorMatrixFilter; + + Object.defineProperty(ColorMatrixFilter.prototype, 'matrix', { + get: function() { + return this.uniforms.matrix.value; + }, + set: function(value) { + this.uniforms.matrix.value = value; + } + }); + + + + var colorFilter = new ColorMatrixFilter() + colorFilter.matrix = [ + 1,1,0,0, + 0,1,0,0, + 0,0,1,0, + 0,0,0,1 + ]; + this.infoFilters = [colorFilter]; + + + this.infoText = new PIXI.Text("", {font: "normal 20px monospace", fill: "red", align: "center"}); this.infoBox = new PIXI.Graphics(); this.infoBox.alpha = 0.7; @@ -215,7 +285,7 @@ function (Parent, DomController, PIXI, Settings, Nc) { this.infoBox.position.x = this.infoText.position.x + borderWidth/2 - padding * 2; this.infoBox.position.y = this.infoText.position.y + borderWidth/2 - padding; - this.infoContainer.visible = true; + this.infoContainer.visible = false; this.container.filters = this.infoFilters; this.infoFilters.forEach(function(filter) { filter.dirty = true; }); } else {