mirror of
https://github.com/scratchfoundation/scratch-render.git
synced 2025-08-28 22:30:04 -04:00
Fix brightness and ghost effects
The renderer now uses premultiplied alpha in the frame buffer, though textures are still stored without premultiplied alpha. This makes it easier to get the desired results from the browser's canvas compositing step, and might be nicer for mobile hardware depending on which parts of the Internet you believe.
This commit is contained in:
parent
920271d076
commit
dcedd0c3cf
3 changed files with 13 additions and 8 deletions
|
@ -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';
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue