-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
azeem
committed
Nov 3, 2013
1 parent
b6eba5e
commit e15619c
Showing
4 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.