filter test updates

This commit is contained in:
photonstorm
2013-11-09 02:16:52 +00:00
parent 3f99b691c9
commit 46cf024a35
10 changed files with 120 additions and 4 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

+68
View File
@@ -0,0 +1,68 @@
PIXI.GreyFilter = function()
{
PIXI.AbstractFilter.call( this );
this.passes = [this];
// set the uniforms
this.uniforms = {
grey: {type: 'f', value: 1},
};
this.OLDfragmentSrc = [
"precision mediump float;",
"varying vec2 vTextureCoord;",
"varying float vColor;",
"uniform sampler2D uSampler;",
"uniform float grey;",
"void main(void) {",
"gl_FragColor = texture2D(uSampler, vTextureCoord);",
"gl_FragColor.rgb = mix(gl_FragColor.rgb, vec3(0.2126*gl_FragColor.r + 0.7152*gl_FragColor.g + 0.0722*gl_FragColor.b), grey);",
"gl_FragColor = gl_FragColor * vColor;",
"}"
];
}
PIXI.GreyFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
PIXI.GreyFilter.prototype.constructor = PIXI.GreyFilter;
/**
The strength of the grey. 1 will make the object black and white, 0 will make the object its normal color
@property grey
*/
Object.defineProperty(PIXI.GreyFilter.prototype, 'grey', {
get: function() {
return this.uniforms.grey.value;
},
set: function(value) {
this.uniforms.grey.value = value;
}
});
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update, render: render });
function preload() {
game.load.image('atari1', 'assets/sprites/atari130xe.png');
game.load.image('coke', 'assets/sprites/cokecan.png');
game.load.image('mushroom', 'assets/sprites/mushroom2.png');
}
function create() {
game.add.sprite(60, 100, 'atari1');
game.add.sprite(360, 200, 'coke');
}
function update() {
}
function render() {
}
+45
View File
@@ -0,0 +1,45 @@
<?php
$output = "this.fragmentSrc = [\n";
if (isset($_POST['shader']))
{
$shader = explode("\n", $_POST['shader']);
for ($i = 0; $i < count($shader); $i++)
{
$output = $output . "\t\"" . trim($shader[$i]) . "\",\n";
}
}
$output .= "];";
?>
<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<title>phaser - filter conv</title>
<style>
body {
font-family: Arial;
font-size: 14px;
}
</style>
</head>
<body>
<form action="filterconv.php" method="post">
<h2>Input</h2>
<textarea name="shader" style="width: 800px; height: 400px"></textarea>
<h2>Output</h2>
<textarea style="width: 800px; height: 400px"><?php echo $output ?></textarea>
<br />
<input type="submit" value="Convert" />
</form>
</body>
</html>