Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'negate' option for recent msdfgen. #24

Merged
merged 1 commit into from
Mar 2, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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