Skip to content

Commit

Permalink
Merge pull request #73 from brianchirls/develop
Browse files Browse the repository at this point in the history
Release 2014-10-13
  • Loading branch information
brianchirls committed Oct 13, 2014
2 parents 7c6c9fb + 899c181 commit 63bf296
Show file tree
Hide file tree
Showing 29 changed files with 14,285 additions and 15,225 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Full documentation is in progress at the [wiki](https://github.com/brianchirls/S
- Color Generator
- [Color Cube](http://www.youtube.com/watch?v=rfQ8rKGTVlg&t=24m30s)
- Color Select
- Crop
- [Daltonize](http://www.daltonize.org/p/about.html)
- Directional Blur
- Displacement Map
Expand All @@ -59,6 +60,7 @@ Full documentation is in progress at the [wiki](https://github.com/brianchirls/S
- Mirror
- Night Vision
- Panorama
- Pixelate
- Polar Coordinates
- Ripple
- Scanlines
Expand Down
1 change: 1 addition & 0 deletions effects/seriously.blend.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
nativeBlendModes = {
normal: ['FUNC_ADD', 'SRC_ALPHA', 'ONE_MINUS_SRC_ALPHA', 'SRC_ALPHA', 'DST_ALPHA']/*,
add: ['FUNC_ADD', 'SRC_ALPHA', 'ONE_MINUS_SRC_ALPHA', 'SRC_ALPHA', 'DST_ALPHA']*/
//todo: multiply, screen
},
identity = new Float32Array([
1, 0, 0, 0,
Expand Down
22 changes: 6 additions & 16 deletions effects/seriously.blur.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,7 @@ http://v002.info/plugins/v002-blurs/
inputScale: 1,
resolution: [this.width, this.height],
transform: identity,
direction: null,
projection: new Float32Array([
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
])
direction: null
};

return {
Expand Down Expand Up @@ -90,16 +84,16 @@ http://v002.info/plugins/v002-blurs/
'attribute vec2 texCoord;',

'uniform vec2 resolution;',
'uniform mat4 projection;',
'uniform mat4 transform;',

'varying vec2 vTexCoord;',

'uniform vec2 direction;',
'uniform float amount;',
'uniform float inputScale;',

'const vec2 zero = vec2(0.0, 0.0);',

'varying vec2 vTexCoord;',

'#ifdef USE_VARYINGS',
'vec2 one;',
'vec2 amount1;',
Expand Down Expand Up @@ -131,7 +125,7 @@ http://v002.info/plugins/v002-blurs/
' if (inputScale < 1.0) {',
' one -= 1.0 / resolution;',
' }',
//' one *= inputScale;',

' vTexCoord = max(zero, min(one, texCoord.st * inputScale));',
' amount1 = direction * (inputScale * amount * 5.0 / resolution);',

Expand Down Expand Up @@ -162,9 +156,6 @@ http://v002.info/plugins/v002-blurs/
'varying vec2 vTexCoord;',

'uniform sampler2D source;',
'uniform float angle;',
'uniform float amount;',
'uniform float inputScale;',

'#ifdef USE_VARYINGS',
'varying vec2 vTexCoord1;',
Expand Down Expand Up @@ -235,14 +226,13 @@ http://v002.info/plugins/v002-blurs/

//vertical pass
uniforms.direction = vertical;
uniforms.source = fbVertical.texture;
uniforms.source = fbHorizontal.texture;
parent(shader, model, uniforms, frameBuffer);
return;
}

loopUniforms.amount = amount;
loopUniforms.source = this.inputs.source.texture;
loopUniforms.projection[0] = this.height / this.width;

for (i = 0; i < passes.length; i++) {
pass = Math.min(1, passes[i] / amount);
Expand Down
86 changes: 41 additions & 45 deletions effects/seriously.chroma.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
}(this, function (Seriously) {
'use strict';

/* experimental chroma key algorithm
todo: see if we can minimize branching
todo: calculate HSL of screen color outside shader
/*
experimental chroma key algorithm
todo: try allowing some color despill on opaque pixels
todo: add different modes?
todo: rename parameters
*/

Seriously.plugin('chroma', {
commonShader: true,
shader: function (inputs, shaderSource) {
shaderSource.vertex = [
'precision mediump float;',
Expand All @@ -44,12 +42,10 @@
'varying vec3 screenPrimary;',

'void main(void) {',
' float fmin = min(min(screen.r, screen.g), screen.b); //Min. value of RGB',
' float fmax = max(max(screen.r, screen.g), screen.b); //Max. value of RGB',
' float fmin = min(min(screen.r, screen.g), screen.b);', //Min. value of RGB
' float fmax = max(max(screen.r, screen.g), screen.b);', //Max. value of RGB
' float secondaryComponents;',

//' luminance = (fmax + fmin) / 2.0; // Luminance',
//' screenSat = fmax - fmin; // Saturation',
' screenPrimary = step(fmax, screen.rgb);',
' secondaryComponents = dot(1.0 - screenPrimary, screen.rgb);',
' screenSat = fmax - mix(secondaryComponents - fmin, secondaryComponents / 2.0, balance);',
Expand All @@ -66,6 +62,7 @@
'}'
].join('\n');
shaderSource.fragment = [
this.inputs.mask ? '#define MASK' : '',
'precision mediump float;',

'varying vec2 vTexCoord;',
Expand All @@ -81,52 +78,51 @@
'varying float screenSat;',
'varying vec3 screenPrimary;',

'vec4 sourcePixel;',
'void main(void) {',
' float pixelSat, secondaryComponents;',
' vec4 sourcePixel = texture2D(source, vTexCoord);',

'const mat3 yuv = mat3(',
' 54.213, 182.376, 18.411,',
' -54.213, -182.376, 236.589,',
' 200.787, -182.376, -18.411',
');',
' float fmin = min(min(sourcePixel.r, sourcePixel.g), sourcePixel.b);', //Min. value of RGB
' float fmax = max(max(sourcePixel.r, sourcePixel.g), sourcePixel.b);', //Max. value of RGB
// luminance = fmax

'float round(float n) {',
' return floor(n) + step(0.5, fract(n));',
'}',
' vec3 pixelPrimary = step(fmax, sourcePixel.rgb);',

'void main(void) {',
' float pixelSat, luminance, secondaryComponents;',
' vec3 pixelPrimary;',
' vec4 pixel = vec4(0.0);',
' sourcePixel = texture2D(source, vTexCoord);',

' float fmin = min(min(sourcePixel.r, sourcePixel.g), sourcePixel.b); //Min. value of RGB',
' float fmax = max(max(sourcePixel.r, sourcePixel.g), sourcePixel.b); //Max. value of RGB',
//' float delta = fmax - fmin; //Delta RGB value',

//' luminance = (fmax + fmin) / 2.0; // Luminance',
//' luminance = dot(vec3(0.3, 0.59, 0.11), sourcePixel.rgb); // Luminance',
' luminance = fmax; // Luminance',
' pixelPrimary = step(fmax, sourcePixel.rgb);',
//' pixelSat = delta; // Saturation',
' secondaryComponents = dot(1.0 - pixelPrimary, sourcePixel.rgb);',
' pixelSat = fmax - mix(secondaryComponents - fmin, secondaryComponents / 2.0, balance);', // Saturation
' if (pixelSat < 0.1 || luminance < 0.1 || any(notEqual(pixelPrimary, screenPrimary))) {',

// solid pixel if primary color component is not the same as the screen color
' float diffPrimary = dot(abs(pixelPrimary - screenPrimary), vec3(1.0));',
' float solid = step(1.0, step(pixelSat, 0.1) + step(fmax, 0.1) + diffPrimary);',

/*
Semi-transparent pixel if the primary component matches but if saturation is less
than that of screen color. Otherwise totally transparent
*/
' float alpha = max(0.0, 1.0 - pixelSat / screenSat);',
' alpha = smoothstep(clipBlack, clipWhite, alpha);',
' vec4 semiTransparentPixel = vec4((sourcePixel.rgb - (1.0 - alpha) * screen.rgb * screenWeight) / alpha, alpha);',

' vec4 pixel = mix(semiTransparentPixel, sourcePixel, solid);',

/*
Old branching code
' if (pixelSat < 0.1 || fmax < 0.1 || any(notEqual(pixelPrimary, screenPrimary))) {',
' pixel = sourcePixel;',
//' pixel = vec4(1.0);',
' } else if (pixelSat < screenSat) {',
' float alpha = 1.0 - pixelSat / screenSat;',
' float alpha = max(0.0, 1.0 - pixelSat / screenSat);',
' alpha = smoothstep(clipBlack, clipWhite, alpha);',
//' float despill = alpha / screenWeight;',
' pixel = vec4((sourcePixel.rgb - (1.0 - alpha) * screen.rgb * screenWeight) / alpha, alpha);',
//' pixel = vec4(vec3(alpha), 1.0);',
' }',
//*/

' if (mask) {',
' gl_FragColor = vec4(vec3(pixel.a), 1.0);',
' } else {',
' gl_FragColor = pixel;',
' }',

'#ifdef MASK',
' gl_FragColor = vec4(vec3(pixel.a), 1.0);',
'#else',
' gl_FragColor = pixel;',
'#endif',
'}'
].join('\n');
return shaderSource;
Expand Down Expand Up @@ -172,9 +168,9 @@
mask: {
type: 'boolean',
defaultValue: false,
uniform: 'mask'
uniform: 'mask',
shaderDirty: true
}

},
title: 'Chroma Key',
description: ''
Expand Down
158 changes: 158 additions & 0 deletions effects/seriously.crop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/* global define, require */
(function (root, factory) {
'use strict';

if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['seriously'], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS
factory(require('seriously'));
} else {
if (!root.Seriously) {
root.Seriously = { plugin: function (name, opt) { this[name] = opt; } };
}
factory(root.Seriously);
}
}(this, function (Seriously) {
'use strict';

Seriously.plugin('crop', function () {
var me = this;

// custom resize method
function resize() {
var width = 1,
height = 1,
source = me.inputs.source,
target,
i;

if (me.source) {
width = me.source.width;
height = me.source.height;
} else if (me.sources && me.sources.source) {
width = me.sources.source.width;
height = me.sources.source.height;
}

width = width - me.inputs.left - me.inputs.right;
height = height - me.inputs.top - me.inputs.bottom;

width = Math.max(1, Math.floor(width));
height = Math.max(1, Math.floor(height));


if (me.width !== width || me.height !== height) {
me.width = width;
me.height = height;

me.uniforms.resolution[0] = width;
me.uniforms.resolution[1] = height;

if (me.frameBuffer) {
me.frameBuffer.resize(me.width, me.height);
}

me.emit('resize');
me.setDirty();
}

for (i = 0; i < me.targets.length; i++) {
target = me.targets[i];
target.resize();
if (target.setTransformDirty) {
target.setTransformDirty();
}
}
}

me.resize = resize;

return {
commonShader: true,
shader: function (inputs, shaderSource) {
shaderSource.vertex = [
'precision mediump float;',

'attribute vec4 position;',
'attribute vec2 texCoord;',

'uniform vec2 resolution;',
'uniform mat4 transform;',

'uniform float top;',
'uniform float left;',
'uniform float bottom;',
'uniform float right;',

'varying vec2 vTexCoord;',

'const vec2 ZERO = vec2(0.0);',
'const vec2 ONE = vec2(1.0);',

'void main(void) {',
// first convert to screen space
' vec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);',
' screenPosition = transform * screenPosition;',

// convert back to OpenGL coords
' gl_Position.xy = screenPosition.xy * 2.0 / resolution;',
' gl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);',
' gl_Position.w = screenPosition.w;',

' vec2 dim = resolution + vec2(right + left, bottom + top);',
' vec2 scale = dim / resolution;',
' vec2 offset = vec2(left, bottom) / resolution;',

' vTexCoord = max(ZERO, (texCoord + offset) / scale);',
'}\n'
].join('\n');
return shaderSource;
},
inputs: {
source: {
type: 'image',
uniform: 'source',
update: resize
},
top: {
type: 'number',
uniform: 'top',
min: 0,
step: 1,
update: resize,
defaultValue: 0
},
left: {
type: 'number',
uniform: 'left',
min: 0,
step: 1,
update: resize,
defaultValue: 0
},
bottom: {
type: 'number',
uniform: 'bottom',
min: 0,
step: 1,
update: resize,
defaultValue: 0
},
right: {
type: 'number',
uniform: 'right',
min: 0,
step: 1,
update: resize,
defaultValue: 0
}
}
};
},
{
inPlace: true,
title: 'Crop'
});
}));
Loading

0 comments on commit 63bf296

Please sign in to comment.