Skip to content

Commit

Permalink
Adding UniqueTone #6
Browse files Browse the repository at this point in the history
  • Loading branch information
azeem committed Nov 3, 2013
1 parent b6eba5e commit e15619c
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 3 deletions.
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = function(grunt) {
"src/trans/ColorClip.js",
"src/trans/DynamicMovement.js",
"src/trans/ChannelShift.js",
"src/trans/UniqueTone.js",

"src/render/SuperScope.js",
"src/render/Simple.js",
Expand Down
61 changes: 61 additions & 0 deletions src/trans/UniqueTone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Copyright (c) 2013 Azeem Arshad
* See the file license.txt for copying permission.
*/

(function(Webvs) {

function UniqueTone(options) {
options = _.defaults(options, {
color: "#ffffff",
invert: false,
blendMode: "REPLACE"
});

this.tone = Webvs.parseColorNorm(options.color);
this.invert = options.invert;
this.program = new UniqueToneProgram(Webvs.getBlendMode(options.blendMode));
}
Webvs.UniqueTone = Webvs.defineClass(UniqueTone, Webvs.Component, {
init: function(gl, main, parent) {
UniqueTone.super.init.call(this, gl, main, parent);
this.program.init(gl);
},

update: function() {
this.program.run(this.parent.fm, null, this.tone, this.invert);
},

destroy: function() {
UniqueTone.super.destroy.call(this);
this.program.cleanup();
}
});

function UniqueToneProgram(blendMode) {
UniqueToneProgram.super.constructor.call(this, {
outputBlendMode: blendMode,
swapFrame: true,
fragmentShader: [
"uniform vec3 u_tone;",
"uniform bool u_invert;",
"void main() {",
" vec4 srcColor = getSrcColor();",
" float depth = max(srcColor.r, max(srcColor.g, srcColor.b));",
" if(u_invert) {",
" depth = 1.0-depth;",
" }",
" setFragColor(vec4(depth*u_tone, 1));",
"}"
]
});
}
Webvs.UniqueToneProgram = Webvs.defineClass(UniqueToneProgram, Webvs.QuadBoxProgram, {
draw: function(tone, invert) {
this.setUniform.apply(this, ["u_tone", "3f"].concat(tone));
this.setUniform("u_invert", "1f", invert?1:0);
UniqueToneProgram.super.draw.call(this);
}
});

})(Webvs);
6 changes: 3 additions & 3 deletions test/Simple.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions test/UniqueTone.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e15619c

Please sign in to comment.