Skip to content

Commit

Permalink
Merge pull request #103 from brianchirls/develop
Browse files Browse the repository at this point in the history
Release Summer 2015
  • Loading branch information
brianchirls committed Sep 8, 2015
2 parents 2fc0553 + f34009e commit 513d2b8
Show file tree
Hide file tree
Showing 86 changed files with 4,467 additions and 3,224 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ Full documentation is in progress at the [wiki](https://github.com/brianchirls/S
- Checkerboard Generator
- Chroma Key
- Color Complements
- Color Generator
- [Color Cube](http://www.youtube.com/watch?v=rfQ8rKGTVlg&t=24m30s)
- Color Generator
- Color Look-Up Table
- Color Select
- Color Temperature
- Crop
- [Daltonize](http://www.daltonize.org/p/about.html)
- Directional Blur
Expand All @@ -59,6 +61,7 @@ Full documentation is in progress at the [wiki](https://github.com/brianchirls/S
- Luma Key
- Mirror
- Night Vision
- Optical Flow
- Panorama
- Pixelate
- Polar Coordinates
Expand Down
59 changes: 52 additions & 7 deletions effects/seriously.accumulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
factory(root.Seriously);
}
}(this, function (Seriously) {
}(window, function (Seriously) {
'use strict';

/*
Expand Down Expand Up @@ -92,7 +92,28 @@
clear: false
},
frameBuffers,
fbIndex = 0;
fbIndex = 0,
me = this,
width = this.width,
height = this.height;

function clear() {
var gl = me.gl,
width = me.width,
height = me.height,
color = me.inputs.startColor;

if (gl && width && height) {
gl.viewport(0, 0, width, height);
gl.clearColor.apply(gl, color);

gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffers[0].frameBuffer);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

gl.bindFramebuffer(gl.FRAMEBUFFER, frameBuffers[1].frameBuffer);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
}
}

return {
initialize: function (initialize, gl) {
Expand All @@ -101,12 +122,14 @@
this.frameBuffer,
new Seriously.util.FrameBuffer(gl, this.width, this.height)
];
clear();
},
shader: function (inputs, shaderSource) {
var mode = inputs.blendMode || 'normal';
mode = mode.toLowerCase();

shaderSource.fragment = [
'#define SHADER_NAME seriously.accumulator.' + mode,
'precision mediump float;',

'const vec3 ZERO = vec3(0.0);',
Expand Down Expand Up @@ -266,15 +289,21 @@
'uniform sampler2D previous;',

'uniform float opacity;',
'uniform float blendGamma;',

'vec3 BlendOpacity(vec4 base, vec4 blend, float opacity) {',
//apply blend, then mix by (opacity * blend.a)
' vec3 blendedColor = BlendFunction(base.rgb, blend.rgb);',
' return mix(base.rgb, blendedColor, opacity * blend.a);',
'}',

'vec4 linear(vec4 color, vec3 gamma) {',
' return vec4(pow(color.rgb, gamma), color.a);',
'}',

'void main(void) {',
' vec4 topPixel = texture2D(source, vTexCoord);',
' vec3 exp = vec3(blendGamma);',
' vec4 topPixel = linear(texture2D(source, vTexCoord), exp);',
' vec4 bottomPixel = texture2D(previous, vTexCoord);',

' if (topPixel.a == 0.0) {',
Expand All @@ -287,17 +316,21 @@
'#else',
' alpha = bottomPixel.a;',
'#endif',
' gl_FragColor = vec4(BlendOpacity(bottomPixel, topPixel, opacity), alpha);',
' bottomPixel = linear(bottomPixel, exp);',
' gl_FragColor = vec4(pow(BlendOpacity(bottomPixel, topPixel, opacity), 1.0 / exp), alpha);',
' }',
'}'
].join('\n');

return shaderSource;
},
resize: function () {
if (frameBuffers) {
frameBuffers[0].resize(this.width, this.height);
frameBuffers[1].resize(this.width, this.height);
if (frameBuffers && (this.width !== width || this.height !== height)) {
width = this.width;
height = this.height;
frameBuffers[0].resize(width, height);
frameBuffers[1].resize(width, height);
clear();
}
},
draw: function (shader, model, uniforms, frameBuffer, draw) {
Expand All @@ -311,6 +344,7 @@
this.texture = fb.texture;

if (this.inputs.clear) {
clear();
draw(this.baseShader, model, uniforms, fb.frameBuffer, null);
return;
}
Expand Down Expand Up @@ -338,13 +372,24 @@
type: 'boolean',
defaultValue: false
},
startColor: {
type: 'color',
defaultValue: [0, 0, 0, 0]
},
opacity: {
type: 'number',
uniform: 'opacity',
defaultValue: 1,
min: 0,
max: 1
},
blendGamma: {
type: 'number',
uniform: 'blendGamma',
defaultValue: 2.2,
min: 0,
max: 4
},
blendMode: {
type: 'enum',
shaderDirty: true,
Expand Down
2 changes: 1 addition & 1 deletion effects/seriously.ascii.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
factory(root.Seriously);
}
}(this, function (Seriously) {
}(window, function (Seriously) {
'use strict';

/*
Expand Down
2 changes: 1 addition & 1 deletion effects/seriously.bleach-bypass.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
factory(root.Seriously);
}
}(this, function (Seriously) {
}(window, function (Seriously) {
'use strict';

/*
Expand Down
30 changes: 24 additions & 6 deletions effects/seriously.blend.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
factory(root.Seriously);
}
}(this, function (Seriously) {
}(window, function (Seriously) {
'use strict';

/*
Expand Down Expand Up @@ -81,9 +81,9 @@
glow: vectorBlendFormula('BlendReflectf(blend, base)')
},
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
//native blend modes removed for now, because they don't work with linear blending
// normal: ['FUNC_ADD', 'SRC_ALPHA', 'ONE_MINUS_SRC_ALPHA', 'SRC_ALPHA', 'DST_ALPHA']
//todo: add, multiply, screen
},
identity = new Float32Array([
1, 0, 0, 0,
Expand Down Expand Up @@ -231,6 +231,7 @@
}

shaderSource.vertex = [
'#define SHADER_NAME seriously.blend.' + mode,
'precision mediump float;',

'attribute vec4 position;',
Expand All @@ -257,6 +258,7 @@
].join('\n');

shaderSource.fragment = [
'#define SHADER_NAME seriously.blend.' + mode,
'precision mediump float;',
'varying vec2 vTexCoord;',
'uniform sampler2D source;',
Expand All @@ -275,6 +277,7 @@

//todo: need separate texture coords for different size top/bottom images
shaderSource.vertex = [
'#define SHADER_NAME seriously.blend.' + mode,
'precision mediump float;',

'attribute vec4 position;',
Expand All @@ -301,6 +304,7 @@
].join('\n');

shaderSource.fragment = [
'#define SHADER_NAME seriously.blend.' + mode,
'precision mediump float;',

'const vec3 ZERO = vec3(0.0);',
Expand Down Expand Up @@ -459,21 +463,28 @@
'uniform sampler2D top;',
'uniform sampler2D bottom;',
'uniform float opacity;',
'uniform float blendGamma;',

'vec3 BlendOpacity(vec4 base, vec4 blend, float opacity) {',
//apply blend, then mix by (opacity * blend.a)
' vec3 blendedColor = BlendFunction(base.rgb, blend.rgb);',
' return mix(base.rgb, blendedColor, opacity * blend.a);',
'}',

'vec4 linear(vec4 color, vec3 gamma) {',
' return vec4(pow(color.rgb, gamma), color.a);',
'}',

'void main(void) {',
' vec4 topPixel = texture2D(top, texCoordTop);',
' vec3 exp = vec3(blendGamma);',
' vec4 topPixel = linear(texture2D(top, texCoordTop), exp);',
' vec4 bottomPixel = texture2D(bottom, texCoordBottom);',

' if (topPixel.a == 0.0) {',
' gl_FragColor = bottomPixel;',
' } else {',
' gl_FragColor = vec4(BlendOpacity(bottomPixel, topPixel, opacity), bottomPixel.a);',
' bottomPixel = linear(bottomPixel, exp);',
' gl_FragColor = vec4(pow(BlendOpacity(bottomPixel, topPixel, opacity), 1.0 / exp), bottomPixel.a);',
' }',
'}'
].join('\n');
Expand Down Expand Up @@ -541,6 +552,13 @@
}
}
},
blendGamma: {
type: 'number',
uniform: 'blendGamma',
defaultValue: 2.2,
min: 0,
max: 4
},
sizeMode: {
type: 'enum',
defaultValue: 'bottom',
Expand Down
Loading

0 comments on commit 513d2b8

Please sign in to comment.