diff --git a/src/Drawable.js b/src/Drawable.js index 30a432a..197cf8d 100644 --- a/src/Drawable.js +++ b/src/Drawable.js @@ -95,10 +95,10 @@ Drawable._effectConverter = { return Math.max(1, Math.min(x, 512)); }, brightness: function(x) { - return Math.max(-100, Math.min(x, 100)); + return Math.max(-100, Math.min(x, 100)) / 100; }, ghost: function(x) { - return Math.max(0, Math.min(x, 100)); + return 1 - Math.max(0, Math.min(x, 100)) / 100; } }; @@ -312,6 +312,8 @@ Drawable.prototype._setSkinCore = function (source, costumeResolution) { var options = { auto: true, + mag: this._gl.NEAREST, + min: this._gl.LINEAR, // TODO: mipmaps src: source }; var willCallCallback = typeof source == 'string'; diff --git a/src/index.js b/src/index.js index 3775c9e..2352ffe 100644 --- a/src/index.js +++ b/src/index.js @@ -29,7 +29,7 @@ function RenderWebGL( // TODO: remove? twgl.setDefaults({crossOrigin: true}); - this._gl = twgl.getWebGLContext(canvas); + this._gl = twgl.getWebGLContext(canvas, {alpha: false}); this._drawables = []; this._projection = twgl.m4.identity(); @@ -105,8 +105,8 @@ RenderWebGL.prototype.draw = function () { gl.clear(gl.COLOR_BUFFER_BIT); gl.enable(gl.BLEND); - gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); - + gl.blendFuncSeparate(gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ZERO, gl.ONE); + var currentShader = null; var numDrawables = this._drawables.length; diff --git a/src/shaders/sprite.frag b/src/shaders/sprite.frag index 7ee1cb8..d8f4966 100644 --- a/src/shaders/sprite.frag +++ b/src/shaders/sprite.frag @@ -108,9 +108,9 @@ void main() #ifdef ENABLE_pixelate { - // TODO: understand why this padding helps clean up "pixel" edges - const vec2 pixelPadding = vec2(0.125, 0.125); - vec2 pixelTexelSize = u_skinSize * u_scale / u_pixelate; + // TODO: understand why this padding helps clean up "pixel" edges + const vec2 pixelPadding = vec2(0.125, 0.125); + vec2 pixelTexelSize = u_skinSize * u_scale / u_pixelate; texcoord0 = (floor(texcoord0 * pixelTexelSize + pixelPadding)) / pixelTexelSize; } #endif // ENABLE_pixelate @@ -186,4 +186,7 @@ void main() #ifdef ENABLE_ghost gl_FragColor.a *= u_ghost; #endif // ENABLE_ghost + + // WebGL defaults to premultiplied alpha + gl_FragColor.rgb *= gl_FragColor.a; }