Skip to content

Commit 9dbb4db

Browse files
committed
Added inverted alpha to bitmap mask
1 parent e0b85dd commit 9dbb4db

4 files changed

Lines changed: 35 additions & 5 deletions

File tree

src/display/mask/BitmapMask.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ var BitmapMask = new Class({
8989
* [description]
9090
*
9191
* @name Phaser.Display.Masks.BitmapMask#mainFramebuffer
92-
* @type {[type]}
92+
* @type {WebGLFramebuffer}
9393
* @since 3.0.0
9494
*/
9595
this.mainFramebuffer = null;
@@ -98,11 +98,20 @@ var BitmapMask = new Class({
9898
* [description]
9999
*
100100
* @name Phaser.Display.Masks.BitmapMask#maskFramebuffer
101-
* @type {[type]}
101+
* @type {WebGLFramebuffer}
102102
* @since 3.0.0
103103
*/
104104
this.maskFramebuffer = null;
105105

106+
/**
107+
* [description]
108+
*
109+
* @name Phaser.Display.Masks.BitmapMask#invertAlpha
110+
* @type {boolean}
111+
* @since 3.1.2
112+
*/
113+
this.invertAlpha = false;
114+
106115
if (renderer.gl)
107116
{
108117
var width = renderer.width;

src/gameobjects/rendertexture/RenderTextureWebGL.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
var RenderTextureWebGL = {
22

3-
fill: function (color)
3+
fill: function (rgb)
44
{
5+
var ur = ((rgb >> 16)|0) & 0xff;
6+
var ug = ((rgb >> 8)|0) & 0xff;
7+
var ub = (rgb|0) & 0xff;
8+
9+
this.renderer.setFramebuffer(this.framebuffer);
10+
var gl = this.gl;
11+
gl.clearColor(ur / 255.0, ug / 255.0, ub / 255.0, 1);
12+
gl.clear(gl.COLOR_BUFFER_BIT);
13+
this.renderer.setFramebuffer(null);
514
return this;
615
},
716

src/renderer/webgl/pipelines/BitmapMaskPipeline.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ var BitmapMaskPipeline = new Class({
194194

195195
renderer.setTexture2D(mask.maskTexture, 1);
196196
renderer.setTexture2D(mask.mainTexture, 0);
197-
197+
renderer.setInt1(this.program, 'uInvertMaskAlpha', mask.invertAlpha);
198+
198199
// Finally draw a triangle filling the whole screen
199200
gl.drawArrays(this.topology, 0, 3);
200201
}

src/renderer/webgl/shaders/BitmapMask.frag

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,23 @@ precision mediump float;
55
uniform vec2 uResolution;
66
uniform sampler2D uMainSampler;
77
uniform sampler2D uMaskSampler;
8+
uniform bool uInvertMaskAlpha;
89

910
void main()
1011
{
1112
vec2 uv = gl_FragCoord.xy / uResolution;
1213
vec4 mainColor = texture2D(uMainSampler, uv);
1314
vec4 maskColor = texture2D(uMaskSampler, uv);
14-
float alpha = maskColor.a * mainColor.a;
15+
float alpha = mainColor.a;
16+
17+
if (!uInvertMaskAlpha)
18+
{
19+
alpha *= (maskColor.a);
20+
}
21+
else
22+
{
23+
alpha *= (1.0 - maskColor.a);
24+
}
25+
1526
gl_FragColor = vec4(mainColor.rgb * alpha, alpha);
1627
}

0 commit comments

Comments
 (0)