Skip to content

Commit

Permalink
Merge pull request #24 from donmccurdy/feat-msdfgen-1.4
Browse files Browse the repository at this point in the history
Add 'negate' option for recent msdfgen.
  • Loading branch information
mattdesl authored Mar 2, 2018
2 parents 98e69cb + ca4cefa commit 9663ebb
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion shaders/msdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ module.exports = function createMSDFShader (opt) {
var precision = opt.precision || 'highp';
var color = opt.color;
var map = opt.map;
var negate = typeof opt.negate === 'boolean' ? opt.negate : true;

// remove to satisfy r73
delete opt.map;
delete opt.color;
delete opt.precision;
delete opt.opacity;
delete opt.negate;

return assign({
uniforms: {
Expand Down Expand Up @@ -46,7 +48,7 @@ module.exports = function createMSDFShader (opt) {
'}',

'void main() {',
' vec3 sample = 1.0 - texture2D(map, vUv).rgb;',
' vec3 sample = ' + (negate ? '1.0 - ' : '') + 'texture2D(map, vUv).rgb;',
' float sigDist = median(sample.r, sample.g, sample.b) - 0.5;',
' float alpha = clamp(sigDist/fwidth(sigDist) + 0.5, 0.0, 1.0);',
' gl_FragColor = vec4(color.xyz, alpha * opacity);',
Expand Down

0 comments on commit 9663ebb

Please sign in to comment.