Skip to content

Commit 496639f

Browse files
committed
Added Phaser.Filter and started moving the shaders over into their own filter classes, so they won't all get bundled in unless needed.
1 parent e32c127 commit 496639f

39 files changed

Lines changed: 982 additions & 341 deletions

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Change Log
4141

4242
Version 1.1.3 - in build
4343

44+
* New: Added a new in-built texture. Sprites now use __default if no texture was provided (a 32x32 transparent PNG) or __missing if one was given but not found (a 32x32 black box with a green cross through it)
45+
* New: Added Phaser.Filter. A new way to use the new WebGL shaders/filters that the new version of Pixi supports.
4446
* New: The object returned by Math.sinCosGenerator now contains a length property.
4547
* New: Phaser.BitmapData object. Can be used as a texture for a Sprite or Tiling Sprite. See the new examples and docs for details.
4648
* New: RenderTexture.render now takes a Phaser.Group. Also added renderXY for when you don't want to make a new Point object.
@@ -68,6 +70,7 @@ Version 1.1.3 - in build
6870
* Fixed: Point.rotate asDegrees fixed (thanks BorisKozo)
6971
* Fixed: ArcadePhysics.separateTile wasn't returning the value, so the custom process callback wasn't getting called (thanks flameiguana)
7072
* Fixed: StageScaleMode.forceOrientation now correctly stores the forcePortrait value (thanks haden)
73+
* Fixed: Fixes to Math and Loader (thanks theJare)
7174

7275
* Updated: ArcadePhysics.updateMotion applies the dt to the velocity calculations as well as position now (thanks jcs)
7376
* Updated: RequestAnimationFrame now retains the callbackID which is passed to cancelRequestAnimationFrame.

build/config.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<script src="../src/pixi/filters/DisplacementFilter.js"></script>
3232
<script src="../src/pixi/filters/DotScreenFilter.js"></script>
3333
<script src="../src/pixi/filters/FilterBlock.js"></script>
34-
<script src="../src/pixi/filters/GreyFilter.js"></script>
34+
<script src="../src/pixi/filters/GrayFilter.js"></script>
3535
<script src="../src/pixi/filters/InvertFilter.js"></script>
3636
<script src="../src/pixi/filters/PixelateFilter.js"></script>
3737
<script src="../src/pixi/filters/RGBSplitFilter.js"></script>
@@ -69,6 +69,7 @@
6969
<script src="../src/core/LinkedList.js"></script>
7070
<script src="../src/core/Signal.js"></script>
7171
<script src="../src/core/SignalBinding.js"></script>
72+
<script src="../src/core/Filter.js"></script>
7273
<script src="../src/core/Plugin.js"></script>
7374
<script src="../src/core/PluginManager.js"></script>
7475
<script src="../src/core/Stage.js"></script>

examples/wip/binarySerpentsFilter.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ PIXI.BinarySerpentsFilter = function(width, height, texture)
1414
];
1515

1616
this.uniforms = {
17-
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
18-
iMouse: { type: 'f3', value: { x: 0, y: 0, z: 0 }},
19-
iGlobalTime: { type: 'f', value: 1 },
20-
iDate: { type: 'f4', value: dates },
17+
iResolution: { type: '3f', value: { x: width, y: height, z: 0 }},
18+
iMouse: { type: '3f', value: { x: 0, y: 0, z: 0 }},
19+
iGlobalTime: { type: '1f', value: 1 },
20+
iDate: { type: '4fv', value: dates },
2121
iChannel0: { type: 'sampler2D', value: texture, wrap: 'repeat' }
2222
};
2323

examples/wip/book/part2.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
<script type="text/javascript">
1919

20+
var PIXI = PIXI || {};
21+
2022
document.addEventListener('DOMContentLoaded', function() {
2123

2224
function makeFilter () {

examples/wip/colorBoxFilter.js

Lines changed: 12 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,25 @@
1-
PIXI.ColorBoxFilter = function()
2-
{
3-
PIXI.AbstractFilter.call( this );
4-
5-
this.passes = [this];
61

7-
var d = new Date();
2+
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { create: create, update: update });
83

9-
var dates = [
10-
d.getFullYear(), // the year (four digits)
11-
d.getMonth(), // the month (from 0-11)
12-
d.getDate(), // the day of the month (from 1-31)
13-
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
14-
];
15-
16-
this.uniforms = {
17-
iResolution: { type: 'f3', value: { x: 800, y: 600, z: 0 }},
18-
iGlobalTime: { type: 'f', value: 1 },
19-
iDate: { type: 'f4', value: dates }
20-
};
21-
22-
this.fragmentSrc = [
23-
"precision mediump float;",
24-
"uniform vec3 iResolution;",
25-
"uniform float iGlobalTime;",
26-
"uniform float iChannelTime[4];",
27-
"uniform vec4 iMouse;",
28-
"uniform vec4 iDate;",
29-
"uniform vec3 iChannelResolution[4];",
30-
31-
"void main(void) {",
32-
"vec2 uv = gl_FragCoord.xy / iResolution.xy;",
33-
"gl_FragColor = vec4(uv, 0.5 * sin(iGlobalTime), 0.0);",
34-
"}"
35-
];
36-
37-
}
38-
39-
PIXI.ColorBoxFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
40-
PIXI.ColorBoxFilter.prototype.constructor = PIXI.ColorBoxFilter;
41-
42-
Object.defineProperty(PIXI.ColorBoxFilter.prototype, 'iGlobalTime', {
43-
get: function() {
44-
return this.uniforms.iGlobalTime.value;
45-
},
46-
set: function(value) {
47-
this.uniforms.iGlobalTime.value = value;
48-
}
49-
});
50-
51-
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
52-
53-
function preload() {
54-
55-
game.load.image('tex', 'wip/tex16.png');
56-
game.load.image('sea', 'assets/pics/undersea.jpg');
57-
58-
}
59-
60-
var stars;
4+
var background;
5+
var filter;
616

627
function create() {
638

64-
stars = new PIXI.ColorBoxFilter();
9+
// Because we don't specify a texture it will revert to using __default, a 64x64 transparent PNG - ideal for applying a filter to
10+
background = game.add.sprite(0, 0);
11+
background.width = 800;
12+
background.height = 600;
13+
14+
// filter = game.add.filter('SampleFilter', 800, 600, 0.5);
15+
filter = game.add.filter('BinarySerpents', 800, 600, 100, 5.0);
6516

66-
var a = game.add.sprite(0, 0, 'sea');
67-
a.filters = [stars];
17+
background.filters = [filter];
6818

6919
}
7020

7121
function update() {
7222

73-
stars.iGlobalTime = game.time.totalElapsedSeconds();
74-
75-
}
23+
filter.update();
7624

77-
function render() {
7825
}

examples/wip/colorbars_demo.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
3+
4+
var background;
5+
var filter;
6+
7+
function preload() {
8+
9+
game.load.image('phaser', 'assets/sprites/phaser2.png');
10+
11+
}
12+
13+
function create() {
14+
15+
var logo = game.add.sprite(game.world.centerX, game.world.centerY, 'phaser');
16+
logo.anchor.setTo(0.5, 0.5);
17+
18+
background = game.add.sprite(0, 0);
19+
background.width = 800;
20+
background.height = 600;
21+
22+
filter = game.add.filter('ColorBars', 800, 600);
23+
24+
filter.alpha = 0.0;
25+
26+
background.filters = [filter];
27+
28+
29+
}
30+
31+
function update() {
32+
33+
filter.update();
34+
35+
}

examples/wip/filter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ PIXI.RayTracedBallsFilter = function(width, height, texture)
1414
];
1515

1616
this.uniforms = {
17-
resolution: { type: 'f2', value: { x: width, y: height }},
18-
mouse: { type: 'f2', value: { x: 0, y: 0 }},
19-
time: { type: 'f', value: 1 }
17+
resolution: { type: '2f', value: { x: width, y: height }},
18+
mouse: { type: '2f', value: { x: 0, y: 0 }},
19+
time: { type: '1f', value: 1 }
2020
};
2121

2222
// http://glsl.heroku.com/e#11707.0

examples/wip/index.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ function printJSLinks($dir, $files) {
8585
$f = $_GET['f'];
8686
?>
8787
<script src="wip/<?php echo $f?>" type="text/javascript"></script>
88+
<script src="../filters/SampleFilter.js" type="text/javascript"></script>
89+
<script src="../filters/BinarySerpents.js" type="text/javascript"></script>
90+
<script src="../filters/Tunnel.js" type="text/javascript"></script>
91+
<script src="../filters/ColorBars.js" type="text/javascript"></script>
8892
<?php
8993
}
9094
?>

examples/wip/tunnel_demo.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
3+
4+
var background;
5+
var filter;
6+
7+
function preload() {
8+
9+
game.load.image('texture', 'wip/tex00.jpg');
10+
game.load.image('sea', 'assets/pics/undersea.jpg');
11+
12+
}
13+
14+
function create() {
15+
16+
game.add.sprite(0, 0, 'sea');
17+
18+
background = game.add.sprite(0, 0, 'texture');
19+
background.width = 800;
20+
background.height = 600;
21+
22+
filter = game.add.filter('Tunnel', 800, 600, background.texture);
23+
24+
// filter.alpha = 0.5;
25+
// filter.origin = 0.5;
26+
27+
background.filters = [filter];
28+
29+
}
30+
31+
function update() {
32+
33+
filter.update();
34+
35+
}

examples/wip/wobbleFilter.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
PIXI.WobbleFilter = function(width, height, texture0, texture1)
2+
{
3+
PIXI.AbstractFilter.call( this );
4+
5+
this.passes = [this];
6+
7+
var d = new Date();
8+
9+
var dates = [
10+
d.getFullYear(), // the year (four digits)
11+
d.getMonth(), // the month (from 0-11)
12+
d.getDate(), // the day of the month (from 1-31)
13+
d.getHours()*60.0*60 + d.getMinutes()*60 + d.getSeconds()
14+
];
15+
16+
this.uniforms = {
17+
iResolution: { type: 'f3', value: { x: width, y: height, z: 0 }},
18+
iGlobalTime: { type: 'f', value: 1 },
19+
iDate: { type: 'f4', value: dates },
20+
iChannel0: { type: 'sampler2D', value: texture0, wrap: 'repeat' },
21+
iChannel1: { type: 'sampler2D', value: texture1, wrap: 'repeat' }
22+
};
23+
24+
// Shader by deps (https://www.shadertoy.com/view/MssGDM)
25+
this.fragmentSrc = [
26+
"precision mediump float;",
27+
"uniform vec3 iResolution;",
28+
"uniform float iGlobalTime;",
29+
"uniform float iChannelTime[4];",
30+
"uniform vec4 iMouse;",
31+
"uniform vec4 iDate;",
32+
"uniform vec3 iChannelResolution[4];",
33+
"uniform sampler2D iChannel0;",
34+
"uniform sampler2D iChannel1;",
35+
"// add any extra uniforms here",
36+
37+
"void main(void)",
38+
"{",
39+
"vec2 uv = (gl_FragCoord.xy / iResolution.xy);",
40+
"uv.y = 1.0-uv.y;",
41+
42+
"float time = iGlobalTime * 0.75;",
43+
44+
"vec4 pixel2 = texture2D(iChannel1, (uv+vec2(sin(time),cos(time))) * 0.15 );",
45+
46+
"float xDiff = pixel2.r * 0.02;",
47+
"float yDiff = 0.0;",
48+
49+
"vec2 diffVec = vec2( xDiff, yDiff );",
50+
51+
"vec4 pixel = texture2D(iChannel0, uv + diffVec);",
52+
53+
"gl_FragColor = pixel;",
54+
"}"];
55+
56+
}
57+
58+
PIXI.WobbleFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
59+
PIXI.WobbleFilter.prototype.constructor = PIXI.WobbleFilter;
60+
61+
Object.defineProperty(PIXI.WobbleFilter.prototype, 'iGlobalTime', {
62+
get: function() {
63+
return this.uniforms.iGlobalTime.value;
64+
},
65+
set: function(value) {
66+
this.uniforms.iGlobalTime.value = value;
67+
}
68+
});
69+
70+
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
71+
72+
function preload() {
73+
74+
game.load.image('texture0', 'wip/tex04.jpg');
75+
game.load.image('texture1', 'wip/tex10.png');
76+
77+
}
78+
79+
var filter;
80+
var sprite;
81+
82+
function create() {
83+
84+
noise = game.add.sprite(0, 0, 'texture1');
85+
86+
sprite = game.add.sprite(0, 0, 'texture0');
87+
sprite.width = 800;
88+
sprite.height = 600;
89+
90+
filter = new PIXI.WobbleFilter(sprite.width, sprite.height, sprite.texture, noise.texture);
91+
92+
sprite.filters = [filter];
93+
94+
}
95+
96+
function update() {
97+
98+
filter.iGlobalTime = game.time.totalElapsedSeconds();
99+
100+
}
101+
102+
function render() {
103+
}

0 commit comments

Comments
 (0)