ShaderToy convertor up and working, lots of shaders being turned into Pixi filters :)

This commit is contained in:
photonstorm
2013-11-20 02:28:28 +00:00
parent 40e1b4b9aa
commit e620c99479
50 changed files with 2599 additions and 59 deletions
+8 -1
View File
@@ -58,7 +58,14 @@ Phaser.BitmapData = function (game, width, height) {
/**
* @property {UInt8Clamped} pixels - A reference to the context imageData buffer.
*/
this.pixels = this.imageData.data.buffer;
if (this.imageData.data.buffer)
{
this.pixels = this.imageData.data.buffer;
}
else
{
this.pixels = this.imageData.data;
}
/**
* @property {PIXI.BaseTexture} baseTexture - The PIXI.BaseTexture.
+1
View File
@@ -474,6 +474,7 @@ PIXI.DisplayObject.prototype.removeFilter = function(data)
{
//if(!this.filter)return;
//this.filter = false;
console.log("YUOIO")
// modify the list..
var startBlock = data.start;
+1 -1
View File
@@ -6,7 +6,7 @@
/**
*
* This turns your displayObjects to black and white.
* @class GreyFilter
* @class ColorStepFilter
* @contructor
*/
PIXI.ColorStepFilter = function()
+51
View File
@@ -0,0 +1,51 @@
/**
* @author Mat Groves http://matgroves.com/ @Doormat23
*/
/**
*
* This turns your displayObjects to black and white.
* @class GrayFilter
* @contructor
*/
PIXI.GrayFilter = function()
{
PIXI.AbstractFilter.call( this );
this.passes = [this];
// set the uniforms
this.uniforms = {
gray: {type: 'f', value: 1},
};
this.fragmentSrc = [
"precision mediump float;",
"varying vec2 vTextureCoord;",
"varying float vColor;",
"uniform sampler2D uSampler;",
"uniform float gray;",
"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), gray);",
"gl_FragColor = gl_FragColor * vColor;",
"}"
];
}
PIXI.GrayFilter.prototype = Object.create( PIXI.AbstractFilter.prototype );
PIXI.GrayFilter.prototype.constructor = PIXI.GrayFilter;
/**
The strength of the gray. 1 will make the object black and white, 0 will make the object its normal color
@property gray
*/
Object.defineProperty(PIXI.GrayFilter.prototype, 'gray', {
get: function() {
return this.uniforms.gray.value;
},
set: function(value) {
this.uniforms.gray.value = value;
}
});
+1 -1
View File
@@ -85,7 +85,7 @@ PIXI.AssetLoader.prototype.load = function()
for (var i=0; i < this.assetURLs.length; i++)
{
var fileName = this.assetURLs[i];
var fileType = fileName.split(".").pop().toLowerCase();
var fileType = fileName.split("?").shift().split(".").pop().toLowerCase();
var loaderClass = this.loadersByType[fileType];
if(!loaderClass)
+49 -1
View File
@@ -25,7 +25,7 @@ PIXI.PixiShader.prototype.init = function()
var program = PIXI.compileProgram(this.vertexSrc || PIXI.PixiShader.defaultVertexSrc, this.fragmentSrc)
var gl = PIXI.gl;
gl.useProgram(program);
// get and store the uniforms for the shader
@@ -63,6 +63,44 @@ PIXI.PixiShader.prototype.syncUniforms = function()
var type = this.uniforms[key].type;
// need to grow this!
/*
http://www.khronos.org/registry/webgl/specs/latest/1.0/
http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf
void uniform1f(WebGLUniformLocation? location, GLfloat x);
void uniform1fv(WebGLUniformLocation? location, Float32Array v);
void uniform1fv(WebGLUniformLocation? location, sequence<GLfloat> v);
void uniform1i(WebGLUniformLocation? location, GLint x);
void uniform1iv(WebGLUniformLocation? location, Int32Array v);
void uniform1iv(WebGLUniformLocation? location, sequence<long> v);
void uniform2f(WebGLUniformLocation? location, GLfloat x, GLfloat y);
void uniform2fv(WebGLUniformLocation? location, Float32Array v);
void uniform2fv(WebGLUniformLocation? location, sequence<GLfloat> v);
void uniform2i(WebGLUniformLocation? location, GLint x, GLint y);
void uniform2iv(WebGLUniformLocation? location, Int32Array v);
void uniform2iv(WebGLUniformLocation? location, sequence<long> v);
void uniform3f(WebGLUniformLocation? location, GLfloat x, GLfloat y, GLfloat z);
void uniform3fv(WebGLUniformLocation? location, Float32Array v);
void uniform3fv(WebGLUniformLocation? location, sequence<GLfloat> v);
void uniform3i(WebGLUniformLocation? location, GLint x, GLint y, GLint z);
void uniform3iv(WebGLUniformLocation? location, Int32Array v);
void uniform3iv(WebGLUniformLocation? location, sequence<long> v);
void uniform4f(WebGLUniformLocation? location, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
void uniform4fv(WebGLUniformLocation? location, Float32Array v);
void uniform4fv(WebGLUniformLocation? location, sequence<GLfloat> v);
void uniform4i(WebGLUniformLocation? location, GLint x, GLint y, GLint z, GLint w);
void uniform4iv(WebGLUniformLocation? location, Int32Array v);
void uniform4iv(WebGLUniformLocation? location, sequence<long> v);
void uniformMatrix2fv(WebGLUniformLocation? location, GLboolean transpose, Float32Array value);
void uniformMatrix2fv(WebGLUniformLocation? location, GLboolean transpose, sequence<GLfloat> value);
void uniformMatrix3fv(WebGLUniformLocation? location, GLboolean transpose, Float32Array value);
void uniformMatrix3fv(WebGLUniformLocation? location, GLboolean transpose, sequence<GLfloat> value);
void uniformMatrix4fv(WebGLUniformLocation? location, GLboolean transpose, Float32Array value);
void uniformMatrix4fv(WebGLUniformLocation? location, GLboolean transpose, sequence<GLfloat> value);
*/
if(type == "f")
{
gl.uniform1f(this.uniforms[key].uniformLocation, this.uniforms[key].value);
@@ -72,6 +110,16 @@ PIXI.PixiShader.prototype.syncUniforms = function()
// console.log(this.program[key])
gl.uniform2f(this.uniforms[key].uniformLocation, this.uniforms[key].value.x, this.uniforms[key].value.y);
}
else if(type == "f3")
{
// console.log(this.uniforms[key].value)
gl.uniform3f(this.uniforms[key].uniformLocation, this.uniforms[key].value.x, this.uniforms[key].value.y, this.uniforms[key].value.z);
}
else if(type == "f3v")
{
// console.log(this.uniforms[key].value)
gl.uniform3fv(this.uniforms[key].uniformLocation, this.uniforms[key].value);
}
else if(type == "f4")
{
// console.log(this.uniforms[key].value)
@@ -25,6 +25,7 @@ PIXI.WebGLRenderGroup = function(gl, transparent)
this.batchs = [];
this.toRemove = [];
console.log(this.transparent)
this.filterManager = new PIXI.WebGLFilterManager(this.transparent);
}
+1
View File
@@ -93,6 +93,7 @@ PIXI._CompileShader = function(gl, shaderSrc, shaderType)
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
console.log(gl.getShaderInfoLog(shader));
return null;
}
+2
View File
@@ -6,6 +6,8 @@
/**
* Sound Manager constructor.
* The Sound Manager is responsible for playing back audio via either the Legacy HTML Audio tag or via Web Audio if the browser supports it.
* Note: On Firefox 25+ on Linux if you have media.gstreamer disabled in about:config then it cannot play back mp3 or m4a files.
*
* @class Phaser.SoundManager
* @classdesc Phaser Sound Manager.
+28 -10
View File
@@ -126,67 +126,78 @@ Phaser.Device = function () {
*/
this.pointerLock = false;
/**
* @property {boolean} typedArray - Does the browser support TypedArrays?
* @default
*/
this.typedArray = false;
// Browser
/**
* @property {boolean} arora - Is running in arora?
* @property {boolean} arora - Set to true if running in Arora.
* @default
*/
this.arora = false;
/**
* @property {boolean} chrome - Is running in chrome?
* @property {boolean} chrome - Set to true if running in Chrome.
* @default
*/
this.chrome = false;
/**
* @property {boolean} epiphany - Is running in epiphany?
* @property {boolean} epiphany - Set to true if running in Epiphany.
* @default
*/
this.epiphany = false;
/**
* @property {boolean} firefox - Is running in firefox?
* @property {boolean} firefox - Set to true if running in Firefox.
* @default
*/
this.firefox = false;
/**
* @property {boolean} ie - Is running in ie?
* @property {boolean} ie - Set to true if running in Internet Explorer.
* @default
*/
this.ie = false;
/**
* @property {number} ieVersion - Version of ie?
* @property {number} ieVersion - If running in Internet Explorer this will contain the major version number.
* @default
*/
this.ieVersion = 0;
/**
* @property {boolean} mobileSafari - Is running in mobileSafari?
* @property {boolean} mobileSafari - Set to true if running in Mobile Safari.
* @default
*/
this.mobileSafari = false;
/**
* @property {boolean} midori - Is running in midori?
* @property {boolean} midori - Set to true if running in Midori.
* @default
*/
this.midori = false;
/**
* @property {boolean} opera - Is running in opera?
* @property {boolean} opera - Set to true if running in Opera.
* @default
*/
this.opera = false;
/**
* @property {boolean} safari - Is running in safari?
* @property {boolean} safari - Set to true if running in Safari.
* @default
*/
this.safari = false;
/**
* @property {boolean} webApp - Set to true if running as a WebApp, i.e. within a WebView
* @default
*/
this.webApp = false;
// Audio
@@ -226,6 +237,7 @@ Phaser.Device = function () {
* @default
*/
this.wav = false;
/**
* Can this device play m4a files?
* @property {boolean} m4a - True if this device can play m4a files.
@@ -453,6 +465,12 @@ Phaser.Device.prototype = {
if (typeof Int8Array !== 'undefined')
{
this.littleEndian = new Int8Array(new Int16Array([1]).buffer)[0] > 0;
this.typedArray = true;
}
else
{
this.littleEndian = false;
this.typedArray = false;
}
},
+12
View File
@@ -135,6 +135,16 @@ Phaser.StageScaleMode = function (game, width, height) {
*/
this.enterPortrait = new Phaser.Signal();
/**
* @property {Phaser.Signal} enterIncorrectOrientation - The event that is dispatched when the browser enters an incorrect orientation, as defined by forceOrientation.
*/
this.enterIncorrectOrientation = new Phaser.Signal();
/**
* @property {Phaser.Signal} leaveIncorrectOrientation - The event that is dispatched when the browser leaves an incorrect orientation, as defined by forceOrientation.
*/
this.leaveIncorrectOrientation = new Phaser.Signal();
if (window['orientation'])
{
this.orientation = window['orientation'];
@@ -365,6 +375,7 @@ Phaser.StageScaleMode.prototype = {
// Back to normal
this.game.paused = false;
this.incorrectOrientation = false;
this.leaveIncorrectOrientation.dispatch();
if (this.orientationSprite)
{
@@ -382,6 +393,7 @@ Phaser.StageScaleMode.prototype = {
// Show orientation screen
this.game.paused = true;
this.incorrectOrientation = true;
this.enterIncorrectOrientation.dispatch();
if (this.orientationSprite && this.orientationSprite.visible == false)
{
+44 -9
View File
@@ -195,19 +195,54 @@ Phaser.Utils = {
// Global functions that PIXI needs
/**
* Converts a hex color number to an [R, G, B] array
*
* @param {number} hex
* @return {array}
*/
(function() {
var consoleDisabled = false;
if (consoleDisabled) {
window.console = undefined;
}
if (window.console == undefined) {
window.console = {
debug: function() {
return true;
},
info: function() {
return false;
},
warn: function() {
return false;
},
log: function() {
return false;
}
}
}
debug = (function(args) {
window.console.debug(args);
});
info = (function(args) {
window.console.info(args);
});
warn = (function(args) {
window.console.warn(args);
});
log = (function(args) {
window.console.log(args);
});
})();
/**
* Converts a hex color number to an [R, G, B] array
*
* @param {number} hex
* @return {array}
*/
function HEXtoRGB(hex) {
return [(hex >> 16 & 0xFF) / 255, ( hex >> 8 & 0xFF) / 255, (hex & 0xFF)/ 255];
}
/**
* A polyfill for Function.prototype.bind
*/
/**
* A polyfill for Function.prototype.bind
*/
if (typeof Function.prototype.bind != 'function') {
Function.prototype.bind = (function () {
var slice = Array.prototype.slice;