diff --git a/filters/pixi/.jshintrc b/filters/pixi/.jshintrc deleted file mode 100644 index ec8189515..000000000 --- a/filters/pixi/.jshintrc +++ /dev/null @@ -1,49 +0,0 @@ -{ - "globals" : { "Phaser": false, "PIXI": false, "p2": false }, - // Ignore Environment Globals - "browser" : true, // Standard browser globals e.g. `window`, `document`. - - // Development - "devel" : true, // Allow developments statements e.g. `console.log();`. - - // ECMAScript Support - "es3" : true, // Support legacy browser and javascript environments. - "esnext" : false, // This option tells JSHint that your code uses ECMAScript 6 specific syntax. - "strict" : false, // Require `use strict` pragma in every file. - "globalstrict": false, // Allow global "use strict" (also enables 'strict'). - - // Functionality - "bitwise" : false, // Prohibit bitwise operators (&, |, ^, etc.). - "boss" : true, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments. - "camelcase" : false, // Force all variable names to use either camelCase style or UPPER_CASE with underscores. - "curly" : true, // Require {} for every new block or scope. - "eqeqeq" : false, // Require triple equals i.e. `===`. - "eqnull" : true, // Tolerate use of `== null`. - "evil" : false, // Tolerate use of `eval`. - "expr" : false, // Tolerate `ExpressionStatement` as Programs. - "forin" : false, // Tolerate `for in` loops without `hasOwnPrototype`. - "freeze" : true, // Prohibits overwriting prototypes of native objects such as Array and Date. - "funcscope" : true, // This option suppresses warnings about declaring variables inside of control structures while accessing them later from the outside. - "immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );` - "latedef" : true, // Prohibit variable use before definition. - "laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons. - "laxcomma" : false, // This option suppresses warnings about comma-first coding style. - "loopfunc" : true, // Allow functions to be defined within loops. - "noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`. - "notypeof" : false, // This option suppresses warnings about invalid typeof operator values. - "shadow" : true, // Allows re-define variables later in code e.g. `var x=1; x=2;`. - "smarttabs" : false, // This option suppresses warnings about mixed tabs and spaces when the latter are used for alignmnent only. - "supernew" : false, // Tolerate `new function () { ... };` and `new Object;`. - "undef" : true, // Require all non-global variables be declared before they are used. - "unused" : true, // This option warns when you define and never use your variables. - - // Styling - "indent" : false, // Specify indentation spacing - "newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`. - "noempty" : true, // Prohibit use of empty blocks. - "nonew" : true, // Prohibit use of constructors for side-effects. - "plusplus" : false, // Prohibit use of `++` & `--`. - "quotmark" : false, // This option enforces the consistency of quotation marks used throughout your code. - "sub" : true, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`. - "trailing" : true // Prohibit trailing whitespaces. -} diff --git a/filters/pixi/AlphaMaskFilter.js b/filters/pixi/AlphaMaskFilter.js index 130c7fff6..470cb9e23 100644 --- a/filters/pixi/AlphaMaskFilter.js +++ b/filters/pixi/AlphaMaskFilter.js @@ -14,7 +14,7 @@ */ PIXI.AlphaMaskFilter = function(texture) { - PIXI.AbstractFilter.call( this ); + PIXI.AbstractFilter.call(this); this.passes = [this]; texture.baseTexture._powerOf2 = true; @@ -26,7 +26,7 @@ PIXI.AlphaMaskFilter = function(texture) dimensions: {type: '4fv', value:[0,0,0,0]} }; - if(texture.baseTexture.hasLoaded) + if (texture.baseTexture.hasLoaded) { this.uniforms.mask.value.x = texture.width; this.uniforms.mask.value.y = texture.height; @@ -58,9 +58,7 @@ PIXI.AlphaMaskFilter = function(texture) ' vec4 original = texture2D(uSampler, vTextureCoord);', ' float maskAlpha = texture2D(mask, mapCords).r;', ' original *= maskAlpha;', - //' original.rgb *= maskAlpha;', ' gl_FragColor = original;', - //' gl_FragColor = gl_FragColor;', '}' ]; }; @@ -88,9 +86,11 @@ PIXI.AlphaMaskFilter.prototype.onTextureLoaded = function() * @type Texture */ Object.defineProperty(PIXI.AlphaMaskFilter.prototype, 'map', { + get: function() { return this.uniforms.mask.value; }, + set: function(value) { this.uniforms.mask.value = value; } diff --git a/filters/pixi/AsciiFilter.js b/filters/pixi/AsciiFilter.js index f7c30be82..88c236090 100644 --- a/filters/pixi/AsciiFilter.js +++ b/filters/pixi/AsciiFilter.js @@ -12,7 +12,7 @@ */ PIXI.AsciiFilter = function() { - PIXI.AbstractFilter.call( this ); + PIXI.AbstractFilter.call(this); this.passes = [this]; @@ -45,7 +45,7 @@ PIXI.AsciiFilter = function() ' vec3 col = texture2D(uSampler, floor( uv / pixelSize ) * pixelSize / dimensions.xy).rgb;', ' #ifdef HAS_GREENSCREEN', - ' float gray = (col.r + col.b)/2.0;', + ' float gray = (col.r + col.b)/2.0;', ' #else', ' float gray = (col.r + col.g + col.b)/3.0;', ' #endif', @@ -77,9 +77,11 @@ PIXI.AsciiFilter.prototype.constructor = PIXI.AsciiFilter; * @type Number */ Object.defineProperty(PIXI.AsciiFilter.prototype, 'size', { + get: function() { return this.uniforms.pixelSize.value; }, + set: function(value) { this.dirty = true; this.uniforms.pixelSize.value = value; diff --git a/filters/pixi/NormalMapFilter.js b/filters/pixi/NormalMapFilter.js index e686905c9..f7e19e5ee 100644 --- a/filters/pixi/NormalMapFilter.js +++ b/filters/pixi/NormalMapFilter.js @@ -15,111 +15,111 @@ */ PIXI.NormalMapFilter = function(texture) { - PIXI.AbstractFilter.call( this ); - - this.passes = [this]; - texture.baseTexture._powerOf2 = true; + PIXI.AbstractFilter.call( this ); + + this.passes = [this]; + texture.baseTexture._powerOf2 = true; - // set the uniforms - this.uniforms = { - displacementMap: {type: 'sampler2D', value:texture}, - scale: {type: '2f', value:{x:15, y:15}}, - offset: {type: '2f', value:{x:0, y:0}}, - mapDimensions: {type: '2f', value:{x:1, y:1}}, - dimensions: {type: '4f', value:[0,0,0,0]}, - // LightDir: {type: 'f3', value:[0, 1, 0]}, - LightPos: {type: '3f', value:[0, 1, 0]} - }; - + // set the uniforms + this.uniforms = { + displacementMap: {type: 'sampler2D', value:texture}, + scale: {type: '2f', value:{x:15, y:15}}, + offset: {type: '2f', value:{x:0, y:0}}, + mapDimensions: {type: '2f', value:{x:1, y:1}}, + dimensions: {type: '4f', value:[0,0,0,0]}, + // LightDir: {type: 'f3', value:[0, 1, 0]}, + LightPos: {type: '3f', value:[0, 1, 0]} + }; + - if(texture.baseTexture.hasLoaded) - { - this.uniforms.mapDimensions.value.x = texture.width; - this.uniforms.mapDimensions.value.y = texture.height; - } - else - { - this.boundLoadedFunction = this.onTextureLoaded.bind(this); + if(texture.baseTexture.hasLoaded) + { + this.uniforms.mapDimensions.value.x = texture.width; + this.uniforms.mapDimensions.value.y = texture.height; + } + else + { + this.boundLoadedFunction = this.onTextureLoaded.bind(this); - texture.baseTexture.on("loaded", this.boundLoadedFunction); - } + texture.baseTexture.on("loaded", this.boundLoadedFunction); + } - this.fragmentSrc = [ - "precision mediump float;", - "varying vec2 vTextureCoord;", - "varying float vColor;", - "uniform sampler2D displacementMap;", - "uniform sampler2D uSampler;", - - "uniform vec4 dimensions;", - - "const vec2 Resolution = vec2(1.0,1.0);", //resolution of screen - "uniform vec3 LightPos;", //light position, normalized - "const vec4 LightColor = vec4(1.0, 1.0, 1.0, 1.0);", //light RGBA -- alpha is intensity - "const vec4 AmbientColor = vec4(1.0, 1.0, 1.0, 0.5);", //ambient RGBA -- alpha is intensity - "const vec3 Falloff = vec3(0.0, 1.0, 0.2);", //attenuation coefficients + this.fragmentSrc = [ + "precision mediump float;", + "varying vec2 vTextureCoord;", + "varying float vColor;", + "uniform sampler2D displacementMap;", + "uniform sampler2D uSampler;", + + "uniform vec4 dimensions;", + + "const vec2 Resolution = vec2(1.0,1.0);", //resolution of screen + "uniform vec3 LightPos;", //light position, normalized + "const vec4 LightColor = vec4(1.0, 1.0, 1.0, 1.0);", //light RGBA -- alpha is intensity + "const vec4 AmbientColor = vec4(1.0, 1.0, 1.0, 0.5);", //ambient RGBA -- alpha is intensity + "const vec3 Falloff = vec3(0.0, 1.0, 0.2);", //attenuation coefficients - "uniform vec3 LightDir;",//" = vec3(1.0, 0.0, 1.0);", + "uniform vec3 LightDir;",//" = vec3(1.0, 0.0, 1.0);", - "uniform vec2 mapDimensions;",// = vec2(256.0, 256.0);", - + "uniform vec2 mapDimensions;",// = vec2(256.0, 256.0);", + - "void main(void) {", - "vec2 mapCords = vTextureCoord.xy;", + "void main(void) {", + "vec2 mapCords = vTextureCoord.xy;", - "vec4 color = texture2D(uSampler, vTextureCoord.st);", + "vec4 color = texture2D(uSampler, vTextureCoord.st);", "vec3 nColor = texture2D(displacementMap, vTextureCoord.st).rgb;", - "mapCords *= vec2(dimensions.x/512.0, dimensions.y/512.0);", - - "mapCords.y *= -1.0;", - "mapCords.y += 1.0;", + "mapCords *= vec2(dimensions.x/512.0, dimensions.y/512.0);", + + "mapCords.y *= -1.0;", + "mapCords.y += 1.0;", - //RGBA of our diffuse color - "vec4 DiffuseColor = texture2D(uSampler, vTextureCoord);", + //RGBA of our diffuse color + "vec4 DiffuseColor = texture2D(uSampler, vTextureCoord);", - //RGB of our normal map - "vec3 NormalMap = texture2D(displacementMap, mapCords).rgb;", + //RGB of our normal map + "vec3 NormalMap = texture2D(displacementMap, mapCords).rgb;", - //The delta position of light - //"vec3 LightDir = vec3(LightPos.xy - (gl_FragCoord.xy / Resolution.xy), LightPos.z);", - "vec3 LightDir = vec3(LightPos.xy - (mapCords.xy), LightPos.z);", - //Correct for aspect ratio - //"LightDir.x *= Resolution.x / Resolution.y;", + //The delta position of light + //"vec3 LightDir = vec3(LightPos.xy - (gl_FragCoord.xy / Resolution.xy), LightPos.z);", + "vec3 LightDir = vec3(LightPos.xy - (mapCords.xy), LightPos.z);", + //Correct for aspect ratio + //"LightDir.x *= Resolution.x / Resolution.y;", - //Determine distance (used for attenuation) BEFORE we normalize our LightDir - "float D = length(LightDir);", + //Determine distance (used for attenuation) BEFORE we normalize our LightDir + "float D = length(LightDir);", - //normalize our vectors - "vec3 N = normalize(NormalMap * 2.0 - 1.0);", - "vec3 L = normalize(LightDir);", + //normalize our vectors + "vec3 N = normalize(NormalMap * 2.0 - 1.0);", + "vec3 L = normalize(LightDir);", - //Pre-multiply light color with intensity - //Then perform "N dot L" to determine our diffuse term - "vec3 Diffuse = (LightColor.rgb * LightColor.a) * max(dot(N, L), 0.0);", + //Pre-multiply light color with intensity + //Then perform "N dot L" to determine our diffuse term + "vec3 Diffuse = (LightColor.rgb * LightColor.a) * max(dot(N, L), 0.0);", - //pre-multiply ambient color with intensity - "vec3 Ambient = AmbientColor.rgb * AmbientColor.a;", + //pre-multiply ambient color with intensity + "vec3 Ambient = AmbientColor.rgb * AmbientColor.a;", - //calculate attenuation - "float Attenuation = 1.0 / ( Falloff.x + (Falloff.y*D) + (Falloff.z*D*D) );", + //calculate attenuation + "float Attenuation = 1.0 / ( Falloff.x + (Falloff.y*D) + (Falloff.z*D*D) );", - //the calculation which brings it all together - "vec3 Intensity = Ambient + Diffuse * Attenuation;", - "vec3 FinalColor = DiffuseColor.rgb * Intensity;", - "gl_FragColor = vColor * vec4(FinalColor, DiffuseColor.a);", - //"gl_FragColor = vec4(1.0, 0.0, 0.0, Attenuation);",//vColor * vec4(FinalColor, DiffuseColor.a);", - /* - // normalise color - "vec3 normal = normalize(nColor * 2.0 - 1.0);", - - "vec3 deltaPos = vec3( (light.xy - gl_FragCoord.xy) / resolution.xy, light.z );", + //the calculation which brings it all together + "vec3 Intensity = Ambient + Diffuse * Attenuation;", + "vec3 FinalColor = DiffuseColor.rgb * Intensity;", + "gl_FragColor = vColor * vec4(FinalColor, DiffuseColor.a);", + //"gl_FragColor = vec4(1.0, 0.0, 0.0, Attenuation);",//vColor * vec4(FinalColor, DiffuseColor.a);", + /* + // normalise color + "vec3 normal = normalize(nColor * 2.0 - 1.0);", + + "vec3 deltaPos = vec3( (light.xy - gl_FragCoord.xy) / resolution.xy, light.z );", - "float lambert = clamp(dot(normal, lightDir), 0.0, 1.0);", + "float lambert = clamp(dot(normal, lightDir), 0.0, 1.0);", - "float d = sqrt(dot(deltaPos, deltaPos));", + "float d = sqrt(dot(deltaPos, deltaPos));", "float att = 1.0 / ( attenuation.x + (attenuation.y*d) + (attenuation.z*d*d) );", "vec3 result = (ambientColor * ambientIntensity) + (lightColor.rgb * lambert) * att;", @@ -127,12 +127,12 @@ PIXI.NormalMapFilter = function(texture) "gl_FragColor = vec4(result, 1.0);",*/ - + - "}" - ]; - -} + "}" + ]; + +}; PIXI.NormalMapFilter.prototype = Object.create( PIXI.AbstractFilter.prototype ); PIXI.NormalMapFilter.prototype.constructor = PIXI.NormalMapFilter; @@ -144,10 +144,10 @@ PIXI.NormalMapFilter.prototype.constructor = PIXI.NormalMapFilter; */ PIXI.NormalMapFilter.prototype.onTextureLoaded = function() { - this.uniforms.mapDimensions.value.x = this.uniforms.displacementMap.value.width; - this.uniforms.mapDimensions.value.y = this.uniforms.displacementMap.value.height; + this.uniforms.mapDimensions.value.x = this.uniforms.displacementMap.value.width; + this.uniforms.mapDimensions.value.y = this.uniforms.displacementMap.value.height; - this.uniforms.displacementMap.value.baseTexture.off("loaded", this.boundLoadedFunction) + this.uniforms.displacementMap.value.baseTexture.off("loaded", this.boundLoadedFunction); }; /** @@ -161,7 +161,7 @@ Object.defineProperty(PIXI.NormalMapFilter.prototype, 'map', { return this.uniforms.displacementMap.value; }, set: function(value) { - this.uniforms.displacementMap.value = value; + this.uniforms.displacementMap.value = value; } }); @@ -176,7 +176,7 @@ Object.defineProperty(PIXI.NormalMapFilter.prototype, 'scale', { return this.uniforms.scale.value; }, set: function(value) { - this.uniforms.scale.value = value; + this.uniforms.scale.value = value; } }); @@ -191,6 +191,6 @@ Object.defineProperty(PIXI.NormalMapFilter.prototype, 'offset', { return this.uniforms.offset.value; }, set: function(value) { - this.uniforms.offset.value = value; + this.uniforms.offset.value = value; } }); diff --git a/src/geom/Matrix.js b/src/geom/Matrix.js index f213a5649..b29c46f05 100644 --- a/src/geom/Matrix.js +++ b/src/geom/Matrix.js @@ -98,8 +98,8 @@ Phaser.Matrix.prototype.toArray = function(transpose) { if (!this.array) { - this.array = new PIXI.Float32Array(9); - } + this.array = new PIXI.Float32Array(9); + } var array = this.array;